tnt.gui
Class ScrollablePaintPanel

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 tnt.gui.ScrollablePaintPanel
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.MouseInputListener, javax.swing.Scrollable

public class ScrollablePaintPanel
extends javax.swing.JPanel
implements javax.swing.event.MouseInputListener, javax.swing.Scrollable

This class encapsulates a panel that displays a background image and on top of which, allows the user to draw rectangular outlines (encapsulated as Rectangle2D.Double objects).

Version:
1.0 - 01/2006
Author:
Steven J. Castellucci
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
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
protected  javax.swing.ImageIcon bkgdImage
          The background image
protected  java.awt.Color color
          The colour of the outlines
protected  javax.swing.ListModel dataModel
          The model containing all the outlines
protected  int HANDLE_SIZE
          The width and height of the (square) outline handles
protected  int mouseDownX
          The position of the last mouse pres
protected  int mouseDownY
          The position of the last mouse pres
protected  int mouseX
          The current position of the mouse
protected  int mouseY
          The current position of the mouse
static int MOVE_ACTION
          The current mouse movement represents moving the selected outline.
protected  java.awt.geom.Rectangle2D.Double moveHandle
          Rectangles representing handles to move and resize the selected outline
static int NO_ACTION
          The current mouse movement represents no particular action.
protected  int panelHeight
          The width and height of this panel
protected  int panelWidth
          The width and height of this panel
static int RESIZE_ACTION
          The current mouse movement represents resizing the selected outline
protected  java.awt.geom.Rectangle2D.Double resizeHandle
          Rectangles representing handles to move and resize the selected outline
static int SCROLL_INCREMENT
           
protected  java.awt.geom.Rectangle2D.Double selectedOutline
          The selected outline
protected  java.awt.geom.Rectangle2D.Double tempOutline
          The temporary outline representing one that is being created
 
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
ScrollablePaintPanel(java.awt.Color c, javax.swing.ListModel m)
          Initializes a new object.
ScrollablePaintPanel(javax.swing.ImageIcon i, java.awt.Color c, javax.swing.ListModel m)
          Initializes a new object with a background image.
 
Method Summary
 void changeColor(java.awt.Color c)
          Changes the color of the outlines to the passed color.
 void clearOutline()
          Removes the temporary outline defined by the last mouse drag.
 int getMouseMode()
          Returns the current mode of mouse movement.
 java.awt.Dimension getPreferredScrollableViewportSize()
           
 int getScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
           
 boolean getScrollableTracksViewportHeight()
           
 boolean getScrollableTracksViewportWidth()
           
 int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
           
 void mouseClicked(java.awt.event.MouseEvent me)
           
 void mouseDragged(java.awt.event.MouseEvent me)
           
 void mouseEntered(java.awt.event.MouseEvent me)
           
 void mouseExited(java.awt.event.MouseEvent me)
           
 void mouseMoved(java.awt.event.MouseEvent me)
           
 void mousePressed(java.awt.event.MouseEvent me)
           
 void mouseReleased(java.awt.event.MouseEvent me)
           
 void paintComponent(java.awt.Graphics g)
           
 void setImage(javax.swing.ImageIcon i)
          Sets the background image.
 void setSelected(int i)
          Selects (i.e., draws move and resize handles for) the outline represented by the passed index.
 
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
 

Field Detail

NO_ACTION

public static final int NO_ACTION
The current mouse movement represents no particular action.

See Also:
Constant Field Values

MOVE_ACTION

public static final int MOVE_ACTION
The current mouse movement represents moving the selected outline.

See Also:
Constant Field Values

RESIZE_ACTION

public static final int RESIZE_ACTION
The current mouse movement represents resizing the selected outline

See Also:
Constant Field Values

SCROLL_INCREMENT

public static final int SCROLL_INCREMENT
See Also:
Constant Field Values

bkgdImage

protected javax.swing.ImageIcon bkgdImage
The background image


panelHeight

protected int panelHeight
The width and height of this panel


panelWidth

protected int panelWidth
The width and height of this panel


color

protected java.awt.Color color
The colour of the outlines


dataModel

protected javax.swing.ListModel dataModel
The model containing all the outlines


mouseX

protected int mouseX
The current position of the mouse


mouseY

protected int mouseY
The current position of the mouse


mouseDownX

protected int mouseDownX
The position of the last mouse pres


mouseDownY

protected int mouseDownY
The position of the last mouse pres


selectedOutline

protected java.awt.geom.Rectangle2D.Double selectedOutline
The selected outline


tempOutline

protected java.awt.geom.Rectangle2D.Double tempOutline
The temporary outline representing one that is being created


moveHandle

protected java.awt.geom.Rectangle2D.Double moveHandle
Rectangles representing handles to move and resize the selected outline


resizeHandle

protected java.awt.geom.Rectangle2D.Double resizeHandle
Rectangles representing handles to move and resize the selected outline


HANDLE_SIZE

protected final int HANDLE_SIZE
The width and height of the (square) outline handles

See Also:
Constant Field Values
Constructor Detail

ScrollablePaintPanel

ScrollablePaintPanel(java.awt.Color c,
                     javax.swing.ListModel m)
Initializes a new object.

Parameters:
c - the default color of the outlines.
m - the list to contain the outlines (as Rectangle2D.Double objects) and maintained by the business logic of the containing frame.

ScrollablePaintPanel

ScrollablePaintPanel(javax.swing.ImageIcon i,
                     java.awt.Color c,
                     javax.swing.ListModel m)
Initializes a new object with a background image.

Parameters:
i - the background image.
c - the default color of the outlines.
m - the list to contain the outlines (as Rectangle2D.Double objects) and maintained by the business logic of the containing frame.
Method Detail

setImage

public void setImage(javax.swing.ImageIcon i)
Sets the background image.

Parameters:
i - the background image.

paintComponent

public void paintComponent(java.awt.Graphics g)
Overrides:
paintComponent in class javax.swing.JComponent

setSelected

public void setSelected(int i)
Selects (i.e., draws move and resize handles for) the outline represented by the passed index.

Parameters:
i - the outline to be selected, as represented by its index in the data model (-1 to select none).

changeColor

public void changeColor(java.awt.Color c)
Changes the color of the outlines to the passed color.

Parameters:
c - the new color.

getMouseMode

public int getMouseMode()
Returns the current mode of mouse movement. For further information, see the static constants for this class.

Returns:
int representing current mouse movement.

clearOutline

public void clearOutline()
Removes the temporary outline defined by the last mouse drag.


mouseClicked

public void mouseClicked(java.awt.event.MouseEvent me)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent me)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent me)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent me)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent me)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent me)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent me)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

getPreferredScrollableViewportSize

public java.awt.Dimension getPreferredScrollableViewportSize()
Specified by:
getPreferredScrollableViewportSize in interface javax.swing.Scrollable

getScrollableBlockIncrement

public int getScrollableBlockIncrement(java.awt.Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Specified by:
getScrollableBlockIncrement in interface javax.swing.Scrollable

getScrollableUnitIncrement

public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Specified by:
getScrollableUnitIncrement in interface javax.swing.Scrollable

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Specified by:
getScrollableTracksViewportWidth in interface javax.swing.Scrollable

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Specified by:
getScrollableTracksViewportHeight in interface javax.swing.Scrollable


Copyright © 2006 Steven Castellucci and Scott MacKenzie. All Rights Reserved.