Change layout/banner/take backup works.
authorJimmy Christensen <dusted@dusted.dk>
Wed, 25 Mar 2015 07:28:55 +0000 (09:28 +0200)
committerJimmy Christensen <dusted@dusted.dk>
Wed, 25 Mar 2015 07:28:55 +0000 (09:28 +0200)
Still missing: Restore, re-encrypt (change password), format, debugging.

src/fkgui/Backup.java [new file with mode: 0644]
src/fkgui/FkActionEventListener.java
src/fkgui/FkManager.java
src/fkgui/MainWin.java
src/fkgui/Messages.java
src/fkgui/NewAccountDialog.java
src/fkgui/SaveSettingsDialog.java [new file with mode: 0644]
src/fkgui/SerialWorker.java
src/fkgui/gfx/backup.png [new file with mode: 0644]
src/fkgui/gfx/restore.png [new file with mode: 0644]
src/fkgui/messages.properties

diff --git a/src/fkgui/Backup.java b/src/fkgui/Backup.java
new file mode 100644 (file)
index 0000000..da2558b
--- /dev/null
@@ -0,0 +1,238 @@
+package fkgui;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+
+import org.eclipse.core.runtime.Path;
+import org.eclipse.swt.widgets.Dialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Button;
+
+import com.sun.org.apache.bcel.internal.generic.CPInstruction;
+
+public class Backup extends Dialog implements FkActionEventListener {
+
+       protected Object result;
+       protected Shell shell;
+
+       /**
+        * Create the dialog.
+        * @param parent
+        * @param style
+        */
+       public Backup(Shell parent, int style) {
+               super(parent, style);
+       }
+
+       /**
+        * Open the dialog.
+        * @return the result
+        */
+       private boolean restoreBackup;
+       private File backupFile;
+       private String fileName;
+       private Backup mySelf; 
+       private Composite cmpBackupFileSelect;
+       
+       
+       public Object open(boolean _restoreBackup) {
+               restoreBackup=_restoreBackup;
+               createContents();
+               shell.open();
+               shell.layout();
+               mySelf = this;
+
+               if( _restoreBackup )
+               {
+                       setText("FinalKey - Restore");
+               } else {
+                       setText("FinalKey - Backup");
+               }
+
+               Display display = getParent().getDisplay();
+               while (!shell.isDisposed()) {
+                       if (!display.readAndDispatch()) {
+                               display.sleep();
+                       }
+               }
+               return result;
+       }
+
+       /**
+        * Create contents of the dialog.
+        */
+       private void createContents() {
+               shell = new Shell(getParent(), SWT.DIALOG_TRIM);
+               shell.setSize(510, 506);
+               shell.setText(getText());
+               shell.setLayout(new FormLayout());
+               
+               cmpBackupFileSelect = new Composite(shell, SWT.NONE);
+               cmpBackupFileSelect.setLayout(new FormLayout());
+               FormData fd_cmpBackupFileSelect = new FormData();
+               fd_cmpBackupFileSelect.bottom = new FormAttachment(0, 481);
+               fd_cmpBackupFileSelect.right = new FormAttachment(0, 506);
+               fd_cmpBackupFileSelect.top = new FormAttachment(0);
+               fd_cmpBackupFileSelect.left = new FormAttachment(0);
+               cmpBackupFileSelect.setLayoutData(fd_cmpBackupFileSelect);
+               
+               Label lblNewLabel = new Label(cmpBackupFileSelect, SWT.NONE);
+               FormData fd_lblNewLabel = new FormData();
+               fd_lblNewLabel.top = new FormAttachment(0, 10);
+               fd_lblNewLabel.left = new FormAttachment(0, 10);
+               fd_lblNewLabel.bottom = new FormAttachment(0, 184);
+               fd_lblNewLabel.right = new FormAttachment(0, 496);
+               lblNewLabel.setLayoutData(fd_lblNewLabel);
+               lblNewLabel.setText("About backup:\nIt is a good idea to backup your FinalKey so you don't\nlose all your logins if you lose your FinalKey or it breaks.\n\nSecurity:\nThe FinalKey backup files are encrypted, but you should\nnever keep them on your computer or in a place where\nsomeone else may steal them. Keep your backup on\nan offline storage medium in a safe place.\n");
+               
+               Button btnBrowse = new Button(cmpBackupFileSelect, SWT.NONE);
+               FormData fd_btnBrowse = new FormData();
+               fd_btnBrowse.right = new FormAttachment(100, -10);
+               fd_btnBrowse.top = new FormAttachment(100, -53);
+               fd_btnBrowse.bottom = new FormAttachment(100, -10);
+               btnBrowse.setLayoutData(fd_btnBrowse);
+               btnBrowse.setText("Browse ...");
+               
+               btnBrowse.addSelectionListener( new SelectionAdapter() {
+                       public void widgetSelected(SelectionEvent e) {
+                               FileDialog fd = new FileDialog(shell, SWT.SAVE );
+                               String[] ext = { "*.fkb", "*.*"  };
+                               String[] extN = { "FinalKey Backup Files", "All Files"};
+                               fd.setFilterExtensions( ext );
+                               fd.setFilterNames(extN);
+                               
+                               fileName = fd.open();
+                               System.out.println("FileName:" +fileName);
+                               backupFile = new File(fileName);
+                               if( !backupFile.exists() && !backupFile.isDirectory())
+                               { 
+                                       try {
+                                               backupFile.createNewFile();
+                                               
+                                               MessageBox m = new MessageBox(shell, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
+                                               m.setText("Ready to take backup?");
+                                               m.setMessage("When you press Yes, the FinalKey will blink, and you have 5 seconds to press the button to allow backup. Save backup now ?");
+                                               
+                                               if( m.open() == SWT.YES )
+                                               {
+                                                       FkManager.getInstance().backup(backupFile, mySelf);
+                                                       
+                                               } else {
+                                                       backupFile.delete();
+                                               }
+
+                                       } catch (IOException e1) {
+                                               MessageBox m = new MessageBox(shell, SWT.ERROR);
+                                               m.setText("Error");
+                                               m.setMessage("Could not create the file, do you have permissions to write there? Is there enough free space?");
+                                               m.open();
+                                               fileName=null;
+                                       }
+                               } else {
+                                       MessageBox m = new MessageBox(shell, SWT.ERROR);
+                                       m.setText("Error");
+                                       m.setMessage("Will not overwrite an existing file, select another file-name or delete the existing file first.");
+                                       m.open();
+                                       fileName=null;
+                               }
+                               
+                               System.out.println(fileName);
+                       }
+                       
+               });
+               
+               Label lblPressbrowseAnd = new Label(cmpBackupFileSelect, SWT.NONE);
+               fd_btnBrowse.left = new FormAttachment(0, 408);
+               FormData fd_lblPressbrowseAnd = new FormData();
+               fd_lblPressbrowseAnd.right = new FormAttachment(btnBrowse, -6);
+               fd_lblPressbrowseAnd.bottom = new FormAttachment(100, -10);
+               fd_lblPressbrowseAnd.left = new FormAttachment(0, 10);
+               fd_lblPressbrowseAnd.top = new FormAttachment(100, -77);
+               lblPressbrowseAnd.setLayoutData(fd_lblPressbrowseAnd);
+               lblPressbrowseAnd.setText("Press \"Browse\" to select where to save the backup.");
+
+       }
+
+       @Override
+       public void fkActionEvent(FkActionEvent event) {
+               MessageBox m;
+               System.out.println(event);
+               
+               //Handle errors differently when we are taking bacup
+               if( !restoreBackup )
+               {
+                       switch( event.type )
+                       {
+                       case ACTION_ABORTED:
+                               break;
+                       case ACTION_ERROR:
+                               m = new MessageBox(shell, SWT.ICON_ERROR| SWT.YES| SWT.NO);
+                               m.setText("Checksum Error");
+                               m.setMessage("There were one or more errors when verifying the backup data, this may indicate a bad connection or a hardware-malfunction on the FinalKey.\nThe Backup File can NOT be restored onto the FinalKey, but it may be manually repaired by someone with a hex-editor and too much free-time. Do you want to delete the corrupted file ?");
+                               if( m.open() == SWT.YES )
+                               {
+                                       backupFile.delete();
+                               } else {
+                                       backupFile.renameTo( new File(fileName+"-failed"));
+                                       File crashLog = new File(fileName+"-errorlog.txt");
+                                       FileOutputStream fout;
+                                       try {
+                                               fout = new FileOutputStream( crashLog );
+                                               fout.write( event.data.getBytes() );
+                                               fout.close();
+                                       } catch (Exception e) {
+                                               e.printStackTrace();
+                                       }
+
+                               }
+                               shell.close();
+                               
+                               break;
+                       case ACTION_OKAY:
+                               //TODO:
+                               m=new MessageBox(shell, SWT.ICON_INFORMATION);
+                               m.setText("Backup successful");
+                               m.setMessage("Your backup was verified and saved.");
+                               m.open();
+                               shell.close();
+                               break;
+                       case ACTION_WAITING:
+                               //TODO:
+                               //Make visible icon
+                               //Write text "waiting for button press"
+                               break;
+                       case ACTION_WORKING:
+                               //TODO:
+                               //Switch to status-view (writing)
+                               cmpBackupFileSelect.dispose();
+                               break;
+                       case PROGRESS_UPDATE:
+                               
+                               break;
+                       case STATE_ERROR:
+                               break;
+                       case UNEXPECTED_ACTION_RESULT_ERROR:
+                               break;
+                       default:
+                               break;
+                       
+                       }
+               }
+               
+       }
+
+}
index ed125ab..f44ee32 100644 (file)
@@ -17,7 +17,12 @@ public interface FkActionEventListener {
                        acc=a;
                        action=act;
                }
+               
+               public String toString()
+               {
+                       return("Event {\n  Type: "+type+"\n  Data: "+data+"\n  Account: "+((acc!=null)?acc.toString():"null")+"\n  Action:"+action+"\n}");
+               }
        }
