Load tree
authoramwaterhouse <Andrew Waterhouse>
Thu, 16 Mar 2006 15:18:55 +0000 (15:18 +0000)
committeramwaterhouse <Andrew Waterhouse>
Thu, 16 Mar 2006 15:18:55 +0000 (15:18 +0000)
src/jalview/appletgui/AlignFrame.java

index 03c0db9..aceb508 100755 (executable)
@@ -41,7 +41,10 @@ public class AlignFrame extends Frame implements ActionListener,
   jalview.bin.JalviewLite applet;\r
 \r
 \r
-  public AlignFrame(AlignmentI al, jalview.bin.JalviewLite applet, String title)\r
+   public AlignFrame(AlignmentI al,\r
+                     jalview.bin.JalviewLite applet,\r
+                     String title,\r
+                     boolean embedded)\r
   {\r
     try{\r
       jbInit();\r
@@ -115,9 +118,16 @@ public class AlignFrame extends Frame implements ActionListener,
    });\r
 \r
 \r
-   add(alignPanel, BorderLayout.CENTER);\r
-   jalview.bin.JalviewLite.addFrame(this, title, NEW_WINDOW_WIDTH, NEW_WINDOW_HEIGHT);\r
-\r
+   if(embedded)\r
+   {\r
+     setEmbedded();\r
+   }\r
+   else\r
+   {\r
+     add(alignPanel, BorderLayout.CENTER);\r
+     jalview.bin.JalviewLite.addFrame(this, title, NEW_WINDOW_WIDTH,\r
+                                      NEW_WINDOW_HEIGHT);\r
+   }\r
    alignPanel.validate();\r
    alignPanel.repaint();\r
   }\r
@@ -227,10 +237,7 @@ public class AlignFrame extends Frame implements ActionListener,
       }\r
 \r
       viewport.showSequenceFeatures = true;\r
-      viewMenu.addSeparator();\r
-      viewMenu.add(sequenceFeatures);\r
-      viewMenu.add(featureSettings);\r
-\r
+      sequenceFeatures.setState(true);\r
 \r
       alignPanel.repaint();\r
 \r
@@ -319,9 +326,10 @@ public void itemStateChanged(ItemEvent evt)
     else if(evt.getSource()==annotationPanelMenuItem)\r
             annotationPanelMenuItem_actionPerformed();\r
       else if(evt.getSource()==sequenceFeatures)\r
-       {     viewport.showSequenceFeatures(sequenceFeatures.getState());\r
+      {\r
+           viewport.showSequenceFeatures(sequenceFeatures.getState());\r
             alignPanel.seqPanel.seqCanvas.repaint();\r
-        }\r
+      }\r
       else if(evt.getSource()==conservationMenuItem)\r
             conservationMenuItem_actionPerformed();\r
       else if(evt.getSource()==abovePIDThreshold)\r
