public class Display2D extends javax.swing.JComponent implements Steppable, Manipulating2D
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().
Modifier and Type | Class and Description |
---|---|
class |
Display2D.InnerDisplay2D
The object which actually does all the drawing.
|
class |
Display2D.OptionPane
Option pane
|
javax.swing.JComponent.AccessibleJComponent
Modifier and Type | Field and Description |
---|---|
static javax.swing.ImageIcon |
CAMERA_ICON |
static javax.swing.ImageIcon |
CAMERA_ICON_P |
static javax.swing.ImageIcon |
CLOSED_HAND_CURSOR_P |
java.lang.String |
DEFAULT_PREFERENCES_KEY |
javax.swing.JScrollPane |
display
The scroll view which holds the insideDisplay.
|
javax.swing.Box |
header
The component bar at the top of the Display2D.
|
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 java.lang.String |
javaVersion
Set to the version number
|
static javax.swing.ImageIcon |
LAYERS_ICON |
static javax.swing.ImageIcon |
LAYERS_ICON_P |
javax.swing.JToggleButton |
layersbutton
The button which pops up the layers menu
|
static javax.swing.ImageIcon |
MOVIE_OFF_ICON |
static javax.swing.ImageIcon |
MOVIE_OFF_ICON_P |
static javax.swing.ImageIcon |
MOVIE_ON_ICON |
static javax.swing.ImageIcon |
MOVIE_ON_ICON_P |
javax.swing.JButton |
movieButton
The button which starts or stops a movie
|
static javax.swing.ImageIcon |
OPEN_HAND_CURSOR_P |
javax.swing.JButton |
optionButton
The button which pops up the option pane
|
Display2D.OptionPane |
optionPane
Our option pane
|
static javax.swing.ImageIcon |
OPTIONS_ICON |
static javax.swing.ImageIcon |
OPTIONS_ICON_P |
javax.swing.JPopupMenu |
popup
The popup layers menu
|
static java.lang.Object[] |
REDRAW_OPTIONS |
static javax.swing.ImageIcon |
REFRESH_ICON |
static javax.swing.ImageIcon |
REFRESH_ICON_P |
javax.swing.JToggleButton |
refreshbutton
The button which pops up the refresh menu
|
javax.swing.JPopupMenu |
refreshPopup
The refresh menu
|
NumberTextField |
scaleField
The field for scaling values
|
static int |
SELECTION_MODE_MULTI |
static int |
SELECTION_MODE_SINGLE |
javax.swing.JComboBox |
skipBox
The combo box for skipping frames
|
NumberTextField |
skipField
The field for skipping frames
|
javax.swing.JFrame |
skipFrame
The frame which holds the skip controls
|
javax.swing.JButton |
snapshotButton
The button which snaps a screenshot
|
protected long |
stepInterval |
protected double |
timeInterval |
static int |
TYPE_PDF |
static int |
TYPE_PNG |
static int |
UPDATE_RULE_ALWAYS |
static int |
UPDATE_RULE_INTERNAL_TIME |
static int |
UPDATE_RULE_NEVER |
static int |
UPDATE_RULE_STEPS
Used internally and by Display3D to indicate
|
static int |
UPDATE_RULE_WALLCLOCK_TIME |
protected int |
updateRule |
protected long |
wallInterval |
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
Display2D(double width,
double height,
GUIState simulation)
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).
|
Display2D(double width,
double height,
GUIState simulation,
long interval)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
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,
boolean visible)
Attaches a portrayal to the Display2D, along with the provided
human-readable name for the portrayal.
|
void |
attach(FieldPortrayal2D portrayal,
java.lang.String name,
double x,
double y,
boolean visible)
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.
|
void |
attach(FieldPortrayal2D portrayal,
java.lang.String name,
java.awt.geom.Rectangle2D.Double bounds,
boolean visible)
Attaches a portrayal to the Display2D, along with the provided
human-readable name for the portrayal.
|
void |
attach(Inspector inspector,
java.lang.String name)
A convenience function: creates a popup menu item of the given name which, when selected, will display the
given inspector in the Console.
|
void |
clearSelections() |
javax.swing.JFrame |
createFrame()
Creates a frame holding the Display2D.
|
void |
createInspector(LocationWrapper wrapper,
GUIState simulation)
Inspects the following object.
|
void |
createInspectors(Bag locationWrappers,
GUIState simulation)
Determines the inspectors appropriate for the wrappers, and sends
them on to the Controller.
|
void |
createInspectors(java.awt.geom.Point2D point,
GUIState simulation)
Determines the inspectors appropriate for the given point, and sends
them on to the Controller.
|
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 |
detachAll()
Detatches all portrayals from the Display2D.
|
protected void |
finalize()
Quits the Display2D.
|
java.awt.Paint |
getBackdrop()
Returns the backdrop color or paint.
|
DrawInfo2D |
getDrawInfo2D(FieldPortrayal2D portrayal,
java.awt.geom.Point2D point)
Constructs a DrawInfo2D for the given portrayal, or null if failed.
|
DrawInfo2D |
getDrawInfo2D(FieldPortrayal2D portrayal,
java.awt.geom.Rectangle2D clip)
Constructs a DrawInfo2D for the given portrayal, or null if failed.
|
java.awt.Frame |
getFrame()
Returns the frame holding this Component.
|
boolean |
getMouseChangesOffset()
Sets whether the user can change the offset by right-mouse-button-dragging,
(or on OS X) Command-dragging or two-finger-click-dragging.
|
java.awt.geom.Point2D.Double |
getOffset()
Returns the offset of the origin of the display.
|
boolean |
getPrecise()
Returns true if this display has been set to always draw precisely.
|
java.lang.String |
getPreferencesKey() |
double |
getScale()
Returns the scale (the zoom value) of the Display2D
|
Double2D |
getScrollPosition()
Returns the current scroll positions (x and y) as proportional values between 0.0 (minimum scroll position) and 1.0 (maximum scroll position).
|
LocationWrapper[] |
getSelectedWrappers()
Returns as LocationWrappers all the currently selected objects in the
display.
|
int |
getSelectionMode()
Returns whether selecting a region will select all the objects within that region (the default), or instead a single object.
|
boolean |
handleMouseEvent(java.awt.event.MouseEvent event) |
boolean |
isClipping()
Returns true if the Display2D is clipping the drawing area to the user-specified
height and width
|
Bag[] |
objectsHitBy(java.awt.geom.Point2D point)
Returns LocationWrappers for all the objects which overlap with the point specified by 'point'.
|
Bag[] |
objectsHitBy(java.awt.geom.Rectangle2D.Double rect)
Returns LocationWrappers for all the objects which fall within the coordinate rectangle specified by rect.
|
void |
performSelection(Bag locationWrappers) |
void |
performSelection(LocationWrapper wrapper)
Selects the following object, deselecting other objects if so asked.
|
void |
performSelection(java.awt.geom.Point2D point) |
void |
performSelection(java.awt.geom.Rectangle2D.Double rect) |
void |
quit()
Quits the Display2D.
|
protected void |
rebuildRefreshPopup() |
protected void |
rebuildSkipFrame() |
void |
removeListeners()
Removes all mouse listeners, mouse motion listeners, and Key listeners from this component.
|
void |
requestUpdate()
Asks Display2D to update itself next iteration regardless of the current redrawing/updating rule.
|
void |
reset()
Resets the Display2D so it reschedules itself and clears out all selections.
|
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 |
setMouseChangesOffset(boolean val)
Sets whether the user can change the offset by right-mouse-button-dragging,
(or on OS X) Command-dragging or two-finger-click-dragging.
|
void |
setMovingWrapper(LocationWrapper wrapper)
Declares an object to be the one under control of MovablePortrayal2D.
|
void |
setOffset(double x,
double y)
Sets the offset of the origin of the display.
|
void |
setOffset(java.awt.geom.Point2D.Double d)
Sets the offset of the origin of the display.
|
void |
setPrecise(boolean precise)
Sets this display to always draw precisely (or not).
|
void |
setPreferencesKey(java.lang.String s)
If you have more than one Display2D in your simulation and you want them to have
different preferences, set each to a different key value.
|
void |
setScale(double val)
Sets the scale (the zoom value) of the Display2D
|
void |
setScrollPosition(Double2D vals)
Sets the current scroll positions (x and y) to proportional values between 0.0 (minimum scroll position) and 1.0 (maximum scroll position).
|
void |
setScrollPosition(double x,
double y)
Sets the current scroll positions (x and y) to proportional values between 0.0 (minimum scroll position) and 1.0 (maximum scroll position).
|
void |
setSelectionMode(int val)
Sets whether selecting a region will select all the objects within that region (the default), or instead a single object.
|
boolean |
shouldUpdate()
Returns whether it's time to update.
|
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() |
void |
takeSnapshot(java.io.File file,
int type) |
addAncestorListener, addNotify, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, 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, updateUI
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, transferFocusDownCycle, validate, validateTree
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, getAccessibleContext, 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, 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, transferFocusBackward, transferFocusUpCycle
public java.lang.String DEFAULT_PREFERENCES_KEY
public static final boolean isMacOSX
public static final boolean isWindows
public static final java.lang.String javaVersion
public static final javax.swing.ImageIcon OPEN_HAND_CURSOR_P
public static final javax.swing.ImageIcon CLOSED_HAND_CURSOR_P
public static final javax.swing.ImageIcon LAYERS_ICON
public static final javax.swing.ImageIcon LAYERS_ICON_P
public static final javax.swing.ImageIcon REFRESH_ICON
public static final javax.swing.ImageIcon REFRESH_ICON_P
public static final javax.swing.ImageIcon MOVIE_ON_ICON
public static final javax.swing.ImageIcon MOVIE_ON_ICON_P
public static final javax.swing.ImageIcon MOVIE_OFF_ICON
public static final javax.swing.ImageIcon MOVIE_OFF_ICON_P
public static final javax.swing.ImageIcon CAMERA_ICON
public static final javax.swing.ImageIcon CAMERA_ICON_P
public static final javax.swing.ImageIcon OPTIONS_ICON
public static final javax.swing.ImageIcon OPTIONS_ICON_P
public static final java.lang.Object[] REDRAW_OPTIONS
public Display2D.InnerDisplay2D insideDisplay
public Display2D.OptionPane optionPane
public javax.swing.JScrollPane display
public javax.swing.Box header
public javax.swing.JPopupMenu popup
public javax.swing.JToggleButton layersbutton
public javax.swing.JPopupMenu refreshPopup
public javax.swing.JToggleButton refreshbutton
public javax.swing.JButton movieButton
public javax.swing.JButton snapshotButton
public javax.swing.JButton optionButton
public NumberTextField scaleField
public NumberTextField skipField
public javax.swing.JComboBox skipBox
public javax.swing.JFrame skipFrame
public static final int SELECTION_MODE_MULTI
public static final int SELECTION_MODE_SINGLE
public static final int TYPE_PDF
public static final int TYPE_PNG
public static final int UPDATE_RULE_STEPS
public static final int UPDATE_RULE_INTERNAL_TIME
public static final int UPDATE_RULE_WALLCLOCK_TIME
public static final int UPDATE_RULE_ALWAYS
public static final int UPDATE_RULE_NEVER
protected int updateRule
protected long stepInterval
protected double timeInterval
protected long wallInterval
public Display2D(double width, double height, GUIState simulation, long interval)
public Display2D(double width, double height, GUIState simulation)
public boolean getPrecise()
public void setPrecise(boolean precise)
public void setPreferencesKey(java.lang.String s)
public java.lang.String getPreferencesKey()
public void removeListeners()
public void setScale(double val)
public double getScale()
public boolean isClipping()
public void setClipping(boolean val)
public void setBackdrop(java.awt.Paint c)
public java.awt.Paint getBackdrop()
public Double2D getScrollPosition()
public void setScrollPosition(Double2D vals)
public void setScrollPosition(double x, double y)
public void setOffset(double x, double y)
public void setOffset(java.awt.geom.Point2D.Double d)
public java.awt.geom.Point2D.Double getOffset()
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
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 void attach(FieldPortrayal2D portrayal, java.lang.String name, boolean visible)
public void attach(FieldPortrayal2D portrayal, java.lang.String name, double x, double y, boolean visible)
public void attach(FieldPortrayal2D portrayal, java.lang.String name, java.awt.geom.Rectangle2D.Double bounds, boolean visible)
public void attach(Inspector inspector, java.lang.String name)
public java.util.ArrayList detachAll()
public Bag[] objectsHitBy(java.awt.geom.Rectangle2D.Double rect)
portrayals
list.public Bag[] objectsHitBy(java.awt.geom.Point2D point)
portrayals
list.public DrawInfo2D getDrawInfo2D(FieldPortrayal2D portrayal, java.awt.geom.Point2D point)
public DrawInfo2D getDrawInfo2D(FieldPortrayal2D portrayal, java.awt.geom.Rectangle2D clip)
public LocationWrapper[] getSelectedWrappers()
public void performSelection(LocationWrapper wrapper)
performSelection
in interface Manipulating2D
public void clearSelections()
public void performSelection(java.awt.geom.Point2D point)
public void performSelection(java.awt.geom.Rectangle2D.Double rect)
public int getSelectionMode()
public void setSelectionMode(int val)
public void performSelection(Bag locationWrappers)
public void createInspector(LocationWrapper wrapper, GUIState simulation)
public void createInspectors(java.awt.geom.Point2D point, GUIState simulation)
public void createInspectors(Bag locationWrappers, GUIState simulation)
public void createInspectors(java.awt.geom.Rectangle2D.Double rect, GUIState simulation)
public javax.swing.JFrame createFrame()
public java.awt.Frame getFrame()
public void takeSnapshot(java.io.File file, int type) throws java.io.IOException
java.io.IOException
public void takeSnapshot()
public void startMovie()
public void stopMovie()
public void requestUpdate()
public boolean shouldUpdate()
public void setMouseChangesOffset(boolean val)
public boolean getMouseChangesOffset()
public void setMovingWrapper(LocationWrapper wrapper)
setMovingWrapper
in interface Manipulating2D
public boolean handleMouseEvent(java.awt.event.MouseEvent event)
protected void rebuildSkipFrame()
protected void rebuildRefreshPopup()