package org.mastodon.trackmate.ui.wizard;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Locale;

import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.WindowConstants;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.StyledDocument;

import org.mastodon.detection.DetectionUtil;
import org.mastodon.revised.mamut.MainWindow;
import org.mastodon.revised.mamut.MamutProject;
import org.mastodon.revised.mamut.WindowManager;
import org.mastodon.trackmate.Settings;
import org.mastodon.trackmate.TrackMate;
import org.scijava.Context;
import org.scijava.plugin.Parameter;

import bdv.viewer.SourceAndConverter;
import mpicbg.spim.data.SpimDataException;

public class Wizard
{

	@Parameter
	private Context context;

	private final JFrame frame;

	private final WizardLogService wizardLogService;

	public Wizard( final StyledDocument log )
	{
		this.frame = new JFrame();
		this.wizardLogService = new WizardLogService( log );
	}

	public Wizard()
	{
		this( new DefaultStyledDocument() );
	}

	public WizardLogService getLogService()
	{
		return wizardLogService;
	}

	public void show( final WizardSequence sequence, final String title )
	{
		context.inject( wizardLogService );
		final WizardController controller = new WizardController( sequence, wizardLogService );
		frame.getContentPane().removeAll();
		frame.getContentPane().add( controller.getWizardPanel() );
		frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
		frame.setSize( 300, 600 );
		frame.setTitle( title );
		controller.init();
		frame.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
		frame.addWindowListener( controller );
		frame.setVisible( true );
	}

	public static void main( final String[] args ) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException, IOException, SpimDataException
	{
		UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
		Locale.setDefault( Locale.ROOT );
		System.setProperty( "apple.laf.useScreenMenuBar", "true" );
		final Context context = new Context();

		/*
		 * Load SpimData
		 */
//		final String bdvFile = "../TrackMate3/samples/datasethdf5.xml";
//		final String bdvFile = "/Users/Jean-Yves/Desktop/MaMuT_demo_dataset/MaMuT_Parhyale_demo.xml";
//		final String bdvFile = "/Users/pietzsch/Desktop/data/MAMUT/MaMuT_demo_dataset/MaMuT_Parhyale_demo.xml";
		final String bdvFile = "/Users/tinevez/Projects/JYTinevez/MaMuT/MaMuT_demo_dataset/MaMuT_Parhyale_demo.xml";
//		final String bdvFile = "/Users/tinevez/Projects/JYTinevez/MaMuT/MaMuT_demo_dataset/MaMuT_Parhyale_demo.xml";

		final List< SourceAndConverter< ? > > sources = DetectionUtil.loadData( bdvFile );
		final Settings settings = new Settings()
				.sources( sources );

		final WindowManager windowManager = new WindowManager( context );
		final MainWindow mw = new MainWindow( windowManager );

		final MamutProject project = new MamutProject( null, new File( bdvFile ) );
		windowManager.getProjectManager().open( project );

		mw.setVisible( true );

		final Wizard wizard = new Wizard();
		windowManager.getContext().inject( wizard );
		final TrackMate trackmate = new TrackMate( settings, windowManager.getAppModel().getModel(), windowManager.getAppModel().getSelectionModel() );
		context.inject( trackmate );
		final DetectionSequence sequence = new DetectionSequence( trackmate, windowManager, wizard.getLogService() );
		wizard.show( sequence, "TrackMate detection" );
	}

}

@@ -51,742 +51,211 @@
 java
-.io.File;%0Aimport java.io.IOException;%0Aimport java.util.List;%0Aimport java.util.Locale;%0A%0Aimport javax.swing.JFrame;%0Aimport javax.swing.UIManager;%0Aimport javax.swing.UnsupportedLookAndFeelException;%0Aimport javax.swing.WindowConstants;%0Aimport javax.swing.text.DefaultStyledDocument;%0Aimport javax.swing.text.StyledDocument;%0A%0Aimport org.mastodon.detection.DetectionUtil;%0Aimport org.mastodon.revised.mamut.MainWindow;%0Aimport org.mastodon.revised.mamut.MamutProject;%0Aimport org.mastodon.revised.mamut.WindowManager;%0Aimport org.mastodon.trackmate.Settings;%0Aimport org.mastodon.trackmate.TrackMate;%0Aimport org.scijava.Context;%0Aimport org.scijava.plugin.Parameter;%0A%0Aimport bdv.viewer.SourceAndConverter;%0Aimport mpicbg.spim.data.SpimDataException
+x.swing.JFrame;%0Aimport javax.swing.WindowConstants;%0Aimport javax.swing.text.DefaultStyledDocument;%0Aimport javax.swing.text.StyledDocument;%0A%0Aimport org.scijava.Context;%0Aimport org.scijava.plugin.Parameter
 ;%0A%0Ap
@@ -1256,1809 +1256,6 @@
 %0A%09%7D%0A
-%0A%09public static void main( final String%5B%5D args ) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException, IOException, SpimDataException%0A%09%7B%0A%09%09UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );%0A%09%09Locale.setDefault( Locale.ROOT );%0A%09%09System.setProperty( %22apple.laf.useScreenMenuBar%22, %22true%22 );%0A%09%09final Context context = new Context();%0A%0A%09%09/*%0A%09%09 * Load SpimData%0A%09%09 */%0A//%09%09final String bdvFile = %22../TrackMate3/samples/datasethdf5.xml%22;%0A//%09%09final String bdvFile = %22/Users/Jean-Yves/Desktop/MaMuT_demo_dataset/MaMuT_Parhyale_demo.xml%22;%0A//%09%09final String bdvFile = %22/Users/pietzsch/Desktop/data/MAMUT/MaMuT_demo_dataset/MaMuT_Parhyale_demo.xml%22;%0A%09%09final String bdvFile = %22/Users/tinevez/Projects/JYTinevez/MaMuT/MaMuT_demo_dataset/MaMuT_Parhyale_demo.xml%22;%0A//%09%09final String bdvFile = %22/Users/tinevez/Projects/JYTinevez/MaMuT/MaMuT_demo_dataset/MaMuT_Parhyale_demo.xml%22;%0A%0A%09%09final List%3C SourceAndConverter%3C ? %3E %3E sources = DetectionUtil.loadData( bdvFile );%0A%09%09final Settings settings = new Settings()%0A%09%09%09%09.sources( sources );%0A%0A%09%09final WindowManager windowManager = new WindowManager( context );%0A%09%09final MainWindow mw = new MainWindow( windowManager );%0A%0A%09%09final MamutProject project = new MamutProject( null, new File( bdvFile ) );%0A%09%09windowManager.getProjectManager().open( project );%0A%0A%09%09mw.setVisible( true );%0A%0A%09%09final Wizard wizard = new Wizard();%0A%09%09windowManager.getContext().inject( wizard );%0A%09%09final TrackMate trackmate = new TrackMate( settings, windowManager.getAppModel().getModel(), windowManager.getAppModel().getSelectionModel() );%0A%09%09context.inject( trackmate );%0A%09%09final DetectionSequence sequence = new DetectionSequence( trackmate, windowManager, wizard.getLogService() );%0A%09%09wizard.show( sequence, %22TrackMate detection%22 );%0A%09%7D%0A%0A
 %7D%0A

Remove debug code.