Skip to content

Commit 026292d

Browse files
committed
Use MastodonLogger to report progress in FeatureComputer panel.
Discard entirely ProgressListener which was not used anywhere else.
1 parent 7ff36e6 commit 026292d

7 files changed

Lines changed: 47 additions & 107 deletions

File tree

src/main/java/org/mastodon/revised/mamut/FeatureComputersPanel.java

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import javax.swing.JFrame;
3030
import javax.swing.JLabel;
3131
import javax.swing.JPanel;
32-
import javax.swing.JProgressBar;
3332
import javax.swing.JScrollPane;
3433
import javax.swing.LayoutStyle.ComponentPlacement;
3534
import javax.swing.ScrollPaneConstants;
@@ -43,7 +42,6 @@
4342
import org.mastodon.revised.mamut.feature.MamutFeatureComputerService;
4443
import org.mastodon.revised.model.feature.FeatureComputer;
4544
import org.mastodon.revised.model.mamut.Model;
46-
import org.mastodon.revised.ui.ProgressListener;
4745
import org.scijava.Context;
4846

4947
public class FeatureComputersPanel extends JPanel
@@ -64,8 +62,6 @@ public class FeatureComputersPanel extends JPanel
6462

6563
private final Model model;
6664

67-
private final MyProgressBar progressBar;
68-
6965
private final Set< FeatureComputer< Model > > selectedComputers;
7066

