in progress
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Tue, 22 May 2012 17:38:05 +0000 (17:38 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Tue, 22 May 2012 17:38:05 +0000 (17:38 +0000)
forester/java/src/org/forester/archaeopteryx/MainFrame.java
forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java
forester/java/src/org/forester/archaeopteryx/tools/AncestralTaxonomyInferrer.java
forester/java/src/org/forester/archaeopteryx/tools/GoAnnotation.java
forester/java/src/org/forester/archaeopteryx/tools/RunnableProcess.java [new file with mode: 0644]

index a04ebe5..f4f9c5c 100644 (file)
@@ -24,6 +24,7 @@
 
 package org.forester.archaeopteryx;
 
+import java.awt.Color;
 import java.awt.Component;
 import java.awt.Container;
 import java.awt.Font;
@@ -203,6 +204,8 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     JMenuItem                 _phyloxml_website_item;
     JMenuItem                 _phyloxml_ref_item;
     JMenuItem                 _aptx_ref_item;
+    // process menu:
+    JMenu                     _process_menu;
     // Handy pointers to child components:
     MainPanel                 _mainpanel;
     Container                 _contentpane;
@@ -541,6 +544,43 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         _jmenubar.add( _help_jmenu );
     }
 
+    public void updateProcessMenu() {
+        System.out.println( "pool size " + _process_pool.size() );
+        if ( _process_pool.size() > 0 ) {
+            if ( _process_menu == null ) {
+                _process_menu = createMenu( "", getConfiguration() );
+                _process_menu.setForeground( Color.RED );
+            }
+            final String text = "processes running: " + _process_pool.size();
+            _process_menu.setText( text );
+            _jmenubar.add( _process_menu );
+        }
+        else {
+            if ( _process_menu != null ) {
+                _jmenubar.remove( _process_menu );
+            }
+        }
+        _jmenubar.validate();
+        _jmenubar.repaint();
+        repaint();
+        //        _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
+        //        _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
+        //        _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
+        //        _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
+        //        _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
+        //        _help_jmenu.addSeparator();
+        //        _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
+        //        customizeJMenuItem( _help_item );
+        //        customizeJMenuItem( _website_item );
+        //        customizeJMenuItem( _phyloxml_website_item );
+        //        customizeJMenuItem( _aptx_ref_item );
+        //        customizeJMenuItem( _phyloxml_ref_item );
+        //        customizeJMenuItem( _about_item );
+        //        _phyloxml_ref_item.setToolTipText( PHYLOXML_REF_TOOL_TIP );
+        //        _aptx_ref_item.setToolTipText( APTX_REF_TOOL_TIP );
+        //        _jmenubar.add( _help_jmenu );
+    }
+
     void buildTypeMenu() {
         _type_menu = createMenu( TYPE_MENU_HEADER, getConfiguration() );
         _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
@@ -782,7 +822,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         return _label_direction_cbmi;
     }
 
