Skip to content

Commit

Permalink
fixed icons and added restart button
Browse files Browse the repository at this point in the history
  • Loading branch information
moovida committed Jul 10, 2018
1 parent 207b98b commit f5bd16e
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 4 deletions.
32 changes: 32 additions & 0 deletions src/main/java/com/hydrologis/remarkable/SshHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;

public class SshHelper {
Expand Down Expand Up @@ -197,4 +198,35 @@ public static int checkAck( InputStream in ) throws IOException {
return b;
}

public static String launchSshCommand( Session session, String command ) throws JSchException, IOException {
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);
channel.setInputStream(null);
((ChannelExec) channel).setErrStream(System.err);
InputStream in = channel.getInputStream();
channel.connect();
StringBuilder sb = new StringBuilder();
byte[] tmp = new byte[1024];
while( true ) {
while( in.available() > 0 ) {
int i = in.read(tmp, 0, 1024);
if (i < 0)
break;
sb.append(new String(tmp, 0, i));
}
if (channel.isClosed()) {
if (in.available() > 0)
continue;
System.out.println("exit-status: " + channel.getExitStatus());
break;
}
try {
Thread.sleep(1000);
} catch (Exception ee) {
}
}
channel.disconnect();
return sb.toString();
}

}
27 changes: 26 additions & 1 deletion src/main/java/com/hydrologis/remarkable/TemplatesController.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.hydrologis.remarkable.utils.GuiBridgeHandler;
import com.hydrologis.remarkable.utils.GuiUtilities;
import com.hydrologis.remarkable.utils.GuiUtilities.IOnCloseListener;
import com.hydrologis.remarkable.utils.IconsHandler;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSchException;
Expand All @@ -50,6 +51,7 @@ public class TemplatesController extends TemplatesView implements IOnCloseListen

private static final String TEMPLATES_KEY_IN_JSON = "templates";
private static final String FILENAME_KEY_IN_JSON = "filename";
private static final String ICONCODE_KEY_IN_JSON = "iconCode";
private static final String TEMPLATES_JSON_NAME = "templates.json";
private static final String LS_TEMPLATES = "ls " + PreKeys.REMOTE_TEMPLATES_PATH + "/*.png";
private static final String LS_GRAPHICS = "ls " + PreKeys.REMOTE_GRAPHICS_PATH + "/*.{png,bmp}";
Expand Down Expand Up @@ -198,6 +200,23 @@ public void postWork() throws Exception {
}
});

