Snapshot before changing swt list to comboviewer
authorJimmy Christensen <dusted@dusted.dk>
Mon, 4 Aug 2014 13:40:41 +0000 (15:40 +0200)
committerJimmy Christensen <dusted@dusted.dk>
Mon, 4 Aug 2014 13:40:41 +0000 (15:40 +0200)
13 files changed:
.classpath
src/fkgui/AccountManager.java [new file with mode: 0644]
src/fkgui/Animation.java [new file with mode: 0644]
src/fkgui/ConsoleMsg.java
src/fkgui/FireActionListener.java [deleted file]
src/fkgui/FkActionEventListener.java [new file with mode: 0644]
src/fkgui/FkManager.java [new file with mode: 0644]
src/fkgui/MainWin.java
src/fkgui/NewAccountDialog.java [new file with mode: 0644]
src/fkgui/PermitCountDownDialog.java [new file with mode: 0644]
src/fkgui/SerialWorker.java
src/fkgui/TriggerDialog.java [new file with mode: 0644]
src/fkgui/UpdateChecker.java [new file with mode: 0644]

index 94a33f5..1bb5831 100644 (file)
@@ -2,18 +2,17 @@
 <classpath>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
-       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.osgi_3.9.1.v20140110-1610.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.osgi.source_3.9.1.v20140110-1610.jar"/>
-       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.core.commands_3.6.100.v20130515-1857.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.core.commands.source_3.6.100.v20130515-1857.jar"/>
+       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.osgi_3.10.0.v20140606-1445.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.osgi.source_3.9.1.v20140110-1610.jar"/>
+       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.core.commands_3.6.100.v20140528-1422.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.core.commands.source_3.6.100.v20130515-1857.jar"/>
        <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.equinox.common_3.6.200.v20130402-1505.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.equinox.common.source_3.6.200.v20130402-1505.jar"/>
-       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.equinox.registry_3.5.301.v20130717-1549.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.equinox.registry.source_3.5.301.v20130717-1549.jar"/>
-       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.core.runtime_3.9.100.v20131218-1515.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.core.runtime.source_3.9.100.v20131218-1515.jar"/>
+       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.equinox.registry_3.5.400.v20140428-1507.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.equinox.registry.source_3.5.301.v20130717-1549.jar"/>
+       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.core.runtime_3.10.0.v20140318-2214.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.core.runtime.source_3.9.100.v20131218-1515.jar"/>
        <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.text_3.5.300.v20130515-1451.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.text.source_3.5.300.v20130515-1451.jar"/>
-       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.swt.gtk.linux.x86_64_3.102.1.v20140206-1358.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.swt.gtk.linux.x86_64.source_3.102.1.v20140206-1358.jar"/>
-       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.jface_3.9.1.v20130725-1141.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.jface.source_3.9.1.v20130725-1141.jar"/>
-       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.jface.text_3.8.101.v20130802-1147.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.jface.text.source_3.8.101.v20130802-1147.jar"/>
-       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.ui.workbench_3.105.2.v20140211-1711.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.ui.workbench.source_3.105.2.v20140211-1711.jar"/>
-       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/com.ibm.icu_50.1.1.v201304230130.jar" sourcepath="/usr/share/eclipse/plugins/com.ibm.icu.source_50.1.1.v201304230130.jar"/>
-       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.ui.forms_3.6.1.v20130822-1117.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.ui.forms.source_3.6.1.v20130822-1117.jar"/>
+       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.swt.gtk.linux.x86_64_3.103.0.v20140605-2012.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.swt.gtk.linux.x86_64.source_3.102.1.v20140206-1358.jar"/>
+       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.jface_3.10.0.v20140604-0740.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.jface.source_3.9.1.v20130725-1141.jar"/>
+       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.jface.text_3.9.0.v20140521-1657.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.jface.text.source_3.8.101.v20130802-1147.jar"/>
+       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/com.ibm.icu_52.1.0.v201404241930.jar" sourcepath="/usr/share/eclipse/plugins/com.ibm.icu.source_50.1.1.v201304230130.jar"/>
+       <classpathentry kind="lib" path="/usr/share/eclipse/plugins/org.eclipse.ui.workbench_3.106.0.v20140530-0732.jar" sourcepath="/usr/share/eclipse/plugins/org.eclipse.ui.forms.source_3.6.1.v20130822-1117.jar"/>
        <classpathentry kind="lib" path="lib/jssc-2.8.0-javadoc.jar"/>
        <classpathentry kind="lib" path="lib/jssc-2.8.0.jar">
                <attributes>
diff --git a/src/fkgui/AccountManager.java b/src/fkgui/AccountManager.java
new file mode 100644 (file)
index 0000000..456a341
--- /dev/null
@@ -0,0 +1,5 @@
+package fkgui;
+
+public class AccountManager {
+
+}
diff --git a/src/fkgui/Animation.java b/src/fkgui/Animation.java
new file mode 100644 (file)
index 0000000..84284e2
--- /dev/null
@@ -0,0 +1,100 @@
+package fkgui;
+
+import java.util.Vector;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.wb.swt.SWTResourceManager;
+
+public class Animation extends Composite {
+
+       /**
+        * Create the composite.
+        * @param parent
+        * @param style
+        */
+       
+       public int msDelay=1000;
+       public Boolean playing=false;
+       public int curFrame=0;
+       public Vector<Image> frames;
+       Label label;
+       
+       public Animation(Composite parent, int style, float FPS) {
+               super(parent, style);
+               setLayout(new FormLayout());
+               
+               label = new Label(this, SWT.NONE);
+               FormData fd_label = new FormData();
+               fd_label.top = new FormAttachment(0);
+               fd_label.left = new FormAttachment(0);
+               fd_label.bottom = new FormAttachment(0, 32);
+               fd_label.right = new FormAttachment(0, 32);
+               label.setLayoutData(fd_label);
+               frames = new Vector<Image>(0);
+               setFPS(FPS);
+       }
+       
+       public void setPlaying(Boolean state )
+       {
+               playing=state;
+               if(playing)
+               {
+                       animate();
+               }
+       }
+
+       private void animate() {
+               getDisplay().timerExec(msDelay, new Runnable() {
+                       
+                       @Override
+                       public void run() {
+
+                               if( !label.isDisposed() )
+                               {
+                                       if( isVisible() && frames.size() > 0 )
+                                       {
+                                               curFrame++;
+
+                                               if( curFrame > frames.size()-1 )
+                                               {
+                                                       curFrame=0;
+                                               }
+                                               
+                                               label.setImage( frames.get(curFrame) );
+       
+                                               label.getDisplay().update();
+                                       }
+                                       if(playing)
+                                       {
+                                               animate();
+                                       }
+                               }
+                               
+                       }
+               });
+               
+       }
+
+
+
+       @Override
+       protected void checkSubclass() {
+               // Disable the check that prevents subclassing of SWT components
+       }
+
+       public void addFrame(Image image) {
+               frames.addElement(image);
+       }
+       
+       public void setFPS( float fps )
+       {
+               msDelay = (int)(1000.0 / fps);
+       }
+}
index 795ea61..b8f1eb8 100644 (file)
@@ -6,6 +6,5 @@ import fkgui.SerialWorker.SerialState;
 
 public interface ConsoleMsg {
        public void log(String msg);
-       public PopupMenu getPopup();
        public void serialEvent( SerialState state );
 }
diff --git a/src/fkgui/FireActionListener.java b/src/fkgui/FireActionListener.java
deleted file mode 100644 (file)
index 7c717d9..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-package fkgui;
-
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-
-import jssc.SerialPort;
-import jssc.SerialPortException;
-
-public class FireActionListener implements ActionListener {
-       public String name;
-       public String num;
-       public String action;
-       public SerialPort port;
-       public void actionPerformed(ActionEvent e) {
-               System.out.println("Performing action " + action + " on account ("+num+") - "+name );
-               if(!action.equals("%"))
-               {
-                       System.out.println("Here");
-                       try
-                       {
-                               port.writeBytes(action.getBytes());
-                       } catch( Exception ex )
-                       {
-                               ex.printStackTrace();
-                       }
-               }
-               
-               try {
-                       port.writeBytes(num.toLowerCase().getBytes());
-       
-                       try {
-                               Thread.sleep(400);
-                       } catch (InterruptedException e1) {
-                               // TODO Auto-generated catch block
-                               e1.printStackTrace();
-                       }
-                       System.out.println( port.readString() );
-                       
-               } catch (SerialPortException e1) {
-                       // TODO Auto-generated catch block
-                       e1.printStackTrace();
-               }
-               
-               
-               
-       }
-
-}
diff --git a/src/fkgui/FkActionEventListener.java b/src/fkgui/FkActionEventListener.java
new file mode 100644 (file)
index 0000000..73a8773
--- /dev/null
@@ -0,0 +1,20 @@
+package fkgui;
+
+import fkgui.FkManager.Account;
+
+public interface FkActionEventListener {
+       public class FkActionEvent
+       {
+               FkActionEventType type;
+               public String data;
+               Account acc;
+               public FkActionEvent( FkActionEventType t, String d, Account a )
+               {
+                       data = d;
+                       type = t;
+                       acc=a;
+               }
+       }
+       public enum FkActionEventType { ACTION_ABORTED, ACTION_OKAY, ACTION_ERROR };
+       public void fkActionEvent( FkActionEvent event );
+}
diff --git a/src/fkgui/FkManager.java b/src/fkgui/FkManager.java
new file mode 100644 (file)
index 0000000..764e380
--- /dev/null
@@ -0,0 +1,213 @@
+package fkgui;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Vector;
+
+import javax.swing.JFrame;
+import javax.swing.JTextField;
+
+import org.eclipse.swt.widgets.Display;
+
+import jssc.SerialPortException;
+import fkgui.FkActionEventListener.FkActionEvent;
+import fkgui.FkActionEventListener.FkActionEventType;
+import fkgui.FkManager.Account;
+import fkgui.SerialWorker.SerialState;
+
+public class FkManager implements ActionListener {
+       private static FkManager instance = null;
+       private SerialWorker com = null;
+
+       public class Account
+       {
+               public String name;
+               public String num;
+               
+               public Account( String acNum, String acName )
+               {
+                       name = acName;
+                       num = acNum;
+               }
+       }
+               
+       private Vector<Account> list;
+       
+       protected FkManager()
+       {
+               list = new Vector<Account>(256);
+       }
+       
+       public static FkManager getInstance()
+       {
+               if( instance == null )
+               {
+                       instance = new FkManager();
+               }
+
+               return( instance );
+       }
+       
+       public void setWorker( SerialWorker sw )
+       {
+               com = sw;
+       }
+       
+       private class TrigTask implements Runnable
+       {
+               private Account acc;
+               private char action;
+               private FkActionEventListener delegate;
+               public TrigTask(Account ac, char act, FkActionEventListener d )
+               {
+                       acc=ac;
+                       action=act;
+                       delegate=d;
+               }
+
+               private class FkActionEventMsg implements Runnable  {
+                       private FkActionEventListener delegate;
+                       private FkActionEvent event;
+
+                       private FkActionEventMsg(FkActionEventListener d, FkActionEventType t, String data, Account acc )
+                       {
+                               delegate=d;
+                               event=new FkActionEvent(t, data, acc) ;
+                       }
+                       @Override
+                       public void run() {
+                               if( delegate != null )
+                               {
+                                       delegate.fkActionEvent(event);
+                               }
+                       }
+               }
+               
+               @Override
+               public void run() {
+                       if(action != '%' )
+                       {
+                               try
+                               {
+                                       com.serialPort.writeByte((byte)action);
+                               } catch( Exception ex )
+                               {
+                                       ex.printStackTrace();
+                               }
+                       }
+                       
+                       try {
+                               com.serialPort.writeBytes(acc.num.toLowerCase().getBytes());
+               
+                               try {
+                                       Thread.sleep(400);
+                               } catch (InterruptedException e1) {
+                                       // TODO Auto-generated catch block
+                                       e1.printStackTrace();
+                               }
+                               
+                               int t=0;
+
+                               String msg = "";
+                               while( t < 1200 )
+                               {
+                                       t++;
+                                       try {
+                                               Thread.sleep(50);
+                                       } catch (InterruptedException e) {
+                                               // TODO Auto-generated catch block
+                                               e.printStackTrace();
+                                       }
+                                       if( com.serialPort.getInputBufferBytesCount() > 0 )
+                                       {
+                                               msg += com.serialPort.readString();
+                                               //System.out.println( msg );
+                                               if( msg.contains("[done]") )
+                                               {
+                                                       //System.out.println("FkManager: Action OK");;
+                                                       Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_OKAY, msg, acc) );
+                                                       return;
+                                               } else if( msg.contains("[abort]") )
+                                               {
+                                                       //System.out.println("FkManager: Action Abort");;
+                                                       Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_ABORTED, msg,acc) );
+                                                       
+                                                       return;
+                                               }
+                                       }
+                               }
+                               Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_ERROR, msg,acc) );
+
+                       } catch (Exception e1) {
+                               // TODO Auto-generated catch block
+                               System.out.println("TrigTask Exception:");
+                               e1.printStackTrace();
+                               Display.getDefault().asyncExec( new FkActionEventMsg(delegate, FkActionEventListener.FkActionEventType.ACTION_ERROR, "EXCEPTION",acc) );
+                       }
+                       
+               }
+               
+       }
+       
+       public void trig(Account acc, char action, FkActionEventListener delegate)
+       {
+               TrigTask trigTask = new TrigTask(acc,action,delegate);
+               new Thread(trigTask).start();
+       }
+       
+       
+       public void listAddAcc(String num, String name)
+       {
+               list.addElement( new Account(num,name) );
+       }
+       
+       public void listClear()
+       {
+               list.clear();
+       }
+       
+       public Vector<Account> getList()
+       {
+               return(list);
+       }
+       
+       public void getCurrentLayout()
+       {
+               
+       }
+       
+       public void getAvailableLayouts()
+       {
+               
+       }
+       
+       public void setLayout(int num)
+       {
+               
+       }
+
+       @Override
+       public void actionPerformed(ActionEvent e) {
+               Account f=null;
+               for( Account a : list )
+               {
+                       if( a.num.compareTo( e.getActionCommand().substring(1, 3)) == 0 )
+                       {
+                               f=a;
+                               break;
+                       }
+               }
+               if(f!=null)
+               {
+                       trig(f, e.getActionCommand().charAt(0), null);
+               }
+               
+       }
+
+       public void setCurrentLayout(String str) {
+               System.out.println("FkManager: Got current layout:" + str );
+               
+       }
+       
+       
+}
index 0576351..025f868 100644 (file)
@@ -1,6 +1,8 @@
 package fkgui;
 
 
