schmitzm.geotools.gui
Class JEditorToolBar

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JToolBar
                  extended by schmitzm.geotools.gui.JEditorToolBar
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants

public class JEditorToolBar
extends JToolBar

A toolbar to control the operations of a JEditorPane.

Author:
Martin Schmitz (University of Bonn/Germany)
See Also:
Serialized Form

Nested Class Summary
static class JEditorToolBar.EditorPaneToolBarAction
          Extends the AbstractAction with maintaining an ID and the JEditorToolBar the action controls.
 
Nested classes/interfaces inherited from class javax.swing.JToolBar
JToolBar.AccessibleJToolBar, JToolBar.Separator
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  SortedMap<Integer,JButton> actionButtons
          Holds the action buttons of the bar.
static int EDIT_CLEAR
          Constant for the tool "Undo all editor actions" (100).
static int EDIT_FINISH
          Constant for the tool "Finish current segment" (130).
static int EDIT_REDO
          Constant for the tool "Redo last undone editor action" (120).
static int EDIT_UNDO
          Constant for the tool "Undo last editor action" (110).
protected  JEditorPane editorPane
          Holds the JEditorPane this tool bar controls.
static int LAYER_CANCEL
          Constant for the tool "Cancel layer" (30).
static int LAYER_NEW
          Constant for the tool "New layer" (10).
static int LAYER_SAVE
          Constant for the tool "Save layer" (20).
protected  JMapPaneListener mapPaneListener
          Holds the listener, that reacts on editor actions.
 
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 javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JEditorToolBar()
          Creates a new toolbar.
JEditorToolBar(JEditorPane editorPane)
          Creates a new tool bar.
 
Method Summary
 void addAction(JEditorToolBar.EditorPaneToolBarAction buttonAction)
          Adds an action to the tool bar and resets the toolbar GUI.
 void addAction(JEditorToolBar.EditorPaneToolBarAction buttonAction, boolean resetToolBar)
          Adds an action to the tool bar.
protected  void createNewLayer()
          Starts new layer.
 JButton getActionButton(int action)
          Returns the button for a specific action.
 AbstractButton getButton(int id)
          Returns the button for a specific tool or action.
 int getMaxActionID()
          Returns the maximum ID of actions.
 int getMinActionID()
          Returns the minimum ID of actions.
protected static String getResourceString(String key, Object... params)
           
protected  void init()
          Calls initActions() and then puts all action buttons to the tool bar.
protected  void initActions()
          Creates the action buttons and adds them to actionButtons.
protected  void initToolBar()
          Clears the GUI of all components and adds all action buttons to the tool bar.
 boolean isButtonEnabled(int id)
          Checks whether a tool is activated.
 boolean isButtonIDUsed(int id)
          Checks whether a ID is already used for a tool or action.
protected  void performActionButton(int action, ActionEvent e)
          Performs the action of an action button.
 void setAllActionsEnabled(boolean enabled, boolean hideOnDisable)
          Sets the activation for all actions.
 void setButtonEnabled(int id, boolean enabled)
          Sets whether an action is activated or not.
 void setButtonEnabled(int id, boolean enabled, boolean hideOnDisable)
          Sets whether an action is activated or not.
 void setMapPane(JEditorPane editorPane)
          Sets the JEditorPane controlled by this tool bar.
protected  void updateButtonActivation(JEditorPane.EditorMode editorMode)
          Sets the enables/disables property for every toolbar button according to the current editor state.
 
Methods inherited from class javax.swing.JToolBar
add, addImpl, addSeparator, addSeparator, createActionChangeListener, createActionComponent, getAccessibleContext, getComponentAtIndex, getComponentIndex, getMargin, getOrientation, getUI, getUIClassID, isBorderPainted, isFloatable, isRollover, paintBorder, paramString, setBorderPainted, setFloatable, setLayout, setMargin, setOrientation, setRollover, 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, getBaseline, getBaselineResizeBehavior, 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, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, 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, 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, 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

LAYER_NEW

public static final int LAYER_NEW
Constant for the tool "New layer" (10).

See Also:
Constant Field Values

LAYER_SAVE

public static final int LAYER_SAVE
Constant for the tool "Save layer" (20).

See Also:
Constant Field Values

LAYER_CANCEL

public static final int LAYER_CANCEL
Constant for the tool "Cancel layer" (30).

See Also:
Constant Field Values

EDIT_CLEAR

