dbrown
Class RTGraphicView

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by dbrown.RTGraphicView
All Implemented Interfaces:
IView, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class RTGraphicView
extends javax.swing.JComponent
implements IView

Displays a right triangle as a graphic within a JComponent with a blank border of size BORDER. The upper right corner of the triangle can be selected and used to change the size of the triangle by clicking and dragging with with mouse.

Version:
2006-11-01
Author:
David Brown from Byron Weber-Becker
See Also:
Serialized Form

Nested Class Summary
private  class RTGraphicView.MListener
          Inner class the allows the right triangle to be selected or deselected.
private  class RTGraphicView.MMListener
          Inner class for allowing the triangle to be dragged in order to change its size.
 
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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int BORDER
          The default blank border size.
private  RTModel model
          The right triangle model.
private  double scale
          How much should the triangle be scaled?
private  boolean selected
          Did the user select the triangle to resize it?
 
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
RTGraphicView(RTModel newModel)
          The View constructor.
 
Method Summary
private  void drawHandle(java.awt.Graphics g, int top, int left, int bottom, int right)
          Draw handles for resizing the triangle.
private  void drawTriangle(java.awt.Graphics g, int top, int left, int bottom, int right)
          Draw the triangle.
protected  double fromX(int x)
          Convert from the component's X coordinate to the model's X coordinate.
protected  double fromY(int y)
          Convert from the component's Y coordinate to the model's Y coordinate.
private  void layoutView()
          Empty method: the JComponent contains no further elements.
private  boolean onTopCorner(int x, int y)
          Determines if mouse is on the top corner of the triangle.
 void paintComponent(java.awt.Graphics g)
          Overrides JComponent's paintComponent method.
private  void registerListeners()
          Adds the mouse listeners to the JComponent.
protected  int toX(double modelX)
          Convert from the model's X coordinate to the component's X coordinate.
protected  int toY(double modelY)
          Convert from the model's Y coordinate to the component's Y coordinate.
 void updateView()
          All views that implement this class must have an updateView method.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, 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
 
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
 

Field Detail

BORDER

public static final int BORDER
The default blank border size.

See Also:
Constant Field Values

model

private RTModel model
The right triangle model.


scale

private double scale
How much should the triangle be scaled?


selected

private boolean selected
Did the user select the triangle to resize it?

Constructor Detail

RTGraphicView

public RTGraphicView(RTModel newModel)
The View constructor.

Parameters:
newModel -
Method Detail

drawHandle

private void drawHandle(java.awt.Graphics g,
                        int top,
                        int left,
                        int bottom,
                        int right)
Draw handles for resizing the triangle.

Parameters:
g -
top -
left -
bottom -
right -

drawTriangle

private void drawTriangle(java.awt.Graphics g,
                          int top,
                          int left,
                          int bottom,
                          int right)
Draw the triangle.

Parameters:
g -
top -
left -
bottom -
right -

fromX

protected double fromX(int x)
Convert from the component's X coordinate to the model's X coordinate.

Parameters:
x -
Returns:
the model's X coordinate.

fromY

protected double fromY(int y)
Convert from the component's Y coordinate to the model's Y coordinate.

Parameters:
y -
Returns:
the model's y coordinate

layoutView

private void layoutView()
Empty method: the JComponent contains no further elements.


onTopCorner

private boolean onTopCorner(int x,
                            int y)
Determines if mouse is on the top corner of the triangle.

Parameters:
x -
y -
Returns:
whether the mouse is on the top corner of the triangle.

paintComponent

public void paintComponent(java.awt.Graphics g)
Overrides JComponent's paintComponent method. Draws the triangle and adds a handle to the top corner of the triangle if the triangle has been selected.

Overrides:
paintComponent in class javax.swing.JComponent
See Also:
JComponent.paintComponent(java.awt.Graphics)

registerListeners

private void registerListeners()
Adds the mouse listeners to the JComponent.


toX

protected int toX(double modelX)
Convert from the model's X coordinate to the component's X coordinate.

Parameters:
modelX - the model's X coordinate
Returns:
the component's X coordinate

toY

protected int toY(double modelY)
Convert from the model's Y coordinate to the component's Y coordinate.

Parameters:
modelY - the model's Y coordinate
Returns:
the component's Y coordinate

updateView

public void updateView()
Description copied from interface: IView
All views that implement this class must have an updateView method. (All methods in an interface are actually abstract by default.)

Specified by:
updateView in interface IView