package org.helioviewer.jhv.plugins.eveplugin;

import java.net.URL;
import java.util.LinkedList;

import javax.swing.JComponent;

import org.helioviewer.jhv.base.plugin.interfaces.Plugin;
import org.helioviewer.jhv.gui.ImageViewerGui;
import org.helioviewer.jhv.gui.dialogs.observation.ObservationDialog;
import org.helioviewer.jhv.gui.interfaces.MainContentPanelPlugin;
import org.helioviewer.jhv.layers.Layers;
import org.helioviewer.jhv.plugins.eveplugin.draw.DrawController;
import org.helioviewer.jhv.plugins.eveplugin.events.model.EventModel;
import org.helioviewer.jhv.plugins.eveplugin.radio.data.RadioDataManager;
import org.helioviewer.jhv.plugins.eveplugin.radio.model.ZoomManager;
import org.helioviewer.jhv.plugins.eveplugin.settings.BandTypeAPI;
import org.helioviewer.jhv.plugins.eveplugin.settings.EVESettings;
import org.helioviewer.jhv.plugins.eveplugin.view.ObservationDialogUIPanel;
import org.helioviewer.jhv.plugins.eveplugin.view.RadioObservationDialogUIPanel;
import org.helioviewer.jhv.plugins.eveplugin.view.chart.PlotPanel;
import org.helioviewer.jhv.plugins.eveplugin.view.linedataselector.LineDataSelectorTablePanel;
import org.helioviewer.jhv.threads.JHVWorker;

public class EVEPlugin implements Plugin, MainContentPanelPlugin {

    private final LinkedList<JComponent> pluginPanes = new LinkedList<JComponent>();
    private final PlotPanel plotOne = new PlotPanel();
    private final LineDataSelectorTablePanel timelinePluginPanel = new LineDataSelectorTablePanel();
    public final static DrawController dc = new DrawController();

    @Override
    public void installPlugin() {
        dc.addTimingListener(EventModel.getSingletonInstance());

        // Create an instance of eveDrawController and leave it here
        ZoomManager.getSingletonInstance();
        RadioDataManager.getSingletonInstance();
        pluginPanes.add(plotOne);

        ImageViewerGui.getLeftContentPane().add("Timeline Layers", timelinePluginPanel, true);
        ImageViewerGui.getLeftContentPane().revalidate();

        ImageViewerGui.getMainContentPanel().addPlugin(EVEPlugin.this);

        EventModel.getSingletonInstance().activateEvents();

        Layers.addLayersListener(dc);
        Layers.addTimeListener(dc);

        JHVWorker<Void, Void> loadSources = new JHVWorker<Void, Void>() {

            @Override
            protected Void backgroundWork() {
                // call BandType API in background => loads the datasets
                BandTypeAPI.getSingletonInstance();
                return null;
            }

            @Override
            public void done() {
                ObservationDialog.getInstance().addUserInterface(EVESettings.OBSERVATION_UI_NAME, new ObservationDialogUIPanel());
                ObservationDialog.getInstance().addUserInterface(EVESettings.RADIO_OBSERVATION_UI_NAME, new RadioObservationDialogUIPanel());
            }

        };

        loadSources.setThreadName("EVE--LoadSources");
        EVESettings.getExecutorService().execute(loadSources);
    }

    @Override
    public void uninstallPlugin() {
        Layers.removeTimeListener(dc);
        Layers.removeLayersListener(dc);

        ObservationDialog.getInstance().removeUserInterface(EVESettings.OBSERVATION_UI_NAME, new ObservationDialogUIPanel());
        ObservationDialog.getInstance().removeUserInterface(EVESettings.RADIO_OBSERVATION_UI_NAME, new RadioObservationDialogUIPanel());

        ImageViewerGui.getMainContentPanel().removePlugin(this);

        ImageViewerGui.getLeftContentPane().remove(timelinePluginPanel);
        ImageViewerGui.getLeftContentPane().revalidate();
        pluginPanes.remove(plotOne);
    }

    public static URL getResourceUrl(String name) {
        return EVEPlugin.class.getResource(name);
    }

    @Override
    public String getName() {
        return "EVEPlugin " + "$Rev$";
    }

    @Override
    public String getDescription() {
        return "This plugin visualizes 1D and 2D time series";
    }

    @Override
    public String getAboutLicenseText() {
        return "<p>The plugin uses the <a href=\"https://github.com/stleary/JSON-java\">JSON in Java</a> Library, licensed under a custom <a href=\"http://www.json.org/license.html\">License</a>.";
    }

    @Override
    public LinkedList<JComponent> getVisualInterfaces() {
        return pluginPanes;
    }

    @Override
    public String getTabName() {
        return "Timelines";
    }

    @Override
    public void setState(String state) {
    }

    @Override
    public String getState() {
        return null;
    }

}

@@ -621,78 +621,8 @@
 er;%0A
-import org.helioviewer.jhv.plugins.eveplugin.radio.model.ZoomManager;%0A
 impo
@@ -1611,121 +1611,8 @@
 );%0A%0A
-        // Create an instance of eveDrawController and leave it here%0A        ZoomManager.getSingletonInstance();%0A
     

Remove zoomManager