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