();
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)
{
AlignmentViewport viewport = ap.av;
SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
CommandI undo;
undo = new OrderCommand("Tree Sort", oldOrder, viewport.getAlignment());
ap.paintAlignment(true);
return undo;
}
/**
* DOCUMENT ME!
*
* @param e
* DOCUMENT ME!
*/
@Override
public void font_actionPerformed(ActionEvent e)
{
if (treeCanvas == null)
{
return;
}
new FontChooser(this);
}
public Font getTreeFont()
{
return treeCanvas.font;
}
public void setTreeFont(Font f)
{
if (treeCanvas != null)
{
treeCanvas.setFont(f);
}
}
/**
* DOCUMENT ME!
*
* @param e
* DOCUMENT ME!
*/
@Override
public void distanceMenu_actionPerformed(ActionEvent e)
{
treeCanvas.setShowDistances(distanceMenu.isSelected());
}
/**
* DOCUMENT ME!
*
* @param e
* DOCUMENT ME!
*/
@Override
public void bootstrapMenu_actionPerformed(ActionEvent e)
{
treeCanvas.setShowBootstrap(bootstrapMenu.isSelected());
}
/**
* DOCUMENT ME!
*
* @param e
* DOCUMENT ME!
*/
@Override
public void placeholdersMenu_actionPerformed(ActionEvent e)
{
treeCanvas.setMarkPlaceholders(placeholdersMenu.isSelected());
}
/**
* DOCUMENT ME!
*
* @param e
* DOCUMENT ME!
*/
@Override
public void epsTree_actionPerformed(ActionEvent e)
{
boolean accurateText = true;
String renderStyle = jalview.bin.Cache.getDefault("EPS_RENDERING",
"Prompt each time");
// If we need to prompt, and if the GUI is visible then
// Prompt for EPS rendering style
if (renderStyle.equalsIgnoreCase("Prompt each time")
&& !(System.getProperty("java.awt.headless") != null && System
.getProperty("java.awt.headless").equals("true")))
{
EPSOptions eps = new EPSOptions();
renderStyle = eps.getValue();
if (renderStyle == null || eps.cancelled)
{
return;
}
}
if (renderStyle.equalsIgnoreCase("text"))
{
accurateText = false;
}
int width = treeCanvas.getWidth();
int height = treeCanvas.getHeight();
try
{
JalviewFileChooser chooser = new JalviewFileChooser(
ImageMaker.EPS_EXTENSION, ImageMaker.EPS_EXTENSION);
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(MessageManager
.getString("label.create_eps_from_tree"));
chooser.setToolTipText(MessageManager.getString("action.save"));
int value = chooser.showSaveDialog(this);
if (value != JalviewFileChooser.APPROVE_OPTION)
{
return;
}
Cache.setProperty("LAST_DIRECTORY", chooser.getSelectedFile()
.getParent());
FileOutputStream out = new FileOutputStream(chooser.getSelectedFile());
EpsGraphics2D pg = new EpsGraphics2D("Tree", out, 0, 0, width, height);
pg.setAccurateTextMode(accurateText);
treeCanvas.draw(pg, width, height);
pg.flush();
pg.close();
} catch (Exception ex)
{
ex.printStackTrace();
}
}
/**
* DOCUMENT ME!
*
* @param e
* DOCUMENT ME!
*/
@Override
public void pngTree_actionPerformed(ActionEvent e)
{
int width = treeCanvas.getWidth();
int height = treeCanvas.getHeight();
try
{
JalviewFileChooser chooser = new JalviewFileChooser(
ImageMaker.PNG_EXTENSION, ImageMaker.PNG_DESCRIPTION);
chooser.setFileView(new jalview.io.JalviewFileView());
chooser.setDialogTitle(MessageManager
.getString("label.create_png_from_tree"));
chooser.setToolTipText(MessageManager.getString("action.save"));
int value = chooser.showSaveDialog(this);
if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION)
{
return;
}
jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
.getSelectedFile().getParent());
FileOutputStream out = new FileOutputStream(chooser.getSelectedFile());
BufferedImage bi = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics png = bi.getGraphics();
treeCanvas.draw(png, width, height);
ImageIO.write(bi, "png", out);
out.close();
} catch (Exception ex)
{
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)};
*
* @param labelClass
*/
public void changeNames(final String labelClass)
{
tree.applyToNodes(new NodeTransformI()
{
@Override
public void transform(BinaryNode node)
{
if (node instanceof SequenceNode
&& !((SequenceNode) node).isPlaceholder()
&& !((SequenceNode) node).isDummy())
{
String newname = null;
SequenceI sq = (SequenceI) ((SequenceNode) node).element();
if (sq != null)
{
// search dbrefs, features and annotation
DBRefEntry[] refs = jalview.util.DBRefUtils.selectRefs(
sq.getDBRefs(),
new String[] { labelClass.toUpperCase() });
if (refs != null)
{
for (int i = 0; i < refs.length; i++)
{
if (newname == null)
{
newname = new String(refs[i].getAccessionId());
}
else
{
newname = newname + "; " + refs[i].getAccessionId();
}
}
}
if (newname == null)
{
SequenceFeature sf[] = sq.getSequenceFeatures();
for (int i = 0; sf != null && i < sf.length; i++)
{
if (sf[i].getType().equals(labelClass))
{
if (newname == null)
{
newname = new String(sf[i].getDescription());
}
else
{
newname = newname + "; " + sf[i].getDescription();
}
}
}
}
}
if (newname != null)
{
// String oldname = ((SequenceNode) node).getName();
// TODO : save oldname in the undo object for this modification.
((SequenceNode) node).setName(newname);
}
}
}
});
}
/**
* Formats a localised title for the tree panel, like
*
* Neighbour Joining Using BLOSUM62
*
* For a tree loaded from file, just uses the file name
* @return
*/
public String getPanelTitle()
{
if (treeTitle != null)
{
return treeTitle;
}
/*
* i18n description of Neighbour Joining or Average Distance method
*/
String treecalcnm = MessageManager.getString("label.tree_calc_"
+ treeType.toLowerCase());
/*
* short score model name (long description can be too long)
*/
String smn = scoreModelName;
/*
* put them together as Using
*/
final String ttl = MessageManager.formatMessage("label.treecalc_title",
treecalcnm, smn);
return ttl;
}
}