+import java.util.Iterator;
+import java.util.concurrent.CountDownLatch;
 import  java.util.prefs.*;
 import java.awt.*;
 import java.awt.event.ActionEvent;
@@ -14,6 +16,7 @@ import javax.swing.UnsupportedLookAndFeelException;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.SWT;
@@ -30,6 +33,7 @@ import org.eclipse.swt.widgets.Control;
 import org.eclipse.wb.swt.SWTResourceManager;
 
 import fkgui.SerialWorker.SerialState;
+import fkgui.UpdateChecker.AutoUpdaterResultListener;
 
 import org.eclipse.swt.widgets.TabFolder;
 import org.eclipse.swt.widgets.TabItem;
@@ -41,7 +45,8 @@ import org.eclipse.swt.layout.FormData;
 import org.eclipse.swt.layout.FormAttachment;
 import org.eclipse.swt.widgets.List;
 
-public class MainWin implements ConsoleMsg {
+
+public class MainWin implements ConsoleMsg, AutoUpdaterResultListener {
 
        protected Shell shell;
        private Text txtPsw;
@@ -55,6 +60,10 @@ public class MainWin implements ConsoleMsg {
        public Button chkAutoHide;
        public Label lblPort;
        public Label lblPassword;
+       
+       public Animation animation;
+       
+       public TabFolder tabFolder;
 
        private Text txtDev;
        Preferences prefs;
@@ -69,10 +78,8 @@ public class MainWin implements ConsoleMsg {
        static final String DEFAULT_DEVICE = "/dev/FinalKey";
        static final String PREF_AUTOHIDE = "hideMainWinAfterConnect";
        public Composite cmpConnect;
-       private Composite composite;
        private Composite cmpAccounts;
        List lstAccounts;
-       private Text txtSearch;
  
        
        /**
@@ -100,6 +107,7 @@ public class MainWin implements ConsoleMsg {
                shell.layout();
                createSysTrayIcon();
                serialEvent(SerialState.Disconnected);
+               new Thread(new UpdateChecker(this)).start();
 
                while (!shell.isDisposed()) {
                        if (!display.readAndDispatch()) {
@@ -147,6 +155,7 @@ public class MainWin implements ConsoleMsg {
         popup = new PopupMenu();
         trayIcon =
                 new TrayIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource("finalkey.png")));
+        trayIcon.setToolTip("The Final Key - Hardware password manager");
         trayIcon.setImageAutoSize(true);
         final SystemTray tray = SystemTray.getSystemTray();
        
@@ -255,9 +264,15 @@ public class MainWin implements ConsoleMsg {
                
 
                mySelf = this;
-               shell.setLayout(new FillLayout(SWT.HORIZONTAL));
+               shell.setLayout(new FormLayout());
                
-               TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
+               tabFolder = new TabFolder(shell, SWT.NONE);
+               FormData fd_tabFolder = new FormData();
+               fd_tabFolder.bottom = new FormAttachment(0, 627);
+               fd_tabFolder.right = new FormAttachment(0, 709);
+               fd_tabFolder.top = new FormAttachment(0);
+               fd_tabFolder.left = new FormAttachment(0);
+               tabFolder.setLayoutData(fd_tabFolder);
                tabFolder.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
                
                TabItem tbtmConnection = new TabItem(tabFolder, SWT.NONE);
@@ -269,7 +284,9 @@ public class MainWin implements ConsoleMsg {
                
 
                btnConnect = new Button(cmpConnect, SWT.CENTER);
+               btnConnect.setImage(SWTResourceManager.getImage("/home/dusted/Downloads/lightning.png"));
                FormData fd_btnConnect = new FormData();
+               fd_btnConnect.left = new FormAttachment(100, -125);
                fd_btnConnect.right = new FormAttachment(100, -10);
                btnConnect.setLayoutData(fd_btnConnect);
 
@@ -303,10 +320,10 @@ public class MainWin implements ConsoleMsg {
                
                txtLog = new Text(cmpConnect, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
                FormData fd_txtLog = new FormData();
+               fd_txtLog.left = new FormAttachment(0, 10);
+               fd_txtLog.right = new FormAttachment(100, -10);
                fd_txtLog.bottom = new FormAttachment(100, -10);
-               fd_txtLog.right = new FormAttachment(btnConnect, 0, SWT.RIGHT);
                fd_txtLog.top = new FormAttachment(0, 58);
-               fd_txtLog.left = new FormAttachment(0, 10);
                txtLog.setLayoutData(fd_txtLog);
                txtLog.setEditable(false);
                
@@ -346,138 +363,29 @@ public class MainWin implements ConsoleMsg {
                
                chkAutoHide.setSelection( prefs.getBoolean(PREF_AUTOHIDE, false)) ;
                
-               cmpConnect.setTabList(new Control[]{txtPsw, btnConnect});
-               
-               
-               TabItem tbtmOptions = new TabItem(tabFolder, SWT.NONE);
-               tbtmOptions.setText("Options");
-               
-               composite = new Composite(tabFolder, SWT.BORDER);
-               tbtmOptions.setControl(composite);
-               
-               TabItem tbtmAccounts = new TabItem(tabFolder, SWT.NONE);
-               tbtmAccounts.setText("Accounts");
-               
-               cmpAccounts = new Composite(tabFolder, SWT.BORDER);
-               tbtmAccounts.setControl(cmpAccounts);
-               cmpAccounts.setLayout(new FormLayout());
-               
-               Button btnNewAccoount = new Button(cmpAccounts, SWT.NONE);
-               FormData fd_btnNewAccoount = new FormData();
-               fd_btnNewAccoount.top = new FormAttachment(0, 10);
-               fd_btnNewAccoount.left = new FormAttachment(0, 10);
-               btnNewAccoount.setLayoutData(fd_btnNewAccoount);
-               btnNewAccoount.setText("New");
-               
-               Button btnEditAccount = new Button(cmpAccounts, SWT.NONE);
-               FormData fd_btnEditAccount = new FormData();
-               fd_btnEditAccount.top = new FormAttachment(0, 10);
-               fd_btnEditAccount.left = new FormAttachment(0, 63);
-               btnEditAccount.setLayoutData(fd_btnEditAccount);
-               btnEditAccount.setText("Edit");
-               
-               Button btnDeleteAccount = new Button(cmpAccounts, SWT.NONE);
-               FormData fd_btnDeleteAccount = new FormData();
-               fd_btnDeleteAccount.top = new FormAttachment(btnNewAccoount, 0, SWT.TOP);
-               btnDeleteAccount.setLayoutData(fd_btnDeleteAccount);
-               btnDeleteAccount.setText("Delete");
-               
-               lstAccounts = new List(cmpAccounts, SWT.BORDER | SWT.V_SCROLL);
-               fd_btnDeleteAccount.right = new FormAttachment(lstAccounts, 0, SWT.RIGHT);
-               FormData fd_lstAccounts = new FormData();
-               fd_lstAccounts.left = new FormAttachment(0, 10);
-               fd_lstAccounts.bottom = new FormAttachment(100, -6);
-               fd_lstAccounts.right = new FormAttachment(100, -10);
-               fd_lstAccounts.top = new FormAttachment(btnNewAccoount, 6);
+               animation = new Animation(cmpConnect, SWT.NONE, 4);
 
-               lstAccounts.setLayoutData(fd_lstAccounts);
+               FormData fd_animation = new FormData();
+               fd_animation.right = new FormAttachment(0, 86);
+               fd_animation.top = new FormAttachment(0);
+               fd_animation.left = new FormAttachment(0, 10);          
                
-               lstAccounts.add("Facebook");
-               lstAccounts.add("Twitter");
-               lstAccounts.add("Krapbox Twitter");
-               lstAccounts.add("Fjord");
-               lstAccounts.add("Ordbogen");
-               lstAccounts.add("Fisker");
-               lstAccounts.add("KrapBox");
-               lstAccounts.add("En to tre");
-               lstAccounts.add("Item9");
-               lstAccounts.add("Item0");
-               lstAccounts.add("Itema");
-               lstAccounts.add("Itemb");
-               lstAccounts.add("Itemc");
-               lstAccounts.add("Itemd");
-               lstAccounts.add("Iteme");
-               lstAccounts.add("Itemf");
-               lstAccounts.add("Itemg");
-               lstAccounts.add("Itemh");
-               lstAccounts.add("Itemi");
-               lstAccounts.add("Itemj");
-               lstAccounts.add("Itemk");
+               animation.setLayoutData(fd_animation);
+
+
                
-               txtSearch = new Text(cmpAccounts, SWT.BORDER);
-               txtSearch.setText("Search");
-               FormData fd_txtSearch = new FormData();
-               fd_txtSearch.right = new FormAttachment(btnDeleteAccount, -6);
-               fd_txtSearch.bottom = new FormAttachment(lstAccounts, -6);
-               fd_txtSearch.left = new FormAttachment(btnEditAccount, 6);
-               txtSearch.setLayoutData(fd_txtSearch);
                
-               lstAccounts.addListener(SWT.Selection, new Listener()
-               {
 
-                       @Override
-                       public void handleEvent(Event event) {
-                               System.out.println( "Selected Idx:"+lstAccounts.getSelectionIndex() );
-                               //txtSearch.setText( lstAccounts.getItem(lstAccounts.getSelectionIndex() ) );
-                               
-                       }
-                       
-               });
                
-               txtSearch.addModifyListener(new ModifyListener() {
-                       
-                       @Override
-                       public void modifyText(ModifyEvent e) {
-                               if( txtSearch.getText().length()<1) return;
-
-                               String lst[] = lstAccounts.getItems();
-                               String wrds[] = txtSearch.getText().toLowerCase().split(" ");
-                               int idx=0;
-                               int scores[] = new int[lst.length];
-                               for( String s : lst )
-                               {
-                                       s = s.toLowerCase();
-                                       scores[idx]=0;
-                                       for(String w: wrds )
-                                       {
-                                               if( s.contains(w) )
-                                               {
-                                                       scores[idx]++;
-                                                       //System.out.println("Account: "+s+ " scores +1 for substring "+w);
-                                               }
-                                       }
-                                       idx++;
-                               }
-                               
-                               int top=0;
-                               int biggest=0;
-                               for(int i=0; i<lst.length;i++)
-                               {
-                                       if( scores[i] > biggest )
-                                       {
-                                               biggest=scores[i];
-                                               top=i;
-                                       }
-                               }
-                               
-                               if(biggest!=0)
-                               {
-                                       lstAccounts.setSelection(top);
-                               }
-                       }
-               });
+               animation.setVisible(false);
+               animation.addFrame( SWTResourceManager.getImage("/home/dusted/Downloads/finalkey1.png") );
+               animation.addFrame( SWTResourceManager.getImage("/home/dusted/Downloads/finalkey2.png") );
+               animation.setPlaying(false);
+               cmpConnect.setTabList(new Control[]{txtPsw, btnConnect});
                
-               log("Welcome!\nConnect your Final Key and enter password.\nThen press connect.\nPress the button when it blinks.\n----------\n");
+       
+               
+               log("Type your password and press connect.\n----------\n");
 
 
                shell.addShellListener( new ShellListener() {
@@ -498,7 +406,6 @@ public class MainWin implements ConsoleMsg {
                        
                        public void shellClosed(ShellEvent e) {
                                shutDownApp();
-                               
                        }
                        
                        public void shellActivated(ShellEvent e) {
@@ -512,29 +419,75 @@ public class MainWin implements ConsoleMsg {
        }
 
 
-
-       @Override
-       public PopupMenu getPopup() {
-               return this.popup;
-       }
-
        @Override
        public void serialEvent(SerialState state) {
                switch(state)
                {
                case Connected:
                        shell.setText("Final Key (Connected)");
+                       
+                       animation.setVisible(false);
+                       animation.setPlaying(false);
+
+
                        btnConnect.setText("Disconnect");
                        btnConnect.setVisible(true);
+                       
                        //Should we hide?
                        if( prefs.getBoolean(PREF_AUTOHIDE, false) == true)
                        {
                                hideToTray();
                        }
+                       
+                       addAccountsTab();
+                       
+                       
+                       tabFolder.setSelection(1);
+                       
+                       for( FkManager.Account a : FkManager.getInstance().getList() )
+                       {
+                               lstAccounts.add(a.name);
+                               
+                               Menu menu = new Menu(a.name+" ["+a.num+"]");
+                               MenuItem both = new MenuItem("User + Pass");
+                               MenuItem usr = new MenuItem("User");
+                               MenuItem psw = new MenuItem("Pass");
+                               menu.add(both);
+                               menu.add(usr);
+                               menu.add(psw);
+
+
+                               both.addActionListener(FkManager.getInstance());
+                               both.setActionCommand( "%"+a.num );
+
+
+
+                               psw.addActionListener(FkManager.getInstance()); 
+                               psw.setActionCommand( "p"+a.num);
+
+
+                               usr.addActionListener(FkManager.getInstance()); 
+                               usr.setActionCommand( "u"+a.num );
+
+                               popup.add(menu);                                
+                               
+                               
+                       }
+                       
+                       if( lstAccounts.getItemCount() > 0 )
+                       {
+                               trayIcon.displayMessage("FinalKey", lstAccounts.getItemCount() + " account"+(( lstAccounts.getItemCount()>1)?"s":"")+" ready.", 
+                                   TrayIcon.MessageType.INFO);
+                       }
+
+                       
                        log("* Connected *");
                        break;
                case Connecting:
                        shell.setText("Final Key (Connecting...)");
+                       animation.setVisible(true);
+                       animation.setPlaying(true);
+
                        txtPsw.setVisible(false);
                        txtDev.setVisible(false);
                        btnConnect.setVisible(false);
@@ -544,6 +497,13 @@ public class MainWin implements ConsoleMsg {
                        break;
                case Disconnected:
                        fkSerial=null;
+                       animation.setVisible(false);
+                       animation.setPlaying(false);
+
+                       remAccountsTab();
+                       
+                       tabFolder.setSelection(0);
+
                        shell.setText("Final Key (Not connected)");
                        txtPsw.setVisible(true);
                        txtDev.setVisible(true);
@@ -558,10 +518,97 @@ public class MainWin implements ConsoleMsg {
                                log("* Disconnected *");
                        }
                        break;
+               
+               case Working:
+                       animation.setPlaying(false);
+                       animation.setVisible(false);
+                       break;
+                       
                default:
                        break;
                }
                lastState=state;
                cmpConnect.layout();
        }
+
+       private void remAccountsTab() {
+               if( tabFolder.getItemCount() > 1 )
+               {
+                       tabFolder.getItem(1).dispose();
+               }
+               
+       }
+
+       private void addAccountsTab() {
+               TabItem tbtmAccounts = new TabItem(tabFolder, SWT.NONE);
+               tbtmAccounts.setText("Accounts");
+               
+               cmpAccounts = new Composite(tabFolder, SWT.BORDER);
+               tbtmAccounts.setControl(cmpAccounts);
+               cmpAccounts.setLayout(new FormLayout());
+               
+               Button btnNewAccoount = new Button(cmpAccounts, SWT.NONE);
+               btnNewAccoount.setImage(SWTResourceManager.getImage("/home/dusted/Downloads/Button New-01.png"));
+               btnNewAccoount.addSelectionListener(new SelectionAdapter() {
+                       @Override
+                       public void widgetSelected(SelectionEvent e) {
+                       }
+               });
+               FormData fd_btnNewAccoount = new FormData();
+               fd_btnNewAccoount.left = new FormAttachment(0, 530);
+               fd_btnNewAccoount.right = new FormAttachment(100, -10);
+               fd_btnNewAccoount.bottom = new FormAttachment(100, -10);
+               btnNewAccoount.setLayoutData(fd_btnNewAccoount);
+               btnNewAccoount.setText("New Account");
+               
+               lstAccounts = new List(cmpAccounts, SWT.BORDER | SWT.V_SCROLL);
+               FormData fd_lstAccounts = new FormData();
+               fd_lstAccounts.bottom = new FormAttachment(btnNewAccoount, -6);
+               fd_lstAccounts.top = new FormAttachment(0, 10);
+               fd_lstAccounts.left = new FormAttachment(0, 10);
+               fd_lstAccounts.right = new FormAttachment(100, -10);
+
+               lstAccounts.setLayoutData(fd_lstAccounts);
+                               
+               lstAccounts.addListener(SWT.Selection, new Listener()
+               {
+
+                       @Override
+                       public void handleEvent(Event event) {
+                               System.out.println( "Selected Idx:"+lstAccounts.getSelectionIndex() );
+                               TriggerDialog diag = new TriggerDialog(shell, shell.getStyle(), FkManager.getInstance().getList().get(lstAccounts.getSelectionIndex()) );
+
+                               shell.setMinimized(true);
+                               shell.setEnabled(false);
+                               if( !((Boolean)diag.open()) )
+                               {
+                                       shell.setMinimized(false);
+                               }
+                               
+                               shell.setEnabled(true);
+                       }
+                       
+               });
+       }
+
+
+       @Override
+       public void updateCheckFinished(AutoUpdaterResultEvent event) {
+               switch(event.result)
+               {
+               case CHECK_FAILED:
+                       System.out.println("Trouble checking for updates.");
+                       break;
+               case NO_UPDATE:
+                       System.out.println("No update avaiable at this time.");
+                       break;
+               case UPDATE_AVAILABLE:
+                       MessageBox dialog = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
+                       dialog.setText("FinalKey GUI Version "+event.version+" available.");
+                       dialog.setMessage("There's a new version of FinalKey GUI available.\nGo to http://cyberstalker.dk/finalkey/gui/ to download.\n\nNews:\n"+event.message);
+                       dialog.open();  
+                       break;
+               }
+               
+       }
 }
diff --git a/src/fkgui/NewAccountDialog.java b/src/fkgui/NewAccountDialog.java
new file mode 100644 (file)
index 0000000..67d1c41
--- /dev/null
@@ -0,0 +1,49 @@
+package fkgui;
+
+import org.eclipse.swt.widgets.Dialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+public class NewAccountDialog extends Dialog {
+
+       protected Object result;
+       protected Shell shell;
+
+       /**
+        * Create the dialog.
+        * @param parent
+        * @param style
+        */
+       public NewAccountDialog(Shell parent, int style) {
+               super(parent, style);
+               setText("SWT Dialog");
+       }
+
+       /**
+        * 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(450, 300);
+               shell.setText(getText());
+
+       }
+
+}
diff --git a/src/fkgui/PermitCountDownDialog.java b/src/fkgui/PermitCountDownDialog.java
new file mode 100644 (file)
index 0000000..9cd3959
--- /dev/null
@@ -0,0 +1,122 @@
+package fkgui;
+
+import org.eclipse.swt.events.ShellEvent;
+import org.eclipse.swt.events.ShellListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Dialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.wb.swt.SWTResourceManager;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormAttachment;
+
+public class PermitCountDownDialog extends Dialog {
+
+       protected Object result;
+       protected Shell shell;
+       public Display display;
+
+       String msg;
+       int msLeft;
+       private Label lblTimeLeft;
+       /**
+        * Create the dialog.
+        * @param parent
+        * @param style
+        */
+       public PermitCountDownDialog(Shell parent, int style, String title, String m, int msL) {
+               super(parent, style);
+               setText(title);
+               msLeft = msL;
+               msg = m;
+       
+       }
+
+       /**
+        * Open the dialog.
+        * @return the result
+        */
+       public Object open() {
+               createContents();
+               Point p = getParent().getSize();
+               p.x /= 2;
+               p.y /= 2;
+               p.x -= shell.getSize().x/2;
+               p.y -= shell.getSize().y/2;
+               p.x += getParent().getLocation().x;
+               p.y += getParent().getLocation().y;
+               shell.setLocation( p );
+               shell.setLayout(null);
+               
+               Label lblMsg = new Label(shell, SWT.NONE);
+               lblMsg.setBounds(48, 10, 461, 54);
+               lblMsg.setText(msg);
+               
+               lblTimeLeft = new Label(shell, SWT.NONE);
+               lblTimeLeft.setText("    ");
+               lblTimeLeft.setBounds(48, 56, 201, 32);
+               
+               Animation animation = new Animation(shell, SWT.NONE, 4);
+               animation.setBounds(10, 32, 32, 32);
+               animation.setVisible(true);
+               animation.addFrame( SWTResourceManager.getImage("/home/dusted/Downloads/finalkey1.png") );
+               animation.addFrame( SWTResourceManager.getImage("/home/dusted/Downloads/finalkey2.png") );
+               animation.setPlaying(true);
+               
+               
+
+               shell.open();
+               
+               shell.layout();
+               display = getParent().getDisplay();
+                               
+               animate();
+               shell.setActive();
+               
+               while (!shell.isDisposed()) {
+                       if (!display.readAndDispatch()) {
+                               display.sleep();
+                       }
+               }
+               return result;
+       }
+
+       private void animate() {
+               display.timerExec(1000, new Runnable() {
+                       
+                       @Override
+                       public void run() {
+                               if( !shell.isDisposed() )
+                               {
+
+                                       lblTimeLeft.setText( Math.round(msLeft/1000) + " seconds left.");
+
+                                       display.update();
+                                       msLeft -= 1000;
+                                       if( msLeft<1)
+                                       {
+                                               shell.close();
+                                               
+                                       } else {                                
+                                               animate();
+                                       }
+                                       
+                               }
+                       }
+               });
+               
+       }
+
+       /**
+        * Create contents of the dialog.
+        */
+       private void createContents() {
+               shell = new Shell(getParent(), getStyle());
+               shell.setSize(521, 125);
+               shell.setText(getText());
+       }
+}
index f97c1e3..fc54ef3 100644 (file)
@@ -15,16 +15,17 @@ import org.eclipse.swt.widgets.Display;
 public class SerialWorker extends javax.swing.SwingWorker<Void, String> implements SerialPortEventListener {
        public String dev;
        public String pass;
-       private SerialPort serialPort;
+       public SerialPort serialPort;
        SerialState state;
        private ConsoleMsg delegate; 
        
-       public enum SerialState { Connecting, Connected, Disconnected };
+       public enum SerialState { Connecting,Working, Connected, Disconnected };
 
 
        public SerialWorker(ConsoleMsg d) {
                delegate=d;
                state = SerialState.Disconnected;
+               FkManager.getInstance().setWorker(this);
        }
        
        public void connect(String d, String p)
@@ -36,7 +37,7 @@ public class SerialWorker extends javax.swing.SwingWorker<Void, String> implemen
 
                state = SerialState.Connecting;
                postStateChange( state );
-               
+               FkManager.getInstance().listClear();
                execute();
        }
        
@@ -118,8 +119,7 @@ public class SerialWorker extends javax.swing.SwingWorker<Void, String> implemen
                        String test = expectString("The Final Key", 1000);
                        if( test != null )
                        {
-                               publish("Ready to log in, press button now.");
-                               publish("Waiting for button press...");
+                               publish("\n* Press the button on the Final Key *");
                        } else {
                                //Try logging out.
                                serialPort.writeByte( (byte)'q');
@@ -130,7 +130,8 @@ public class SerialWorker extends javax.swing.SwingWorker<Void, String> implemen
                        
                        if( expectString( "Pass:", 0 ) != null )
                        {
-                               publish("Logging in...");
+                               publish("Logging in.");
+                               postStateChange(SerialState.Working);
                        } else {
                                publish("Error: Did not get password prompt. Unplug and try again.");
                                disconnect();
@@ -142,17 +143,24 @@ public class SerialWorker extends javax.swing.SwingWorker<Void, String> implemen
                        serialPort.writeByte( (byte)13 );
                        pass = "";
                        
+                       /*String str = expectString( "[Keyboard: ", 200 );
+                       if( str != null )
+                       {
+                               FkManager.getInstance().setCurrentLayout( str );
+                       } else {
+                               publish("Did not get Keyboard layout.");
+                       }*/
                        
                        if( expectString( "[Granted]", 200 ) != null )
                        {
-                               publish("Access Granted.");
+                               publish("\nAccess Granted.");
                        } else {
-                               publish("Error: Access Denied.");
+                               publish("\nError: Access Denied.");
                                disconnect();
                                return null;
                        }
 
-                       publish("Getting account list...");
+                       publish("Getting account list.");
                        serialPort.writeByte( (byte)'X'); //Machine commands with uppercase X
                        expectString("[auto]", 200);
                        serialPort.writeByte( (byte)'l'); //Full list 
@@ -190,66 +198,45 @@ public class SerialWorker extends javax.swing.SwingWorker<Void, String> implemen
 
                        String[] lines = accounts.split( "\r\n" );
                        numAccounts=lines.length;
+                       Boolean kbList=false;
                        for(String l:lines)
                        {
-                               String ac = l.substring(0,2);
-                               String an = l.substring(2);
-                               
-                               //publish( "Account number: "+ac+" ["+an+"]");
-
-                               Menu menu = new Menu(an+" ["+ac+"]");
-                               MenuItem both = new MenuItem("User + Pass");
-                               MenuItem usr = new MenuItem("User");
-                               MenuItem psw = new MenuItem("Pass");
-                               menu.add(both);
-                               menu.add(usr);
-                               menu.add(psw);
-
-                               FireActionListener fal = new FireActionListener();
-                               fal.action = "%";
-                               fal.name = an;
-                               fal.num = ac;
-                               fal.port = serialPort;
-                               both.addActionListener(fal);
-
-
-                               fal = new FireActionListener();
-                               fal.action = "p";
-                               fal.name = an;
-                               fal.num = ac;
-                               fal.port = serialPort;
-                               psw.addActionListener(fal);                     
-
-                               fal = new FireActionListener();
-                               fal.action = "u";
-                               fal.name = an;
-                               fal.num = ac;
-                               fal.port = serialPort;
-                               usr.addActionListener(fal);                     
-
-                               delegate.getPopup().add(menu);
+                               if( ! kbList )
+                               {
+                                       if( l.compareTo("[KBL]") == 0 )
+                                       {
+                                               kbList=true;
+                                       } else {
+                                               String ac = l.substring(0,2);
+                                               String an = l.substring(2);
+                                               FkManager.getInstance().listAddAcc(ac, an);
+                                       }
+                               } else {
+                                       //Next entries are supported keyboard layouts
+                                       publish("Supported layout:" + l);
+                               }
                        }
 
                }
-               catch (SerialPortException ex){
-                       System.out.println(ex);
-               } catch (Exception e )
-               {
-                       System.out.println("Other exception: "+e.getMessage() );
-                       e.printStackTrace();
+               catch (Exception ex){
+                       publish("Error: Exception: "+ex.getMessage() );
+                       disconnect();
                }
 
-               if(numAccounts==1)
+               if( state != SerialState.Disconnected )
                {
-                       publish(numAccounts+" account.");
-               } else {
-                       publish(numAccounts+" accounts ready.");
-               }
-
-               publish("Use the systray icon to trigger.");
+                       if(numAccounts==1)
+                       {
+                               publish(numAccounts+" account.");
+                       } else {
+                               publish(numAccounts+" accounts ready.");
+                       }
+       
+                       publish("\n* Use the FinalKey icon in the systray to access your logins *");
 
-               state = SerialState.Connected;
-               postStateChange( state);
+                       state = SerialState.Connected;
+                       postStateChange( state);
+               }
                
                return null;
        }
diff --git a/src/fkgui/TriggerDialog.java b/src/fkgui/TriggerDialog.java
new file mode 100644 (file)
index 0000000..e2df667
--- /dev/null
@@ -0,0 +1,290 @@
+package fkgui;
+
+import java.awt.Color;
+import java.io.Closeable;
+
+import javax.swing.JFrame;
+import javax.swing.JTextField;
+
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.swt.graphics.Point;
+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.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.Button;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.wb.swt.SWTResourceManager;
+
+import fkgui.FkManager.Account;
+
+public class TriggerDialog extends Dialog implements FkActionEventListener {
+
+       protected Object result;
+       protected Shell shell;
+       private Account account;
+       public TriggerDialog mySelf;
+       private FormData fd_grpChange;
+       private Group grpMakeFinalKey;
+       private Group grpChange;
+       private Boolean askPermitShow = false;
+       PermitCountDownDialog permitCountdownDialog = null;
+       /**
+        * Create the dialog.
+        * @param parent
+        * @param style
+        */
+       public TriggerDialog(Shell parent, int style, Account a) {
+               super(parent, style);
+               account = a;
+               setText("Use "+ account.name);
+       }
+
+       /**
+        * Open the dialog.
+        * @return the result
+        */
+       public Object open() {
+               result = (Object)new Boolean(false);
+               createContents();
+
+               Point p = getParent().getSize();
+               p.x /= 2;
+               p.y /= 2;
+               p.x -= shell.getSize().x/2;
+               p.y -= shell.getSize().y/2;
+               p.x += getParent().getLocation().x;
+               p.y += getParent().getLocation().y;
+               shell.setLocation( p );
+
+               shell.open();
+               shell.layout();
+               Display display = getParent().getDisplay();
+               
+               
+               while (!shell.isDisposed()) {
+                       if (!display.readAndDispatch()) {
+                               display.sleep();
+                       }
+               }
+               System.out.println("Returning result:" + (Boolean)result);
+               return result;
+       }
+
+       /**
+        * Create contents of the dialog.
+        */
+       private void createContents() {
+               shell = new Shell(getParent(), SWT.BORDER | SWT.CLOSE);
+               shell.setSize(677, 250);
+               shell.setText(getText());
+               shell.setLayout(new FormLayout());
+               mySelf = this;
+               grpMakeFinalKey = new Group(shell, SWT.NONE);
+               grpMakeFinalKey.setLayout(new FormLayout());
+               FormData fd_grpMakeFinalKey = new FormData();
+               fd_grpMakeFinalKey.top = new FormAttachment(0, 10);
+               fd_grpMakeFinalKey.bottom = new FormAttachment(0, 88);
+               fd_grpMakeFinalKey.left = new FormAttachment(0, 10);
+               fd_grpMakeFinalKey.right = new FormAttachment(100, -10);
+               grpMakeFinalKey.setLayoutData(fd_grpMakeFinalKey);
+               grpMakeFinalKey.setText("Use " + account.name);
+               
+               Button btnUsernamePassword = new Button(grpMakeFinalKey, SWT.NONE);
+               btnUsernamePassword.addSelectionListener(new SelectionAdapter() {
+                       @Override
+                       public void widgetSelected(SelectionEvent e) {
+                               FkManager.getInstance().trig(account, '%', mySelf);
+                               permitCountdownDialog = new PermitCountDownDialog(shell,SWT.SHELL_TRIM, account.name + ": Ready with username and password", "Focus username field and press button.\nPress and hold to cancel.", 30000);
+                               shell.setMinimized(true);
+                               permitCountdownDialog.open();
+                       }
+               });
+               btnUsernamePassword.setImage(SWTResourceManager.getImage("/home/dusted/Downloads/both.png"));
+               FormData fd_btnUsernamePassword = new FormData();
+               fd_btnUsernamePassword.top = new FormAttachment(0, 10);
+               fd_btnUsernamePassword.left = new FormAttachment(0, 10);
+               fd_btnUsernamePassword.right = new FormAttachment(0, 224);
+               btnUsernamePassword.setLayoutData(fd_btnUsernamePassword);
+
+               btnUsernamePassword.setText("Username + Password");
+               
+               Button btnUsernameOnly = new Button(grpMakeFinalKey, SWT.NONE);
+               btnUsernameOnly.addSelectionListener(new SelectionAdapter() {
+                       @Override
+                       public void widgetSelected(SelectionEvent e) {
+                               FkManager.getInstance().trig(account, 'u', mySelf);
+                               permitCountdownDialog = new PermitCountDownDialog(shell,SWT.SHELL_TRIM, account.name + ": Ready with username", "Focus username field and press button.\nPress and hold to cancel.", 30000);
+                               shell.setMinimized(true);
+                               permitCountdownDialog.open();
+                       }
+               });
+               btnUsernameOnly.setImage(SWTResourceManager.getImage("/home/dusted/Downloads/Deep_User.png"));
+               FormData fd_btnUsernameOnly = new FormData();
+               fd_btnUsernameOnly.top = new FormAttachment(btnUsernamePassword, -35);
+               fd_btnUsernameOnly.bottom = new FormAttachment(btnUsernamePassword, 0, SWT.BOTTOM);
+               fd_btnUsernameOnly.left = new FormAttachment(btnUsernamePassword, 6);
+               fd_btnUsernameOnly.right = new FormAttachment(0, 405);
+               btnUsernameOnly.setLayoutData(fd_btnUsernameOnly);
+
+               btnUsernameOnly.setText("Username");
+               
+               Button btnPasswordOnly = new Button(grpMakeFinalKey, SWT.NONE);
+               btnPasswordOnly.addSelectionListener(new SelectionAdapter() {
+                       @Override
+                       public void widgetSelected(SelectionEvent e) {
+                               FkManager.getInstance().trig(account, 'p', mySelf);
+                               
+                               permitCountdownDialog = new PermitCountDownDialog(shell,SWT.SHELL_TRIM, account.name + ": Ready with password", "Focus username field and press button.\nPress and hold to cancel.", 30000);
+
+                               shell.setMinimized(true);
+                               permitCountdownDialog.open();
+                       }
+               });
+               btnPasswordOnly.setImage(SWTResourceManager.getImage("/home/dusted/Downloads/key-icon.png"));
+               FormData fd_btnPasswordOnly = new FormData();
+               fd_btnPasswordOnly.left = new FormAttachment(btnUsernameOnly, 29);
+               fd_btnPasswordOnly.top = new FormAttachment(btnUsernamePassword, 0, SWT.TOP);
+               fd_btnPasswordOnly.right = new FormAttachment(100, -9);
+               fd_btnPasswordOnly.bottom = new FormAttachment(0, 45);
+               btnPasswordOnly.setLayoutData(fd_btnPasswordOnly);
+
+               btnPasswordOnly.setText("Password");
+                               
+                               grpChange = new Group(shell, SWT.NONE);
+                               grpChange.setText("Change "+account.name);
+                               grpChange.setLayout(new FormLayout());
+                               fd_grpChange = new FormData();
+                               fd_grpChange.left = new FormAttachment(grpMakeFinalKey, 353, SWT.LEFT);
+                               fd_grpChange.right = new FormAttachment(grpMakeFinalKey, 0, SWT.RIGHT);
+                               fd_grpChange.top = new FormAttachment(grpMakeFinalKey, 6);
+                               grpChange.setLayoutData(fd_grpChange);
+                               
+                               Button btnEdit = new Button(grpChange, SWT.NONE);
+                               btnEdit.setImage(SWTResourceManager.getImage("/home/dusted/Downloads/gtk_edit.png"));
+                               FormData fd_btnEdit = new FormData();
+                               fd_btnEdit.top = new FormAttachment(0, 10);
+                               fd_btnEdit.left = new FormAttachment(0, 10);
+                               btnEdit.setLayoutData(fd_btnEdit);
+                               btnEdit.setText("Edit");
+                               ///TODO: Inplement edit box..
+                               btnEdit.setVisible(false);
+                               
+                               Button btnDelete = new Button(grpChange, SWT.NONE);
+                               btnDelete.addSelectionListener(new SelectionAdapter() {
+                                       @Override
+                                       public void widgetSelected(SelectionEvent e) {
+                                               MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO );
+                                               dialog.setText("WARNING! Confirm delete "+account.name );
+                                               dialog.setMessage("Are you sure you want to delete account "+account.name+" ?\nAccount id: "+account.num+"\nIf you remove the account, it can not be recovered!");
+                                               if( dialog.open() == SWT.YES )
+                                               {
+                                                       permitCountdownDialog = new PermitCountDownDialog(shell,SWT.SHELL_TRIM, account.name + ": Confirm deletion", "Press button to show delete "+account.name+".\nPress and hold to cancel.", 5000);
+                                                       shell.setMinimized(true);
+                                                       permitCountdownDialog.open();
+
+                                               }
+                                       }
+                               });
+                               fd_btnEdit.right = new FormAttachment(btnDelete, -6);
+                               btnDelete.setImage(SWTResourceManager.getImage("/home/dusted/Downloads/trashdelete.gif"));
+                               FormData fd_btnDelete = new FormData();
+                               fd_btnDelete.top = new FormAttachment(0, 10);
+                               fd_btnDelete.left = new FormAttachment(0, 166);
+                               fd_btnDelete.right = new FormAttachment(100, -11);
+                               btnDelete.setLayoutData(fd_btnDelete);
+                               btnDelete.setText("Delete");
+
+                               Button btnCancel = new Button(shell, SWT.NONE);
+                               fd_grpChange.bottom = new FormAttachment(btnCancel, -6);
+                               btnCancel.setImage(SWTResourceManager.getImage("/home/dusted/Downloads/Delete.png"));
+                               FormData fd_btnCancel = new FormData();
+                               fd_btnCancel.left = new FormAttachment(grpMakeFinalKey, 0, SWT.LEFT);
+                               fd_btnCancel.bottom = new FormAttachment(100, -10);
+                               fd_btnCancel.right = new FormAttachment(grpMakeFinalKey, 2, SWT.RIGHT);
+                               btnCancel.setLayoutData(fd_btnCancel);
+                               
+                               btnCancel.setText("Do nothing");
+                               
+                               btnCancel.addSelectionListener( new SelectionAdapter() {
+                                       public void widgetSelected(SelectionEvent e) {
+                                               shell.close();
+                                       }
+                               });                             
+                               Group grpShow = new Group(shell, SWT.NONE);
+                               grpShow.setText("Show "+account.name);
+                               FormData fd_grpShow = new FormData();
+                               fd_grpShow.bottom = new FormAttachment(grpChange, 0, SWT.BOTTOM);
+                               fd_grpShow.right = new FormAttachment(grpChange, -6);
+                               fd_grpShow.left = new FormAttachment(grpMakeFinalKey, 0, SWT.LEFT);
+                               fd_grpShow.top = new FormAttachment(grpMakeFinalKey, 6);
+                               grpShow.setLayoutData(fd_grpShow);
+                               
+                               Button btnShowUsername = new Button(grpShow, SWT.NONE);
+                               btnShowUsername.addSelectionListener(new SelectionAdapter() {
+                                       @Override
+                                       public void widgetSelected(SelectionEvent e) {
+                                               FkManager.getInstance().trig(account, 's', mySelf);
+                                               permitCountdownDialog = new PermitCountDownDialog(shell,SWT.SHELL_TRIM, account.name + ": Ready for display", "Press button to show username and password.\nPress and hold to cancel.", 30000);
+                                               askPermitShow=true;
+                                               shell.setMinimized(true);
+                                               permitCountdownDialog.open();
+                                       }
+                               });
+                               btnShowUsername.setImage(SWTResourceManager.getImage("/home/dusted/Downloads/both.png"));
+                               btnShowUsername.setBounds(10, 36, 327, 35);
+                               btnShowUsername.setText("Show Username + Password");                            
+                               
+
+       }
+
+       @Override
+       public void fkActionEvent(FkActionEvent event) {
+               MessageBox dialog;
+               
+               if( permitCountdownDialog != null && !permitCountdownDialog.shell.isDisposed() )
+               {
+                       permitCountdownDialog.shell.close();
+               }
+               
+               switch(event.type)
+               {
+               case ACTION_ABORTED:
+                       dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
+                       dialog.setText(event.acc.name);
+                       dialog.setMessage("Action aborted or timed out.");
+                       dialog.open();
+                       break;
+               case ACTION_ERROR:
+                       dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
+                       dialog.setText(event.acc.name + " error");
+                       dialog.setMessage("An error ocurred.");
+                       dialog.open();                  
+                       break;
+               case ACTION_OKAY:
+                       result = (Object)new Boolean(true);
+                       if( askPermitShow )
+                       {
+                               String s = event.data.substring( event.data.indexOf( "Account: "+ event.acc.num), event.data.lastIndexOf("[done]") );
+                               dialog = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
+                               dialog.setText("Account information");
+                               dialog.setMessage(s);
+                               dialog.open();
+                       }
+                       if( !shell.isDisposed() )
+                       {
+                               shell.close();
+                       }                       
+                       break;
+               }
+
+
+               
+       }
+}
diff --git a/src/fkgui/UpdateChecker.java b/src/fkgui/UpdateChecker.java
new file mode 100644 (file)
index 0000000..9cab9b6
--- /dev/null
@@ -0,0 +1,98 @@
+package fkgui;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+import org.eclipse.swt.widgets.Display;
+
+import fkgui.UpdateChecker.AutoUpdaterResultListener.AutoUpdaterResultEvent;
+import fkgui.UpdateChecker.AutoUpdaterResultListener.UpdateCheckResult;
+
+
+public class UpdateChecker implements Runnable {
+       
+       static final String CHECK_URL="http://cyberstalker.dk/finalkey/gui/update.php";
+       static final String CUR_VER="0.0";
+       static final String PLATFORM="lin_x64";
+       static final String LANG = "US";
+
+       public static final String REQUEST_STRING = CHECK_URL + "?version="+CUR_VER+"&platform="+PLATFORM+"&lang="+LANG;
+       
+       public interface AutoUpdaterResultListener {
+               public class AutoUpdaterResultEvent
+               {
+                       public String version;
+                       public String message;
+                       public UpdateCheckResult result;
+                       public AutoUpdaterResultEvent( UpdateCheckResult res, String ver, String msg )
+                       {
+                               result=res;
+                               version=ver;
+                               message=msg;
+                       }
+               }
+               public enum UpdateCheckResult { NO_UPDATE, CHECK_FAILED, UPDATE_AVAILABLE };
+               
+               public void updateCheckFinished( AutoUpdaterResultEvent event );
+       }       
+       
+       AutoUpdaterResultListener delegate;
+       public UpdateChecker( AutoUpdaterResultListener del )
+       {
+               delegate=del;
+       }
+
+       public class AutoUpdaterResultTask implements Runnable
+       {
+               private AutoUpdaterResultEvent e;
+               private AutoUpdaterResultListener d;
+               public AutoUpdaterResultTask( AutoUpdaterResultEvent event, AutoUpdaterResultListener delegate )
+               {
+                       e=event;
+                       d=delegate;
+               }
+               @Override
+               public void run() {
+                       d.updateCheckFinished(e);                       
+               }
+               
+       }
+       
+       @Override
+       public void run() {
+               UpdateCheckResult state = UpdateCheckResult.CHECK_FAILED;
+               String res="";
+               String ver="No Version";
+               String msg="No Update";
+
+               try {
+                       URL url = new URL(REQUEST_STRING);
+                       BufferedReader  in = new BufferedReader ( new InputStreamReader( url.openStream() ) );
+                       res=in.readLine();
+                       in.close();
+                       state = UpdateCheckResult.NO_UPDATE;
+
+                       String[] lines = res.split( "," );
+
+                       if( lines[0].compareTo("1")==0 )
+                       {
+                               state = UpdateCheckResult.UPDATE_AVAILABLE;
+                               ver = lines[1];
+                               msg = lines[2];
+                               msg=msg.replace("<br>", "\n");
+                               msg.trim();
+
+                       }
+
+               } catch (Exception e) {
+                       System.out.println("Trouble checking for new version: "+e.getMessage() );
+               }
+
+               Display.getDefault().asyncExec( new AutoUpdaterResultTask(new AutoUpdaterResultEvent(state , ver, msg), delegate) );
+               
+       }
+
+}