|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
sim.display.Display2D
Display2D holds, displays, and manipulates 2D Portrayal objects, allowing the user to scale them, scroll them, change how often they're updated, take snapshots, and generate Quicktime movies. Display2D is Steppable, and each time it is stepped it redraws itself. Display2D also handles double-click events, routing them to the underlying portrayals as inspector requests.
In addition to various GUI widgets, Display2D holds a JScrollView which in turn holds a Display2D.InnerDisplay2D (a JComponent responsible for doing the actual drawing). Display2D can be placed in a JFrame; indeed it provides a convenience function to sprout its own JFrame with the method createFrame(). You can put Display2D in your own JFrame if you like, but you should try to call Display2D.quit() when the frame is disposed.
Display2D's constructor takes a height and a width; this will be the "expected" height and width of the underlying portrayal region when the Display2D is scaled to 1.0 (the default). The portrayals will also have an origin at (0,0) -- the top left corner. Display2D will automatically clip the portrayals to the area (0,0) to (width * scale, height * scale).
Display2D's step() method is typically called from the underlying schedule thread; this means that it has to be careful about painting as Swing widgets expect to be painted in the event loop thread. Display2D handles this in two ways. First, on MacOS X, the step() method calls repaint(), which will in turn call paintComponent() from the event loop thread at a time when the underlying schedule thread is doing nothing -- see Console. Second, on Windows and XWindows, the step() method immediately calls paintComponent(). Different OSes do it differently because MacOS X is far more efficient using standard repaint() calls, which get routed through Quartz. The step() method also updates various widgets using SwingUtilities.invokeLater().
Nested Class Summary | |
class |
Display2D.InnerDisplay2D
The object which actually does all the drawing. |
class |
Display2D.OptionPane
Option pane |
Nested classes inherited from class javax.swing.JComponent |
javax.swing.JComponent.AccessibleJComponent |
Nested classes inherited from class java.awt.Container |
java.awt.Container.AccessibleAWTContainer |
Nested classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary | |
static javax.swing.ImageIcon |
CAMERA_ICON
|
Display2D.InnerDisplay2D |
insideDisplay
The 2D display inside the scroll view. |
static boolean |
isMacOSX
Set to true if we're running on a Mac |
static boolean |
isWindows
Set to true if we're running on Windows |
static javax.swing.ImageIcon |
LAYERS_ICON
|
static javax.swing.ImageIcon |
MOVIE_OFF_ICON
|
static javax.swing.ImageIcon |
MOVIE_ON_ICON
|
MovieMaker |
movieMaker
Our movie maker, if one is running, else null. |
Display2D.OptionPane |
optionPane
Our option pane |
static javax.swing.ImageIcon |
OPTIONS_ICON
|
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 java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
Display2D(double width,
double height,
GUIState simulation,
long interval)
Creates a Display2D with the provided width and height for its portrayal region, attached to the provided simulation, and displaying itself with the given interval (which must be > 0). |
Method Summary | |
void |
attach(FieldPortrayal2D portrayal,
java.lang.String name)
Attaches a portrayal to the Display2D, along with the provided human-readable name for the portrayal. |
void |
attach(FieldPortrayal2D portrayal,
java.lang.String name,
java.awt.geom.Rectangle2D.Double bounds)
Attaches a portrayal to the Display2D, along with the provided human-readable name for the portrayal. |
javax.swing.JFrame |
createFrame()
Creates a frame holding the Display2D. |
void |
createInspectors(java.awt.geom.Rectangle2D.Double rect,
GUIState simulation)
Determines the inspectors appropriate for the given selection region (rect), and sends them on to the Controller. |
java.util.ArrayList |
detatchAll()
Detatches all portrayals from the Display2D. |
static java.lang.String |
ensureFileEndsWith(java.lang.String filename,
java.lang.String ending)
Utility method. |
void |
ensureRepaintHeader()
Force-repaints the header by running the repaint through an invokeLater(), which seems to be more stable than just calling header.repaint() directly. |
protected void |
finalize()
Quits the Display2D. |
java.awt.Paint |
getBackdrop()
Returns the backdrop color or paint. |
long |
getInterval()
Gets how many ticks are skipped before the display updates itself. |
double |
getScale()
Returns the scale (the zoom value) of the Display2D |
boolean |
isClipping()
Returns true if the Display2D is clipping the drawing area to the user-specified height and width |
Bag[] |
objectsHitBy(java.awt.geom.Rectangle2D.Double rect)
Returns LocationWrappers for all the objects which fall within the coordinate rectangle specified by rect. |
void |
quit()
Quits the Display2D. |
void |
reset()
Resets the Display2D so it reschedules itself. |
void |
setBackdrop(java.awt.Paint c)
Specify the backdrop color or other paint. |
void |
setClipping(boolean val)
Sets the Display2D to clip or to not clip to the user-specified height and width when drawing |
void |
setInterval(long i)
Sets how many ticks are skipped before the display updates itself. |
void |
setScale(double val)
Sets the scale (the zoom value) of the Display2D |
void |
startMovie()
Starts a Quicktime movie on the given Display2D. |
void |
step(SimState state)
Steps the Display2D in the GUIState schedule. |
void |
stopMovie()
Stops a Quicktime movie and cleans up, flushing the remaining frames out to disk. |
void |
takeSnapshot()
Takes a snapshot of the Display2D's currently displayed simulation. |
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, getAccessibleContext, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, updateUI |
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, isFocusTraversable, 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, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final boolean isMacOSX
public static final boolean isWindows
public static final javax.swing.ImageIcon LAYERS_ICON
public static final javax.swing.ImageIcon MOVIE_ON_ICON
public static final javax.swing.ImageIcon MOVIE_OFF_ICON
public static final javax.swing.ImageIcon CAMERA_ICON
public static final javax.swing.ImageIcon OPTIONS_ICON
public MovieMaker movieMaker
public Display2D.InnerDisplay2D insideDisplay
public Display2D.OptionPane optionPane
Constructor Detail |
public Display2D(double width, double height, GUIState simulation, long interval)
Method Detail |
public void setScale(double val)
public double getScale()
public void setInterval(long i)
public long getInterval()
public boolean isClipping()
public void setClipping(boolean val)
public void setBackdrop(java.awt.Paint c)
public java.awt.Paint getBackdrop()
protected void finalize() throws java.lang.Throwable
java.lang.Throwable
public void quit()
public void reset()
public void attach(FieldPortrayal2D portrayal, java.lang.String name)
public void attach(FieldPortrayal2D portrayal, java.lang.String name, java.awt.geom.Rectangle2D.Double bounds)
public java.util.ArrayList detatchAll()
public Bag[] objectsHitBy(java.awt.geom.Rectangle2D.Double rect)
portrayals
list.
public void createInspectors(java.awt.geom.Rectangle2D.Double rect, GUIState simulation)
public void ensureRepaintHeader()
public javax.swing.JFrame createFrame()
public static java.lang.String ensureFileEndsWith(java.lang.String filename, java.lang.String ending)
public void takeSnapshot()
public void startMovie()
public void stopMovie()
public void step(SimState state)
step
in interface Steppable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |