import java.awt.BorderLayout;
import java.awt.Container;
-import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
-import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
-import org.forester.archaeopteryx.webservices.WebservicesManager;
import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyMethods;
private final static String NAME = "ArchaeopteryxE";
private static final long serialVersionUID = -1220055577935759443L;
private Configuration _configuration;
- private MainPanelApplets _mainpanel;
+ private MainPanel _mainpanel;
private JMenuBar _jmenubar;
private JMenu _options_jmenu;
private JMenu _font_size_menu;
private JCheckBoxMenuItem _right_line_up_domains_cbmi;
private JCheckBoxMenuItem _line_up_renderable_data_cbmi;
// file menu:
- private JMenuItem _open_item;
- private JMenuItem _open_url_item;
- private JMenuItem _save_item;
- private JMenuItem _save_all_item;
- private JMenuItem _close_item;
- private JMenuItem _exit_item;
- private JMenuItem _new_item;
- private JMenuItem _print_item;
- private JMenuItem _write_to_pdf_item;
- private JMenuItem _write_to_jpg_item;
- private JMenuItem _write_to_gif_item;
- private JMenuItem _write_to_tif_item;
- private JMenuItem _write_to_png_item;
- private JMenuItem _write_to_bmp_item;
- private JMenu _file_jmenu;
- private JFileChooser _writetopdf_filechooser;
- private File _current_dir;
- private JFileChooser _save_filechooser;
- private JFileChooser _writetographics_filechooser;
-
-
+ private JMenuItem _open_item;
+ private JMenuItem _open_url_item;
+ private JMenuItem _save_item;
+ private JMenuItem _save_all_item;
+ private JMenuItem _close_item;
+ private JMenuItem _exit_item;
+ private JMenuItem _new_item;
+ private JMenuItem _print_item;
+ private JMenuItem _write_to_pdf_item;
+ private JMenuItem _write_to_jpg_item;
+ private JMenuItem _write_to_gif_item;
+ private JMenuItem _write_to_tif_item;
+ private JMenuItem _write_to_png_item;
+ private JMenuItem _write_to_bmp_item;
+ private JMenu _file_jmenu;
+ private JFileChooser _writetopdf_filechooser;
+ private File _current_dir;
+ private JFileChooser _save_filechooser;
+ private JFileChooser _writetographics_filechooser;
+
void setCurrentDir( final File current_dir ) {
_current_dir = current_dir;
}
-
+
File getCurrentDir() {
if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
if ( ForesterUtil.isWindows() ) {
}
return _current_dir;
}
-
-
-
void buildFileMenu() {
_file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
_file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
customizeJMenuItem( _exit_item );
_jmenubar.add( _file_jmenu );
}
-
+
@Override
public void actionPerformed( final ActionEvent e ) {
final Object o = e.getSource();
}
//
else if ( o == _write_to_pdf_item ) {
- // writeToPdf( _mainpanel.getCurrentPhylogeny() );
- final File curr_dir =MainFrame.writeToPdf( _mainpanel.getCurrentPhylogeny(),
- getMainPanel(),
- _writetopdf_filechooser,
- _current_dir,
- getContentPane(),
- this );
-
-
+ // writeToPdf( _mainpanel.getCurrentPhylogeny() );
+ final File curr_dir = MainFrame.writeToPdf( _mainpanel.getCurrentPhylogeny(),
+ getMainPanel(),
+ _writetopdf_filechooser,
+ _current_dir,
+ getContentPane(),
+ this );
if ( curr_dir != null ) {
setCurrentDir( curr_dir );
}
-
}
-
else if ( o == _write_to_jpg_item ) {
-
- writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.JPG );
+ final File curr_dir = MainFrame.writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
+ GraphicsExportType.JPG,
+ _mainpanel,
+ _writetographics_filechooser,
+ this,
+ getContentPane(),
+ _current_dir );
+ if ( curr_dir != null ) {
+ setCurrentDir( curr_dir );
+ }
}
else if ( o == _write_to_gif_item ) {
- writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.GIF );
+ final File curr_dir = MainFrame.writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
+ GraphicsExportType.GIF,
+ _mainpanel,
+ _writetographics_filechooser,
+ this,
+ getContentPane(),
+ _current_dir );
+ if ( curr_dir != null ) {
+ setCurrentDir( curr_dir );
+ }
}
else if ( o == _write_to_tif_item ) {
- writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.TIFF );
+ final File curr_dir = MainFrame.writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
+ GraphicsExportType.TIFF,
+ _mainpanel,
+ _writetographics_filechooser,
+ this,
+ getContentPane(),
+ _current_dir );
+ if ( curr_dir != null ) {
+ setCurrentDir( curr_dir );
+ }
}
else if ( o == _write_to_bmp_item ) {
- writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.BMP );
+ final File curr_dir = MainFrame.writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
+ GraphicsExportType.BMP,
+ _mainpanel,
+ _writetographics_filechooser,
+ this,
+ getContentPane(),
+ _current_dir );
+ if ( curr_dir != null ) {
+ setCurrentDir( curr_dir );
+ }
}
else if ( o == _write_to_png_item ) {
- writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.PNG );
+ final File curr_dir = MainFrame.writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
+ GraphicsExportType.PNG,
+ _mainpanel,
+ _writetographics_filechooser,
+ this,
+ getContentPane(),
+ _current_dir );
+ if ( curr_dir != null ) {
+ setCurrentDir( curr_dir );
+ }
}
else if ( o == _print_item ) {
- MainFrame.print( getCurrentTreePanel(),
- getOptions(),
-
- this );
-
+ MainFrame.print( getCurrentTreePanel(), getOptions(), this );
}
else if ( o == _save_item ) {
- writeToFile( _mainpanel.getCurrentPhylogeny() );
- }
-
-// else if ( o == _graphics_export_visible_only_cbmi ) {
-// updateOptions( getOptions() );
-// }
-// else if ( o == _antialias_print_cbmi ) {
-// updateOptions( getOptions() );
-// }
-// else if ( o == _print_black_and_white_cbmi ) {
-// updateOptions( getOptions() );
-// }
-// else if ( o == _print_using_actual_size_cbmi ) {
-// updateOptions( getOptions() );
-// }
-// else if ( o == _graphics_export_using_actual_size_cbmi ) {
-// updateOptions( getOptions() );
-// }
-// else if ( o == _print_size_mi ) {
-// choosePrintSize();
-// }
-// else if ( o == _choose_pdf_width_mi ) {
-// choosePdfWidth();
-// }
+
+ final File new_dir = MainFrame.writeToFile( _mainpanel.getCurrentPhylogeny() ,
+ getMainPanel(), _save_filechooser, _current_dir, getContentPane(), this );
+
+ if ( new_dir != null ) {
+ setCurrentDir( new_dir );
+ }
+
+
+ } // TODO
+ // TODO
+ // TODO
+ // TODO
+ // TODO
+
+ // else if ( o == _graphics_export_visible_only_cbmi ) {
+ // updateOptions( getOptions() );
+ // }
+ // else if ( o == _antialias_print_cbmi ) {
+ // updateOptions( getOptions() );
+ // }
+ // else if ( o == _print_black_and_white_cbmi ) {
+ // updateOptions( getOptions() );
+ // }
+ // else if ( o == _print_using_actual_size_cbmi ) {
+ // updateOptions( getOptions() );
+ // }
+ // else if ( o == _graphics_export_using_actual_size_cbmi ) {
+ // updateOptions( getOptions() );
+ // }
+ // else if ( o == _print_size_mi ) {
+ // choosePrintSize();
+ // }
+ // else if ( o == _choose_pdf_width_mi ) {
+ // choosePdfWidth();
+ // }
repaint();
}
@Override
public void init() {
_writetopdf_filechooser = new JFileChooser();
+ _writetographics_filechooser = new JFileChooser();
final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
final Configuration configuration = new Configuration( config_filename, true, true, true );
public void componentResized( final ComponentEvent e ) {
if ( getMainPanel().getCurrentTreePanel() != null ) {
getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel()
- .getCurrentTreePanel()
- .getWidth(),
+ .getCurrentTreePanel()
+ .getWidth(),
getMainPanel()
- .getCurrentTreePanel()
- .getHeight() );
+ .getCurrentTreePanel()
+ .getHeight() );
}
}
} );
void customizeJMenuItem( final JMenuItem jmi ) {
if ( jmi != null ) {
- jmi.setFont( MainFrame.menu_font );
- if ( !getConfiguration().isUseNativeUI() ) {
- jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
- jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
- }
- jmi.addActionListener( this );
+ jmi.setFont( MainFrame.menu_font );
+ if ( !getConfiguration().isUseNativeUI() ) {
+ jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
+ jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
+ }
+ jmi.addActionListener( this );
}
}
print( getCurrentTreePanel(), getOptions(), this );\r
}\r
else if ( o == _save_item ) {\r
- writeToFile( _mainpanel.getCurrentPhylogeny() );\r
+ \r
+ final File new_dir = writeToFile( _mainpanel.getCurrentPhylogeny() ,\r
+ getMainPanel(), _save_filechooser, _current_dir, getContentPane(), this );\r
+ \r
+ if ( new_dir != null ) {\r
+ setCurrentDir( new_dir ); \r
+ }\r
+ \r
}\r
\r
else if ( o == _graphics_export_visible_only_cbmi ) {\r
JOptionPane.ERROR_MESSAGE );\r
}\r
\r
- void exceptionOccuredDuringSaveAs( final Exception e ) {\r
+ static void exceptionOccuredDuringSaveAs( final Exception e, \r
+ final TreePanel tp,\r
+ final Component comp ) {\r
try {\r
- _mainpanel.getCurrentTreePanel().setArrowCursor();\r
+ tp.setArrowCursor();\r
}\r
catch ( final Exception ex ) {\r
// Do nothing.\r
}\r
- JOptionPane.showMessageDialog( this, "Exception" + e, "Error during File|SaveAs", JOptionPane.ERROR_MESSAGE );\r
+ JOptionPane.showMessageDialog( comp, "Exception" + e, "Error during File|SaveAs", JOptionPane.ERROR_MESSAGE );\r
}\r
\r
void executeGSDI() {\r
}\r
}\r
\r
- boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {\r
+ static boolean writeAsNewHampshire( final TreePanel tp,\r
+ final Options op,\r
+ boolean exception,\r
+ final File file ) {\r
try {\r
final PhylogenyWriter writer = new PhylogenyWriter();\r
- writer.toNewHampshire( t, true, getOptions().getNhConversionSupportValueStyle(), file );\r
+ writer.toNewHampshire( tp.getPhylogeny(), true, op.getNhConversionSupportValueStyle(), file );\r
}\r
catch ( final Exception e ) {\r
exception = true;\r
- exceptionOccuredDuringSaveAs( e );\r
+ exceptionOccuredDuringSaveAs( e, tp, tp);\r
}\r
return exception;\r
}\r
\r
- boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {\r
+ \r
+ \r
+ \r
+ static boolean writeAsNexus( final TreePanel tp,\r
+ final Options op,\r
+ boolean exception,\r
+ final File file ) {\r
try {\r
final PhylogenyWriter writer = new PhylogenyWriter();\r
- writer.toNexus( file, t, getOptions().getNhConversionSupportValueStyle() );\r
+ writer.toNexus(file , tp.getPhylogeny(), op.getNhConversionSupportValueStyle());\r
}\r
catch ( final Exception e ) {\r
exception = true;\r
- exceptionOccuredDuringSaveAs( e );\r
+ exceptionOccuredDuringSaveAs( e, tp, tp);\r
}\r
return exception;\r
}\r
+ \r
+ \r
+ \r
\r
- boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {\r
+ static boolean writeAsPhyloXml( final TreePanel tp,\r
+ final Options op,\r
+ boolean exception,\r
+ final File file ) {\r
try {\r
final PhylogenyWriter writer = new PhylogenyWriter();\r
- writer.toPhyloXML( file, t, 0 );\r
+ writer.toPhyloXML( file, tp.getPhylogeny(), 0 );\r
}\r
catch ( final Exception e ) {\r
exception = true;\r
- exceptionOccuredDuringSaveAs( e );\r
+ exceptionOccuredDuringSaveAs( e, tp, tp);\r
}\r
return exception;\r
}\r
contentpane.repaint();\r
}\r
\r
- void writeToFile( final Phylogeny t ) {\r
+ static File writeToFile( final Phylogeny t,\r
+ final MainPanel mp,\r
+ final JFileChooser save_filechooser,\r
+ final File current_dir,\r
+ Container contentpane,\r
+ Component comp\r
+ \r
+ ) {\r
+ File new_file = null;\r
if ( t == null ) {\r
- return;\r
+ return null;\r
}\r
String initial_filename = null;\r
- if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {\r
+ if ( mp.getCurrentTreePanel().getTreeFile() != null ) {\r
try {\r
- initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();\r
+ initial_filename = mp.getCurrentTreePanel().getTreeFile().getCanonicalPath();\r
}\r
catch ( final IOException e ) {\r
initial_filename = null;\r
}\r
}\r
if ( !ForesterUtil.isEmpty( initial_filename ) ) {\r
- _save_filechooser.setSelectedFile( new File( initial_filename ) );\r
+ save_filechooser.setSelectedFile( new File( initial_filename ) );\r
}\r
else {\r
- _save_filechooser.setSelectedFile( new File( "" ) );\r
+ save_filechooser.setSelectedFile( new File( "" ) );\r
}\r
- final File my_dir = getCurrentDir();\r
+ final File my_dir = current_dir;\r
if ( my_dir != null ) {\r
- _save_filechooser.setCurrentDirectory( my_dir );\r
+ save_filechooser.setCurrentDirectory( my_dir );\r
}\r
- final int result = _save_filechooser.showSaveDialog( _contentpane );\r
- final File file = _save_filechooser.getSelectedFile();\r
- setCurrentDir( _save_filechooser.getCurrentDirectory() );\r
+ final int result = save_filechooser.showSaveDialog( contentpane );\r
+ final File file = save_filechooser.getSelectedFile();\r
+ \r
+ new_file = save_filechooser.getCurrentDirectory();\r
boolean exception = false;\r
if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {\r
if ( file.exists() ) {\r
- final int i = JOptionPane.showConfirmDialog( this,\r
+ final int i = JOptionPane.showConfirmDialog( comp,\r
file + " already exists.\nOverwrite?",\r
"Overwrite?",\r
JOptionPane.OK_CANCEL_OPTION,\r
JOptionPane.QUESTION_MESSAGE );\r
if ( i != JOptionPane.OK_OPTION ) {\r
- return;\r
+ return null;\r
}\r
else {\r
final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );\r
ForesterUtil.copyFile( file, to );\r
}\r
catch ( final Exception e ) {\r
- JOptionPane.showMessageDialog( this,\r
+ JOptionPane.showMessageDialog( comp,\r
"Failed to create backup copy " + to,\r
"Failed to Create Backup Copy",\r
JOptionPane.WARNING_MESSAGE );\r
file.delete();\r
}\r
catch ( final Exception e ) {\r
- JOptionPane.showMessageDialog( this,\r
+ JOptionPane.showMessageDialog( comp,\r
"Failed to delete: " + file,\r
"Failed to Delete",\r
JOptionPane.WARNING_MESSAGE );\r
}\r
}\r
}\r
- if ( _save_filechooser.getFileFilter() == MainFrame.nhfilter ) {\r
- exception = writeAsNewHampshire( t, exception, file );\r
+ if ( save_filechooser.getFileFilter() == MainFrame.nhfilter ) {\r
+ \r
+ \r
+ exception = writeAsNewHampshire( mp.getCurrentTreePanel(), mp.getOptions(), exception, file );\r
}\r
- else if ( _save_filechooser.getFileFilter() == MainFrame.xmlfilter ) {\r
- exception = writeAsPhyloXml( t, exception, file );\r
+ else if ( save_filechooser.getFileFilter() == MainFrame.xmlfilter ) {\r
+ \r
+ exception = writeAsPhyloXml( mp.getCurrentTreePanel(), mp.getOptions(),\r
+ exception,\r
+ file ) ;\r
+ \r
}\r
- else if ( _save_filechooser.getFileFilter() == MainFrame.nexusfilter ) {\r
- exception = writeAsNexus( t, exception, file );\r
+ else if ( save_filechooser.getFileFilter() == MainFrame.nexusfilter ) {\r
+ \r
+ exception = writeAsNexus( mp.getCurrentTreePanel(), mp.getOptions(), exception, file );\r
}\r
// "*.*":\r
else {\r
final String file_name = file.getName().trim().toLowerCase();\r
if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )\r
|| file_name.endsWith( ".tree" ) ) {\r
- exception = writeAsNewHampshire( t, exception, file );\r
+ exception = writeAsNewHampshire( mp.getCurrentTreePanel(), mp.getOptions(), exception, file );\r
+ \r
}\r
else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {\r
- exception = writeAsNexus( t, exception, file );\r
+ exception = writeAsNexus( mp.getCurrentTreePanel(), mp.getOptions(), exception, file );\r
}\r
// XML is default:\r
else {\r
- exception = writeAsPhyloXml( t, exception, file );\r
+ exception = writeAsPhyloXml( mp.getCurrentTreePanel(), mp.getOptions(),\r
+ exception,\r
+ file ) ;\r
}\r
}\r
if ( !exception ) {\r
- getMainPanel().setTitleOfSelectedTab( file.getName() );\r
- getMainPanel().getCurrentTreePanel().setTreeFile( file );\r
- getMainPanel().getCurrentTreePanel().setEdited( false );\r
+ mp.setTitleOfSelectedTab( file.getName() );\r
+ mp.getCurrentTreePanel().setTreeFile( file );\r
+ mp.getCurrentTreePanel().setEdited( false );\r
}\r
}\r
+ return new_file;\r
}\r
\r
static File writeToGraphicsFile( final Phylogeny t,\r