Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework the Main window and Logging. #58

Draft
wants to merge 10 commits into
base: master-before-switch
Choose a base branch
from
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scijava</groupId>
<artifactId>scijava-ui-swing</artifactId>
</dependency>
</dependencies>

<mailingLists>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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 );
Expand All @@ -98,20 +91,15 @@ 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() ) );
gl_panelComputation.setVerticalGroup(
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 )
Expand Down Expand Up @@ -178,7 +166,6 @@ private synchronized void compute()

if ( worker == null )
{
progressBar.setEnabled( true );
btnCompute.setText( "Cancel" );
btnCompute.setIcon( CANCEL_ICON );
btnCompute.setEnabled( true );
Expand Down Expand Up @@ -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" );
Expand Down Expand Up @@ -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();
Expand Down
Loading