Fixed stuff.
[FinalKeyGui.git] / src / fkgui / MainWin.java
index 6ea0865..3846489 100644 (file)
@@ -2,6 +2,7 @@ package fkgui;
 
 
 import java.util.Map;
+import java.util.Vector;
 import  java.util.prefs.*;
 import java.awt.*;
 import java.awt.event.ActionEvent;
@@ -21,6 +22,8 @@ import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
 import org.eclipse.swt.events.KeyEvent;
 import org.eclipse.swt.events.KeyListener;
 import org.eclipse.swt.events.SelectionAdapter;
@@ -28,6 +31,8 @@ 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.graphics.Color;
+import org.eclipse.swt.graphics.Device;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Control;
@@ -58,7 +63,6 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
 
        public Text txtLog;
        public Button btnConnect;
-       public Button chkAutoHide;
        public Label lblPort;
        public Label lblPassword;
        
@@ -74,25 +78,44 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
        SerialWorker fkSerial;
        private boolean sysTrayIconVisible;
        
-       Button btnActivateAccount;
-
+       Button btnOpenAccount;
+       private Color blackColor;
+       private Color grayColor;
+       private Color defaultBgColor;
+       private Color greenColor;
+       private Color redColor;
        
-       static final String PREF_PORT ="lastUsedPortPref"; //$NON-NLS-1$
-       static final String PREF_DEFAULT_DEVICE = "/dev/FinalKey"; //$NON-NLS-1$
-       static final String PREF_AUTOHIDE = "hideMainWinAfterConnect"; //$NON-NLS-1$
+       private static final String PREF_PORT ="lastUsedPortPref"; //$NON-NLS-1$
+       private static final String PREF_DEFAULT_DEVICE = "/dev/FinalKey"; //$NON-NLS-1$
+       private static final String PREF_AUTOHIDE = "hideMainWinAfterConnect"; //$NON-NLS-1$
        private static final String PREF_SORT_BY_ID_KEY = "sortAccountListById"; //$NON-NLS-1$
+       private static final String PREF_SHOW_ACCOUNT_ID_IN_NAME_KEY = "showAccountIdInName"; //$NON-NLS-1$
+       private static final String PREF_ALLOW_UPDATE_CHECK = "allowUpdateCheck"; //$NON-NLS-1$
+       private static final String PREF_SHOW_ACCOUNTS_READY_NOTICE = "showAccountsReadyNotice"; //$NON-NLS-1$
+
        public Composite cmpConnect;
        private Composite cmpAccounts;
        ListViewer lstAccounts;
+       private List lstAccountsControl;
        Label lblNumFree;
-       Button btnNewAccoount;
+       Button btnNewAccount;
+       Button chkCheckForUpdates;
        Boolean hiddenAtStart=false;
+       Button btnShowaccountsReady;
  
        //Icons
        private org.eclipse.swt.graphics.Image iconProgramOnline  = SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/finalkey.png");  //$NON-NLS-1$
        private org.eclipse.swt.graphics.Image iconProgramOffline  = SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/finalkey-big-offline.png");  //$NON-NLS-1$
        private Image iconSystrayOnline = Toolkit.getDefaultToolkit().createImage(getClass().getResource("gfx/systray-color.png"));  //$NON-NLS-1$
        private Image iconSystrayOffline= Toolkit.getDefaultToolkit().createImage(getClass().getResource("gfx/systray-offline.png"));  //$NON-NLS-1$