-    MainPanel getMainPanel() {
+    public MainPanel getMainPanel() {
         return _mainpanel;
     }
 
index b056ac8..74b747c 100644 (file)
@@ -270,7 +270,7 @@ public final class MainFrameApplet extends MainFrame {
     }
 
     @Override
-    MainPanel getMainPanel() {
+    public MainPanel getMainPanel() {
         return _mainpanel;
     }
 
index 8a93585..7475d1d 100644 (file)
@@ -31,27 +31,16 @@ import javax.swing.JOptionPane;
 
 import org.forester.analysis.AncestralTaxonomyInference;
 import org.forester.analysis.AncestralTaxonomyInferenceException;
-import org.forester.archaeopteryx.Constants;
 import org.forester.archaeopteryx.MainFrameApplication;
 import org.forester.archaeopteryx.TreePanel;
 import org.forester.phylogeny.Phylogeny;
-import org.forester.util.ForesterUtil;
 import org.forester.ws.uniprot.UniProtWsTools;
 
-public class AncestralTaxonomyInferrer implements Runnable {
+public class AncestralTaxonomyInferrer extends RunnableProcess {
 
     private final Phylogeny            _phy;
     private final MainFrameApplication _mf;
     private final TreePanel            _treepanel;
-    private long                       _process_id;
-
-    private long getProcessId() {
-        return _process_id;
-    }
-
-    private void setProcessId( final long process_id ) {
-        _process_id = process_id;
-    }
 
     public AncestralTaxonomyInferrer( final MainFrameApplication mf, final TreePanel treepanel, final Phylogeny phy ) {
         _phy = phy;
@@ -63,27 +52,13 @@ public class AncestralTaxonomyInferrer implements Runnable {
         return UniProtWsTools.BASE_URL;
     }
 
-    private void start() {
-        _mf.getMainPanel().getCurrentTreePanel().setWaitCursor();
-        setProcessId( _mf.getProcessPool().addProcess( "ancestral taxonomy" ) );
-    }
-
-    private void end() {
-        final boolean removed = _mf.getProcessPool().removeProcess( getProcessId() );
-        if ( !removed ) {
-            ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not remove process " + getProcessId()
-                    + " from process pool" );
-        }
-        _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
-    }
-
     private void inferTaxonomies() {
-        start();
+        start( _mf, "ancestral taxonomy" );
         try {
             AncestralTaxonomyInference.inferTaxonomyFromDescendents( _phy );
         }
         catch ( final AncestralTaxonomyInferenceException e ) {
-            end();
+            end( _mf );
             JOptionPane.showMessageDialog( _mf,
                                            e.getMessage(),
                                            "Error during ancestral taxonomy inference",
@@ -91,7 +66,7 @@ public class AncestralTaxonomyInferrer implements Runnable {
             return;
         }
         catch ( final UnknownHostException e ) {
-            end();
+            end( _mf );
             JOptionPane.showMessageDialog( _mf,
                                            "Could not connect to \"" + getBaseUrl() + "\"",
                                            "Network error during ancestral taxonomy inference",
@@ -99,7 +74,7 @@ public class AncestralTaxonomyInferrer implements Runnable {
             return;
         }
         catch ( final Exception e ) {
-            end();
+            end( _mf );
             e.printStackTrace();
             JOptionPane.showMessageDialog( _mf,
                                            e.toString(),
@@ -108,8 +83,7 @@ public class AncestralTaxonomyInferrer implements Runnable {
             return;
         }
         catch ( final Error e ) {
-            end();
-            e.printStackTrace();
+            end( _mf );
             JOptionPane.showMessageDialog( _mf,
                                            e.toString(),
                                            "Unexpected error during ancestral taxonomy inference",
@@ -120,7 +94,7 @@ public class AncestralTaxonomyInferrer implements Runnable {
         _treepanel.setTree( _phy );
         _mf.showWhole();
         _treepanel.setEdited( true );
-        end();
+        end( _mf );
         try {
             JOptionPane.showMessageDialog( _mf,
                                            "Ancestral taxonomy inference successfully completed",
index 6ca6a2f..17d417f 100644 (file)
@@ -43,7 +43,7 @@ import org.forester.phylogeny.data.Sequence;
 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
 import org.forester.util.ForesterUtil;
 
-public class GoAnnotation implements Runnable {
+public class GoAnnotation extends RunnableProcess {
 
     private static final String        SYMBOL   = "Symbol";
     private static final String        ASPECT   = "Aspect";
@@ -62,7 +62,7 @@ public class GoAnnotation implements Runnable {
     }
 
     private void annotate() {
-        _mf.getMainPanel().getCurrentTreePanel().setWaitCursor();
+        start( _mf, "GO annotate" );
         for( final PhylogenyNodeIterator iter = _phy.iteratorPostorder(); iter.hasNext(); ) {
             final PhylogenyNode node = iter.next();
             if ( ( node.getNodeData().getSequences() != null ) && !node.getNodeData().getSequences().isEmpty() ) {
@@ -125,6 +125,7 @@ public class GoAnnotation implements Runnable {
                 }
             }
         }
+        end( _mf );
         _treepanel.repaint();
         _treepanel.setEdited( true );
     }
diff --git a/forester/java/src/org/forester/archaeopteryx/tools/RunnableProcess.java b/forester/java/src/org/forester/archaeopteryx/tools/RunnableProcess.java
new file mode 100644 (file)
index 0000000..159ee9b
--- /dev/null
@@ -0,0 +1,35 @@
+
+package org.forester.archaeopteryx.tools;
+
+import org.forester.archaeopteryx.Constants;
+import org.forester.archaeopteryx.MainFrame;
+import org.forester.util.ForesterUtil;
+
+public abstract class RunnableProcess implements Runnable {
+
+    long _process_id;
+
+    long getProcessId() {
+        return _process_id;
+    }
+
+    void setProcessId( final long process_id ) {
+        _process_id = process_id;
+    }
+
+    void start( final MainFrame mf, final String name ) {
+        mf.getMainPanel().getCurrentTreePanel().setWaitCursor();
+        setProcessId( mf.getProcessPool().addProcess( name ) );
+        mf.updateProcessMenu();
+    }
+
+    void end( final MainFrame mf ) {
+        final boolean removed = mf.getProcessPool().removeProcess( getProcessId() );
+        if ( !removed ) {
+            ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not remove process " + getProcessId()
+                    + " from process pool" );
+        }
+        mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
+        mf.updateProcessMenu();
+    }
+}