X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fgui%2FTreePanel.java;h=ee0bfafdf497c697521b85bde53537ea06ed3f7e;hb=aec85d6dfc1dd5970a50a53dc9d161635d1e9960;hp=646cbb4bd8c0865e4de845e5d90b758a2da82c85;hpb=eb53458ceff17b79d613ec208b5185f541eb6320;p=jalview.git
diff --git a/src/jalview/gui/TreePanel.java b/src/jalview/gui/TreePanel.java
index 646cbb4..ee0bfaf 100755
--- a/src/jalview/gui/TreePanel.java
+++ b/src/jalview/gui/TreePanel.java
@@ -1,26 +1,30 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
- * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
+ * Copyright (C) 2014 The Jalview Authors
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This file is part of Jalview.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.gui;
import java.beans.*;
import java.io.*;
import java.util.*;
+import java.util.List;
+
import javax.imageio.*;
import java.awt.*;
@@ -30,10 +34,12 @@ import javax.swing.*;
import org.jibble.epsgraphics.*;
import jalview.analysis.*;
+import jalview.commands.CommandI;
import jalview.commands.OrderCommand;
import jalview.datamodel.*;
import jalview.io.*;
import jalview.jbgui.*;
+import jalview.util.MessageManager;
/**
* DOCUMENT ME!
@@ -141,7 +147,9 @@ public class TreePanel extends GTreePanel
if (tree == null)
{
System.out.println("tree is null");
- // TODO: deal with case when a change event is received whilst a tree is still being calculated - should save reference for processing message later.
+ // TODO: deal with case when a change event is received whilst a
+ // tree is still being calculated - should save reference for
+ // processing message later.
return;
}
if (evt.getNewValue() == null)
@@ -150,7 +158,7 @@ public class TreePanel extends GTreePanel
.println("new alignment sequences vector value is null");
}
- tree.UpdatePlaceHolders((Vector) evt.getNewValue());
+ tree.UpdatePlaceHolders((List) evt.getNewValue());
treeCanvas.nameHash.clear(); // reset the mapping between canvas
// rectangles and leafnodes
repaint();
@@ -253,11 +261,11 @@ public class TreePanel extends GTreePanel
{
if (odata == null)
{
- tree = new NJTree(av.alignment.getSequencesArray(), newtree);
+ tree = new NJTree(av.getAlignment().getSequencesArray(), newtree);
}
else
{
- tree = new NJTree(av.alignment.getSequencesArray(), odata,
+ tree = new NJTree(av.getAlignment().getSequencesArray(), odata,
newtree);
}
if (!tree.hasOriginalSequenceData())
@@ -269,19 +277,21 @@ public class TreePanel extends GTreePanel
{
int start, end;
SequenceI[] seqs;
- AlignmentView seqStrings = av.getAlignmentView(av
- .getSelectionGroup() != null);
- if (av.getSelectionGroup() == null)
+ boolean selview = av.getSelectionGroup() != null
+ && av.getSelectionGroup().getSize() > 1;
+ AlignmentView seqStrings = av.getAlignmentView(selview);
+ if (!selview)
{
start = 0;
- end = av.alignment.getWidth();
- seqs = av.alignment.getSequencesArray();
+ end = av.getAlignment().getWidth();
+ seqs = av.getAlignment().getSequencesArray();
}
else
{
start = av.getSelectionGroup().getStartRes();
end = av.getSelectionGroup().getEndRes() + 1;
- seqs = av.getSelectionGroup().getSequencesInOrder(av.alignment);
+ seqs = av.getSelectionGroup().getSequencesInOrder(
+ av.getAlignment());
}
tree = new NJTree(seqs, seqStrings, type, pwtype, start, end);
@@ -363,12 +373,19 @@ public class TreePanel extends GTreePanel
buffer.append("PID");
}
- Desktop.addInternalFrame(cap, buffer.toString(), 500, 100);
+ jalview.io.NewickFile fout = new jalview.io.NewickFile(
+ tree.getTopNode());
+ try
+ {
+ cap.setText(fout.print(tree.isHasBootstrap(), tree.isHasDistances(),
+ tree.isHasRootDistance()));
+ Desktop.addInternalFrame(cap, buffer.toString(), 500, 100);
+ } catch (OutOfMemoryError oom)
+ {
+ new OOMWarning("generating newick tree file", oom);
+ cap.dispose();
+ }
- jalview.io.NewickFile fout = new jalview.io.NewickFile(tree
- .getTopNode());
- cap.setText(fout.print(tree.isHasBootstrap(), tree.isHasDistances(),
- tree.isHasRootDistance()));
}
/**
@@ -379,11 +396,11 @@ public class TreePanel extends GTreePanel
*/
public void saveAsNewick_actionPerformed(ActionEvent e)
{
- JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
- .getProperty("LAST_DIRECTORY"));
+ JalviewFileChooser chooser = new JalviewFileChooser(
+ jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
chooser.setFileView(new JalviewFileView());
- chooser.setDialogTitle("Save tree as newick file");
- chooser.setToolTipText("Save");
+ chooser.setDialogTitle(MessageManager.getString("label.save_tree_as_newick"));
+ chooser.setToolTipText(MessageManager.getString("action.save"));
int value = chooser.showSaveDialog(null);
@@ -395,10 +412,10 @@ public class TreePanel extends GTreePanel
try
{
- jalview.io.NewickFile fout = new jalview.io.NewickFile(tree
- .getTopNode());
- String output = fout.print(tree.isHasBootstrap(), tree
- .isHasDistances(), tree.isHasRootDistance());
+ jalview.io.NewickFile fout = new jalview.io.NewickFile(
+ tree.getTopNode());
+ String output = fout.print(tree.isHasBootstrap(),
+ tree.isHasDistances(), tree.isHasRootDistance());
java.io.PrintWriter out = new java.io.PrintWriter(
new java.io.FileWriter(choice));
out.println(output);
@@ -475,8 +492,10 @@ public class TreePanel extends GTreePanel
// af.addSortByOrderMenuItem(ServiceName + " Ordering",
// msaorder);
- Desktop.addInternalFrame(af, "Original Data for " + this.title,
- AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
+ Desktop.addInternalFrame(af, MessageManager.formatMessage(
+ "label.original_data_for_params", new String[]
+ { this.title }), AlignFrame.DEFAULT_WIDTH,
+ AlignFrame.DEFAULT_HEIGHT);
}
}
}
@@ -495,20 +514,79 @@ public class TreePanel extends GTreePanel
/**
* sort the associated alignment view by the current tree.
+ *
* @param e
*/
public void sortByTree_actionPerformed(ActionEvent e)
{
- AlignmentPanel ap = av.getAlignPanel();
+
+ if (treeCanvas.applyToAllViews)
+ {
+ final ArrayList commands = new ArrayList();
+ for (AlignmentPanel ap : PaintRefresher.getAssociatedPanels(av
+ .getSequenceSetId()))
+ {
+ commands.add(sortAlignmentIn(ap.av.getAlignPanel()));
+ }
+ av.getAlignPanel().alignFrame.addHistoryItem(new CommandI()
+ {
+
+ @Override
+ public void undoCommand(AlignmentI[] views)
+ {
+ for (CommandI tsort : commands)
+ {
+ tsort.undoCommand(views);
+ }
+ }
+
+ @Override
+ public int getSize()
+ {
+ return commands.size();
+ }
+
+ @Override
+ public String getDescription()
+ {
+ return "Tree Sort (many views)";
+ }
+
+ @Override
+ public void doCommand(AlignmentI[] views)
+ {
+
+ for (CommandI tsort : commands)
+ {
+ tsort.doCommand(views);
+ }
+ }
+ });
+ for (AlignmentPanel ap : PaintRefresher.getAssociatedPanels(av
+ .getSequenceSetId()))
+ {
+ // ensure all the alignFrames refresh their GI after adding an undo item
+ ap.alignFrame.updateEditMenuBar();
+ }
+ }
+ else
+ {
+ treeCanvas.ap.alignFrame
+ .addHistoryItem(sortAlignmentIn(treeCanvas.ap));
+ }
+
+ }
+
+ public CommandI sortAlignmentIn(AlignmentPanel ap)
+ {
+ AlignViewport av = ap.av;
SequenceI[] oldOrder = av.getAlignment().getSequencesArray();
AlignmentSorter.sortByTree(av.getAlignment(), tree);
-
- ap.alignFrame
- .addHistoryItem(new OrderCommand("Tree Sort", oldOrder,
- av.alignment));
+ CommandI undo;
+ undo = new OrderCommand("Tree Sort", oldOrder, av.getAlignment());
ap.paintAlignment(true);
-
+ return undo;
}
/**
@@ -617,8 +695,8 @@ public class TreePanel extends GTreePanel
{ "eps" }, new String[]
{ "Encapsulated Postscript" }, "Encapsulated Postscript");
chooser.setFileView(new jalview.io.JalviewFileView());
- chooser.setDialogTitle("Create EPS file from tree");
- chooser.setToolTipText("Save");
+ chooser.setDialogTitle(MessageManager.getString("label.create_eps_from_tree"));
+ chooser.setToolTipText(MessageManager.getString("action.save"));
int value = chooser.showSaveDialog(this);
@@ -664,8 +742,8 @@ public class TreePanel extends GTreePanel
{ "Portable network graphics" }, "Portable network graphics");
chooser.setFileView(new jalview.io.JalviewFileView());
- chooser.setDialogTitle("Create PNG image from tree");
- chooser.setToolTipText("Save");
+ chooser.setDialogTitle(MessageManager.getString("label.create_png_from_tree"));
+ chooser.setToolTipText(MessageManager.getString("action.save"));
int value = chooser.showSaveDialog(this);
@@ -692,55 +770,68 @@ public class TreePanel extends GTreePanel
ex.printStackTrace();
}
}
+
/**
- * change node labels to the annotation referred to by labelClass
- * TODO: promote to a datamodel modification that can be undone
- * TODO: make argument one case of a generic transformation function ie { undoStep = apply(Tree, TransformFunction)};
+ * change node labels to the annotation referred to by labelClass TODO:
+ * promote to a datamodel modification that can be undone TODO: make argument
+ * one case of a generic transformation function ie { undoStep = apply(Tree,
+ * TransformFunction)};
+ *
* @param labelClass
*/
public void changeNames(final String labelClass)
{
- tree.applyToNodes(new NodeTransformI() {
+ tree.applyToNodes(new NodeTransformI()
+ {
public void transform(BinaryNode node)
{
- if (node instanceof SequenceNode && !((SequenceNode) node).isPlaceholder() && !((SequenceNode) node).isDummy())
+ if (node instanceof SequenceNode
+ && !((SequenceNode) node).isPlaceholder()
+ && !((SequenceNode) node).isDummy())
{
- String newname=null;
+ String newname = null;
SequenceI sq = (SequenceI) ((SequenceNode) node).element();
- if (sq!=null)
+ if (sq != null)
{
// search dbrefs, features and annotation
- DBRefEntry[] refs = jalview.util.DBRefUtils.selectRefs(sq.getDBRef(), new String[] {labelClass.toUpperCase()});
- if (refs!=null)
+ DBRefEntry[] refs = jalview.util.DBRefUtils.selectRefs(
+ sq.getDBRef(), new String[]
+ { labelClass.toUpperCase() });
+ if (refs != null)
{
- for (int i=0; i