uk.ac.ic.doc.y2002.tool.editor
Class PNLabel

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JLabel
                          |
                          +--uk.ac.ic.doc.y2002.tool.editor.PNLabel
All Implemented Interfaces:
javax.accessibility.Accessible, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable, javax.swing.SwingConstants
Direct Known Subclasses:
ArcLabel, NodeLabel

public class PNLabel
extends javax.swing.JLabel
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener

The PNLabel class is the basis of all Petri Net Labels in the program. Each PNLabel contains a reference to the Element within the DOM that the Label represents on screen. PNLabel itself should not be instantiated.

See Also:
PlaceLabel, Serialized Form

Inner classes inherited from class javax.swing.JLabel
javax.swing.JLabel.AccessibleJLabel
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
protected  boolean beingMoved
           
protected  java.lang.Class contextmenu
          Class that is used to generate a context (right-click) menu for this type of PNLabel.
protected  org.jdom.Element element
          Reference to the JDOM Element which represents this object.
protected  java.awt.Color fillcolour
           
protected  boolean firsttime
           
protected  int height
           
protected  java.awt.Color highlightfill
           
protected  java.lang.String id
          Locally-stored copy of the object's unique id.
protected  int lastX
           
protected  int lastY
           
protected  java.awt.Color normalfill
           
protected  org.jdom.Namespace ns
          Namespace of the JDOM Element which represents this object.
protected  int offset
           
protected  java.lang.Class propertiesbox
          Class that is used to generate a properties box for this type of PNLabel.
protected  int rotation
           
protected  int scaling
           
protected  boolean selected
           
protected  int textspace
           
protected  int width
           
protected  int xoffset
           
protected  int xPress
           
protected  int yoffset
           
protected  int yPress
           
 
Fields inherited from class javax.swing.JLabel
labelFor
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NORTH, NORTH_EAST, NORTH_WEST, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PNLabel(org.jdom.Element element)
           
 
Method Summary
 void addToken()
          Override this as necessary (eg for PlaceLabel).
 void changeElement(org.jdom.Element newElement)
          Changes the element this PNLabel is representing.
protected  void dofirst()
           
 void doubleclickAction()
          Override in subclasses to produce required functionality
 DisplayPane getDisplayPane()
           
 java.lang.String getID()
           
 int getJX()
          Get X value from the JDOM Document Defaults to 0 if not found
 int getJY()
          Get Y value from the JDOM Document Defaults to 0 if not found
 java.util.List getLinkedLabels()
          Override in subclasses to return a list of PNLabels which are linked to this PNLabel.
 java.awt.Dimension getPreferredSize()
           
 org.jdom.Element getToolspecific()
          Function to find and return the Toolspecific element corresponding to this tool.
 void highlight(boolean highlight)
          Should not be called directly: call select instead.
 boolean isActive()
          Override in subclasses to indicate when an element is enabled within the net.
