From: cmzmasek Date: Tue, 10 Mar 2015 05:56:18 +0000 (+0000) Subject: in progress X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=5b0302dbbd662402f68e5dee1c1e8d457144f53f;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 f6c26cf..daa0147 100644 --- a/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java +++ b/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java @@ -3,7 +3,6 @@ package org.forester.archaeopteryx; 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; @@ -35,8 +34,6 @@ import org.forester.archaeopteryx.AptxUtil.GraphicsExportType; 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; @@ -66,7 +63,7 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { 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; @@ -141,31 +138,30 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { 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() ) { @@ -187,10 +183,7 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { } return _current_dir; } - - - void buildFileMenu() { _file_jmenu = MainFrame.createMenu( "File", getConfiguration() ); _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) ); @@ -222,7 +215,7 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { customizeJMenuItem( _exit_item ); _jmenubar.add( _file_jmenu ); } - + @Override public void actionPerformed( final ActionEvent e ) { final Object o = e.getSource(); @@ -464,70 +457,118 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { } // 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(); } @@ -629,6 +670,7 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { @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 ); @@ -765,11 +807,11 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { public void componentResized( final ComponentEvent e ) { if ( getMainPanel().getCurrentTreePanel() != null ) { getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel() - .getCurrentTreePanel() - .getWidth(), + .getCurrentTreePanel() + .getWidth(), getMainPanel() - .getCurrentTreePanel() - .getHeight() ); + .getCurrentTreePanel() + .getHeight() ); } } } ); @@ -1102,12 +1144,12 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { 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 ); } } diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrame.java b/forester/java/src/org/forester/archaeopteryx/MainFrame.java index f544c43..d3ef951 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrame.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrame.java @@ -691,7 +691,14 @@ public abstract class MainFrame extends JFrame implements ActionListener { print( getCurrentTreePanel(), getOptions(), this ); } else if ( o == _save_item ) { - writeToFile( _mainpanel.getCurrentPhylogeny() ); + + final File new_dir = writeToFile( _mainpanel.getCurrentPhylogeny() , + getMainPanel(), _save_filechooser, _current_dir, getContentPane(), this ); + + if ( new_dir != null ) { + setCurrentDir( new_dir ); + } + } else if ( o == _graphics_export_visible_only_cbmi ) { @@ -1091,14 +1098,16 @@ public abstract class MainFrame extends JFrame implements ActionListener { JOptionPane.ERROR_MESSAGE ); } - void exceptionOccuredDuringSaveAs( final Exception e ) { + static void exceptionOccuredDuringSaveAs( final Exception e, + final TreePanel tp, + final Component comp ) { try { - _mainpanel.getCurrentTreePanel().setArrowCursor(); + tp.setArrowCursor(); } catch ( final Exception ex ) { // Do nothing. } - JOptionPane.showMessageDialog( this, "Exception" + e, "Error during File|SaveAs", JOptionPane.ERROR_MESSAGE ); + JOptionPane.showMessageDialog( comp, "Exception" + e, "Error during File|SaveAs", JOptionPane.ERROR_MESSAGE ); } void executeGSDI() { @@ -1736,38 +1745,53 @@ public abstract class MainFrame extends JFrame implements ActionListener { } } - boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) { + static boolean writeAsNewHampshire( final TreePanel tp, + final Options op, + boolean exception, + final File file ) { try { final PhylogenyWriter writer = new PhylogenyWriter(); - writer.toNewHampshire( t, true, getOptions().getNhConversionSupportValueStyle(), file ); + writer.toNewHampshire( tp.getPhylogeny(), true, op.getNhConversionSupportValueStyle(), file ); } catch ( final Exception e ) { exception = true; - exceptionOccuredDuringSaveAs( e ); + exceptionOccuredDuringSaveAs( e, tp, tp); } return exception; } - boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) { + + + + static boolean writeAsNexus( final TreePanel tp, + final Options op, + boolean exception, + final File file ) { try { final PhylogenyWriter writer = new PhylogenyWriter(); - writer.toNexus( file, t, getOptions().getNhConversionSupportValueStyle() ); + writer.toNexus(file , tp.getPhylogeny(), op.getNhConversionSupportValueStyle()); } catch ( final Exception e ) { exception = true; - exceptionOccuredDuringSaveAs( e ); + exceptionOccuredDuringSaveAs( e, tp, tp); } return exception; } + + + - boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) { + static boolean writeAsPhyloXml( final TreePanel tp, + final Options op, + boolean exception, + final File file ) { try { final PhylogenyWriter writer = new PhylogenyWriter(); - writer.toPhyloXML( file, t, 0 ); + writer.toPhyloXML( file, tp.getPhylogeny(), 0 ); } catch ( final Exception e ) { exception = true; - exceptionOccuredDuringSaveAs( e ); + exceptionOccuredDuringSaveAs( e, tp, tp); } return exception; } @@ -1812,42 +1836,51 @@ public abstract class MainFrame extends JFrame implements ActionListener { contentpane.repaint(); } - void writeToFile( final Phylogeny t ) { + static File writeToFile( final Phylogeny t, + final MainPanel mp, + final JFileChooser save_filechooser, + final File current_dir, + Container contentpane, + Component comp + + ) { + File new_file = null; if ( t == null ) { - return; + return null; } String initial_filename = null; - if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) { + if ( mp.getCurrentTreePanel().getTreeFile() != null ) { try { - initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath(); + initial_filename = mp.getCurrentTreePanel().getTreeFile().getCanonicalPath(); } catch ( final IOException e ) { initial_filename = null; } } if ( !ForesterUtil.isEmpty( initial_filename ) ) { - _save_filechooser.setSelectedFile( new File( initial_filename ) ); + save_filechooser.setSelectedFile( new File( initial_filename ) ); } else { - _save_filechooser.setSelectedFile( new File( "" ) ); + save_filechooser.setSelectedFile( new File( "" ) ); } - final File my_dir = getCurrentDir(); + final File my_dir = current_dir; if ( my_dir != null ) { - _save_filechooser.setCurrentDirectory( my_dir ); + save_filechooser.setCurrentDirectory( my_dir ); } - final int result = _save_filechooser.showSaveDialog( _contentpane ); - final File file = _save_filechooser.getSelectedFile(); - setCurrentDir( _save_filechooser.getCurrentDirectory() ); + final int result = save_filechooser.showSaveDialog( contentpane ); + final File file = save_filechooser.getSelectedFile(); + + new_file = save_filechooser.getCurrentDirectory(); boolean exception = false; if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) { if ( file.exists() ) { - final int i = JOptionPane.showConfirmDialog( this, + final int i = JOptionPane.showConfirmDialog( comp, file + " already exists.\nOverwrite?", "Overwrite?", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE ); if ( i != JOptionPane.OK_OPTION ) { - return; + return null; } else { final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX ); @@ -1855,7 +1888,7 @@ public abstract class MainFrame extends JFrame implements ActionListener { ForesterUtil.copyFile( file, to ); } catch ( final Exception e ) { - JOptionPane.showMessageDialog( this, + JOptionPane.showMessageDialog( comp, "Failed to create backup copy " + to, "Failed to Create Backup Copy", JOptionPane.WARNING_MESSAGE ); @@ -1864,43 +1897,54 @@ public abstract class MainFrame extends JFrame implements ActionListener { file.delete(); } catch ( final Exception e ) { - JOptionPane.showMessageDialog( this, + JOptionPane.showMessageDialog( comp, "Failed to delete: " + file, "Failed to Delete", JOptionPane.WARNING_MESSAGE ); } } } - if ( _save_filechooser.getFileFilter() == MainFrame.nhfilter ) { - exception = writeAsNewHampshire( t, exception, file ); + if ( save_filechooser.getFileFilter() == MainFrame.nhfilter ) { + + + exception = writeAsNewHampshire( mp.getCurrentTreePanel(), mp.getOptions(), exception, file ); } - else if ( _save_filechooser.getFileFilter() == MainFrame.xmlfilter ) { - exception = writeAsPhyloXml( t, exception, file ); + else if ( save_filechooser.getFileFilter() == MainFrame.xmlfilter ) { + + exception = writeAsPhyloXml( mp.getCurrentTreePanel(), mp.getOptions(), + exception, + file ) ; + } - else if ( _save_filechooser.getFileFilter() == MainFrame.nexusfilter ) { - exception = writeAsNexus( t, exception, file ); + else if ( save_filechooser.getFileFilter() == MainFrame.nexusfilter ) { + + exception = writeAsNexus( mp.getCurrentTreePanel(), mp.getOptions(), exception, file ); } // "*.*": else { final String file_name = file.getName().trim().toLowerCase(); if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" ) || file_name.endsWith( ".tree" ) ) { - exception = writeAsNewHampshire( t, exception, file ); + exception = writeAsNewHampshire( mp.getCurrentTreePanel(), mp.getOptions(), exception, file ); + } else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) { - exception = writeAsNexus( t, exception, file ); + exception = writeAsNexus( mp.getCurrentTreePanel(), mp.getOptions(), exception, file ); } // XML is default: else { - exception = writeAsPhyloXml( t, exception, file ); + exception = writeAsPhyloXml( mp.getCurrentTreePanel(), mp.getOptions(), + exception, + file ) ; } } if ( !exception ) { - getMainPanel().setTitleOfSelectedTab( file.getName() ); - getMainPanel().getCurrentTreePanel().setTreeFile( file ); - getMainPanel().getCurrentTreePanel().setEdited( false ); + mp.setTitleOfSelectedTab( file.getName() ); + mp.getCurrentTreePanel().setTreeFile( file ); + mp.getCurrentTreePanel().setEdited( false ); } } + return new_file; } static File writeToGraphicsFile( final Phylogeny t,