From 8d6e81da091d432309f2f7034cf93dbc5ba5e82a Mon Sep 17 00:00:00 2001 From: cmzmasek Date: Mon, 9 Mar 2015 22:22:30 +0000 Subject: [PATCH] in progress --- .../org/forester/archaeopteryx/ArchaeopteryxE.java | 179 +------------------- .../src/org/forester/archaeopteryx/MainFrame.java | 33 ++-- 2 files changed, 21 insertions(+), 191 deletions(-) diff --git a/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java b/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java index 7426a4f..22ade3b 100644 --- a/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java +++ b/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java @@ -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..." ) ); diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrame.java b/forester/java/src/org/forester/archaeopteryx/MainFrame.java index 9708688..7ab7ce7 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrame.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrame.java @@ -1335,7 +1335,7 @@ public abstract class MainFrame extends JFrame implements ActionListener { } } - void printPhylogenyToPdf( final String file_name ) { + void static printPhylogenyToPdf( final String file_name ) { if ( !getOptions().isPrintUsingActualSize() ) { getCurrentTreePanel() .calcParametersForPainting( getOptions().getPrintSizeX(), getOptions().getPrintSizeY() ); @@ -1893,42 +1893,49 @@ public abstract class MainFrame extends JFrame implements ActionListener { } } - void writeToPdf( final Phylogeny t ) { + static File writeToPdf( final Phylogeny t, + final MainPanel mp, + JFileChooser writetopdf_filechooser, + File curr_dir, + Container contentpane , + Component component ) { if ( ( t == null ) || t.isEmpty() ) { - return; + return null; } String initial_filename = ""; - if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) { - initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString(); + if (mp.getCurrentTreePanel().getTreeFile() != null ) { + initial_filename = mp.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(); + writetopdf_filechooser.setSelectedFile( new File( initial_filename ) ); + final File my_dir = curr_dir; if ( my_dir != null ) { - _writetopdf_filechooser.setCurrentDirectory( my_dir ); + writetopdf_filechooser.setCurrentDirectory( my_dir ); } - final int result = _writetopdf_filechooser.showSaveDialog( _contentpane ); - File file = _writetopdf_filechooser.getSelectedFile(); - setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() ); + final int result = writetopdf_filechooser.showSaveDialog( contentpane ); + File file = writetopdf_filechooser.getSelectedFile(); + // setCurrentDir( writetopdf_filechooser.getCurrentDirectory() ); + final File new_current_dir = 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, + final int i = JOptionPane.showConfirmDialog( component, file + " already exists. Overwrite?", "WARNING", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE ); if ( i != JOptionPane.OK_OPTION ) { - return; + return null; } } printPhylogenyToPdf( file.toString() ); } + return new_current_dir; } private void annotateSequences() { -- 1.7.10.2