NGP.Containers
Class DrawingPanel

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--NGP.Containers.Panel
                                |
                                +--NGP.Containers.DrawingPanel
All Implemented Interfaces:
Accessible, Colorable, Container, ImageObserver, MenuContainer, Serializable, Sizeable
Direct Known Subclasses:
ReactiveDrawingPanel

public class DrawingPanel
extends Panel

A Panel that allows Graphics to be drawn. NGP automatically draws objects by putting them in this special Container. The DrawingPanel keeps track of the Graphics and tells them to draw when it is appropriate. It has some special methods, some of which will be necessary for the normal user, some which aren't.

Author:
Matt Chotin (mhc)
See Also:
Serialized Form

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 NGP.Colorable
DEFAULT_GRAY
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DrawingPanel(Container container)
          Create a DrawingPanel with the container as its parent.
 
Method Summary
 void addGraphic(Graphic g)
          Normal users need not use this!
 boolean lowerGraphic(Graphic g)
          Lower the graphic to be behind one more grpahic on the screen.
 void paintComponent(Graphics g)
          Normal users need not use this!
 void paintGraphics(Graphics g)
          Normal users need not use this!
 boolean raiseGraphic(Graphic g)
          Raise the graphic to be in front of one more graphic on the screen.
 Point randomPoint()
          Give a random point in this DrawingPanel.
 void removeAllGraphics()
          Normal users need not use this!
 void removeGraphic(Graphic g)
          Normal users need not use this!
 void saveAsJPEG(File file)
          Save the DrawingPanel as a JPEG to the file that was passed in.
 
Methods inherited from class NGP.Containers.Panel
getColor, getDimension, isFocusTraversable, setColor, setDimension
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, 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, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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
 
Methods inherited from interface NGP.Container
add, remove
 

Constructor Detail

DrawingPanel

public DrawingPanel(Container container)
Create a DrawingPanel with the container as its parent.

Parameters:
container - the graphical container for this Panel
Method Detail

addGraphic

public void addGraphic(Graphic g)
Normal users need not use this!

Add the Graphic to the vector and add the mouse listener so that it will be able to react.

Parameters:
g - the Graphic to add

removeGraphic

public void removeGraphic(Graphic g)
Normal users need not use this!

Remove the Graphic from the vector and remove the mouse listener so that it won't be able to react.

Parameters:
g - the Graphic to remove

removeAllGraphics

public void removeAllGraphics()
Normal users need not use this!

Remove all of the graphics from the vector and remove their mouse listeners so that they won't be able to react.


raiseGraphic

public boolean raiseGraphic(Graphic g)
Raise the graphic to be in front of one more graphic on the screen.

Parameters:
g - the Graphic that should be raised.
Returns:
a boolean indicating whether it is at the top (true is yes)

lowerGraphic

public boolean lowerGraphic(Graphic g)
Lower the graphic to be behind one more grpahic on the screen.

Parameters:
g - the Graphic that should be lowered.
Returns:
a boolean indicating whether it is at the bottom (true is yes).

paintGraphics

public void paintGraphics(Graphics g)
Normal users need not use this!

Loop through all of the NGP.Graphics and paint each one. If we are only updating part of the screen, the Graphics instance will be set correctly so we don't have to worry about it.

Parameters:
g - the Graphics that we use

paintComponent

public void paintComponent(Graphics g)
Normal users need not use this!

Called by AWT to paint the panel. Ours just paints all the contained Graphics.

Overrides:
paintComponent in class JComponent
Parameters:
g - the Graphics we should use

randomPoint

public Point randomPoint()
Give a random point in this DrawingPanel.

Returns:
a randomly generated Point

saveAsJPEG

public void saveAsJPEG(File file)
Save the DrawingPanel as a JPEG to the file that was passed in. You may want to have your application provide a FileDialog which will then call this method passing in the file that was selected.

Parameters:
file - the java.io.File that this image should be saved to