package hyperia.quickviz;

// TODO Properties for visualization modes
// TODO Add a Zoom menu
// TODO Improve Spectrum related classes: better variance storage (MetaData class), genericity
// TODO Log scale for the intensity
// TODO Use a thread for checkForUpdate
// TODO Format both intensity and spectral axes
// TODO Add a CalibManager (singleton pattern) storing spectral calibrations associated to each cube

import java.text.ParseException;

import cds.aladin.AladinException;
import cds.aladin.AladinPlugin;

/**
 * The QuickViz plugin is an Aladin plugin based on the QuickViz application. It
 * allows to display spectra coming from Aladin planes and to fully interact
 * with them. This class does not provide additional features to the original
 * QuickViz software but only manages the interaction with Aladin.<BR>
 * <BR>
 * <B> Installation : </B> copy the jar file of the plugin into the plugin
 * folder of Aladin
 * 
 * @author petremand
 * @version 1.8
 * @see QuickViz
 * @see Reader
 * @see ReaderCleaner
 */
public class QuickVizPlugin extends AladinPlugin {
	/**
	 * QuickViz application
	 */
	private QuickViz application = null;

	/**
	 * Returns the script command to run the plugin
	 * 
	 * @return Script command to run the plugin
	 */
	public String scriptCommand() { return "quickviz"; }

	/**
	 * This method is called by Aladin whenever the plugin becomes active. It
	 * constructs and starts the application
	 * 
	 * @throws AladinException
	 *             for Aladin exceptions
	 */
	@Override
	public void exec() throws AladinException {
		// If the plugin wasn't already running
		if (!isRunning()) {
			// Creates the QuickViz plugin
			try {
				application = QuickViz.runQuickViz(aladin);
			} catch (ParseException e) {
				application = null;
			}
		}
	}

	/**
	 * Returns true if the plugin is currently running. false otherwise
	 * 
	 * @return true if the plugin is currently running. false otherwise
	 */
	@Override
	public boolean isRunning() {
		return (application == null ? false : application.isDisplayable());
	}

	/**
	 * Returns the menu label
	 * 
	 * @return Menu label
	 */
	@Override
	public String menu() { return "QuickViz"; }

	/**
	 * Returns the plugin author
	 * 
	 * @return Plugin author
	 */
	@Override
	public String author() { return "Petremand Matthieu"; }

	/**
	 * Returns the version number of the plugin
	 * 
	 * @return Version number of the plugin
	 */
	@Override
	public String version() {
		return "1.8 - requires Aladin v7.000";
	}

	/**
	 * Returns the plugin description
	 * 
	 * @return Plugin description
	 */
	@Override
	public String description() {
		return "The QuickViz software allows to visualize spectra coming from hyperspectral datacubes and to fully interact with Aladin";
	}

	/**
	 * This method is called by Aladin whenever the user closes the plugin. It
	 * properly kills all running reading tasks thanks to the ReaderCleaner
	 * object
	 * 
	 * @see ReaderCleaner
	 */
	@Override
	public void cleanup() {
		// If the plugin is running
		if (isRunning()) {
			application.dispose();
			application = null;
		}
	}
}
