diff --git a/pom.xml b/pom.xml index 8b5fcec08..ffab5c67a 100644 --- a/pom.xml +++ b/pom.xml @@ -59,6 +59,10 @@ junit test + + org.scijava + scijava-ui-swing + diff --git a/src/main/java/org/mastodon/revised/mamut/DefaultMastodonLogger.java b/src/main/java/org/mastodon/revised/mamut/DefaultMastodonLogger.java new file mode 100644 index 000000000..e8bc14994 --- /dev/null +++ b/src/main/java/org/mastodon/revised/mamut/DefaultMastodonLogger.java @@ -0,0 +1,87 @@ +package org.mastodon.revised.mamut; + +import javax.swing.JPanel; + +import org.scijava.log.LogSource; +import org.scijava.plugin.Plugin; +import org.scijava.service.AbstractService; + +/** + * A default {@link MastodonLogger} that echoes messages and progress to a + * {@link JPanel}. Suitable to be used in a GUI. + * + * @author Jean-Yves Tinevez + * + */ +@Plugin( type = DefaultMastodonLogger.class ) +public class DefaultMastodonLogger extends AbstractService implements MastodonLogger +{ + + private MastodonLogPanel mastodonLogPanel; + + @Override + public void initialize() + { + super.initialize(); + mastodonLogPanel = new MastodonLogPanel( getContext() ); + } + + public MastodonLogPanel getMastodonLogPanel() + { + return mastodonLogPanel; + } + + @Override + public LogSource getLogSourceRoot() + { + return mastodonLogPanel.getRootSource(); + } + + @Override + public void info( final String message, final LogSource source ) + { + mastodonLogPanel.info( message, source ); + } + + @Override + public void info( final String message ) + { + mastodonLogPanel.info( message ); + } + + @Override + public void error( final String message, final LogSource source ) + { + mastodonLogPanel.error( message, source ); + } + + @Override + public void error( final String message ) + { + mastodonLogPanel.error( message ); + } + + @Override + public void setStatus( final String status, final LogSource source ) + { + mastodonLogPanel.setStatus( status, source ); + } + + @Override + public void setStatus( final String status ) + { + mastodonLogPanel.setStatus( status ); + } + + @Override + public void setProgress( final double progress, final LogSource source ) + { + mastodonLogPanel.setProgress( progress, source ); + } + + @Override + public void setProgress( final double progress ) + { + mastodonLogPanel.setProgress( progress ); + } +} diff --git a/src/main/java/org/mastodon/revised/mamut/FeatureComputersPanel.java b/src/main/java/org/mastodon/revised/mamut/FeatureComputersPanel.java index 9d800850d..e60115e5a 100644 --- a/src/main/java/org/mastodon/revised/mamut/FeatureComputersPanel.java +++ b/src/main/java/org/mastodon/revised/mamut/FeatureComputersPanel.java @@ -29,7 +29,6 @@ import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; -import javax.swing.JProgressBar; import javax.swing.JScrollPane; import javax.swing.LayoutStyle.ComponentPlacement; import javax.swing.ScrollPaneConstants; @@ -43,7 +42,6 @@ import org.mastodon.revised.mamut.feature.MamutFeatureComputerService; import org.mastodon.revised.model.feature.FeatureComputer; import org.mastodon.revised.model.mamut.Model; -import org.mastodon.revised.ui.ProgressListener; import org.scijava.Context; public class FeatureComputersPanel extends JPanel @@ -64,8 +62,6 @@ public class FeatureComputersPanel extends JPanel private final Model model; - private final MyProgressBar progressBar; - private final Set< FeatureComputer< Model > > selectedComputers; private final JButton btnCompute; @@ -87,9 +83,6 @@ public FeatureComputersPanel( final MamutFeatureComputerService computerService, btnCompute = new JButton( "Compute", GO_ICON ); - progressBar = new MyProgressBar(); - progressBar.setStringPainted( true ); - lblComputationDate = new JLabel( "Last feature computation: Never." ); final JLabel lblModelModificationDate = new JLabel( "Model last modified: Unknown." ); final GroupLayout gl_panelComputation = new GroupLayout( panelComputation ); @@ -98,10 +91,7 @@ public FeatureComputersPanel( final MamutFeatureComputerService computerService, .addGroup( gl_panelComputation.createSequentialGroup() .addContainerGap() .addGroup( gl_panelComputation.createParallelGroup( Alignment.LEADING ) - .addGroup( gl_panelComputation.createSequentialGroup() - .addComponent( btnCompute ) - .addPreferredGap( ComponentPlacement.RELATED ) - .addComponent( progressBar, GroupLayout.DEFAULT_SIZE, 349, Short.MAX_VALUE ) ) + .addComponent( btnCompute ) .addComponent( lblComputationDate, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE ) .addComponent( lblModelModificationDate, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE ) ) .addContainerGap() ) ); @@ -109,9 +99,7 @@ public FeatureComputersPanel( final MamutFeatureComputerService computerService, gl_panelComputation.createParallelGroup( Alignment.LEADING ) .addGroup( gl_panelComputation.createSequentialGroup() .addContainerGap() - .addGroup( gl_panelComputation.createParallelGroup( Alignment.TRAILING, false ) - .addComponent( progressBar, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE ) - .addComponent( btnCompute, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE ) ) + .addComponent( btnCompute ) .addPreferredGap( ComponentPlacement.UNRELATED ) .addComponent( lblComputationDate ) .addComponent( lblModelModificationDate ) @@ -178,7 +166,6 @@ private synchronized void compute() if ( worker == null ) { - progressBar.setEnabled( true ); btnCompute.setText( "Cancel" ); btnCompute.setIcon( CANCEL_ICON ); btnCompute.setEnabled( true ); @@ -208,8 +195,6 @@ public void propertyChange( final PropertyChangeEvent evt ) else { worker.cancel( true ); - progressBar.clearStatus(); - progressBar.setString( "Canceled." ); enableComponents( FeatureComputersPanel.this, true ); worker = null; btnCompute.setText( "Compute" ); @@ -281,42 +266,11 @@ private class FeatureComputerWorker extends SwingWorker< Boolean, String > @Override protected Boolean doInBackground() throws Exception { - final boolean ok = computerService.compute( model, model.getFeatureModel(), selectedComputers, progressBar ); + final boolean ok = computerService.compute( model, model.getFeatureModel(), selectedComputers ); return Boolean.valueOf( ok ); } } - private class MyProgressBar extends JProgressBar implements ProgressListener - { - - private static final long serialVersionUID = 1L; - - public MyProgressBar() - { - super(); - setStringPainted( true ); - } - - @Override - public void showStatus( final String string ) - { - setString( string ); - } - - @Override - public void showProgress( final int current, final int total ) - { - setValue( ( int ) ( 100. * current / total ) ); - } - - @Override - public void clearStatus() - { - setString( "" ); - setValue( 0 ); - } - } - private static final void enableComponents( final Container container, final boolean enable ) { final Component[] components = container.getComponents(); diff --git a/src/main/java/org/mastodon/revised/mamut/MainButtonPanel.java b/src/main/java/org/mastodon/revised/mamut/MainButtonPanel.java new file mode 100644 index 000000000..72e9c6b06 --- /dev/null +++ b/src/main/java/org/mastodon/revised/mamut/MainButtonPanel.java @@ -0,0 +1,255 @@ +package org.mastodon.revised.mamut; + +import static org.mastodon.revised.mamut.MastodonIcons.BDV_ICON; +import static org.mastodon.revised.mamut.MastodonIcons.FEATURE_ICON; +import static org.mastodon.revised.mamut.MastodonIcons.MAMUT_ICON; +import static org.mastodon.revised.mamut.MastodonIcons.SAVEAS_ICON; +import static org.mastodon.revised.mamut.MastodonIcons.SAVE_ICON; +import static org.mastodon.revised.mamut.MastodonIcons.TABLE_ICON; +import static org.mastodon.revised.mamut.MastodonIcons.TAG_ICON; +import static org.mastodon.revised.mamut.MastodonIcons.TRACKSCHEME_ICON; + +import java.awt.Font; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; + +import javax.swing.ActionMap; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JSeparator; + +import org.scijava.ui.behaviour.util.RunnableAction; + +public class MainButtonPanel extends JPanel +{ + + private static final long serialVersionUID = 1L; + + public MainButtonPanel(final WindowManager windowManager) + { + final ActionMap actionMap = windowManager.getGlobalAppActions().getActionMap(); + + final MastodonLogger logger = windowManager.getContext().getService( MastodonLogger.class ); + final RunnableAction notImplementedAction = new RunnableAction( + "Notify not implemeted", () -> logger.error( "Not implemented yet." ) ); + + final GridBagLayout gridBagLayout = new GridBagLayout(); + gridBagLayout.columnWidths = new int[]{0, 0, 0}; + gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + gridBagLayout.columnWeights = new double[]{1.0, 0.0, Double.MIN_VALUE}; + gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; + setLayout(gridBagLayout); + + final JLabel lblViews = new JLabel("Windows."); + lblViews.setFont(lblViews.getFont().deriveFont(lblViews.getFont().getStyle() | Font.BOLD)); + final GridBagConstraints gbc_lblViews = new GridBagConstraints(); + gbc_lblViews.gridwidth = 2; + gbc_lblViews.insets = new Insets(0, 0, 5, 0); + gbc_lblViews.anchor = GridBagConstraints.WEST; + gbc_lblViews.gridx = 0; + gbc_lblViews.gridy = 2; + add(lblViews, gbc_lblViews); + + final JLabel lblBigDataViewer = new JLabel("Big Data Viewer"); + final GridBagConstraints gbc_lblBigDataViewer = new GridBagConstraints(); + gbc_lblBigDataViewer.anchor = GridBagConstraints.EAST; + gbc_lblBigDataViewer.insets = new Insets(0, 0, 5, 5); + gbc_lblBigDataViewer.gridx = 0; + gbc_lblBigDataViewer.gridy = 3; + add(lblBigDataViewer, gbc_lblBigDataViewer); + + final JButton btnBdv = new JButton(); + btnBdv.setAction( actionMap.get( WindowManager.NEW_BDV_VIEW ) ); + btnBdv.setIcon( BDV_ICON ); + btnBdv.setText( "" ); + final GridBagConstraints gbc_btnBdv = new GridBagConstraints(); + gbc_btnBdv.insets = new Insets(0, 0, 5, 0); + gbc_btnBdv.gridx = 1; + gbc_btnBdv.gridy = 3; + add(btnBdv, gbc_btnBdv); + + final JLabel lblTrackscheme = new JLabel("TrackScheme"); + final GridBagConstraints gbc_lblTrackscheme = new GridBagConstraints(); + gbc_lblTrackscheme.anchor = GridBagConstraints.EAST; + gbc_lblTrackscheme.insets = new Insets(0, 0, 5, 5); + gbc_lblTrackscheme.gridx = 0; + gbc_lblTrackscheme.gridy = 4; + add(lblTrackscheme, gbc_lblTrackscheme); + + final JButton btnTs = new JButton(); + btnTs.setAction( actionMap.get( WindowManager.NEW_TRACKSCHEME_VIEW ) ); + btnTs.setIcon( TRACKSCHEME_ICON ); + btnTs.setText( "" ); + final GridBagConstraints gbc_btnTs = new GridBagConstraints(); + gbc_btnTs.insets = new Insets(0, 0, 5, 0); + gbc_btnTs.gridx = 1; + gbc_btnTs.gridy = 4; + add(btnTs, gbc_btnTs); + + final JLabel lblTable = new JLabel("Table"); + final GridBagConstraints gbc_lblTable = new GridBagConstraints(); + gbc_lblTable.anchor = GridBagConstraints.EAST; + gbc_lblTable.insets = new Insets(0, 0, 5, 5); + gbc_lblTable.gridx = 0; + gbc_lblTable.gridy = 5; + add(lblTable, gbc_lblTable); + + final JButton btnTa = new JButton(); + btnTa.setAction( notImplementedAction ); + btnTa.setText( "" ); + btnTa.setIcon( TABLE_ICON ); + final GridBagConstraints gbc_btnTa = new GridBagConstraints(); + gbc_btnTa.insets = new Insets(0, 0, 5, 0); + gbc_btnTa.gridx = 1; + gbc_btnTa.gridy = 5; + add(btnTa, gbc_btnTa); + + final JSeparator separator_1 = new JSeparator(); + final GridBagConstraints gbc_separator_1 = new GridBagConstraints(); + gbc_separator_1.insets = new Insets(0, 0, 5, 0); + gbc_separator_1.fill = GridBagConstraints.HORIZONTAL; + gbc_separator_1.gridwidth = 2; + gbc_separator_1.gridx = 0; + gbc_separator_1.gridy = 6; + add(separator_1, gbc_separator_1); + + final JLabel lblTags = new JLabel("Tags."); + lblTags.setFont(lblTags.getFont().deriveFont(lblTags.getFont().getStyle() | Font.BOLD)); + final GridBagConstraints gbc_lblTags = new GridBagConstraints(); + gbc_lblTags.insets = new Insets(0, 0, 5, 0); + gbc_lblTags.gridwidth = 2; + gbc_lblTags.anchor = GridBagConstraints.WEST; + gbc_lblTags.gridx = 0; + gbc_lblTags.gridy = 7; + add(lblTags, gbc_lblTags); + + final JLabel lblDefineTags = new JLabel("Define tags"); + final GridBagConstraints gbc_lblDefineTags = new GridBagConstraints(); + gbc_lblDefineTags.anchor = GridBagConstraints.EAST; + gbc_lblDefineTags.insets = new Insets(0, 0, 5, 5); + gbc_lblDefineTags.gridx = 0; + gbc_lblDefineTags.gridy = 8; + add(lblDefineTags, gbc_lblDefineTags); + + final JButton btnTg = new JButton(); + btnTg.setAction( actionMap.get( WindowManager.TAGSETS_DIALOG ) ); + btnTg.setIcon( TAG_ICON ); + btnTg.setText( "" ); + final GridBagConstraints gbc_btnTg = new GridBagConstraints(); + gbc_btnTg.insets = new Insets(0, 0, 5, 0); + gbc_btnTg.gridx = 1; + gbc_btnTg.gridy = 8; + add(btnTg, gbc_btnTg); + + final JSeparator separator_2 = new JSeparator(); + final GridBagConstraints gbc_separator_2 = new GridBagConstraints(); + gbc_separator_2.insets = new Insets(0, 0, 5, 0); + gbc_separator_2.fill = GridBagConstraints.HORIZONTAL; + gbc_separator_2.gridwidth = 2; + gbc_separator_2.gridx = 0; + gbc_separator_2.gridy = 9; + add(separator_2, gbc_separator_2); + + final JLabel lblFeatures = new JLabel("Features."); + lblFeatures.setFont(lblFeatures.getFont().deriveFont(lblFeatures.getFont().getStyle() | Font.BOLD)); + final GridBagConstraints gbc_lblFeatures = new GridBagConstraints(); + gbc_lblFeatures.insets = new Insets(0, 0, 5, 0); + gbc_lblFeatures.gridwidth = 2; + gbc_lblFeatures.anchor = GridBagConstraints.WEST; + gbc_lblFeatures.gridx = 0; + gbc_lblFeatures.gridy = 10; + add(lblFeatures, gbc_lblFeatures); + + final JLabel lblComputeFeatures = new JLabel("Compute features"); + final GridBagConstraints gbc_lblComputeFeatures = new GridBagConstraints(); + gbc_lblComputeFeatures.anchor = GridBagConstraints.EAST; + gbc_lblComputeFeatures.insets = new Insets(0, 0, 5, 5); + gbc_lblComputeFeatures.gridx = 0; + gbc_lblComputeFeatures.gridy = 11; + add(lblComputeFeatures, gbc_lblComputeFeatures); + + final JButton btnFc = new JButton(); + btnFc.setAction( notImplementedAction ); + btnFc.setText( "" ); + btnFc.setIcon( FEATURE_ICON ); + final GridBagConstraints gbc_btnFc = new GridBagConstraints(); + gbc_btnFc.insets = new Insets(0, 0, 5, 0); + gbc_btnFc.gridx = 1; + gbc_btnFc.gridy = 11; + add(btnFc, gbc_btnFc); + + final JSeparator separator_3 = new JSeparator(); + final GridBagConstraints gbc_separator_3 = new GridBagConstraints(); + gbc_separator_3.insets = new Insets(0, 0, 5, 0); + gbc_separator_3.fill = GridBagConstraints.HORIZONTAL; + gbc_separator_3.gridwidth = 2; + gbc_separator_3.gridx = 0; + gbc_separator_3.gridy = 12; + add(separator_3, gbc_separator_3); + + final JLabel lblSaving = new JLabel("Saving."); + lblSaving.setFont(lblSaving.getFont().deriveFont(lblSaving.getFont().getStyle() | Font.BOLD)); + final GridBagConstraints gbc_lblSaving = new GridBagConstraints(); + gbc_lblSaving.insets = new Insets(0, 0, 5, 0); + gbc_lblSaving.gridwidth = 2; + gbc_lblSaving.anchor = GridBagConstraints.WEST; + gbc_lblSaving.gridx = 0; + gbc_lblSaving.gridy = 13; + add(lblSaving, gbc_lblSaving); + + final JLabel lblSave = new JLabel("Save"); + final GridBagConstraints gbc_lblSave = new GridBagConstraints(); + gbc_lblSave.anchor = GridBagConstraints.EAST; + gbc_lblSave.insets = new Insets(0, 0, 5, 5); + gbc_lblSave.gridx = 0; + gbc_lblSave.gridy = 14; + add(lblSave, gbc_lblSave); + + final JButton btnS = new JButton(); + btnS.setAction( notImplementedAction ); + btnS.setText( "" ); + btnS.setIcon( SAVE_ICON ); + final GridBagConstraints gbc_btnS = new GridBagConstraints(); + gbc_btnS.insets = new Insets(0, 0, 5, 0); + gbc_btnS.gridx = 1; + gbc_btnS.gridy = 14; + add(btnS, gbc_btnS); + + final JLabel lblSaveAs = new JLabel("Save as..."); + final GridBagConstraints gbc_lblSaveAs = new GridBagConstraints(); + gbc_lblSaveAs.anchor = GridBagConstraints.EAST; + gbc_lblSaveAs.insets = new Insets(0, 0, 5, 5); + gbc_lblSaveAs.gridx = 0; + gbc_lblSaveAs.gridy = 15; + add(lblSaveAs, gbc_lblSaveAs); + + final JButton btnSa = new JButton(); + btnSa.setAction( actionMap.get( ProjectManager.SAVE_PROJECT ) ); + btnSa.setIcon( SAVEAS_ICON ); + btnSa.setText( "" ); + final GridBagConstraints gbc_btnSa = new GridBagConstraints(); + gbc_btnSa.insets = new Insets(0, 0, 5, 0); + gbc_btnSa.gridx = 1; + gbc_btnSa.gridy = 15; + add(btnSa, gbc_btnSa); + + final JLabel lblExportToMamut = new JLabel("Export to MaMuT"); + final GridBagConstraints gbc_lblExportToMamut = new GridBagConstraints(); + gbc_lblExportToMamut.anchor = GridBagConstraints.EAST; + gbc_lblExportToMamut.insets = new Insets(0, 0, 0, 5); + gbc_lblExportToMamut.gridx = 0; + gbc_lblExportToMamut.gridy = 16; + add(lblExportToMamut, gbc_lblExportToMamut); + + final JButton btnEm = new JButton(); + btnEm.setAction( actionMap.get( ProjectManager.EXPORT_MAMUT ) ); + btnEm.setText( "" ); + btnEm.setIcon( MAMUT_ICON ); + final GridBagConstraints gbc_btnEm = new GridBagConstraints(); + gbc_btnEm.gridx = 1; + gbc_btnEm.gridy = 16; + add( btnEm, gbc_btnEm ); + } +} diff --git a/src/main/java/org/mastodon/revised/mamut/MastodonIcons.java b/src/main/java/org/mastodon/revised/mamut/MastodonIcons.java new file mode 100644 index 000000000..d9a4a9874 --- /dev/null +++ b/src/main/java/org/mastodon/revised/mamut/MastodonIcons.java @@ -0,0 +1,28 @@ +package org.mastodon.revised.mamut; + +import javax.swing.ImageIcon; + +public class MastodonIcons +{ + + public static final ImageIcon TITLE_ICON = new ImageIcon( Mastodon.class.getResource( "Mastodon-logo-01-128x128.png" ) ); + + public static final ImageIcon BDV_ICON = new ImageIcon( Mastodon.class.getResource( "BDV-logo-32x32.png" ) ); + + public static final ImageIcon TRACKSCHEME_ICON = new ImageIcon( Mastodon.class.getResource( "TrackScheme-logo2-32x32.png" ) ); + + public static final ImageIcon TABLE_ICON = new ImageIcon( Mastodon.class.getResource( "Table-icon2-32x32.png" ) ); + + public static final ImageIcon TAG_ICON = new ImageIcon( Mastodon.class.getResource( "Tag-icon-32x32.png" ) ); + + public static final ImageIcon FEATURE_ICON = new ImageIcon( Mastodon.class.getResource( "Feature-icon-32x32.png" ) ); + + public static final ImageIcon SAVE_ICON = new ImageIcon( Mastodon.class.getResource( "Save-icon-32x32.png" ) ); + + public static final ImageIcon SAVEAS_ICON = new ImageIcon( Mastodon.class.getResource( "SaveAs-icon-32x32.png" ) ); + + public static final ImageIcon MAMUT_ICON = new ImageIcon( Mastodon.class.getResource( "MaMuT-icon-32x32.png" ) ); + + private MastodonIcons() + {} +} diff --git a/src/main/java/org/mastodon/revised/mamut/MastodonLogPanel.java b/src/main/java/org/mastodon/revised/mamut/MastodonLogPanel.java new file mode 100644 index 000000000..c6df6b1cd --- /dev/null +++ b/src/main/java/org/mastodon/revised/mamut/MastodonLogPanel.java @@ -0,0 +1,132 @@ +package org.mastodon.revised.mamut; + +import java.awt.BorderLayout; +import java.util.HashMap; +import java.util.Map; + +import javax.swing.BoxLayout; +import javax.swing.JPanel; +import javax.swing.JProgressBar; + +import org.scijava.Context; +import org.scijava.log.LogLevel; +import org.scijava.log.LogMessage; +import org.scijava.log.LogSource; +import org.scijava.ui.swing.console.LoggingPanel; + +public class MastodonLogPanel extends JPanel +{ + + private static final long serialVersionUID = 1L; + + private final LogSource root = LogSource.newRoot(); + + private final LogSource unknownSource = root.subSource( "Unkown source" ); + + private static final String PREF_KEY = "MastodonLoggerPreferencesKey"; + + private final Context context; + + private final LoggingPanel loggingPanel; + + private final JPanel panelProgressBars; + + private final Map< LogSource, JProgressBar > progressBars; + + public MastodonLogPanel(final Context context) + { + this.context = ( null == context ) ? new Context() : context; + setLayout( new BorderLayout( 5, 5 ) ); + + panelProgressBars = new JPanel(); + add( panelProgressBars, BorderLayout.NORTH ); + panelProgressBars.setLayout( new BoxLayout( panelProgressBars, BoxLayout.PAGE_AXIS ) ); + + loggingPanel = new LoggingPanel( this.context, PREF_KEY ); + loggingPanel.setOpaque( false ); + add( loggingPanel, BorderLayout.CENTER ); + + this.progressBars = new HashMap<>(); + } + + public LogSource getRootSource() + { + return root; + } + + protected void log( final String msg, final int level, final LogSource source ) + { + loggingPanel.messageLogged( new LogMessage( source, level, msg ) ); + } + + public void info( final String msg, final LogSource source ) + { + log( msg, LogLevel.INFO, source ); + } + + public void info( final String msg ) + { + info( msg, unknownSource ); + } + + public void error( final String msg, final LogSource source ) + { + log( msg, LogLevel.ERROR, source ); + } + + public void error( final String msg ) + { + error( msg, unknownSource ); + } + + public void setStatus( final String status, final LogSource source ) + { + final JProgressBar pb = getProgressBar( source ); + pb.setString( status ); + } + + public void setStatus( final String status ) + { + setStatus( status, unknownSource ); + } + + public void setProgress( final double progress, final LogSource source ) + { + if ( progress >= 1 ) + { + removeProgressBar( source ); + return; + } + final JProgressBar pb = getProgressBar( source ); + pb.setValue( ( int ) ( 100 * progress ) ); + } + + public void setProgress( final double progress ) + { + setProgress( progress, unknownSource ); + } + + private void removeProgressBar( final LogSource source ) + { + final JProgressBar pb = progressBars.remove( source ); + if ( null == pb ) + return; + + panelProgressBars.remove( pb ); + revalidate(); + } + + private JProgressBar getProgressBar( final LogSource source ) + { + JProgressBar pg = progressBars.get( source ); + if (null == pg) + { + pg = new JProgressBar( 0, 100 ); + pg.setStringPainted( true ); + panelProgressBars.add( pg ); + revalidate(); + progressBars.put( source, pg ); + } + return pg; + } +} diff --git a/src/main/java/org/mastodon/revised/mamut/MastodonLogger.java b/src/main/java/org/mastodon/revised/mamut/MastodonLogger.java new file mode 100644 index 000000000..d685e2fde --- /dev/null +++ b/src/main/java/org/mastodon/revised/mamut/MastodonLogger.java @@ -0,0 +1,107 @@ +package org.mastodon.revised.mamut; + +import org.scijava.log.LogSource; +import org.scijava.service.SciJavaService; + +/** + * Mastodon logging service. + *

+ * 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(); + } + } + } ); + } + + +}