+       private TabItem tbtmSettings;
+       private Composite cmpSettings;
+       private Button chkAutoHide;
+       private Button chkSortByAccountId;
+       private Button chkShowAccountId;
+       private Thread updateCheckThread;
+       private Text txtFilter;
+       
        
        /**
         * Launch the application.
@@ -125,10 +148,13 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                Display display = Display.getDefault();
                createContents();
                addAccountsTab();
+               addSettingsTab();
                createSysTrayIcon();
 
                serialEvent(SerialState.Disconnected);
-               new Thread(new UpdateChecker(this)).start();
+
+
+               checkForUpdates();
 
                if( hiddenAtStart )
                {
@@ -145,6 +171,21 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                }
        }
        
+       private void checkForUpdates() {
+               if( prefs.getBoolean(PREF_ALLOW_UPDATE_CHECK, true) )
+               {
+                       if( updateCheckThread == null )
+                       {
+                               updateCheckThread = new Thread(new UpdateChecker(this));
+                               updateCheckThread.start();
+                       } else {
+                               System.out.println(Messages.MainWin_0);
+                       }
+               } else {
+                       System.out.println(Messages.MainWin_3);
+               }
+       }
+
        public void log( String str )
        {
                txtLog.append(str+"\n"); //$NON-NLS-1$
@@ -163,34 +204,33 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
        private void createSysTrayIcon()
        {
                sysTrayIconVisible=true;
-        //Check the SystemTray is supported
-        if (!SystemTray.isSupported()) {
-            log("SystemTray is not supported, app is useless"); //$NON-NLS-1$
-            return;
-        }
-        
-        try {
+               //Check the SystemTray is supported
+               if (!SystemTray.isSupported()) {
+                       log("SystemTray is not supported, app is useless"); //$NON-NLS-1$
+                       return;
+               }
+
+               try {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (Exception e1) {
                        e1.printStackTrace();
                } 
 
-        popup = new PopupMenu();
-        trayIcon =
-                new TrayIcon( iconSystrayOffline ); //$NON-NLS-1$
-        trayIcon.setToolTip("The Final Key - Hardware password manager"); //$NON-NLS-1$
-        trayIcon.setImageAutoSize(true);
-        final SystemTray tray = SystemTray.getSystemTray();
-       
-        // Create a pop-up menu components
-        showMain = new MenuItem(Messages.MainWin_7);
-        hideMain = new MenuItem(Messages.MainWin_8);
-
-        showMain.addActionListener(new ActionListener() {
+               popup = new PopupMenu();
+               trayIcon = new TrayIcon( iconSystrayOffline ); //$NON-NLS-1$
+               trayIcon.setToolTip("The Final Key - Hardware password manager"); //$NON-NLS-1$
+               trayIcon.setImageAutoSize(true);
+               final SystemTray tray = SystemTray.getSystemTray();
+
+               // Create a pop-up menu components
+               showMain = new MenuItem(Messages.MainWin_7);
+               hideMain = new MenuItem(Messages.MainWin_8);
+
+               showMain.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                                Display.getDefault().syncExec( new Runnable(){
-                                       
+
                                        public void run()
                                        {
                                                showFromTray();
@@ -199,41 +239,41 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                        }
 
                });
-        
-        hideMain.addActionListener(new ActionListener() {
+
+               hideMain.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                                Display.getDefault().syncExec( new Runnable(){
-                                       
+
                                        public void run()
                                        {
                                                hideToTray();
                                        }
                                } );
                        }
-                               
+
                });
 
-        clearSystray();
+               clearSystray();
+
 
+               trayIcon.setPopupMenu(popup);
+
+               try {
+                       tray.add(trayIcon);
+               } catch (AWTException e) {
+                       log("TrayIcon could not be added."); //$NON-NLS-1$
+               }
 
-        trayIcon.setPopupMenu(popup);
-       
-        try {
-            tray.add(trayIcon);
-        } catch (AWTException e) {
-               log("TrayIcon could not be added."); //$NON-NLS-1$
-        }      
-        
        }
-       
+
        private void hideToTray()
        {
                popup.remove(0);
                popup.insert(showMain, 0);
                shell.setVisible(false);
        }
-       
+
        private void showFromTray()
        {
                popup.remove(0);
@@ -241,23 +281,23 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                shell.setVisible(true);
                shell.forceActive();
        }
-       
+
        private void destroySysTrayIcon()
        {
                sysTrayIconVisible=false;
                SystemTray.getSystemTray().remove(trayIcon);
        }
-       
+
        private void clearSystray() {
                        popup.removeAll();
-               //Add components to pop-up menu
+                       //Add components to pop-up menu
                        if(shell.isVisible()==true)
                        {
                                popup.add(hideMain);
                        } else {
                                popup.add(showMain);
                        }
-               popup.addSeparator();
+                       popup.addSeparator();
        }
 
        public void shutDownApp()
@@ -272,13 +312,13 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                }
                System.exit(0);
        }
-       
+
        /**
         * Create contents of the window.
         */
        protected void createContents() {
-               
-               
+
+
                shell = new Shell();
                shell.setImage( iconProgramOffline ); //$NON-NLS-1$
                shell.setSize(711, 655);
@@ -286,7 +326,7 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
 
                prefs = Preferences.userNodeForPackage(this.getClass());
 
-               FkManager.getInstance().sortById( prefs.getBoolean(PREF_SORT_BY_ID_KEY, false) );               
+               FkManager.getInstance().sortById( prefs.getBoolean(PREF_SORT_BY_ID_KEY, false) );
 
                mySelf = this;
                shell.setLayout(new FillLayout(SWT.HORIZONTAL));
@@ -300,48 +340,39 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                cmpConnect = new Composite(tabFolder, SWT.BORDER);
                tbtmConnection.setControl(cmpConnect);
                cmpConnect.setLayout(new FormLayout());
-               
 
                btnConnect = new Button(cmpConnect, SWT.CENTER);
                btnConnect.setImage( SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/lightning.png") ); //$NON-NLS-1$
                FormData fd_btnConnect = new FormData();
+               fd_btnConnect.top = new FormAttachment(0, 8);
                fd_btnConnect.left = new FormAttachment(100, -125);
                fd_btnConnect.right = new FormAttachment(100, -10);
+               
                btnConnect.setLayoutData(fd_btnConnect);
 
                btnConnect.addSelectionListener(new SelectionAdapter() {
                        public void widgetSelected(SelectionEvent e) {
-                               
-                               
+
                                if( fkSerial!=null && fkSerial.state == SerialState.Connected )
                                {
                                        fkSerial.disconnect();
                                } else {
-                                       
                                        connect();
                                }
                        }
 
                });
                btnConnect.setText(Messages.MainWin_15);
-               
                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);
                txtPsw.setFocus();
                txtPsw.addKeyListener( new KeyListener() {
-                       
                        @Override
-                       public void keyReleased(KeyEvent arg0) {
+                       public void keyReleased(KeyEvent arg0) { }
 
-                               
-                       }
-                       
                        @Override
                        public void keyPressed(KeyEvent arg0) {
                                if( arg0.character==(char)13 )
@@ -350,35 +381,34 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                                }
                        }
                });
