From: cmzmasek@gmail.com Date: Sat, 11 Jun 2011 04:04:40 +0000 (+0000) Subject: in progress X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=2f2348de20c5db605c224b87dadd2e8c10f5d51d;p=jalview.git in progress --- diff --git a/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java b/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java index 9e483b7..7dbed25 100644 --- a/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java +++ b/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java @@ -98,7 +98,6 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { private JMenuItem _choose_font_mi; private JMenuItem _switch_colors_mi; JCheckBoxMenuItem _label_direction_cbmi; - private JCheckBoxMenuItem _show_node_boxes_cbmi; private JCheckBoxMenuItem _show_scale_cbmi; private JCheckBoxMenuItem _search_case_senstive_cbmi; private JCheckBoxMenuItem _search_whole_words_only_cbmi; @@ -109,6 +108,11 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { private JMenuItem _collapse_species_specific_subtrees; private JMenuItem _overview_placment_mi; private ButtonGroup _radio_group_1; + private JCheckBoxMenuItem _show_default_node_shapes_cbmi; + private JMenuItem _cycle_node_shape_mi; + private JMenuItem _cycle_node_fill_mi; + private JMenuItem _choose_node_size_mi; + private JCheckBoxMenuItem _taxonomy_colorize_node_shapes_cbmi; @Override public void actionPerformed( final ActionEvent e ) { @@ -186,11 +190,17 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { else if ( o == _choose_minimal_confidence_mi ) { chooseMinimalConfidence(); } + else if ( o == _choose_node_size_mi ) { + MainFrame.chooseNodeSize( getOptions(), this ); + } else if ( o == _overview_placment_mi ) { MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() ); } - else if ( o == _show_node_boxes_cbmi ) { - updateOptions( getOptions() ); + else if ( o == _cycle_node_fill_mi ) { + MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() ); + } + else if ( o == _cycle_node_shape_mi ) { + MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() ); } else if ( o == _non_lined_up_cladograms_rbmi ) { updateOptions( getOptions() ); @@ -249,6 +259,12 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { else if ( o == _color_labels_same_as_parent_branch ) { updateOptions( getOptions() ); } + else if ( o == _show_default_node_shapes_cbmi ) { + updateOptions( getOptions() ); + } + else if ( o == _taxonomy_colorize_node_shapes_cbmi ) { + updateOptions( getOptions() ); + } else if ( o == _about_item ) { MainFrame.about(); } @@ -331,7 +347,7 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { @Override public void stateChanged( final ChangeEvent e ) { - MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getCurrentTreePanel() ); + MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() ); MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() ); MainFrame .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() ); @@ -344,6 +360,9 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { _uniform_cladograms_rbmi, _ext_node_dependent_cladogram_rbmi, _label_direction_cbmi ); + MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() ); + MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() ); + MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() ); } } ); _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ), @@ -357,7 +376,15 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { _radio_group_1.add( _ext_node_dependent_cladogram_rbmi ); _radio_group_1.add( _uniform_cladograms_rbmi ); _radio_group_1.add( _non_lined_up_cladograms_rbmi ); - _options_jmenu.add( _show_node_boxes_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL ) ); + // + _options_jmenu + .add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL ) ); + _options_jmenu + .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) ); + _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) ); + _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) ); + _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) ); + // _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) ); _options_jmenu .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) ); @@ -389,13 +416,17 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { customizeJMenuItem( _choose_minimal_confidence_mi ); customizeJMenuItem( _switch_colors_mi ); customizeJMenuItem( _overview_placment_mi ); - customizeCheckBoxMenuItem( _show_node_boxes_cbmi, getOptions().getDefaultNodeShape() ); customizeCheckBoxMenuItem( _label_direction_cbmi, getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL ); customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() ); customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() ); customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() ); customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() ); + customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() ); + customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() ); + customizeJMenuItem( _cycle_node_shape_mi ); + customizeJMenuItem( _cycle_node_fill_mi ); + customizeJMenuItem( _choose_node_size_mi ); customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() ); customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() ); customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() ); @@ -894,7 +925,10 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { && _abbreviate_scientific_names.isSelected() ); options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null ) && _color_labels_same_as_parent_branch.isSelected() ); - options.setShowNodeBoxes( ( _show_node_boxes_cbmi != null ) && _show_node_boxes_cbmi.isSelected() ); + options.setShowDefaultNodeShapes( ( _show_default_node_shapes_cbmi != null ) + && _show_default_node_shapes_cbmi.isSelected() ); + options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null ) + && _taxonomy_colorize_node_shapes_cbmi.isSelected() ); if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) { options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP ); } diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrame.java b/forester/java/src/org/forester/archaeopteryx/MainFrame.java index fdff501..95d8b92 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrame.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrame.java @@ -24,6 +24,7 @@ package org.forester.archaeopteryx; +import java.awt.Component; import java.awt.Container; import java.awt.Font; import java.awt.event.ActionEvent; @@ -309,9 +310,18 @@ public abstract class MainFrame extends JFrame implements ActionListener { else if ( o == _choose_minimal_confidence_mi ) { chooseMinimalConfidence(); } + else if ( o == _choose_node_size_mi ) { + chooseNodeSize( getOptions(), this ); + } else if ( o == _overview_placment_mi ) { MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() ); } + else if ( o == _cycle_node_fill_mi ) { + MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() ); + } + else if ( o == _cycle_node_shape_mi ) { + MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() ); + } else if ( o == _screen_antialias_cbmi ) { updateOptions( getOptions() ); updateScreenTextAntialias( getMainPanel().getTreePanels() ); @@ -574,6 +584,40 @@ public abstract class MainFrame extends JFrame implements ActionListener { } } + static void chooseNodeSize( final Options options, final Component parent ) { + final String s = ( String ) JOptionPane.showInputDialog( parent, + "Please enter the default size for node shapes.\n" + + "[current value: " + + options.getDefaultNodeShapeSize() + "]\n", + "Node Shape Size", + JOptionPane.QUESTION_MESSAGE, + null, + null, + options.getDefaultNodeShapeSize() ); + if ( !ForesterUtil.isEmpty( s ) ) { + boolean success = true; + double m = 0.0; + final String m_str = s.trim(); + if ( !ForesterUtil.isEmpty( m_str ) ) { + try { + m = Double.parseDouble( m_str ); + } + catch ( final Exception ex ) { + success = false; + } + } + else { + success = false; + } + if ( success && ( m >= 0.0 ) ) { + final short size = ForesterUtil.roundToShort( m ); + if ( size >= 0.0 ) { + options.setDefaultNodeShapeSize( size ); + } + } + } + } + void close() { removeTextFrame(); if ( _mainpanel != null ) { @@ -861,12 +905,10 @@ public abstract class MainFrame extends JFrame implements ActionListener { && _abbreviate_scientific_names.isSelected() ); options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null ) && _color_labels_same_as_parent_branch.isSelected() ); - //TODO FIXME ~~ options.setShowDefaultNodeShapes( ( _show_default_node_shapes_cbmi != null ) && _show_default_node_shapes_cbmi.isSelected() ); options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null ) && _taxonomy_colorize_node_shapes_cbmi.isSelected() ); - //TODO FIXME ~~ if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) { options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP ); } @@ -1068,7 +1110,38 @@ public abstract class MainFrame extends JFrame implements ActionListener { default: throw new RuntimeException( "unknown placement: " + op.getOvPlacement() ); } - tree_panel.updateOvSettings(); + if ( tree_panel != null ) { + tree_panel.updateOvSettings(); + } + } + + static void cycleNodeFill( final Options op, final TreePanel tree_panel ) { + switch ( op.getDefaultNodeFill() ) { + case GRADIENT: + op.setDefaultNodeFill( Options.NodeFill.SOLID ); + break; + case NONE: + op.setDefaultNodeFill( Options.NodeFill.GRADIENT ); + break; + case SOLID: + op.setDefaultNodeFill( Options.NodeFill.NONE ); + break; + default: + throw new RuntimeException( "unknown fill: " + op.getDefaultNodeFill() ); + } + } + + static void cycleNodeShape( final Options op, final TreePanel tree_panel ) { + switch ( op.getDefaultNodeShape() ) { + case CIRCLE: + op.setDefaultNodeShape( Options.NodeShape.RECTANGLE ); + break; + case RECTANGLE: + op.setDefaultNodeShape( Options.NodeShape.CIRCLE ); + break; + default: + throw new RuntimeException( "unknown shape: " + op.getDefaultNodeShape() ); + } } static void help( final Map weblinks ) { @@ -1169,12 +1242,32 @@ public abstract class MainFrame extends JFrame implements ActionListener { TextFrame.instantiate( sb.toString() ); } - static void setOvPlacementColorChooseMenuItem( final JMenuItem mi, final TreePanel tree_panel ) { - if ( ( tree_panel != null ) && ( tree_panel.getTreeColorSet() != null ) ) { - mi.setText( "Overview Placement... (current: " + tree_panel.getOptions().getOvPlacement() + ")" ); + static void setOvPlacementColorChooseMenuItem( final JMenuItem mi, final Options options ) { + if ( ( options != null ) && ( options.getOvPlacement() != null ) ) { + mi.setText( "Cycle Overview Placement... (current: " + options.getOvPlacement() + ")" ); } else { - mi.setText( "Overview Placement..." ); + mi.setText( "Cycle Overview Placement..." ); + } + } + + static void setCycleNodeFillMenuItem( final JMenuItem mi, final Options options ) { + if ( ( options != null ) && ( options.getDefaultNodeFill() != null ) ) { + mi.setText( "Cycle Node Shape Fill Type... (current: " + + options.getDefaultNodeFill().toString().toLowerCase() + ")" ); + } + else { + mi.setText( "Cycle Node Shape Fill Type..." ); + } + } + + static void setCycleNodeShapeMenuItem( final JMenuItem mi, final Options options ) { + if ( ( options != null ) && ( options.getDefaultNodeShape() != null ) ) { + mi.setText( "Cycle Node Shape Fill Type... (current: " + + options.getDefaultNodeShape().toString().toLowerCase() + ")" ); + } + else { + mi.setText( "Cycle Node Shape Fill Type..." ); } } @@ -1204,6 +1297,10 @@ public abstract class MainFrame extends JFrame implements ActionListener { mi.setText( "Enter Min Confidence Value... (current: " + options.getMinConfidenceValue() + ")" ); } + static void setTextNodeSizeMenuItem( final JMenuItem mi, final Options options ) { + mi.setText( "Enter Default Node Shape Size... (current: " + options.getDefaultNodeShapeSize() + ")" ); + } + static void updateOptionsMenuDependingOnPhylogenyType( final MainPanel main_panel, final JCheckBoxMenuItem scale, final JCheckBoxMenuItem branch_lengths, diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java index 7eb1f4f..c67d836 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java @@ -142,7 +142,6 @@ public final class MainFrameApplet extends MainFrame { setFocusable( true ); requestFocus(); requestFocusInWindow(); - // All done: hello, world! setVisible( true ); System.gc(); } @@ -153,7 +152,7 @@ public final class MainFrameApplet extends MainFrame { @Override public void stateChanged( final ChangeEvent e ) { - MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getCurrentTreePanel() ); + MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() ); MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() ); MainFrame .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() ); @@ -166,6 +165,9 @@ public final class MainFrameApplet extends MainFrame { _uniform_cladograms_rbmi, _ext_node_dependent_cladogram_rbmi, _label_direction_cbmi ); + MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() ); + MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() ); + MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() ); } } ); _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ), @@ -178,8 +180,12 @@ public final class MainFrameApplet extends MainFrame { _radio_group_1.add( _ext_node_dependent_cladogram_rbmi ); _radio_group_1.add( _uniform_cladograms_rbmi ); _radio_group_1.add( _non_lined_up_cladograms_rbmi ); + _options_jmenu.add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL ) ); _options_jmenu - .add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL ) ); + .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) ); + _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) ); + _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) ); + _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) ); _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) ); _options_jmenu .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) ); @@ -209,7 +215,11 @@ public final class MainFrameApplet extends MainFrame { customizeJMenuItem( _switch_colors_mi ); customizeJMenuItem( _choose_minimal_confidence_mi ); customizeJMenuItem( _overview_placment_mi ); - customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().getDefaultNodeShape() ); + customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() ); + customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() ); + customizeJMenuItem( _cycle_node_shape_mi ); + customizeJMenuItem( _cycle_node_fill_mi ); + customizeJMenuItem( _choose_node_size_mi ); customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() ); customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() ); customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() ); diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index f37e8a7..7af0adc 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -685,7 +685,7 @@ public final class MainFrameApplication extends MainFrame { @Override public void stateChanged( final ChangeEvent e ) { - MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getCurrentTreePanel() ); + MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() ); MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() ); MainFrame .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() ); @@ -700,6 +700,9 @@ public final class MainFrameApplication extends MainFrame { _uniform_cladograms_rbmi, _ext_node_dependent_cladogram_rbmi, _label_direction_cbmi ); + MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() ); + MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() ); + MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() ); } } ); _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) ); @@ -711,14 +714,12 @@ public final class MainFrameApplication extends MainFrame { _radio_group_1.add( _ext_node_dependent_cladogram_rbmi ); _radio_group_1.add( _uniform_cladograms_rbmi ); _radio_group_1.add( _non_lined_up_cladograms_rbmi ); - // _options_jmenu.add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL ) ); _options_jmenu .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) ); _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) ); _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) ); _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) ); - // _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) ); _options_jmenu .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) ); @@ -769,13 +770,11 @@ public final class MainFrameApplication extends MainFrame { customizeJMenuItem( _print_size_mi ); customizeJMenuItem( _choose_pdf_width_mi ); customizeJMenuItem( _overview_placment_mi ); - //TODO FIXME ~~ customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() ); customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() ); customizeJMenuItem( _cycle_node_shape_mi ); customizeJMenuItem( _cycle_node_fill_mi ); customizeJMenuItem( _choose_node_size_mi ); - //TODO FIXME ~~ customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() ); customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() ); customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() ); diff --git a/forester/java/src/org/forester/archaeopteryx/TreePanel.java b/forester/java/src/org/forester/archaeopteryx/TreePanel.java index fc2c074..7bf3375 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreePanel.java +++ b/forester/java/src/org/forester/archaeopteryx/TreePanel.java @@ -144,7 +144,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee private final static NumberFormat FORMATTER_CONFIDENCE; private final static NumberFormat FORMATTER_BRANCH_LENGTH; private final static int WIGGLE = 2; - private final int _half_box_size_plus_wiggle; + //private final int _half_box_size_plus_wiggle; private final static int LIMIT_FOR_HQ_RENDERING = 1000; private final static int CONFIDENCE_LEFT_MARGIN = 4; // TODO "rendering_hints" was static before. Need to make sure everything is OK with it not @@ -218,8 +218,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee private boolean _edited = false; private Popup _node_desc_popup; private JTextArea _rollover_popup; - private final int _box_size; - private final int _half_box_size; + // private final int _box_size; + // private final int _half_box_size; //private final short _skip_counter = 0; private final StringBuffer _popup_buffer = new StringBuffer(); final private static Font POPUP_FONT = new Font( Configuration.getDefaultFontFamilyName(), @@ -268,9 +268,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee _configuration = configuration; _phylogeny = t; _phy_has_branch_lengths = ForesterUtil.isHasAtLeastOneBranchLengthLargerThanZero( _phylogeny ); - _box_size = tjp.getOptions().getDefaultNodeShapeSize(); - _half_box_size = tjp.getOptions().getDefaultNodeShapeSize() / 2; - _half_box_size_plus_wiggle = _half_box_size + WIGGLE; init(); // if ( !_phylogeny.isEmpty() ) { _phylogeny.recalculateNumberOfExternalDescendants( true ); @@ -945,7 +942,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee g.fill( _rectangle ); } - //TODO FIXME final private void drawRectGradient( final double x, final double y, final double width, @@ -969,7 +965,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } } - //TODO FIXME final private void drawOvalGradient( final double x, final double y, final double width, @@ -1011,13 +1006,14 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) { return null; } + final int half_box_size_plus_wiggle = getOptions().getDefaultNodeShapeSize() / 2 + WIGGLE; for( final PhylogenyNodeIterator iter = _phylogeny.iteratorPostorder(); iter.hasNext(); ) { final PhylogenyNode node = iter.next(); if ( ( _phylogeny.isRooted() || !node.isRoot() || ( node.getNumberOfDescendants() > 2 ) ) - && ( ( node.getXcoord() - _half_box_size_plus_wiggle ) <= x ) - && ( ( node.getXcoord() + _half_box_size_plus_wiggle ) >= x ) - && ( ( node.getYcoord() - _half_box_size_plus_wiggle ) <= y ) - && ( ( node.getYcoord() + _half_box_size_plus_wiggle ) >= y ) ) { + && ( ( node.getXcoord() - half_box_size_plus_wiggle ) <= x ) + && ( ( node.getXcoord() + half_box_size_plus_wiggle ) >= x ) + && ( ( node.getYcoord() - half_box_size_plus_wiggle ) <= y ) + && ( ( node.getYcoord() + half_box_size_plus_wiggle ) >= y ) ) { return node; } } @@ -2469,9 +2465,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee g.draw( _arc ); } } - //TODO new ***** if ( node.isExternal() ) { - //TODO new ***** paintNodeBox( x2, y2, node, g, to_pdf, to_graphics_file, isInFoundNodes( node ) ); } } @@ -2600,21 +2594,22 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final boolean to_graphics_file, final boolean to_pdf, final boolean is_in_found_nodes ) { + Color c = null; if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) { - g.setColor( Color.BLACK ); + c = Color.BLACK; } else if ( is_in_found_nodes ) { - g.setColor( getTreeColorSet().getFoundColor() ); + c = getTreeColorSet().getFoundColor(); } else if ( getControlPanel().isColorAccordingToTaxonomy() ) { - g.setColor( getTaxonomyBasedColor( node ) ); + c = getTaxonomyBasedColor( node ); } else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) { - g.setColor( PhylogenyMethods.getBranchColorValue( node ) ); + c = PhylogenyMethods.getBranchColorValue( node ); } else { - g.setColor( getTreeColorSet().getCollapseFillColor() ); + c = getTreeColorSet().getCollapseFillColor(); } double d = node.getAllExternalDescendants().size(); if ( d > 1000 ) { @@ -2623,17 +2618,34 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else { d = ( Math.log10( d ) * _y_distance ) / 2.5; } - if ( d < _box_size ) { - d = _box_size; + final int box_size = getOptions().getDefaultNodeShapeSize(); + if ( d < box_size ) { + d = box_size; } _polygon.reset(); - _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() - _box_size ), + _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() - box_size ), ForesterUtil.roundToInt( node.getYcoord() ) ); - _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() + _box_size ), + _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() + box_size ), ForesterUtil.roundToInt( node.getYcoord() - d ) ); - _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() + _box_size ), + _polygon.addPoint( ForesterUtil.roundToInt( node.getXcoord() + box_size ), ForesterUtil.roundToInt( node.getYcoord() + d ) ); - g.fillPolygon( _polygon ); + if ( getOptions().getDefaultNodeFill() == NodeFill.SOLID ) { + g.setColor( c ); + g.fillPolygon( _polygon ); + } + else if ( getOptions().getDefaultNodeFill() == NodeFill.NONE ) { + g.setColor( getBackground() ); + g.fillPolygon( _polygon ); + g.setColor( c ); + g.drawPolygon( _polygon ); + } + else if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) { + g.setPaint( new GradientPaint( node.getXcoord() - box_size, node.getYcoord(), getBackground(), ( node + .getXcoord() + box_size ), ( float ) ( node.getYcoord() - d ), c, false ) ); + g.fill( _polygon ); + g.setPaint( c ); + g.draw( _polygon ); + } paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes ); } @@ -2724,8 +2736,10 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } final private void paintFoundNode( final int x, final int y, final Graphics2D g ) { + final int box_size = getOptions().getDefaultNodeShapeSize(); + final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2; g.setColor( getTreeColorSet().getFoundColor() ); - g.fillRect( x - _half_box_size, y - _half_box_size, _box_size, _box_size ); + g.fillRect( x - half_box_size, y - half_box_size, box_size, box_size ); } final private void paintGainedAndLostCharacters( final Graphics2D g, @@ -2804,16 +2818,16 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else { outline_color = getGraphicsForNodeBoxWithColorForParentBranch( node ); } + final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2; + final int box_size = getOptions().getDefaultNodeShapeSize(); if ( ( ( getOptions().isShowDefaultNodeShapes() ) /*&& !to_pdf && !to_graphics_file*/) || ( getControlPanel().isEvents() && node.isHasAssignedEvent() ) ) { if ( to_pdf || to_graphics_file ) { if ( node.isDuplication() || !getOptions().isPrintBlackAndWhite() ) { - //TODO FIXME - //drawOvalFilled( x - _half_box_size, y - _half_box_size, _box_size, _box_size, g ); - drawOvalGradient( x - _half_box_size, - y - _half_box_size, - _box_size, - _box_size, + drawOvalGradient( x - half_box_size, + y - half_box_size, + box_size, + box_size, g, outline_color, getBackground(), @@ -2821,24 +2835,22 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } } else { - //TODO FIXME - //drawRectFilled( x - HALF_BOX_SIZE, y - HALF_BOX_SIZE, BOX_SIZE, BOX_SIZE, g ); if ( getOptions().getDefaultNodeShape() == NodeShape.CIRCLE ) { if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) { - drawOvalGradient( x - _half_box_size, - y - _half_box_size, - _box_size, - _box_size, + drawOvalGradient( x - half_box_size, + y - half_box_size, + box_size, + box_size, g, outline_color, getBackground(), outline_color ); } else if ( getOptions().getDefaultNodeFill() == NodeFill.NONE ) { - drawOvalGradient( x - _half_box_size, - y - _half_box_size, - _box_size, - _box_size, + drawOvalGradient( x - half_box_size, + y - half_box_size, + box_size, + box_size, g, getBackground(), getBackground(), @@ -2846,25 +2858,25 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } else if ( getOptions().getDefaultNodeFill() == NodeFill.SOLID ) { g.setColor( outline_color ); - drawOvalFilled( x - _half_box_size, y - _half_box_size, _box_size, _box_size, g ); + drawOvalFilled( x - half_box_size, y - half_box_size, box_size, box_size, g ); } } else if ( getOptions().getDefaultNodeShape() == NodeShape.RECTANGLE ) { if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) { - drawRectGradient( x - _half_box_size, - y - _half_box_size, - _box_size, - _box_size, + drawRectGradient( x - half_box_size, + y - half_box_size, + box_size, + box_size, g, outline_color, getBackground(), outline_color ); } else if ( getOptions().getDefaultNodeFill() == NodeFill.NONE ) { - drawRectGradient( x - _half_box_size, - y - _half_box_size, - _box_size, - _box_size, + drawRectGradient( x - half_box_size, + y - half_box_size, + box_size, + box_size, g, getBackground(), getBackground(), @@ -2872,7 +2884,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } else if ( getOptions().getDefaultNodeFill() == NodeFill.SOLID ) { g.setColor( outline_color ); - drawRectFilled( x - _half_box_size, y - _half_box_size, _box_size, _box_size, g ); + drawRectFilled( x - half_box_size, y - half_box_size, box_size, box_size, g ); } } } @@ -2898,13 +2910,14 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee return; } int x = 0; + final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2; if ( getControlPanel().isShowTaxonomyImages() && ( getImageMap() != null ) && !getImageMap().isEmpty() && node.getNodeData().isHasTaxonomy() && ( ( node.getNodeData().getTaxonomy().getUris() != null ) && !node.getNodeData().getTaxonomy() .getUris().isEmpty() ) ) { - x += drawTaxonomyImage( node.getXcoord() + 2 + _half_box_size, node.getYcoord(), node, g ); + x += drawTaxonomyImage( node.getXcoord() + 2 + half_box_size, node.getYcoord(), node, g ); } if ( ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel() .isShowTaxonomyCommonNames() ) && node.getNodeData().isHasTaxonomy() ) { @@ -2973,7 +2986,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( !node.isExternal() && ( node.getNumberOfDescendants() == 1 ) ) { down_shift_factor = 1; } - final double pos_x = node.getXcoord() + x + 2 + _half_box_size; + final double pos_x = node.getXcoord() + x + 2 + half_box_size; final double pos_y = ( node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ) ); final String sb_str = _sb.toString(); // GUILHEM_BEG ______________ @@ -2998,7 +3011,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee && seqRelation.getType().equals( getControlPanel().getSequenceRelationTypeBox() .getSelectedItem() ); if ( fGotRelationWithQuery ) { // we will underline the text to show that this sequence is ortholog to the query - final double linePosX = node.getXcoord() + 2 + _half_box_size; + final double linePosX = node.getXcoord() + 2 + half_box_size; final String sConfidence = ( !getControlPanel().isShowSequenceRelationConfidence() || ( seqRelation .getConfidence() == null ) ) ? null : " (" + seqRelation.getConfidence().getValue() + ")"; @@ -3056,7 +3069,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee g.setColor( calculateColorForAnnotation( ann ) ); } final String ann_str = ann.asSimpleText().toString(); - TreePanel.drawString( ann_str, node.getXcoord() + x + 3 + _half_box_size, node.getYcoord() + TreePanel.drawString( ann_str, node.getXcoord() + x + 3 + half_box_size, node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g ); _sb.setLength( 0 ); _sb.append( ann_str ); @@ -3077,7 +3090,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } if ( getControlPanel().isShowBinaryCharacters() ) { TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCharactersAsStringBuffer() - .toString(), node.getXcoord() + x + 1 + _half_box_size, node.getYcoord() + .toString(), node.getXcoord() + x + 1 + half_box_size, node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g ); paintGainedAndLostCharacters( g, node, node.getNodeData().getBinaryCharacters() .getGainedCharactersAsStringBuffer().toString(), node.getNodeData().getBinaryCharacters() @@ -3096,12 +3109,12 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } final double mean = ForesterUtil.round( sum / count, 1 ); TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount() + " [" - + mean + "]", node.getXcoord() + x + 4 + _half_box_size, node.getYcoord() + + mean + "]", node.getXcoord() + x + 4 + half_box_size, node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g ); } else { TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount(), - node.getXcoord() + x + 4 + _half_box_size, + node.getXcoord() + x + 4 + half_box_size, node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g ); @@ -3432,9 +3445,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee child_node.setYcoord( y2 ); y2 += _y_distance * child_node.getNumberOfExternalNodes(); } - //TODO new ***** paintNodeBox( node.getXcoord(), node.getYcoord(), node, g, to_pdf, to_graphics_file, isInFoundNodes( node ) ); - //TODO new ***** } if ( dynamically_hide && !is_in_found_nodes @@ -3844,7 +3855,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else { g.setColor( getTreeColorSet().getTaxonomyColor() ); } - final double start_x = node.getXcoord() + 3 + _half_box_size + x_shift; + final double start_x = node.getXcoord() + 3 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift; final double start_y = node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0 ) ); _sb.setLength( 0 ); diff --git a/forester/java/src/org/forester/util/ForesterUtil.java b/forester/java/src/org/forester/util/ForesterUtil.java index 11eb2e4..111dc40 100644 --- a/forester/java/src/org/forester/util/ForesterUtil.java +++ b/forester/java/src/org/forester/util/ForesterUtil.java @@ -1066,6 +1066,10 @@ public final class ForesterUtil { return ( int ) ( d + 0.5 ); } + final public static short roundToShort( final double d ) { + return ( short ) ( d + 0.5 ); + } + final public static int roundToInt( final float f ) { return ( int ) ( f + 0.5f ); }