-       public enum FkActionEventType { ACTION_ABORTED, ACTION_OKAY, ACTION_ERROR, ACTION_WAITING, ACTION_WORKING, STATE_ERROR, UNEXPECTED_ACTION_RESULT_ERROR };
+       public enum FkActionEventType { ACTION_ABORTED, ACTION_OKAY, ACTION_ERROR, ACTION_WAITING, ACTION_WORKING, STATE_ERROR, UNEXPECTED_ACTION_RESULT_ERROR, PROGRESS_UPDATE };
        public void fkActionEvent( FkActionEvent event );
 }
index 21b37b9..8d95a4c 100644 (file)
@@ -2,6 +2,9 @@ package fkgui;
 
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Vector;
@@ -10,6 +13,8 @@ import jssc.SerialPort;
 
 import org.eclipse.swt.widgets.Display;
 
+import com.sun.corba.se.impl.ior.ByteBuffer;
+
 import fkgui.FkActionEventListener.FkActionEvent;
 import fkgui.FkActionEventListener.FkActionEventType;
 
@@ -347,9 +352,10 @@ public class FkManager implements ActionListener {
                return(res);
        }
 
-       public Vector<String> getAvailableLayouts()
+       public String[] getAvailableLayouts()
        {
-               return(supportedLayouts);
+               String[] layouts = supportedLayouts.toArray(new String[supportedLayouts.size()]);
+               return(layouts);
        }
        
        public String addAvailableLayout( String str )
@@ -361,10 +367,7 @@ public class FkManager implements ActionListener {
                return(l);
        }
        
-       public void setLayout(int num)
-       {
-               
-       }
+
 
        @Override
        public void actionPerformed(ActionEvent e) {
@@ -666,7 +669,7 @@ public class FkManager implements ActionListener {
                }
        }
 
