loading/saving changes
authoramwaterhouse <Andrew Waterhouse>
Thu, 19 May 2005 17:57:34 +0000 (17:57 +0000)
committeramwaterhouse <Andrew Waterhouse>
Thu, 19 May 2005 17:57:34 +0000 (17:57 +0000)
src/jalview/gui/AlignFrame.java

index 4fbdb72..300be96 100755 (executable)
@@ -32,18 +32,12 @@ public class AlignFrame extends GAlignFrame
   final AlignViewport viewport;\r
   public static final int NEW_WINDOW_WIDTH = 700;\r
   public static final int NEW_WINDOW_HEIGHT = 500;\r
+  public String currentFileFormat = "Jalview";\r
 \r
   public AlignFrame(AlignmentI al)\r
   {\r
-    try{\r
-      String ip = java.net.InetAddress.getLocalHost().getHostAddress();\r
-      if( !ip.startsWith("10."))\r
-        webService.setVisible(false);\r
-    }\r
-    catch(java.net.UnknownHostException e){}\r
     viewport = new AlignViewport(al);\r
 \r
-\r
     alignPanel = new AlignmentPanel(this, viewport);\r
     alignPanel.annotationPanel.adjustPanelHeight();\r
     alignPanel.annotationSpaceFillerHolder.setPreferredSize(alignPanel.annotationPanel.getPreferredSize());\r
@@ -67,34 +61,36 @@ public class AlignFrame extends GAlignFrame
 \r
   }\r
 \r
-  protected void saveAs_actionPerformed(ActionEvent e)\r
+  public void saveAlignmentMenu_actionPerformed(ActionEvent e)\r
   {\r
-    String suffix [] = null;\r
-    if(e.getActionCommand().equals("FASTA"))\r
-      suffix = new String[]{"fa", "fasta"};\r
-    else if(e.getActionCommand().equals("MSF"))\r
-      suffix = new String[]{"msf"};\r
-    else if(e.getActionCommand().equals("CLUSTAL"))\r
-      suffix = new String[]{"aln"};\r
-    else if(e.getActionCommand().equals("BLC"))\r
-      suffix = new String[]{"blc"};\r
-    else if(e.getActionCommand().equals("PIR"))\r
-      suffix = new String[]{"pir"};\r
-    else if(e.getActionCommand().equals("PFAM"))\r
-      suffix = new String[]{"pfam"};\r
-\r
-\r
     JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY")\r
-        , suffix, e.getActionCommand()+" file");\r
+        ,  new String[]{"fa, fasta, fastq", "aln",  "pfam", "msf", "pir","blc","jar"},\r
+          new String[]{"FASTA", "CLUSTAL", "PFAM", "MSF", "PIR", "BLC", "Jalview"},\r
+          currentFileFormat);\r
+\r
+    chooser.setAcceptAllFileFilterUsed(false);\r
     chooser.setFileView(new JalviewFileView());\r
-    chooser.setDialogTitle("Save Alignment to file - "+e.getActionCommand() +" format.");\r
+    chooser.setDialogTitle("Save Alignment to file");\r
     chooser.setToolTipText("Save");\r
     int value = chooser.showSaveDialog(this);\r
     if(value == JalviewFileChooser.APPROVE_OPTION)\r
     {\r
+      currentFileFormat  = chooser.getSelectedFormat();\r
+\r
+      if (currentFileFormat.equals("Jalview"))\r
+      {\r
+        String shortName = title.replace('/', '_');\r
+        title = title.replace('\\', '_');\r
+        String choice = chooser.getSelectedFile().getPath();\r
+        Jalview2XML.SaveState(this, System.currentTimeMillis(), shortName,\r
+                              choice);\r
+        // USE Jalview2XML to save this file\r
+        return;\r
+      }\r
+\r
       String choice =  chooser.getSelectedFile().getPath();\r
       jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);\r
-      String output = FormatAdapter.formatSequences(e.getActionCommand(), viewport.getAlignment().getSequences());\r
+      String output = FormatAdapter.formatSequences(currentFileFormat, viewport.getAlignment().getSequences());\r
       try{\r
         java.io.PrintWriter out = new java.io.PrintWriter( new java.io.FileWriter( choice )  );\r
         out.println(output);\r
@@ -205,6 +201,7 @@ public class AlignFrame extends GAlignFrame
   {\r
     // must make sure we add new sequence objects her, not refs to the existing sequences\r
     redoList.clear();\r
+\r
     SequenceI[] seq = new SequenceI[viewport.getAlignment().getHeight()];\r
     for(int i=0; i<viewport.getAlignment().getHeight(); i++)\r
     {\r
@@ -212,6 +209,7 @@ public class AlignFrame extends GAlignFrame
                              viewport.getAlignment().getSequenceAt(i).getSequence());\r
     }\r
 \r
+\r
     historyList.add(0, new Object[]{type,  seq} );\r
     updateEditMenuBar();\r
   }\r
@@ -234,6 +232,7 @@ public class AlignFrame extends GAlignFrame
       seq = (SequenceI[]) history[1];\r
       AlignmentAnnotation [] old = viewport.alignment.getAlignmentAnnotation();\r
       viewport.setAlignment( new Alignment(seq) );\r
