More ui, going to redesign.
authorJimmy Christensen <dusted@dusted.dk>
Fri, 25 Jul 2014 22:57:36 +0000 (00:57 +0200)
committerJimmy Christensen <dusted@dusted.dk>
Fri, 25 Jul 2014 22:57:36 +0000 (00:57 +0200)
.classpath
src/fkgui/MainWin.java
swing2swt.jar [new file with mode: 0644]

index 0925262..94a33f5 100644 (file)
@@ -20,5 +20,6 @@
                        <attribute name="javadoc_location" value="jar:platform:/resource/FinalKeyGUI/lib/jssc-2.8.0-javadoc.jar!/"/>
                </attributes>
        </classpathentry>
+       <classpathentry kind="lib" path="swing2swt.jar"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>
index ded849b..0576351 100644 (file)
@@ -12,11 +12,16 @@ import javax.swing.UIManager;
 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.Shell;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.SWT;
+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.widgets.Text;
@@ -26,6 +31,16 @@ import org.eclipse.wb.swt.SWTResourceManager;
 
 import fkgui.SerialWorker.SerialState;
 
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.widgets.List;
+
 public class MainWin implements ConsoleMsg {
 
        protected Shell shell;
@@ -37,6 +52,7 @@ public class MainWin implements ConsoleMsg {
 
        public Text txtLog;
        public Button btnConnect;
+       public Button chkAutoHide;
        public Label lblPort;
        public Label lblPassword;
 
@@ -52,6 +68,11 @@ public class MainWin implements ConsoleMsg {
        static final String PREF_PORT ="lastUsedPortPref";
        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;
  
        
        /**
@@ -140,7 +161,6 @@ public class MainWin implements ConsoleMsg {
                                        
                                        public void run()
                                        {
-                               //Remove myself and make main window visible
                                                showFromTray();
                                        }
                                } );
@@ -227,20 +247,32 @@ public class MainWin implements ConsoleMsg {
        protected void createContents() {
                shell = new Shell();
                shell.setImage(SWTResourceManager.getImage(MainWin.class, "/fkgui/finalkey.png"));
-               shell.setSize(450, 495);
+               shell.setSize(711, 655);
                shell.setText("Final Key (Not connected)");
-               
-               shell.setLayout(null);
 
                
                prefs = Preferences.userNodeForPackage(this.getClass());
                
 
                mySelf = this;
+               shell.setLayout(new FillLayout(SWT.HORIZONTAL));
+               
+               TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
+               tabFolder.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
+               
+               TabItem tbtmConnection = new TabItem(tabFolder, SWT.NONE);
+               tbtmConnection.setText("Connection");
                
+               cmpConnect = new Composite(tabFolder, SWT.BORDER);
+               tbtmConnection.setControl(cmpConnect);
+               cmpConnect.setLayout(new FormLayout());
+               
+
+               btnConnect = new Button(cmpConnect, SWT.CENTER);
+               FormData fd_btnConnect = new FormData();
+               fd_btnConnect.right = new FormAttachment(100, -10);
+               btnConnect.setLayoutData(fd_btnConnect);
 
-               btnConnect = new Button(shell, SWT.NONE);
-               btnConnect.setBounds(330, 10, 104, 52);
                btnConnect.addSelectionListener(new SelectionAdapter() {
                        public void widgetSelected(SelectionEvent e) {
                                
@@ -248,6 +280,9 @@ public class MainWin implements ConsoleMsg {
                                {
                                        fkSerial.disconnect();
                                } else {
+                                       
+                                       prefs.putBoolean(PREF_AUTOHIDE, chkAutoHide.getSelection() );
+
                                        fkSerial = new SerialWorker(mySelf);
                                        prefs.put(PREF_PORT, txtDev.getText() );
                                        fkSerial.connect(txtDev.getText(),txtPsw.getText());
@@ -256,26 +291,191 @@ public class MainWin implements ConsoleMsg {
                        }
                });
                btnConnect.setText("Connect");
-               lblPassword = new Label(shell, SWT.NONE);
-               lblPassword.setText("Password");
-               lblPassword.setBounds(10, 39, 85, 23);
                
-               txtPsw = new Text(shell, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
-               txtPsw.setBounds(101, 39, 223, 23);
+               txtPsw = new Text(cmpConnect, SWT.BORDER | SWT.PASSWORD);
+               fd_btnConnect.bottom = new FormAttachment(txtPsw, 0, SWT.BOTTOM);
+               FormData fd_txtPsw = new FormData();
+               fd_txtPsw.bottom = new FormAttachment(0, 52);
+               fd_txtPsw.right = new FormAttachment(0, 501);
+               fd_txtPsw.top = new FormAttachment(0, 29);
+               fd_txtPsw.left = new FormAttachment(0, 102);
+               txtPsw.setLayoutData(fd_txtPsw);
                
-               txtLog = new Text(shell, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
+               txtLog = new Text(cmpConnect, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
+               FormData fd_txtLog = new FormData();
+               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);
-               txtLog.setBounds(10, 68, 424, 388);
                
-               lblPort = new Label(shell, SWT.NONE);
-               lblPort.setBounds(10, 10, 76, 23);
+               lblPort = new Label(cmpConnect, SWT.NONE);
+               fd_btnConnect.top = new FormAttachment(lblPort, 0, SWT.TOP);
+               FormData fd_lblPort = new FormData();
+               fd_lblPort.right = new FormAttachment(0, 86);
+               fd_lblPort.top = new FormAttachment(0);
+               fd_lblPort.left = new FormAttachment(0, 10);
+               lblPort.setLayoutData(fd_lblPort);
                lblPort.setText("Port");
                
-               txtDev = new Text(shell, SWT.BORDER);
+               txtDev = new Text(cmpConnect, SWT.BORDER);
+               FormData fd_txtDev = new FormData();
+               fd_txtDev.bottom = new FormAttachment(0, 23);
+               fd_txtDev.right = new FormAttachment(0, 256);
+               fd_txtDev.top = new FormAttachment(0);
+               fd_txtDev.left = new FormAttachment(0, 102);
+               txtDev.setLayoutData(fd_txtDev);
                txtDev.setFont(SWTResourceManager.getFont("Cantarell", 9, SWT.NORMAL));
                txtDev.setText( prefs.get(PREF_PORT, DEFAULT_DEVICE));
-               txtDev.setBounds(101, 10, 223, 23);
-               shell.setTabList(new Control[]{txtPsw, btnConnect});
+               lblPassword = new Label(cmpConnect, SWT.NONE);
+               FormData fd_lblPassword = new FormData();
+               fd_lblPassword.right = new FormAttachment(0, 95);
+               fd_lblPassword.top = new FormAttachment(0, 29);
+               fd_lblPassword.left = new FormAttachment(0, 10);
+               lblPassword.setLayoutData(fd_lblPassword);
+               lblPassword.setText("Password");
+               
+               chkAutoHide = new Button(cmpConnect, SWT.CHECK);
+               FormData fd_chkAutoHide = new FormData();
+               fd_chkAutoHide.right = new FormAttachment(0, 501);
+               fd_chkAutoHide.top = new FormAttachment(0);
+               fd_chkAutoHide.left = new FormAttachment(0, 262);
+               chkAutoHide.setLayoutData(fd_chkAutoHide);
+               chkAutoHide.setText("Hide after connection");
+               
+               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);
+
+               lstAccounts.setLayoutData(fd_lstAccounts);
+               
+               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");
+               
+               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);
+                               }
+                       }
+               });
                
                log("Welcome!\nConnect your Final Key and enter password.\nThen press connect.\nPress the button when it blinks.\n----------\n");
 
@@ -323,6 +523,7 @@ public class MainWin implements ConsoleMsg {
                switch(state)
                {
                case Connected:
+                       shell.setText("Final Key (Connected)");
                        btnConnect.setText("Disconnect");
                        btnConnect.setVisible(true);
                        //Should we hide?
@@ -339,6 +540,7 @@ public class MainWin implements ConsoleMsg {
                        btnConnect.setVisible(false);
                        lblPort.setVisible(false);
                        lblPassword.setVisible(false);
+                       chkAutoHide.setVisible(false);
                        break;
                case Disconnected:
                        fkSerial=null;
@@ -349,6 +551,7 @@ public class MainWin implements ConsoleMsg {
                        btnConnect.setVisible(true);
                        lblPort.setVisible(true);
                        lblPassword.setVisible(true);
+                       chkAutoHide.setVisible(true);
                        clearSystray();
                        if(lastState != state)
                        {
@@ -359,8 +562,6 @@ public class MainWin implements ConsoleMsg {
                        break;
                }
                lastState=state;
-               
+               cmpConnect.layout();
        }
-
-
 }
diff --git a/swing2swt.jar b/swing2swt.jar
new file mode 100644 (file)
index 0000000..8e13f25
Binary files /dev/null and b/swing2swt.jar differ