-       public void setCurrentBanner(String _banner) {
+       public void setBanner(String _banner) {
                banner = _banner;
                
        }
@@ -675,6 +678,520 @@ public class FkManager implements ActionListener {
        {
                return(banner);
        }
+       
+       public boolean isStringValidForFk(String str)
+       {
+
+               char passChars[] = {
+                               '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E',
+                               'F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T',
+                               'U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i',
+                               'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x',
+                               'y','z','!','"','#','$','%','&','@','?','(',')','[',']','-',
+                               '.',',','+','{','}','_','/','<','>','=','|','\'','\\', 
+                               ';',':',' ','*'// <- 92 (idx 91)
+                               };
+
+
+               int len = str.length();
+               for(int i=0; i<len; i++)
+               {
+                       boolean valid=false;
+
+                       for(char c : passChars)
+                       {
+                               if(str.charAt(i)==c)
+                               {
+                                       valid=true;
+                               }
+                       }
+
+                       if(!valid)
+                       {
+                               System.out.println("FkManager.isStringValidForFk(); Invalid character '"+str.charAt(i)+"' at pos "+i+" in '"+str+"'");
+                               return false;
+                       }
+               }
+
+               return true;
+       }
+
+       
+       
+       ///
+       private class BannerTask implements Runnable
+       {
+
+               private FkActionEventListener delegate;
+               private String bannerTxt;
+               
+               public BannerTask(String txt, FkActionEventListener d )
+               {
+                       bannerTxt=txt;
+                       delegate=d;
+               }
+               
+               @Override
+               public void run() {
+                       
+                       int timeOut=0;
+                       String data="";
+                       String msg = "";
+
+
+                       try {
+                       
+                               //First check that we get a prompt
+                               if( !checkState() )
+                               {
+                                       Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.STATE_ERROR, "EXCEPTION",null,'b') );
+                                       return;
+                               }
+
+                               //Drain any previous input.
+                               while( com.serialPort.getInputBufferBytesCount() > 0 )
+                               {
+                                       com.serialPort.readBytes();
+                               }
+                               
+                               com.serialPort.writeByte((byte)'x');
+                               com.serialPort.writeByte((byte)'b');
+                               Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_WAITING, "WAITING",null,'b') );
+
+                               timeOut = 6000;
+                               while(timeOut > 0)
+                               {
+                                       if( com.serialPort.getInputBufferBytesCount() > 0 )
+                                       {
+                                               String in = com.serialPort.readString(); 
+                                               data += in;
+                                               System.out.println("Datain:" +in);
+                                               if( data.contains("Banner (0-31):\r\n") )
+                                               {
+                                                       System.out.println("Found");
+                                                       break;
+                                               }
+                                       } else {
+                                               timeOut -= 50;
+                                               Thread.sleep(50);
+                                       }
+                               }
+                               
+
+                               if(timeOut > 0 )
+                               {
+                                       Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_WORKING, "WORKING",null,'b') );
+
+                                       for(int p=0; p < bannerTxt.length();p++)
+                                       {
+                                               com.serialPort.writeByte( (byte)bannerTxt.charAt(p) );
+                                               Thread.sleep(5);
+                                       }
+
+                                       while( com.serialPort.getInputBufferBytesCount() > 0 )
+                                       {
+                                               com.serialPort.readBytes();
+                                       }
+
+                                       com.serialPort.writeByte( (byte)ENTER_KEY );
+
+                                       timeOut = 3000;
+                                       while(timeOut > 0)
+                                       {
+                                               if( com.serialPort.getInputBufferBytesCount() > 0 )
+                                               {
+                                                       String in = com.serialPort.readString(); 
+                                                       data += in;
+                                                       System.out.println("Datain:" +in);
+                                                       if( data.contains("[done]\r\n") )
+                                                       {
+                                                               System.out.println("Found");
+                                                               break;
+                                                       }
+                                               } else {
+                                                       timeOut -= 50;
+                                                       Thread.sleep(50);
+                                               }
+                                       }
+                               }
+
+                               if( timeOut > 0 )
+                               {
+
+                                       Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_OKAY, "Saved:"+data,null,'b') );
+                               } else {
+                                       Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_ABORTED, "TIMEOUT:"+data,null,'b') );
+                               }
+
+                       } catch(Exception e)
+                       {
+                               Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_ERROR, "EXCEPTION",null,'b') );
+                               return;
+                       }
+               }
+
+       }
+
+       public void saveBanner(String bannerTxt, FkActionEventListener eventListener) {
+               BannerTask bannerTask = new BannerTask(bannerTxt, eventListener);
+               new Thread(bannerTask).start();
+       }
+
+       
+       private class LayoutTask implements Runnable
+       {
+
+               private FkActionEventListener delegate;
+               private String layout;
+               
+               public LayoutTask(int _Layout, FkActionEventListener d )
+               {
+                       layout = ""+_Layout;
+                       delegate=d;
+               }
+               
+               @Override
+               public void run() {
+                       
+                       int timeOut=0;
+                       String data="";
+                       String msg = "";
+
+
+                       try {
+                       
+                               //First check that we get a prompt
+                               if( !checkState() )
+                               {
+                                       Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.STATE_ERROR, "EXCEPTION",null,'k') );
+                                       return;
+                               }
+
+                               //Drain any previous input.
+                               while( com.serialPort.getInputBufferBytesCount() > 0 )
+                               {
+                                       com.serialPort.readBytes();
+                               }
+                               
+                               com.serialPort.writeByte((byte)'x');
+                               com.serialPort.writeByte((byte)'k');
+                               Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_WAITING, "WAITING",null,'k') );
+
+                               timeOut = 6000;
+                               while(timeOut > 0)
+                               {
+                                       if( com.serialPort.getInputBufferBytesCount() > 0 )
+                                       {
+                                               String in = com.serialPort.readString(); 
+                                               data += in;
+                                               System.out.println("Datain:" +in);
+                                               if( data.contains("Select keyboard layout:\r\n") && data.contains("\r\n% ") )
+                                               {
+                                                       System.out.println("Found");
+                                                       break;
+                                               }
+                                       } else {
+                                               timeOut -= 50;
+                                               Thread.sleep(50);
+                                       }
+                               }
+
+                               if(timeOut > 0 )
+                               {
+
+
+                                       com.serialPort.writeByte( (byte)layout.charAt(0) );
+
+
+                                       while( com.serialPort.getInputBufferBytesCount() > 0 )
+                                       {
+                                               com.serialPort.readBytes();
+                                       }
+
+                                       com.serialPort.writeByte( (byte)ENTER_KEY );
+
+                                       timeOut = 3000;
+                                       while(timeOut > 0)
+                                       {
+                                               if( com.serialPort.getInputBufferBytesCount() > 0 )
+                                               {
+                                                       String in = com.serialPort.readString(); 
+                                                       data += in;
+                                                       System.out.println("Datain:" +in);
+                                                       if( data.contains("test.\r\n#") )
+                                                       {
+                                                               System.out.println("Found");
+                                                               break;
+                                                       }
+                                               } else {
+                                                       timeOut -= 50;
+                                                       Thread.sleep(50);
+                                               }
+                                       }
+                               }
+
+                               timeOut = 30000;
+                               while(timeOut > 0)
+                               {
+                                       if( com.serialPort.getInputBufferBytesCount() > 0 )
+                                       {
+                                               String in = com.serialPort.readString(); 
+                                               data += in;
+                                               System.out.println("Datain:" +in);
+                                               if( data.contains("Correct [y/n] ?") )
+                                               {
+                                                       Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_WORKING, "WORKING",null,'k') );
+                                                       System.out.println("Found");
+                                                       com.serialPort.writeByte((byte)'y');
+
+                                                       Thread.sleep(500); //sleep before returning the result, give the UI plenty of time to catch up.
+
+                                                       break;
+                                               }
+                                       } else {
+                                               timeOut -= 50;
+                                               Thread.sleep(50);
+                                       }
+                               }                               
+
+                               if( timeOut > 0 )
+                               {
+                                       Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_OKAY, "Saved:"+data,null,'k') );
+                               } else {
+                                       Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_ABORTED, "TIMEOUT:"+data,null,'k') );
+                               }
+
+                       } catch(Exception e)
+                       {
+                               Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_ERROR, "EXCEPTION",null,'k') );
+                               return;
+                       }
+               }
+
+       }
+       
+       public void saveLayout(int layout, FkActionEventListener eventListener) {
+               LayoutTask lt = new LayoutTask(layout, eventListener);
+               new Thread(lt).start();
+       }
+       
+       
+       private class BackupTask implements Runnable
+       {
+
+               private FkActionEventListener delegate;
+               private File file;
+               
+               
+               public BackupTask(File f, FkActionEventListener d )
+               {
+                       file=f;
+                       delegate=d;
+               }
+               
+               /*
+                * 
+                * uint8_t crc8(const uint8_t *addr, uint8_t len)
+               {
+                       uint8_t crc = 0;
+
+                       while (len--) {
+                               uint8_t inbyte = *addr++;
+                               for (uint8_t i = 8; i; i--) {
+                                       uint8_t mix = (crc ^ inbyte) & 0x01;
+                                       crc >>= 1;
+                                       if (mix) crc ^= 0x8C;
+                                       inbyte >>= 1;
+                               }
+                       }
+                       return crc;
+               }*/
+               
+               byte crc8( byte[] dat, int begin, int len )
+               {
+                       int crc = 0;
+                       
+                       int idx=0;
+
+                       while( len-- != 0 )
+                       {
+                               int inbyte = dat[begin+idx];
+                               idx++;
+                               
+                               for(int i=8; i!=0; i--)
+                               {
+                                       int mix =  (( crc ^ inbyte) & 0x01);
+                                       crc >>=1;
+                                       if( mix != 0 )
+                                       {
+                                               crc ^=0x8C;
+                                       }
+                                       inbyte >>=1;
+                               }
+                       }
+                       return((byte)crc);
+               }
+               
+               @Override
+               public void run() {
+                       
+                       int timeOut=0;
+                       String data="";
+
+                       int state=0;
+
+                       try {
+
+                               //First check that we get a prompt
+                               if( !checkState() )
+                               {
+                                       Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.STATE_ERROR, "EXCEPTION",null,'e') );
+                                       return;
+                               }
+
+                               //Drain any previous input.
+                               while( com.serialPort.getInputBufferBytesCount() > 0 )
+                               {
+                                       com.serialPort.readBytes();
+                               }
+                               com.serialPort.writeByte((byte)'X');
+                               com.serialPort.writeByte((byte)'e');
+
+                               
+                               timeOut = 6000;
+                               
+                               ByteBuffer bin = new ByteBuffer( 67000 );
+
+                               while(timeOut > 0)
+                               {
+                                       if( com.serialPort.getInputBufferBytesCount() > 0 )
+                                       {
+                                               
+                                               int n = com.serialPort.getInputBufferBytesCount();
+                                               while(n-->0)
+                                               {
+                                                       bin.append( com.serialPort.readBytes(1)[0]);
+                                               }
+
+
+                                               data += new String(bin.toArray());
+
+                                               if( state==0 && data.contains("[RDY]\r\n") )
+                                               {
+                                                       Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_WAITING, "WAITING",null,'e') );
+
+                                                       state=1;
+                                               }
+
+                                               if( state==1 && data.contains("[OK]\r\n[BEGIN]" ) )
+                                               {
+                                                       state=2;
+
+                                                       Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_WORKING, "Working",null,'e') );
+                                               }
+
+                                               if( state==2 )
+                                               {
+                                                       timeOut=3000;
+                                                       if( data.contains("[END]") )
+                                                       {
+
+                                                               //data = data.substring(0, data.length()-5 );
+                                                               
+                                                               bin.trimToSize();
+                                                               
+                                                               byte[] arr = bin.toArray();
+                                                               
+                                                               byte[] clean = new byte[66000];
+                                                               
+                                                               state=0;
+                                                               int idx=0;
+                                                               int cc=0;
+                                                               String errors="";
+                                                               for(int i=0;i< arr.length; i++ )
+                                                               {
+                                                                       //Find [BEGIN]
+                                                                       if(state==0 && i+6 < arr.length)
+                                                                       {
+                                                                               if(arr[i] == '[' &&arr[i+1] == 'B' &&arr[i+2] == 'E' &&arr[i+3] == 'G' &&arr[i+4] == 'I' &&arr[i+5] == 'N' &&arr[i+6] == ']' )
+                                                                               {
+                                                                                       i+=7;
+                                                                                       state=1;
+                                                                                       idx=0;
+                                                                               }
+                                                                       }
+                                                                       
+                                                                       if(state==1)
+                                                                       {
+                                                                               
+                                                                               if( idx < 66000 )
+                                                                               {
+                                                                                       clean[idx] = arr[i];
+                                                                                       cc++;
+                                                                                       
+                                                                                       if( cc==33  )
+                                                                                       {
+                                                                                               cc=0;
+
+                                                                                               byte c = crc8(clean,(idx-32),32);
+                                                                                               
+                                                                                               if( c != clean[idx] )
+                                                                                               {
+                                                                                                       errors += "CRC Error: Bytes "+(idx-32)+" to "+(idx-1)+" have CRC "+c+" but the CRC sent from FinalKey in byte "+idx+" is "+clean[idx]+"\n";
+                                                                                               }
+                                                                                       }
+                                                                                       
+                                                                                       idx++;
+                                                                               } else {
+                                                                                       if( arr[i] == '['  &&arr[i+1] == 'E' &&arr[i+2] == 'N' &&arr[i+3] == 'D' &&arr[i+4] == ']' )
+                                                                                       {
+                                                                                               FileOutputStream fout = new FileOutputStream( file );
+                                                                                               fout.write( clean );
+                                                                                               fout.close();
+                                                                                               
+                                                                                               if( errors.length() == 0 )
+                                                                                               {
+                                                                                                       Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_OKAY, "Done" ,null,'e') );
+                                                                                               } else {
+                                                                                                       Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_ERROR, errors ,null,'e') );
+                                                                                               }
+                                                                                               return;
+                                                                                       } else {
+                                                                                               Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.UNEXPECTED_ACTION_RESULT_ERROR, "Read past the end?" ,null,'e') );
+                                                                                       }
+                                                                               }
+                                                                       }
+                                                                       
+                                                                       
+                                                               }
+                                                               
+                                                               
+                                                               break;
+                                                       } else {
+                                                               Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.PROGRESS_UPDATE, ""+bin.size() ,null,'e') );
+                                                       }
+                                               }
+
+                                       } else {
+                                               timeOut -= 50;
+                                               Thread.sleep(50);
+                                       }
+                               }
+                               Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_ABORTED, "Timed out" ,null,'e') );
+                               
+                               
+                       } catch (Exception e) { 
+                               
+                       }
+               }
+       }
+
+       public void backup(File f, FkActionEventListener delegate) {
+               BackupTask bt = new BackupTask(f, delegate );
+               new Thread(bt).start();
+       }
+       
+       
 
 
 }
index 5f3d3ab..225fc10 100644 (file)
@@ -27,15 +27,21 @@ import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.ControlListener;
 import org.eclipse.swt.events.FocusEvent;
 import org.eclipse.swt.events.FocusListener;
 import org.eclipse.swt.events.KeyEvent;
 import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.events.ShellEvent;
 import org.eclipse.swt.events.ShellListener;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.Device;
 import org.eclipse.swt.widgets.Text;
@@ -55,6 +61,10 @@ import org.eclipse.swt.layout.FormData;
 import org.eclipse.swt.layout.FormAttachment;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.awt.SWT_AWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Group;
 
 public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
 
@@ -64,6 +74,7 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
        public PopupMenu popup;
        public MenuItem showMain;
        public MenuItem hideMain;
+       public MenuItem exitApp;
 
        public Text txtLog;
        public Button btnConnect;
@@ -96,6 +107,7 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
        private static final String PREF_ALLOW_UPDATE_CHECK = "allowUpdateCheck"; //$NON-NLS-1$
        private static final String PREF_SHOW_ACCOUNTS_READY_NOTICE = "showAccountsReadyNotice"; //$NON-NLS-1$
        private static final String PREF_SHOW_SYSTRAY_NAME = "showSystrayName"; //$NON-NLS-1$
+       private static final String PREF_HIDE_ON_CLOSE = "hideToSysTrayOnMainWinClose"; //$NON-NLS-1$
 
        public Composite cmpConnect;
        private Composite cmpAccounts;
@@ -121,6 +133,30 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
        private Button chkShowAccountId;
        private Thread updateCheckThread;
        private Text txtFilter;
+       
+       String systrayTipTxt;
+       private Button btnHideToTrayOnClose;
+       private TabItem tbtmThisFinalkey;
+       private Composite composite;
+       private Text txtBanner; 
+       private Combo cmbLayout;
+       private Group grpBackupAndRestore;
+       private Group group_1;
+       private Label label;
+       private Text text_1;
+       private Text text_2;
+       private Text text_3;
+       private Label label_1;
+       private Label label_2;
+       private Label label_3;
+       private Button button;
+       private Group grpFormat;
+       private Label lblNewLabel;
+       private Button btnNewButton;
+       private Button btnNewButton_1;
+       
+       private Button btnFkSettingsSave;
+       private Label lblMakeSureYou;
 
        
        
