/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info: http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2005, by :
* Corporate:
* EADS Astrium SAS
* EADS CRC
* Individual:
* Claude Cazenave
*
* $Id: CircuitPlugin.java,v 1.9 2009/02/04 11:11:58 ogor Exp $
*
* Changes
* -------
* 08 sept 2008 : Initial public release (RO);
*
*/
package jsynoptic.plugins.circuit;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import javax.swing.Icon;
import jsynoptic.base.HelpNode;
import jsynoptic.base.Plugin;
import jsynoptic.plugins.circuit.boxes.Emitter;
import jsynoptic.plugins.circuit.boxes.Receiver;
import jsynoptic.plugins.circuit.switches.SwitchBox2Pos;
import jsynoptic.plugins.circuit.switches.SwitchBox3Pos;
import jsynoptic.ui.ShapeCreator;
import simtools.shapes.AbstractShape;
import simtools.ui.ColorMapper;
import simtools.ui.HelpBundle;
import simtools.ui.HelpFinder;
import simtools.ui.MenuResourceBundle;
import simtools.ui.ResourceFinder;
public class CircuitPlugin extends Plugin{
public static MenuResourceBundle resources = ResourceFinder.getMenu(CircuitPlugin.class);
public static HelpBundle help = HelpFinder.getMenu(CircuitPlugin.class);
public final static String SWITCH_BOX_2_POS = resources.getString("SwitchBox2Pos");
public final static String SWITCH_BOX_3_POS = resources.getString("SwitchBox3Pos");
public final static String EMITTER = resources.getString("Emitter");
public final static String RECEIVER = resources.getString("Receiver");
public final static String GATED_SVG_SHAPE = resources.getString("GatedSvgShape");
public final static String CIRCUIT_CONNECTOR = resources.getString("CircuitConnector");
public final static Icon CIRCUIT_CONNECTOR_ICON = resources.getIcon("CircuitConnectorIcon");
public final static String CIRCUIT = resources.getString("Circuit");
public final static Icon CIRCUIT_ICON = resources.getIcon("CircuitIcon");
protected List shapeCreators;
public CircuitPlugin(){
shapeCreators = new ArrayList();
shapeCreators.add(new ShapeCreator(this, SWITCH_BOX_2_POS, null, CIRCUIT, CIRCUIT_ICON));
shapeCreators.add(new ShapeCreator(this, SWITCH_BOX_3_POS, null, CIRCUIT, CIRCUIT_ICON));
shapeCreators.add(new ShapeCreator(this, EMITTER, null, CIRCUIT, CIRCUIT_ICON));
shapeCreators.add(new ShapeCreator(this, RECEIVER, null, CIRCUIT, CIRCUIT_ICON));
shapeCreators.add(new ShapeCreator(this, GATED_SVG_SHAPE, null, CIRCUIT, CIRCUIT_ICON));
ShapeCreator connectorCreator = new ShapeCreator(this, CIRCUIT_CONNECTOR, CIRCUIT_CONNECTOR_ICON, CIRCUIT, CIRCUIT_ICON);
connectorCreator.enableGateTrackingAtCreation = true;
shapeCreators.add(connectorCreator);
}
/* (non-Javadoc)
* @see jsynoptic.base.Plugin#getShapeCreators()
*/
public List getShapeCreators(){
return shapeCreators;
}
public String about() {
return resources.getString("about");
}
public static ColorMapper EMITTER_DEFAULT_MAPPER = new ColorMapper(CircuitPlugin.resources.getString("OnOffEmitterMapper"));
static{
EMITTER_DEFAULT_MAPPER.setMapping("ON", Color.GREEN);
EMITTER_DEFAULT_MAPPER.setMapping("OFF", Color.RED);
ColorMapper.updateColorMapper(EMITTER_DEFAULT_MAPPER);
}
/* (non-Javadoc)
* @see jsynoptic.base.Plugin#createShape(java.lang.String)
*/
public AbstractShape createShape(String name) {
AbstractShape res = null;
if (name.equals(CIRCUIT_CONNECTOR)) {
res = createShape(name, 0, 0, 100, 0);
} else if (name.equals(EMITTER)) {
res = createShape(name,0, 0, 35, 35);
} else if (name.equals(RECEIVER)) {
res = createShape(name,0, 0,35, 35);
} else if (name.equals(SWITCH_BOX_2_POS)) {
res = createShape(name,0, 0, 35, 35);
} else if (name.equals(SWITCH_BOX_3_POS)) {
res = createShape(name,0, 0, 35, 45);
} else if (name.equals(GATED_SVG_SHAPE)) {
res = createShape(name,0, 0, 35, 45);
}
return res;
}
public AbstractShape createShape(String name, int x, int y, int width, int height) {
AbstractShape res = null;
if (name.equals(CIRCUIT_CONNECTOR)) {
res = new CircuitConnection(x, y, width, height);
} else if (name.equals(EMITTER)) {
res = new Emitter(x, y, width, height);
} else if (name.equals(RECEIVER)) {
res = new Receiver(x, y, width, height);
} else if (name.equals(SWITCH_BOX_2_POS)) {
res = new SwitchBox2Pos(x, y, width, height);
} else if (name.equals(SWITCH_BOX_3_POS)) {
res = new SwitchBox3Pos(x, y, width, height);
} else if (name.equals(GATED_SVG_SHAPE)) {
res = new GatedSvgShape(x, y, width, height);
}
return res;
}
/* (non-Javadoc)
* @see jsynoptic.base.Plugin#getHelp()
*/
public HelpNode getHelp(){
HelpNode rootNode = new HelpNode();
HelpNode circuitNode = new HelpNode("Circuit", help.getURLValue("circuitFeatures"));
HelpNode switchNode = new HelpNode("Switch", help.getURLValue("circuitFeatures_switch"));
circuitNode.addHelpNode(switchNode);
switchNode.addHelpNode( new HelpNode("Set switch position", help.getURLValue("circuitFeatures_switch", "switchPosition")));
switchNode.addHelpNode( new HelpNode("Round switches", help.getURLValue("circuitFeatures_switch", "roundSwitch")));
HelpNode emitterNode = new HelpNode("Emitter & Receiver", help.getURLValue("circuitFeatures_emitter"));
circuitNode.addHelpNode(emitterNode);
HelpNode svgNode = new HelpNode("Gated SVG Shape", help.getURLValue("circuitFeatures_gatedSVGShape"));
circuitNode.addHelpNode(svgNode);
svgNode.addHelpNode( new HelpNode("Add or remove a gate", help.getURLValue("circuitFeatures_gatedSVGShape", "addGate")));
svgNode.addHelpNode( new HelpNode("Set up gate properties", help.getURLValue("circuitFeatures_gatedSVGShape", "setupGate")));
HelpNode tuto = new HelpNode("Tutorial: create a very simple circuit", help.getURLValue("circuitFeatures_tutorial"));
circuitNode.addHelpNode(tuto);
tuto.addHelpNode( new HelpNode("Assert that plugin Circuit has been loaded", help.getURLValue("circuitFeatures_tutorial", "circuitConfiguration")));
tuto.addHelpNode( new HelpNode("Create some dynamic values to animate the circuit", help.getURLValue("circuitFeatures_tutorial", "createDynamicDs")));
tuto.addHelpNode( new HelpNode("Create circuit components", help.getURLValue("circuitFeatures_tutorial", "createCircuit")));
tuto.addHelpNode( new HelpNode("Configure gates", help.getURLValue("circuitFeatures_tutorial", "comfigureGates")));
tuto.addHelpNode( new HelpNode("Connect gate components through connectors", help.getURLValue("circuitFeatures_tutorial", "connectComponents")));
tuto.addHelpNode( new HelpNode("Set up Emitter properties", help.getURLValue("circuitFeatures_tutorial", "setupEmiter")));
tuto.addHelpNode( new HelpNode("Set up switch properties", help.getURLValue("circuitFeatures_tutorial", "setupSwitch")));
rootNode.addHelpNode(circuitNode);
return rootNode;
}
}