-               
+
                txtLog = new Text(cmpConnect, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI | SWT.WRAP);
+               fd_btnConnect.bottom = new FormAttachment(txtPsw, 0, SWT.BOTTOM);
                FormData fd_txtLog = new FormData();
-               fd_txtLog.top = new FormAttachment(btnConnect, 6);
-               fd_txtLog.left = new FormAttachment(0, 10);
-               fd_txtLog.right = new FormAttachment(100, -10);
-               fd_txtLog.bottom = new FormAttachment(100, -10);
+               fd_txtLog.bottom = new FormAttachment(100, -8);
+               fd_txtLog.top = new FormAttachment(btnConnect, 8, SWT.BOTTOM);
+               fd_txtLog.left = new FormAttachment(0, 8);
+               fd_txtLog.right = new FormAttachment(btnConnect,0, SWT.RIGHT);
                txtLog.setLayoutData(fd_txtLog);
                txtLog.setEditable(false);
-               
-               
+
                lblPort = new Label(cmpConnect, SWT.NONE);
                lblPort.setAlignment(SWT.RIGHT);
-               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"); //$NON-NLS-1$
-               
+               lblPort.setText(Messages.MainWin_4);
+
                txtDev = new Text(cmpConnect, SWT.BORDER);
+               fd_txtPsw.top = new FormAttachment(txtDev,4, SWT.BOTTOM);
+               fd_lblPort.top = new FormAttachment(txtDev,0,SWT.CENTER);
+               fd_lblPort.right = new FormAttachment(txtDev, -7);
                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.bottom = new FormAttachment(txtPsw, -6);
+               fd_txtDev.top = new FormAttachment(btnConnect,0,SWT.TOP);
                fd_txtDev.left = new FormAttachment(0, 102);
                txtDev.setLayoutData(fd_txtDev);
-               txtDev.setFont(SWTResourceManager.getFont("Cantarell", 9, SWT.NORMAL)); //$NON-NLS-1$
+//             txtDev.setFont(SWTResourceManager.getFont("Cantarell", 9, SWT.NORMAL)); //$NON-NLS-1$
                txtDev.setText( prefs.get(PREF_PORT, PREF_DEFAULT_DEVICE));
                lblPassword = new Label(cmpConnect, SWT.NONE);
                lblPassword.setAlignment(SWT.RIGHT);
@@ -389,27 +419,19 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                lblPassword.setLayoutData(fd_lblPassword);
                lblPassword.setText(Messages.MainWin_18);
 
-               chkAutoHide = new Button(cmpConnect, SWT.CHECK);
-               FormData fd_chkAutoHide = new FormData();
-               fd_chkAutoHide.top = new FormAttachment(btnConnect, 0, SWT.TOP);
-               fd_chkAutoHide.left = new FormAttachment(txtDev, 6);
-               fd_chkAutoHide.right = new FormAttachment(0, 501);
-               chkAutoHide.setLayoutData(fd_chkAutoHide);
-               chkAutoHide.setText(Messages.MainWin_19);
-
-               chkAutoHide.setSelection( prefs.getBoolean(PREF_AUTOHIDE, false)) ;
-
                animation = new Animation(cmpConnect, SWT.NONE, 4);
