header updated
[jalview.git] / src / jalview / gui / Desktop.java
index cd01cf8..9d58c7b 100755 (executable)
-/********************\r
- * 2004 Jalview Reengineered\r
- * Barton Group\r
- * Dundee University\r
+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
  *\r
- * AM Waterhouse\r
- *******************/\r
-\r
-\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+ */\r
 package jalview.gui;\r
 \r
-import jalview.gui.*;\r
 import jalview.io.*;\r
-import jalview.datamodel.*;\r
-import javax.swing.*;\r
+\r
 import java.awt.*;\r
+import java.awt.datatransfer.*;\r
+import java.awt.dnd.*;\r
 import java.awt.event.*;\r
+import java.util.*;\r
+\r
+import javax.swing.*;\r
 \r
 \r
+/**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @author $author$\r
+ * @version $Revision$\r
+ */\r
 public class Desktop extends jalview.jbgui.GDesktop\r
+    implements DropTargetListener, ClipboardOwner\r
 {\r
-  public static JDesktopPane desktop;\r
-  static int openFrameCount = 0;\r
-  static final int xOffset = 30, yOffset = 30;\r
-  static boolean splashScreenVisible = false;\r
-\r
-  public Desktop()\r
-  {\r
-    Image image =null;\r
-    try{\r
-      java.net.URL url = getClass().getResource("/BartonGroupBanner.gif");\r
-      if(url!=null)\r
+    /** DOCUMENT ME!! */\r
+    public static Desktop instance;\r
+    public static JDesktopPane desktop;\r
+    static int openFrameCount = 0;\r
+    static final int xOffset = 30;\r
+    static final int yOffset = 30;\r
+    public static jalview.ws.Discoverer discoverer;\r
+\r
+    public static Object [] jalviewClipboard;\r
+\r
+    static int fileLoadingCount= 0;\r
+\r
+    /**\r
+     * Creates a new Desktop object.\r
+     */\r
+    public Desktop()\r
+    {\r
+        instance = this;\r
+\r
+        Image image = null;\r
+\r
+        try\r
+        {\r
+            java.net.URL url = getClass().getResource("/images/logo.gif");\r
+\r
+            if (url != null)\r
+            {\r
+                image = java.awt.Toolkit.getDefaultToolkit().createImage(url);\r
+\r
+                MediaTracker mt = new MediaTracker(this);\r
+                mt.addImage(image, 0);\r
+                mt.waitForID(0);\r
+                setIconImage(image);\r
+            }\r
+        }\r
+        catch (Exception ex)\r
+        {\r
+        }\r
+\r
+        setTitle("Jalview "+jalview.bin.Cache.getProperty("VERSION"));\r
+        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r
+        desktop = new JDesktopPane();\r
+        desktop.setBackground(Color.white);\r
+        getContentPane().setLayout(new BorderLayout());\r
+        getContentPane().add(desktop, BorderLayout.CENTER);\r
+        desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);\r
+\r
+        // This line prevents Windows Look&Feel resizing all new windows to maximum\r
+        // if previous window was maximised\r
+        desktop.setDesktopManager(new DefaultDesktopManager());\r
+\r
+        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();\r
+        String x = jalview.bin.Cache.getProperty("SCREEN_X");\r
+        String y = jalview.bin.Cache.getProperty("SCREEN_Y");\r
+        String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH");\r
+        String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT");\r
+\r
+        if ((x != null) && (y != null) && (width != null) && (height != null))\r
+        {\r
+            setBounds(Integer.parseInt(x), Integer.parseInt(y),\r
+                Integer.parseInt(width), Integer.parseInt(height));\r
+        }\r
+        else\r
+        {\r
+            setBounds((int) (screenSize.width - 900) / 2,\r
+                (int) (screenSize.height - 650) / 2, 900, 650);\r
+        }\r
+\r
+        this.addWindowListener(new WindowAdapter()\r
+            {\r
+                public void windowClosing(WindowEvent evt)\r
+                {\r
+                    quit();\r
+                }\r
+            });\r
+\r
+        this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));\r
+\r
+        /////////Add a splashscreen on startup\r
+        /////////Add a splashscreen on startup\r
+        JInternalFrame frame = new JInternalFrame();\r
+\r
+        SplashScreen splash = new SplashScreen(frame, image);\r
+        frame.setContentPane(splash);\r
+        frame.setLayer(JLayeredPane.PALETTE_LAYER);\r
+        frame.setLocation((int) ((getWidth() - 750) / 2),\r
+            (int) ((getHeight() - 160) / 2));\r
+\r
+        addInternalFrame(frame, "", 750, 160, false);\r
+\r
+        discoverer=new jalview.ws.Discoverer(); // Only gets started if gui is displayed.\r
+\r
+    }\r
+\r
+    /**\r
+     * DOCUMENT ME!\r
+     *\r
+     * @param frame DOCUMENT ME!\r
+     * @param title DOCUMENT ME!\r
+     * @param w DOCUMENT ME!\r
+     * @param h DOCUMENT ME!\r
+     */\r
+    public static synchronized void addInternalFrame(final JInternalFrame frame,\r
+        String title, int w, int h)\r
+    {\r
+        addInternalFrame(frame, title, w, h, true);\r
+    }\r
+\r
+    /**\r
+     * DOCUMENT ME!\r
+     *\r
+     * @param frame DOCUMENT ME!\r
+     * @param title DOCUMENT ME!\r
+     * @param w DOCUMENT ME!\r
+     * @param h DOCUMENT ME!\r
+     * @param resizable DOCUMENT ME!\r
+     */\r
+    public static synchronized void addInternalFrame(final JInternalFrame frame,\r
+        String title, int w, int h, boolean resizable)\r
+    {\r
+\r
+      frame.setTitle(title);\r
+      if(frame.getWidth()<1 || frame.getHeight()<1)\r
+      {\r
+        frame.setSize(w, h);\r
+      }\r
+      // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN\r
+      // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN\r
+      // IF JALVIEW IS RUNNING HEADLESS\r
+      /////////////////////////////////////////////////\r
+      if (System.getProperty("java.awt.headless") != null\r
+          && System.getProperty("java.awt.headless").equals("true"))\r
+      {\r
+        return;\r
+      }\r
+\r
+\r
+        openFrameCount++;\r
+\r
+        frame.setVisible(true);\r
+        frame.setClosable(true);\r
+        frame.setResizable(resizable);\r
+        frame.setMaximizable(resizable);\r
+        frame.setIconifiable(resizable);\r
+        frame.setFrameIcon(null);\r
+\r
+        if (frame.getX()<1 && frame.getY()<1)\r
+       {\r
+         frame.setLocation(xOffset * openFrameCount, yOffset * ((openFrameCount-1)%10)+yOffset);\r
+       }\r
+\r
+        final JMenuItem menuItem = new JMenuItem(title);\r
+        frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()\r
+            {\r
+              public void internalFrameActivated(javax.swing.event.\r
+                                                 InternalFrameEvent evt)\r
+              {\r
+                JInternalFrame itf = desktop.getSelectedFrame();\r
+                if (itf != null)\r
+                  itf.requestFocus();\r
+\r
+              }\r
+\r
+                public void internalFrameClosed(\r
+                    javax.swing.event.InternalFrameEvent evt)\r
+                {\r
+                    openFrameCount--;\r
+                    windowMenu.remove(menuItem);\r
+                    JInternalFrame itf = desktop.getSelectedFrame();\r
+                       if (itf != null)\r
+                        itf.requestFocus();\r
+                }\r
+                ;\r
+            });\r
+\r
+        menuItem.addActionListener(new ActionListener()\r
+            {\r
+                public void actionPerformed(ActionEvent e)\r
+                {\r
+                    try\r
+                    {\r
+                        frame.setSelected(true);\r
+                        frame.setIcon(false);\r
+                    }\r
+                    catch (java.beans.PropertyVetoException ex)\r
+                    {\r
+\r
+                    }\r
+                }\r
+            });\r
+\r
+        windowMenu.add(menuItem);\r
+\r
+        desktop.add(frame);\r
+        frame.toFront();\r
+        try{\r
+          frame.setSelected(true);\r
+          frame.requestFocus();\r
+        }catch(java.beans.PropertyVetoException ve)\r
+        {}\r
+    }\r
+\r
+    public void lostOwnership(Clipboard clipboard, Transferable contents)\r
+    {\r
+      Desktop.jalviewClipboard = null;\r
+    }\r
+\r
+    public void dragEnter(DropTargetDragEvent evt)\r
+    {}\r
+\r
+    public void dragExit(DropTargetEvent evt)\r
+    {}\r
+\r
+    public void dragOver(DropTargetDragEvent evt)\r
+    {}\r
+\r
+    public void dropActionChanged(DropTargetDragEvent evt)\r
+    {}\r
+\r
+    /**\r
+     * DOCUMENT ME!\r
+     *\r
+     * @param evt DOCUMENT ME!\r
+     */\r
+    public void drop(DropTargetDropEvent evt)\r
+    {\r
+        Transferable t = evt.getTransferable();\r
+        java.util.List files = null;\r
+\r
+        try\r
+        {\r
+          DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");\r
+          if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))\r
+          {\r
+            //Works on Windows and MacOSX\r
+            evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);\r
+            files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);\r
+          }\r
+          else if (t.isDataFlavorSupported(uriListFlavor))\r
+          {\r
+            // This is used by Unix drag system\r
+            evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);\r
+            String data = (String) t.getTransferData(uriListFlavor);\r
+            files = new java.util.ArrayList(1);\r
+            for (java.util.StringTokenizer st = new java.util.StringTokenizer(\r
+                data,\r
+                "\r\n");\r
+                 st.hasMoreTokens(); )\r
+            {\r
+              String s = st.nextToken();\r
+              if (s.startsWith("#"))\r
+              {\r
+                // the line is a comment (as per the RFC 2483)\r
+                continue;\r
+              }\r
+\r
+              java.net.URI uri = new java.net.URI(s);\r
+              java.io.File file = new java.io.File(uri);\r
+              files.add(file);\r
+            }\r
+          }\r
+        }\r
+        catch (Exception e)\r
+        {\r
+          e.printStackTrace();\r
+        }\r
+\r
+        if (files != null)\r
+        {\r
+          try\r
+          {\r
+            for (int i = 0; i < files.size(); i++)\r
+            {\r
+              String file = files.get(i).toString();\r
+              String protocol = FormatAdapter.FILE;\r
+              String format = null;\r
+\r
+              if (file.endsWith(".jar"))\r
+              {\r
+                format = "Jalview";\r
+\r
+              }\r
+              else\r
+              {\r
+                format = new IdentifyFile().Identify(file,\r
+                                                          protocol);\r
+              }\r
+\r
+\r
+              new FileLoader().LoadFile(file, protocol, format);\r
+\r
+            }\r
+          }\r
+          catch (Exception ex)\r
+          {\r
+            ex.printStackTrace();\r
+          }\r
+        }\r
+    }\r
+\r
+    /**\r
+     * DOCUMENT ME!\r
+     *\r
+     * @param e DOCUMENT ME!\r
+     */\r
+    public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)\r
+    {\r
+        JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(\r
+                    "LAST_DIRECTORY"),\r
+                new String[]\r
+                {\r
+                    "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",\r
+                    "jar"\r
+                },\r
+                new String[]\r
+                {\r
+                    "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"\r
+                }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));\r
+\r
+        chooser.setFileView(new JalviewFileView());\r
+        chooser.setDialogTitle("Open local file");\r
+        chooser.setToolTipText("Open");\r
+\r
+        int value = chooser.showOpenDialog(this);\r
+\r
+        if (value == JalviewFileChooser.APPROVE_OPTION)\r
+        {\r
+            String choice = chooser.getSelectedFile().getPath();\r
+            jalview.bin.Cache.setProperty("LAST_DIRECTORY",\r
+                chooser.getSelectedFile().getParent());\r
+\r
+            String format = null;\r
+            if (chooser.getSelectedFormat().equals("Jalview"))\r
+            {\r
+                format = "Jalview";\r
+            }\r
+            else\r
+            {\r
+                format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);\r
+            }\r
+\r
+            if (viewport != null)\r
+              new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format);\r
+            else\r
+              new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);\r
+        }\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * DOCUMENT ME!\r
+     *\r
+     * @param e DOCUMENT ME!\r
+     */\r
+    public void inputURLMenuItem_actionPerformed(AlignViewport viewport)\r
+    {\r
+      // This construct allows us to have a wider textfield\r
+      // for viewing\r
+      JLabel label = new JLabel("Enter URL of Input File");\r
+      final JComboBox history = new JComboBox();\r
+\r
+      JPanel panel = new JPanel(new GridLayout(2,1));\r
+      panel.add(label);\r
+      panel.add(history);\r
+      history.setPreferredSize(new Dimension(400,20));\r
+      history.setEditable(true);\r
+      history.addItem("http://www.");\r
+\r
+      String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");\r
+\r
+      StringTokenizer st;\r
+\r
+      if (historyItems != null)\r
       {\r
-        image = java.awt.Toolkit.getDefaultToolkit().createImage(url);\r
-        MediaTracker mt = new MediaTracker(this);\r
-        mt.addImage(image, 0);\r
-        mt.waitForID(0);\r
-        setIconImage(image);\r
+        st = new StringTokenizer(historyItems, "\t");\r
+\r
+        while (st.hasMoreTokens())\r
+        {\r
+          history.addItem(st.nextElement());\r
+        }\r
       }\r
 \r
-    }catch(Exception ex){}\r
-\r
-    setTitle("Jalview 2005");\r
-    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r
-    setVisible(true);\r
-    desktop = new JDesktopPane();\r
-    setContentPane(desktop);\r
-    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);\r
-\r
-    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();\r
-    setBounds( (int)(screenSize.getWidth()-1200)/2,\r
-               (int)(screenSize.getHeight()-800)/2,\r
-              1200 ,\r
-              800);\r
-\r
-\r
-   /////////Add a splashscreen on startup\r
-    JInternalFrame frame = new JInternalFrame();\r
-\r
-    SplashScreen splash = new SplashScreen(frame, image);\r
-    frame.setContentPane(splash);\r
-    addInternalFrame(frame, "",820,200);\r
-    splashScreenVisible = true;\r
-\r
-    frame.setLocation( (int)((getWidth()-820) /2), (int)((getHeight()-240) /2));\r
-    frame.setClosable(false);\r
-    frame.setIconifiable(false);\r
-    frame.setMaximizable(false);\r
-    frame.setFrameIcon(null);\r
-  }\r
-\r
-  public static void splashScreenClosing()\r
-  {\r
-    splashScreenVisible = false;\r
-    JInternalFrame [] frames  = desktop.getAllFrames();\r
-    for(int i=0; i<frames.length; i++)\r
+       int reply = JOptionPane.showInternalConfirmDialog(desktop,\r
+          panel, "Input Alignment From URL",\r
+          JOptionPane.OK_CANCEL_OPTION );\r
+\r
+\r
+        if (reply != JOptionPane.OK_OPTION )\r
+        {\r
+            return;\r
+        }\r
+\r
+        String url = history.getSelectedItem().toString();\r
+\r
+        if (url.toLowerCase().endsWith(".jar"))\r
+        {\r
+          if (viewport != null)\r
+            new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, "Jalview");\r
+          else\r
+            new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");\r
+        }\r
+        else\r
+        {\r
+          String format = new IdentifyFile().Identify(url, FormatAdapter.URL);\r
+\r
+          if (format.equals("URL NOT FOUND"))\r
+          {\r
+            JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+                                                  "Couldn't locate " + url,\r
+                                                  "URL not found",\r
+                                                  JOptionPane.WARNING_MESSAGE);\r
+\r
+            return;\r
+          }\r
+\r
+          if (viewport != null)\r
+            new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);\r
+          else\r
+            new FileLoader().LoadFile(url, FormatAdapter.URL, format);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * DOCUMENT ME!\r
+     *\r
+     * @param e DOCUMENT ME!\r
+     */\r
+    public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)\r
+    {\r
+        CutAndPasteTransfer cap = new CutAndPasteTransfer();\r
+        cap.setForInput(viewport);\r
+        Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);\r
+    }\r
+\r
+    /*\r
+     * Exit the program\r
+     */\r
+    public void quit()\r
     {\r
-      frames[i].invalidate();\r
-      frames[i].setVisible(true);\r
-      frames[i].validate();\r
+        jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");\r
+        jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");\r
+        jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");\r
+        jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");\r
+        System.exit(0);\r
     }\r