ActionWithProgress restartAction = new ActionWithProgress(this, "Restart", 4, true){
@Override
public void onError( Exception e ) {
e.printStackTrace();
JOptionPane.showMessageDialog(parent, e.getLocalizedMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
}

@Override
public void backGroundWork( ProgressMonitor monitor ) throws Exception {
try (EasySession s1 = new EasySession()) {
SshHelper.launchSshCommand(s1.getSession(), "systemctl restart xochitl");
}
}
};
_restartRemarkableButton.setAction(restartAction);
_restartRemarkableButton.setText("Restart Device");

_aboutButton.addActionListener(e -> {
JOptionPane.showMessageDialog(this,
"This software is developed by HydroloGIS S.r.l. and released under GPL v3.0 license.\n\n"
Expand Down Expand Up @@ -403,6 +422,11 @@ private void downloadTemplatesJson( Session session ) {
for( int i = 0; i < templatesArray.length(); i++ ) {
JSONObject templateObject = templatesArray.getJSONObject(i);
String fileName = templateObject.getString(FILENAME_KEY_IN_JSON);
String iconCode = templateObject.getString(ICONCODE_KEY_IN_JSON);
String iconString = IconsHandler.INSTANCE.getIconString(iconCode);
if (iconString != null) {
templateObject.put(ICONCODE_KEY_IN_JSON, iconString);
}
remoteTemplateFileNames.add(fileName);
}

Expand All @@ -417,6 +441,7 @@ private void downloadTemplatesJson( Session session ) {
FileUtilities.copyFile(localJsonPath, localJsonPath + "_" + dateFormatter.format(new Date()));

String newTemplates = root.toString(2);
newTemplates = newTemplates.replaceAll("\\\\\\\\", "\\\\");
FileUtilities.writeFile(newTemplates, new File(localJsonPath));

} catch (Exception e) {
Expand All @@ -430,7 +455,7 @@ private JSONObject getNewJson( String name, String fileName ) {
String json = "{" + //
" \"name\": \"" + name + "\"," + //
" \"filename\": \"" + fileName + "\"," + //
" \"iconCode\": \"\ue9fe\"," + //
" \"iconCode\": \"" + IconsHandler.CUSTOM_ICON + "\"," + //
" \"categories\": [" + //
" \"Custom\"" + //
" ]" + //
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/hydrologis/remarkable/TemplatesView.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class TemplatesView extends JPanel
JButton _basefolderButton = new JButton();
JButton _backupButton = new JButton();
JButton _aboutButton = new JButton();
JButton _restartRemarkableButton = new JButton();

/**
* Default constructor
Expand Down Expand Up @@ -189,6 +190,11 @@ public JPanel createPanel()
_aboutButton.setText("About");
jpanel1.add(_aboutButton,cc.xy(19,26));

_restartRemarkableButton.setActionCommand("Restart Remarkable");
_restartRemarkableButton.setName("restartRemarkableButton");
_restartRemarkableButton.setText("Restart Remarkable");
jpanel1.add(_restartRemarkableButton,cc.xy(17,26));

addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27 });
return jpanel1;
}
Expand Down
60 changes: 58 additions & 2 deletions src/main/java/com/hydrologis/remarkable/TemplatesView.xml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
</at>
<at name="componentclass">com.jeta.forms.gui.form.FormComponent</at>
</super>
<at name="id">embedded.907090833</at>
<at name="id">embedded.1314414079</at>
<at name="rowspecs">CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,FILL:DEFAULT:GROW(1.0),CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),CENTER:DEFAULT:NONE</at>
<at name="colspecs">FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE</at>
<at name="components">
Expand Down Expand Up @@ -961,7 +961,7 @@
</at>
<at name="componentclass">com.jeta.forms.gui.form.FormComponent</at>
</super>
<at name="id">embedded.1142693022</at>
<at name="id">embedded.1937775010</at>
<at name="rowspecs">CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE</at>
<at name="colspecs">FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE</at>
<at name="components">
Expand Down Expand Up @@ -1533,6 +1533,62 @@
</object>
</at>
</item>
<item >
<at name="value">
<object classname="com.jeta.forms.store.memento.BeanMemento">
<super classname="com.jeta.forms.store.memento.ComponentMemento">
<at name="cellconstraints">
<object classname="com.jeta.forms.store.memento.CellConstraintsMemento">
<at name="column">17</at>
<at name="row">26</at>
<at name="colspan">1</at>
<at name="rowspan">1</at>
<at name="halign">default</at>
<at name="valign">default</at>
<at name="insets" object="insets">0,0,0,0</at>
</object>
</at>
<at name="componentclass">com.jeta.forms.gui.form.StandardComponent</at>
</super>
<at name="jetabeanclass">com.jeta.forms.gui.beans.JETABean</at>
<at name="beanclass">javax.swing.JButton</at>
<at name="beanproperties">
<object classname="com.jeta.forms.store.memento.PropertiesMemento">
<at name="classname">javax.swing.JButton</at>
<at name="properties">
<object classname="com.jeta.forms.store.support.PropertyMap">
<at name="border">
<object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
<super classname="com.jeta.forms.store.properties.BorderProperty">
<at name="name">border</at>
</super>
<at name="borders">
<object classname="java.util.LinkedList">
<item >
<at name="value">
<object classname="com.jeta.forms.store.properties.DefaultBorderProperty">
<super classname="com.jeta.forms.store.properties.BorderProperty">
<at name="name">border</at>
</super>
</object>
</at>
</item>
</object>
</at>
</object>
</at>
<at name="actionCommand">Restart Remarkable</at>
<at name="name">restartRemarkableButton</at>
<at name="width">116</at>
<at name="text">Restart Remarkable</at>
<at name="height">22</at>
</object>
</at>
</object>
</at>
</object>
</at>
</item>
</object>
</at>
<at name="properties">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ public static String readFile( File file ) throws IOException {
if (!file.exists()) {
throw new FileNotFoundException("The required projection file is not available: " + file.getAbsolutePath());
}
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
try (BufferedReader br = new BufferedReader(
new InputStreamReader(new FileInputStream(file.getAbsolutePath()), "UTF-8"))) {
StringBuilder sb = new StringBuilder(200);
String line;
while( (line = br.readLine()) != null ) {
Expand Down
85 changes: 85 additions & 0 deletions src/main/java/com/hydrologis/remarkable/utils/IconsHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.hydrologis.remarkable.utils;

import java.util.HashMap;

public enum IconsHandler {
INSTANCE;

public static final String CUSTOM_ICON = "\\ue9fe";

private HashMap<String, String> iconsMap = new HashMap<>();
private IconsHandler() {
iconsMap.put("\ue9fe", "\\ue9fe");
iconsMap.put("\ue9fd", "\\ue9fd");
iconsMap.put("\ue9aa", "\\ue9aa");
iconsMap.put("\ue9ab", "\\ue9ab");
iconsMap.put("\ue9ac", "\\ue9ac");
iconsMap.put("\ue9ad", "\\ue9ad");
iconsMap.put("\ue9b4", "\\ue9b4");
iconsMap.put("\ue9b6", "\\ue9b6");
iconsMap.put("\ue9bc", "\\ue9bc");
iconsMap.put("\ue9c9", "\\ue9c9");
iconsMap.put("\ue9b7", "\\ue9b7");
iconsMap.put("\ue9ba", "\\ue9ba");
iconsMap.put("\ue9b8", "\\ue9b8");
iconsMap.put("\ue9b9", "\\ue9b9");
iconsMap.put("\ue9bb", "\\ue9bb");
iconsMap.put("\ue9c8", "\\ue9c8");
iconsMap.put("\ue9ca", "\\ue9ca");
iconsMap.put("\ue9cc", "\\ue9cc");
iconsMap.put("\ue9cb", "\\ue9cb");
iconsMap.put("\ue9d4", "\\ue9d4");
iconsMap.put("\ue9d7", "\\ue9d7");
iconsMap.put("\ue9cd", "\\ue9cd");
iconsMap.put("\ue9b5", "\\ue9b5");
iconsMap.put("\ue997", "\\ue997");
iconsMap.put("\ue9ce", "\\ue9ce");
iconsMap.put("\ue9cf", "\\ue9cf");
iconsMap.put("\ue9d3", "\\ue9d3");
iconsMap.put("\ue98f", "\\ue98f");
iconsMap.put("\ue9ff", "\\ue9ff");
iconsMap.put("\ue991", "\\ue991");
iconsMap.put("\ue993", "\\ue993");
iconsMap.put("\ue996", "\\ue996");
iconsMap.put("\ue995", "\\ue995");
iconsMap.put("\ue994", "\\ue994");
iconsMap.put("\ue9f9", "\\ue9f9");
iconsMap.put("\ue9f8", "\\ue9f8");
iconsMap.put("\ue999", "\\ue999");
iconsMap.put("\ue99a", "\\ue99a");
iconsMap.put("\ue99d", "\\ue99d");
iconsMap.put("\ue99e", "\\ue99e");
iconsMap.put("\ue9fc", "\\ue9fc");
iconsMap.put("\ue9fb", "\\ue9fb");
iconsMap.put("\ue9fa", "\\ue9fa");
iconsMap.put("\ue99b", "\\ue99b");
iconsMap.put("\ue99c", "\\ue99c");
iconsMap.put("\ue99f", "\\ue99f");
iconsMap.put("\ue9a5", "\\ue9a5");
iconsMap.put("\ue9a0", "\\ue9a0");
iconsMap.put("\ue9a9", "\\ue9a9");
iconsMap.put("\ue9a6", "\\ue9a6");
iconsMap.put("\ue9a7", "\\ue9a7");
iconsMap.put("\ue9a8", "\\ue9a8");
iconsMap.put("\ue9d0", "\\ue9d0");
iconsMap.put("\ue9d1", "\\ue9d1");
iconsMap.put("\ue9d2", "\\ue9d2");
iconsMap.put("\ue9d8", "\\ue9d8");
iconsMap.put("\ue9d9", "\\ue9d9");
iconsMap.put("\ue9dc", "\\ue9dc");
iconsMap.put("\ue9da", "\\ue9da");
iconsMap.put("\ue9db", "\\ue9db");
iconsMap.put("\uea00", "\\uea00");
iconsMap.put("\ue9d5", "\\ue9d5");
iconsMap.put("\ue9d6", "\\ue9d6");
iconsMap.put("\ue9fe", "\\ue9fe");
iconsMap.put("\ue9fe", "\\ue9fe");
iconsMap.put("\ue9fe", "\\ue9fe");
iconsMap.put("\ue9fe", "\\ue9fe");
}

public String getIconString( String code ) {
return iconsMap.get(code);
}

}

0 comments on commit f5bd16e

Please sign in to comment.