in progress
authorcmzmasek <cmzmasek@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Tue, 10 Mar 2015 05:56:18 +0000 (05:56 +0000)
committercmzmasek <cmzmasek@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Tue, 10 Mar 2015 05:56:18 +0000 (05:56 +0000)
forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java
forester/java/src/org/forester/archaeopteryx/MainFrame.java

index f6c26cf..daa0147 100644 (file)
@@ -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 );
         }
     }
 
index f544c43..d3ef951 100644 (file)
@@ -691,7 +691,14 @@ public abstract class MainFrame extends JFrame implements ActionListener {
             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
@@ -1091,14 +1098,16 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                                        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
@@ -1736,38 +1745,53 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         }\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
@@ -1812,42 +1836,51 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         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
@@ -1855,7 +1888,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                         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
@@ -1864,43 +1897,54 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                         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