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));
	}
	
}
