Formatted source
[jalview.git] / src / jalview / gui / Desktop.java
index bfbdc1d..e239a10 100755 (executable)
-/********************\r
- * 2004 Jalview Reengineered\r
- * Barton Group\r
- * Dundee University\r
+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 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 jalview.schemes.*;\r
-import javax.swing.*;\r
 import java.awt.*;\r
+import java.awt.datatransfer.*;\r
+import java.awt.dnd.*;\r
 import java.awt.event.*;\r
+import javax.swing.*;\r
 \r
+import jalview.datamodel.*;\r
+import jalview.io.*;\r
 \r
-public class Desktop extends jalview.jbgui.GDesktop\r
+public class Desktop\r
+    extends jalview.jbgui.GDesktop implements DropTargetListener\r
 {\r
   public static JDesktopPane desktop;\r
   static int openFrameCount = 0;\r
-  static final int xOffset = 30, yOffset = 30;\r
+  static final int xOffset = 30;\r
+  static final int yOffset = 30;\r
 \r
   public Desktop()\r
   {\r
-    Image image =null;\r
-    try{\r
-      java.net.URL url = getClass().getResource("/images/BartonGroupBanner.gif");\r
-      if(url!=null)\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
+    catch (Exception ex)\r
+    {\r
+    }\r
 \r
     setTitle("Jalview 2005");\r
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r
-    setVisible(true);\r
     desktop = new JDesktopPane();\r
     desktop.setBackground(Color.white);\r
     setContentPane(desktop);\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
+    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
+      setBounds(Integer.parseInt(x), Integer.parseInt(y),\r
+                Integer.parseInt(width), Integer.parseInt(height));\r
     }\r
     else\r
-      setBounds( (int)(screenSize.width-900)/2,\r
-           (int)(screenSize.height-650)/2,\r
-          900 ,\r
-          650);\r
-\r
-this.addWindowListener(new WindowAdapter()\r
-{\r
-public void windowClosing(WindowEvent evt)\r
-{\r
- jalview.bin.Cache.setProperty("SCREEN_X",\r
-                               getBounds().x + "");\r
- jalview.bin.Cache.setProperty("SCREEN_Y",\r
-                               getBounds().y + "");\r
- jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");\r
- jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");\r
-}\r
-});\r
+    {\r
+      setBounds( (int) (screenSize.width - 900) / 2,\r
+                (int) (screenSize.height - 650) / 2, 900, 650);\r
+    }\r
 \r
-/////////Add a splashscreen on startup\r
+    this.addWindowListener(new WindowAdapter()\r
+    {\r
+      public void windowClosing(WindowEvent evt)\r
+      {\r
+        jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x +\r
+                                      "");\r
+        jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y +\r
+                                      "");\r
+        jalview.bin.Cache.setProperty("SCREEN_WIDTH",\r
+                                      getWidth() + "");\r
+        jalview.bin.Cache.setProperty("SCREEN_HEIGHT",\r
+                                      getHeight() + "");\r
+      }\r
+    });\r
+    setVisible(true);\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
+    /////////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
+    addInternalFrame(frame, "", 750, 160, false);\r
+    frame.setLocation( (int) ( (getWidth() - 750) / 2),\r
+                      (int) ( (getHeight() - 160) / 2));\r
+  }\r
+\r
+  public static void addInternalFrame(final JInternalFrame frame,\r
+                                      String title, int w, int h)\r
+  {\r
+    addInternalFrame(frame, title, w, h, true);\r
+  }\r
+\r
+  public static void addInternalFrame(final JInternalFrame frame,\r
+                                      String title, int w, int h,\r
+                                      boolean resizable)\r
+  {\r
     desktop.add(frame);\r
-    frame.setVisible(true);\r
     openFrameCount++;\r
+\r
     try\r
     {\r
       frame.setSelected(true);\r
     }\r
     catch (java.beans.PropertyVetoException e)\r
-    {}\r
-    frame.setResizable(true);\r
-    frame.setSize(845, 200);\r
-    frame.setLocation( (int)((getWidth()-845) /2), (int)((getHeight()-240) /2));\r
-    frame.setClosable(false);\r
-    frame.setIconifiable(false);\r
-    frame.setMaximizable(false);\r
+    {\r
+    }\r
+\r
+    frame.setTitle(title);\r
+    frame.setSize(w, h);\r
+    frame.setClosable(true);\r
+    frame.setResizable(resizable);\r
+    frame.setMaximizable(resizable);\r
+    frame.setIconifiable(resizable);\r
     frame.setFrameIcon(null);\r
+    frame.setLocation(xOffset * openFrameCount, yOffset * openFrameCount);\r
+    frame.toFront();\r
 \r
-  }\r
+    final JMenuItem menuItem = new JMenuItem(title);\r
+    frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()\r
+    {\r
+      public void internalFrameClosed(\r
+          javax.swing.event.InternalFrameEvent evt)\r
+      {\r
+        openFrameCount--;\r
+        windowMenu.remove(menuItem);\r
+      }\r
+      ;\r
+    });\r
 \r
-  public static void addInternalFrame(final JInternalFrame frame, String title, int w, int h)\r
-  {\r
-   desktop.add(frame);\r
-   frame.setVisible(true);\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
+    menuItem.addActionListener(new ActionListener()\r
     {\r
       public void actionPerformed(ActionEvent e)\r
       {\r
-        try{  frame.setSelected(true);   frame.setIcon(false); }\r
-        catch(java.beans.PropertyVetoException ex){};\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
 \r
-   windowMenu.add(menuItem);\r
- }\r
-\r
-\r
-\r
- public void inputLocalFileMenuItem_actionPerformed(ActionEvent e)\r
- {\r
-   JFileChooser chooser = new JFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY"));\r
-   chooser.setFileView(new JalviewFileView());\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.setProperty("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(Desktop.desktop,  "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(Desktop.desktop,"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(Desktop.desktop,"Couldn't locate " + url,\r
-                                   "URL not found",\r
-                                   JOptionPane.WARNING_MESSAGE);\r
-     return;\r
-   }\r
+    frame.setVisible(true);\r
+    windowMenu.add(menuItem);\r
+  }\r
 \r
-    LoadFile(url, "URL", format);\r
- }\r
+  public void dragEnter(DropTargetDragEvent evt)\r
+  {\r
+  }\r
+\r
+  public void dragExit(DropTargetEvent evt)\r
+  {\r
+  }\r
 \r
- public void inputTextboxMenuItem_actionPerformed(ActionEvent e)\r
- {\r
-   CutAndPasteTransfer cap = new CutAndPasteTransfer(true);\r
-   int accept =  JOptionPane.showInternalOptionDialog(Desktop.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
+  public void dragOver(DropTargetDragEvent evt)\r
+  {\r
+  }\r
 \r
+  public void dropActionChanged(DropTargetDragEvent evt)\r
+  {\r
+  }\r
 \r
-  if(accept == JOptionPane.YES_OPTION)\r
+  public void drop(DropTargetDropEvent evt)\r
   {\r
-    String format = IdentifyFile.Identify(cap.getText(), "Paste");\r
-    SequenceI [] sequences = null;\r
+    Transferable t = evt.getTransferable();\r
 \r
-    if (FormatProperties.contains( format ))\r
-      sequences = FormatAdapter.read(cap.getText(), "Paste", format);\r
+    if (!t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))\r
+    {\r
+      return;\r
+    }\r
+\r
+    evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);\r
 \r
+    try\r
+    {\r
+      java.util.List files = (java.util.List) t.getTransferData(DataFlavor.\r
+          javaFileListFlavor);\r
 \r
-      if(sequences!=null)\r
+      for (int i = 0; i < files.size(); i++)\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
+        String file = files.get(i).toString();\r
+        String protocol = "File";\r
+\r
+        if (file.endsWith(".jar"))\r
+        {\r
+          Jalview2XML.LoadJalviewAlign(file);\r
+        }\r
+        else\r
+        {\r
+          String format = jalview.io.IdentifyFile.Identify(file,\r
+              protocol);\r
+          LoadFile(file, protocol, format);\r
+        }\r
+      }\r
+    }\r
+    catch (Exception ex)\r
+    {\r
+      ex.printStackTrace();\r
+    }\r
+  }\r
+\r
+  public void inputLocalFileMenuItem_actionPerformed(ActionEvent e)\r
+  {\r
+    JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.\r
+        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
+      if (chooser.getSelectedFormat().equals("Jalview"))\r
+      {\r
+        jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", "Jalivew");\r
+        Jalview2XML.LoadJalviewAlign(choice);\r
       }\r
       else\r
-        JOptionPane.showInternalMessageDialog(Desktop.desktop, "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
+        String format = IdentifyFile.Identify(choice, "File");\r
+        jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", format);\r
+        LoadFile(choice, "File", format);\r
+      }\r
+    }\r
+  }\r
 \r
-   }\r
- }\r
+  public void LoadFile(String file, String protocol, String format)\r
+  {\r
+    LoadingThread loader = new LoadingThread(file, protocol, format);\r
+    loader.start();\r
+  }\r
 \r
-/*\r
-* Exit the program\r
-*/\r
- public void quit_actionPerformed(ActionEvent e)\r
- {\r
-   if(jalview.bin.Jalview.applet!=null)\r
-     jalview.bin.Jalview.applet.destroy();\r
-    else\r
-      System.exit(0);\r
- }\r
+  public void inputURLMenuItem_actionPerformed(ActionEvent e)\r
+  {\r
+    String url = JOptionPane.showInternalInputDialog(Desktop.desktop,\r
+        "Enter url of input file", "Input alignment from URL",\r
+        JOptionPane.QUESTION_MESSAGE, null, null, "http://www.")\r
+        .toString();\r
+\r
+    if (url == null)\r
+    {\r
+      return;\r
+    }\r
+\r
+    String format = IdentifyFile.Identify(url, "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
+    LoadFile(url, "URL", format);\r
+  }\r
 \r
+  public void inputTextboxMenuItem_actionPerformed(ActionEvent e)\r
+  {\r
+    CutAndPasteTransfer cap = new CutAndPasteTransfer();\r
+    cap.setForInput();\r
+    Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);\r
+  }\r
 \r
