JAL-2797 the big switch, all GUI method calls now go via the AptxFrame
[jalview.git] / forester / java / src / org / forester / archaeopteryx / MainFrame.java
index 20bbcde..3cdbca2 100644 (file)
@@ -30,6 +30,8 @@ import java.awt.Container;
 import java.awt.Font;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentListener;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -40,10 +42,10 @@ import java.util.Map;
 import java.util.NoSuchElementException;
 
 import javax.swing.Box;
-import javax.swing.JApplet;
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JFileChooser;
 import javax.swing.JFrame;
+import javax.swing.JInternalFrame;
 import javax.swing.JLabel;
 import javax.swing.JMenu;
 import javax.swing.JMenuBar;
@@ -82,18 +84,18 @@ import org.forester.util.ForesterConstants;
 import org.forester.util.ForesterUtil;
 import org.forester.util.WindowsUtils;
 
-public abstract class MainFrame extends JFrame implements ActionListener {
-
-    final static NHFilter            nhfilter                                = new NHFilter();
-    final static NHXFilter           nhxfilter                               = new NHXFilter();
-    final static XMLFilter           xmlfilter                               = new XMLFilter();
-    final static TolFilter           tolfilter                               = new TolFilter();
-    final static NexusFilter         nexusfilter                             = new NexusFilter();
-    final static PdfFilter           pdffilter                               = new PdfFilter();
-    final static GraphicsFileFilter  graphicsfilefilter                      = new GraphicsFileFilter();
-    final static MsaFileFilter       msafilter                               = new MsaFileFilter();
-    final static SequencesFileFilter seqsfilter                              = new SequencesFileFilter();
-    final static DefaultFilter       defaultfilter                           = new DefaultFilter();
+public abstract class MainFrame implements ActionListener {
+
+    public final static NHFilter            nhfilter                                = new NHFilter();
+    public final static NHXFilter           nhxfilter                               = new NHXFilter();
+    public final static XMLFilter           xmlfilter                               = new XMLFilter();
+    public final static TolFilter           tolfilter                               = new TolFilter();
+    public final static NexusFilter         nexusfilter                             = new NexusFilter();
+    public final static PdfFilter           pdffilter                               = new PdfFilter();
+    public final static GraphicsFileFilter  graphicsfilefilter                      = new GraphicsFileFilter();
+    public final static MsaFileFilter       msafilter                               = new MsaFileFilter();
+    public final static SequencesFileFilter seqsfilter                              = new SequencesFileFilter();
+    public final static DefaultFilter       defaultfilter                           = new DefaultFilter();
     static final String              USE_MOUSEWHEEL_SHIFT_TO_ROTATE          = "rotate with mousewheel + Shift (or A and S), D toggles between horizontal and radial labels";
     static final String              PHYLOXML_REF_TOOL_TIP                   = AptxConstants.PHYLOXML_REFERENCE;                                                                                                                                                //TODO //FIXME
     static final String              APTX_REF_TOOL_TIP                       = AptxConstants.APTX_REFERENCE;
@@ -113,10 +115,10 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     static final String              OPTIONS_HEADER                          = "Options";
     static final String              SEARCH_SUBHEADER                        = "Search:";
     static final String              DISPLAY_SUBHEADER                       = "Display:";
-    static final String              SEARCH_TERMS_ONLY_LABEL                 = "Match Complete Terms Only";
-    static final String              SEARCH_REGEX_LABEL                      = "Search with Regular Expressions";
-    static final String              SEARCH_CASE_SENSITIVE_LABEL             = "Case Sensitive";
-    static final String              INVERSE_SEARCH_RESULT_LABEL             = "Negate Result";
+    static final String              SEARCH_TERMS_ONLY_LABEL                 = "Words";
+    static final String              SEARCH_REGEX_LABEL                      = "Regex";
+    static final String              SEARCH_CASE_SENSITIVE_LABEL             = "Match Case";
+    static final String              INVERSE_SEARCH_RESULT_LABEL             = "Inverse";
     static final String              COLOR_BY_TAXONOMIC_GROUP                = "Colorize by Taxonomic Group";
     static final String              DISPLAY_SCALE_LABEL                     = "Scale";
     static final String              NON_LINED_UP_CLADOGRAMS_LABEL           = "Non-Lined Up Cladogram";
@@ -148,6 +150,8 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     static final String              LINE_UP_RENDERABLE_DATA                 = "Line Up Diagrams (such as Domain Architectures)";
     static final String              INFER_ANCESTOR_TAXONOMIES               = "Infer Ancestor Taxonomies";
     static final String              OBTAIN_DETAILED_TAXONOMIC_INFORMATION   = "Obtain Detailed Taxonomic Information";
+    
+    final AptxFrame                  _frame;
     JMenuBar                         _jmenubar;
     JMenu                            _file_jmenu;
     JMenu                            _tools_menu;
@@ -274,6 +278,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     JMenuItem                        _about_item;
     JMenuItem                        _help_item;
     JMenuItem                        _website_item;
+    JMenuItem                        _aptxjs_website_item;
     JMenuItem                        _mailing_list_item;
     JMenuItem                        _phyloxml_website_item;
     JMenuItem                        _phyloxml_ref_item;
@@ -296,6 +301,15 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     private String                   _previous_node_annotation_ref;
 
     MainFrame() {
+        this(false);
+    }
+    MainFrame(boolean embedded){
+        if (embedded) {
+            _frame = new EmbeddedFrame();
+        }
+        else {
+            _frame = new StandaloneFrame();
+        } 
         _process_pool = ProcessPool.createInstance();
         _writetopdf_filechooser = new JFileChooser();
         _writetopdf_filechooser.setMultiSelectionEnabled( false );
@@ -320,21 +334,76 @@ public abstract class MainFrame extends JFrame implements ActionListener {
             // Do nothing. Not important.
         }
     }
-
+    public void addComponentListener( ComponentListener componentListener ) {
+        _frame.addComponentListener( componentListener );
+        
+    }
+    
+    public void dispose() {
+        _frame.dispose();
+    }
+    public Container getContentPane() {
+        return _frame.getContentPane();
+    }
+    
+    public void repaint() {
+       _frame.repaint();
+    }
+    
+     
+    public void addFrameListener(FrameListener frameListener) {
+        _frame.addFrameListener(frameListener);
+    }
+    
+    public void setSize(int x, int y) {
+        _frame.setSize(x,y);
+    }
+    public Container getJMenuBar() {
+        return _frame.getJMenuBar();
+    }
+    public void setDefaultCloseOperation( int doNothingOnClose ) {
+        _frame.setDefaultCloseOperation(doNothingOnClose);
+        
+    }
+    public Container getParent() {
+        return _frame.getParent();
+    }
+    public void setVisible(boolean visible) {
+        _frame.setVisible(visible);
+    }
+    public void requestFocusInWindow() {
+        _frame.requestFocusInWindow();
+    }
+    public void setJMenuBar( JMenuBar jmenubar ) {
+        _frame.setJMenuBar(jmenubar);
+    }
+    public void setLocationRelativeTo( Component component ) {
+        _frame.setLocationRelativeTo(component);  
+    }
+    public void setTitle(String title) {
+       _frame.setTitle(title);
+    }
+    
+    public Container getThisFrame() {
+        return _frame.getThisFrame();
+    }
+    
+    public void validate() {
+        _frame.validate();
+    }
+    
+    
+    
+    
+    
+    
     /**
      * Action performed.
      */
     @Override
     public void actionPerformed( final ActionEvent e ) {
         final Object o = e.getSource();
-        boolean is_applet = false;
-        JApplet applet = null;
-        if ( getCurrentTreePanel() != null ) {
-            is_applet = getCurrentTreePanel().isApplet();
-            if ( is_applet ) {
-                applet = getCurrentTreePanel().obtainApplet();
-            }
-        }
+      
         if ( o == _exit_item ) {
             close();
         }
@@ -454,7 +523,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
             chooseMinimalConfidence();
         }
         else if ( o == _choose_node_size_mi ) {
-            chooseNodeSize( getOptions(), this );
+            chooseNodeSize( getOptions(), _frame.getThisFrame() );
         }
         else if ( o == _overview_placment_mi ) {
             MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
@@ -607,7 +676,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         }
         else if ( o == _help_item ) {
             try {
-                AptxUtil.openWebsite( AptxConstants.APTX_DOC_SITE, is_applet, applet );
+                AptxUtil.openWebsite( AptxConstants.APTX_DOC_SITE );
             }
             catch ( final IOException e1 ) {
                 ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
@@ -615,7 +684,15 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         }
         else if ( o == _website_item ) {
             try {
-                AptxUtil.openWebsite( AptxConstants.APTX_WEB_SITE, is_applet, applet );
+                AptxUtil.openWebsite( AptxConstants.APTX_WEB_SITE);
+            }
+            catch ( final IOException e1 ) {
+                ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
+            }
+        }
+        else if ( o == _aptxjs_website_item ) {
+            try {
+                AptxUtil.openWebsite( AptxConstants.APTX_JS_WEB_SITE);;
             }
             catch ( final IOException e1 ) {
                 ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
@@ -623,7 +700,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         }
         else if ( o == _mailing_list_item ) {
             try {
-                AptxUtil.openWebsite( AptxConstants.APTX_MAILING_LIST, is_applet, applet );
+                AptxUtil.openWebsite( AptxConstants.APTX_MAILING_LIST );
             }
             catch ( final IOException e1 ) {
                 ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
@@ -631,7 +708,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         }
         else if ( o == _phyloxml_website_item ) {
             try {
-                AptxUtil.openWebsite( AptxConstants.PHYLOXML_WEB_SITE, is_applet, applet );
+                AptxUtil.openWebsite( AptxConstants.PHYLOXML_WEB_SITE );
             }
             catch ( final IOException e1 ) {
                 ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
@@ -639,7 +716,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         }
         else if ( o == _aptx_ref_item ) {
             try {
-                AptxUtil.openWebsite( AptxConstants.APTX_REFERENCE_URL, is_applet, applet );
+                AptxUtil.openWebsite( AptxConstants.APTX_REFERENCE_URL );
             }
             catch ( final IOException e1 ) {
                 ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
@@ -647,7 +724,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         }
         else if ( o == _phyloxml_ref_item ) {
             try {
-                AptxUtil.openWebsite( AptxConstants.PHYLOXML_REFERENCE_URL, is_applet, applet );
+                AptxUtil.openWebsite( AptxConstants.PHYLOXML_REFERENCE_URL );
             }
             catch ( final IOException e1 ) {
                 ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
@@ -659,7 +736,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                                               _writetopdf_filechooser,
                                               _current_dir,
                                               getContentPane(),
-                                              this );
+                                              getThisFrame() );
             if ( curr_dir != null ) {
                 setCurrentDir( curr_dir );
             }
@@ -672,7 +749,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                                                       GraphicsExportType.JPG,
                                                       _mainpanel,
                                                       _writetographics_filechooser,
-                                                      this,
+                                                      getThisFrame(),
                                                       getContentPane(),
                                                       _current_dir );
             if ( new_dir != null ) {
@@ -684,7 +761,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                                                       GraphicsExportType.GIF,
                                                       _mainpanel,
                                                       _writetographics_filechooser,
-                                                      this,
+                                                      getThisFrame(),
                                                       getContentPane(),
                                                       _current_dir );
             if ( new_dir != null ) {
@@ -696,7 +773,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                                                       GraphicsExportType.TIFF,
                                                       _mainpanel,
                                                       _writetographics_filechooser,
-                                                      this,
+                                                      getThisFrame(),
                                                       getContentPane(),
                                                       _current_dir );
             if ( new_dir != null ) {
@@ -708,7 +785,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                                                       GraphicsExportType.BMP,
                                                       _mainpanel,
                                                       _writetographics_filechooser,
-                                                      this,
+                                                      getThisFrame(),
                                                       getContentPane(),
                                                       _current_dir );
             if ( new_dir != null ) {
@@ -720,7 +797,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                                                       GraphicsExportType.PNG,
                                                       _mainpanel,
                                                       _writetographics_filechooser,
-                                                      this,
+                                                      getThisFrame(),
                                                       getContentPane(),
                                                       _current_dir );
             if ( new_dir != null ) {
@@ -728,7 +805,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
             }
         }
         else if ( o == _print_item ) {
-            print( getCurrentTreePanel(), getOptions(), this );
+            print( getCurrentTreePanel(), getOptions(), _frame.getThisFrame() );
         }
         else if ( o == _save_item ) {
             final File new_dir = writeToFile( _mainpanel.getCurrentPhylogeny(),
@@ -736,7 +813,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                                               _save_filechooser,
                                               _current_dir,
                                               getContentPane(),
-                                              this );
+                                              _frame.getThisFrame() );
             if ( new_dir != null ) {
                 setCurrentDir( new_dir );
             }
@@ -755,7 +832,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         }
         else if ( o == _lineage_inference ) {
             if ( isSubtreeDisplayed() ) {
-                JOptionPane.showMessageDialog( this,
+                JOptionPane.showMessageDialog( getThisFrame(),
                                                "Subtree is shown.",
                                                "Cannot infer ancestral taxonomies",
                                                JOptionPane.ERROR_MESSAGE );
@@ -775,6 +852,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         _contentpane.repaint();
     }
 
+
     public Configuration getConfiguration() {
         return _configuration;
     }
@@ -845,7 +923,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
             }
             if ( ( nodes == null ) || nodes.isEmpty() ) {
                 JOptionPane
-                        .showMessageDialog( this,
+                        .showMessageDialog( getThisFrame(),
                                             "Need to select nodes, either via direct selection or via the \"Search\" function",
                                             "No nodes selected for annotation",
                                             JOptionPane.ERROR_MESSAGE );
@@ -876,7 +954,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                         ref = ref.replaceAll( "\\s+", " " );
                         if ( ( ref.indexOf( ':' ) < 1 ) || ( ref.indexOf( ':' ) > ( ref.length() - 2 ) )
                                 || ( ref.length() < 3 ) ) {
-                            JOptionPane.showMessageDialog( this,
+                            JOptionPane.showMessageDialog( getThisFrame(),
                                                            "Reference needs to be in the form of \"GO:1234567\"",
                                                            "Illegal Format for Annotation Reference",
                                                            JOptionPane.ERROR_MESSAGE );
@@ -910,7 +988,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     private void chooseFont() {
         final FontChooser fc = new FontChooser();
         fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
-        fc.showDialog( this, "Select the Base Font" );
+        fc.showDialog( getThisFrame(), "Select the Base Font" );
         getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
         getControlPanel().displayedPhylogenyMightHaveChanged( true );
         if ( getMainPanel().getCurrentTreePanel() != null ) {
@@ -923,7 +1001,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
 
     private void chooseMinimalConfidence() {
         final String s = ( String ) JOptionPane
-                .showInputDialog( this,
+                .showInputDialog( getThisFrame(),
                                   "Please enter the minimum for confidence values to be displayed.\n"
                                           + "[current value: " + getOptions().getMinConfidenceValue() + "]\n",
                                   "Minimal Confidence Value",
@@ -972,7 +1050,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         }
         if ( ( nodes == null ) || nodes.isEmpty() ) {
             JOptionPane
-                    .showMessageDialog( this,
+                    .showMessageDialog( getThisFrame(),
                                         "Need to select external nodes, either via direct selection or via the \"Search\" function",
                                         "No external nodes selected to " + function.toLowerCase(),
                                         JOptionPane.ERROR_MESSAGE );
@@ -985,7 +1063,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
             res = ext - todo;
         }
         if ( res < 1 ) {
-            JOptionPane.showMessageDialog( this,
+            JOptionPane.showMessageDialog( getThisFrame(),
                                            "Cannot delete all nodes",
                                            "Attempt to delete all nodes ",
                                            JOptionPane.ERROR_MESSAGE );
@@ -1030,7 +1108,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                 _process_menu.setForeground( Color.RED );
             }
             _process_menu.removeAll();
-            final String text = "processes running: " + _process_pool.size();
+            final String text = "Processes Running: " + _process_pool.size();
             _process_menu.setText( text );
             _jmenubar.add( _process_menu );
             for( int i = 0; i < _process_pool.size(); ++i ) {
@@ -1083,7 +1161,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         setCurrentDir( _save_filechooser.getCurrentDirectory() );
         if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
             if ( file.exists() ) {
-                final int i = JOptionPane.showConfirmDialog( this,
+                final int i = JOptionPane.showConfirmDialog( getThisFrame(),
                                                              file + " already exists. Overwrite?",
                                                              "Warning",
                                                              JOptionPane.OK_CANCEL_OPTION,
@@ -1096,7 +1174,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                         file.delete();
                     }
                     catch ( final Exception e ) {
-                        JOptionPane.showMessageDialog( this,
+                        JOptionPane.showMessageDialog( getThisFrame(),
                                                        "Failed to delete: " + file,
                                                        "Error",
                                                        JOptionPane.WARNING_MESSAGE );
@@ -1119,7 +1197,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
             }
             catch ( final IOException e ) {
-                JOptionPane.showMessageDialog( this,
+                JOptionPane.showMessageDialog( getThisFrame(),
                                                "Failed to write to: " + file,
                                                "Error",
                                                JOptionPane.WARNING_MESSAGE );
@@ -1127,7 +1205,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         }
     }
 
-    void activateSaveAllIfNeeded() {
+    public void activateSaveAllIfNeeded() {
         if ( ( getMainPanel().getTabbedPane() != null ) && ( getMainPanel().getTabbedPane().getTabCount() > 1 ) ) {
             _save_all_item.setEnabled( true );
         }
@@ -1188,6 +1266,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         _help_jmenu.add( _help_item = new JMenuItem( "Documentation" ) );
         _help_jmenu.addSeparator();
         _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
+        _help_jmenu.add( _aptxjs_website_item = new JMenuItem( "NEW! Archaeopteryx online version: Archaeopteryx.js" ) );
         _help_jmenu.add( _mailing_list_item = new JMenuItem( "Mailing List" ) );
         _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" ); //TODO need to add this...
         _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
@@ -1196,6 +1275,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
         customizeJMenuItem( _help_item );
         customizeJMenuItem( _website_item );
+        customizeJMenuItem( _aptxjs_website_item );
         customizeJMenuItem( _mailing_list_item );
         customizeJMenuItem( _phyloxml_website_item );
         customizeJMenuItem( _aptx_ref_item );
@@ -1263,7 +1343,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     }
 
     void choosePdfWidth() {
-        final String s = ( String ) JOptionPane.showInputDialog( this,
+        final String s = ( String ) JOptionPane.showInputDialog( getThisFrame(),
                                                                  "Please enter the default line width for PDF export.\n"
                                                                          + "[current value: "
                                                                          + getOptions().getPrintLineWidth() + "]\n",
@@ -1310,7 +1390,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
             final Map<String, Integer> present_ranks = AptxUtil.getRankCounts( _mainpanel.getCurrentTreePanel().getPhylogeny());
             final String[] ranks = AptxUtil.getAllPossibleRanks(present_ranks);
             String rank = ( String ) JOptionPane
-                    .showInputDialog( this,
+                    .showInputDialog( getThisFrame(),
                                       "What rank should the colorization be based on",
                                       "Rank Selection",
                                       JOptionPane.QUESTION_MESSAGE,
@@ -1385,7 +1465,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         catch ( final Exception ex ) {
             // Do nothing.
         }
-        JOptionPane.showMessageDialog( this,
+        JOptionPane.showMessageDialog( getThisFrame(),
                                        ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
                                        "Error during File|Open",
                                        JOptionPane.ERROR_MESSAGE );
@@ -1396,7 +1476,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
             return;
         }
         if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
-            JOptionPane.showMessageDialog( this,
+            JOptionPane.showMessageDialog( getThisFrame(),
                                            "Gene tree is not rooted.",
                                            "Cannot execute GSDI",
                                            JOptionPane.ERROR_MESSAGE );
@@ -1411,7 +1491,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
             gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
         }
         catch ( final SDIException e ) {
-            JOptionPane.showMessageDialog( this,
+            JOptionPane.showMessageDialog( getThisFrame(),
                                            e.getLocalizedMessage(),
                                            "Error during GSDI",
                                            JOptionPane.ERROR_MESSAGE );
@@ -1435,7 +1515,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         _mainpanel.getCurrentTreePanel().setEdited( true );
         final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
         if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
-            JOptionPane.showMessageDialog( this,
+            JOptionPane.showMessageDialog( getThisFrame(),
                                            "Duplications: " + gsdi.getDuplicationsSum() + "\n"
                                                    + "Potential duplications: "
                                                    + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
@@ -1448,7 +1528,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                                            JOptionPane.WARNING_MESSAGE );
         }
         else {
-            JOptionPane.showMessageDialog( this,
+            JOptionPane.showMessageDialog( getThisFrame(),
                                            "Duplications: " + gsdi.getDuplicationsSum() + "\n"
                                                    + "Potential duplications: "
                                                    + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
@@ -1469,7 +1549,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
         if ( ( p > 0 )
                 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
-            JOptionPane.showMessageDialog( this,
+            JOptionPane.showMessageDialog( getThisFrame(),
                                            "Gene tree is not completely binary",
                                            "Cannot execute GSDI",
                                            JOptionPane.ERROR_MESSAGE );
@@ -1484,7 +1564,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
             gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
         }
         catch ( final SDIException e ) {
-            JOptionPane.showMessageDialog( this,
+            JOptionPane.showMessageDialog( getThisFrame(),
                                            e.getLocalizedMessage(),
                                            "Error during GSDIR",
                                            JOptionPane.ERROR_MESSAGE );
@@ -1510,7 +1590,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         _mainpanel.getCurrentTreePanel().setEdited( true );
         final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
         if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
-            JOptionPane.showMessageDialog( this,
+            JOptionPane.showMessageDialog( getThisFrame(),
                                            "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
                                                    + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
                                                    + "Stripped gene tree nodes: "
@@ -1521,7 +1601,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                                            JOptionPane.WARNING_MESSAGE );
         }
         else {
-            JOptionPane.showMessageDialog( this,
+            JOptionPane.showMessageDialog( getThisFrame(),
                                            "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
                                                    + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
                                                    + "Stripped gene tree nodes: "
@@ -1538,7 +1618,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
             return;
         }
         if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
-            JOptionPane.showMessageDialog( this,
+            JOptionPane.showMessageDialog( getThisFrame(),
                                            "Phylogeny is not rooted.",
                                            "Cannot infer ancestral taxonomies",
                                            JOptionPane.ERROR_MESSAGE );
@@ -1553,14 +1633,14 @@ public abstract class MainFrame extends JFrame implements ActionListener {
 
     boolean GAndSDoHaveMoreThanOneSpeciesInComman( final Phylogeny gene_tree ) {
         if ( ( gene_tree == null ) || gene_tree.isEmpty() ) {
-            JOptionPane.showMessageDialog( this,
+            JOptionPane.showMessageDialog( getThisFrame(),
                                            "Gene tree and species tree have no species in common.",
                                            "Error during SDI",
                                            JOptionPane.ERROR_MESSAGE );
             return false;
         }
         else if ( gene_tree.getNumberOfExternalNodes() < 2 ) {
-            JOptionPane.showMessageDialog( this,
+            JOptionPane.showMessageDialog( getThisFrame(),
                                            "Gene tree and species tree have only one species in common.",
                                            "Error during SDI",
                                            JOptionPane.ERROR_MESSAGE );
@@ -1652,21 +1732,21 @@ public abstract class MainFrame extends JFrame implements ActionListener {
             return false;
         }
         else if ( ( getSpeciesTree() == null ) || getSpeciesTree().isEmpty() ) {
-            JOptionPane.showMessageDialog( this,
+            JOptionPane.showMessageDialog( getThisFrame(),
                                            "No species tree loaded",
                                            "Cannot execute GSDI",
                                            JOptionPane.ERROR_MESSAGE );
             return false;
         }
         else if ( species_tree_has_to_binary && !getSpeciesTree().isCompletelyBinary() ) {
-            JOptionPane.showMessageDialog( this,
+            JOptionPane.showMessageDialog( getThisFrame(),
                                            "Species tree is not completely binary",
                                            "Cannot execute GSDI",
                                            JOptionPane.ERROR_MESSAGE );
             return false;
         }
         else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
-            JOptionPane.showMessageDialog( this,
+            JOptionPane.showMessageDialog( getThisFrame(),
                                            "Gene tree is not completely binary",
                                            "Cannot execute GSDI",
                                            JOptionPane.ERROR_MESSAGE );
@@ -1681,7 +1761,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         if ( getCurrentTreePanel() != null ) {
             if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
                 JOptionPane
-                        .showMessageDialog( this,
+                        .showMessageDialog( getThisFrame(),
                                             "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
                                             "Operation can not be exectuted on a sub-tree",
                                             JOptionPane.WARNING_MESSAGE );
@@ -2616,6 +2696,8 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         }
         return new_current_dir;
     }
+
 }
 
 class DefaultFilter extends FileFilter {