edu.southern.computing.oopj
Class GraphicalObject

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by edu.southern.computing.oopj.GraphicalObject
All Implemented Interfaces:
InteractiveArea, java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible
Direct Known Subclasses:
GraphicalText

public class GraphicalObject
extends javax.swing.JPanel
implements InteractiveArea

GraphicalObjects are persistent visual images that users can manipulate within a viewport. Graphical objects can receive user input from the pointing device and keyboard.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
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 edu.southern.computing.oopj.InteractiveArea
BLACK, BLUE, CROSSHAIR, CYAN, DARK_GRAY, GRAY, GREEN, HAND, LIGHT_GRAY, MAGENTA, MOVE, ORANGE, PINK, RED, TRANSPARENT, VERSION, WHITE, YELLOW
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
GraphicalObject(int width, int height)
          Creates a graphical object with a given width and height.
 
Method Summary
 void addNotify()
          Called when a graphical object is added to another graphical component such as a viewport or another graphical object.
 void draw()
          Called when this graphical object must be rendered within a viewport.
 void drawLine(int startX, int startY, int endX, int endY)
          Draws a line with the current drawing color.
 void drawLine(int startX, int startY, int endX, int endY, java.awt.Color color)
          Draws a line with the given color.
 void drawOval(int left, int top, int width, int height)
          Draws an oval with the current drawing color.
 void drawOval(int left, int top, int width, int height, java.awt.Color color)
          Draws an oval with the given color.
 void drawPolygon(int... coords)
          Draws a polygon with the current color.
 void drawRectangle(int left, int top, int width, int height)
          Draws a rectangle with the current drawing color.
 void drawRectangle(int left, int top, int width, int height, java.awt.Color color)
          Draws a rectangle with the given color.
 void drawString(java.lang.String message, int x, int y)
          Draws a string with the current color.
 void fillOval(int left, int top, int width, int height)
          Paints a filled oval with the current color.
 void fillOval(int left, int top, int width, int height, java.awt.Color color)
          Paints a filled oval with the given color.
 void fillPolygon(int... coords)
          Paints a filled polygon with the current color.
 void fillRectangle(int left, int top, int width, int height)
          Paints a filled rectangle with the current color.
 void fillRectangle(int left, int top, int width, int height, java.awt.Color color)
          Paints a filled rectangle with the given color.
 char getKeyTyped()
          Returns the key typed by the user during the latest keyboard interaction event.
 int getMouseX()
          Returns the x position of the latest mouse event.
 int getMouseY()
          Returns the y position of the latest mouse event.
 boolean isMovable()
          Indicates if the user can move the object.
 void keyPressed(java.awt.event.KeyEvent e)
          Called when the user presses down a key when the graphical object has the keyboard focus.
 void keyReleased(java.awt.event.KeyEvent e)
          Called when the user releases a pressed down a key when the graphical object has the keyboard focus.
 void keyTyped()
          Called when the user presses and releases a key when the graphical object has the keyboard focus.
 void keyTyped(java.awt.event.KeyEvent e)
          Called when the user presses and releases a key when the graphical object has the keyboard focus.
 void mouseClicked()
          Called when the user presses and releases a mouse button when the pointer is over the graphical object.
 void mouseClicked(java.awt.event.MouseEvent e)
          Called when the user presses and releases a mouse button when the pointer is over the graphical object.
 void mouseDragged()
          Called when the user drags the mouse when the pointer is over the graphical object.
 void mouseDragged(java.awt.event.MouseEvent e)
          Called when the user drags the mouse when the pointer is over the graphical object.
 void mouseEntered()
          Called when the user moves the pointer into the graphical object.
 void mouseEntered(java.awt.event.MouseEvent e)
          Called when the user moves the pointer into the graphical object.
 void mouseExited()
          Called when the user moves the pointer out of the graphical object.
 void mouseExited(java.awt.event.MouseEvent e)
          Called when the user moves the pointer out of the graphical object.
 void mouseMoved()
          Called when the user moves the mouse when the pointer is over the graphical object.
 void mouseMoved(java.awt.event.MouseEvent e)
          Called when the user moves the mouse when the pointer is over the graphical object.
 void mousePressed()
          Called when the user presses a mouse button when the pointer is over the graphical object.
 void mousePressed(java.awt.event.MouseEvent e)
          Called when the user presses a mouse button when the pointer is over the graphical object.
 void mouseReleased()
          Called when the user releases a mouse button when the pointer is over the graphical object.
 void mouseReleased(java.awt.event.MouseEvent e)
          Called when the user releases a mouse button when the pointer is over the graphical object.
 void paintComponent(java.awt.Graphics g)
          Called when this graphical object must be rendered within a viewport.
 void removeNotify()
          Called when a graphical object is removed from its current containing graphical component.
static int round(double d)
          Rounds the double to the nearest integer.
 void setColor(java.awt.Color color)
          Draws a rectangle with the current drawing color.
 void setContextMenu(ContextMenu menu)
          Attaches a given context menu to this graphical object/
 void setMovable(boolean flag)
          Determines if the user can move the object.
protected  void updateRoot(GraphicalObject root)
           
 void visuallyUpdate()
          Forces the redrawing of this graphical object.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GraphicalObject

public GraphicalObject(int width,
                       int height)
Creates a graphical object with a given width and height.

Parameters:
width - the width of the graphical object
height - the height of the graphical object
Method Detail

updateRoot

protected void updateRoot(GraphicalObject root)
Parameters:
root -

addNotify

public void addNotify()
Called when a graphical object is added to another graphical component such as a viewport or another graphical object.

