in progress
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Tue, 22 May 2012 01:20:49 +0000 (01:20 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Tue, 22 May 2012 01:20:49 +0000 (01:20 +0000)
forester/java/src/org/forester/archaeopteryx/Configuration.java
forester/java/src/org/forester/archaeopteryx/MainFrame.java
forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java
forester/java/src/org/forester/archaeopteryx/tools/AncestralTaxonomyInferrer.java
forester/java/src/org/forester/archaeopteryx/tools/InferenceManager.java [new file with mode: 0644]
forester/java/src/org/forester/archaeopteryx/tools/ProcessPool.java
forester/java/src/org/forester/archaeopteryx/tools/ProcessRunning.java

index bb896ae..ea48459 100644 (file)
@@ -62,10 +62,9 @@ public final class Configuration {
     private boolean                         _use_tabbed_display                                    = false;
     private boolean                         _hide_controls_and_menus                               = false;
     private CLADOGRAM_TYPE                  _cladogram_type                                        = Constants.CLADOGRAM_TYPE_DEFAULT;
-    private File _mafft = null;
-    private File _clustalo = null;
-    private File _fastme = null;
-    
+    private File                            _mafft                                                 = null;
+    private File                            _clustalo                                              = null;
+    private File                            _fastme                                                = null;
     private SortedMap<String, WebLink>      _weblinks                                              = null;
     private SortedMap<String, Color>        _display_colors                                        = null;
     private boolean                         _antialias_screen                                      = true;
@@ -932,16 +931,16 @@ public final class Configuration {
             }
         }
         else if ( key.equals( "path_to_mafft" ) ) {
-            setPathToMafft( new File( (String) st.nextElement() ) );
+            setPathToMafft( new File( ( String ) st.nextElement() ) );
         }
         else if ( key.equals( "path_to_clustalo" ) ) {
-            setPathToClustalOmega( new File( (String) st.nextElement() ) );
+            setPathToClustalOmega( new File( ( String ) st.nextElement() ) );
         }
         else if ( key.equals( "path_to_fastme" ) ) {
-            setPathToFastME( new File( (String) st.nextElement() ) );
+            setPathToFastME( new File( ( String ) st.nextElement() ) );
         }
         else if ( key.equals( "path_to_mafft" ) ) {
-            setPathToMafft( new File( (String) st.nextElement() ) );
+            setPathToMafft( new File( ( String ) st.nextElement() ) );
         }
         else if ( key.equals( VALIDATE_AGAINST_PHYLOXML_XSD_SCHEMA ) ) {
             setValidatePhyloXmlAgainstSchema( parseBoolean( ( String ) st.nextElement() ) );
@@ -1518,36 +1517,28 @@ public final class Configuration {
         return DEFAULT_FONT_FAMILY;
     }
 
-   
     public File getPathToMafft() {
         return _mafft;
     }
 
-    
-
     public File getPathToClustalOmega() {
         return _clustalo;
     }
 
-   
     public File getPathToFastME() {
         return _fastme;
     }
-    
-    
+
     public void setPathToMafft( final File mafft ) {
         _mafft = mafft;
     }
 
-    
-
-    public void setPathToClustalOmega(  final File clustalo ) {
-         _clustalo = clustalo ;
+    public void setPathToClustalOmega( final File clustalo ) {
+        _clustalo = clustalo;
     }
 
-   
     public void setPathToFastME( final File fastme ) {
-         _fastme = fastme;
+        _fastme = fastme;
     }
 
     static enum TRIPLET {
index e2ba175..a04ebe5 100644 (file)
@@ -210,13 +210,13 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     Configuration             _configuration;
     JMenuItem                 _remove_branch_color_item;
     Options                   _options;
-    final ProcessPool               _process_pool;
-    
+    final ProcessPool         _process_pool;
+
     MainFrame() {
-        _process_pool = new ProcessPool();
+        _process_pool = ProcessPool.createInstance();
     }
-    
-    ProcessPool getProcessPool() {
+
+    public ProcessPool getProcessPool() {
         return _process_pool;
     }
 
index 55ddbc1..d6fe0f6 100644 (file)
@@ -65,6 +65,7 @@ import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
 import org.forester.archaeopteryx.tools.AncestralTaxonomyInferrer;
 import org.forester.archaeopteryx.tools.GoAnnotation;
+import org.forester.archaeopteryx.tools.InferenceManager;
 import org.forester.archaeopteryx.tools.PhyloInferenceDialog;
 import org.forester.archaeopteryx.tools.PhylogeneticInferenceOptions;
 import org.forester.archaeopteryx.tools.PhylogeneticInferrer;
@@ -234,7 +235,6 @@ public final class MainFrameApplication extends MainFrame {
     JMenuItem                                _read_values_jmi;
 
     private MainFrameApplication( final Phylogeny[] phys, final Configuration config, final String title ) {
-        
         this( phys, config, title, null );
     }
 
@@ -681,12 +681,10 @@ public final class MainFrameApplication extends MainFrame {
     void buildPhylogeneticInferenceMenu() {
         final InferenceManager inference_manager = InferenceManager.getInstance();
         _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() );
-        _inference_menu
-                .add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment..." ) );
+        _inference_menu.add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment..." ) );
         customizeJMenuItem( _inference_from_msa_item );
         _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" );
-        _inference_menu
-                .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences..." ) );
+        _inference_menu.add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences..." ) );
         customizeJMenuItem( _inference_from_seqs_item );
         _inference_from_seqs_item.setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" );
         _jmenubar.add( _inference_menu );
index 8445246..8a93585 100644 (file)
@@ -31,9 +31,11 @@ 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 {
@@ -41,6 +43,15 @@ public class AncestralTaxonomyInferrer implements Runnable {
     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;
@@ -52,13 +63,27 @@ public class AncestralTaxonomyInferrer implements Runnable {
         return UniProtWsTools.BASE_URL;
     }
 
-    private void inferTaxonomies() {
+    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();
         try {
             AncestralTaxonomyInference.inferTaxonomyFromDescendents( _phy );
         }
         catch ( final AncestralTaxonomyInferenceException e ) {
-            _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
+            end();
             JOptionPane.showMessageDialog( _mf,
                                            e.getMessage(),
                                            "Error during ancestral taxonomy inference",
@@ -66,7 +91,7 @@ public class AncestralTaxonomyInferrer implements Runnable {
             return;
         }
         catch ( final UnknownHostException e ) {
-            _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
+            end();
             JOptionPane.showMessageDialog( _mf,
                                            "Could not connect to \"" + getBaseUrl() + "\"",
                                            "Network error during ancestral taxonomy inference",
@@ -74,7 +99,16 @@ public class AncestralTaxonomyInferrer implements Runnable {
             return;
         }
         catch ( final Exception e ) {
-            _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
+            end();
+            e.printStackTrace();
+            JOptionPane.showMessageDialog( _mf,
+                                           e.toString(),
+                                           "Unexpected exception during ancestral taxonomy inference",
+                                           JOptionPane.ERROR_MESSAGE );
+            return;
+        }
+        catch ( final Error e ) {
+            end();
             e.printStackTrace();
             JOptionPane.showMessageDialog( _mf,
                                            e.toString(),
@@ -82,11 +116,11 @@ public class AncestralTaxonomyInferrer implements Runnable {
                                            JOptionPane.ERROR_MESSAGE );
             return;
         }
-        _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
         _phy.setRerootable( false );
         _treepanel.setTree( _phy );
         _mf.showWhole();
         _treepanel.setEdited( true );
+        end();
         try {
             JOptionPane.showMessageDialog( _mf,
                                            "Ancestral taxonomy inference successfully completed",
diff --git a/forester/java/src/org/forester/archaeopteryx/tools/InferenceManager.java b/forester/java/src/org/forester/archaeopteryx/tools/InferenceManager.java
new file mode 100644 (file)
index 0000000..fc679aa
--- /dev/null
@@ -0,0 +1,10 @@
+
+package org.forester.archaeopteryx.tools;
+
+public class InferenceManager {
+
+    public static InferenceManager getInstance() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}
index 0e58ca2..60c531f 100644 (file)
@@ -30,8 +30,16 @@ import java.util.List;
 \r
 public class ProcessPool {\r
 \r
-    private final static boolean                   DEBUG      = true;\r
-    final static private ArrayList<ProcessRunning> _processes = new ArrayList<ProcessRunning>();\r
+    private final static boolean            DEBUG = true;\r
+    private final ArrayList<ProcessRunning> _processes;\r
+\r
+    private ProcessPool() {\r
+        _processes = new ArrayList<ProcessRunning>();\r
+    }\r
+\r
+    public static ProcessPool createInstance() {\r
+        return new ProcessPool();\r
+    }\r
 \r
     public synchronized ProcessRunning getProcessByIndex( final int i ) {\r
         return getProcesses().get( i );\r
@@ -41,7 +49,7 @@ public class ProcessPool {
         return getProcesses().size();\r
     }\r
 \r
-    public synchronized ProcessRunning getProcessById( final int id ) {\r
+    public synchronized ProcessRunning getProcessById( final long id ) {\r
         for( final ProcessRunning p : getProcesses() ) {\r
             if ( p.getId() == id ) {\r
                 return p;\r
@@ -50,25 +58,25 @@ public class ProcessPool {
         return null;\r
     }\r
 \r
-    public synchronized int addProcess( final String name ) {\r
+    public synchronized long addProcess( final String name ) {\r
         final ProcessRunning p = ProcessRunning.createInstance( name );\r
-        final int id = p.getId();\r
+        final long id = p.getId();\r
         if ( getProcessById( id ) != null ) {\r
             throw new IllegalStateException( " process with id " + id + "already exists" );\r
         }\r
         getProcesses().add( p );\r
         if ( DEBUG ) {\r
-            System.out.println( "added: " + p );\r
+            System.out.println( " pp: added: " + p );\r
         }\r
         return id;\r
     }\r
 \r
-    public synchronized boolean removeProcess( final int id ) {\r
+    public synchronized boolean removeProcess( final long id ) {\r
         final int i = getProcessIndexById( id );\r
         if ( i >= 0 ) {\r
             if ( DEBUG ) {\r
                 final ProcessRunning p = getProcessById( id );\r
-                System.out.println( " removing: " + p );\r
+                System.out.println( " pp: removing: " + p );\r
             }\r
             getProcesses().remove( i );\r
             return true;\r
@@ -76,10 +84,11 @@ public class ProcessPool {
         return false;\r
     }\r
 \r
-    private synchronized int getProcessIndexById( final int id ) {\r
-        final ProcessRunning p = getProcessById( id );\r
-        if ( p != null ) {\r
-            return p.getId();\r
+    private synchronized int getProcessIndexById( final long id ) {\r
+        for( int i = 0; i < size(); ++i ) {\r
+            if ( getProcesses().get( i ).getId() == id ) {\r
+                return i;\r
+            }\r
         }\r
         return -1;\r
     }\r
index 8b923f2..2ca5f05 100644 (file)
@@ -30,37 +30,40 @@ import java.util.Calendar;
 \r
 final public class ProcessRunning {\r
 \r
-    private static int   count = 0;\r
-    final private int    _id;\r
+    private static long  count = 0;\r
+    final private long   _id;\r
     final private String _name;\r
     final private String _start;\r
 \r
-    public  int getId() {\r
+    public long getId() {\r
         return _id;\r
     }\r
-    \r
-    public  String getName() {\r
+\r
+    public String getName() {\r
         return _name;\r
     }\r
-    \r
+\r
     public String getStart() {\r
         return _start;\r
     }\r
-    \r
+\r
+    @Override\r
     public String toString() {\r
         return getName() + " [id=" + getId() + "] [start=" + getStart() + "]";\r
     }\r
-    \r
+\r
     synchronized static ProcessRunning createInstance( final String name ) {\r
         final Calendar cal = Calendar.getInstance();\r
         final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" );\r
         return new ProcessRunning( count++, name, sdf.format( cal.getTime() ) );\r
     }\r
-    \r
-    private ProcessRunning( final int id, final String name, final String start ) {\r
+\r
+    private ProcessRunning( final long id, final String name, final String start ) {\r
+        if ( id < 0 ) {\r
+            throw new IllegalArgumentException( "process id cannot be negative" );\r
+        }\r
         _id = id;\r
         _name = name;\r
-        _start = start;  \r
+        _start = start;\r
     }\r
-\r
 }\r