+ * This service is used to report to the user information about what processes + * are running and how, in the Mastodon-app. + * + * @author Jean-Yves Tinevez + */ +public interface MastodonLogger extends SciJavaService +{ + + /** + * Returns the log source for the Mastodon-app running. + *
+ * All log sources should derive from this root, using e.g.: + * + *
+ * LogSource myProcessSource = logger.getLogSourceRoot().subSource( "My process" ); + *+ * + * @return the log source root. + */ + public LogSource getLogSourceRoot(); + + /** + * Displays an information message. + * + * @param message + * the message to display. + * @param source + * the source of the message. + */ + public void info( String message, LogSource source ); + + /** + * Displays an information message. It will appear as coming from an unknown + * source. + * + * @param message + * the message to display. + */ + public void info( String message ); + + /** + * Displays an error message. + * + * @param message + * the message to display. + * @param source + * the source of the message. + */ + public void error( String message, LogSource source ); + + /** + * Displays an error message. It will appear as coming from an unknown source. + * + * @param message + * the message to display. + */ + public void error( String message ); + + /** + * Sets the status message to display for the process with the specified log + * source. + * + * @param status + * the status to set. + * @param source + * the source of the process. + */ + public void setStatus( String status, LogSource source ); + + /** + * Sets the status message to display for an unknown process. + * + * @param status + * the status to set. + */ + public void setStatus( String status ); + + /** + * Sets the progress to display for the process with the specified log source. + * + * @param progress + * a
double value between 0 and 1. If
+ * progress is equal to or larger than 1, then the
+ * process is considered finished.
+ * @param source
+ * the source of the process.
+ */
+ public void setProgress( double progress, LogSource source );
+
+ /**
+ * Sets the progress to display for an unknown process.
+ *
+ * @param progress
+ * a double value between 0 and 1. If
+ * progress is equal to or larger than 1, then the
+ * process is considered finished.
+ */
+ public void setProgress( double progress );
+}
diff --git a/src/main/java/org/mastodon/revised/mamut/MastodonMainWindow.java b/src/main/java/org/mastodon/revised/mamut/MastodonMainWindow.java
new file mode 100644
index 000000000..e174fa148
--- /dev/null
+++ b/src/main/java/org/mastodon/revised/mamut/MastodonMainWindow.java
@@ -0,0 +1,97 @@
+package org.mastodon.revised.mamut;
+
+import static org.mastodon.app.ui.ViewMenuBuilder.item;
+import static org.mastodon.app.ui.ViewMenuBuilder.separator;
+import static org.mastodon.revised.mamut.MamutMenuBuilder.fileMenu;
+import static org.mastodon.revised.mamut.MamutMenuBuilder.windowMenu;
+import static org.mastodon.revised.mamut.MastodonIcons.TITLE_ICON;
+
+import java.awt.BorderLayout;
+import java.awt.Font;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import javax.swing.ActionMap;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JMenuBar;
+import javax.swing.JPanel;
+import javax.swing.SwingConstants;
+import javax.swing.WindowConstants;
+import javax.swing.border.EmptyBorder;
+
+import org.mastodon.app.ui.ViewMenu;
+import org.mastodon.revised.ui.keymap.Keymap;
+
+public class MastodonMainWindow extends JFrame
+{
+
+ private static final long serialVersionUID = 1L;
+
+ public MastodonMainWindow( final WindowManager windowManager )
+ {
+ setTitle( "Mastodon-app" );
+ setIconImage( MastodonIcons.TITLE_ICON.getImage() );
+ setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
+
+ final JPanel contentPane = new JPanel();
+ contentPane.setBorder( new EmptyBorder( 5, 5, 5, 5 ) );
+ contentPane.setLayout( new BorderLayout( 10, 10 ) );
+ setContentPane( contentPane );
+
+ final JLabel lblTitle = new JLabel( "Mastodon-app" );
+ lblTitle.setHorizontalAlignment( SwingConstants.CENTER );
+ lblTitle.setFont( lblTitle.getFont().deriveFont( lblTitle.getFont().getStyle() | Font.BOLD, lblTitle.getFont().getSize() + 2f ) );
+ lblTitle.setIcon( TITLE_ICON );
+ contentPane.add( lblTitle, BorderLayout.NORTH );
+
+ final MainButtonPanel mainButtonPanel = new MainButtonPanel( windowManager );
+ contentPane.add( mainButtonPanel, BorderLayout.WEST );
+
+ final DefaultMastodonLogger mastodonLogger = windowManager.getContext().getService( DefaultMastodonLogger.class );
+ contentPane.add( mastodonLogger.getMastodonLogPanel(), BorderLayout.CENTER );
+
+ final JMenuBar menubar = new JMenuBar();
+ setJMenuBar( menubar );
+
+ final Keymap keymap = windowManager.getKeymapManager().getForwardDefaultKeymap();
+ final ViewMenu menu = new ViewMenu( menubar, keymap, KeyConfigContexts.MASTODON );
+ keymap.updateListeners().add( menu::updateKeymap );
+ final ActionMap actionMap = windowManager.getGlobalAppActions().getActionMap();
+ addMenus( menu, actionMap );
+ windowManager.getPlugins().addMenus( menu );
+
+ setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE );
+ addWindowListener( new WindowAdapter()
+ {
+ @Override
+ public void windowClosed( final WindowEvent e )
+ {
+ if ( windowManager != null )
+ windowManager.closeAllWindows();
+ }
+ } );
+
+ pack();
+ setLocationByPlatform( true );
+ }
+
+ public static void addMenus( final ViewMenu menu, final ActionMap actionMap )
+ {
+ MamutMenuBuilder.build( menu, actionMap,
+ fileMenu(
+ item( ProjectManager.CREATE_PROJECT ),
+ item( ProjectManager.LOAD_PROJECT ),
+ item( ProjectManager.SAVE_PROJECT ),
+ separator(),
+ item( ProjectManager.IMPORT_TGMM ),
+ item( ProjectManager.IMPORT_SIMI ),
+ item( ProjectManager.IMPORT_MAMUT ),
+ item( ProjectManager.EXPORT_MAMUT ),
+ separator(),
+ item( WindowManager.PREFERENCES_DIALOG ) ),
+ windowMenu(
+ item( WindowManager.NEW_BDV_VIEW ),
+ item( WindowManager.NEW_TRACKSCHEME_VIEW ) ) );
+ }
+}
diff --git a/src/main/java/org/mastodon/revised/mamut/SysOutMastodonLogger.java b/src/main/java/org/mastodon/revised/mamut/SysOutMastodonLogger.java
new file mode 100644
index 000000000..7368ee67f
--- /dev/null
+++ b/src/main/java/org/mastodon/revised/mamut/SysOutMastodonLogger.java
@@ -0,0 +1,71 @@
+package org.mastodon.revised.mamut;
+
+import org.scijava.Priority;
+import org.scijava.log.LogSource;
+import org.scijava.plugin.Plugin;
+import org.scijava.service.AbstractService;
+
+/**
+ * A low priority {@link MastodonLogger} that appends messages to
+ * {@link System#out} and {@link System#err}. Progress messages are discarded.
+ *
+ * @author Jean-Yves Tinevez
+ */
+@Plugin( type = MastodonLogger.class, priority = Priority.LOW )
+public class SysOutMastodonLogger extends AbstractService implements MastodonLogger
+{
+
+ private final LogSource root = LogSource.newRoot();
+
+ private final LogSource unknownSource = root.subSource( "Unkown source" );
+
+ @Override
+ public LogSource getLogSourceRoot()
+ {
+ return root;
+ }
+
+ @Override
+ public void info( final String message, final LogSource source )
+ {
+ System.out.println( '[' + source.name() + "] " + message );
+ }
+
+ @Override
+ public void info( final String message )
+ {
+ info( message, unknownSource );
+ }
+
+ @Override
+ public void error( final String message, final LogSource source )
+ {
+ System.err.println( '[' + source.name() + "] " + message );
+ }
+
+ @Override
+ public void error( final String message )
+ {
+ error( message, unknownSource );
+ }
+
+ @Override
+ public void setStatus( final String status, final LogSource source )
+ {
+ info( status, source );
+ }
+
+ @Override
+ public void setStatus( final String status )
+ {
+ setStatus( status, unknownSource );
+ }
+
+ @Override
+ public void setProgress( final double progress, final LogSource source )
+ {}
+
+ @Override
+ public void setProgress( final double progress )
+ {}
+}
diff --git a/src/main/java/org/mastodon/revised/mamut/feature/DefaultMamutFeatureComputerService.java b/src/main/java/org/mastodon/revised/mamut/feature/DefaultMamutFeatureComputerService.java
index 708fdc45f..3ceb001c2 100644
--- a/src/main/java/org/mastodon/revised/mamut/feature/DefaultMamutFeatureComputerService.java
+++ b/src/main/java/org/mastodon/revised/mamut/feature/DefaultMamutFeatureComputerService.java
@@ -10,6 +10,7 @@ public class DefaultMamutFeatureComputerService extends AbstractFeatureComputerS
@Override
public void initialize()
{
+ super.initialize();
initializeFeatureComputers( SpotFeatureComputer.class );
initializeFeatureComputers( LinkFeatureComputer.class );
}
diff --git a/src/main/java/org/mastodon/revised/model/feature/AbstractFeatureComputerService.java b/src/main/java/org/mastodon/revised/model/feature/AbstractFeatureComputerService.java
index 61ab24b67..18e740b95 100644
--- a/src/main/java/org/mastodon/revised/model/feature/AbstractFeatureComputerService.java
+++ b/src/main/java/org/mastodon/revised/model/feature/AbstractFeatureComputerService.java
@@ -13,11 +13,10 @@
import org.mastodon.graph.object.ObjectEdge;
import org.mastodon.graph.object.ObjectGraph;
import org.mastodon.graph.object.ObjectVertex;
+import org.mastodon.revised.mamut.MastodonLogger;
import org.mastodon.revised.model.AbstractModel;
-import org.mastodon.revised.ui.ProgressListener;
import org.scijava.InstantiableException;
-import org.scijava.app.StatusService;
-import org.scijava.log.LogService;
+import org.scijava.log.LogSource;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.PluginInfo;
import org.scijava.plugin.PluginService;
@@ -30,10 +29,7 @@ public abstract class AbstractFeatureComputerService< AM extends AbstractModel<
private PluginService pluginService;
@Parameter
- private LogService logService;
-
- @Parameter
- private StatusService status;
+ private MastodonLogger logger;
/**
* Feature computers of any type, mapped by their key, for dependency
@@ -41,17 +37,26 @@ public abstract class AbstractFeatureComputerService< AM extends AbstractModel<
*/
private final Map< String, FeatureComputer< AM > > featureComputers = new HashMap<>();
+ private LogSource logSource;
+
+ @Override
+ public void initialize()
+ {
+ super.initialize();
+ logSource = logger.getLogSourceRoot().subSource( "Feature computer" );
+ }
+
@Override
- public boolean compute( final AM model, final FeatureModel featureModel, final Set< FeatureComputer< AM > > computers, final ProgressListener progressListener )
+ public boolean compute( final AM model, final FeatureModel featureModel, final Set< FeatureComputer< AM > > computers )
{
final ObjectGraph< FeatureComputer< AM > > dependencyGraph = getDependencyGraph( computers );
final TopologicalSort< ObjectVertex< FeatureComputer< AM > >, ObjectEdge< FeatureComputer< AM > > > sorter = new TopologicalSort<>( dependencyGraph );
if ( sorter.hasFailed() )
{
- logService.error( "Could not compute features using " + computers +
- " as they have a circular dependency." );
- progressListener.showStatus( "Circular dependency!" );
+ logger.error( "Could not compute features using " + computers +
+ " as they have a circular dependency.", logSource );
+ logger.setStatus( "Circular dependency!", logSource );
return false;
}
@@ -62,16 +67,16 @@ public boolean compute( final AM model, final FeatureModel featureModel, final S
for ( final ObjectVertex< FeatureComputer< AM > > v : sorter.get() )
{
final FeatureComputer< AM > computer = v.getContent();
- progressListener.showStatus( computer.getKey() );
+ logger.setStatus( computer.getKey(), logSource );
final Feature< ?, ? > feature = computer.compute( model );
featureModel.declareFeature( feature );
- progressListener.showProgress( progress++, computers.size() );
+ logger.setProgress( progress++ / ( double ) computers.size(), logSource );
}
final long end = System.currentTimeMillis();
- progressListener.clearStatus();
- progressListener.showStatus( String.format( "Done in %.1f s.", ( end - start ) / 1000. ) );
+ logger.setProgress( 1., logSource );
+ logger.info( String.format( "Done in %.1f s.", ( end - start ) / 1000. ), logSource );
return true;
}
@@ -148,14 +153,14 @@ private final ObjectVertex< FeatureComputer< AM > > addDepVertex(
final FeatureComputer< AM > computerDep = featureComputers.get( dep );
if ( null == computerDep )
{
- logService.error( "Cannot add feature computer named " + dep + " as it is not registered." );
+ logger.error( "Cannot add feature computer named " + dep + " as it is not registered.", logSource );
return null;
}
final ObjectVertex< FeatureComputer< AM > > target = addDepVertex( computerDep, computerGraph, vref2 );
if ( null == target )
{
- logService.error( "Removing feature computer named " + computer + " as some of its dependencies could not be resolved." );
+ logger.error( "Removing feature computer named " + computer + " as some of its dependencies could not be resolved.", logSource );
computerGraph.remove( source );
break;
}
@@ -180,8 +185,8 @@ protected < K extends FeatureComputer< AM > > void initializeFeatureComputers( f
final String name = info.getName();
if ( featureComputers.keySet().contains( name ) )
{
- logService.error( "Cannot register feature computer with name " + name + " of class " + cl +
- ". There is already a feature computer registered with this name." );
+ logger.error( "Cannot register feature computer with name " + name + " of class " + cl +
+ ". There is already a feature computer registered with this name.", logSource );
continue;
}
@@ -192,8 +197,8 @@ protected < K extends FeatureComputer< AM > > void initializeFeatureComputers( f
}
catch ( final InstantiableException e )
{
- logService.error( "Could not instantiate computer with name " + name + " of class " + cl +
- ":\n" + e.getMessage() );
+ logger.error( "Could not instantiate computer with name " + name + " of class " + cl +
+ ":\n" + e.getMessage(), logSource );
e.printStackTrace();
}
}
diff --git a/src/main/java/org/mastodon/revised/model/feature/FeatureComputerService.java b/src/main/java/org/mastodon/revised/model/feature/FeatureComputerService.java
index 56d8a545a..1e6b9af8e 100644
--- a/src/main/java/org/mastodon/revised/model/feature/FeatureComputerService.java
+++ b/src/main/java/org/mastodon/revised/model/feature/FeatureComputerService.java
@@ -4,7 +4,6 @@
import java.util.Set;
import org.mastodon.revised.model.AbstractModel;
-import org.mastodon.revised.ui.ProgressListener;
import org.scijava.service.SciJavaService;
/**
@@ -37,10 +36,8 @@ public interface FeatureComputerService< AM extends AbstractModel< ?, ?, ? > > e
* @param selectedComputers
* what computers to run. The computers in the specified set must
* have been discovered by this instance.
- * @param progressListener
- * a progress listener, used to report calculation progress.
* @return true if computation terminated successfully.
*/
- public boolean compute( AM model, FeatureModel featureModel, Set< FeatureComputer< AM > > selectedComputers, ProgressListener progressListener );
+ public boolean compute( AM model, FeatureModel featureModel, Set< FeatureComputer< AM > > selectedComputers );
}
diff --git a/src/main/java/org/mastodon/revised/ui/ProgressListener.java b/src/main/java/org/mastodon/revised/ui/ProgressListener.java
deleted file mode 100644
index c6a6068d1..000000000
--- a/src/main/java/org/mastodon/revised/ui/ProgressListener.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package org.mastodon.revised.ui;
-
-public interface ProgressListener
-{
- public void showStatus( String string );
-
- public void showProgress( int current, int total );
-
- public void clearStatus();
-}
diff --git a/src/main/resources/org/mastodon/revised/mamut/BDV-logo-32x32.png b/src/main/resources/org/mastodon/revised/mamut/BDV-logo-32x32.png
new file mode 100644
index 000000000..0241a5019
Binary files /dev/null and b/src/main/resources/org/mastodon/revised/mamut/BDV-logo-32x32.png differ
diff --git a/src/main/resources/org/mastodon/revised/mamut/Feature-icon-32x32.png b/src/main/resources/org/mastodon/revised/mamut/Feature-icon-32x32.png
new file mode 100644
index 000000000..34cf63df8
Binary files /dev/null and b/src/main/resources/org/mastodon/revised/mamut/Feature-icon-32x32.png differ
diff --git a/src/main/resources/org/mastodon/revised/mamut/MaMuT-icon-32x32.png b/src/main/resources/org/mastodon/revised/mamut/MaMuT-icon-32x32.png
new file mode 100644
index 000000000..b04efe677
Binary files /dev/null and b/src/main/resources/org/mastodon/revised/mamut/MaMuT-icon-32x32.png differ
diff --git a/src/main/resources/org/mastodon/revised/mamut/Mastodon-logo-01-128x128.png b/src/main/resources/org/mastodon/revised/mamut/Mastodon-logo-01-128x128.png
new file mode 100644
index 000000000..9059b2ff7
Binary files /dev/null and b/src/main/resources/org/mastodon/revised/mamut/Mastodon-logo-01-128x128.png differ
diff --git a/src/main/resources/org/mastodon/revised/mamut/Mastodon-logo-01-16x16.png b/src/main/resources/org/mastodon/revised/mamut/Mastodon-logo-01-16x16.png
new file mode 100644
index 000000000..7e56e798c
Binary files /dev/null and b/src/main/resources/org/mastodon/revised/mamut/Mastodon-logo-01-16x16.png differ
diff --git a/src/main/resources/org/mastodon/revised/mamut/Mastodon-logo-01-256x256.png b/src/main/resources/org/mastodon/revised/mamut/Mastodon-logo-01-256x256.png
new file mode 100644
index 000000000..141871907
Binary files /dev/null and b/src/main/resources/org/mastodon/revised/mamut/Mastodon-logo-01-256x256.png differ
diff --git a/src/main/resources/org/mastodon/revised/mamut/Mastodon-logo-01-32x32.png b/src/main/resources/org/mastodon/revised/mamut/Mastodon-logo-01-32x32.png
new file mode 100644
index 000000000..f8c1ed08c
Binary files /dev/null and b/src/main/resources/org/mastodon/revised/mamut/Mastodon-logo-01-32x32.png differ
diff --git a/src/main/resources/org/mastodon/revised/mamut/Mastodon-logo-01-64x64.png b/src/main/resources/org/mastodon/revised/mamut/Mastodon-logo-01-64x64.png
new file mode 100644
index 000000000..2d065d1c3
Binary files /dev/null and b/src/main/resources/org/mastodon/revised/mamut/Mastodon-logo-01-64x64.png differ
diff --git a/src/main/resources/org/mastodon/revised/mamut/Mastodon-logo-01.png b/src/main/resources/org/mastodon/revised/mamut/Mastodon-logo-01.png
new file mode 100644
index 000000000..bea7b352e
Binary files /dev/null and b/src/main/resources/org/mastodon/revised/mamut/Mastodon-logo-01.png differ
diff --git a/src/main/resources/org/mastodon/revised/mamut/Save-icon-32x32.png b/src/main/resources/org/mastodon/revised/mamut/Save-icon-32x32.png
new file mode 100644
index 000000000..c6347ea8a
Binary files /dev/null and b/src/main/resources/org/mastodon/revised/mamut/Save-icon-32x32.png differ
diff --git a/src/main/resources/org/mastodon/revised/mamut/SaveAs-icon-32x32.png b/src/main/resources/org/mastodon/revised/mamut/SaveAs-icon-32x32.png
new file mode 100644
index 000000000..e40030ab2
Binary files /dev/null and b/src/main/resources/org/mastodon/revised/mamut/SaveAs-icon-32x32.png differ
diff --git a/src/main/resources/org/mastodon/revised/mamut/Table-icon-32x32.png b/src/main/resources/org/mastodon/revised/mamut/Table-icon-32x32.png
new file mode 100644
index 000000000..7d9ce7c07
Binary files /dev/null and b/src/main/resources/org/mastodon/revised/mamut/Table-icon-32x32.png differ
diff --git a/src/main/resources/org/mastodon/revised/mamut/Table-icon2-32x32.png b/src/main/resources/org/mastodon/revised/mamut/Table-icon2-32x32.png
new file mode 100644
index 000000000..25b3a0404
Binary files /dev/null and b/src/main/resources/org/mastodon/revised/mamut/Table-icon2-32x32.png differ
diff --git a/src/main/resources/org/mastodon/revised/mamut/Tag-icon-32x32.png b/src/main/resources/org/mastodon/revised/mamut/Tag-icon-32x32.png
new file mode 100644
index 000000000..008496eea
Binary files /dev/null and b/src/main/resources/org/mastodon/revised/mamut/Tag-icon-32x32.png differ
diff --git a/src/main/resources/org/mastodon/revised/mamut/TrackScheme-logo2-32x32.png b/src/main/resources/org/mastodon/revised/mamut/TrackScheme-logo2-32x32.png
new file mode 100644
index 000000000..072340a49
Binary files /dev/null and b/src/main/resources/org/mastodon/revised/mamut/TrackScheme-logo2-32x32.png differ
diff --git a/src/test/java/org/mastodon/revised/mamut/MaMuTExportExample.java b/src/test/java/org/mastodon/revised/mamut/MaMuTExportExample.java
index 7c7fa36ca..19ed90bf5 100644
--- a/src/test/java/org/mastodon/revised/mamut/MaMuTExportExample.java
+++ b/src/test/java/org/mastodon/revised/mamut/MaMuTExportExample.java
@@ -8,12 +8,12 @@
import org.jdom2.JDOMException;
import org.mastodon.revised.mamut.feature.MamutFeatureComputerService;
import org.mastodon.revised.model.feature.FeatureComputer;
-import org.mastodon.revised.model.mamut.ModelUtils;
import org.mastodon.revised.model.mamut.Model;
+import org.mastodon.revised.model.mamut.ModelUtils;
import org.mastodon.revised.model.mamut.trackmate.MamutExporter;
import org.mastodon.revised.model.mamut.trackmate.TrackMateImporter;
-import org.mastodon.revised.ui.ProgressListener;
import org.scijava.Context;
+import org.scijava.prefs.PrefService;
import mpicbg.spim.data.SpimDataException;
@@ -27,7 +27,7 @@ public static void main( final String[] args ) throws IOException, JDOMException
*/
final String projectFolder = "samples/mamutproject";
- final String bdvFile = "samples/datasethdf5.xml";
+ final String bdvFile = "samples/mamutproject/datasethdf5.xml";
final MamutProject project = new MamutProject( new File( projectFolder ), new File( bdvFile ) );
// final MamutProject project = new MamutProjectIO().load( "samples/mamutproject" );
final Model model = new Model();
@@ -37,28 +37,15 @@ public static void main( final String[] args ) throws IOException, JDOMException
* 1.1. Compute features.
*/
- final Context context = new Context( MamutFeatureComputerService.class );
+ // Tune context to use command-liner logger.
+ final Context context = new Context(
+ SysOutMastodonLogger.class,
+ MamutFeatureComputerService.class,
+ PrefService.class );
final MamutFeatureComputerService featureComputerService = context.getService( MamutFeatureComputerService.class );
final Set< FeatureComputer< Model > > featureComputers = new HashSet<>( featureComputerService.getFeatureComputers() );
- final ProgressListener pl = new ProgressListener()
- {
-
- @Override
- public void showStatus( final String string )
- {
- System.out.println( " - " + string );
- }
-
- @Override
- public void showProgress( final int current, final int total )
- {}
-
- @Override
- public void clearStatus()
- {}
- };
System.out.println( "Computing all features." );
- final boolean computed = featureComputerService.compute( model, model.getFeatureModel(), featureComputers, pl );
+ final boolean computed = featureComputerService.compute( model, model.getFeatureModel(), featureComputers );
if (!computed)
{
System.err.println( "Error while calculating model features." );
diff --git a/src/test/java/org/mastodon/revised/mamut/MastodonLoggerExample.java b/src/test/java/org/mastodon/revised/mamut/MastodonLoggerExample.java
new file mode 100644
index 000000000..13c918901
--- /dev/null
+++ b/src/test/java/org/mastodon/revised/mamut/MastodonLoggerExample.java
@@ -0,0 +1,97 @@
+package org.mastodon.revised.mamut;
+
+import java.awt.EventQueue;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
+
+import org.mastodon.revised.mamut.feature.MamutFeatureComputerService;
+import org.mastodon.revised.model.mamut.Model;
+import org.scijava.Context;
+import org.scijava.log.LogSource;
+
+public class MastodonLoggerExample
+{
+
+ public static void main( final String[] args ) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException
+ {
+ UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
+ EventQueue.invokeLater( new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ final Context context = new Context();
+ final WindowManager windowManager = new WindowManager( context );
+ final MamutProject project = new MamutProjectIO().load( "samples/mamutproject" );
+ windowManager.projectManager.open( project );
+
+ final MastodonMainWindow frame = new MastodonMainWindow( windowManager );
+ frame.setVisible( true );
+
+ // Send some messages.
+ final MastodonLogger logger = context.getService( DefaultMastodonLogger.class );
+ final LogSource source1 = logger.getLogSourceRoot().subSource( "the frame" );
+ final LogSource source2 = logger.getLogSourceRoot().subSource( "another one" );
+ logger.info( "Hey man! " );
+ logger.info( "Check this! ", source1 );
+
+ final Timer timer1 = new Timer();
+ final TimerTask t1 = new TimerTask()
+ {
+
+ private final AtomicInteger ai = new AtomicInteger( 0 );
+
+ @Override
+ public void run()
+ {
+ logger.setProgress( ai.getAndIncrement() / 100., source1 );
+ if ( ai.get() > 100 )
+ {
+ logger.error( "Oh no! I finished last!", source1 );
+ timer1.cancel();
+ }
+ }
+ };
+ logger.setStatus( "Doing stuff", source1 );
+ timer1.scheduleAtFixedRate( t1, 100, 50 );
+
+ final Timer timer2 = new Timer();
+ final TimerTask t2 = new TimerTask()
+ {
+
+ private final AtomicInteger ai = new AtomicInteger( 0 );
+
+ @Override
+ public void run()
+ {
+ logger.setProgress( ai.getAndIncrement() / 100., source2 );
+ if ( ai.get() > 100 )
+ {
+ logger.info( "Other stuff done too.", source2 );
+ timer2.cancel();
+ }
+ }
+ };
+ logger.setStatus( "Doing later but faster", source2 );
+ timer2.scheduleAtFixedRate( t2, 1000, 20 );
+
+ final Model model = windowManager.getAppModel().getModel();
+ final MamutFeatureComputerService computerService = context.getService( MamutFeatureComputerService.class );
+ new FeatureAndTagDialog( frame, model, computerService ).setVisible( true );
+ }
+ catch ( final Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+ } );
+ }
+
+
+}