/*
 *  Draco Econometrics
 *  Copyright (C) 2008-2009 Approximatrix, LLC
 *  http://www.approximatrix.com
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.approximatrix.draco.application.plugin.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

import com.approximatrix.draco.application.ChildFrame;
import com.approximatrix.draco.application.plugin.PluginData;
import com.approximatrix.draco.general.ui.InfoWindow;
import com.approximatrix.draco.general.ui.VectorGraphicsPanel;

public class UnknownPluginWindow extends ChildFrame implements PluginDataProvidingWindow, ActionListener {

	private static final String RESULTSMENUITEM = "View Results...";
	private static final String PATH_TO_IMAGE = "/com/approximatrix/draco/application/plugin/ui/images/plugin.svg";
	
	private PluginData data = null;
	
	private static final int WIDTH = 250;
	private static final int HEIGHT = 150;
	
	private JMenu[] menus = null;
	
	public UnknownPluginWindow(PluginData data) {
		this(data,data.getName());
	}
	
	public UnknownPluginWindow(PluginData data, String name) {
		super(name,true,true,true,true);
		this.data = data;
		initialize();
	}
	
	private void initialize() {
		this.setSize(WIDTH,HEIGHT);
		this.getContentPane().setLayout(new BorderLayout());
		
		JPanel image_panel = new VectorGraphicsPanel(PATH_TO_IMAGE);
		image_panel.setBackground(Color.WHITE);
		this.getContentPane().add(image_panel,BorderLayout.CENTER);
	}
	
	public PluginData getPluginData() {
		return data;
	}

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

	@Override
	public JMenu[] getMenuItems() {
		if(menus == null) {
			menus = new JMenu[1];
		
			JMenu pMenu = new JMenu("Plugin");
		
			if(data.getResults() != null) {
				JMenuItem resItem = new JMenuItem(RESULTSMENUITEM);
				resItem.addActionListener(this);
				pMenu.add(resItem);
			}
		
			menus[0] = pMenu;
		}
		return menus;
	}

	@Override
	public Component[] getToolbarButtons() {
		return null;
	}

	@Override
	public boolean isRenameable() {
		return true;
	}

	public void actionPerformed(ActionEvent arg0) {
		getMainWindow().openWindow(new InfoWindow(data.getName()+" Results",data.getResults(),false,true));
	}
	
}
