/* ========================
* 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: SwitchBox3Pos.java,v 1.2 2008/10/24 15:49:11 ogor Exp $
*
* Changes
* -------
* 08 sept 2008 : Initial public release (RO);
*
*/
package jsynoptic.plugins.circuit.switches;
import jsynoptic.plugins.circuit.CircuitGate;
import jsynoptic.plugins.circuit.CircuitPlugin;
import simtools.diagram.gate.Gate;
import simtools.shapes.AbstractShape;
public class SwitchBox3Pos extends SwitchBox{
private static final long serialVersionUID = -6562509065320403946L;
protected final static int POS_1 = 1;
protected final static int POS_2 = 2;
protected final static int POS_3 = 3;
// Gates
protected CircuitGate j01;
protected CircuitGate j02;
protected CircuitGate j03;
protected CircuitGate j04;
/**
* @param ox
* @param oy
* @param diameter
*/
public SwitchBox3Pos(int ox, int oy, int width, int height) {
super(ox, oy, width, height, POS_1, 1, 3);
// Add gates
addGate(j01 = new CircuitGate(this, Gate.WEST, "J01", true));
addGate(j02 = new CircuitGate(this, Gate.EAST, "J02", true));
addGate(j03 = new CircuitGate(this, Gate.EAST, "J03", true));
addGate(j04 = new CircuitGate(this, Gate.EAST, "J04", true));
}
/*
* (non-Javadoc)
*
* @see simtools.shapes.AbstractShape#cloneShape()
*/
protected AbstractShape cloneShape() {
SwitchBox3Pos res = (SwitchBox3Pos) super.cloneShape();
res.j01 = (CircuitGate)j01.cloneGate(res);
res.addGate(res.j01);
res.j02 = (CircuitGate)j02.cloneGate(res);
res.addGate(res.j02);
res.j03 = (CircuitGate)j03.cloneGate(res);
res.addGate(res.j03);
res.j04 = (CircuitGate)j04.cloneGate(res);
res.addGate(res.j04);
return res;
}
/* (non-Javadoc)
* @see simtools.shapes.AbstractShape#getShapeName()
*/
public String getShapeName(){
return CircuitPlugin.resources.getString("SwitchBox2Pos");
}
/* (non-Javadoc)
* @see net.eads.astrium.jsynoptic.cuircuit.Switch#getTargetGate(jsynoptic.plugins.circuit.Gate)
*/
protected CircuitGate getTargetGate(CircuitGate sourceGate) {
CircuitGate res = null;
if (sourceGate == j01){
if (currentPosition == POS_1){
res = j02;
} else if (currentPosition == POS_2){
res = j03;
} else {
res = j04;
}
} else if (sourceGate == j02){
if (currentPosition == POS_1){
res = j01;
}
} else if (sourceGate == j03){
if (currentPosition == POS_2){
res = j01;
}
}else if (sourceGate == j04){
if (currentPosition == POS_3){
res = j01;
}
}
return res;
}
protected boolean isValidPosition(int position) {
return (position == POS_1) || (position == POS_2) || (position == POS_3);
}
/* (non-Javadoc)
* @see jsynoptic.plugins.circuit.SwitchShape#updateSwitchInnerConnections(int)
*/
protected void updateSwitchInnerConnections(){
super.updateSwitchInnerConnections();
if (isValidPosition(currentPosition)){ // add middle connections
try{
if (currentPosition == POS_1){
switchInnerConnections.add(new BoxSwitchMiddleConnector(0,0));
} else if (currentPosition == POS_2){
switchInnerConnections.add(new BoxSwitchMiddleConnector(0,1));
} else if (currentPosition == POS_3){
switchInnerConnections.add(new BoxSwitchMiddleConnector(0,2));
}
}catch (InvalidSwitchConnection e){
e.printStackTrace();
}
}
}
}