import java.awt.event.ActionListener;\r
import java.io.File;\r
import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.HashSet;\r
import java.util.LinkedList;\r
import java.util.List;\r
import java.util.Locale;\r
import org.forester.phylogeny.data.Annotation;\r
import org.forester.phylogeny.data.NodeVisualData.NodeFill;\r
import org.forester.phylogeny.data.NodeVisualData.NodeShape;\r
+import org.forester.phylogeny.iterators.PhylogenyNodeIterator;\r
import org.forester.sdi.GSDI;\r
import org.forester.sdi.GSDIR;\r
import org.forester.sdi.SDIException;\r
JMenuItem _annotate_item;\r
JMenuItem _remove_branch_color_item;\r
JMenuItem _remove_visual_styles_item;\r
+ JMenuItem _deleted_selected_nodes_item;\r
+ JMenuItem _deleted_not_selected_nodes_item;\r
// font size menu:\r
JMenuItem _super_tiny_fonts_item;\r
JMenuItem _tiny_fonts_item;\r
}\r
midpointRoot();\r
}\r
+ else if ( o == _deleted_selected_nodes_item ) {\r
+ if ( isSubtreeDisplayed() ) {\r
+ return;\r
+ }\r
+ deleteSelectedNodes( true );\r
+ }\r
+ else if ( o == _deleted_not_selected_nodes_item ) {\r
+ if ( isSubtreeDisplayed() ) {\r
+ return;\r
+ }\r
+ deleteSelectedNodes( false );\r
+ }\r
else if ( o == _annotate_item ) {\r
annotateSequences();\r
}\r
_contentpane.repaint();\r
}\r
\r
+ private void deleteSelectedNodes( boolean delete ) {\r
+ final Phylogeny phy = getMainPanel().getCurrentPhylogeny();\r
+ if ( phy == null || phy.getNumberOfExternalNodes() < 2 ) {\r
+ return;\r
+ }\r
+ List<PhylogenyNode> nodes = null;\r
+ if ( ( getCurrentTreePanel().getFoundNodes0() != null ) || ( getCurrentTreePanel().getFoundNodes1() != null ) ) {\r
+ nodes = getCurrentTreePanel().getFoundNodesAsListOfPhylogenyNodes();\r
+ }\r
+ String function = "Retain";\r
+ if ( delete ) {\r
+ function = "Delete";\r
+ }\r
+ if ( ( nodes == null ) || nodes.isEmpty() ) {\r
+ JOptionPane\r
+ .showMessageDialog( this,\r
+ "Need to select external nodes, either via direct selection or via the \"Search\" function",\r
+ "No external nodes selected to " + function.toLowerCase(),\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ final int todo = nodes.size();\r
+ final int ext = phy.getNumberOfExternalNodes();\r
+ int res = todo;\r
+ if ( delete ) {\r
+ res = ext - todo;\r
+ }\r
+ \r
+ if ( res < 1 ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Cannot delete all nodes",\r
+ "Attempt to delete all nodes ",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ final int result = JOptionPane.showConfirmDialog( null, "OK to " + function.toLowerCase() + " " + todo\r
+ + " external node(s), from a total of " + ext + " external nodes," + "\nresulting in tree with " + res\r
+ + " nodes", function + " external nodes", JOptionPane.OK_CANCEL_OPTION );\r
+ if ( result == JOptionPane.OK_OPTION ) {\r
+ if ( !delete ) {\r
+ final List<PhylogenyNode> to_delete = new ArrayList<PhylogenyNode>();\r
+ for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {\r
+ final PhylogenyNode n = it.next();\r
+ if ( !nodes.contains( n ) ) {\r
+ to_delete.add( n );\r
+ }\r
+ }\r
+ for( final PhylogenyNode n : to_delete ) {\r
+ phy.deleteSubtree( n, true );\r
+ }\r
+ }\r
+ else {\r
+ for( final PhylogenyNode n : nodes ) {\r
+ phy.deleteSubtree( n, true );\r
+ }\r
+ }\r
+ resetSearch();\r
+ getCurrentTreePanel().setNodeInPreorderToNull();\r
+ phy.externalNodesHaveChanged();\r
+ phy.clearHashIdToNodeMap();\r
+ phy.recalculateNumberOfExternalDescendants( true );\r
+ getCurrentTreePanel().resetNodeIdToDistToLeafMap();\r
+ getCurrentTreePanel().setEdited( true );\r
+ repaint();\r
+ }\r
+ }\r
+\r
+ void resetSearch() {\r
+ getMainPanel().getCurrentTreePanel().setFoundNodes0( null );\r
+ getMainPanel().getCurrentTreePanel().setFoundNodes1( null );\r
+ getMainPanel().getControlPanel().setSearchFoundCountsOnLabel0( 0 );\r
+ getMainPanel().getControlPanel().getSearchFoundCountsLabel0().setVisible( false );\r
+ getMainPanel().getControlPanel().getSearchTextField0().setText( "" );\r
+ getMainPanel().getControlPanel().getSearchResetButton0().setEnabled( false );\r
+ getMainPanel().getControlPanel().getSearchResetButton0().setVisible( false );\r
+ getMainPanel().getControlPanel().setSearchFoundCountsOnLabel1( 0 );\r
+ getMainPanel().getControlPanel().getSearchFoundCountsLabel1().setVisible( false );\r
+ getMainPanel().getControlPanel().getSearchTextField1().setText( "" );\r
+ getMainPanel().getControlPanel().getSearchResetButton1().setEnabled( false );\r
+ getMainPanel().getControlPanel().getSearchResetButton1().setVisible( false );\r
+ }\r
+\r
public Configuration getConfiguration() {\r
return _configuration;\r
}\r
\r
private void annotateSequences() {\r
if ( getCurrentTreePanel() != null ) {\r
- final Set<Long> nodes = getCurrentTreePanel().getFoundNodes0();\r
+ List<PhylogenyNode> nodes = null;\r
+ if ( ( getCurrentTreePanel().getFoundNodes0() != null )\r
+ || ( getCurrentTreePanel().getFoundNodes1() != null ) ) {\r
+ nodes = getCurrentTreePanel().getFoundNodesAsListOfPhylogenyNodes();\r
+ }\r
if ( ( nodes == null ) || nodes.isEmpty() ) {\r
JOptionPane\r
.showMessageDialog( this,\r
desc = desc.replaceAll( "\\s+", " " );\r
}\r
if ( !ForesterUtil.isEmpty( ref ) || !ForesterUtil.isEmpty( desc ) ) {\r
- for( final Long id : nodes ) {\r
- final PhylogenyNode n = phy.getNode( id );\r
+ for( final PhylogenyNode n : nodes ) {\r
ForesterUtil.ensurePresenceOfSequence( n );\r
final Annotation ann = ForesterUtil.isEmpty( ref ) ? new Annotation()\r
: new Annotation( ref );\r