in progress
authorcmzmasek <cmzmasek@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Mon, 9 Mar 2015 22:22:30 +0000 (22:22 +0000)
committercmzmasek <cmzmasek@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Mon, 9 Mar 2015 22:22:30 +0000 (22:22 +0000)
forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java
forester/java/src/org/forester/archaeopteryx/MainFrame.java

index 7426a4f..22ade3b 100644 (file)
@@ -193,184 +193,7 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
         _contentpane.repaint();
     }
 
-    void writeToFile( final Phylogeny t ) {
-        if ( t == null ) {
-            return;
-        }
-        String initial_filename = null;
-        if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
-            try {
-                initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
-            }
-            catch ( final IOException e ) {
-                initial_filename = null;
-            }
-        }
-        if ( !ForesterUtil.isEmpty( initial_filename ) ) {
-            _save_filechooser.setSelectedFile( new File( initial_filename ) );
-        }
-        else {
-            _save_filechooser.setSelectedFile( new File( "" ) );
-        }
-        final File my_dir = getCurrentDir();
-        if ( my_dir != null ) {
-            _save_filechooser.setCurrentDirectory( my_dir );
-        }
-        final int result = _save_filechooser.showSaveDialog( _contentpane );
-        final File file = _save_filechooser.getSelectedFile();
-        setCurrentDir( _save_filechooser.getCurrentDirectory() );
-        boolean exception = false;
-        if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
-            if ( file.exists() ) {
-                final int i = JOptionPane.showConfirmDialog( this,
-                                                             file + " already exists.\nOverwrite?",
-                                                             "Overwrite?",
-                                                             JOptionPane.OK_CANCEL_OPTION,
-                                                             JOptionPane.QUESTION_MESSAGE );
-                if ( i != JOptionPane.OK_OPTION ) {
-                    return;
-                }
-                else {
-                    final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
-                    try {
-                        ForesterUtil.copyFile( file, to );
-                    }
-                    catch ( final Exception e ) {
-                        JOptionPane.showMessageDialog( this,
-                                                       "Failed to create backup copy " + to,
-                                                       "Failed to Create Backup Copy",
-                                                       JOptionPane.WARNING_MESSAGE );
-                    }
-                    try {
-                        file.delete();
-                    }
-                    catch ( final Exception e ) {
-                        JOptionPane.showMessageDialog( this,
-                                                       "Failed to delete: " + file,
-                                                       "Failed to Delete",
-                                                       JOptionPane.WARNING_MESSAGE );
-                    }
-                }
-            }
-            if ( _save_filechooser.getFileFilter() == MainFrame.nhfilter ) {
-                exception = writeAsNewHampshire( t, exception, file );
-            }
-            else if ( _save_filechooser.getFileFilter() == MainFrame.xmlfilter ) {
-                exception = writeAsPhyloXml( t, exception, file );
-            }
-            else if ( _save_filechooser.getFileFilter() == MainFrame.nexusfilter ) {
-                exception = writeAsNexus( t, 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 );
-                }
-                else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
-                    exception = writeAsNexus( t, exception, file );
-                }
-                // XML is default:
-                else {
-                    exception = writeAsPhyloXml( t, exception, file );
-                }
-            }
-            if ( !exception ) {
-                getMainPanel().setTitleOfSelectedTab( file.getName() );
-                getMainPanel().getCurrentTreePanel().setTreeFile( file );
-                getMainPanel().getCurrentTreePanel().setEdited( false );
-            }
-        }
-    }
-
-    void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
-        if ( ( t == null ) || t.isEmpty() ) {
-            return;
-        }
-        String initial_filename = "";
-        if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
-            initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
-        }
-        if ( initial_filename.indexOf( '.' ) > 0 ) {
-            initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
-        }
-        initial_filename = initial_filename + "." + type;
-        _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
-        final File my_dir = getCurrentDir();
-        if ( my_dir != null ) {
-            _writetographics_filechooser.setCurrentDirectory( my_dir );
-        }
-        final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
-        File file = _writetographics_filechooser.getSelectedFile();
-        setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
-        if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
-            if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
-                file = new File( file.toString() + "." + type );
-            }
-            if ( file.exists() ) {
-                final int i = JOptionPane.showConfirmDialog( this,
-                                                             file + " already exists. Overwrite?",
-                                                             "Warning",
-                                                             JOptionPane.OK_CANCEL_OPTION,
-                                                             JOptionPane.WARNING_MESSAGE );
-                if ( i != JOptionPane.OK_OPTION ) {
-                    return;
-                }
-                else {
-                    try {
-                        file.delete();
-                    }
-                    catch ( final Exception e ) {
-                        JOptionPane.showMessageDialog( this,
-                                                       "Failed to delete: " + file,
-                                                       "Error",
-                                                       JOptionPane.WARNING_MESSAGE );
-                    }
-                }
-            }
-            writePhylogenyToGraphicsFile( file.toString(), type );
-        }
-    }
-
-    void writeToPdf( final Phylogeny t ) {
-        if ( ( t == null ) || t.isEmpty() ) {
-            return;
-        }
-        String initial_filename = "";
-        if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
-            initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
-        }
-        if ( initial_filename.indexOf( '.' ) > 0 ) {
-            initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
-        }
-        initial_filename = initial_filename + ".pdf";
-        _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
-        final File my_dir = getCurrentDir();
-        if ( my_dir != null ) {
-            _writetopdf_filechooser.setCurrentDirectory( my_dir );
-        }
-        final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
-        File file = _writetopdf_filechooser.getSelectedFile();
-        setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
-        if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
-            if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
-                file = new File( file.toString() + ".pdf" );
-            }
-            if ( file.exists() ) {
-                final int i = JOptionPane.showConfirmDialog( this,
-                                                             file + " already exists. Overwrite?",
-                                                             "WARNING",
-                                                             JOptionPane.OK_CANCEL_OPTION,
-                                                             JOptionPane.WARNING_MESSAGE );
-                if ( i != JOptionPane.OK_OPTION ) {
-                    return;
-                }
-            }
-            printPhylogenyToPdf( file.toString() );
-        }
-    }
-    
+  
     void buildFileMenu() {
         _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
         _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
index 9708688..7ab7ce7 100644 (file)
@@ -1335,7 +1335,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         }\r
     }\r
 \r