public static final int EDIT_CLEAR
Constant for the tool "Undo all editor actions" (100).

See Also:
Constant Field Values

EDIT_UNDO

public static final int EDIT_UNDO
Constant for the tool "Undo last editor action" (110).

See Also:
Constant Field Values

EDIT_REDO

public static final int EDIT_REDO
Constant for the tool "Redo last undone editor action" (120).

See Also:
Constant Field Values

EDIT_FINISH

public static final int EDIT_FINISH
Constant for the tool "Finish current segment" (130).

See Also:
Constant Field Values

actionButtons

protected SortedMap<Integer,JButton> actionButtons
Holds the action buttons of the bar.


editorPane

protected JEditorPane editorPane
Holds the JEditorPane this tool bar controls.


mapPaneListener

protected JMapPaneListener mapPaneListener
Holds the listener, that reacts on editor actions.

Constructor Detail

JEditorToolBar

public JEditorToolBar()
Creates a new toolbar. Notice: This toolbar does nothing until setMapPane(JEditorPane) is called!


JEditorToolBar

public JEditorToolBar(JEditorPane editorPane)
Creates a new tool bar.

Parameters:
editorPane - JEditorPane the tool bar controls
Method Detail

setMapPane

public void setMapPane(JEditorPane editorPane)
Sets the JEditorPane controlled by this tool bar.

Parameters:
editorPane - JEditorPane to control (if null this tool bar controls NOTHING!)

init

protected void init()
Calls initActions() and then puts all action buttons to the tool bar.


initActions

protected void initActions()
Creates the action buttons and adds them to actionButtons.


initToolBar

protected void initToolBar()
Clears the GUI of all components and adds all action buttons to the tool bar.


performActionButton

protected void performActionButton(int action,
                                   ActionEvent e)
Performs the action of an action button.

Parameters:
tool - the action
e - the event of the button

updateButtonActivation

protected void updateButtonActivation(JEditorPane.EditorMode editorMode)
Sets the enables/disables property for every toolbar button according to the current editor state.

Parameters:
editorMode - editor mode (because some events are fired BEFORE the new mode is set)

createNewLayer

protected void createNewLayer()
Starts new layer.


addAction

public void addAction(JEditorToolBar.EditorPaneToolBarAction buttonAction,
                      boolean resetToolBar)
Adds an action to the tool bar. Does nothing if a tool or action with the specified ID already exists!

Parameters:
buttonAction - action for the button
resetToolBar - indicates whether the toolbar GUI is reset after adding the button (if adding several actions it useful only to reset the GUI for the last added tool)

addAction

public void addAction(JEditorToolBar.EditorPaneToolBarAction buttonAction)
Adds an action to the tool bar and resets the toolbar GUI.

Parameters:
buttonAction - action for the toggle button

getButton

public AbstractButton getButton(int id)
Returns the button for a specific tool or action.

Parameters:
id - the constant for a tool
Returns:
a JButton if id specifies an action button or JToogleButton if id specifies a tool button

getActionButton

public JButton getActionButton(int action)
Returns the button for a specific action.

Parameters:
action - the constant an action

setButtonEnabled

public void setButtonEnabled(int id,
                             boolean enabled)
Sets whether an action is activated or not. The visible property of the button is not affected.

Parameters:
id - actionID
enabled - if true the action becomes available

setButtonEnabled

public void setButtonEnabled(int id,
                             boolean enabled,
                             boolean hideOnDisable)
Sets whether an action is activated or not.

Parameters:
id - actionID
enabled - if true the tool becomes available
hideOnDisable - if true the button is also hidden if enabled is false

isButtonIDUsed

public boolean isButtonIDUsed(int id)
Checks whether a ID is already used for a tool or action.

Parameters:
tool - tool ID

isButtonEnabled

public boolean isButtonEnabled(int id)
Checks whether a tool is activated.

Parameters:
tool - tool ID
Returns:
false if an unknown ID is specified

setAllActionsEnabled

public void setAllActionsEnabled(boolean enabled,
                                 boolean hideOnDisable)
Sets the activation for all actions.

Parameters:
enabled - if true all actions becomes available
hideOnDisable - if true the buttons are also hidden if enabled is false

getMaxActionID

public int getMaxActionID()
Returns the maximum ID of actions.


getMinActionID

public int getMinActionID()
Returns the minimum ID of actions.


getResourceString

protected static String getResourceString(String key,
                                          Object... params)