Thank you, Oracle!
[jalview.git] / forester / java / src / org / forester / archaeopteryx / ArchaeopteryxE.java
index 4321360..38f0516 100644 (file)
@@ -151,6 +151,13 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
     private File                        _current_dir;
     private JFileChooser                _save_filechooser;
     private JFileChooser                _writetographics_filechooser;
+    private JCheckBoxMenuItem           _graphics_export_visible_only_cbmi;
+    private JCheckBoxMenuItem           _antialias_print_cbmi;
+    private JCheckBoxMenuItem           _print_black_and_white_cbmi;
+    private JCheckBoxMenuItem           _print_using_actual_size_cbmi;
+    private JCheckBoxMenuItem           _graphics_export_using_actual_size_cbmi;
+    private JMenuItem                   _print_size_mi;
+    private JMenuItem                   _choose_pdf_width_mi;
 
     @Override
     public void actionPerformed( final ActionEvent e ) {
@@ -391,9 +398,7 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
             }
             updateOptions( getOptions() );
         }
-        //
         else if ( o == _write_to_pdf_item ) {
-            // writeToPdf( _mainpanel.getCurrentPhylogeny() );
             final File curr_dir = MainFrame.writeToPdf( _mainpanel.getCurrentPhylogeny(),
                                                         getMainPanel(),
                                                         _writetopdf_filechooser,
@@ -477,32 +482,28 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
             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();
-        //        }
+        }
+        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();
     }
 
@@ -603,16 +604,18 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
 
     @Override
     public void init() {
-        _writetographics_filechooser = new JFileChooser();
         _writetopdf_filechooser = new JFileChooser();
+        _writetopdf_filechooser.setMultiSelectionEnabled( false );
+        _writetopdf_filechooser.addChoosableFileFilter( MainFrame.pdffilter );
+        _writetographics_filechooser = new JFileChooser();
+        _writetographics_filechooser.setMultiSelectionEnabled( false );
+        _writetographics_filechooser.addChoosableFileFilter( MainFrame.graphicsfilefilter );
         _save_filechooser = new JFileChooser();
         _save_filechooser.setMultiSelectionEnabled( false );
         _save_filechooser.setFileFilter( MainFrame.xmlfilter );
         _save_filechooser.addChoosableFileFilter( MainFrame.nhfilter );
         _save_filechooser.addChoosableFileFilter( MainFrame.nexusfilter );
         _save_filechooser.addChoosableFileFilter( _save_filechooser.getAcceptAllFileFilter() );
-        _writetographics_filechooser = new JFileChooser();
-        _writetographics_filechooser.addChoosableFileFilter( MainFrame.graphicsfilefilter );
         try {
             final String home_dir = System.getProperty( "user.home" );
             _save_filechooser.setCurrentDirectory( new File( home_dir ) );
@@ -620,6 +623,7 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
             _writetographics_filechooser.setCurrentDirectory( new File( home_dir ) );
         }
         catch ( final Exception e ) {
+            e.printStackTrace();
             // Do nothing. Not important.
         }
         final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
@@ -871,6 +875,84 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
         }
     }
 
