FreeHEP API
Version current

org.freehep.swing.graphics
Class AbstractRegionSelectionPanel

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byorg.freehep.swing.graphics.GraphicalSelectionPanel
                      extended byorg.freehep.swing.graphics.AbstractRegionSelectionPanel
All Implemented Interfaces:
Accessible, EventListener, ImageObserver, KeyListener, MenuContainer, MouseListener, MouseMotionListener, Serializable
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,v 1.10 2002/06/12 23:15:15 duns Exp $
Author:
Charles Loomis, Mark Donszelmann
See Also:
Serialized Form
Source Code:
AbstractRegionSelectionPanel.java

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  int activeCtrlPt
          Which control point is the active one, or which one can be controlled from the arrow keys on the keyboard?
protected static int ctrlPtSize
          The size of the control point boxes.
protected  int hitThreshold
          The maximum distance from a control point the cursor can be and still be selected.
protected  Rectangle lastDrawnRect
          The bounding rectangle of the last box which was drawn.
protected  boolean lastDrawnRectValid
          Flag indicating whether or not the last drawn rectangle is valid.
protected  int nCtrlPts
          The number of control points for this component.
static int NO_CONTROL_POINT
          A constant which flags that no control point was near the mouse-pressed event.
protected  Rectangle rectToDraw
          The bounding rectangle of the next box to be drawn.
protected  Rectangle updateRect
          The bounding box of the region to repaint, usually the union of the rectToDraw and lastDrawnRect rectangles.
protected  boolean visible
          Flag indicating whether or not the selection box is visible.
protected  boolean visibleGuides
          Flag indicating whether or not additional guide lines should be visible.
protected  int[] xCtrlPts
          The x-coordinates of the control points.
protected  int[] yCtrlPts
          The y-coordinates of the control points.
 
Fields inherited from class org.freehep.swing.graphics.GraphicalSelectionPanel
actionMap, defaultModeAction, nextAction, previousAction, selectionActions, thickStroke, thinStroke
 
Fields inherited from class javax.swing.JComponent
accessibleContext, 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
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.
protected  void makeSelectionEvent(int actionCode)
          A utility function which creates an appropriate selection event when the user accepts the current selection.
protected  AffineTransform makeTransform(double x0, double y0, double x1, double y1, double x2, double y2)
          A utility which makes an AffineTransform given three corner points.
 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.
protected  void moveActiveControlPoint(int dx, int dy)
          A utility method which moves the currently active control point by the given delta-x and delta-y.
protected  int nearWhichControlPoint(int x, int y, int maxDist)
          Check to see if the point (x,y) is near one of the control points.
 void paintComponent(Graphics g)
          Repaint this component.
protected  void repaintPanel()
          Repaint the panel.
 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
addActionEntry, addActionEntry, addGraphicalSelectionListener, cancelPopupProcessing, fireGraphicalSelectionMade, getBorder, getPopupMenu, isProcessingPopup, keyPressed, keyTyped, mouseClicked, mouseEntered, mouseExited, removeGraphicalSelectionListener, setBorder, setBounds, setSelectionActionsEnabled, testPopupTrigger
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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
clone, equals, finalize, 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

visibleGuides

protected boolean visibleGuides
Flag indicating whether or not additional guide lines should be visible.


rectToDraw

protected Rectangle rectToDraw
The bounding rectangle of the next box to be drawn.


lastDrawnRect

protected Rectangle lastDrawnRect
The bounding rectangle of the last box which was drawn.


updateRect

protected Rectangle updateRect
The bounding box of the region to repaint, usually the union of the rectToDraw and lastDrawnRect rectangles.


visible

protected boolean visible
Flag indicating whether or not the selection box is visible.


lastDrawnRectValid

protected boolean lastDrawnRectValid
Flag indicating whether or not the last drawn rectangle is valid. (Not valid when the box is first made visible.)


hitThreshold

protected int hitThreshold
The maximum distance from a control point the cursor can be and still be selected.


ctrlPtSize

protected static int ctrlPtSize
The size of the control point boxes.


nCtrlPts

protected int nCtrlPts
The number of control points for this component.


activeCtrlPt

protected int activeCtrlPt
Which control point is the active one, or which one can be controlled from the arrow keys on the keyboard?


xCtrlPts

protected int[] xCtrlPts
The x-coordinates of the control points. The first four of these control points MUST define the outer boundries of the selected region.


yCtrlPts

protected int[] yCtrlPts
The y-coordinates of the control points. The first four of these control points MUST define the outer boundries of the selected region.

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

makeSelectionEvent

protected void makeSelectionEvent(int actionCode)
A utility function which creates an appropriate selection event when the user accepts the current selection.

Overrides:
makeSelectionEvent in class GraphicalSelectionPanel

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.


moveActiveControlPoint

protected void moveActiveControlPoint(int dx,
                                      int dy)
A utility method which moves the currently active control point by the given delta-x and delta-y. It does this by calling updateActiveControlPoint(x,y), so subclasses shouldn't normally need to override this method.

Parameters:
dx - the distance to move the x-coordinate
dy - the distance to move the y-coordinate

nearWhichControlPoint

protected int nearWhichControlPoint(int x,
                                    int y,
                                    int maxDist)
Check to see if the point (x,y) is near one of the control points. If it is, return the index of the nearest one, otherwise return NO_CONTROL_POINT.

Parameters:
x - x-coordinate to compare to control points
y - y-coordinate to compare to control points
maxDist - the maximum distance from a control point which still selects it
Returns:
the index of the nearest control point

resetSelection

public void resetSelection()
Make the selection box invisible.

Overrides:
resetSelection in class GraphicalSelectionPanel

repaintPanel

protected void repaintPanel()
Repaint the panel. Calculate the bounding box of the selection box along with associated control points.


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.

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

makeTransform

protected AffineTransform makeTransform(double x0,
                                        double y0,
                                        double x1,
                                        double y1,
                                        double x2,
                                        double y2)
A utility which makes an AffineTransform given three corner points. The first point must be the upper, left-hand corner point, the second, the upper, right-hand corner point, and the third, the lower, right-hand corner point.

Returns:
AffineTransform which does the appropriate mapping

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

FreeHEP API
Version current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.