FreeHEP API
Version current

org.freehep.swing.graphics
Class GraphicalSelectionPanel

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
All Implemented Interfaces:
Accessible, EventListener, ImageObserver, KeyListener, MenuContainer, MouseListener, MouseMotionListener, Serializable
Direct Known Subclasses:
AbstractRegionSelectionPanel, PointSelectionPanel, RotationSelectionPanel

public class GraphicalSelectionPanel
extends JPanel
implements MouseListener, KeyListener, MouseMotionListener, Serializable

The primary superclass of all graphical selection panels. These panels are expected to handle all of the interaction with the user, and generate a GraphicalSelectionEvent when a selection has been made. Note that GraphicalSelectionPanels use the information about the size of the component to send back meaningful zoom transformation and the like. To keep these calculations simple, Borders are not allowed on these components. If a Border is desired, then embed the selection panel within a container and put the Border on the container.

Version:
$Id: GraphicalSelectionPanel.java,v 1.10 2004/01/19 21:23:53 duns Exp $
Author:
Charles Loomis
See Also:
Serialized Form
Source Code:
GraphicalSelectionPanel.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  ActionMap actionMap
          The hash map which maps keys to actions.
protected  org.freehep.swing.graphics.GraphicalSelectionPanel.SelectionAction defaultModeAction
          The "Leave" action in the popup menu.
protected  org.freehep.swing.graphics.GraphicalSelectionPanel.SelectionAction nextAction
          The "Next" action in the popup menu.
protected  org.freehep.swing.graphics.GraphicalSelectionPanel.SelectionAction previousAction
          The "Previous" action in the popup menu.
protected  LinkedList selectionActions
          The list of selection actions.
protected static Stroke thickStroke
          Thick stroke for the black part of the selection box.
protected static Stroke thinStroke
          Thin stroke for the white part of the selection box.
 
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
GraphicalSelectionPanel()
          Creates a selection panel which is transparent.
 
Method Summary
protected  void addActionEntry(int keyCode, Action action)
          This utility method binds an action to a particular key.
protected  void addActionEntry(KeyStroke keyStroke, Action action)
          This utility method binds an action to a KeyStroke.
 void addGraphicalSelectionListener(GraphicalSelectionListener listener)
          Add a GraphicalSelectionListener.
protected  void cancelPopupProcessing()
          This resets a flag which indicates when a popup menu is being processed.
protected  void fireGraphicalSelectionMade(GraphicalSelectionEvent gsEvent)
          Send the GraphicalSelectionMade event to all currently registered GraphicalSelectionListeners.
 Border getBorder()
          This component does not support borders.
 JPopupMenu getPopupMenu()
          This method returns the popup menu for this component.
 boolean isProcessingPopup(MouseEvent e)
          This method determines whether or not a popup menu is being processed.
 void keyPressed(KeyEvent e)
          Invoked when a key has been pressed.
 void keyReleased(KeyEvent e)
          Process key-released events.
 void keyTyped(KeyEvent e)
          Invoked when a key has been typed.
protected  void makeSelectionEvent(int type)
          A utility function which creates an appropriate selection event when the user accepts the current selection and sends it to all listeners.
 void mouseClicked(MouseEvent e)
          Invoked when the mouse has been clicked on a component.
 void mouseDragged(MouseEvent e)
          Invoked when a mouse button is pressed on a component and then dragged.
 void mouseEntered(MouseEvent e)
          Invoked when the mouse enters a component.
 void mouseExited(MouseEvent e)
          Invoked when the mouse exits a component.
 void mouseMoved(MouseEvent e)
          Invoked when the mouse button has been moved on a component (with no buttons down).
 void mousePressed(MouseEvent e)
          Invoked when the mouse button has been pressed on a component.
 void mouseReleased(MouseEvent e)
          Invoked when a mouse button has been released on a component.
 void removeGraphicalSelectionListener(GraphicalSelectionListener listener)
          Remove a GraphicalSelectionListener.
 void resetSelection()
          The default implementation of this method does nothing.
 void setBorder(Border border)
          This component does not support borders.
 void setBounds(int x, int y, int width, int height)
          Moves and resizes this component.
protected  void setSelectionActionsEnabled(boolean enable)
          Activate or inactivate all of the selection actions.
protected  boolean testPopupTrigger(MouseEvent e)
          A utility method which tests to see if the given mouse event should trigger the popup menu.
 
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, paintComponent, 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

selectionActions

protected LinkedList selectionActions
The list of selection actions.


actionMap

protected ActionMap actionMap
The hash map which maps keys to actions.


defaultModeAction

protected org.freehep.swing.graphics.GraphicalSelectionPanel.SelectionAction defaultModeAction
The "Leave" action in the popup menu. Created here as an Action so that subclasses can more easily enable and disable this item.


nextAction

protected org.freehep.swing.graphics.GraphicalSelectionPanel.SelectionAction nextAction
The "Next" action in the popup menu. Created here as an Action so that subclasses can more easily enable and disable this item.


previousAction

protected org.freehep.swing.graphics.GraphicalSelectionPanel.SelectionAction previousAction
The "Previous" action in the popup menu. Created here as an Action so that subclasses can more easily enable and disable this item.


thinStroke

protected static final Stroke thinStroke
Thin stroke for the white part of the selection box. Set the miter limit so that the drawing doesn't extend outside of the bounding box.


thickStroke