- public void aboutMenuItem_actionPerformed(ActionEvent e)\r
- {\r
-   JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
-                                         "JalView 2005"\r
-                                       +"\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
-                                       +"\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
+   * Exit the program\r
+   */\r
+  public void quit_actionPerformed(ActionEvent e)\r
+  {\r
+    if (jalview.bin.Jalview.applet != null)\r
+    {\r
+      jalview.bin.Jalview.applet.destroy();\r
+    }\r
+    else\r
+    {\r
+      System.exit(0);\r
+    }\r
+  }\r
 \r
- public void documentationMenuItem_actionPerformed(ActionEvent e)\r
- {\r
-   try\r
-   {\r
+  public void aboutMenuItem_actionPerformed(ActionEvent e)\r
+  {\r
+    JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+                                          "JalView 2005 version " +\r
+                                          jalview.bin.Cache.VERSION +\r
+                                          "; last updated: " +\r
+                                          jalview.bin.Cache.BUILD_DATE +\r
+                                          "\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 12;426-7.",\r
+                                          "About Jalview",\r
+                                          JOptionPane.INFORMATION_MESSAGE);\r
+  }\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
+      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.setLocation(new Point(200, 50));\r
-      hb.setSize(new Dimension(800,700));\r
+      hb.setSize(new Dimension(800, 700));\r
       hb.setCurrentID("home");\r
       hb.setDisplayed(true);\r
-   }\r
-   catch (Exception ex)\r
-   {\r
-     ex.printStackTrace();\r
-   }\r
- }\r
-\r
- static JInternalFrame conservationSlider;\r
- static JInternalFrame PIDSlider;\r
- public static int setConservationSliderSource(AlignmentPanel ap, ColourSchemeI cs, String source)\r
- {\r
-   SliderPanel sp = null;\r
-\r
-   if(conservationSlider == null)\r
-   {\r
-     sp = new SliderPanel(ap, 30, true, cs);\r
-     conservationSlider = new JInternalFrame();\r
-     conservationSlider.setContentPane(sp);\r
-     conservationSlider.setResizable(false);\r
-     addInternalFrame(conservationSlider, "Conservation Colour Increment  ("+source+")", 420, 90);\r
-     conservationSlider.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()\r
-                  {\r
-                    public void internalFrameClosed(javax.swing.event.InternalFrameEvent e)\r
-                    {\r
-                      conservationSlider = null;\r
-                    }\r
-                  });\r
-   }\r
-   else\r
-   {\r
-       conservationSlider.setTitle("Conservation Colour Increment  ("+source+")");\r
-       sp = (SliderPanel)conservationSlider.getContentPane();\r
-       sp.cs = cs;\r
-   }\r
-\r
-   if(ap.av.alignment.getGroups()!=null)\r
-     sp.setAllGroupsCheckEnabled( true );\r
-   else\r
-     sp.setAllGroupsCheckEnabled( false);\r
-\r
-   return sp.getValue();\r
-\r
- }\r
-\r
- public static void hideConservationSlider()\r
- {\r
-  try{\r
-    conservationSlider.setClosed(true);\r
-    conservationSlider = null;\r
-  }catch(Exception ex){}\r
-}\r
+    }\r
+    catch (Exception ex)\r
+    {\r
+      ex.printStackTrace();\r
+    }\r
+  }\r
+\r
+  protected void preferences_actionPerformed(ActionEvent e)\r
+  {\r
+    Preferences pref = new Preferences();\r
+  }\r
+\r
+  public void saveState_actionPerformed(ActionEvent e)\r
+  {\r
+    JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.\r
+        getProperty(\r
+            "LAST_DIRECTORY"), new String[]\r
+        {"jar"},\r
+        new String[]\r
+        {"Jalview Project"}, "Jalview Project");\r
 \r