7167
private final JButton btnCompute;
@@ -87,9 +83,6 @@ public FeatureComputersPanel( final MamutFeatureComputerService computerService,
8783

8884
btnCompute = new JButton( "Compute", GO_ICON );
8985

90-
progressBar = new MyProgressBar();
91-
progressBar.setStringPainted( true );
92-
9386
lblComputationDate = new JLabel( "Last feature computation: Never." );
9487
final JLabel lblModelModificationDate = new JLabel( "Model last modified: Unknown." );
9588
final GroupLayout gl_panelComputation = new GroupLayout( panelComputation );
@@ -98,20 +91,15 @@ public FeatureComputersPanel( final MamutFeatureComputerService computerService,
9891
.addGroup( gl_panelComputation.createSequentialGroup()
9992
.addContainerGap()
10093
.addGroup( gl_panelComputation.createParallelGroup( Alignment.LEADING )
101-
.addGroup( gl_panelComputation.createSequentialGroup()
102-
.addComponent( btnCompute )
103-
.addPreferredGap( ComponentPlacement.RELATED )
104-
.addComponent( progressBar, GroupLayout.DEFAULT_SIZE, 349, Short.MAX_VALUE ) )
94+
.addComponent( btnCompute )
10595
.addComponent( lblComputationDate, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE )
10696
.addComponent( lblModelModificationDate, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE ) )
10797
.addContainerGap() ) );
10898
gl_panelComputation.setVerticalGroup(
10999
gl_panelComputation.createParallelGroup( Alignment.LEADING )
110100
.addGroup( gl_panelComputation.createSequentialGroup()
111101
.addContainerGap()
112-
.addGroup( gl_panelComputation.createParallelGroup( Alignment.TRAILING, false )
113-
.addComponent( progressBar, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE )
114-
.addComponent( btnCompute, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE ) )
102+
.addComponent( btnCompute )
115103
.addPreferredGap( ComponentPlacement.UNRELATED )
116104
.addComponent( lblComputationDate )
117105
.addComponent( lblModelModificationDate )
@@ -178,7 +166,6 @@ private synchronized void compute()
178166

179167
if ( worker == null )
180168
{
181-
progressBar.setEnabled( true );
182169
btnCompute.setText( "Cancel" );
183170
btnCompute.setIcon( CANCEL_ICON );
184171
btnCompute.setEnabled( true );
@@ -208,8 +195,6 @@ public void propertyChange( final PropertyChangeEvent evt )
208195
else
209196
{
210197
worker.cancel( true );
211-
progressBar.clearStatus();
212-
progressBar.setString( "Canceled." );
213198
enableComponents( FeatureComputersPanel.this, true );
214199
worker = null;
215200
btnCompute.setText( "Compute" );
@@ -281,42 +266,11 @@ private class FeatureComputerWorker extends SwingWorker< Boolean, String >
281266
@Override
282267
protected Boolean doInBackground() throws Exception
283268
{
284-
final boolean ok = computerService.compute( model, model.getFeatureModel(), selectedComputers, progressBar );
269+
final boolean ok = computerService.compute( model, model.getFeatureModel(), selectedComputers );
285270
return Boolean.valueOf( ok );
286271
}
287272
}
288273

289-
private class MyProgressBar extends JProgressBar implements ProgressListener
290-
{
291-
292-
private static final long serialVersionUID = 1L;
293-
294-
public MyProgressBar()
295-
{
296-
super();
297-
setStringPainted( true );
298-
}
299-
300-
@Override
301-
public void showStatus( final String string )
302-
{
303-
setString( string );
304-
}
305-
306-
@Override
307-
public void showProgress( final int current, final int total )
308-
{
309-
setValue( ( int ) ( 100. * current / total ) );
310-
}
311-
312-
@Override
313-
public void clearStatus()
314-
{
315-
setString( "" );
316-
setValue( 0 );
317-
}
318-
}
319-
320274
private static final void enableComponents( final Container container, final boolean enable )
321275
{
322276
final Component[] components = container.getComponents();

src/main/java/org/mastodon/revised/mamut/feature/DefaultMamutFeatureComputerService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class DefaultMamutFeatureComputerService extends AbstractFeatureComputerS
1010
@Override
1111
public void initialize()
1212
{
13+
super.initialize();
1314
initializeFeatureComputers( SpotFeatureComputer.class );
1415
initializeFeatureComputers( LinkFeatureComputer.class );
1516
}

src/main/java/org/mastodon/revised/model/feature/AbstractFeatureComputerService.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
import org.mastodon.graph.object.ObjectEdge;
1414
import org.mastodon.graph.object.ObjectGraph;
1515
import org.mastodon.graph.object.ObjectVertex;
16+
import org.mastodon.revised.mamut.MastodonLogger;
1617
import org.mastodon.revised.model.AbstractModel;
17-
import org.mastodon.revised.ui.ProgressListener;
1818
import org.scijava.InstantiableException;
19-
import org.scijava.app.StatusService;
20-
import org.scijava.log.LogService;
19+
import org.scijava.log.LogSource;
2120
import org.scijava.plugin.Parameter;
2221
import org.scijava.plugin.PluginInfo;
2322
import org.scijava.plugin.PluginService;
@@ -30,28 +29,34 @@ public abstract class AbstractFeatureComputerService< AM extends AbstractModel<
3029
private PluginService pluginService;
3130

3231
@Parameter
33-
private LogService logService;
34-
35-
@Parameter
36-
private StatusService status;
32+
private MastodonLogger logger;
3733

3834
/**
3935
* Feature computers of any type, mapped by their key, for dependency
4036
* management.
4137
*/
4238
private final Map< String, FeatureComputer< AM > > featureComputers = new HashMap<>();
4339

40+
private LogSource logSource;
41+
42+
@Override
43+
public void initialize()
44+
{
45+
super.initialize();
46+
logSource = logger.getLogSourceRoot().subSource( "Feature computer" );
47+
}
48+
4449
@Override
45-
public boolean compute( final AM model, final FeatureModel featureModel, final Set< FeatureComputer< AM > > computers, final ProgressListener progressListener )
50+
public boolean compute( final AM model, final FeatureModel featureModel, final Set< FeatureComputer< AM > > computers )
4651
{
4752
final ObjectGraph< FeatureComputer< AM > > dependencyGraph = getDependencyGraph( computers );
4853
final TopologicalSort< ObjectVertex< FeatureComputer< AM > >, ObjectEdge< FeatureComputer< AM > > > sorter = new TopologicalSort<>( dependencyGraph );
4954

5055
if ( sorter.hasFailed() )
5156
{
52-
logService.error( "Could not compute features using " + computers +
53-
" as they have a circular dependency." );
54-
progressListener.showStatus( "Circular dependency!" );
57+
logger.error( "Could not compute features using " + computers +
58+
" as they have a circular dependency.", logSource );
59+
logger.setStatus( "Circular dependency!", logSource );
5560
return false;
5661
}
5762

@@ -62,16 +67,16 @@ public boolean compute( final AM model, final FeatureModel featureModel, final S
6267
for ( final ObjectVertex< FeatureComputer< AM > > v : sorter.get() )
6368
{
6469
final FeatureComputer< AM > computer = v.getContent();
65-
progressListener.showStatus( computer.getKey() );
70+
logger.setStatus( computer.getKey(), logSource );
6671
final Feature< ?, ? > feature = computer.compute( model );
6772
featureModel.declareFeature( feature );
6873

69-
progressListener.showProgress( progress++, computers.size() );
74+
logger.setProgress( progress++ / ( double ) computers.size(), logSource );
7075
}
7176

7277
final long end = System.currentTimeMillis();
73-
progressListener.clearStatus();
74-
progressListener.showStatus( String.format( "Done in %.1f s.", ( end - start ) / 1000. ) );
78+
logger.setProgress( 1., logSource );
79+
logger.info( String.format( "Done in %.1f s.", ( end - start ) / 1000. ), logSource );
7580

7681
return true;
7782
}
@@ -148,14 +153,14 @@ private final ObjectVertex< FeatureComputer< AM > > addDepVertex(
148153
final FeatureComputer< AM > computerDep = featureComputers.get( dep );
149154
if ( null == computerDep )
150155
{
151-
logService.error( "Cannot add feature computer named " + dep + " as it is not registered." );
156+
logger.error( "Cannot add feature computer named " + dep + " as it is not registered.", logSource );
152157
return null;
153158
}
154159

155160
final ObjectVertex< FeatureComputer< AM > > target = addDepVertex( computerDep, computerGraph, vref2 );
156161
if ( null == target )
157162
{
158-
logService.error( "Removing feature computer named " + computer + " as some of its dependencies could not be resolved." );
163+
logger.error( "Removing feature computer named " + computer + " as some of its dependencies could not be resolved.", logSource );
159164
computerGraph.remove( source );
160165
break;
161166
}
@@ -180,8 +185,8 @@ protected < K extends FeatureComputer< AM > > void initializeFeatureComputers( f
180185
final String name = info.getName();
181186
if ( featureComputers.keySet().contains( name ) )
182187
{
183-
logService.error( "Cannot register feature computer with name " + name + " of class " + cl +
184-
". There is already a feature computer registered with this name." );
188+
logger.error( "Cannot register feature computer with name " + name + " of class " + cl +
189+
". There is already a feature computer registered with this name.", logSource );
185190
continue;
186191
}
187192

@@ -192,8 +197,8 @@ protected < K extends FeatureComputer< AM > > void initializeFeatureComputers( f
192197
}
193198
catch ( final InstantiableException e )
194199
{
195-
logService.error( "Could not instantiate computer with name " + name + " of class " + cl +
196-
":\n" + e.getMessage() );
200+
logger.error( "Could not instantiate computer with name " + name + " of class " + cl +
201+
":\n" + e.getMessage(), logSource );
197202
e.printStackTrace();
198203
}
199204
}

src/main/java/org/mastodon/revised/model/feature/FeatureComputerService.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.Set;
55

66
import org.mastodon.revised.model.AbstractModel;
7-
import org.mastodon.revised.ui.ProgressListener;
87
import org.scijava.service.SciJavaService;
98

109
/**
@@ -37,10 +36,8 @@ public interface FeatureComputerService< AM extends AbstractModel< ?, ?, ? > > e
3736
* @param selectedComputers
3837
* what computers to run. The computers in the specified set must
3938
* have been discovered by this instance.
40-
* @param progressListener
41-
* a progress listener, used to report calculation progress.
4239
* @return <code>true</code> if computation terminated successfully.
4340
*/
44-
public boolean compute( AM model, FeatureModel featureModel, Set< FeatureComputer< AM > > selectedComputers, ProgressListener progressListener );
41+
public boolean compute( AM model, FeatureModel featureModel, Set< FeatureComputer< AM > > selectedComputers );
4542

4643
}

src/main/java/org/mastodon/revised/ui/ProgressListener.java

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/test/java/org/mastodon/revised/mamut/MaMuTExportExample.java

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
import org.jdom2.JDOMException;
99
import org.mastodon.revised.mamut.feature.MamutFeatureComputerService;
1010
import org.mastodon.revised.model.feature.FeatureComputer;
11-
import org.mastodon.revised.model.mamut.ModelUtils;
1211
import org.mastodon.revised.model.mamut.Model;
12+
import org.mastodon.revised.model.mamut.ModelUtils;
1313
import org.mastodon.revised.model.mamut.trackmate.MamutExporter;
1414
import org.mastodon.revised.model.mamut.trackmate.TrackMateImporter;
15-
import org.mastodon.revised.ui.ProgressListener;
1615
import org.scijava.Context;
16+
import org.scijava.prefs.PrefService;
1717

1818
import mpicbg.spim.data.SpimDataException;
1919

@@ -27,7 +27,7 @@ public static void main( final String[] args ) throws IOException, JDOMException
2727
*/
2828

2929
final String projectFolder = "samples/mamutproject";
30-
final String bdvFile = "samples/datasethdf5.xml";
30+
final String bdvFile = "samples/mamutproject/datasethdf5.xml";
3131
final MamutProject project = new MamutProject( new File( projectFolder ), new File( bdvFile ) );
3232
// final MamutProject project = new MamutProjectIO().load( "samples/mamutproject" );
3333
final Model model = new Model();
@@ -37,28 +37,15 @@ public static void main( final String[] args ) throws IOException, JDOMException
3737
* 1.1. Compute features.
3838
*/
3939

40-
final Context context = new Context( MamutFeatureComputerService.class );
40+
// Tune context to use command-liner logger.
41+
final Context context = new Context(
42+
SysOutMastodonLogger.class,
43+
MamutFeatureComputerService.class,
44+
PrefService.class );
4145
final MamutFeatureComputerService featureComputerService = context.getService( MamutFeatureComputerService.class );
4246
final Set< FeatureComputer< Model > > featureComputers = new HashSet<>( featureComputerService.getFeatureComputers() );
43-
final ProgressListener pl = new ProgressListener()
44-
{
45-
46-
@Override
47-
public void showStatus( final String string )
48-
{
49-
System.out.println( " - " + string );
50-
}
51-
52-
@Override
53-
public void showProgress( final int current, final int total )
54-
{}
55-
56-
@Override
57-
public void clearStatus()
58-
{}
59-
};
6047
System.out.println( "Computing all features." );
61-
final boolean computed = featureComputerService.compute( model, model.getFeatureModel(), featureComputers, pl );
48+
final boolean computed = featureComputerService.compute( model, model.getFeatureModel(), featureComputers );
6249
if (!computed)
6350
{
6451
System.err.println( "Error while calculating model features." );

src/test/java/org/mastodon/revised/mamut/MastodonLoggerExample.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import javax.swing.UIManager;
99
import javax.swing.UnsupportedLookAndFeelException;
1010

11+
import org.mastodon.revised.mamut.feature.MamutFeatureComputerService;
12+
import org.mastodon.revised.model.mamut.Model;
1113
import org.scijava.Context;
1214
import org.scijava.log.LogSource;
1315

@@ -33,7 +35,7 @@ public void run()
3335
frame.setVisible( true );
3436

3537
// Send some messages.
36-
final MastodonLogger logger = context.getService( MastodonLogger.class );
38+
final MastodonLogger logger = context.getService( DefaultMastodonLogger.class );
3739
final LogSource source1 = logger.getLogSourceRoot().subSource( "the frame" );
3840
final LogSource source2 = logger.getLogSourceRoot().subSource( "another one" );
3941
logger.info( "Hey man! " );
@@ -78,6 +80,10 @@ public void run()
7880
};
7981
logger.setStatus( "Doing later but faster", source2 );
8082
timer2.scheduleAtFixedRate( t2, 1000, 20 );
83+
84+
final Model model = windowManager.getAppModel().getModel();
85+
final MamutFeatureComputerService computerService = context.getService( MamutFeatureComputerService.class );
86+
new FeatureAndTagDialog( frame, model, computerService ).setVisible( true );
8187
}
8288
catch ( final Exception e )
8389
{

0 commit comments

Comments
 (0)