From f507bf348ffed906d04bc76a614d6778d4cb5d64 Mon Sep 17 00:00:00 2001 From: cmzmasek Date: Thu, 18 Aug 2016 11:27:59 -0700 Subject: [PATCH] 0.9916 beta --- .../org/forester/archaeopteryx/AptxConstants.java | 5 +- .../org/forester/archaeopteryx/ControlPanel.java | 2 + .../src/org/forester/archaeopteryx/MainFrame.java | 10 ++ .../archaeopteryx/MainFrameApplication.java | 7 + .../src/org/forester/archaeopteryx/Options.java | 12 +- .../src/org/forester/archaeopteryx/TreePanel.java | 101 +++++++++++-- .../org/forester/archaeopteryx/TreePanelUtil.java | 140 ++++++++--------- .../archaeopteryx/util/TypomaticJButton.java | 158 ++++++++++++++++++++ .../java/src/org/forester/phylogeny/Phylogeny.java | 23 +-- .../org/forester/phylogeny/PhylogenyMethods.java | 17 ++- .../src/org/forester/util/ForesterConstants.java | 4 +- .../java/src/org/forester/util/TaxonomyUtil.java | 2 - 12 files changed, 366 insertions(+), 115 deletions(-) create mode 100644 forester/java/src/org/forester/archaeopteryx/util/TypomaticJButton.java diff --git a/forester/java/src/org/forester/archaeopteryx/AptxConstants.java b/forester/java/src/org/forester/archaeopteryx/AptxConstants.java index c322ccf..cb03d46 100644 --- a/forester/java/src/org/forester/archaeopteryx/AptxConstants.java +++ b/forester/java/src/org/forester/archaeopteryx/AptxConstants.java @@ -38,8 +38,8 @@ public final class AptxConstants { final static boolean __ALLOW_PHYLOGENETIC_INFERENCE = true; public final static String PRG_NAME = "Archaeopteryx"; - final static String VERSION = "0.9915 test"; - final static String PRG_DATE = "160727"; + final static String VERSION = "0.9916 beta"; + final static String PRG_DATE = "160817"; final static String DEFAULT_CONFIGURATION_FILE_NAME = "_aptx_configuration_file"; final static String[] DEFAULT_FONT_CHOICES = { "Arial Unicode MS", "Dialog", "SansSerif", "Sans", "Arial", "Helvetica" }; @@ -106,4 +106,5 @@ public final class AptxConstants { 150, 150 ); final static short DEFAULT_NODE_SHAPE_SIZE_DEFAULT = 4; + static final int MAX_LENGTH_FOR_COLLAPSED_NAME = 8; } diff --git a/forester/java/src/org/forester/archaeopteryx/ControlPanel.java b/forester/java/src/org/forester/archaeopteryx/ControlPanel.java index 6a45310..32121a0 100644 --- a/forester/java/src/org/forester/archaeopteryx/ControlPanel.java +++ b/forester/java/src/org/forester/archaeopteryx/ControlPanel.java @@ -2604,6 +2604,8 @@ final class ControlPanel extends JPanel implements ActionListener { } final void updateRankCollapseRankDisplay() { + + if ( _rank_collapse_depth_tf != null ) { final String r = obtainRankCollapseDepthValue(); if ( r.equals( "off" ) ) { diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrame.java b/forester/java/src/org/forester/archaeopteryx/MainFrame.java index 758f053..a06adaf 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrame.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrame.java @@ -231,6 +231,7 @@ public abstract class MainFrame extends JFrame implements ActionListener { JCheckBoxMenuItem _right_line_up_domains_cbmi; JCheckBoxMenuItem _line_up_renderable_data_cbmi; JCheckBoxMenuItem _collapsed_with_average_height_cbmi; + JCheckBoxMenuItem _show_abbreviated_labels_for_collapsed_nodes_cbmi; // _ print JCheckBoxMenuItem _graphics_export_visible_only_cbmi; JCheckBoxMenuItem _antialias_print_cbmi; @@ -581,6 +582,12 @@ public abstract class MainFrame extends JFrame implements ActionListener { } updateOptions( getOptions() ); } + else if ( o == _show_abbreviated_labels_for_collapsed_nodes_cbmi ) { + if ( _show_abbreviated_labels_for_collapsed_nodes_cbmi.isSelected() ) { + _show_abbreviated_labels_for_collapsed_nodes_cbmi.setSelected( true ); + } + updateOptions( getOptions() ); + } else if ( o == _right_line_up_domains_cbmi ) { if ( _right_line_up_domains_cbmi.isSelected() ) { _line_up_renderable_data_cbmi.setSelected( true ); @@ -1943,6 +1950,9 @@ public abstract class MainFrame extends JFrame implements ActionListener { if ( ( _collapsed_with_average_height_cbmi != null ) && _collapsed_with_average_height_cbmi.isEnabled() ) { options.setCollapsedWithAverageHeigh(_collapsed_with_average_height_cbmi.isSelected() ); } + if ( ( _show_abbreviated_labels_for_collapsed_nodes_cbmi != null ) && _show_abbreviated_labels_for_collapsed_nodes_cbmi.isEnabled() ) { + options.setShowAbbreviatedLabelsForCollapsedNodes(_show_abbreviated_labels_for_collapsed_nodes_cbmi.isSelected() ); + } } diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index 3baabd1..f5b88fb 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -1834,6 +1834,11 @@ public final class MainFrameApplication extends MainFrame { _options_jmenu + .add( _show_abbreviated_labels_for_collapsed_nodes_cbmi = new JCheckBoxMenuItem( "Add Abbreviated Labels to Collapsed Subtrees" ) ); + + + + _options_jmenu .add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) ); @@ -1941,6 +1946,8 @@ public final class MainFrameApplication extends MainFrame { customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() ); customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() ); customizeCheckBoxMenuItem( _collapsed_with_average_height_cbmi, getOptions().isCollapsedWithAverageHeigh() ); + customizeCheckBoxMenuItem( _show_abbreviated_labels_for_collapsed_nodes_cbmi, getOptions().isShowAbbreviatedLabelsForCollapsedNodes() ); + customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi, getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP ); customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi, diff --git a/forester/java/src/org/forester/archaeopteryx/Options.java b/forester/java/src/org/forester/archaeopteryx/Options.java index 4241797..5a083b4 100644 --- a/forester/java/src/org/forester/archaeopteryx/Options.java +++ b/forester/java/src/org/forester/archaeopteryx/Options.java @@ -121,6 +121,7 @@ final public class Options { private boolean _color_all_found_nodes_when_coloring_subtree; private boolean _parse_beast_style_extended_nexus_tags; private boolean _collapsed_with_average_height; + private boolean _show_abbreviated_labels_for_collapsed_nodes; private Options() { init(); @@ -225,7 +226,8 @@ final public class Options { _ext_desc_data_to_return = NodeDataField.UNKNOWN; _line_up_renderable_node_data = true; _right_align_domains = false; - _collapsed_with_average_height= true; + _collapsed_with_average_height = true; + _show_abbreviated_labels_for_collapsed_nodes = true; } final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) { @@ -611,6 +613,14 @@ final public class Options { final void setCollapsedWithAverageHeigh( final boolean collapsed_with_average_height ) { _collapsed_with_average_height = collapsed_with_average_height; } + + final boolean isShowAbbreviatedLabelsForCollapsedNodes() { + return _show_abbreviated_labels_for_collapsed_nodes; + } + + final void setShowAbbreviatedLabelsForCollapsedNodes(final boolean show_abbreviated_labels_for_collapsed_nodes) { + _show_abbreviated_labels_for_collapsed_nodes = show_abbreviated_labels_for_collapsed_nodes; + } } diff --git a/forester/java/src/org/forester/archaeopteryx/TreePanel.java b/forester/java/src/org/forester/archaeopteryx/TreePanel.java index ef650bc..53b1620 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreePanel.java +++ b/forester/java/src/org/forester/archaeopteryx/TreePanel.java @@ -2399,6 +2399,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) { c = PhylogenyMethods.getBranchColorValue( node ); } + else if ( to_pdf ) { + g.setColor( getTreeColorSet().getBranchColorForPdf() ); + } else { c = getTreeColorSet().getCollapseFillColor(); } @@ -2825,7 +2828,45 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getSequenceColor() ); if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) { - if ( _sb.length() > 0 ) { + if ( _sb.length() == 0 ) { + if ( getOptions().isShowAbbreviatedLabelsForCollapsedNodes() + && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() + || getControlPanel().isShowSeqNames() || getControlPanel().isShowNodeNames() ) ) { + final PhylogenyNode first = PhylogenyMethods.getFirstExternalNode( node ); + final PhylogenyNode last = PhylogenyMethods.getLastExternalNode( node ); + if ( getControlPanel().isShowTaxonomyCode() && first.getNodeData().isHasTaxonomy() + && last.getNodeData().isHasTaxonomy() + && !ForesterUtil.isEmpty( first.getNodeData().getTaxonomy().getTaxonomyCode() ) + && !ForesterUtil.isEmpty( last.getNodeData().getTaxonomy().getTaxonomyCode() ) ) { + addLabelForCollapsed( first.getNodeData().getTaxonomy().getTaxonomyCode(), + last.getNodeData().getTaxonomy().getTaxonomyCode(), + node.getAllExternalDescendants().size() ); + } + else if ( getControlPanel().isShowTaxonomyScientificNames() && first.getNodeData().isHasTaxonomy() + && last.getNodeData().isHasTaxonomy() + && !ForesterUtil.isEmpty( first.getNodeData().getTaxonomy().getScientificName() ) + && !ForesterUtil.isEmpty( last.getNodeData().getTaxonomy().getScientificName() ) ) { + addLabelForCollapsed( first.getNodeData().getTaxonomy().getScientificName(), + last.getNodeData().getTaxonomy().getScientificName(), + node.getAllExternalDescendants().size() ); + } + else if ( getControlPanel().isShowSeqNames() && first.getNodeData().isHasSequence() + && last.getNodeData().isHasSequence() + && !ForesterUtil.isEmpty( first.getNodeData().getSequence().getName() ) + && !ForesterUtil.isEmpty( last.getNodeData().getSequence().getName() ) ) { + addLabelForCollapsed( first.getNodeData().getSequence().getName(), + last.getNodeData().getSequence().getName(), + node.getAllExternalDescendants().size() ); + } + else if ( getControlPanel().isShowNodeNames() && !ForesterUtil.isEmpty( first.getName() ) + && !ForesterUtil.isEmpty( last.getName() ) ) { + addLabelForCollapsed( first.getName(), + last.getName(), + node.getAllExternalDescendants().size() ); + } + } + } + else if ( _sb.length() > 0 ) { _sb.setLength( 0 ); _sb.append( " (" ); _sb.append( node.getAllExternalDescendants().size() ); @@ -2993,6 +3034,15 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee return x; } + private final void addLabelForCollapsed( final String first, final String last, final int size ) { + _sb.append( first.length() < AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME ? first + : first.substring( 0, AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME - 1 ) ); + _sb.append( " ... " ); + _sb.append( last.length() < AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME ? last + : last.substring( 0, AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME - 1 ) ); + _sb.append( " (" + size + ")" ); + } + private final boolean isAllowAttributedStrings() { return false; } @@ -4847,8 +4897,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee setArrowCursor(); } - - final void colorRank( final String rank ) { if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) { return; @@ -6051,7 +6099,20 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee _sub_phylogenies_temp_roots[ _subtree_index ] = node; ++_subtree_index; _phylogeny = TreePanelUtil.subTree( node, _phylogeny ); + if ( _phylogeny.getRoot().isCollapse() ) { + _phylogeny.getRoot().setCollapse( false ); + } + _phylogeny.externalNodesHaveChanged(); + _phylogeny.clearHashIdToNodeMap(); + _phylogeny.recalculateNumberOfExternalDescendants( true ); updateSubSuperTreeButton(); + getMainPanel().getControlPanel().search0(); + getMainPanel().getControlPanel().search1(); + resetRankCollapseRankValue(); + resetDepthCollapseDepthValue(); + getMainPanel().getControlPanel().updateDomainStructureEvaluethresholdDisplay(); + getMainPanel().getControlPanel().updateDepthCollapseDepthDisplay(); + getMainPanel().getControlPanel().updateRankCollapseRankDisplay(); } else if ( node.isRoot() && isCurrentTreeIsSubtree() ) { superTree(); @@ -6069,6 +6130,16 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee _sub_phylogenies[ _subtree_index ] = null; _sub_phylogenies_temp_roots[ _subtree_index ] = null; _phylogeny = _sub_phylogenies[ --_subtree_index ]; + _phylogeny.externalNodesHaveChanged(); + _phylogeny.clearHashIdToNodeMap(); + _phylogeny.recalculateNumberOfExternalDescendants( true ); + getMainPanel().getControlPanel().search0(); + getMainPanel().getControlPanel().search1(); + resetRankCollapseRankValue(); + resetDepthCollapseDepthValue(); + getMainPanel().getControlPanel().updateDomainStructureEvaluethresholdDisplay(); + getMainPanel().getControlPanel().updateDepthCollapseDepthDisplay(); + getMainPanel().getControlPanel().updateRankCollapseRankDisplay(); updateSubSuperTreeButton(); } @@ -6290,7 +6361,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee --_depth_collapse_level; PhylogenyMethods.collapseToDepth( _phylogeny, _depth_collapse_level ); } - } } @@ -6317,34 +6387,35 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } else { --_rank_collapse_level; - PhylogenyMethods.collapseToRank( _phylogeny, mapToAbsoluteRankLevel( ranks, _rank_collapse_level ) ); + PhylogenyMethods.collapseToRank( _phylogeny, + mapToAbsoluteRankLevel( ranks, _rank_collapse_level ) ); } } } } - public void increaseRankCollapseLevel() { if ( ( _phylogeny != null ) && ( _phylogeny.getNumberOfExternalNodes() > 2 ) ) { final String ranks[] = PhylogenyMethods.obtainPresentRanksSorted( _phylogeny ); if ( ranks.length > 1 ) { - if ( _rank_collapse_level >= (ranks.length - 1 ) ) { + if ( _rank_collapse_level >= ( ranks.length - 1 ) ) { _rank_collapse_level = 0; - PhylogenyMethods.collapseToRank( _phylogeny,mapToAbsoluteRankLevel( ranks, _rank_collapse_level ) ); + PhylogenyMethods.collapseToRank( _phylogeny, + mapToAbsoluteRankLevel( ranks, _rank_collapse_level ) ); } - else if ( _rank_collapse_level == (ranks.length - 2 ) ) { + else if ( _rank_collapse_level == ( ranks.length - 2 ) ) { ++_rank_collapse_level; uncollapseAll(); } else { ++_rank_collapse_level; - PhylogenyMethods.collapseToRank( _phylogeny,mapToAbsoluteRankLevel( ranks, _rank_collapse_level ) ); + PhylogenyMethods.collapseToRank( _phylogeny, + mapToAbsoluteRankLevel( ranks, _rank_collapse_level ) ); } } } } - private final static int mapToAbsoluteRankLevel( final String present_ranks_sorted[], final int rank_collapse_level ) { final String rank_str = present_ranks_sorted[ rank_collapse_level ]; @@ -6353,14 +6424,14 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } return TaxonomyUtil.RANK_TO_INT.get( rank_str ); } - + private final void uncollapseAll() { - final PhylogenyNodeIterator it = new PreorderTreeIterator(_phylogeny ); + final PhylogenyNodeIterator it = new PreorderTreeIterator( _phylogeny ); while ( it.hasNext() ) { it.next().setCollapse( false ); } } - + final int resetDepthCollapseDepthValue() { return _depth_collapse_level = -1; } @@ -6372,7 +6443,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final void setDepthCollapseDepthValue( final int depth_collapse_level ) { _depth_collapse_level = depth_collapse_level; } - + final int resetRankCollapseRankValue() { return _rank_collapse_level = -1; } diff --git a/forester/java/src/org/forester/archaeopteryx/TreePanelUtil.java b/forester/java/src/org/forester/archaeopteryx/TreePanelUtil.java index 9aeec3b..c764eae 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreePanelUtil.java +++ b/forester/java/src/org/forester/archaeopteryx/TreePanelUtil.java @@ -307,76 +307,76 @@ public class TreePanelUtil { } } - final static int collapseByTaxonomicRank( final Phylogeny tree, final String rank, final TreePanel tree_panel ) { - final Set true_lineage_set = new HashSet(); - for( final PhylogenyNodeIterator iter = tree.iteratorPreorder(); iter.hasNext(); ) { - iter.next().setCollapse( false ); - } - int collapsed = 0; - for( final PhylogenyNodeIterator it = tree.iteratorPostorder(); it.hasNext(); ) { - final PhylogenyNode n = it.next(); - if ( !n.isExternal() && n.getNodeData().isHasTaxonomy() && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getRank() ) - && n.getNodeData().getTaxonomy().getRank().equalsIgnoreCase( rank ) /*&& !n.isRoot()*/ ) { - TreePanelUtil.collapseSubtree( n, true ); - ++collapsed; - if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) { - true_lineage_set.add( n.getNodeData().getTaxonomy().getScientificName() ); - } - } - } - for( final PhylogenyNodeIterator it = tree.iteratorPostorder(); it.hasNext(); ) { - final PhylogenyNode node = it.next(); - if ( ( !node.isExternal() && !node.isCollapse() ) && node.getNodeData().isHasTaxonomy() - && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getLineage() ) /* && !node.isRoot()*/ ) { - boolean success = false; - if ( !true_lineage_set.isEmpty() ) { - for( final String lin : node.getNodeData().getTaxonomy().getLineage() ) { - if ( true_lineage_set.contains( lin ) ) { - TreePanelUtil.collapseSubtree( node, true ); - ++collapsed; - success = true; - break; - } - } - } - if ( !success ) { - final Map lineage_to_rank_map = MainPanel.getLineageToRankMap(); - for( final String lin : node.getNodeData().getTaxonomy().getLineage() ) { - final Taxonomy temp_tax = new Taxonomy(); - temp_tax.setScientificName( lin ); - if ( lineage_to_rank_map.containsKey( lin ) - && !ForesterUtil.isEmpty( lineage_to_rank_map.get( lin ) ) - && lineage_to_rank_map.get( lin ).equalsIgnoreCase( rank ) ) { - TreePanelUtil.collapseSubtree( node, true ); - ++collapsed; - true_lineage_set.add( lin ); - break; - } - else { - UniProtTaxonomy up = null; - try { - up = TaxonomyDataManager.obtainUniProtTaxonomy( temp_tax, null, null ); - } - catch ( final Exception e ) { - e.printStackTrace(); - } - if ( ( up != null ) && !ForesterUtil.isEmpty( up.getRank() ) ) { - lineage_to_rank_map.put( lin, up.getRank() ); - System.out.println( lin + "->" + up.getRank() ); - if ( up.getRank().equalsIgnoreCase( rank ) ) { - TreePanelUtil.collapseSubtree( node, true ); - ++collapsed; - true_lineage_set.add( lin ); - break; - } - } - } - } - } - } - } - return collapsed; - } +// final static int collapseByTaxonomicRank( final Phylogeny tree, final String rank, final TreePanel tree_panel ) { +// final Set true_lineage_set = new HashSet(); +// for( final PhylogenyNodeIterator iter = tree.iteratorPreorder(); iter.hasNext(); ) { +// iter.next().setCollapse( false ); +// } +// int collapsed = 0; +// for( final PhylogenyNodeIterator it = tree.iteratorPostorder(); it.hasNext(); ) { +// final PhylogenyNode n = it.next(); +// if ( !n.isExternal() && n.getNodeData().isHasTaxonomy() && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getRank() ) +// && n.getNodeData().getTaxonomy().getRank().equalsIgnoreCase( rank ) /*&& !n.isRoot()*/ ) { +// TreePanelUtil.collapseSubtree( n, true ); +// ++collapsed; +// if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) { +// true_lineage_set.add( n.getNodeData().getTaxonomy().getScientificName() ); +// } +// } +// } +// for( final PhylogenyNodeIterator it = tree.iteratorPostorder(); it.hasNext(); ) { +// final PhylogenyNode node = it.next(); +// if ( ( !node.isExternal() && !node.isCollapse() ) && node.getNodeData().isHasTaxonomy() +// && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getLineage() ) /* && !node.isRoot()*/ ) { +// boolean success = false; +// if ( !true_lineage_set.isEmpty() ) { +// for( final String lin : node.getNodeData().getTaxonomy().getLineage() ) { +// if ( true_lineage_set.contains( lin ) ) { +// TreePanelUtil.collapseSubtree( node, true ); +// ++collapsed; +// success = true; +// break; +// } +// } +// } +// if ( !success ) { +// final Map lineage_to_rank_map = MainPanel.getLineageToRankMap(); +// for( final String lin : node.getNodeData().getTaxonomy().getLineage() ) { +// final Taxonomy temp_tax = new Taxonomy(); +// temp_tax.setScientificName( lin ); +// if ( lineage_to_rank_map.containsKey( lin ) +// && !ForesterUtil.isEmpty( lineage_to_rank_map.get( lin ) ) +// && lineage_to_rank_map.get( lin ).equalsIgnoreCase( rank ) ) { +// TreePanelUtil.collapseSubtree( node, true ); +// ++collapsed; +// true_lineage_set.add( lin ); +// break; +// } +// else { +// UniProtTaxonomy up = null; +// try { +// up = TaxonomyDataManager.obtainUniProtTaxonomy( temp_tax, null, null ); +// } +// catch ( final Exception e ) { +// e.printStackTrace(); +// } +// if ( ( up != null ) && !ForesterUtil.isEmpty( up.getRank() ) ) { +// lineage_to_rank_map.put( lin, up.getRank() ); +// System.out.println( lin + "->" + up.getRank() ); +// if ( up.getRank().equalsIgnoreCase( rank ) ) { +// TreePanelUtil.collapseSubtree( node, true ); +// ++collapsed; +// true_lineage_set.add( lin ); +// break; +// } +// } +// } +// } +// } +// } +// } +// return collapsed; +// } final static int colorPhylogenyAccordingToRanks( final Phylogeny tree, final String rank, diff --git a/forester/java/src/org/forester/archaeopteryx/util/TypomaticJButton.java b/forester/java/src/org/forester/archaeopteryx/util/TypomaticJButton.java new file mode 100644 index 0000000..6421ce2 --- /dev/null +++ b/forester/java/src/org/forester/archaeopteryx/util/TypomaticJButton.java @@ -0,0 +1,158 @@ + +package org.forester.archaeopteryx.util; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + +import javax.swing.Action; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.Timer; + +public final class TypomaticJButton extends JButton implements ActionListener, MouseListener { + + private static final long serialVersionUID = 7435606927739361980L; + private boolean pressed = false; + private boolean repeat_enabled = true; + private Timer timer = null; + private int initial_delay = 600; + private int delay = 200; + private int modifiers = 0; + + public TypomaticJButton() { + super(); + init(); + } + + public TypomaticJButton( final Action a ) { + super( a ); + init(); + } + + public TypomaticJButton( final Icon icon ) { + super( icon ); + init(); + } + + public TypomaticJButton( final String text ) { + super( text ); + init(); + } + + public TypomaticJButton( final String text, final Icon icon ) { + super( text, icon ); + init(); + } + + @Override + final public void actionPerformed( final ActionEvent ae ) { + if ( ae.getSource() == timer ) { + final ActionEvent event = new ActionEvent( this, + ActionEvent.ACTION_PERFORMED, + super.getActionCommand(), + modifiers ); + super.fireActionPerformed( event ); + } + } + + final public int getDelay() { + return delay; + } + + final public int getInitialDelay() { + return initial_delay; + } + + final private void init() { + addMouseListener( this ); + timer = new Timer( delay, this ); + timer.setRepeats( true ); + } + + final public boolean isRepeatEnabled() { + return repeat_enabled; + } + + @Override + final public void mouseClicked( final MouseEvent me ) { + if ( me.getSource() == this ) { + pressed = false; + if ( timer.isRunning() ) { + timer.stop(); + } + } + } + + @Override + final public void mouseEntered( final MouseEvent e ) { + if ( ( e.getSource() == this ) && isEnabled() && isRepeatEnabled() ) { + if ( pressed && !timer.isRunning() ) { + modifiers = e.getModifiers(); + timer.setInitialDelay( delay ); + timer.start(); + } + } + } + + @Override + final public void mouseExited( final MouseEvent e ) { + if ( e.getSource() == this ) { + if ( timer.isRunning() ) { + timer.stop(); + } + } + } + + @Override + final public void mousePressed( final MouseEvent e ) { + if ( ( e.getSource() == this ) && isEnabled() && isRepeatEnabled() ) { + pressed = true; + if ( !timer.isRunning() ) { + modifiers = e.getModifiers(); + timer.setInitialDelay( initial_delay ); + timer.start(); + } + } + } + + @Override + final public void mouseReleased( final MouseEvent e ) { + if ( e.getSource() == this ) { + pressed = false; + if ( timer.isRunning() ) { + timer.stop(); + } + } + } + + final public void setDelay( final int d ) { + delay = d; + } + + @Override + final public void setEnabled( final boolean e ) { + if ( e != super.isEnabled() ) { + pressed = false; + if ( timer.isRunning() ) { + timer.stop(); + } + } + super.setEnabled( e ); + } + + final public void setInitialDelay( final int d ) { + initial_delay = d; + } + + final public void setRepeatEnabled( final boolean e ) { + if ( !e ) { + pressed = false; + if ( timer.isRunning() ) { + timer.stop(); + } + } + repeat_enabled = e; + } +} \ No newline at end of file diff --git a/forester/java/src/org/forester/phylogeny/Phylogeny.java b/forester/java/src/org/forester/phylogeny/Phylogeny.java index 0990171..34eb487 100644 --- a/forester/java/src/org/forester/phylogeny/Phylogeny.java +++ b/forester/java/src/org/forester/phylogeny/Phylogeny.java @@ -332,28 +332,7 @@ public class Phylogeny { return _external_nodes_set; } - /** - * Returns the number of duplications of this Phylogeny (int). A return - * value of -1 indicates that the number of duplications is unknown. - */ - // public int getNumberOfDuplications() { - // return _number_of_duplications; - // } // getNumberOfDuplications() - /** - * Sets the number of duplications of this Phylogeny (int). A value of -1 - * indicates that the number of duplications is unknown. - * - * @param clean_nh - * set to true for clean NH format - */ - // public void setNumberOfDuplications( int i ) { - // if ( i < 0 ) { - // _number_of_duplications = -1; - // } - // else { - // _number_of_duplications = i; - // } - // } // setNumberOfDuplications( int ) + /** * Returns the first external PhylogenyNode. */ diff --git a/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java b/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java index dfe3341..97eba29 100644 --- a/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java +++ b/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java @@ -66,6 +66,7 @@ import org.forester.phylogeny.iterators.PhylogenyNodeIterator; import org.forester.phylogeny.iterators.PreorderTreeIterator; import org.forester.util.BasicDescriptiveStatistics; import org.forester.util.DescriptiveStatistics; +import org.forester.util.FailedConditionCheckException; import org.forester.util.ForesterUtil; import org.forester.util.TaxonomyUtil; @@ -2126,6 +2127,20 @@ public class PhylogenyMethods { } } - + public final static PhylogenyNode getFirstExternalNode( final PhylogenyNode node ) { + PhylogenyNode n = node; + while ( n.isInternal() ) { + n = n.getFirstChildNode(); + } + return n; + } + + public final static PhylogenyNode getLastExternalNode( final PhylogenyNode node ) { + PhylogenyNode n = node; + while ( n.isInternal() ) { + n = n.getLastChildNode(); + } + return n; + } } diff --git a/forester/java/src/org/forester/util/ForesterConstants.java b/forester/java/src/org/forester/util/ForesterConstants.java index 441b0f7..af05ca0 100644 --- a/forester/java/src/org/forester/util/ForesterConstants.java +++ b/forester/java/src/org/forester/util/ForesterConstants.java @@ -27,8 +27,8 @@ package org.forester.util; public final class ForesterConstants { - public final static String FORESTER_VERSION = "1.042"; - public final static String FORESTER_DATE = "160712"; + public final static String FORESTER_VERSION = "1.043"; + public final static String FORESTER_DATE = "160817"; public final static String PHYLO_XML_VERSION = "1.20"; public final static String PHYLO_XML_LOCATION = "http://www.phyloxml.org"; public final static String PHYLO_XML_XSD = "phyloxml.xsd"; diff --git a/forester/java/src/org/forester/util/TaxonomyUtil.java b/forester/java/src/org/forester/util/TaxonomyUtil.java index a5beeac..6fc79de 100644 --- a/forester/java/src/org/forester/util/TaxonomyUtil.java +++ b/forester/java/src/org/forester/util/TaxonomyUtil.java @@ -674,12 +674,10 @@ public final class TaxonomyUtil { static { // same thing as set: for( final String rank : TAXONOMY_RANKS_LIST ) { - System.out.println( "=" + rank ); TAXONOMY_RANKS_SET.add( rank ); } final int l = RANKS.length; for( int i = 0; i < l; ++i ) { - System.out.println( "i=" + i ); RANKS[ i ] = TAXONOMY_RANKS_LIST.get( i ); RANK_TO_INT.put( RANKS[ i ], i ); } -- 1.7.10.2