+    chooser.setFileView(new JalviewFileView());\r
+    chooser.setDialogTitle("Save State");\r
 \r
- public static void hidePIDSlider()\r
- {\r
-   try{\r
-     PIDSlider.setClosed(true);\r
-     PIDSlider = null;\r
-   }catch(Exception ex){}\r
- }\r
-\r
- public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs, String source)\r
- {\r
-   SliderPanel pid = null;\r
-   if(PIDSlider == null)\r
-   {\r
-     pid = new SliderPanel(ap, 50, false, cs);\r
-     PIDSlider = new JInternalFrame();\r
-     PIDSlider.setContentPane(pid);\r
-     PIDSlider.setResizable(false);\r
-     addInternalFrame(PIDSlider, "Percentage Identity Threshold ("+source+")", 420, 90);\r
-   }\r
-   else\r
-   {\r
-       PIDSlider.setTitle("Percentage Identity Threshold ("+source+")");\r
-       pid = (SliderPanel)PIDSlider.getContentPane();\r
-       pid.cs = cs;\r
-   }\r
-\r
-   if (ap.av.alignment.getGroups() != null)\r
-     pid.setAllGroupsCheckEnabled(true);\r
-   else\r
-     pid.setAllGroupsCheckEnabled(false);\r
-\r
-\r
-   return pid.getValue();\r
-\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
+      Jalview2XML.SaveState(choice);\r
+    }\r
+  }\r
+\r
+  public void loadState_actionPerformed(ActionEvent e)\r
+  {\r
+    JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.\r
+        getProperty(\r
+            "LAST_DIRECTORY"), new String[]\r
+        {"jar"},\r
+        new String[]\r
+        {"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
+      Jalview2XML.LoadJalviewAlign(choice);\r
+    }\r
+  }\r
 \r