-  }\r
-\r
-  public static void addInternalFrame(final JInternalFrame frame, String title, int w, int h)\r
-  {\r
-   if(!splashScreenVisible)\r
-      frame.setVisible(true); //necessary as of 1.3\r
-   desktop.add(frame);\r
-   openFrameCount++;\r
-   try {\r
-       frame.setSelected(true);\r
-   } catch (java.beans.PropertyVetoException e) {}\r
-   frame.setTitle(title);\r
-   frame.setResizable(true);\r
-   frame.setSize(w,h);\r
-   frame.setClosable(true);\r
-   frame.setMaximizable(true);\r
-   frame.setIconifiable(true);\r
-   frame.setLocation(xOffset*openFrameCount, yOffset*openFrameCount);\r
-   frame.toFront();\r
-   final JMenuItem menuItem = new JMenuItem(title);\r
-   frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()\r
-                                   { public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)\r
-                                     {\r
-                                       openFrameCount--;\r
-                                       windowMenu.remove(menuItem);\r
-                                     };\r
-                                   });\r
-\r
-   menuItem.addActionListener(new ActionListener()\r
+\r
+    /**\r
+     * DOCUMENT ME!\r
+     *\r
+     * @param e DOCUMENT ME!\r
+     */\r
+    public void aboutMenuItem_actionPerformed(ActionEvent e)\r
     {\r
-      public void actionPerformed(ActionEvent e)\r
+      StringBuffer message = new StringBuffer("JalView version " +\r
+                                              jalview.bin.Cache.getProperty(\r
+          "VERSION") +\r
+                                              "; last updated: " +\r
+                                              jalview.bin.\r
+                                              Cache.getDefault("BUILD_DATE", "unknown"));\r
+\r
+      if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(\r
+          jalview.bin.Cache.getProperty("VERSION")))\r
       {\r
-        try{  frame.setSelected(true);   frame.setIcon(false); }\r
-        catch(java.beans.PropertyVetoException ex){};\r
+        message.append("\n\n!! Jalview version "\r
+                       + jalview.bin.Cache.getProperty("LATEST_VERSION")\r
+                       + " is available for download from http://www.jalview.org !!\n");\r
+\r
       }\r
-    });\r
-\r
-   windowMenu.add(menuItem);\r
- }\r
-\r
-\r
-\r
- public void inputLocalFileMenuItem_actionPerformed(ActionEvent e)\r
- {\r
-   JFileChooser chooser = new JFileChooser(jalview.bin.Cache.LAST_DIRECTORY);\r
-   chooser.setDialogTitle("Open local file");\r
-   chooser.setToolTipText("Open");\r
-   int value = chooser.showOpenDialog(this);\r
-   if(value == JFileChooser.APPROVE_OPTION)\r
-   {\r
-     String choice =  chooser.getSelectedFile().getPath();\r
-     jalview.bin.Cache.LAST_DIRECTORY = choice;\r
-     String format = IdentifyFile.Identify(choice, "File");\r
-     LoadFile(choice, "File", format);\r
-   }\r
- }\r
-\r
- public void LoadFile(String file, String protocol,  String format)\r
- {\r
-   SequenceI [] sequences = null;\r
-\r
-   if (FormatProperties.contains(format))\r
-       sequences = FormatAdapter.read(file, protocol, format);\r
-\r
-   if (sequences != null)\r
-   {\r
-     AlignFrame af = new AlignFrame(new Alignment(sequences));\r
-     addInternalFrame(af, file, 700, 500);\r
-     af.statusBar.setText("Successfully loaded file " + file);\r
-\r
-\r
-   }\r
-   else\r
-     JOptionPane.showInternalMessageDialog(this,  "Couldn't open file.\n"\r
-                          + "Formats currently supported are\n"\r
-                          + "Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM"\r
-                          ,"Error loading file",\r
-                                   JOptionPane.WARNING_MESSAGE);\r
-\r
- }\r
-\r
- public void inputURLMenuItem_actionPerformed(ActionEvent e)\r
- {\r
-   String url = JOptionPane.showInternalInputDialog(this,"Enter url of input file",\r
-                                            "Input alignment from URL",\r
-                                            JOptionPane.QUESTION_MESSAGE);\r
-   if (url == null)\r
-     return;\r
-\r
-   String format = IdentifyFile.Identify(url, "URL");\r
-\r
-   System.out.println(format +" format");\r
-   if (format.equals("URL NOT FOUND"))\r
-   {\r
-     JOptionPane.showInternalMessageDialog(this,"Couldn't locate " + url,\r
-                                   "URL not found",\r
-                                   JOptionPane.WARNING_MESSAGE);\r
-     return;\r
-   }\r
-\r
-    LoadFile(url, "URL", format);\r
- }\r
-\r
- public void inputTextboxMenuItem_actionPerformed(ActionEvent e)\r
- {\r
-   CutAndPasteTransfer cap = new CutAndPasteTransfer(true);\r
-   int accept =  JOptionPane.showInternalOptionDialog(desktop, cap, "Cut & paste Alignment File",\r
-                                       JOptionPane.YES_NO_CANCEL_OPTION,\r
-                                       JOptionPane.PLAIN_MESSAGE,\r
-                                       null,\r
-                                       new Object[]{"Accept", "Cancel", }, null);\r
-\r
-\r
-  if(accept == JOptionPane.YES_OPTION)\r
-  {\r
-    String format = IdentifyFile.Identify(cap.getText(), "Paste");\r
-    SequenceI [] sequences = null;\r
-\r
-    if (FormatProperties.contains( format ))\r
-      sequences = FormatAdapter.read(cap.getText(), "Paste", format);\r
-\r
-\r
-      if(sequences!=null)\r
+\r
+      message.append( "\nAuthors:  Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +\r
+            "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +\r
+            "\nFor all issues relating to Jalview, email help@jalview.org" +\r
+            "\n\nIf  you use JalView, please cite:" +\r
+            "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +\r
+            "\nBioinformatics,  2004 20;426-7.");\r
+\r
+        JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+\r
+           message.toString(), "About Jalview",\r
+            JOptionPane.INFORMATION_MESSAGE);\r
+    }\r
+\r
+    /**\r
+     * DOCUMENT ME!\r
+     *\r
+     * @param e DOCUMENT ME!\r
+     */\r
+    public void documentationMenuItem_actionPerformed(ActionEvent e)\r
+    {\r
+        try\r
+        {\r
+            ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();\r
+            java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");\r
+            javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);\r
+\r
+            javax.help.HelpBroker hb = hs.createHelpBroker();\r
+            hb.setCurrentID("home");\r
+            hb.setDisplayed(true);\r
+        }\r
+        catch (Exception ex)\r
+        {\r
+            ex.printStackTrace();\r
+        }\r
+    }\r
+\r
+    /**\r
+     * DOCUMENT ME!\r
+     *\r
+     * @param e DOCUMENT ME!\r
+     */\r
+    protected void preferences_actionPerformed(ActionEvent e)\r
+    {\r
+        new Preferences();\r
+    }\r
+\r
+    /**\r
+     * DOCUMENT ME!\r
+     *\r
+     * @param e DOCUMENT ME!\r
+     */\r
+    public void saveState_actionPerformed(ActionEvent e)\r
+    {\r
+        JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(\r
+                    "LAST_DIRECTORY"), new String[] { "jar" },\r
+                new String[] { "Jalview Project" }, "Jalview Project");\r
+\r
+        chooser.setFileView(new JalviewFileView());\r
+        chooser.setDialogTitle("Save State");\r
+\r
+        int value = chooser.showSaveDialog(this);\r
+\r
+        if (value == JalviewFileChooser.APPROVE_OPTION)\r
+        {\r
+            java.io.File choice = chooser.getSelectedFile();\r
+            jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());\r
+            new Jalview2XML().SaveState(choice);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * DOCUMENT ME!\r
+     *\r
+     * @param e DOCUMENT ME!\r
+     */\r
+    public void loadState_actionPerformed(ActionEvent e)\r
+    {\r
+        JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(\r
+                    "LAST_DIRECTORY"), new String[] { "jar" },\r
+                new String[] { "Jalview Project" }, "Jalview Project");\r
+        chooser.setFileView(new JalviewFileView());\r
+        chooser.setDialogTitle("Restore state");\r
+\r
+        int value = chooser.showOpenDialog(this);\r
+\r
+        if (value == JalviewFileChooser.APPROVE_OPTION)\r
+        {\r
+            String choice = chooser.getSelectedFile().getAbsolutePath();\r
+            jalview.bin.Cache.setProperty("LAST_DIRECTORY",\r
+                chooser.getSelectedFile().getParent());\r
+            new Jalview2XML().LoadJalviewAlign(choice);\r
+        }\r
+    }\r
+\r
+  /*  public void vamsasLoad_actionPerformed(ActionEvent e)\r
+    {\r
+      JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.\r
+          getProperty("LAST_DIRECTORY"));\r
+\r
+      chooser.setFileView(new JalviewFileView());\r
+      chooser.setDialogTitle("Load Vamsas file");\r
+      chooser.setToolTipText("Import");\r
+\r
+      int value = chooser.showOpenDialog(this);\r
+\r
+      if (value == JalviewFileChooser.APPROVE_OPTION)\r
       {\r
-        AlignFrame af = new AlignFrame(new Alignment(sequences));\r
-        addInternalFrame(af, "Cut & Paste input - "+format, 700, 500);\r
-        af.statusBar.setText("Successfully pasted alignment file");\r
+        jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(null);\r
+        vs.load(\r
+            chooser.getSelectedFile().getAbsolutePath()\r
+            );\r
       }\r
-      else\r
-        JOptionPane.showInternalMessageDialog(this, "Couldn't read the pasted text.\n"\r
-                                      +"Formats currently supported are\n"\r
-                                      +"Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM",\r
-                                      "Error parsing text", JOptionPane.WARNING_MESSAGE);\r
 \r
+    }*/\r
 \r
