org.freehep.swing.graphics
Class AbstractRegionSelectionPanel

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 org.freehep.swing.graphics.GraphicalSelectionPanel
                      extended by org.freehep.swing.graphics.AbstractRegionSelectionPanel
All Implemented Interfaces:
KeyListener, MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible
Direct Known Subclasses:
ParallelogramSelectionPanel, RectangularSelectionPanel, RotatedRectangleSelectionPanel, SquareSelectionPanel, XSkewSelectionPanel, XSliceSelectionPanel, YSkewSelectionPanel, YSliceSelectionPanel

public abstract class AbstractRegionSelectionPanel
extends GraphicalSelectionPanel

This abstract class defines the majority of the functionality needed to make selections of arbitrary parallelogram regions on the screen.

Version:
$Id: AbstractRegionSelectionPanel.java 8584 2006-08-10 23:06:37Z duns $
Author:
Charles Loomis, Mark Donszelmann
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
Component.BaselineResizeBehavior
 
Field Summary
static int NO_CONTROL_POINT
          A constant which flags that no control point was near the mouse-pressed event.
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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
AbstractRegionSelectionPanel()
          This constructor makes a new AbstractRegionSelectionPanel.
 
Method Summary
static Cursor compassCursor(String type, int dx, int dy, int n, boolean diagonal)
          returns the appropriate cursor for any of the compass points.
 int forceXCoordinateWithinBounds(int x)
          A utility method which forces the x-coordinate to be within the component boundries.
 int forceYCoordinateWithinBounds(int y)
          A utility method which forces the y-coordinate to be within the component boundries.
 Cursor getControlPointCursor(int index)
          Returns the Cursor to be displayed for a certain control point and the default cursor for this SelectionPanel for an index of NO_CONTROL_POINT.
abstract  int getNumberOfControlPoints()
          Useful subclasses must define the number of control points on the selected region.
 boolean getVisibleGuides()
          Get whether or not the guides are visible.
abstract  void initializeControlPoints(int x, int y)
          Initialize the control points.
abstract  boolean isValidSelection()
          This returns whether the current selected region is valid.
 void keyReleased(KeyEvent e)
          Process key-released events.
abstract  AffineTransform makeAffineTransform()
          Make the affine transform which corresponds to this rectangular selection.
 Polygon makeOutlinePolygon()
          Make the outline of the selection.
 void mouseDragged(MouseEvent e)
          Invoked when a mouse button is pressed on a component and then dragged.
 void mouseMoved(MouseEvent e)
          Changes the active control point according to mouse movements
 void mousePressed(MouseEvent e)
          Handle the mousePressed events.
 void mouseReleased(MouseEvent e)
          Invoked when a mouse button has been released on a component.
 void paintComponent(Graphics g)
          Repaint this component.
 void resetSelection()
          Make the selection box invisible.
 void setVisibleGuides(boolean visibleGuides)
          Determine whether or not to display guide lines.
abstract  void updateActiveControlPoint(int x, int y)
          Change the active control point to the point (x,y).
 
Methods inherited from class org.freehep.swing.graphics.GraphicalSelectionPanel
addGraphicalSelectionListener, getBorder, getPopupMenu, isProcessingPopup, keyPressed, keyTyped, mouseClicked, mouseEntered, mouseExited, removeGraphicalSelectionListener, setBorder, setBounds
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBounds, getClientProperty, 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, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, 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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NO_CONTROL_POINT

public static final int NO_CONTROL_POINT
A constant which flags that no control point was near the mouse-pressed event.

See Also:
Constant Field Values
Constructor Detail

AbstractRegionSelectionPanel

public AbstractRegionSelectionPanel()
This constructor makes a new AbstractRegionSelectionPanel. This constructor only sets the visiblilty flag and the last-drawn rectangle valid flag to false.

Method Detail

setVisibleGuides

public void setVisibleGuides(boolean visibleGuides)
Determine whether or not to display guide lines.


getVisibleGuides

public boolean getVisibleGuides()
Get whether or not the guides are visible.


keyReleased

public void keyReleased(KeyEvent e)
Process key-released events. This allows selection panels which derive from this one to automatically have the default behaviour.
 arrow keys:    move the active control point in the specified
                direction.
 backspace key: reset selection region (make invisible).
 delete key:    reset selection region (make invisible).
 escape key:    leave selection mode (make component invisible).
 tab key:       next selection mode (make next component visible).
 enter key:     accept selection region (send off region selected
                event)
 spacebar:      accept selection region (send off region selected
                event)
 

Specified by:
keyReleased in interface KeyListener
Overrides:
keyReleased in class GraphicalSelectionPanel
Parameters:
e - KeyEvent describing the key which has been released