Overrides:
addNotify in class javax.swing.JComponent

removeNotify

public void removeNotify()
Called when a graphical object is removed from its current containing graphical component.

Overrides:
removeNotify in class javax.swing.JComponent

setColor

public void setColor(java.awt.Color color)
Draws a rectangle with the current drawing color. This method should only be called from within the draw() method, or other methods called from the draw() method.

Parameters:
color - the new drawing color.

drawLine

public void drawLine(int startX,
                     int startY,
                     int endX,
                     int endY,
                     java.awt.Color color)
Draws a line with the given color.


drawLine

public void drawLine(int startX,
                     int startY,
                     int endX,
                     int endY)
Draws a line with the current drawing color.


drawRectangle

public void drawRectangle(int left,
                          int top,
                          int width,
                          int height,
                          java.awt.Color color)
Draws a rectangle with the given color.


drawRectangle

public void drawRectangle(int left,
                          int top,
                          int width,
                          int height)
Draws a rectangle with the current drawing color.


fillRectangle

public void fillRectangle(int left,
                          int top,
                          int width,
                          int height,
                          java.awt.Color color)
Paints a filled rectangle with the given color.


fillRectangle

public void fillRectangle(int left,
                          int top,
                          int width,
                          int height)
Paints a filled rectangle with the current color.


drawOval

public void drawOval(int left,
                     int top,
                     int width,
                     int height,
                     java.awt.Color color)
Draws an oval with the given color.


drawOval

public void drawOval(int left,
                     int top,
                     int width,
                     int height)
Draws an oval with the current drawing color.


fillOval

public void fillOval(int left,
                     int top,
                     int width,
                     int height,
                     java.awt.Color color)
Paints a filled oval with the given color.


fillOval

public void fillOval(int left,
                     int top,
                     int width,
                     int height)
Paints a filled oval with the current color.


drawPolygon

public void drawPolygon(int... coords)
Draws a polygon with the current color. Pass the (x,y) coordinates of the polygon's vertices: x1, y1, x2, y2, x3, y3, ...


fillPolygon

public void fillPolygon(int... coords)
Paints a filled polygon with the current color. Pass the (x,y) coordinates of the polygon's vertices: x1, y1, x2, y2, x3, y3, ...


drawString

public void drawString(java.lang.String message,
                       int x,
                       int y)
Draws a string with the current color.


setMovable

public void setMovable(boolean flag)
Determines if the user can move the object.


isMovable

public boolean isMovable()
Indicates if the user can move the object.


mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Called when the user presses and releases a mouse button when the pointer is over the graphical object. Subclasses normally override the parameterless version of this method.

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Called when the user moves the pointer into the graphical object. Subclasses normally override the parameterless version of this method.

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Called when the user moves the pointer out of the graphical object. Subclasses normally override the parameterless version of this method.

Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Called when the user presses a mouse button when the pointer is over the graphical object. Subclasses normally override the parameterless version of this method.

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Called when the user releases a mouse button when the pointer is over the graphical object. Subclasses normally override the parameterless version of this method.

Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Called when the user drags the mouse when the pointer is over the graphical object. Subclasses normally override the parameterless version of this method.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Called when the user moves the mouse when the pointer is over the graphical object. Subclasses normally override the parameterless version of this method.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseClicked

public void mouseClicked()
Called when the user presses and releases a mouse button when the pointer is over the graphical object.


mouseEntered

public void mouseEntered()
Called when the user moves the pointer into the graphical object.


mouseExited

public void mouseExited()
Called when the user moves the pointer out of the graphical object.


mousePressed

public void mousePressed()
Called when the user presses a mouse button when the pointer is over the graphical object.


mouseReleased

public void mouseReleased()
Called when the user releases a mouse button when the pointer is over the graphical object.


mouseDragged

public void mouseDragged()
Called when the user drags the mouse when the pointer is over the graphical object.


mouseMoved

public void mouseMoved()
Called when the user moves the mouse when the pointer is over the graphical object.


getMouseX

public int getMouseX()
Returns the x position of the latest mouse event.


getMouseY

public int getMouseY()
Returns the y position of the latest mouse event.


keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Called when the user presses down a key when the graphical object has the keyboard focus.

Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Called when the user releases a pressed down a key when the graphical object has the keyboard focus.

Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Called when the user presses and releases a key when the graphical object has the keyboard focus. Subclasses normally override the parameterless version of this method.

Specified by:
keyTyped in interface java.awt.event.KeyListener

keyTyped

public void keyTyped()
Called when the user presses and releases a key when the graphical object has the keyboard focus.


getKeyTyped

public char getKeyTyped()
Returns the key typed by the user during the latest keyboard interaction event.

Returns:
the key typed by the user during the latest keyboard interaction event

paintComponent

public void paintComponent(java.awt.Graphics g)
Called when this graphical object must be rendered within a viewport. Subclasses normally override draw() instead of this method.

Overrides:
paintComponent in class javax.swing.JComponent

draw

public void draw()
Called when this graphical object must be rendered within a viewport. Subclasses should override this method to provide custom drawing behavior.


visuallyUpdate

public void visuallyUpdate()
Forces the redrawing of this graphical object.


setContextMenu

public void setContextMenu(ContextMenu menu)
Attaches a given context menu to this graphical object/

Specified by:
setContextMenu in interface InteractiveArea
Parameters:
menu - the context menu to attach.

round

public static int round(double d)
Rounds the double to the nearest integer.

Parameters:
d - the double value to round.
Returns:
the rounded value of d.