+      viewport.alignment.setGapCharacter( Preferences.gapSymbol );\r
       updateEditMenuBar();\r
       for(int i=0; i<old.length; i++)\r
         viewport.alignment.addAnnotation(old[i]);\r
@@ -348,7 +347,13 @@ public class AlignFrame extends GAlignFrame
         SequenceI[] newSeqs = new SequenceI[seqs.size()];\r
         seqs.toArray(newSeqs);\r
         AlignFrame af = new AlignFrame(new Alignment(newSeqs));\r
-        Desktop.addInternalFrame(af, "Copied sequences", NEW_WINDOW_WIDTH, NEW_WINDOW_HEIGHT);\r
+        String newtitle = new String("Copied sequences");\r
+        if( title.startsWith("Copied sequences"))\r
+         newtitle = title;\r
+       else\r
+         newtitle = newtitle.concat("- from "+title);\r
+\r
+        Desktop.addInternalFrame(af, newtitle, NEW_WINDOW_WIDTH, NEW_WINDOW_HEIGHT);\r
       }\r
       else\r
       {\r
@@ -410,6 +415,7 @@ public class AlignFrame extends GAlignFrame
      Object [] history = (Object[])redoList.remove(0);\r
      SequenceI[] seq = (SequenceI[]) history[1];\r
      viewport.setAlignment( new Alignment(seq) );\r
+     viewport.alignment.setGapCharacter( Preferences.gapSymbol );\r
      updateEditMenuBar();\r
      viewport.updateConsensus();\r
      alignPanel.repaint();\r
@@ -421,7 +427,6 @@ public class AlignFrame extends GAlignFrame
   {\r
     viewport.alignment.deleteAllGroups();\r
     viewport.setSelectionGroup(null);\r
-\r
     alignPanel.repaint();\r
   }\r
 \r
@@ -542,7 +547,7 @@ public class AlignFrame extends GAlignFrame
     JInternalFrame frame = new JInternalFrame();\r
     Finder finder = new Finder(viewport, alignPanel, frame);\r
     frame.setContentPane(finder);\r
-    Desktop.addInternalFrame(frame, "Find", 340,110, false);\r
+    Desktop.addInternalFrame(frame, "Find", 340,110);\r
     frame.setLayer(JLayeredPane.PALETTE_LAYER);\r
 \r
   }\r
@@ -790,16 +795,12 @@ public class AlignFrame extends GAlignFrame
         {\r
           sg.cs = new ClustalxColourScheme(sg.sequences, sg.getWidth());\r
         }\r
-        else\r
-          try\r
-          {\r
+        else if(cs!=null)\r
+        {\r
+          try{\r
             sg.cs = (ColourSchemeI) cs.getClass().newInstance();\r
-          }\r
-          catch (Exception ex)\r
-          {\r
-            ex.printStackTrace();\r
-            sg.cs = cs;\r
-          }\r
+          }catch(Exception ex){ex.printStackTrace();}\r
+        }\r
 \r
         if(viewport.getAbovePIDThreshold())\r
         {\r
@@ -824,7 +825,7 @@ public class AlignFrame extends GAlignFrame
           ccs.setConsensus( AAFrequency.calculate(sg.sequences, 0, sg.getWidth()));\r
           sg.cs = ccs;\r
         }\r
-        else\r
+        else if(cs!=null)\r
         {\r
           // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!\r
           sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0, sg.getWidth()));\r
@@ -1199,20 +1200,10 @@ public class AlignFrame extends GAlignFrame
     {\r
       String choice = chooser.getSelectedFile().getPath();\r
       jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);\r
-      TreePanel treepanel = null;\r
       try\r
       {\r
         jalview.io.NewickFile fin = new jalview.io.NewickFile(choice, "File");\r
-        fin.parse();\r
-\r
-        if (fin.getTree() != null)\r
-        {\r
-          TreePanel tp = null;\r
-          tp = new TreePanel(viewport, viewport.getAlignment().getSequences(),\r
-                             fin, "FromFile", choice);\r
-          Desktop.addInternalFrame(tp, title, 600, 500);\r
-          addTreeMenuItem(tp, title);\r
-        }\r
+        ShowNewickTree(fin, choice);\r
       }\r
       catch (Exception ex)\r
       {\r
@@ -1225,4 +1216,21 @@ public class AlignFrame extends GAlignFrame
     }\r
   }\r
 \r
+  public void ShowNewickTree(NewickFile nf, String title)\r
+  {\r
+    try{\r
+      nf.parse();\r
+      if (nf.getTree() != null)\r
+      {\r
+        TreePanel tp = new TreePanel(viewport,\r
+                                     viewport.getAlignment().getSequences(),\r
+                                     nf, "FromFile", title);\r
+        Desktop.addInternalFrame(tp, title, 600, 500);\r
+        addTreeMenuItem(tp, title);\r
+        viewport.setCurrentTree(tp.getTree());\r
+      }\r
+     }catch(Exception ex){ex.printStackTrace();}\r
+  }\r
+\r
+\r
 }\r