-   }\r
- }\r
 \r
-/*\r
-* Exit the program\r
-*/\r
- public void quit_actionPerformed(ActionEvent e)\r
- {\r
-   this.setVisible(false);\r
-   System.exit(0);\r
- }\r
-\r
-\r
- protected void colourIndexMenuItem_actionPerformed(ActionEvent e)\r
- {\r
-   ColourKey colourKey = new ColourKey(null);\r
-   addInternalFrame(colourKey, "Colour scheme key", 400, 320);\r
- }\r
-\r
-\r
- public void aboutMenuItem_actionPerformed(ActionEvent e)\r
- {\r
-   JOptionPane.showInternalMessageDialog(desktop,\r
-                                         "JalView 2005"\r
-                                       +"\nAuthors:  Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse and Geoff Barton."\r
-                                       +"\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee."\r
-                                       +"\nIf  you use JalView, please cite:  \"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"",\r
-                                         "About Jalview",\r
-                                         JOptionPane.INFORMATION_MESSAGE);\r
- }\r
-\r
- public void documentationMenuItem_actionPerformed(ActionEvent e)\r
- {\r
-   try{\r
-     jalview.util.BrowserLauncher.openURL("http://jalview.org/documentation.html");\r
-   }catch(Exception ex){}\r
- }\r
+    public void inputSequence_actionPerformed(ActionEvent e)\r
+    {\r
+      new SequenceFetcher(null);\r
+    }\r
+\r
+    JPanel progressPanel;\r
+\r
+    public void startLoading(final String fileName)\r
+    {\r
+      if (fileLoadingCount == 0)\r
+      {\r
+        progressPanel = new JPanel(new BorderLayout());\r
+        JProgressBar progressBar = new JProgressBar();\r
+        progressBar.setIndeterminate(true);\r
+\r
+        progressPanel.add(new JLabel("Loading File: " + fileName + "   "),\r
+                          BorderLayout.WEST);\r
+\r
+        progressPanel.add(progressBar, BorderLayout.CENTER);\r
+\r
+        instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);\r
+      }\r
+      fileLoadingCount++;\r
+      validate();\r
+    }\r
 \r
+    public void stopLoading()\r
+    {\r
+      fileLoadingCount--;\r
+      if (fileLoadingCount < 1)\r
+      {\r
+        if(progressPanel!=null)\r
+        {\r
+          this.getContentPane().remove(progressPanel);\r
+          progressPanel = null;\r
+        }\r
+        fileLoadingCount = 0;\r
+      }\r
+      validate();\r
+    }\r
 \r
 }\r
+\r