package pipe.dataLayer; import java.awt.Color; import java.awt.Shape; import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.*; import java.awt.event.*; import java.awt.*; /** * PlaceTransitionObject - Petri-Net PLace or Transition SuperClass - Abstract * * @see

PNML - Petri-Net XMLSchema (stNet.xsd) * @see

UML - PNML Package

* @version 1.0 * @author James D Bloom */ public abstract class PlaceTransitionObject extends PetriNetObject { /** X-axis Position */ protected Double positionX = null; /** Y-axis Position */ protected Double positionY = null; /** Name */ protected String name = null; /** Name X-axis Offset */ protected Double nameOffsetX = null; /** Name Y-axis Offset */ protected Double nameOffsetY = null; /**Width of object */ protected double width = 0; /**Height of object */ protected double height = 0; /** TopOffSet used for setBounds() */ protected int boundsTopoffset; /** LeftOffSet used for setBounds() */ protected int boundsLeftoffset; /** Used in the mouse events to control dragging*/ private boolean isDragging; /** * Create Petri-Net Object * * @param positionXInput X-axis Position * @param positionYInput Y-axis Position * @param idInput Place id * @param nameInput Name * @param nameOffsetXInput Name X-axis Position * @param nameOffsetYInput Name Y-axis Position * @param colorInput Color */ public PlaceTransitionObject(double positionXInput, double positionYInput, String idInput, String nameInput, double nameOffsetXInput, double nameOffsetYInput, Color colorInput){ this(positionXInput,positionYInput,colorInput); id = idInput; name = nameInput; nameOffsetX = new Double(nameOffsetXInput); nameOffsetY = new Double(nameOffsetYInput); /* sets up namelabel for each PN object*/ NameLabel placetransname = new NameLabel(name); pnname = placetransname; pnname.boundsSet(boundsLeftoffset, boundsTopoffset , boundsWidth(), boundsHeight()); } /** * Create Petri-Net Object * * @param positionXInput X-axis Position * @param positionYInput Y-axis Position * @param idInput Place id * @param colorInput Color */ public PlaceTransitionObject(double positionXInput, double positionYInput, String idInput, Color colorInput){ this(positionXInput,positionYInput,colorInput); id = idInput; } /** * Create Petri-Net Object * This constructor does all the work, the others just call it. * * @param positionXInput X-axis Position * @param positionYInput Y-axis Position * @param colorInput Color * */ public PlaceTransitionObject(double positionXInput, double positionYInput, Color colorInput){ positionX = new Double(positionXInput); positionY = new Double(positionYInput); color = colorInput; calculateBoundsOffsets(); setBounds(boundsLeftoffset, boundsTopoffset, boundsWidth(), boundsHeight()); /*sets up Namelabel for each PN object*/ NameLabel placetransname = new NameLabel(name); pnname = placetransname; pnname.boundsSet(boundsLeftoffset, boundsTopoffset , boundsWidth(), boundsHeight()); } /** * Create empty Petri-Net Object * */ public PlaceTransitionObject(){ } /** * Set X-axis position * * @param positionXInput Double value for X-axis position */ public void setPositionX(double positionXInput) { positionX = new Double(positionXInput); } /** * Set Y-axis position * * @param positionYInput Double value for Y-axis position */ public void setPositionY(double positionYInput) { positionY = new Double(positionYInput); } /** * Set id * * @param idInput String value for Place id; */ public void setId(String idInput) { id = idInput; setName(id); //System.out.println("setting id to: " + idInput); } /** * Set name * * @param nameInput String value for Place name; */ public void setName(String nameInput) { name = nameInput; //sets the text within the label // System.out.println("setting name to: " + nameInput); pnname.setText(name); } /** * Set X-axis offset for name position * * @param nameOffsetXInput Double value for name X-axis offset */ public void setNameOffsetX(double nameOffsetXInput) { nameOffsetX = new Double(nameOffsetXInput); } /** * Set Y-axis offset for name position * * @param nameOffsetYInput Double value for name Y-axis offset */ public void setNameOffsetY(double nameOffsetYInput) { nameOffsetY = new Double(nameOffsetYInput); } /** * Get X-axis position * * @return Double value for X-axis position */ public double getPositionX() { if(positionX == null) return 0; return positionX.doubleValue(); } /** * Get Y-axis position * * @return Double value for Y-axis position */ public double getPositionY() { if(positionY == null) return 0; return positionY.doubleValue(); } /** * Get id * * @return String value for Place id; */ public String getId() { if(id != null) return id; else return name; } /** * Get name * * @return String value for Place name; */ public String getName() { if(name != null) return name; else return id; } /** * Get X-axis offset for name position * * @return Double value for name X-axis offset */ public double getNameOffsetX() { if(nameOffsetX == null) return 0; return nameOffsetX.doubleValue(); } /** * Get Y-axis offset for name position * * @return Double value for name Y-axis offset */ public double getNameOffsetY() { if(nameOffsetY == null) return 0; return nameOffsetY.doubleValue(); } /** * Get X-axis position * returns null if value not yet entered * * @return Double value for X-axis position */ public Double getPositionXObject() { return positionX; } /** * Get Y-axis position * returns null if value not yet entered * * @return Double value for Y-axis position * */ public Double getPositionYObject() { return positionY; } /** * Get X-axis offset for name position * returns null if value not yet entered * * @return Double value for name X-axis offset */ public Double getNameOffsetXObject() { return nameOffsetX; } /** * Get Y-axis offset for name position * returns null if value not yet entered * * @return Double value for name Y-axis offset */ public Double getNameOffsetYObject() { return nameOffsetY; } /* MOUSE EVENT HANDLERS - most now do nothing as functionality moved into handlers*/ /** Event handler for when the user presses down on the mouse, this is used in conjunction with mouseDragged and mouseReleased to implement the moving action * @param e Mouse Event */ public void mousePressed(MouseEvent e) { Insets insets = getInsets(); int eventX = e.getX(); int eventY = e.getY(); } /** Implemented the moving action - now moved into the handler * @param e Mouse Event */ public void mouseReleased(MouseEvent e) { } /** Implemented the moving of the objects - now done in the handler * @param e Mouse Event */ public void mouseDragged(MouseEvent e) { } /** Implemented in subclasses as involves some tailoring according to the shape * @param e Mouse Event */ public abstract void updateSize(MouseEvent e); public void paintComponent(Graphics g) { super.paintComponent(g); } /** Returns the width bounds we want to use when initially creating the place on the gui * @return Width bounds of Place */ public int boundsWidth() { return WIDTH+1; } /** Returns the height bounds we want to use when initially creating the place on the gui * @return Height bounds of Place */ public int boundsHeight() { return HEIGHT+1; } /** Returns the distance between the outside of the component to the centre, in order to position the centre of the place where the mouse clicks on the screen * @return Top offset of Place */ public int topOffset() { return boundsHeight() /2; } /** Returns the distance between the outside of the component to the centre, in order to position the centre of the place where the mouse clicks on the screen * @return Left offset of Place */ public int leftOffset() { return boundsWidth() /2; } /** Calculates the BoundsOffsets used for setBounds() method */ public void calculateBoundsOffsets(){ Insets insets = getInsets(); boundsTopoffset = positionY.intValue() - insets.top - topOffset(); boundsLeftoffset = positionX.intValue() - insets.left - leftOffset(); } }