+  class LoadingThread\r
+      extends Thread\r
+  {\r
+    String file;\r
+    String protocol;\r
+    String format;\r
+\r
+    public LoadingThread(String file, String protocol, String format)\r
+    {\r
+      this.file = file;\r
+      this.protocol = protocol;\r
+      this.format = format;\r
+    }\r
+\r
+    public void run()\r
+    {\r
+      SequenceI[] sequences = null;\r
+\r
+      if (FormatAdapter.formats.contains(format))\r
+      {\r
+        sequences = FormatAdapter.readFile(file, protocol, format);\r
+      }\r
+\r
+      if ( (sequences != null) && (sequences.length > 0))\r
+      {\r
+        AlignFrame af = new AlignFrame(new Alignment(sequences));\r
+        addInternalFrame(af, file, AlignFrame.NEW_WINDOW_WIDTH,\r
+                         AlignFrame.NEW_WINDOW_HEIGHT);\r
+        af.currentFileFormat = format;\r
+        af.statusBar.setText("Successfully loaded file " + file);\r
+\r
+        try\r
+        {\r
+          af.setMaximum(Preferences.showFullscreen);\r
+        }\r
+        catch (Exception ex)\r
+        {\r
+        }\r
+      }\r
+      else\r
+      {\r
+        JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+                                              "Couldn't open file.\n" +\r
+                                              "Formats currently supported are\n" +\r
+                                              "Fasta, MSF, Clustal, BLC, PIR, MSP, and PFAM" // JBPNote - message should be generated through FormatAdapter!\r
+                                              , "Error loading file",\r
+                                              JOptionPane.WARNING_MESSAGE);\r
+      }\r
+    }\r
+  }\r
 }\r