@@ -333,6 +341,8 @@ public void itemStateChanged(ItemEvent evt)
  {\r
     if(evt.getSource()==inputText)\r
       inputText_actionPerformed();\r
+    else if(evt.getSource()==loadTree)\r
+      loadTree_actionPerformed();\r
     else if(evt.getSource()==closeMenuItem)\r
       closeMenuItem_actionPerformed();\r
     else if(evt.getSource()==copy)\r
@@ -442,7 +452,7 @@ public void itemStateChanged(ItemEvent evt)
 \r
   public void inputText_actionPerformed()\r
   {\r
-    CutAndPasteTransfer cap = new CutAndPasteTransfer(true, applet);\r
+    CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);\r
     Frame frame = new Frame();\r
     frame.add(cap);\r
     jalview.bin.JalviewLite.addFrame(frame, "Cut & Paste Input", 500, 500);\r
@@ -450,7 +460,7 @@ public void itemStateChanged(ItemEvent evt)
 \r
   protected void outputText_actionPerformed(ActionEvent e)\r
   {\r
-    CutAndPasteTransfer cap = new CutAndPasteTransfer(false, applet);\r
+    CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);\r
     Frame frame = new Frame();\r
     frame.add(cap);\r
     jalview.bin.JalviewLite.addFrame(frame,\r
@@ -526,41 +536,7 @@ public void itemStateChanged(ItemEvent evt)
   // used by undo and redo\r
   void restoreHistoryItem(HistoryItem hi)\r
   {\r
-    if (hi.getType() == HistoryItem.SORT)\r
-    {\r
-      for (int i = 0; i < hi.getSequences().size(); i++)\r
-      {\r
-        viewport.alignment.getSequences().setElementAt(hi.getSequences().\r
-            elementAt(i), i);\r
-      }\r
-    }\r
-    else\r
-    {\r
-      for (int i = 0; i < hi.getSequences().size(); i++)\r
-      {\r
-        SequenceI restore = (SequenceI) hi.getSequences().elementAt(i);\r
-        if (restore.getLength() == 0)\r
-        {\r
-          // log.System.out.println(hi.getHidden().elementAt(i));\r
-          restore.setSequence(hi.getHidden().elementAt(i).toString());\r
-          viewport.alignment.getSequences().insertElementAt(\r
-              restore,\r
-              hi.getAlignIndex(i));\r
-        }\r
-        else\r
-        {\r
-          restore.setSequence(hi.getHidden().elementAt(i).toString());\r
-        }\r
-      }\r
-      if (hi.getType() == HistoryItem.PASTE)\r
-      {\r
-        for (int i = viewport.alignment.getHeight() - 1;\r
-             i > hi.getSequences().size() - 1; i--)\r
-        {\r
-          viewport.alignment.deleteSequence(i);\r
-        }\r
-      }\r
-    }\r
+    hi.restore();\r
 \r
     updateEditMenuBar();\r
 \r
@@ -747,7 +723,10 @@ public void itemStateChanged(ItemEvent evt)
         {\r
           newtitle = newtitle.concat("- from " + getTitle());\r
         }\r
-        AlignFrame af = new AlignFrame(new Alignment(newSeqs), applet, newtitle);\r
+        AlignFrame af = new AlignFrame(new Alignment(newSeqs),\r
+                                       applet,\r
+                                       newtitle,\r
+                                       false);\r
 \r
         jalview.bin.JalviewLite.addFrame(af, newtitle, NEW_WINDOW_WIDTH,\r
                                          NEW_WINDOW_HEIGHT);\r
@@ -1562,7 +1541,28 @@ public void itemStateChanged(ItemEvent evt)
     jalview.bin.JalviewLite.addFrame(tp, title, 600, 500);\r
   }\r
 \r
-  public void addTreeMenuItem(final TreePanel treePanel, String title)\r
+  void loadTree_actionPerformed()\r
+  {\r
+    TreePanel tp = null;\r
+\r
+      CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);\r
+      cap.setText("Paste your Newick tree file here.");\r
+      cap.treeImport = true;\r
+      Frame frame = new Frame();\r
+      frame.add(cap);\r
+      jalview.bin.JalviewLite.addFrame(frame, "Paste Newick file ", 400, 300);\r
+  }\r
+\r
+  public void loadTree(jalview.io.NewickFile tree, String treeFile)\r
+  {\r
+    TreePanel tp = new TreePanel(viewport,\r
+                      viewport.getAlignment().getSequences(),\r
+                      tree, "From File - ", treeFile);\r
+    jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500);\r
+    addTreeMenuItem(tp, treeFile);\r
+  }\r
+\r
+  void addTreeMenuItem(final TreePanel treePanel, String title)\r
   {\r
     final MenuItem item = new MenuItem(title);\r
     sortByTreeMenu.add(item);\r
@@ -1681,13 +1681,14 @@ public void itemStateChanged(ItemEvent evt)
   //JBuilder Graphics here\r
 \r
     protected MenuBar alignFrameMenuBar = new MenuBar();\r
-    protected Menu fileMenu = new Menu();\r
-    protected MenuItem closeMenuItem = new MenuItem();\r
-    protected Menu editMenu = new Menu();\r
-    protected Menu viewMenu = new Menu();\r
-    protected Menu colourMenu = new Menu();\r
-    protected Menu calculateMenu = new Menu();\r
-    protected MenuItem selectAllSequenceMenuItem = new MenuItem();\r
+    protected Menu fileMenu = new Menu("File");\r
+    protected MenuItem loadTree = new MenuItem("Load Associated Tree");\r
+    protected MenuItem closeMenuItem = new MenuItem("Close");\r
+    protected Menu editMenu = new Menu("Edit");\r
+    protected Menu viewMenu = new Menu("View");\r
+    protected Menu colourMenu = new Menu("Colour");\r
+    protected Menu calculateMenu = new Menu("Calculate");\r
+    protected MenuItem selectAllSequenceMenuItem = new MenuItem("Select all");\r
     protected MenuItem deselectAllSequenceMenuItem = new MenuItem();\r
     protected MenuItem invertSequenceMenuItem = new MenuItem();\r
     protected MenuItem remove2LeftMenuItem = new MenuItem();\r
@@ -1788,15 +1789,9 @@ public void itemStateChanged(ItemEvent evt)
 \r
         outputTextboxMenu.add(item);\r
       }\r