static org.jdom.Element makeGraphics(java.lang.String x, java.lang.String y, org.jdom.Namespace ns)
          Creates a graphics JDOM Element for use by a new PN element.
 org.jdom.Element makeToolspecific()
          Function to make a Toolspecific element - assumes one does not exist already.
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseDragged(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 java.lang.String myElementName()
           
 void paintComponent(java.awt.Graphics g)
          The function which draws the PNLabel on screen.
 DisplayPane remove()
          Function that should be called when the element is removed from the Petri Net.
 void remToken()
          Override as necessary (eg for PlaceLabel).
 org.jdom.Element returnElement()
          An access function that returns the JDOM Element which this PNLabel represents.
 boolean returnSelected()
           
 void select(boolean select)
          Selects the PNLabel.
 void selectOnly(boolean select)
          Selects the PNLabel without unselecting others in the display.
protected  void setJX(int x)
          Set X value in the JDOM Document note this may need conversion from the actual x,y values for the label
protected  void setJY(int y)
          Set Y value in the JDOM Document note this may need conversion from the actual x,y values for the label
 void setPosition(int x, int y)
          Update DOM with new values and set the label position.
 void showContextMenu(java.awt.event.MouseEvent e)
          Brings up the right-click popup menu.
protected  void updateBounds()
          may be overridden to deal with different sizes and shapes of labels.
protected  void updateLocation(int newx, int newy)
           
protected  void updateLocation(java.awt.event.MouseEvent e)
           
protected  void updatePosition()
           
 void updateSelf()
          Function which allows the label to update itself (eg for modifying screen display) in response to changes in the underlying JDOM Element.
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setText, setUI, setVerticalAlignment, setVerticalTextPosition, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

element

protected org.jdom.Element element
Reference to the JDOM Element which represents this object. All useful information about this object should be stored in and accessible from this Element.

ns

protected org.jdom.Namespace ns
Namespace of the JDOM Element which represents this object.

propertiesbox

protected java.lang.Class propertiesbox
Class that is used to generate a properties box for this type of PNLabel.

contextmenu

protected java.lang.Class contextmenu
Class that is used to generate a context (right-click) menu for this type of PNLabel.

beingMoved

protected boolean beingMoved

selected

protected boolean selected

firsttime

protected boolean firsttime

fillcolour

protected java.awt.Color fillcolour

normalfill

protected java.awt.Color normalfill

highlightfill

protected java.awt.Color highlightfill

height

protected int height

width

protected int width

lastX

protected int lastX

lastY

protected int lastY

offset

protected int offset

xoffset

protected int xoffset

yoffset

protected int yoffset

scaling

protected int scaling

textspace

protected int textspace

xPress

protected int xPress

yPress

protected int yPress

id

protected java.lang.String id
Locally-stored copy of the object's unique id.

rotation

protected int rotation
Constructor Detail

PNLabel

public PNLabel(org.jdom.Element element)
Parameters:
element - a JDOM Element which contains all the relevant data for this Petri net object, e.g. the <place> element.
Method Detail

paintComponent

public void paintComponent(java.awt.Graphics g)
The function which draws the PNLabel on screen. Overridden in subclasses of PNLabel.
Overrides:
paintComponent in class javax.swing.JComponent

returnElement

public org.jdom.Element returnElement()
An access function that returns the JDOM Element which this PNLabel represents.
Returns:
the JDOM Element object for this PNLabel.

changeElement

public void changeElement(org.jdom.Element newElement)
Changes the element this PNLabel is representing. Not currently used in the program.

returnSelected

public boolean returnSelected()
Returns:
true if this PNLabel is selected, false if not.

highlight

public void highlight(boolean highlight)
Should not be called directly: call select instead. Deals with highlighting: changes the displayed colour of the PNLabel, and sets the boolean selected.

select

public void select(boolean select)
Selects the PNLabel. Uses the PNAnimator associated with the current display to deal with highlighting.
See Also:
PNAnimator

selectOnly

public void selectOnly(boolean select)
Selects the PNLabel without unselecting others in the display.
See Also:
PNAnimator

getPreferredSize

public java.awt.Dimension getPreferredSize()
Overrides:
getPreferredSize in class javax.swing.JComponent

dofirst

protected void dofirst()

updatePosition

protected void updatePosition()

updateLocation

protected void updateLocation(java.awt.event.MouseEvent e)

updateLocation

protected void updateLocation(int newx,
                              int newy)

setPosition

public void setPosition(int x,
                        int y)
Update DOM with new values and set the label position. The parameters given are the x,y coordinates for the screen position, which may vary from the coordinates stored in the JDOM: this is because the XML file stores the centre position of the element, while the JLabel refers to the top left corner.
Parameters:
x - the x position on screen
y - the y position on screen

getJX

public int getJX()
Get X value from the JDOM Document Defaults to 0 if not found

getJY

public int getJY()
Get Y value from the JDOM Document Defaults to 0 if not found

setJX

protected void setJX(int x)
Set X value in the JDOM Document note this may need conversion from the actual x,y values for the label

setJY

protected void setJY(int y)
Set Y value in the JDOM Document note this may need conversion from the actual x,y values for the label

updateBounds

protected void updateBounds()
may be overridden to deal with different sizes and shapes of labels.

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

doubleclickAction

public void doubleclickAction()
Override in subclasses to produce required functionality

showContextMenu

public void showContextMenu(java.awt.event.MouseEvent e)
Brings up the right-click popup menu. The class is determined by the local variable propertiesbox.

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

getDisplayPane

public DisplayPane getDisplayPane()
Returns:
The DisplayPane which contains this PNLabel.

makeGraphics

public static org.jdom.Element makeGraphics(java.lang.String x,
                                            java.lang.String y,
                                            org.jdom.Namespace ns)
Creates a graphics JDOM Element for use by a new PN element.
Returns:
<graphics> element corresponding to this PNLabel's current values

getID

public java.lang.String getID()
Returns:
locally-stored unique id of the Petri net object

myElementName

public java.lang.String myElementName()

remove

public DisplayPane remove()
Function that should be called when the element is removed from the Petri Net. May override in subclasses to do custom display cleanup as necessary. Removes both the element from the JDOM and the PNLabel from the DisplayPane that contains it.
Returns:
The DisplayPane that contained the PNLabel.

isActive

public boolean isActive()
Override in subclasses to indicate when an element is enabled within the net.

addToken

public void addToken()
Override this as necessary (eg for PlaceLabel).
See Also:
PlaceLabel, ArcLabel

remToken

public void remToken()
Override as necessary (eg for PlaceLabel).
See Also:
PlaceLabel, ArcLabel

getLinkedLabels

public java.util.List getLinkedLabels()
Override in subclasses to return a list of PNLabels which are linked to this PNLabel.
Returns:
a List of PNLabels which are linked to this PNLabel.

updateSelf

public void updateSelf()
Function which allows the label to update itself (eg for modifying screen display) in response to changes in the underlying JDOM Element. Override in subclasses.

getToolspecific

public org.jdom.Element getToolspecific()
Function to find and return the Toolspecific element corresponding to this tool. If not found, returns null.

makeToolspecific

public org.jdom.Element makeToolspecific()
Function to make a Toolspecific element - assumes one does not exist already. (check with getToolspecific first) Returns the new element.