-    void printPhylogenyToPdf( final String file_name ) {\r
+    void static printPhylogenyToPdf( final String file_name ) {\r
         if ( !getOptions().isPrintUsingActualSize() ) {\r
             getCurrentTreePanel()\r
                     .calcParametersForPainting( getOptions().getPrintSizeX(), getOptions().getPrintSizeY() );\r
@@ -1893,42 +1893,49 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         }\r
     }\r
 \r
-    void writeToPdf( final Phylogeny t ) {\r
+    static File writeToPdf( final Phylogeny t,\r
+                            final MainPanel mp,\r
+                            JFileChooser writetopdf_filechooser,\r
+                            File curr_dir,\r
+                            Container contentpane ,\r
+                            Component component ) {\r
         if ( ( t == null ) || t.isEmpty() ) {\r
-            return;\r
+            return null;\r
         }\r
         String initial_filename = "";\r
-        if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {\r
-            initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();\r
+        if (mp.getCurrentTreePanel().getTreeFile() != null ) {\r
+            initial_filename = mp.getCurrentTreePanel().getTreeFile().toString();\r
         }\r
         if ( initial_filename.indexOf( '.' ) > 0 ) {\r
             initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );\r
         }\r
         initial_filename = initial_filename + ".pdf";\r
-        _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );\r
-        final File my_dir = getCurrentDir();\r
+        writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );\r
+        final File my_dir = curr_dir;\r
         if ( my_dir != null ) {\r
-            _writetopdf_filechooser.setCurrentDirectory( my_dir );\r
+            writetopdf_filechooser.setCurrentDirectory( my_dir );\r
         }\r
-        final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );\r
-        File file = _writetopdf_filechooser.getSelectedFile();\r
-        setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );\r
+        final int result = writetopdf_filechooser.showSaveDialog( contentpane );\r
+        File file = writetopdf_filechooser.getSelectedFile();\r
+       // setCurrentDir( writetopdf_filechooser.getCurrentDirectory() );\r
+        final File new_current_dir = writetopdf_filechooser.getCurrentDirectory();\r
         if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {\r
             if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {\r
                 file = new File( file.toString() + ".pdf" );\r
             }\r
             if ( file.exists() ) {\r
-                final int i = JOptionPane.showConfirmDialog( this,\r
+                final int i = JOptionPane.showConfirmDialog( component,\r
                                                              file + " already exists. Overwrite?",\r
                                                              "WARNING",\r
                                                              JOptionPane.OK_CANCEL_OPTION,\r
                                                              JOptionPane.WARNING_MESSAGE );\r
                 if ( i != JOptionPane.OK_OPTION ) {\r
-                    return;\r
+                    return null;\r
                 }\r
             }\r
             printPhylogenyToPdf( file.toString() );\r
         }\r
+        return new_current_dir;\r
     }\r
 \r
     private void annotateSequences() {\r