-\r
-        fileMenu.setLabel("File");\r
-        closeMenuItem.setLabel("Close");\r
         closeMenuItem.addActionListener(this);\r
-        editMenu.setLabel("Edit");\r
-        viewMenu.setLabel("View");\r
-        colourMenu.setLabel("Colour");\r
-        calculateMenu.setLabel("Calculate");\r
-        selectAllSequenceMenuItem.setLabel("Select all");\r
+\r
+        loadTree.addActionListener(this);\r
         selectAllSequenceMenuItem.addActionListener(this);\r
         deselectAllSequenceMenuItem.setLabel("Deselect All");\r
         deselectAllSequenceMenuItem.addActionListener(this);\r
@@ -1948,7 +1943,7 @@ public void itemStateChanged(ItemEvent evt)
     featureSettings.addActionListener(this);\r
     sequenceFeatures.setLabel("Sequence Features");\r
     sequenceFeatures.addItemListener(this);\r
-    sequenceFeatures.setState(true);\r
+    sequenceFeatures.setState(false);\r
 \r
     alignFrameMenuBar.add(fileMenu);\r
         alignFrameMenuBar.add(editMenu);\r
@@ -1960,6 +1955,7 @@ public void itemStateChanged(ItemEvent evt)
         fileMenu.add(inputText);\r
         fileMenu.add(outputTextboxMenu);\r
         fileMenu.addSeparator();\r
+        fileMenu.add(loadTree);\r
         fileMenu.add(closeMenuItem);\r
         editMenu.add(undoMenuItem);\r
         editMenu.add(redoMenuItem);\r
@@ -1994,6 +1990,9 @@ public void itemStateChanged(ItemEvent evt)
         viewMenu.add(renderGapsMenuItem);\r
         viewMenu.add(annotationPanelMenuItem);\r
     viewMenu.addSeparator();\r
+        viewMenu.add(sequenceFeatures);\r
+        viewMenu.add(featureSettings);\r
+    viewMenu.addSeparator();\r
         viewMenu.add(overviewMenuItem);\r
         colourMenu.add(applyToAllGroups);\r
         colourMenu.addSeparator();\r
@@ -2081,21 +2080,21 @@ public void itemStateChanged(ItemEvent evt)
     embeddedCalculate.addMouseListener(this);\r
     embeddedHelp.addMouseListener(this);\r
 \r
-    setVisible(false);\r
+   // setVisible(false);\r
     fileMenu.remove(closeMenuItem);\r
     fileMenu.remove(2); // Seperator\r
 \r
     applet.setLayout(new BorderLayout());\r
     applet.add(embeddedMenu, BorderLayout.NORTH);\r
     applet.add(statusBar, BorderLayout.SOUTH);\r
-    applet.validate();\r
-\r
+   // applet.validate();\r
 \r
     alignPanel.setSize(applet.size().width, applet.size().height\r
                        - embeddedMenu.HEIGHT - statusBar.HEIGHT);\r
 \r
      applet.add(alignPanel, BorderLayout.CENTER);\r
      applet.validate();\r
+\r
   }\r
 \r
 \r