Skip to content

Commit fbee967

Browse files
committed
Example using the GUI Mastodon logger.
1 parent 776c1ab commit fbee967

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package org.mastodon.revised.mamut;
2+
3+
import java.awt.EventQueue;
4+
import java.util.Timer;
5+
import java.util.TimerTask;
6+
import java.util.concurrent.atomic.AtomicInteger;
7+
8+
import javax.swing.UIManager;
9+
import javax.swing.UnsupportedLookAndFeelException;
10+
11+
import org.mastodon.revised.mamut.feature.MamutFeatureComputerService;
12+
import org.mastodon.revised.model.mamut.Model;
13+
import org.scijava.Context;
14+
import org.scijava.log.LogSource;
15+
16+
public class MastodonLoggerExample
17+
{
18+
19+
public static void main( final String[] args ) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException
20+
{
21+
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
22+
EventQueue.invokeLater( new Runnable()
23+
{
24+
@Override
25+
public void run()
26+
{
27+
try
28+
{
29+
final Context context = new Context();
30+
final WindowManager windowManager = new WindowManager( context );
31+
final MamutProject project = new MamutProjectIO().load( "samples/mamutproject" );
32+
windowManager.projectManager.open( project );
33+
34+
final MastodonMainWindow frame = new MastodonMainWindow( windowManager );
35+
frame.setVisible( true );
36+
37+
// Send some messages.
38+
final MastodonLogger logger = context.getService( DefaultMastodonLogger.class );
39+
final LogSource source1 = logger.getLogSourceRoot().subSource( "the frame" );
40+
final LogSource source2 = logger.getLogSourceRoot().subSource( "another one" );
41+
logger.info( "Hey man! " );
42+
logger.info( "Check this! ", source1 );
43+
44+
final Timer timer1 = new Timer();
45+
final TimerTask t1 = new TimerTask()
46+
{
47+
48+
private final AtomicInteger ai = new AtomicInteger( 0 );
49+
50+
@Override
51+
public void run()
52+
{
53+
logger.setProgress( ai.getAndIncrement() / 100., source1 );
54+
if ( ai.get() > 100 )
55+
{
56+
logger.error( "Oh no! I finished last!", source1 );
57+
timer1.cancel();
58+
}
59+
}
60+
};
61+
logger.setStatus( "Doing stuff", source1 );
62+
timer1.scheduleAtFixedRate( t1, 100, 50 );
63+
64+
final Timer timer2 = new Timer();
65+
final TimerTask t2 = new TimerTask()
66+
{
67+
68+
private final AtomicInteger ai = new AtomicInteger( 0 );
69+
70+
@Override
71+
public void run()
72+
{
73+
logger.setProgress( ai.getAndIncrement() / 100., source2 );
74+
if ( ai.get() > 100 )
75+
{
76+
logger.info( "Other stuff done too.", source2 );
77+
timer2.cancel();
78+
}
79+
}
80+
};
81+
logger.setStatus( "Doing later but faster", source2 );
82+
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 );
87+
}
88+
catch ( final Exception e )
89+
{
90+
e.printStackTrace();
91+
}
92+
}
93+
} );
94+
}
95+
96+
97+
}

0 commit comments

Comments
 (0)