X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2FMainFrame.java;h=ac9bd6d6b75908c6f931487ae3a7ff02d58b222c;hb=9e1353590a88991e7593d38c8e307f713a0f3d5b;hp=377c99959051f0e08aa6154c0b4fcb5f7f299d20;hpb=6ffcf85ecb3a59181ef75a41d679952cf085f457;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrame.java b/forester/java/src/org/forester/archaeopteryx/MainFrame.java index 377c999..ac9bd6d 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrame.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrame.java @@ -32,13 +32,14 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.NoSuchElementException; -import java.util.Set; import javax.swing.Box; +import javax.swing.Icon; import javax.swing.JApplet; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; @@ -67,6 +68,7 @@ import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE; import org.forester.phylogeny.data.Annotation; import org.forester.phylogeny.data.NodeVisualData.NodeFill; import org.forester.phylogeny.data.NodeVisualData.NodeShape; +import org.forester.phylogeny.iterators.PhylogenyNodeIterator; import org.forester.sdi.GSDI; import org.forester.sdi.GSDIR; import org.forester.sdi.SDIException; @@ -124,6 +126,8 @@ public abstract class MainFrame extends JFrame implements ActionListener { static final String USE_BRACKETS_FOR_CONF_IN_NH_LABEL = "Use Brackets for Confidence Values"; static final String USE_INTERNAL_NAMES_FOR_CONF_IN_NH_LABEL = "Use Internal Node Names for Confidence Values"; static final String SHOW_BASIC_TREE_INFORMATION_LABEL = "Basic Tree Information"; + static final String RIGHT_LINE_UP_DOMAINS = "Right-align Domain Architectures"; + static final String LINE_UP_RENDERABLE_DATA = "Line Up Node Diagrams"; JMenuBar _jmenubar; JMenu _file_jmenu; JMenu _tools_menu; @@ -162,6 +166,8 @@ public abstract class MainFrame extends JFrame implements ActionListener { JMenuItem _annotate_item; JMenuItem _remove_branch_color_item; JMenuItem _remove_visual_styles_item; + JMenuItem _delete_selected_nodes_item; + JMenuItem _delete_not_selected_nodes_item; // font size menu: JMenuItem _super_tiny_fonts_item; JMenuItem _tiny_fonts_item; @@ -195,6 +201,8 @@ public abstract class MainFrame extends JFrame implements ActionListener { JMenuItem _cycle_node_fill_mi; JMenuItem _choose_node_size_mi; JCheckBoxMenuItem _show_confidence_stddev_cbmi; + JCheckBoxMenuItem _right_line_up_domains_cbmi; + JCheckBoxMenuItem _line_up_renderable_data_cbmi; // _ print JCheckBoxMenuItem _graphics_export_visible_only_cbmi; JCheckBoxMenuItem _antialias_print_cbmi; @@ -320,6 +328,18 @@ public abstract class MainFrame extends JFrame implements ActionListener { } midpointRoot(); } + else if ( o == _delete_selected_nodes_item ) { + if ( isSubtreeDisplayed() ) { + return; + } + deleteSelectedNodes( true ); + } + else if ( o == _delete_not_selected_nodes_item ) { + if ( isSubtreeDisplayed() ) { + return; + } + deleteSelectedNodes( false ); + } else if ( o == _annotate_item ) { annotateSequences(); } @@ -471,16 +491,30 @@ public abstract class MainFrame extends JFrame implements ActionListener { getCurrentTreePanel().updateOvSizes(); } } + else if ( o == _line_up_renderable_data_cbmi ) { + updateOptions( getOptions() ); + } + else if ( o == _right_line_up_domains_cbmi ) { + updateOptions( getOptions() ); + } + + else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi ) || ( o == _convex_type_cbmi ) || ( o == _euro_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) { typeChanged( o ); } + else if ( o == _about_item ) { about(); } else if ( o == _help_item ) { - help(); + try { + AptxUtil.openWebsite( Constants.APTX_DOC_SITE, is_applet, applet ); + } + catch ( final IOException e1 ) { + ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() ); + } } else if ( o == _website_item ) { try { @@ -526,6 +560,93 @@ public abstract class MainFrame extends JFrame implements ActionListener { _contentpane.repaint(); } + private void deleteSelectedNodes( boolean delete ) { + final Phylogeny phy = getMainPanel().getCurrentPhylogeny(); + if ( phy == null || phy.getNumberOfExternalNodes() < 2 ) { + return; + } + List nodes = new ArrayList(); + if ( ( getCurrentTreePanel().getFoundNodes0() != null ) || ( getCurrentTreePanel().getFoundNodes1() != null ) ) { + final List all_selected_nodes = getCurrentTreePanel().getFoundNodesAsListOfPhylogenyNodes(); + for( final PhylogenyNode n : all_selected_nodes ) { + if ( n.isExternal() ) { + nodes.add( n ); + } + } + } + + String function = "Retain"; + if ( delete ) { + function = "Delete"; + } + if ( ( nodes == null ) || nodes.isEmpty() ) { + JOptionPane + .showMessageDialog( this, + "Need to select external nodes, either via direct selection or via the \"Search\" function", + "No external nodes selected to " + function.toLowerCase(), + JOptionPane.ERROR_MESSAGE ); + return; + } + final int todo = nodes.size(); + final int ext = phy.getNumberOfExternalNodes(); + int res = todo; + if ( delete ) { + res = ext - todo; + } + if ( res < 1 ) { + JOptionPane.showMessageDialog( this, + "Cannot delete all nodes", + "Attempt to delete all nodes ", + JOptionPane.ERROR_MESSAGE ); + return; + } + final int result = JOptionPane.showConfirmDialog( null, function + " " + todo + + " external node(s), from a total of " + ext + " external nodes," + "\nresulting in tree with " + res + + " nodes?", function + " external nodes", JOptionPane.OK_CANCEL_OPTION ); + if ( result == JOptionPane.OK_OPTION ) { + if ( !delete ) { + final List to_delete = new ArrayList(); + for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) { + final PhylogenyNode n = it.next(); + if ( !nodes.contains( n ) ) { + to_delete.add( n ); + } + } + for( final PhylogenyNode n : to_delete ) { + phy.deleteSubtree( n, true ); + } + } + else { + for( final PhylogenyNode n : nodes ) { + phy.deleteSubtree( n, true ); + } + } + resetSearch(); + getCurrentTreePanel().setNodeInPreorderToNull(); + phy.externalNodesHaveChanged(); + phy.clearHashIdToNodeMap(); + phy.recalculateNumberOfExternalDescendants( true ); + getCurrentTreePanel().resetNodeIdToDistToLeafMap(); + getCurrentTreePanel().setEdited( true ); + repaint(); + } + } + + void resetSearch() { + getMainPanel().getCurrentTreePanel().setFoundNodes0( null ); + getMainPanel().getCurrentTreePanel().setFoundNodes1( null ); + getMainPanel().getControlPanel().setSearchFoundCountsOnLabel0( 0 ); + getMainPanel().getControlPanel().getSearchFoundCountsLabel0().setVisible( false ); + getMainPanel().getControlPanel().getSearchTextField0().setText( "" ); + getMainPanel().getControlPanel().getSearchResetButton0().setEnabled( false ); + getMainPanel().getControlPanel().getSearchResetButton0().setVisible( false ); + getMainPanel().getControlPanel().setSearchFoundCountsOnLabel1( 0 ); + getMainPanel().getControlPanel().getSearchFoundCountsLabel1().setVisible( false ); + getMainPanel().getControlPanel().getSearchTextField1().setText( "" ); + getMainPanel().getControlPanel().getSearchResetButton1().setEnabled( false ); + getMainPanel().getControlPanel().getSearchResetButton1().setVisible( false ); + } + public Configuration getConfiguration() { return _configuration; } @@ -620,9 +741,10 @@ public abstract class MainFrame extends JFrame implements ActionListener { void buildHelpMenu() { _help_jmenu = createMenu( "Help", getConfiguration() ); - _help_jmenu.add( _help_item = new JMenuItem( "Help" ) ); + _help_jmenu.add( _help_item = new JMenuItem( "Documentation" ) ); + _help_jmenu.addSeparator(); _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) ); - _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" ); + _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" ); //TODO need to add this... _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) ); _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) ); _help_jmenu.addSeparator(); @@ -978,95 +1100,7 @@ public abstract class MainFrame extends JFrame implements ActionListener { return _species_tree; } - void help() { - final StringBuilder sb = new StringBuilder(); - sb.append( "Display options\n" ); - sb.append( "-------------------\n" ); - sb.append( "Use the checkboxes to select types of information to display on the tree.\n\n" ); - sb.append( "Clickable tree nodes\n" ); - sb.append( "--------------------\n" ); - sb.append( "Tree nodes can be clicked, the action is determined by the 'click on node to' menu\n" ); - sb.append( "or by right clicking:\n" ); - sb.append( "o Display Node Data -- display information for a node\n" ); - sb.append( "o Collapse/Uncollapse -- collapse and uncollapse subtree from clicked node\n" ); - sb.append( "o Root/Reroot -- change tree root to clicked node\n" ); - sb.append( "o Sub/Super Tree -- toggle between subtree from clicked node and whole tree\n" ); - sb.append( "o Swap Descendants -- switch descendant on either side of clicked node\n" ); - sb.append( "o Colorize Subtree -- color a subtree\n" ); - sb.append( "o Open Sequence Web -- launch a web browser to display sequence information\n" ); - sb.append( "o Open Taxonomy Web -- launch a web browser to display taxonomy information\n" ); - sb.append( "- there may be additional choices depending on this particular setup\n\n" ); - sb.append( "Right clicking on a node always displays the information of a node.\n\n" ); - sb.append( "Zooming\n" ); - sb.append( "---------\n" ); - sb.append( "The mouse wheel and the plus and minus keys control zooming.\n" ); - sb.append( "Mouse wheel+Ctrl changes the text size.\n" ); - sb.append( "Mouse wheel+Shift controls zooming in vertical direction only.\n" ); - sb.append( "Use the buttons on the control panel to zoom the tree in and out, horizontally or vertically.\n" ); - sb.append( "The entire tree can be fitted into the window by clicking the \"F\" button, or by pressing F, Delete, or Home.\n" ); - sb.append( "The up, down, left, and right keys can be used to move the visible part (if zoomed in).\n" ); - sb.append( "Up, down, left, and right+Shift can be used to control zooming horizontally and vertically.\n" ); - sb.append( "Plus and minus keys+Ctrl change the text size; F+Ctrl, Delete+Ctrl, or Home+Ctrl resets it.\n\n" ); - sb.append( "Quick tree manipulation:\n" ); - sb.append( "------------------------\n" ); - sb.append( "Order Subtrees -- order the tree by branch length\n" ); - sb.append( "Uncollapse All -- uncollapse any and all collapsed branches\n\n" ); - sb.append( "Memory problems (Java heap space error)\n" ); - sb.append( "---------------------------------------\n" ); - sb.append( "Since the Java default memory allocation is quite small, it might by necessary (for trees\n" ); - sb.append( "with more than approximately 5000 external nodes) to increase the memory which Java can use, with\n" ); - sb.append( "the '-Xmx' Java command line option. For example:\n" ); - sb.append( "java -Xmx1024m -cp path\\to\\forester.jar org.forester.archaeopteryx.Archaeopteryx\n\n" ); - // + "General remarks\n" - // + "---------------\n" - // + - // "o The application version permits copying to the clipboard \n" - // + - // " in the \"View\"|\"View as ...\" frame (either by control-c or button press).\n" - // + - // "o Changes made to a subtree affect this subtree and its subtrees,\n" - // + " but not any of its parent tree(s).\n" - // + - // "o Archaeopteryx tries to detect whether the numerical values in a NH tree\n" - // + - // " are likely to be bootstrap values instead of branch length values.\n\n" - // + - // " Remarks regarding SDI (Speciation Duplication Inference):\n" - // + - // "o Each external node of the gene tree (in display) needs to be associated with\n" - // + - // " a species: either directly through the \"Species\" field, or the species\n" - // + - // " is part of the sequence name in the form \"XXXX_SPECIES\"\n" - // + - // " (e.g. \"ACON_DROME\" or \"ACON_DROME/123-4489\" which is also acceptable).\n" - // + - // "o A species tree for each species of the gene tree needs to be loaded with\n" - // + - // " \"SDI\"|\"Load species tree\" prior the SDI execution.\n" - // + - // "o !External nodes of the gene tree associated with species not present in\n" - // + - // " the species tree are REMOVED prior to SDI execution!\n" - // + - // "o Both the gene tree and the species tree must be completely binary.\n" - // + - // "o Duplications and speciations are a function of the position of the root.\n" - // + - // " Hence, after each manual \"Root/Reroot\"ing some duplications will be\n" - // + " incorrect and need to be inferred again\n" - // + - // " with: \"SDI\"|\"SDI (Speciation Duplication Inference)\n\n" - sb.append( "phyloXML\n" ); - sb.append( "-------------------\n" ); - sb.append( "Reference: " + Constants.PHYLOXML_REFERENCE + "\n" ); - sb.append( "Website: " + Constants.PHYLOXML_WEB_SITE + "\n" ); - sb.append( "Version: " + ForesterConstants.PHYLO_XML_VERSION + "\n" ); - sb.append( "\n" ); - sb.append( "For more information: https://sites.google.com/site/cmzmasek/home/software/archaeopteryx\n" ); - sb.append( "Email: " + Constants.AUTHOR_EMAIL + "\n\n" ); - TextFrame.instantiate( sb.toString(), "Help", _textframes ); - } + void initializeTypeMenu( final Options options ) { setTypeMenuToAllUnselected(); @@ -1384,6 +1418,14 @@ public abstract class MainFrame extends JFrame implements ActionListener { else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) { options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ); } + if ( ( _right_line_up_domains_cbmi != null ) && _right_line_up_domains_cbmi.isEnabled() ) { + options.setRightLineUpDomains( _right_line_up_domains_cbmi.isSelected() ); + } + + + if ( ( _line_up_renderable_data_cbmi != null ) && _line_up_renderable_data_cbmi.isEnabled() ) { + options.setLineUpRendarableNodeData( _line_up_renderable_data_cbmi.isSelected() ); + } } void updateTypeCheckboxes( final Options options, final Object o ) { @@ -1426,7 +1468,11 @@ public abstract class MainFrame extends JFrame implements ActionListener { private void annotateSequences() { if ( getCurrentTreePanel() != null ) { - final Set nodes = getCurrentTreePanel().getFoundNodes0(); + List nodes = null; + if ( ( getCurrentTreePanel().getFoundNodes0() != null ) + || ( getCurrentTreePanel().getFoundNodes1() != null ) ) { + nodes = getCurrentTreePanel().getFoundNodesAsListOfPhylogenyNodes(); + } if ( ( nodes == null ) || nodes.isEmpty() ) { JOptionPane .showMessageDialog( this, @@ -1475,8 +1521,7 @@ public abstract class MainFrame extends JFrame implements ActionListener { desc = desc.replaceAll( "\\s+", " " ); } if ( !ForesterUtil.isEmpty( ref ) || !ForesterUtil.isEmpty( desc ) ) { - for( final Long id : nodes ) { - final PhylogenyNode n = phy.getNode( id ); + for( final PhylogenyNode n : nodes ) { ForesterUtil.ensurePresenceOfSequence( n ); final Annotation ann = ForesterUtil.isEmpty( ref ) ? new Annotation() : new Annotation( ref ); @@ -1581,7 +1626,7 @@ public abstract class MainFrame extends JFrame implements ActionListener { */ static void about() { final StringBuffer about = new StringBuffer( "Archaeopteryx\nVersion " + Constants.VERSION + "\n" ); - about.append( "Copyright (C) 2013 Christian M. Zmasek\n" ); + about.append( "Copyright (C) 2014 Christian M Zmasek\n" ); about.append( "All Rights Reserved\n" ); about.append( "License: GNU Lesser General Public License (LGPL)\n" ); about.append( "Last modified: " + Constants.PRG_DATE + "\n" ); @@ -1605,6 +1650,8 @@ public abstract class MainFrame extends JFrame implements ActionListener { about.append( Constants.PHYLOXML_REFERENCE_SHORT + "\n" ); about.append( "For more information & download:\n" ); about.append( Constants.APTX_WEB_SITE + "\n" ); + about.append( "Documentation:\n" ); + about.append( Constants.APTX_DOC_SITE + "\n" ); about.append( "Comments: " + Constants.AUTHOR_EMAIL ); JOptionPane.showMessageDialog( null, about, Constants.PRG_NAME, JOptionPane.PLAIN_MESSAGE ); }