-
+               fd_txtDev.right = new FormAttachment(animation,-16, SWT.LEFT );
+               fd_txtPsw.right = new FormAttachment(animation,-16, SWT.LEFT );
+               
                FormData fd_animation = new FormData();
-               fd_animation.top = new FormAttachment(btnConnect, 0, SWT.CENTER);
-               fd_animation.right = new FormAttachment(btnConnect,-16);
+               fd_animation.right = new FormAttachment(btnConnect, -16);
+               fd_animation.top = new FormAttachment(0, 10);
 
                animation.setLayoutData(fd_animation);
 
                animation.setVisible(false);
                animation.setPlaying(false);
-               cmpConnect.setTabList(new Control[]{txtPsw, btnConnect, txtDev, chkAutoHide});
+               cmpConnect.setTabList(new Control[]{txtPsw, btnConnect, txtDev});
 
                log(Messages.MainWin_22);
 
@@ -451,12 +473,18 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                                log("Warning: Enviroment variable SWT_GTK3 is not set to 0, if FinalKey GUI looks weird or crashes after connecting, try export GTK_SWT3=0 before running."); //$NON-NLS-1$
                        }
                }
-
+               
+               Device display = Display.getCurrent();
+                blackColor = display.getSystemColor(SWT.COLOR_BLACK );
+                 grayColor = display.getSystemColor(SWT.COLOR_GRAY );
+                 defaultBgColor = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND );
+                 greenColor = display.getSystemColor(SWT.COLOR_DARK_GREEN );
+                 redColor = display.getSystemColor(SWT.COLOR_RED );            
+               
        }
 
        
        private void connect() {
-               prefs.putBoolean(PREF_AUTOHIDE, chkAutoHide.getSelection() );
                fkSerial = new SerialWorker(mySelf);
                prefs.put(PREF_PORT, txtDev.getText() );
                fkSerial.connect(txtDev.getText(),txtPsw.getText());
@@ -471,12 +499,14 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                clearSystray();
                lstAccounts.getList().removeAll();
 
+               Boolean showAccountId = prefs.getBoolean( PREF_SHOW_ACCOUNT_ID_IN_NAME_KEY, false);
+               
                for( FkManager.Account a : FkManager.getInstance().getList() )
                {
                        free--;
-                       lstAccounts.add( a );
+                       lstAccounts.add( a.showNumInName( showAccountId ) );
 
-                       Menu menu = new Menu(a.name+" ["+a.num+"]"); //$NON-NLS-1$ //$NON-NLS-1$ //$NON-NLS-2$
+                       Menu menu = new Menu(a.toString());
                        MenuItem both = new MenuItem(Messages.MainWin_25);
                        MenuItem usr = new MenuItem(Messages.MainWin_26);
                        MenuItem psw = new MenuItem(Messages.MainWin_27);
@@ -499,14 +529,14 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
 
                        popup.add(menu);
                }
-               
+
                lblNumFree.setText(" "+free+Messages.MainWin_32); //$NON-NLS-1$
                lblNumFree.pack();
                if( free == 0 )
                {
-                       btnNewAccoount.setVisible(false);
+                       btnNewAccount.setVisible(false);
                } else {
-                       btnNewAccoount.setVisible(true);
+                       btnNewAccount.setVisible(true);
                }
                
        }
@@ -541,7 +571,7 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                        trayIcon.setImage( iconSystrayOnline );
 
                        int numAccounts=FkManager.getInstance().getList().size();
-                       if( numAccounts>0 )
+                       if( numAccounts>0 && prefs.getBoolean( PREF_SHOW_ACCOUNTS_READY_NOTICE, true) )
                        {
                                trayIcon.displayMessage("FinalKey", numAccounts +" "+ (( numAccounts >1)?Messages.MainWin_1:Messages.MainWin_2), //$NON-NLS-1$ //$NON-NLS-2$
                                                TrayIcon.MessageType.INFO);
@@ -560,7 +590,6 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
 
                        lblPort.setEnabled(false);
                        lblPassword.setEnabled(false);
-                       chkAutoHide.setEnabled(false);
                        break;
                case Disconnected:
                        fkSerial=null;
@@ -578,7 +607,6 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
 
                        lblPort.setEnabled(true);
                        lblPassword.setEnabled(true);
-                       chkAutoHide.setEnabled(true);
                        txtPsw.setEnabled(true);
                        txtDev.setEnabled(true);
 
@@ -595,12 +623,12 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                                log(Messages.MainWin_44);
                        }
                        break;
-               
+
                case Working:
                        animation.setPlaying(false);
                        animation.setVisible(false);
                        break;
-                       
+
                default:
                        break;
                }
@@ -613,20 +641,33 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                {
                        tabFolder.getItem(1).dispose();
                }