+    private void choosePdfWidth() {
+        final String s = ( String ) JOptionPane.showInputDialog( this,
+                                                                 "Please enter the default line width for PDF export.\n"
+                                                                         + "[current value: "
+                                                                         + getOptions().getPrintLineWidth() + "]\n",
+                                                                 "Line Width for PDF Export",
+                                                                 JOptionPane.QUESTION_MESSAGE,
+                                                                 null,
+                                                                 null,
+                                                                 getOptions().getPrintLineWidth() );
+        if ( !ForesterUtil.isEmpty( s ) ) {
+            boolean success = true;
+            float f = 0.0f;
+            final String m_str = s.trim();
+            if ( !ForesterUtil.isEmpty( m_str ) ) {
+                try {
+                    f = Float.parseFloat( m_str );
+                }
+                catch ( final Exception ex ) {
+                    success = false;
+                }
+            }
+            else {
+                success = false;
+            }
+            if ( success && ( f > 0.0 ) ) {
+                getOptions().setPrintLineWidth( f );
+            }
+        }
+    }
+
+    private void choosePrintSize() {
+        final String s = ( String ) JOptionPane.showInputDialog( this,
+                                                                 "Please enter values for width and height,\nseparated by a comma.\n"
+                                                                         + "[current values: "
+                                                                         + getOptions().getPrintSizeX() + ", "
+                                                                         + getOptions().getPrintSizeY() + "]\n"
+                                                                         + "[A4: " + Constants.A4_SIZE_X + ", "
+                                                                         + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
+                                                                         + Constants.US_LETTER_SIZE_X + ", "
+                                                                         + Constants.US_LETTER_SIZE_Y + "]",
+                                                                 "Default Size for Graphics Export",
+                                                                 JOptionPane.QUESTION_MESSAGE,
+                                                                 null,
+                                                                 null,
+                                                                 getOptions().getPrintSizeX() + ", "
+                                                                         + getOptions().getPrintSizeY() );
+        if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
+            boolean success = true;
+            int x = 0;
+            int y = 0;
+            final String[] str_ary = s.split( "," );
+            if ( str_ary.length == 2 ) {
+                final String x_str = str_ary[ 0 ].trim();
+                final String y_str = str_ary[ 1 ].trim();
+                if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
+                    try {
+                        x = Integer.parseInt( x_str );
+                        y = Integer.parseInt( y_str );
+                    }
+                    catch ( final Exception ex ) {
+                        success = false;
+                    }
+                }
+                else {
+                    success = false;
+                }
+            }
+            else {
+                success = false;
+            }
+            if ( success && ( x > 1 ) && ( y > 1 ) ) {
+                getOptions().setPrintSizeX( x );
+                getOptions().setPrintSizeY( y );
+            }
+        }
+    }
+
     private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
         if ( item != null ) {
             item.setFont( MainFrame.menu_font );
@@ -1027,6 +1109,8 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
                 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
                 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
                                                          .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
+                setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() );
+                setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() );
                 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
                 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
                 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
@@ -1092,6 +1176,30 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
         _search_with_regex_cbmi.setToolTipText( MainFrame.SEARCH_WITH_REGEX_TIP );
         _options_jmenu
         .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
+        //
+        _options_jmenu.addSeparator();
+        _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),
+                                                                getConfiguration() ) );
+        _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );
+        _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );
+        _options_jmenu
+        .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );
+        _options_jmenu
+        .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );
+        _options_jmenu
+        .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );
+        _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
+        _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
+        //
+        customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
+        customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
+        customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
+        customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
+        customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
+                                   .isGraphicsExportUsingActualSize() );
+        customizeJMenuItem( _print_size_mi );
+        customizeJMenuItem( _choose_pdf_width_mi );
+        //
         customizeJMenuItem( _choose_font_mi );
         customizeJMenuItem( _choose_minimal_confidence_mi );
         customizeJMenuItem( _switch_colors_mi );
@@ -1677,6 +1785,13 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
         options.setSearchWithRegex( ( _search_with_regex_cbmi != null ) && _search_with_regex_cbmi.isSelected() );
         options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
                                         && _inverse_search_result_cbmi.isSelected() );
+        options.setPrintUsingActualSize( ( _print_using_actual_size_cbmi != null )
+                && ( _print_using_actual_size_cbmi.isSelected() ) );
+        options.setGraphicsExportUsingActualSize( ( _graphics_export_using_actual_size_cbmi != null )
+                && ( _graphics_export_using_actual_size_cbmi.isSelected() ) );
+        options.setAntialiasPrint( ( _antialias_print_cbmi != null ) && _antialias_print_cbmi.isSelected() );
+        options.setPrintBlackAndWhite( ( _print_black_and_white_cbmi != null )
+                && _print_black_and_white_cbmi.isSelected() );
         if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
         }
@@ -1710,6 +1825,16 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
         if ( ( _line_up_renderable_data_cbmi != null ) && _line_up_renderable_data_cbmi.isEnabled() ) {
             options.setLineUpRendarableNodeData( _line_up_renderable_data_cbmi.isSelected() );
         }
+        if ( _graphics_export_visible_only_cbmi != null ) {
+            options.setGraphicsExportVisibleOnly( _graphics_export_visible_only_cbmi.isSelected() );
+            if ( _graphics_export_visible_only_cbmi.isSelected() && ( _graphics_export_using_actual_size_cbmi != null ) ) {
+                _graphics_export_using_actual_size_cbmi.setSelected( true );
+                _graphics_export_using_actual_size_cbmi.setEnabled( false );
+            }
+            else {
+                _graphics_export_using_actual_size_cbmi.setEnabled( true );
+            }
+        }
     }
 
     void updateTypeCheckboxes( final Options options, final Object o ) {
@@ -1751,6 +1876,15 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
         }
     }
 
+    static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
+        mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
+                + o.getPrintSizeY() + ")" );
+    }
+
+    static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
+        mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
+    }
+
     static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
         for( final TreePanel tree_panel : treepanels ) {
             tree_panel.setTextAntialias();