package org.mastodon.trackmate.ui.wizard;

import static org.mastodon.trackmate.ui.wizard.descriptors.LogPanel.BLUE_COLOR;
import static org.mastodon.trackmate.ui.wizard.descriptors.LogPanel.ERROR_COLOR;
import static org.mastodon.trackmate.ui.wizard.descriptors.LogPanel.GREEN_COLOR;
import static org.mastodon.trackmate.ui.wizard.descriptors.LogPanel.NORMAL_COLOR;
import static org.mastodon.trackmate.ui.wizard.descriptors.LogPanel.WARN_COLOR;

import java.awt.Color;

import org.mastodon.trackmate.ui.wizard.descriptors.LogPanel;
import org.scijava.app.StatusService;
import org.scijava.app.event.StatusEvent;
import org.scijava.log.AbstractLogService;
import org.scijava.log.LogMessage;
import org.scijava.log.LogService;
import org.scijava.plugin.Plugin;

@Plugin( type = WizardLogService.class )
public class WizardLogService extends AbstractLogService implements LogService, StatusService
{

	private final LogPanel panel;

	public WizardLogService()
	{
		this.panel = new LogPanel();
	}

	public LogPanel getPanel()
	{
		return panel;
	}

	@Override
	public void log( final int level, final Object msg )
	{
		final Color color;
		switch ( level )
		{
		case ERROR:
			color = ERROR_COLOR;
			break;
		case WARN:
			color = WARN_COLOR;
			break;
		case INFO:
		default:
			color = NORMAL_COLOR;
			break;
		case DEBUG:
			color = GREEN_COLOR;
			break;
		case TRACE:
			color = BLUE_COLOR;
			break;
		}
		panel.append( msg.toString(), color );
	}

	protected void log( final String msg )
	{
		log( INFO, msg );
	}

	protected void log( final Throwable t )
	{
		log( INFO, t.getStackTrace() );
	}

	@Override
	public void showProgress( final int value, final int maximum )
	{
		panel.setProgress( ( double ) value / maximum );
	}

	@Override
	public void showStatus( final String message )
	{
		panel.setStatus( message );
	}

	@Override
	public void showStatus( final int progress, final int maximum, final String message )
	{
		showProgress( progress, maximum );
		showStatus( message );
	}

	@Override
	public void showStatus( final int progress, final int maximum, final String message, final boolean warn )
	{
		showProgress( progress, maximum );
		panel.setStatus( message, warn ? WARN_COLOR : NORMAL_COLOR );
	}

	@Override
	public void warn( final String message )
	{
		panel.setStatus( message, WARN_COLOR );
	}

	@Override
	public void clearStatus()
	{
		panel.clearStatus();
	}

	public void clearLog()
	{
		panel.clearLog();
	}

	@Override
	public String getStatusMessage( final String appName, final StatusEvent statusEvent )
	{
		return null;
	}

	@Override
	protected void messageLogged( final LogMessage message )
	{
		// TODO Auto-generated method stub

	}

}

@@ -642,32 +642,65 @@
 ractLogService;%0A
+import org.scijava.log.LogLevel;%0A
 import org.scija
@@ -718,16 +718,16 @@
 essage;%0A
-
 import o
@@ -1193,16 +1193,25 @@
 %0A%09%09case 
+LogLevel.
 ERROR:%0A%09
@@ -1250,16 +1250,25 @@
 %0A%09%09case 
+LogLevel.
 WARN:%0A%09%09
@@ -1305,16 +1305,25 @@
 %0A%09%09case 
+LogLevel.
 INFO:%0A%09%09
@@ -1373,16 +1373,25 @@
 %0A%09%09case 
+LogLevel.
 DEBUG:%0A%09
@@ -1430,16 +1430,25 @@
 %0A%09%09case 
+LogLevel.
 TRACE:%0A%09
@@ -1574,24 +1574,33 @@
 )%0A%09%7B%0A%09%09log( 
+LogLevel.
 INFO, msg );
@@ -1648,23 +1648,32 @@
  t )%0A%09%7B%0A
-
 %09%09log( 
+LogLevel.
 INFO, t.

Fix use of deprecated API