+
+       }
+       
+       void updateFilteredList(Vector<Account> source)
+       {
+               lstAccounts.getList().removeAll();
+
+               Boolean showAccountId = prefs.getBoolean( PREF_SHOW_ACCOUNT_ID_IN_NAME_KEY, false);
                
+               for( FkManager.Account a : source )
+               {
+                       lstAccounts.add( a.showNumInName( showAccountId ) );
+               }
        }
 
        private void addAccountsTab() {
-               TabItem tbtmAccounts = new TabItem(tabFolder, SWT.NONE);
+
+               TabItem tbtmAccounts = new TabItem(tabFolder, SWT.NONE, 1);//TabItem(tabFolder, SWT.NONE);
                tbtmAccounts.setText(Messages.MainWin_45);
-               
+
                cmpAccounts = new Composite(tabFolder, SWT.BORDER);
                tbtmAccounts.setControl(cmpAccounts);
                cmpAccounts.setLayout(new FormLayout());
-               
-               btnNewAccoount = new Button(cmpAccounts, SWT.NONE);
-               btnNewAccoount.setImage(SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/new.png")); //$NON-NLS-1$
-               btnNewAccoount.addSelectionListener(new SelectionAdapter() {
+
+               btnNewAccount = new Button(cmpAccounts, SWT.NONE);
+               btnNewAccount.setImage(SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/new.png")); //$NON-NLS-1$
+               btnNewAccount.addSelectionListener(new SelectionAdapter() {
                        @Override
                        public void widgetSelected(SelectionEvent e) {
                                NewAccountDialog dialog = new NewAccountDialog(shell, shell.getStyle() );
@@ -638,64 +679,118 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                });
                FormData fd_btnNewAccoount = new FormData();
                fd_btnNewAccoount.right = new FormAttachment(100, -10);
-               fd_btnNewAccoount.top = new FormAttachment(0, 549);
+               fd_btnNewAccoount.top = new FormAttachment(100, -40);
                fd_btnNewAccoount.bottom = new FormAttachment(100, -6);
-               btnNewAccoount.setLayoutData(fd_btnNewAccoount);
-               btnNewAccoount.setText(Messages.MainWin_47);
-               
+               fd_btnNewAccoount.left = new FormAttachment(100, -200);
+
+               btnNewAccount.setLayoutData(fd_btnNewAccoount);
+               btnNewAccount.setText(Messages.MainWin_47);
+
+               lstAccounts = new ListViewer(cmpAccounts, SWT.BORDER | SWT.V_SCROLL);
+               lstAccountsControl = lstAccounts.getList();
+               lstAccountsControl.setLayoutData(new FormData());
+
                lblNumFree = new Label(cmpAccounts, SWT.NONE);
                lblNumFree.setText("Hello World!"); //$NON-NLS-1$
-               
                FormData fd_lblNumFree = new FormData();
-               fd_lblNumFree.bottom = new FormAttachment(100, -10);
+               fd_lblNumFree.left = new FormAttachment(lstAccountsControl,0,SWT.LEFT);
+               fd_lblNumFree.bottom = new FormAttachment(btnNewAccount, 0, SWT.CENTER);
                lblNumFree.setLayoutData(fd_lblNumFree);
-               
-               
-               lstAccounts = new ListViewer(cmpAccounts, SWT.BORDER | SWT.V_SCROLL);
-               List list = lstAccounts.getList();
-               fd_lblNumFree.left = new FormAttachment(list, 0, SWT.LEFT);
-               list.setLayoutData(new FormData());
+
+               btnOpenAccount = new Button(cmpAccounts, SWT.NONE);
+               fd_lblNumFree.right = new FormAttachment(btnOpenAccount, -224);
+               btnOpenAccount.setImage(SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/lightbulb.png")); //$NON-NLS-1$
+               FormData fd_btnOpenAccount = new FormData();
+               fd_btnOpenAccount.top = new FormAttachment(btnNewAccount, 0, SWT.TOP);
+               fd_btnOpenAccount.bottom = new FormAttachment(btnNewAccount, 0, SWT.BOTTOM);
+               fd_btnOpenAccount.right = new FormAttachment(btnNewAccount, -8, SWT.LEFT );
+               btnOpenAccount.setLayoutData(fd_btnOpenAccount);
+               btnOpenAccount.setText(Messages.MainWin_5);
+               btnOpenAccount.getShell().layout();
+               btnOpenAccount.setEnabled(false);
+
+
                FormData fd_lstAccounts = new FormData();
-               fd_lstAccounts.bottom = new FormAttachment(btnNewAccoount, -6);
-               
-               btnActivateAccount = new Button(cmpAccounts, SWT.NONE);
-               fd_btnNewAccoount.left = new FormAttachment(btnActivateAccount, 6);
-               btnActivateAccount.setImage(SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/lightbulb.png")); //$NON-NLS-1$
-               FormData fd_btnActivateAccount = new FormData();
-               fd_btnActivateAccount.right = new FormAttachment(100, -169);
-               fd_btnActivateAccount.bottom = new FormAttachment(btnNewAccoount, 0, SWT.BOTTOM);
-               fd_btnActivateAccount.top = new FormAttachment(btnNewAccoount, 0, SWT.TOP);
-               btnActivateAccount.setLayoutData(fd_btnActivateAccount);
                fd_lstAccounts.top = new FormAttachment(0, 10);
-               fd_lstAccounts.left = new FormAttachment(0, 10);
-               fd_lstAccounts.right = new FormAttachment(100, -10);
-               btnActivateAccount.setVisible(false);
+               fd_lstAccounts.bottom = new FormAttachment(btnNewAccount, -6);
                
-               Button btnByAccountId = new Button(cmpAccounts, SWT.CHECK);
-               fd_btnActivateAccount.left = new FormAttachment(btnByAccountId, 6);
-               fd_lblNumFree.right = new FormAttachment(btnByAccountId, -6);
-               btnByAccountId.addSelectionListener(new SelectionAdapter() {
+               txtFilter = new Text(cmpAccounts, SWT.BORDER);
+               txtFilter.setText(Messages.MainWin_10);
+               FormData fd_txtFilter = new FormData();
+               fd_txtFilter.left = new FormAttachment(lblNumFree, 8, SWT.RIGHT);
+               fd_txtFilter.bottom = new FormAttachment(btnOpenAccount,0, SWT.CENTER);
+               fd_txtFilter.right = new FormAttachment(btnOpenAccount, -8, SWT.LEFT);
+               txtFilter.setLayoutData(fd_txtFilter);
+               txtFilter.setForeground( grayColor );
+               txtFilter.addFocusListener( new FocusListener() {
                        @Override
-                       public void widgetSelected(SelectionEvent e) {
-                               Button btnAccId = (Button)e.getSource();
-                               FkManager.getInstance().sortById( btnAccId.getSelection() );
-                               prefs.putBoolean( PREF_SORT_BY_ID_KEY, btnAccId.getSelection() );
-                               updateAccountList();
+                       public void focusLost(FocusEvent arg0) {
+                               txtFilter.setText(Messages.MainWin_10);
+                               txtFilter.setForeground( grayColor );
+                               txtFilter.setBackground( defaultBgColor );
+                               btnOpenAccount.setEnabled(false);
+                       }
+                       
+                       @Override
+                       public void focusGained(FocusEvent arg0) {
+                               btnOpenAccount.setEnabled(false);
+                               updateFilteredList( FkManager.getInstance().getList() );
+                               txtFilter.setForeground( blackColor );
+                               txtFilter.setText(""); //$NON-NLS-1$
+                               
                        }
                });
-               FormData fd_btnByAccountId = new FormData();
-               fd_btnByAccountId.left = new FormAttachment(0, 139);
-               fd_btnByAccountId.right = new FormAttachment(100, -398);
-               fd_btnByAccountId.bottom = new FormAttachment(btnNewAccoount, 0, SWT.BOTTOM);
-               btnByAccountId.setLayoutData(fd_btnByAccountId);
-               btnByAccountId.setText(Messages.MainWin_btnByAccountId_text);
-               btnByAccountId.setSelection( prefs.getBoolean( PREF_SORT_BY_ID_KEY, false));
                
+               txtFilter.addKeyListener( new KeyListener() {
+                       
+
+                       
+                       @Override
+                       public void keyReleased(KeyEvent arg0) {
+                               btnOpenAccount.setEnabled(false);
+                               
+                               if( txtFilter.getText().length() == 0 )
+                               {
+                                       updateFilteredList( FkManager.getInstance().getList() );
+                                       txtFilter.setBackground( defaultBgColor );
+                               } else {
+                                       
+                                       Vector<Account> res = FkManager.getInstance().getList(txtFilter.getText());
+                                       
+                                       if( res.size() < 1 )
+                                       {
+                                               txtFilter.setBackground( redColor );
+       
+                                       } else if( res.size() == 1 )
+                                       {
+                                               txtFilter.setBackground( greenColor );
+                                               btnOpenAccount.setEnabled(true);
+                                               if( arg0.character==(char)13 )
+                                               {
+                                                       showTrigDialog(res.get(0));
+                                               }
+                                               
+                                       } else {
+                                               txtFilter.setBackground( defaultBgColor );
+                                       }
+                                       
+                                       updateFilteredList( res );
+                                       
+                               }
+                       }
+                       
+                       @Override
+                       public void keyPressed(KeyEvent arg0) {
+
+                       }
+               });
                
-               //lstAccounts.setLayoutData(fd_lstAccounts);
+               fd_lstAccounts.left = new FormAttachment(0, 10);
+               fd_lstAccounts.right = new FormAttachment(100, -10);
+
                lstAccounts.getControl().setLayoutData(fd_lstAccounts);
                lstAccounts.addDoubleClickListener( new IDoubleClickListener() {
-                       
+
                        @Override
                        public void doubleClick(DoubleClickEvent arg0) {
                                // TODO Auto-generated method stub
@@ -704,58 +799,135 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                                {
                                        Account acc = (Account)selection.getFirstElement();
                                        showTrigDialog(acc);
-                               } else {
-                                       System.out.println("Selected nothing."); //$NON-NLS-1$
                                }
-                               
-                               
                        }
 
 
                });
-               
+
                lstAccounts.addSelectionChangedListener( new ISelectionChangedListener() {
-                       
+
                        @Override
                        public void selectionChanged(SelectionChangedEvent arg0) {
                                StructuredSelection selection = (StructuredSelection) arg0.getSelection();
                                if( !selection.isEmpty() )
                                {
-                                       Account acc = (Account)selection.getFirstElement();
-                                       btnActivateAccount.setVisible(true);
-                                       btnActivateAccount.setText(acc.name);
-                                       
+                                       btnOpenAccount.setEnabled(true);
+
                                        //Remove any listeners
-                                       for( Listener s :btnActivateAccount.getListeners(SWT.Selection) )
+                                       for( Listener s :btnOpenAccount.getListeners(SWT.Selection) )
                                        {
-                                               btnActivateAccount.removeListener(SWT.Selection, s);
+                                               btnOpenAccount.removeListener(SWT.Selection, s);
                                        }
-                                       
-                                       btnActivateAccount.addSelectionListener( new SelectionListener() {
-                                               
+
+                                       btnOpenAccount.addSelectionListener( new SelectionListener() {
+
                                                @Override
                                                public void widgetSelected(SelectionEvent arg0) {
-                                                       
                                                        StructuredSelection selection = (StructuredSelection) lstAccounts.getSelection();
                                                        Account acc = (Account)selection.getFirstElement();
                                                        showTrigDialog(acc);
                                                }
-                                               
+
                                                @Override
                                                public void widgetDefaultSelected(SelectionEvent arg0) {
                                                        // TODO Auto-generated method stub
-                                                       
                                                }
                                        });
-                                       
                                }
                        }
                });
+
+               cmpAccounts.setTabList(new Control[]{lstAccountsControl, txtFilter, btnOpenAccount, btnNewAccount});
+       }
+
+       private void addSettingsTab()
+       {
+               tbtmSettings = new TabItem(tabFolder, SWT.NONE);
+               tbtmSettings.setText(Messages.MainWin_tbtmSettings_text);
+
+               cmpSettings = new Composite(tabFolder, SWT.BORDER);
+               tbtmSettings.setControl(cmpSettings);
+               cmpSettings.setLayout(new FormLayout());
+
+               chkAutoHide = new Button(cmpSettings, SWT.CHECK);
+               chkAutoHide.setText(Messages.MainWin_6);
+               chkAutoHide.setSelection( prefs.getBoolean( PREF_AUTOHIDE, false ) );
+               FormData fd_chkAutoHide = new FormData();
+               fd_chkAutoHide.top = new FormAttachment(0, 10);
+               fd_chkAutoHide.left = new FormAttachment(0, 10);
+               chkAutoHide.setLayoutData(fd_chkAutoHide);
+               chkAutoHide.addSelectionListener( new SelectionAdapter() {
+                       public void widgetSelected(SelectionEvent e) {
+                               prefs.putBoolean(PREF_AUTOHIDE, chkAutoHide.getSelection() );
+                       }
+               });
+
+               chkSortByAccountId = new Button(cmpSettings, SWT.CHECK);
+               chkSortByAccountId.setText(Messages.MainWin_9);
+               chkSortByAccountId.setSelection( prefs.getBoolean( PREF_SORT_BY_ID_KEY, false) );
+               FormData fd_btnSortByAccountId = new FormData();
+               fd_btnSortByAccountId.top = new FormAttachment(chkAutoHide, 6);
+               fd_btnSortByAccountId.left = new FormAttachment(chkAutoHide, 0, SWT.LEFT);
+               chkSortByAccountId.setLayoutData(fd_btnSortByAccountId);
+               chkSortByAccountId.addSelectionListener( new SelectionAdapter() {
+                       public void widgetSelected(SelectionEvent e) {
+                               prefs.putBoolean( PREF_SORT_BY_ID_KEY, chkSortByAccountId.getSelection() );
+                               FkManager.getInstance().sortById( chkSortByAccountId.getSelection() );
+                               updateAccountList();
+                       }
+               });
+
                
-                               
+               chkShowAccountId = new Button(cmpSettings, SWT.CHECK);
+               FormData fd_chkShowAccountId = new FormData();
+               fd_chkShowAccountId.top = new FormAttachment(chkSortByAccountId, 6);
+               fd_chkShowAccountId.left = new FormAttachment(chkAutoHide, 0, SWT.LEFT);
+               chkShowAccountId.setLayoutData(fd_chkShowAccountId);
+               chkShowAccountId.setText(Messages.MainWin_btnShowAccountId_text);
+               chkShowAccountId.setSelection( prefs.getBoolean(PREF_SHOW_ACCOUNT_ID_IN_NAME_KEY, false) );
+               chkShowAccountId.addSelectionListener( new SelectionAdapter() {
+                       public void widgetSelected(SelectionEvent e) {
+                               prefs.putBoolean( PREF_SHOW_ACCOUNT_ID_IN_NAME_KEY, chkShowAccountId.getSelection() );
+                               updateAccountList();
+                       }
+               });
+               
+               chkCheckForUpdates = new Button(cmpSettings, SWT.CHECK);
+               FormData fd_chkCheckForUpdates = new FormData();
+               fd_chkCheckForUpdates.left = new FormAttachment(chkAutoHide, 0, SWT.LEFT);
+               chkCheckForUpdates.setLayoutData(fd_chkCheckForUpdates);
+               chkCheckForUpdates.setText(Messages.MainWin_btnCheckForUpdates_text);
+               chkCheckForUpdates.setSelection( prefs.getBoolean( PREF_ALLOW_UPDATE_CHECK, true) );
+               chkCheckForUpdates.addSelectionListener( new SelectionAdapter() {
+                       public void widgetSelected(SelectionEvent e) {
+                               prefs.putBoolean( PREF_ALLOW_UPDATE_CHECK, chkCheckForUpdates.getSelection() );
+                               checkForUpdates();
+                       }
+               });
+               fd_chkCheckForUpdates.top = new FormAttachment(chkShowAccountId, 6);
+               
+               btnShowaccountsReady = new Button(cmpSettings, SWT.CHECK);
+               btnShowaccountsReady.setSelection( prefs.getBoolean( PREF_SHOW_ACCOUNTS_READY_NOTICE, true) );
+               FormData fd_btnShowaccountsReady = new FormData();
+               fd_btnShowaccountsReady.top = new FormAttachment(chkCheckForUpdates, 6);
+               fd_btnShowaccountsReady.left = new FormAttachment(chkAutoHide, 0, SWT.LEFT);
+               btnShowaccountsReady.setLayoutData(fd_btnShowaccountsReady);
+
+               btnShowaccountsReady.setText(Messages.MainWin_btnShowaccountsReady_text);
+               btnShowaccountsReady.addSelectionListener( new SelectionAdapter() {
+               public void widgetSelected(SelectionEvent e) {
+                       prefs.putBoolean( PREF_SHOW_ACCOUNTS_READY_NOTICE, btnShowaccountsReady.getSelection() );
+                       checkForUpdates();
+               }
+       });
+               
+
+
        }
 
        private void showTrigDialog(Account acc) {
+               Account selectedAccount = acc;
                TriggerDialog diag = new TriggerDialog(shell, shell.getStyle(), acc, mySelf );
 
                //shell.setMinimized(true);
@@ -764,13 +936,31 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                {
                        //shell.setMinimized(false);
                }
-               
+
+               //Check if the account still exists
+               Boolean deleted=true;
+               for( Account a : FkManager.getInstance().getList() )
+               {
+                       if( a.equals(selectedAccount) )
+                       {
+                               deleted=false;
+                               break;
+                       }
+               }
+
+               if(deleted)
+               {
+                       btnOpenAccount.setEnabled(false);
+               }
+
+               txtFilter.setFocus();
                shell.setEnabled(true);
-               
+
        }
 
        @Override
        public void updateCheckFinished(UpdateResultEvent event) {
+               updateCheckThread=null;
                switch(event.result)
                {
                case CHECK_FAILED:
@@ -786,6 +976,6 @@ public class MainWin implements ConsoleMsg, UpdateCheckResultListener {
                        dialog.open();  
                        break;
                }
-               
+
        }
 }