/* ==============================================
* Simtools : The tools library used in JSynoptic
* ==============================================
*
* Project Info: http://jsynoptic.sourceforge.net/index.html
*
* This library 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 library 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
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 1999-2008, by :
* Corporate:
* Astrium SAS
* EADS CRC
* Individual:
* Claude Cazenave
*
* $Id: GatedRectangleShape.java,v 1.4 2009/01/20 17:52:33 ogor Exp $
*
* Changes
* -------
* 08-Sep-2008 : Initial public release (RO);
*
*/
package examples.gates;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.List;
import jsynoptic.builtin.RectangleShape;
import jsynoptic.plugins.circuit.CircuitGate;
import simtools.diagram.gate.Connection;
import simtools.diagram.gate.Gate;
import simtools.diagram.gate.GatedComponent;
import simtools.shapes.AbstractShape;
import simtools.shapes.GatesHolder;
public class GatedRectangleShape extends RectangleShape implements GatedComponent{
/**
*
*/
private static final long serialVersionUID = -3801450642370829579L;
/**
* Manage gates
*/
protected GatesHolder gateHolder;
protected Gate northGate, southGate, eastGate, westGate;
public GatedRectangleShape(int ox, int oy, int width, int height) {
super(ox, oy, width, height);
gateHolder = new GatesHolder(this);
addGate(northGate = new Gate(this, Gate.NORTH));
addGate(southGate = new Gate(this, Gate.SOUTH));
addGate(eastGate = new Gate(this, Gate.EAST));
addGate(westGate = new Gate(this, Gate.WEST));
}
public Rectangle getGateBounds(){
return new Rectangle(_ox + _x,_oy + _y - _h , _w,_h);
}
/*
* (non-Javadoc)
*
* @see simtools.shapes.AbstractShape#cloneShape()
*/
protected AbstractShape cloneShape() {
GatedRectangleShape res = (GatedRectangleShape) super.cloneShape();
res.gateHolder = gateHolder.cloneGateHolder(res);
res.northGate = (CircuitGate)northGate.cloneGate(res);
res.addGate(res.northGate);
res.southGate = (CircuitGate)southGate.cloneGate(res);
res.addGate(res.southGate);
res.eastGate = (CircuitGate)eastGate.cloneGate(res);
res.addGate(res.eastGate);
res.westGate = (CircuitGate)westGate.cloneGate(res);
res.addGate(res.westGate);
return res;
}
/* (non-Javadoc)
* @see simtools.diagram.gate.GatedComponent#getGateAnchor(simtools.diagram.gate.Gate)
*/
public Point getGateAnchor(Gate gate) {
return gateHolder.getGateAnchor(gate);
}
/* (non-Javadoc)
* @see simtools.diagram.gate.GatedComponent#getGateAt(int, int)
*/
public Gate getGateAt(int ox, int oy) {
return gateHolder.getGateAt(ox, oy);
}
/* (non-Javadoc)
* @see simtools.diagram.gate.GatedComponent#getGates()
*/
public List getGates() {
return gateHolder.getGates();
}
/* (non-Javadoc)
* @see simtools.diagram.gate.GatedComponent#addGate(simtools.diagram.gate.Gate)
*/
public void addGate(Gate gate) {
gateHolder.addGate(gate);
}
public void removeGate(Gate gate) {
gateHolder.removeGate(gate);
}
public void connectionAddedAt(Gate gate, Connection connection) {
// TODO Auto-generated method stub
}
public void connectionRemovedAt(Gate gate, Connection connection) {
// TODO Auto-generated method stub
}
}