/* ========================
* 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: Abstract2DCircuitComponent.java,v 1.2 2009/01/20 17:52:32 ogor Exp $
*
* Changes
* -------
* 08 sept 2008 : Initial public release (RO);
*
*/
package jsynoptic.plugins.circuit;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.List;
import simtools.diagram.DiagramSelection;
import simtools.diagram.SelectableShapeInterface;
import simtools.diagram.ElementSelection;
import simtools.diagram.gate.Connection;
import simtools.diagram.gate.Gate;
import simtools.diagram.gate.GatedComponentSelection;
import simtools.shapes.AbstractShape;
import simtools.shapes.GatesHolder;
import jsynoptic.builtin.Abstract2DShape;
/**
* A Abstract2DCircuitComponent is an {@link Abstract2DShape} that holds circuit gates.
* @author zxpletran007
*
*/
public abstract class Abstract2DCircuitComponent extends Abstract2DShape implements SelectableShapeInterface, GatedCircuitComponent {
private static final long serialVersionUID = 4748022410166944824L;
protected GatesHolder gateHolder;
public Abstract2DCircuitComponent(
int ox,
int oy,
int width,
int height
) {
super(ox, oy, width, height);
gateHolder = new GatesHolder(this);
fixedRatio = true;
}
/*
* (non-Javadoc)
*
* @see simtools.shapes.AbstractShape#cloneShape()
*/
protected AbstractShape cloneShape() {
Abstract2DCircuitComponent res = (Abstract2DCircuitComponent) super.cloneShape();
res.gateHolder = gateHolder.cloneGateHolder(res);
return res;
}
public Rectangle getGateBounds(){
return new Rectangle(_ox + _x,_oy + _y - _h , _w,_h);
}
/**
* A input gate has a new signal
* @param gate
*/
public void signalHasBeenReceived(CircuitGate gate) {
// By default do nothing
}
public void signalHasBeenSent(CircuitGate gate) {
// By default do nothing
}
/* (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);
}
/* (non-Javadoc)
* @see simtools.diagram.gate.GatedComponent#removeGate(simtools.diagram.gate.Gate)
*/
public void removeGate(Gate gate) {
gateHolder.removeGate(gate);
}
public void connectionAddedAt(Gate gate, Connection connection) {
// by default do nothing
}
public void connectionRemovedAt(Gate gate, Connection connection) {
// by default do nothing
}
public ElementSelection createSelection(Point shapeOrigin, DiagramSelection ds){
return new GatedComponentSelection(this, shapeOrigin, ds);
}
}