1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
|
// $Id:
// FORESTER -- software libraries and applications
// for evolutionary biology research and applications.
//
// Copyright (C) 2008-2009 Christian M. Zmasek
// Copyright (C) 2008-2009 Burnham Institute for Medical Research
// Copyright (C) 2000-2001 Washington University School of Medicine
// and Howard Hughes Medical Institute
// Copyright (C) 2003-2007 Ethalinda K.S. Cannon
// All rights reserved
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
//
// Contact: phylosoft @ gmail . com
// WWW: https://sites.google.com/site/cmzmasek/home/software/forester
package org.forester.archaeopteryx;
import java.awt.BorderLayout;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.ButtonGroup;
import javax.swing.JApplet;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
import org.forester.phylogeny.Phylogeny;
import org.forester.util.ForesterUtil;
public final class MainFrameApplet extends MainFrame {
private static final long serialVersionUID = 1941019292746717053L;
private final static int DEFAULT_FRAME_X_SIZE = 640;
private final static int DEFAULT_FRAME_Y_SIZE = 580;
private final ArchaeopteryxA _applet;
private ButtonGroup _radio_group_1;
MainFrameApplet( final ArchaeopteryxA parent_applet,
final Configuration configuration,
final String species_tree_url_str ) {
setTitle( ArchaeopteryxA.NAME );
_applet = parent_applet;
setConfiguration( configuration );
setOptions( Options.createInstance( configuration ) );
_mainpanel = new MainPanelApplets( _configuration, this );
if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
try {
readSpeciesTree( configuration, species_tree_url_str );
}
catch ( final Exception e ) {
ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, "failed to read species tree from "
+ species_tree_url_str );
ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, e.toString() );
}
}
// build the menu bar
_jmenubar = new JMenuBar();
buildFileMenu();
if ( !_configuration.isUseNativeUI() ) {
_jmenubar.setBackground( _configuration.getGuiMenuBackgroundColor() );
}
buildAnalysisMenu();
buildToolsMenu();
buildViewMenu();
buildFontSizeMenu();
buildOptionsMenu();
buildTypeMenu();
buildHelpMenu();
setJMenuBar( _jmenubar );
_contentpane = getContentPane();
_contentpane.setLayout( new BorderLayout() );
_contentpane.add( _mainpanel, BorderLayout.CENTER );
setSize( getConfiguration().getFrameXSize() > 40 ? getConfiguration().getFrameXSize() : DEFAULT_FRAME_X_SIZE,
getConfiguration().getFrameYSize() > 40 ? getConfiguration().getFrameYSize() : DEFAULT_FRAME_Y_SIZE );
addWindowListener( new WindowAdapter() {
@Override
public void windowClosing( final WindowEvent e ) {
close();
}
} );
addComponentListener( new ComponentAdapter() {
@Override
public void componentResized( final ComponentEvent e ) {
if ( _mainpanel.getCurrentTreePanel() != null ) {
_mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getCurrentTreePanel()
.getWidth(),
_mainpanel.getCurrentTreePanel()
.getHeight() );
}
}
} );
setFocusable( true );
requestFocus();
requestFocusInWindow();
setVisible( true );
System.gc();
}
@Override
public MainPanel getMainPanel() {
return _mainpanel;
}
private void readSpeciesTree( final Configuration configuration, final String species_tree_url_str )
throws MalformedURLException, FileNotFoundException, IOException {
final URL species_tree_url = new URL( species_tree_url_str );
final Phylogeny[] species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
configuration
.isValidatePhyloXmlAgainstSchema(),
configuration
.isReplaceUnderscoresInNhParsing(),
false,
TAXONOMY_EXTRACTION.NO,
false );
if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
AptxUtil.printAppletMessage( ArchaeopteryxA.NAME, "successfully read species tree" );
if ( species_trees[ 0 ].isEmpty() ) {
ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, "species tree is empty" );
}
else if ( !species_trees[ 0 ].isRooted() ) {
ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, "species tree is not rooted" );
}
else {
setSpeciesTree( species_trees[ 0 ] );
AptxUtil.printAppletMessage( ArchaeopteryxA.NAME, "species tree OK" );
}
}
else {
ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, "failed to read species tree from "
+ species_tree_url_str );
}
}
void buildAnalysisMenu() {
_analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
if ( getSpeciesTree() != null ) {
_analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
_analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
customizeJMenuItem( _gsdi_item );
customizeJMenuItem( _gsdir_item );
_analysis_menu.addSeparator();
}
_analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
customizeJMenuItem( _lineage_inference );
_lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
_jmenubar.add( _analysis_menu );
}
void buildOptionsMenu() {
_options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
_options_jmenu.addChangeListener( new ChangeListener() {
@Override
public void stateChanged( final ChangeEvent e ) {
MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
MainFrame
.setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, createCurrentFontDesc( getMainPanel()
.getTreeFontSet() ) );
setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() );
setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() );
MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
try {
getMainPanel().getControlPanel().setVisibilityOfDomainStrucureCB();
getMainPanel().getControlPanel().setVisibilityOfX();
}
catch ( final Exception ignore ) {
// do nothing, not important.
}
}
} );
_options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
getConfiguration() ) );
_options_jmenu
.add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
_options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
_options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) );
_radio_group_1 = new ButtonGroup();
_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_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
_options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
_options_jmenu
.add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
_options_jmenu
.add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
_options_jmenu
.add( _show_default_node_shapes_for_marked_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_MARKED ) );
_options_jmenu.add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) );
if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
_options_jmenu.add( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) );
_options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
}
_options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( MainFrame.SHOW_ANN_REF_SOURCE_LABEL ) );
_options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
_options_jmenu
.add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( MainFrame.COLOR_BY_TAXONOMIC_GROUP ) );
_options_jmenu
.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
_color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
_options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
_options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
_label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
_options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
_options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_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( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
_options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
_options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
_options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
_options_jmenu.addSeparator();
_options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
getConfiguration() ) );
_options_jmenu
.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
_options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
_options_jmenu.add( _search_with_regex_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_REGEX_LABEL ) );
_search_with_regex_cbmi.setToolTipText( MainFrame.SEARCH_WITH_REGEX_TIP );
_options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );
//
_options_jmenu.addSeparator();
_options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),
getConfiguration() ) );
_options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );
_options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );
_options_jmenu
.add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );
_options_jmenu
.add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );
_options_jmenu
.add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );
_options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
_options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
//
customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
.isGraphicsExportUsingActualSize() );
customizeJMenuItem( _print_size_mi );
customizeJMenuItem( _choose_pdf_width_mi );
//
customizeJMenuItem( _choose_font_mi );
customizeJMenuItem( _switch_colors_mi );
customizeJMenuItem( _choose_minimal_confidence_mi );
customizeJMenuItem( _overview_placment_mi );
customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
.isShowDefaultNodeShapesInternal() );
customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
.isShowDefaultNodeShapesExternal() );
customizeCheckBoxMenuItem( _show_default_node_shapes_for_marked_cbmi, getOptions()
.isShowDefaultNodeShapesForMarkedNodes() );
customizeJMenuItem( _cycle_node_shape_mi );
customizeJMenuItem( _cycle_node_fill_mi );
customizeJMenuItem( _choose_node_size_mi );
customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
customizeCheckBoxMenuItem( _label_direction_cbmi,
getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
customizeCheckBoxMenuItem( _search_with_regex_cbmi, getOptions().isSearchWithRegex() );
customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
customizeCheckBoxMenuItem( _line_up_renderable_data_cbmi, getOptions().isLineUpRendarableNodeData() );
customizeCheckBoxMenuItem( _right_line_up_domains_cbmi, getOptions().isRightLineUpDomains() );
_jmenubar.add( _options_jmenu );
}
void buildToolsMenu() {
_tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
_tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
customizeJMenuItem( _confcolor_item );
_tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
customizeJMenuItem( _taxcolor_item );
_tools_menu.addSeparator();
_tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) );
_remove_visual_styles_item
.setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny." );
customizeJMenuItem( _remove_visual_styles_item );
_tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) );
_remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny." );
customizeJMenuItem( _remove_branch_color_item );
_tools_menu.addSeparator();
_tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
customizeJMenuItem( _midpoint_root_item );
_tools_menu.addSeparator();
_tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
customizeJMenuItem( _collapse_species_specific_subtrees );
_jmenubar.add( _tools_menu );
}
JApplet getApplet() {
return _applet;
}
}
|