mouseMoved

public void mouseMoved(MouseEvent e)
Changes the active control point according to mouse movements

Specified by:
mouseMoved in interface MouseMotionListener
Overrides:
mouseMoved in class GraphicalSelectionPanel
Parameters:
e - MouseEvent describing action

mousePressed

public void mousePressed(MouseEvent e)
Handle the mousePressed events.

Specified by:
mousePressed in interface MouseListener
Overrides:
mousePressed in class GraphicalSelectionPanel
Parameters:
e - MouseEvent describing action

forceXCoordinateWithinBounds

public int forceXCoordinateWithinBounds(int x)
A utility method which forces the x-coordinate to be within the component boundries.

Parameters:
x - x-coordinate to force within boundries
Returns:
modified x-value

forceYCoordinateWithinBounds

public int forceYCoordinateWithinBounds(int y)
A utility method which forces the y-coordinate to be within the component boundries.

Parameters:
y - y-coordinate to force within boundries
Returns:
modified y-value

mouseDragged

public void mouseDragged(MouseEvent e)
Description copied from class: GraphicalSelectionPanel
Invoked when a mouse button is pressed on a component and then dragged. This is an empty method which subclasses should override if necessary.

Specified by:
mouseDragged in interface MouseMotionListener
Overrides:
mouseDragged in class GraphicalSelectionPanel
Parameters:
e - MouseEvent describing action

mouseReleased

public void mouseReleased(MouseEvent e)
Description copied from class: GraphicalSelectionPanel
Invoked when a mouse button has been released on a component. This is an empty method which subclasses should override if necessary.

Specified by:
mouseReleased in interface MouseListener
Overrides:
mouseReleased in class GraphicalSelectionPanel
Parameters:
e - MouseEvent describing action

isValidSelection

public abstract boolean isValidSelection()
This returns whether the current selected region is valid. Generally if the area has zero volume, then this method should return false.


resetSelection

public void resetSelection()
Make the selection box invisible.

Overrides:
resetSelection in class GraphicalSelectionPanel

initializeControlPoints

public abstract void initializeControlPoints(int x,
                                             int y)
Initialize the control points. Subclasses must provide an implementation of this method which initializes the control points to reasonable values given the first mouse-pressed coordinates, and must also set the activeCtrlPt to the index of the control point which should be active.

Parameters:
x - x-coordinate of initial mouse-pressed event
y - y-coordinate of initial mouse-pressed event

updateActiveControlPoint

public abstract void updateActiveControlPoint(int x,
                                              int y)
Change the active control point to the point (x,y). Subclasses should implement this routine to get the behaviour which is desired. This is the place to impose constraints on how the control points can move. NOTE: repaintPanel() should be called at the end of this method to update the display.

Parameters:
x - x-coordinate of the new point
y - y-coordinate of the new point

getNumberOfControlPoints

public abstract int getNumberOfControlPoints()
Useful subclasses must define the number of control points on the selected region. The first four control points define the outer extent of the selected region. This method MUST NOT return a number less than four.


getControlPointCursor

public Cursor getControlPointCursor(int index)
Returns the Cursor to be displayed for a certain control point and the default cursor for this SelectionPanel for an index of NO_CONTROL_POINT. Return of null will not change the cursor. Subclasses should override this method to provide a default cursor and/or to provide cursors for the different control points.


paintComponent

public void paintComponent(Graphics g)
Repaint this component. This must be overridden by subclasses so that the selection region appears correctly. The subclass should check the visibility flag (visible) to decide if any painting needs to be done.

Overrides:
paintComponent in class JComponent
Parameters:
g - Graphics context in which to draw

makeOutlinePolygon

public Polygon makeOutlinePolygon()
Make the outline of the selection. Note that the order of the points is not guaranteed.

Returns:
a polygon object which describes the outline of the selection

makeAffineTransform

public abstract AffineTransform makeAffineTransform()
Make the affine transform which corresponds to this rectangular selection.

Returns:
AffineTransform which describes the selected region

compassCursor

public static Cursor compassCursor(String type,
                                   int dx,
                                   int dy,
                                   int n,
                                   boolean diagonal)
returns the appropriate cursor for any of the compass points. If both dx and dy are zero, null is returned

Parameters:
type - type of cursor (Resize/Rotation)
dx - screen x of direction
dy - screen y of direction (positive is down)
n - number of compass points (4 or 8)
diagonal - in case n = 4, a diagonal compass point is returned
Returns:
XX_RESIZE_CURSOR


Copyright © 2000-2013 FreeHEP. All Rights Reserved.