protected static final Stroke thickStroke
Thick stroke for the black part of the selection box. Set the miter limit so that the drawing doesn't extend outside of the bounding box.

Constructor Detail

GraphicalSelectionPanel

public GraphicalSelectionPanel()
Creates a selection panel which is transparent.

Method Detail

setSelectionActionsEnabled

protected void setSelectionActionsEnabled(boolean enable)
Activate or inactivate all of the selection actions.


resetSelection

public void resetSelection()
The default implementation of this method does nothing. Subclasses should provide the needed functionality to ensure that the selection is no longer visible after this method is called.


getPopupMenu

public JPopupMenu getPopupMenu()
This method returns the popup menu for this component. This may be modified by subclasses of this event to provide needed menu items.

Returns:
the component's popup menu

cancelPopupProcessing

protected void cancelPopupProcessing()
This resets a flag which indicates when a popup menu is being processed. This should be called by subclasses when the ActionEvent from a popup menu is received.


isProcessingPopup

public boolean isProcessingPopup(MouseEvent e)
This method determines whether or not a popup menu is being processed. If it is then this will return true and the mouse event should be ignored.

Parameters:
e - MouseEvent passed into mouse handling routine
Returns:
a boolean indicating whether or not to ignore the mouse event

setBorder

public final void setBorder(Border border)
This component does not support borders. If this method is called with any non-null argument, then an IllegalArgumentException is thrown. If a border is desired, then this component should be embedded within container which has one.

Parameters:
border - must be null

getBorder

public final Border getBorder()
This component does not support borders. Null is always returned by this method.

Returns:
null

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Moves and resizes this component. This is overridden so that the selection can be reset if the size changes.

Parameters:
x - x-coordinate of component
y - y-coordinate of component
width - width of the component
height - height of the component

addGraphicalSelectionListener

public void addGraphicalSelectionListener(GraphicalSelectionListener listener)
Add a GraphicalSelectionListener.

Parameters:
listener - the GraphicalSelectionListener to add

removeGraphicalSelectionListener

public void removeGraphicalSelectionListener(GraphicalSelectionListener listener)
Remove a GraphicalSelectionListener.

Parameters:
listener - the GraphicalSelectionListener to remove

fireGraphicalSelectionMade

protected void fireGraphicalSelectionMade(GraphicalSelectionEvent gsEvent)
Send the GraphicalSelectionMade event to all currently registered GraphicalSelectionListeners.

Parameters:
gsEvent - the GraphicalSelectionEvent which is sent to all currently registered GraphicalSelectionListeners

mouseClicked

public void mouseClicked(MouseEvent e)
Invoked when the mouse has been clicked on a component. This is an empty method which subclasses should override if necessary.

Specified by:
mouseClicked in interface MouseListener
Parameters:
e - MouseEvent describing action

mouseEntered

public void mouseEntered(MouseEvent e)
Invoked when the mouse enters a component. This method just requests the keyboard focus. Subclasses which override this method should also request the keyboard focus with a call to requestFocus().

Specified by:
mouseEntered in interface MouseListener
Parameters:
e - MouseEvent describing action

mouseExited

public void mouseExited(MouseEvent e)
Invoked when the mouse exits a component. This is an empty method which subclasses should override if necessary.

Specified by:
mouseExited in interface MouseListener
Parameters:
e - MouseEvent describing action

mousePressed

public void mousePressed(MouseEvent e)
Invoked when the mouse button has been pressed on a component. This is an empty method which subclasses should override if necessary.

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

mouseReleased

public void mouseReleased(MouseEvent e)
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
Parameters:
e - MouseEvent describing action

mouseDragged

public void mouseDragged(MouseEvent e)
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
Parameters:
e - MouseEvent describing action

mouseMoved

public void mouseMoved(MouseEvent e)
Invoked when the mouse button has been moved on a component (with no buttons down). This is an empty method which subclasses should override if necessary.

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

keyPressed

public void keyPressed(KeyEvent e)
Invoked when a key has been pressed. This is an empty method which subclasses should override if necessary.

Specified by:
keyPressed in interface KeyListener
Parameters:
e - KeyEvent describing key which has been pressed.

keyReleased

public void keyReleased(KeyEvent e)
Process key-released events. This defines and uses the following key bindings: Subclasses may override this method to provide additional key-bindings. However if the subclass doesn't handle a particular key event, this method should be called.

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

keyTyped

public void keyTyped(KeyEvent e)
Invoked when a key has been typed. This is an empty method which subclasses should override if necessary.

Specified by:
keyTyped in interface KeyListener
Parameters:
e - KeyEvent describing key which has been typed.

makeSelectionEvent

protected void makeSelectionEvent(int type)
A utility function which creates an appropriate selection event when the user accepts the current selection and sends it to all listeners.


testPopupTrigger

protected boolean testPopupTrigger(MouseEvent e)
A utility method which tests to see if the given mouse event should trigger the popup menu. Normally, Java itself has an isPopupTrigger() method, but this doesn't work reliably under Windows. This method will return true if the mouse click is on the right button.


addActionEntry

protected void addActionEntry(int keyCode,
                              Action action)
This utility method binds an action to a particular key. The associated action will be done when the given key is typed.


addActionEntry

protected void addActionEntry(KeyStroke keyStroke,
                              Action action)
This utility method binds an action to a KeyStroke. The associated action will be done when the given KeyStroke is encountered.


FreeHEP API
Version current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.