@@ -154,9 +190,6 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
        public void open() {
                Display display = Display.getDefault();
                createContents();
-               addAccountsTab();
-               addSettingsTab();
-               createSysTrayIcon();
 
                serialEvent(SerialState.Disconnected);
                
@@ -187,7 +220,7 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                        shell.layout();
                }
 
-               clearSystray();
+               clearSystray(true);
                
                while (!shell.isDisposed()) {
                        if (!display.readAndDispatch()) {
@@ -250,6 +283,7 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                // Create a pop-up menu components
                showMain = new MenuItem(Messages.MainWin_7);
                hideMain = new MenuItem(Messages.MainWin_8);
+               exitApp  = new MenuItem("Quit");
 
                showMain.addActionListener(new ActionListener() {
                        @Override
@@ -278,6 +312,19 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                        }
                });
 
+               exitApp.addActionListener(new ActionListener() {
+                       @Override
+                       public void actionPerformed(ActionEvent e) {
+                               Display.getDefault().asyncExec( new Runnable(){
+
+                                       public void run()
+                                       {
+                                               shutDownApp();
+                                       }
+                               } );
+                       }
+               });             
+               
                trayIcon.setPopupMenu(popup);
 
                try {
@@ -288,7 +335,6 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
 
        }
 
-       String systrayTipTxt;
        private void setSystrayIconTip(String tip) {
                if( tip == null )
                {
@@ -326,7 +372,7 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                SystemTray.getSystemTray().remove(trayIcon);
        }
 
-       private void clearSystray() {
+       private void clearSystray(Boolean addExitBtn) {
                        popup.removeAll();
                        //Add components to pop-up menu
                        if(shell.isVisible()==true)
@@ -336,6 +382,11 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                                popup.add(showMain);
                        }
                        popup.addSeparator();
+
+                       if(addExitBtn)
+                       {
+                               popup.add(exitApp);
+                       }
        }
 
        public void shutDownApp()
@@ -354,6 +405,25 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
        /**
         * Create contents of the window.
         */
+       
+
+       /*uint8_t EncryptedStorage::crc8(const uint8_t *addr, uint8_t len)
+       {
+               uint8_t crc = 0;
+
+               while (len--) {
+                       uint8_t inbyte = *addr++;
+                       for (uint8_t i = 8; i; i--) {
+                               uint8_t mix = (crc ^ inbyte) & 0x01;
+                               crc >>= 1;
+                               if (mix) crc ^= 0x8C;
+                               inbyte >>= 1;
+                       }
+               }
+               return crc;
+       } */
+       
+       
        protected void createContents() {
 
 
@@ -361,7 +431,6 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                shell.setImage( iconProgramOffline ); //$NON-NLS-1$
                shell.setSize(711, 655);
 
-
                prefs = Preferences.userNodeForPackage(this.getClass());
 
                FkManager.getInstance().sortById( prefs.getBoolean(PREF_SORT_BY_ID_KEY, false) );
@@ -472,25 +541,19 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                log(Messages.MainWin_22);
 
 
-               shell.addShellListener( new ShellListener() {
-
-                       public void shellIconified(ShellEvent e) {
-                       }
-
-                       public void shellDeiconified(ShellEvent e) {
-                       }
-
-                       public void shellDeactivated(ShellEvent e) {
-                       }
-
-                       public void shellClosed(ShellEvent e) {
-                               shutDownApp();
-                       }
-
-                       public void shellActivated(ShellEvent e) {
-
+               //
+               shell.addListener(SWT.Close, new Listener() {
+                       @Override
+                       public void handleEvent(Event arg0) {
+                               if( prefs.getBoolean(PREF_HIDE_ON_CLOSE, true))
+                               {
+                                       arg0.doit=false;
+                                       hideToTray();
+                               } else {
+                                       shutDownApp();
+                               }
                        }
-               } );
+               });
 
 
                if( System.getProperty("os.name").compareTo("Linux") == 0 ) //$NON-NLS-1$ //$NON-NLS-2$
@@ -517,6 +580,12 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                greenColor = display.getSystemColor(SWT.COLOR_DARK_GREEN );
                redColor = display.getSystemColor(SWT.COLOR_RED );
 
+               
+               //
+               addSettingsTab();
+               addThisFkTab();
+               addAccountsTab();
+               createSysTrayIcon();
        }
 
 
@@ -531,7 +600,7 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
        public void updateAccountList()
        {
                int free=256;
-               clearSystray();
+               clearSystray(false);
                lstAccounts.getList().removeAll();
 
                Boolean showAccountId = prefs.getBoolean( PREF_SHOW_ACCOUNT_ID_IN_NAME_KEY, false);
@@ -541,6 +610,7 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                        free--;
                        lstAccounts.add( a.showNumInName( showAccountId ) );
 
+                       //populate the popup
                        Menu menu = new Menu(a.toString());
                        MenuItem both = new MenuItem(Messages.MainWin_25);
                        MenuItem usr = new MenuItem(Messages.MainWin_26);
@@ -564,6 +634,10 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
 
                        popup.add(menu);
                }
+               
+               //Add the exit button
+               popup.addSeparator();
+               popup.add(exitApp);
 
                lblNumFree.setText(" "+free+Messages.MainWin_32); //$NON-NLS-1$
                lblNumFree.pack();
@@ -598,9 +672,12 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                                hideToTray();
                        }
 
+                       addThisFkTab();
                        addAccountsTab();
+                       
 
-                       tabFolder.setSelection(1);
+                       
+                       tabFolder.setSelection(tbtmAccounts);
 
                        updateAccountList();
                        txtFilter.setFocus();
@@ -654,6 +731,7 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                        animation.setPlaying(false);
 
                        remAccountsTab();
+                       remThisFkTab();
 
                        tabFolder.setSelection(0);
 
@@ -670,7 +748,7 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
 
                        cmpConnect.update();
 
-                       clearSystray();
+                       clearSystray(true);
 
                        //Update icons for systray and window
                        shell.setImage( iconProgramOffline );
@@ -688,10 +766,315 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                cmpConnect.layout();
        }
 
+       private void updateSettingsSaveBtnVisibility()
+       {
+               boolean show=false;
+               if( btnFkSettingsSave != null)
+               {
+                       if( FkManager.getInstance().getBanner().compareTo( txtBanner.getText() ) != 0 )
+                       {
+                               show=true;
+                       }
+
+                       if( cmbLayout.getSelectionIndex() != -1  && cmbLayout.getItem(cmbLayout.getSelectionIndex()).compareTo(FkManager.getInstance().getCurrentLayout()) != 0 )
+                       {
+                               show=true;
+                       }
+
+                       if(show)
+                       {
+                               btnFkSettingsSave.setEnabled(true);
+                       } else {
+                               btnFkSettingsSave.setEnabled(false);
+                       }
+               }
+       }
+
+       private void addThisFkTab()
+       {
+               tbtmThisFinalkey = new TabItem(tabFolder, SWT.NONE,1);
+               tbtmThisFinalkey.setText(Messages.MainWin_tbtmThisFinalkey_text);
+
+               composite = new Composite(tabFolder, SWT.NONE);
+               tbtmThisFinalkey.setControl(composite);
+               composite.setLayout(new FormLayout());
+
+               Group group = new Group(composite, SWT.NONE);
+               group.setText(Messages.MainWin_group_text);
+               group.setLayout(new FormLayout());
+               FormData fd_group = new FormData();
+               fd_group.bottom = new FormAttachment(0, 100);
+               fd_group.top = new FormAttachment(0, 10);
+               fd_group.left = new FormAttachment(0, 10);
+               fd_group.right = new FormAttachment(100, -10);
+               group.setLayoutData(fd_group);
+
+
+               Label lblBannerName = new Label(group, SWT.NONE);
+               lblBannerName.setAlignment(SWT.RIGHT);
+               FormData fd_lblBannerName = new FormData();
+               fd_lblBannerName.left = new FormAttachment(0, 10);
+               fd_lblBannerName.top = new FormAttachment(0, 10);
+               lblBannerName.setLayoutData(fd_lblBannerName);
+               lblBannerName.setText(Messages.MainWin_lblBannerName_text);
+
+               txtBanner = new Text(group, SWT.BORDER);
+               fd_lblBannerName.right = new FormAttachment(txtBanner, -6);
+               FormData fd_txtBanner = new FormData();
+               fd_txtBanner.right = new FormAttachment(0, 455);
+               fd_txtBanner.top = new FormAttachment(0, 10);
+               fd_txtBanner.left = new FormAttachment(0, 149);
+               txtBanner.setLayoutData(fd_txtBanner);
+               txtBanner.setToolTipText(Messages.MainWin_text_1_toolTipText);
+               txtBanner.setText(Messages.MainWin_text_1_text_1);
+               txtBanner.addVerifyListener(new VerifyListener() {
+                       @Override
+                       public void verifyText(VerifyEvent arg0) {
+                               System.out.println("Verify:"+arg0.text );
+                               arg0.doit=false;
+                               if(arg0.text.length()==0)
+                               {
+                                       arg0.doit=true;
+                               } else if( FkManager.getInstance().isStringValidForFk(arg0.text))
+                               {
+                                       if(txtBanner.getText().length()+arg0.text.length() < 32) //Banner can be a max of 31 chars long.
+                                       {
+                                               arg0.doit=true;
+                                       }
+                               }
+                       }
+               });
+               txtBanner.addModifyListener( new ModifyListener() {
+                       @Override
+                       public void modifyText(ModifyEvent arg0) {
+                               updateSettingsSaveBtnVisibility();
+                       }
+               });
+
+               //Populate with data from FkManager
+               txtBanner.setText( FkManager.getInstance().getBanner() );
+
+               Label lblKeyboardLayout = new Label(group, SWT.NONE);
+               lblKeyboardLayout.setAlignment(SWT.RIGHT);
+               FormData fd_lblKeyboardLayout = new FormData();
+               fd_lblKeyboardLayout.left = new FormAttachment(0, 10);
+               fd_lblKeyboardLayout.bottom = new FormAttachment(100, -13);
+               lblKeyboardLayout.setLayoutData(fd_lblKeyboardLayout);
+               lblKeyboardLayout.setText(Messages.MainWin_lblKeyboardLayout_text);
+
+               cmbLayout = new Combo(group, SWT.READ_ONLY);
+               fd_lblKeyboardLayout.right = new FormAttachment(cmbLayout, -6);
+               FormData fd_cmbLayout = new FormData();
+               fd_cmbLayout.bottom = new FormAttachment(100, -11);
+               fd_cmbLayout.top = new FormAttachment(txtBanner, 6);
+               fd_cmbLayout.right = new FormAttachment(0, 301);
+               fd_cmbLayout.left = new FormAttachment(0, 149);
+               cmbLayout.setLayoutData(fd_cmbLayout);
+               cmbLayout.setItems( FkManager.getInstance().getAvailableLayouts() );
+               cmbLayout.addSelectionListener( new SelectionListener() {
+                       
+                       @Override
+                       public void widgetSelected(SelectionEvent arg0) {
+                               updateSettingsSaveBtnVisibility();
+                       }
+
+                       @Override
+                       public void widgetDefaultSelected(SelectionEvent arg0) {} 
+               });
+
+               cmbLayout.select( cmbLayout.indexOf(FkManager.getInstance().getCurrentLayout() ));
+
+               grpBackupAndRestore = new Group(composite, SWT.NONE);
+               grpBackupAndRestore.setText(Messages.MainWin_grpBackupAndRestore_text);
+               grpBackupAndRestore.setLayout(new FormLayout());
+               FormData fd_grpBackupAndRestore = new FormData();
+               fd_grpBackupAndRestore.top = new FormAttachment(group, 6);
+               fd_grpBackupAndRestore.left = new FormAttachment(0, 10);
+               fd_grpBackupAndRestore.bottom = new FormAttachment(0, 243);
+               fd_grpBackupAndRestore.right = new FormAttachment(100, -10);
+
+               btnFkSettingsSave = new Button(group, SWT.NONE);
+               btnFkSettingsSave.addSelectionListener(new SelectionAdapter() {
+                       @Override
+                       public void widgetSelected(SelectionEvent e) {
+                               SaveSettingsDialog dialog = new SaveSettingsDialog(shell, shell.getStyle() );
+                               shell.setEnabled(false);
+                               
+                               if( (FkManager.getInstance().getBanner().compareTo( txtBanner.getText() ) != 0) )
+                               {
+                                       dialog.bannerTxt = txtBanner.getText();
+                               }
+                               
+                               if( (cmbLayout.getSelectionIndex() != -1  && cmbLayout.getItem(cmbLayout.getSelectionIndex()).compareTo(FkManager.getInstance().getCurrentLayout()) != 0) )
+                               {
+                                       dialog.Layout = cmbLayout.getSelectionIndex()+1; //FinalKey presents the layout choice between 1,2,3
+                               }
+                               
+                               dialog.open();
+                               shell.setEnabled(true);
+                               updateSettingsSaveBtnVisibility();
+                               
+                       }
+               });
+               FormData fd_btnSave = new FormData();
+               fd_btnSave.right = new FormAttachment(txtBanner, 68, SWT.RIGHT);
+               fd_btnSave.top = new FormAttachment(lblBannerName, 0, SWT.TOP);
+               fd_btnSave.left = new FormAttachment(txtBanner, 6);
+               btnFkSettingsSave.setLayoutData(fd_btnSave);
+               btnFkSettingsSave.setText(Messages.MainWin_btnSave_text);
+               grpBackupAndRestore.setLayoutData(fd_grpBackupAndRestore);
+               btnFkSettingsSave.setEnabled(false);
+
+               group_1 = new Group(composite, SWT.NONE);
+               group_1.setText("Security");
+               group_1.setLayout(new FormLayout());
+               FormData fd_group_1 = new FormData();
+               fd_group_1.bottom = new FormAttachment(grpBackupAndRestore, 197, SWT.BOTTOM);
+               fd_group_1.top = new FormAttachment(grpBackupAndRestore, 6);
+
+               Button btnBackup = new Button(grpBackupAndRestore, SWT.CENTER);
+               btnBackup.setImage(SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/backup.png"));
+               FormData fd_btnBackup = new FormData();
+               fd_btnBackup.left = new FormAttachment(0, 10);
+               fd_btnBackup.top = new FormAttachment(0, 10);
+               fd_btnBackup.bottom = new FormAttachment(100, -28);
+               btnBackup.setLayoutData(fd_btnBackup);
+               btnBackup.setText(Messages.MainWin_btnBackupYourFinalkey_text);
+               btnBackup.addSelectionListener(new SelectionAdapter() {
+                       @Override
+                       public void widgetSelected(SelectionEvent e) {
+                               shell.setEnabled(false);;
+                               Backup b = new Backup(shell, shell.getStyle() );
+                               b.open(false);
+                               shell.setEnabled(true);
+                       }
+               });
+
+               btnNewButton = new Button(grpBackupAndRestore, SWT.NONE);
+               btnNewButton.setImage(SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/restore.png"));
+               FormData fd_btnNewButton = new FormData();
+               fd_btnNewButton.top = new FormAttachment(0, 10);
+               fd_btnNewButton.right = new FormAttachment(100, -10);
+               fd_btnNewButton.bottom = new FormAttachment(100, -28);
+               btnNewButton.setLayoutData(fd_btnNewButton);
+               btnNewButton.setText(Messages.MainWin_btnNewButton_text);
+               btnNewButton.addSelectionListener(new SelectionAdapter() {
+                       @Override
+                       public void widgetSelected(SelectionEvent e) {
+                               shell.setEnabled(false);;
+                               Backup b = new Backup(shell, shell.getStyle() );
+                               b.open(true);
+                               shell.setEnabled(true);
+                       }
+               });
+               
+               lblMakeSureYou = new Label(grpBackupAndRestore, SWT.NONE);
+               fd_btnNewButton.left = new FormAttachment(lblMakeSureYou, 6);
+               fd_btnBackup.right = new FormAttachment(100, -555);
+               FormData fd_lblMakeSureYou = new FormData();
+               fd_lblMakeSureYou.top = new FormAttachment(0, 10);
+               fd_lblMakeSureYou.left = new FormAttachment(btnBackup, 6);
+               fd_lblMakeSureYou.right = new FormAttachment(0, 541);
+               fd_lblMakeSureYou.bottom = new FormAttachment(0, 92);
+               lblMakeSureYou.setLayoutData(fd_lblMakeSureYou);
+               lblMakeSureYou.setText(Messages.MainWin_lblMakeSureYou_text);
+               fd_group_1.right = new FormAttachment(group, 0, SWT.RIGHT);
+               fd_group_1.left = new FormAttachment(0, 10);
+               group_1.setLayoutData(fd_group_1);
+
+               label = new Label(group_1, SWT.NONE);
+               label.setText("Always use a secure master-password, but don't forget it, you can not unlock\nyour FinalKey without it! Changing the password is risky, it can result in data-loss\nif the process is interrupted, you should take a backup before changing your\nmaster-password. Changing master-password takes a while as it re-encrypts accounts.");
+               FormData fd_label = new FormData();
+               fd_label.bottom = new FormAttachment(0, 79);
+               fd_label.top = new FormAttachment(0, 10);
+               fd_label.right = new FormAttachment(0, 675);
+               fd_label.left = new FormAttachment(0, 10);
+               label.setLayoutData(fd_label);
+
+               text_1 = new Text(group_1, SWT.BORDER | SWT.PASSWORD);
+               FormData fd_text_1 = new FormData();
+               fd_text_1.top = new FormAttachment(label, 6);
+               fd_text_1.right = new FormAttachment(0, 455);
+               fd_text_1.left = new FormAttachment(0, 149);
+               text_1.setLayoutData(fd_text_1);
+
+               text_2 = new Text(group_1, SWT.BORDER | SWT.PASSWORD);
+               FormData fd_text_2 = new FormData();
+               fd_text_2.top = new FormAttachment(text_1, 6);
+               fd_text_2.right = new FormAttachment(0, 455);
+               fd_text_2.left = new FormAttachment(0, 149);
+               text_2.setLayoutData(fd_text_2);
+
+               text_3 = new Text(group_1, SWT.BORDER | SWT.PASSWORD);
+               FormData fd_text_3 = new FormData();
+               fd_text_3.top = new FormAttachment(text_2, 6);
+               fd_text_3.right = new FormAttachment(text_1, 0, SWT.RIGHT);
+               fd_text_3.left = new FormAttachment(0, 149);
+               text_3.setLayoutData(fd_text_3);
+
+               label_1 = new Label(group_1, SWT.NONE);
+               label_1.setText("Current Pass");
+               label_1.setAlignment(SWT.RIGHT);
+               FormData fd_label_1 = new FormData();
+               fd_label_1.top = new FormAttachment(label, 12);
+               fd_label_1.right = new FormAttachment(text_1, -6);
+               fd_label_1.left = new FormAttachment(label, 0, SWT.LEFT);
+               label_1.setLayoutData(fd_label_1);
+
+               label_2 = new Label(group_1, SWT.NONE);
+               label_2.setText("New Pass");
+               label_2.setAlignment(SWT.RIGHT);
+               FormData fd_label_2 = new FormData();
+               fd_label_2.top = new FormAttachment(label_1, 12);
+               fd_label_2.right = new FormAttachment(text_2, -6);
+               fd_label_2.left = new FormAttachment(label, 0, SWT.LEFT);
+               label_2.setLayoutData(fd_label_2);
+
+               label_3 = new Label(group_1, SWT.NONE);
+               label_3.setText("Repeat");
+               label_3.setAlignment(SWT.RIGHT);
+               FormData fd_label_3 = new FormData();
+               fd_label_3.top = new FormAttachment(label_2, 12);
+               fd_label_3.right = new FormAttachment(text_3, -6);
+               fd_label_3.left = new FormAttachment(text_3, -139, SWT.LEFT);
+               label_3.setLayoutData(fd_label_3);
+
+               button = new Button(group_1, SWT.NONE);
+               button.setText("Re-encrypt");
+               FormData fd_button = new FormData();
+               fd_button.bottom = new FormAttachment(text_3, 0, SWT.BOTTOM);
+               fd_button.left = new FormAttachment(text_3, 6);
+               button.setLayoutData(fd_button);
+
+               grpFormat = new Group(composite, SWT.NONE);
+               grpFormat.setText(Messages.MainWin_grpFormat_text);
+               FormData fd_grpFormat = new FormData();
+               fd_grpFormat.bottom = new FormAttachment(group_1, 69, SWT.BOTTOM);
+               fd_grpFormat.top = new FormAttachment(group_1, 6);
+               fd_grpFormat.right = new FormAttachment(group, 0, SWT.RIGHT);
+               fd_grpFormat.left = new FormAttachment(group, 0, SWT.LEFT);
+               grpFormat.setLayoutData(fd_grpFormat);
+
+               lblNewLabel = new Label(grpFormat, SWT.NONE);
+               lblNewLabel.setBounds(10, 0, 366, 40);
+               lblNewLabel.setText(Messages.MainWin_lblNewLabel_text_1);
+
+               btnNewButton_1 = new Button(grpFormat, SWT.NONE);
+               btnNewButton_1.setBounds(382, 10, 91, 26);
+               btnNewButton_1.setText(Messages.MainWin_btnNewButton_1_text);
+
+       }
+       private void remThisFkTab() {
+               if(tbtmThisFinalkey != null)
+               {
+                       tbtmThisFinalkey.dispose();
+               }
+       }
+
        private void remAccountsTab() {
-               if( tabFolder.getItemCount() > 2 )
+               if( tbtmAccounts != null )
                {
-                       tabFolder.getItem(1).dispose();
+                       tbtmAccounts.dispose();
                }
 
        }
@@ -984,11 +1367,13 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                });
 
                chkSortByAccountId = new Button(cmpSettings, SWT.CHECK);
+               fd_chkAutoHide.right = new FormAttachment(chkSortByAccountId, 0, SWT.RIGHT);
                chkSortByAccountId.setText(Messages.MainWin_9);
                chkSortByAccountId.setSelection( prefs.getBoolean( PREF_SORT_BY_ID_KEY, false) );
                FormData fd_btnSortByAccountId = new FormData();
                fd_btnSortByAccountId.top = new FormAttachment(chkAutoHide, 6);
-               fd_btnSortByAccountId.left = new FormAttachment(chkAutoHide, 0, SWT.LEFT);
+               fd_btnSortByAccountId.left = new FormAttachment(0, 10);
+               fd_btnSortByAccountId.right = new FormAttachment(100, -10);
                chkSortByAccountId.setLayoutData(fd_btnSortByAccountId);
                chkSortByAccountId.addSelectionListener( new SelectionAdapter() {
                        public void widgetSelected(SelectionEvent e) {
@@ -1000,8 +1385,9 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
 
                chkShowAccountId = new Button(cmpSettings, SWT.CHECK);
                FormData fd_chkShowAccountId = new FormData();
+               fd_chkShowAccountId.left = new FormAttachment(0, 10);
+               fd_chkShowAccountId.right = new FormAttachment(100, -10);
                fd_chkShowAccountId.top = new FormAttachment(chkSortByAccountId, 6);
-               fd_chkShowAccountId.left = new FormAttachment(chkAutoHide, 0, SWT.LEFT);
                chkShowAccountId.setLayoutData(fd_chkShowAccountId);
                chkShowAccountId.setText(Messages.MainWin_btnShowAccountId_text);
                chkShowAccountId.setSelection( prefs.getBoolean(PREF_SHOW_ACCOUNT_ID_IN_NAME_KEY, false) );
@@ -1014,7 +1400,9 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
 
                chkCheckForUpdates = new Button(cmpSettings, SWT.CHECK);
                FormData fd_chkCheckForUpdates = new FormData();
-               fd_chkCheckForUpdates.left = new FormAttachment(chkAutoHide, 0, SWT.LEFT);
+               fd_chkCheckForUpdates.left = new FormAttachment(0, 10);
+               fd_chkCheckForUpdates.right = new FormAttachment(100, -10);
+               fd_chkCheckForUpdates.top = new FormAttachment(chkShowAccountId, 6);
                chkCheckForUpdates.setLayoutData(fd_chkCheckForUpdates);
                chkCheckForUpdates.setText(Messages.MainWin_btnCheckForUpdates_text);
                chkCheckForUpdates.setSelection( prefs.getBoolean( PREF_ALLOW_UPDATE_CHECK, true) );
@@ -1024,13 +1412,13 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                                checkForUpdates();
                        }
                });
-               fd_chkCheckForUpdates.top = new FormAttachment(chkShowAccountId, 6);
 
                btnShowaccountsReady = new Button(cmpSettings, SWT.CHECK);
                btnShowaccountsReady.setSelection( prefs.getBoolean( PREF_SHOW_ACCOUNTS_READY_NOTICE, true) );
                FormData fd_btnShowaccountsReady = new FormData();
+               fd_btnShowaccountsReady.left = new FormAttachment(0, 10);
+               fd_btnShowaccountsReady.right = new FormAttachment(100, -10);
                fd_btnShowaccountsReady.top = new FormAttachment(chkCheckForUpdates, 6);
-               fd_btnShowaccountsReady.left = new FormAttachment(chkAutoHide, 0, SWT.LEFT);
                btnShowaccountsReady.setLayoutData(fd_btnShowaccountsReady);
 
                btnShowaccountsReady.setText(Messages.MainWin_btnShowaccountsReady_text);
@@ -1043,17 +1431,35 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                Button btnShowSystrayName = new Button( cmpSettings, SWT.CHECK );
                btnShowSystrayName.setSelection( prefs.getBoolean( PREF_SHOW_SYSTRAY_NAME,  true) );
                FormData fd_btnShowSystrayName = new FormData();
-               fd_btnShowSystrayName.top = new FormAttachment( btnShowaccountsReady, 6 );
-               fd_btnShowSystrayName.left = new FormAttachment( chkAutoHide, 0, SWT.LEFT );
+               fd_btnShowSystrayName.left = new FormAttachment(0, 10);
+               fd_btnShowSystrayName.right = new FormAttachment(100, -10);
+               fd_btnShowSystrayName.top = new FormAttachment(btnShowaccountsReady, 6);
                btnShowSystrayName.setLayoutData(fd_btnShowSystrayName);
                btnShowSystrayName.setText( Messages.MainWin_14 );
                btnShowSystrayName.addSelectionListener( new SelectionAdapter() {
-                               public void widgetSelected(SelectionEvent e) {
-                                       Button b = (Button)e.widget;
-                                       prefs.putBoolean( PREF_SHOW_SYSTRAY_NAME, b.getSelection() );
-                                       setSystrayIconTip(null);
-                               }
+                       public void widgetSelected(SelectionEvent e) {
+                               Button b = (Button)e.widget;
+                               prefs.putBoolean( PREF_SHOW_SYSTRAY_NAME, b.getSelection() );
+                               setSystrayIconTip(null);
+                       }
+               });
+
+               btnHideToTrayOnClose = new Button(cmpSettings, SWT.CHECK);
+               btnHideToTrayOnClose.setSelection( prefs.getBoolean( PREF_HIDE_ON_CLOSE, true) );
+               btnHideToTrayOnClose.addSelectionListener(new SelectionAdapter() {
+                       @Override
+                       public void widgetSelected(SelectionEvent e) {
+                               prefs.putBoolean( PREF_HIDE_ON_CLOSE, btnHideToTrayOnClose.getSelection() );
+                       }
                });
+               btnHideToTrayOnClose.setToolTipText(Messages.MainWin_btnHideToTrayOnClose_toolTipText);
+               FormData fd_btnHideToTrayOnClose = new FormData();
+               fd_btnHideToTrayOnClose.top = new FormAttachment(btnShowSystrayName, 6);
+               fd_btnHideToTrayOnClose.right = new FormAttachment(0, 695);
+               fd_btnHideToTrayOnClose.left = new FormAttachment(0, 10);
+               btnHideToTrayOnClose.setLayoutData(fd_btnHideToTrayOnClose);
+               btnHideToTrayOnClose.setText(Messages.MainWin_btnCheckButton_text);
+
        }
 
        private void showTrigDialog(Account acc) {
index 938a6c0..70f075f 100644 (file)
@@ -179,6 +179,38 @@ public class Messages extends NLS {
        public static String MainWin_btnShowaccountsReady_text;
        public static String NewAccountDialog_btnNoSpecialSymbols_text;
        public static String NewAccountDialog_51;
+       public static String MainWin_btnF_text;
+       public static String MainWin_btnCheckButton_text;
+       public static String MainWin_btnHideToTrayOnClose_toolTipText;
+       public static String MainWin_tbtmThisFinalkey_text;
+       public static String MainWin_text_1_text;
+       public static String MainWin_lblF_text;
+       public static String MainWin_text_1_text_1;
+       public static String MainWin_text_1_toolTipText;
+       public static String MainWin_lblBannerName_text;
+       public static String MainWin_btnSaveBanner_text;
+       public static String MainWin_lblKeyb_text;
+       public static String MainWin_lblKeyboardLayout_text;
+       public static String MainWin_group_text;
+       public static String MainWin_group_1_text;
+       public static String MainWin_grpBackupAndRestore_text;
+       public static String MainWin_btnSave_text;
+       public static String MainWin_lblNewLabel_text;
+       public static String MainWin_text_1_text_2;
+       public static String MainWin_lblNewLabel_1_text;
+       public static String MainWin_lblNewPsw1_text;
+       public static String MainWin_lblRepeat_text;
+       public static String MainWin_btnChange_text;
+       public static String MainWin_grpFormat_text;
+       public static String MainWin_lblNewLabel_text_1;
+       public static String MainWin_lblY_text;
+       public static String MainWin_btnBackupYourFinalkey_text;
+       public static String MainWin_btnNewButton_text;
+       public static String MainWin_lblNewLabel_1_text_1;
+       public static String MainWin_btnFormatMyFinalkey_text;
+       public static String MainWin_btnNewButton_1_text;
+       public static String MainWin_lblMakeSureYou_text;
+       public static String MainWin_lblYouHaveNever_text;
 
        static {
                // initialize resource bundle
index 2c66e59..08a68a1 100644 (file)
@@ -72,8 +72,6 @@ public class NewAccountDialog extends Dialog implements FkActionEventListener {
        
        NewAccountDialog mySelf;
 
-       
-       
        Composite composite;
        /**
         * Create the dialog.
diff --git a/src/fkgui/SaveSettingsDialog.java b/src/fkgui/SaveSettingsDialog.java
new file mode 100644 (file)
index 0000000..0d12bc3
--- /dev/null
@@ -0,0 +1,330 @@
+package fkgui;
+
+import org.eclipse.swt.widgets.Dialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Text;
+
+public class SaveSettingsDialog extends Dialog implements FkActionEventListener {
+
+       protected Object result;
+       protected Shell shell;
+
+       public String bannerTxt = null;
+       public int Layout = 0;
+       private Composite cmpSetBanner;
+       public Animation animation;
+       private SaveSettingsDialog mySelf;
+       private Label lblK;
+       private Text txtTest;
+       private Label lblL;
+       
+       /**
+        * Create the dialog.
+        * @param parent
+        * @param style
+        */
+       public SaveSettingsDialog(Shell parent, int style) {
+               super(parent, style);
+       }
+
+       /**
+        * Open the dialog.
+        * @return the result
+        */
+       
+       
+       public Object open() {
+
+               createContents();
+               shell.open();
+               shell.layout();
+               Display display = getParent().getDisplay();
+
+               while (!shell.isDisposed()) {
+                       if (!display.readAndDispatch()) {
+                               display.sleep();
+                       }
+               }
+               return result;
+       }
+
+       /**
+        * Create contents of the dialog.
+        */
+       private void createContents() {
+               shell = new Shell(getParent(), getStyle());
+               shell.setSize(638, 216);
+               shell.setText(getText());
+               shell.setLayout(new FormLayout());
+
+               mySelf = this;
+//             createSetLayout();
+//             createSetBanner();
+               if( bannerTxt != null )
+               {
+                       createSetBanner();
+               } else {
+                       createSetLayout();
+               }
+       
+               
+       }
+
+       private void createSetLayout() {
+               if(bannerTxt == null)
+               {
+                       setText("Save Settings, Save the keyboard layout");
+               } else {
+                       setText("Save Settings, step 2/2: Save the keyboard layout");
+               }
+
+               Composite cmpSetLayout = new Composite(shell, SWT.NONE);
+               cmpSetLayout.setLayout(new FormLayout());
+               FormData fd_cmpSetLayout = new FormData();
+               fd_cmpSetLayout.bottom = new FormAttachment(0, 181);
+               fd_cmpSetLayout.right = new FormAttachment(0, 626);
+               fd_cmpSetLayout.top = new FormAttachment(0, 10);
+               fd_cmpSetLayout.left = new FormAttachment(0, 10);
+               cmpSetLayout.setLayoutData(fd_cmpSetLayout);
+               
+               lblL = new Label(cmpSetLayout, SWT.NONE);
+               FormData fd_lblL = new FormData();
+               fd_lblL.bottom = new FormAttachment(0, 90);
+               fd_lblL.right = new FormAttachment(0, 544);
+               fd_lblL.top = new FormAttachment(0, 10);
+               fd_lblL.left = new FormAttachment(0, 10);
+               lblL.setLayoutData(fd_lblL);
+               lblL.setText("Ready to set the keyboard layout.\nWhen you press GO, The FinalKey will start blinking.\nPress the button on the FinalKey to proceed.");
+
+               Button btnSaveLayout = new Button(cmpSetLayout, SWT.NONE);
+               FormData fd_btnSaveLayout = new FormData();
+               fd_btnSaveLayout.right = new FormAttachment(0, 606);
+               fd_btnSaveLayout.top = new FormAttachment(0, 135);
+               fd_btnSaveLayout.left = new FormAttachment(0, 515);
+               btnSaveLayout.setLayoutData(fd_btnSaveLayout);
+               btnSaveLayout.setText("GO");
+               btnSaveLayout.addSelectionListener( new SelectionAdapter() {
+                       public void widgetSelected(SelectionEvent e) {
+                               lblL.setText("Press the button now.");
+                               animation.setVisible(true);
+                               animation.setPlaying(true);
+                               Button btn = (Button)e.widget;
+                               btn.setVisible(false);
+                               txtTest.setEnabled(true);
+                               txtTest.forceFocus();
+                               FkManager.getInstance().saveLayout( Layout, mySelf );
+                       }
+               });
+               
+               
+               animation = new Animation(cmpSetLayout, SWT.NONE, 4);
+               FormData fd_animation = new FormData();
+               fd_animation.top = new FormAttachment(0, 26);
+               fd_animation.right = new FormAttachment(btnSaveLayout, -16, SWT.RIGHT);
+               animation.setLayoutData(fd_animation);
+
+
+               animation.setVisible(false);
+               animation.setPlaying(false);
+               
+               Label lblTest = new Label(cmpSetLayout, SWT.NONE);
+               FormData fd_lblTest = new FormData();
+               fd_lblTest.bottom = new FormAttachment(lblL, 32, SWT.BOTTOM);
+               fd_lblTest.top = new FormAttachment(lblL, 6);
+               fd_lblTest.left = new FormAttachment(0, 10);
+               fd_lblTest.right = new FormAttachment(0, 52);
+               lblTest.setLayoutData(fd_lblTest);
+               lblTest.setText("Test:");
+               
+               txtTest = new Text(cmpSetLayout, SWT.BORDER);
+               FormData fd_txtTest = new FormData();
+               fd_txtTest.right = new FormAttachment(lblTest, 312, SWT.RIGHT);
+               fd_txtTest.top = new FormAttachment(lblL, 6);
+               fd_txtTest.left = new FormAttachment(lblTest, 6);
+               txtTest.setLayoutData(fd_txtTest);
+               txtTest.setEnabled(false);
+               
+       }
+
+       private void createSetBanner() {
+               
+               if(Layout == 0)
+               {
+                       setText("Save Settings, Save the banner text");
+               } else {
+                       setText("Save Settings, step 1/2: Save the banner text");
+               }
+               
+               cmpSetBanner = new Composite(shell, SWT.NONE);
+               FormData fd_cmpSetBanner = new FormData();
+               fd_cmpSetBanner.bottom = new FormAttachment(0, 181);
+               fd_cmpSetBanner.right = new FormAttachment(0, 626);
+               fd_cmpSetBanner.top = new FormAttachment(0, 10);
+               fd_cmpSetBanner.left = new FormAttachment(0, 10);
+               cmpSetBanner.setLayoutData(fd_cmpSetBanner);
+               cmpSetBanner.setLayout(new FormLayout());
+               
+               lblK = new Label(cmpSetBanner, SWT.NONE);
+               FormData fd_lblK = new FormData();
+               fd_lblK.right = new FormAttachment(0, 564);
+               fd_lblK.top = new FormAttachment(0, 10);
+               fd_lblK.left = new FormAttachment(0, 10);
+               lblK.setLayoutData(fd_lblK);
+               lblK.setText("Ready to set the banner text.\nWhen you press GO, The FinalKey will start blinking, and you have 5 seconds\nto press the button on your FinalKey to confirm saving the new banner.\n");
+               
+               
+               animation = new Animation(cmpSetBanner, SWT.NONE, 4);
+
+
+               FormData fd_animation = new FormData();
+               fd_animation.top = new FormAttachment(0, 16);
+
+               animation.setLayoutData(fd_animation);
+
+               animation.setVisible(false);
+               animation.setPlaying(false);
+               
+               Button btnGoSaveBanner = new Button(cmpSetBanner, SWT.NONE);
+               fd_animation.right = new FormAttachment(btnGoSaveBanner, -16, SWT.RIGHT);
+               FormData fd_btnGoSaveBanner = new FormData();
+               fd_btnGoSaveBanner.top = new FormAttachment(100, -56);
+               fd_btnGoSaveBanner.bottom = new FormAttachment(100, -10);
+               fd_btnGoSaveBanner.right = new FormAttachment(100, -10);
+               fd_btnGoSaveBanner.left = new FormAttachment(100, -117);
+               btnGoSaveBanner.setLayoutData(fd_btnGoSaveBanner);
+               btnGoSaveBanner.setText("GO");
+               
+               btnGoSaveBanner.forceFocus();
+               btnGoSaveBanner.addSelectionListener( new SelectionAdapter() {
+                       public void widgetSelected(SelectionEvent e) {
+                               lblK.setText("Press the button now.");
+                               animation.setVisible(true);
+                               animation.setPlaying(true);
+                               Button btn = (Button)e.widget;
+                               btn.setVisible(false);
+                               FkManager.getInstance().saveBanner( bannerTxt, mySelf );
+                       }
+               });
+       }
+
+       @Override
+       public void fkActionEvent(FkActionEvent event) {
+               MessageBox m;
+               
+               if( event.type == FkActionEventType.ACTION_WORKING )
+               {
+                       if( animation.isVisible() )
+                       {
+                               animation.setPlaying(false);
+                               animation.setVisible(false);
+                       }
+               }
+               
+               if( event.action == 'b' )
+               {
+                       System.out.println("Event (B):" + event.toString() );
+                       
+                       if( event.type == FkActionEventType.ACTION_OKAY )
+                       {
+                               FkManager.getInstance().setBanner(bannerTxt);
+                               m = new MessageBox(shell, SWT.ICON_INFORMATION);
+                               m.setText("Saved");
+                               m.setMessage("Banner is set to "+bannerTxt);
+                               m.open();
+                               
+                               if(Layout!=0)
+                               {
+                                       cmpSetBanner.dispose();
+                                       createSetLayout();
+                                       shell.layout();
+                               } else {
+                                       shell.close();
+                               }
+                       }
+
+                       if( event.type == FkActionEventType.ACTION_ABORTED )
+                       {
+                               m = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO );
+                               m.setText("Set banner was aborted");
+                               m.setMessage("The banner was not saved. You did not press the button in time, or you held it down to cancel saving the banner. Do you want to try again ?");
+
+                               cmpSetBanner.dispose();
+                               if( m.open() == SWT.YES  )
+                               {
+                                       createSetBanner();
+                                       shell.layout();
+                               } else if( Layout != 0 ) {
+                                       m = new MessageBox(shell, SWT.ICON_QUESTION | SWT.YES | SWT.NO );
+                                       m.setText("Continue saving layout");
+                                       m.setMessage("You said no to save the banner, but you also wanted to change the keyboard layout. Do you want save the keyboard layout ?");
+                                       if( m.open() == SWT.YES )
+                                       {
+                                               createSetLayout();
+                                               shell.layout();
+                                       } else {
+                                               shell.close();
+                                       }
+                               }
+
+                       }
+               }
+
+               if( event.action == 'k')
+               {
+                       System.out.println("Event (k):" + event.toString() );
+                       if( event.type == FkActionEventType.ACTION_OKAY )
+                       {
+                               if( txtTest.getText().compareTo( "Supported specials:!\"#$%&@?()[]-.,+{}_/<>=|'\\;: *" ) == 0 )
+                               {
+                                       m = new MessageBox(shell, SWT.ICON_INFORMATION );
+                                       m.setText("Saved");
+                                       m.setMessage("Layout verified.");
+                               } else {
+                                       m = new MessageBox(shell, SWT.ICON_INFORMATION );
+                                       m.setText("Saved");
+                                       m.setMessage("The layout was saved, but it did not look right, maybe the FinalKey application runs with a different input-language setting than the application you want to use, but if your FinalKey is writing the wrong letters then try another layout.");
+                               }
+                               FkManager.getInstance().setCurrentLayout( FkManager.getInstance().getAvailableLayouts()[Layout-1] );
+                               m.open();
+
+                               shell.close();
+                       }
+
+               }
+
+               if( event.type == FkActionEventType.ACTION_ERROR  )
+               {
+                       m = new MessageBox(shell, SWT.ICON_ERROR );
+                       m.setText("Error - All changes may not have been saved");
+                       m.setMessage( "Something went wrong, here is the output: "+event.data);
+                       m.open();
+                       shell.close();
+                       
+               }
+               
+               if( event.type == FkActionEventType.STATE_ERROR )
+               {
+                       m = new MessageBox(shell, SWT.ICON_ERROR );
+                       m.setText("State Error - All changes may not have been saved");
+                       m.setMessage( "Something went wrong, here is the output: "+event.data);
+                       m.open();
+                       shell.close();
+               }
+                       
+
+               
+       }
+}
index 1675503..b7903e5 100644 (file)
@@ -146,7 +146,7 @@ public class SerialWorker extends javax.swing.SwingWorker<Void, String> implemen
                                {
                                        banner = res.substring( res.indexOf('{')+1, res.lastIndexOf('}'));
                                        publish(Messages.SerialWorker_17 );
-                                       FkManager.getInstance().setCurrentBanner( banner );
+                                       FkManager.getInstance().setBanner( banner );
                                        publish(banner);
                                }
                                publish(""); //$NON-NLS-1$
diff --git a/src/fkgui/gfx/backup.png b/src/fkgui/gfx/backup.png
new file mode 100644 (file)
index 0000000..33a8b94
Binary files /dev/null and b/src/fkgui/gfx/backup.png differ
diff --git a/src/fkgui/gfx/restore.png b/src/fkgui/gfx/restore.png
new file mode 100644 (file)
index 0000000..be39711
Binary files /dev/null and b/src/fkgui/gfx/restore.png differ
index 245f654..c5a0326 100644 (file)
@@ -1,5 +1,5 @@
 #Eclipse modern messages class
-#Thu Sep 18 13:35:00 EEST 2014
+#Wed Mar 25 04:44:26 EET 2015
 MainWin_0=Already checking for updates...
 MainWin_1=accounts ready.
 MainWin_10=Search... (Ctrl+f)
@@ -36,10 +36,41 @@ MainWin_6=Hide after connection
 MainWin_7=Show FinalKey
 MainWin_8=Hide FinalKey
 MainWin_9=Sort by account id
+MainWin_btnBackupYourFinalkey_text=Backup
+MainWin_btnChange_text=Re-encrypt
+MainWin_btnCheckButton_text=Hide to System Tray instead of closing
 MainWin_btnCheckForUpdates_text=Check for updates on start
+MainWin_btnF_text=F
+MainWin_btnFormatMyFinalkey_text=Format my FinalKey
+MainWin_btnHideToTrayOnClose_toolTipText=Instead of closing the application completely when the close button is pressed, close only the main window and keep running in the System Tray icon.
+MainWin_btnNewButton_1_text=Format
+MainWin_btnNewButton_text=Restore
+MainWin_btnSaveBanner_text=Save
+MainWin_btnSave_text=Save
 MainWin_btnShowAccountId_text=Show account id
 MainWin_btnShowaccountsReady_text=Show "Accounts Ready" status popup after connection
+MainWin_group_1_text=Security
+MainWin_group_text=General settings
+MainWin_grpBackupAndRestore_text=Backup and Restore
+MainWin_grpFormat_text=Format
+MainWin_lblBannerName_text=Banner Name
+MainWin_lblF_text=Banner Text
+MainWin_lblKeyb_text=Keyb
+MainWin_lblKeyboardLayout_text=Keyboard Layout
+MainWin_lblMakeSureYou_text=Make sure you have a backup of your FinalKey so you\ndon't lose everything if it breaks or is lost.\nAlways keep backup-files in a safe place\!\nBackup-files should not be stored on your computer
+MainWin_lblNewLabel_1_text=Current Pass
+MainWin_lblNewLabel_1_text_1=It's nice to have a backup so you don't lose everything\nif your Finalkey is lost or breaks.\n\nAlways keep your backups in a safe place.
+MainWin_lblNewLabel_text=Always use a secure master-password, but don't forget it, you can not unlock\nyour FinalKey without it\! Changing the password is risky, it can result in data-loss\nif the process is interrupted, you should take a backup before changing your\nmaster-password. Changing master-password takes a while as it re-encrypts accounts.
+MainWin_lblNewLabel_text_1=Delete everything and set a new password.\nThis makes all previous data unrecoverable.
+MainWin_lblNewPsw1_text=New Pass
+MainWin_lblRepeat_text=Repeat
+MainWin_lblY_text=Y
+MainWin_lblYouHaveNever_text=You have never taken a backup of your FinalKey.
 MainWin_tbtmSettings_text=Settings
+MainWin_tbtmThisFinalkey_text=This Finalkey
+MainWin_text_1_text=01234567890123456789012345678912
+MainWin_text_1_text_1=noname
+MainWin_text_1_toolTipText=The name of this FinalKey
 NewAccountDialog_0=ERROR\: FinalKey not ready.
 NewAccountDialog_1=Account not created.
 NewAccountDialog_10=Next up\: Setting a safe password\!\nYou have two options\: Manually enter a password or to\nhave The Final Key generate a strong and random password,\nit is strongly recommended to let The Final Key generate a\nrandom password, select the longest that is allowed by the service.