gov.nasa.ial.mde.ui.graph
Class CartesianGraph

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 gov.nasa.ial.mde.ui.graph.CartesianGraph
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class CartesianGraph
extends JPanel

The CartesianGraph class is used to draw the solutions found by the Solver.

Since:
1.0
Version:
1.0
Author:
Dan Dexter, Dat Truong
See Also:
Solver, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, 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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
CartesianGraph(Solver solver, MdeSettings settings)
          Creates an instance of CartesianGraph using the specified solver and settings.
 
Method Summary
 void clearGraph()
          Clears the graph which will result in the sonification trace and simulation ball indicators being cleared, the one-to-one aspect ratio is disabled, and the AWT Thread will be notified to repaint the CartesianGraph component.
 void dilate(double factor)
          Dialate (change the size of) the graph given the specified scale factor.
 void drawGraph()
          Draws a graph of the solutions from the solver.
 void drawGraph(MdeSettings settings)
          Draws a graph of the solutions from the solver using the specified settings.
 void drawGraphToImage(Image graphImage)
          Draws a graph of the solutions from the solver to the specified image.
 void drawSimulationBall(double x, double y, double xNormal, double yNormal)
          Draws the simulation ball if it is enabled at the specified X and Y coordinates and normal vector.
 void drawTrace(double x, double y)
          Draws a trace at the given X and Y coordinates if the trace is enabled in the MdeSettings.
 CartesianGraph duplicate()
          Create a duplicate of this CartesianGraph instance.
 void enableBlackAndWhite(boolean useBlackWhiteShade)
          If true the graph will be drawn using black and white with shades of gray.
 void enableOneToOneAspectRatio(boolean enable)
          If true the graph will be drawn with a width to height aspect ratio of one-to-one (1:1).
 boolean isBlackAndWhite()
          Returns true if the graph will be drawn using black and white with shades of gray.
 boolean isOneToOneAspectRatio()
          Returns true if the graph will be drawn with a width to height aspect ratio of one-to-one (1:1).
 boolean isSimulationBallEnabled()
          Returns true if the simulation ball is enabled.
 void paintComponent(Graphics g)
          Paints the CartesianGraph component.
 void setSimulationBallEnabled(boolean enable)
          If true the simulation ball will be drawn.
 void translate(double dx, double dy)
          Translate the center of the graph given the specified X and Y offsets.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, 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, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, 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
 
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

CartesianGraph

public CartesianGraph(Solver solver,
                      MdeSettings settings)
Creates an instance of CartesianGraph using the specified solver and settings.

Parameters:
solver - The solutions from this solver will be graphed.
settings - The settings to use for the graph.
Method Detail

duplicate

public CartesianGraph duplicate()
Create a duplicate of this CartesianGraph instance.

Returns:
a duplicate of the CartesianGraph instance

translate

public void translate(double dx,
                      double dy)
Translate the center of the graph given the specified X and Y offsets.

Parameters:
dx - the amount to shift the X-axis by
dy - the amount to shift the Y-axis by
See Also:
dilate(double)

dilate

public void dilate(double factor)
Dialate (change the size of) the graph given the specified scale factor.

Parameters:
factor - the amount to scale the size of the graph by
See Also:
translate(double,double)

isOneToOneAspectRatio

public boolean isOneToOneAspectRatio()
Returns true if the graph will be drawn with a width to height aspect ratio of one-to-one (1:1).

With a one-to-one aspect ratio a circle will appear as a perfectly round circle and not stretched out like an egg.

The default value for this property is true.

Returns:
true for a one-to-one aspect ratio, false otherwise.
See Also:
enableOneToOneAspectRatio(boolean)

enableOneToOneAspectRatio

public void enableOneToOneAspectRatio(boolean enable)
If true the graph will be drawn with a width to height aspect ratio of one-to-one (1:1).

With a one-to-one aspect ratio a circle will appear as a perfectly round circle. Otherwise the graph will be drawn using the the current size of the CartesianGraph component and a circle could appear to be stretched out in an egg shape because the aspect ration may not be one-to-one.

The default value for this property is true.

Parameters:
enable - true to enable a one-to-one aspect ratio, false to use the full size of the CartesianGraph component for drawing.
See Also:
isOneToOneAspectRatio()

isBlackAndWhite

public boolean isBlackAndWhite()
Returns true if the graph will be drawn using black and white with shades of gray. Returns false if the graph will be in color.

The default value for this property is false.

Returns:
true if the graph will be in black and white, false otherwise for a color graph.
See Also:
enableBlackAndWhite(boolean)

enableBlackAndWhite

public void enableBlackAndWhite(boolean useBlackWhiteShade)
If true the graph will be drawn using black and white with shades of gray. If false the graph will be in color.

The default value for this property is false.

Parameters:
useBlackWhiteShade - true for a black and white graph, false for a color graph
See Also:
isBlackAndWhite()

clearGraph

public void clearGraph()
Clears the graph which will result in the sonification trace and simulation ball indicators being cleared, the one-to-one aspect ratio is disabled, and the AWT Thread will be notified to repaint the CartesianGraph component.

See Also:
paintComponent(Graphics)

drawGraph

public void drawGraph()
Draws a graph of the solutions from the solver. The AWT Thread will be notified to repaint the CartesianGraph component.


drawGraph

public void drawGraph(MdeSettings settings)
Draws a graph of the solutions from the solver using the specified settings. The settings will be updated to use those specified and then the drawGraph() method is called.

Parameters:
settings -
See Also:
drawGraph()

drawGraphToImage

public void drawGraphToImage(Image graphImage)
Draws a graph of the solutions from the solver to the specified image.

Parameters:
graphImage - the image to draw the graph to

drawTrace

public void drawTrace(double x,
                      double y)
Draws a trace at the given X and Y coordinates if the trace is enabled in the MdeSettings. If the solution is polar then a ball will be drawn at the given coordinates, otherwise a vertical line will be drawn at the given Y cordinate.

Parameters:
x - the X coordinate of the trace
y - the Y coordinate of the trace
See Also:
MdeSettings

isSimulationBallEnabled

public boolean isSimulationBallEnabled()
Returns true if the simulation ball is enabled.

The default value for this property is false.

Returns:
true if the simulation ball is enabled, false otherwise
See Also:
setSimulationBallEnabled(boolean), drawSimulationBall(double,double,double,double)

setSimulationBallEnabled

public void setSimulationBallEnabled(boolean enable)
If true the simulation ball will be drawn. If false the simulation ball will not be drawn. The AWT Thread will be notified to repaint the CartesianGraph component.

The default value for this property is false.

Parameters:
enable - true to enable/show the simulation ball, false to disable/hide it
See Also:
isSimulationBallEnabled(), drawSimulationBall(double,double,double,double)

drawSimulationBall

public void drawSimulationBall(double x,
                               double y,
                               double xNormal,
                               double yNormal)
Draws the simulation ball if it is enabled at the specified X and Y coordinates and normal vector. In addition the AWT Thread will be notified to repaint the CartesianGraph component.

The normal vector is used to allow the ball to roll along the given point.

Parameters:
x - the X coordinate of the ball location
y - the Y coordinate of the ball location
xNormal - the X-axis component of the normal vector for the ball
yNormal - the Y-axis component of the normal vector for the ball
See Also:
isSimulationBallEnabled(), setSimulationBallEnabled(boolean)

paintComponent

public void paintComponent(Graphics g)
Paints the CartesianGraph component.

Overrides:
paintComponent in class JComponent
Parameters:
g - the Graphics context to paint to
See Also:
JComponent.paintComponent(java.awt.Graphics)


NASA Johnson Space Center Learning Technologies Project