skrueger.geotools
Class MapPaneToolBar

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 skrueger.geotools.MapPaneToolBar
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants

public class MapPaneToolBar
extends JToolBar

A toolbar to control an SelectableXMapPane (Atlas visualization). This contains two types of buttons. A group of tools for the mouse actions on the map represented by JToggleButtons, where only one tool can be activated every time. And some (general) actions, represented by normal JButtons.

Version:
1.2 Stefan Krüger
Author:
Martin Schmitz (University of Bonn/Germany)
See Also:
Serialized Form

Nested Class Summary
static class MapPaneToolBar.MapPaneToolBarAction
          Extends the AbstractAction with maintaining an ID and the MapPaneToolBar the actions 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
static int ACTION_CHARTS
           
static int ACTION_ZOOM_BACK
          Constant for the action "Zoom back" (130).
static int ACTION_ZOOM_DEFAULT
           
static int ACTION_ZOOM_FORWARD
          Constant for the action "Zoom forward" (140).
protected  ArrayList<Envelope> lastZooms
          A List to remember the last Envelopes that have been watched.
protected  SelectableXMapPane mapPane
          Holds the SelectableXMapPane this tool bar controls.
protected  JMapPaneListener mapPaneListener
          Listener to sniff the zoom actions on the map.
static ResourceProvider RESOURCE
           
protected  int selectedTool
          Tool currently selected
static int SEPERATOR0
           
static int SEPERATOR1
           
static int TOOL_INFO
          Constant for the tool "Info" (20).
static int TOOL_PAN
          Constant for the tool "Panning" (10).
static int TOOL_SELECTION_ADD
          Constant for the tool "Selection add" which adds the features to the Selection (220).
static int TOOL_SELECTION_CLEAR
          Constant for the tool "Selection Reset" which clears the selection (240).
static int TOOL_SELECTION_REMOVE
          Constant for the tool "Selection subtract" which removes the selected features from the selection (230).
static int TOOL_SELECTION_SET
          Constant for the tool "Select" which sets the Selection to the selected features (210).
static int TOOL_ZOOMIN
          Constant for the tool "Zoom In" (110).
static int TOOL_ZOOMOUT
          Constant for the tool "Zoom Out" (120).
protected  SortedMap<Integer,JComponent> toolAndActionButtons
          Holds the tool buttons of the tool bar.
protected  ButtonGroup toolButtonGroup
          Controls that only one tool button is activated.
protected  Set<MapPaneToolSelectedListener> toolSelectionListeners
          Listeners what want to be informed about a change of the selected tool
protected  boolean zoomBackForwardButtonInAction
           
protected  int zoomBackIndex
          Holds the index to the current element in lastZooms.
 
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
MapPaneToolBar()
          Creates a new toolbar.
MapPaneToolBar(SelectableXMapPane mapPane)
          Creates a new tool bar.
 
Method Summary
 void addAction(MapPaneToolBar.MapPaneToolBarAction buttonAction)
          Adds an action to the tool bar and resets the toolbar GUI.
 void addAction(MapPaneToolBar.MapPaneToolBarAction buttonAction, boolean resetToolBar)
          Adds an action to the tool bar.
 void addButtonSelectedListener(MapPaneToolSelectedListener listener)
           
 void addJComponent(JComponent component, int id, boolean resetToolBar)
          Adds any JComponent to the tool bar.
 void addSeparator(int id, JToolBar.Separator separator)
           
 void addTool(MapPaneToolBar.MapPaneToolBarAction buttonAction)
          Adds a tool to the tool bar and resets the toolbar GUI.
 void addTool(MapPaneToolBar.MapPaneToolBarAction buttonAction, boolean resetToolBar)
          Adds a tool to the tool bar.
 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 getMaxToolID()
          Returns the maximum ID of tools.
 int getMinToolID()
          Returns the minimum ID of tools.
 int getSelectedTool()
          Returns the selected tool.
 JToggleButton getToolButton(int tool)
          Returns the button for a specific tool.
protected  void init()
          Calls initToolsAndActions() and #initActions() and then puts all tool buttons and all actions buttons to the tool bar.
 void initToolBar()
          Clears the GUI of all components and adds all tool and action buttons to the tool bar.
protected  void initToolsAndActions()
          Creates the tool buttons and action buttons and seperators, adds them to toolAndActionButtons and finally creates a button group for all tools.
 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.
 void paint(Graphics g)
           
protected  void performActionButton(int action, ActionEvent e)
          Performs the action of an action button.
 void performToolButton(int tool, ActionEvent e)
          Performs the activation of a tool.
 void print(Graphics g)
          Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht wird) wird.
static String R(String key, Object... values)
           
 void removeButtonSelectedListener(MapPaneToolSelectedListener listener)
           
 JComponent removeId(int id)
           
 void setAllActionsEnabled(boolean enabled, boolean hideOnDisable)
          Sets the activation for all actions.
 void setAllToolsEnabled(boolean enabled, boolean hideOnDisable)
          Sets the activation for all tools.
 void setButtonEnabled(int id, boolean enabled)
          Sets whether a tool or action is activated or not.
 void setButtonEnabled(int id, boolean enabled, boolean hideOnDisable)
          Sets whether a tool or action is activated or not.
 void setMapPane(SelectableXMapPane mapPane)
          Sets the SelectableXMapPane controlled by this tool bar.
 void setSelectedTool(Integer tool)
          Sets the selected tool.
 
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, paintChildren, paintComponent, paintImmediately, paintImmediately, 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

RESOURCE

public static ResourceProvider RESOURCE

TOOL_PAN

public static final int TOOL_PAN
Constant for the tool "Panning" (10).

See Also:
Constant Field Values

TOOL_INFO

public static final int TOOL_INFO
Constant for the tool "Info" (20).

See Also:
Constant Field Values

SEPERATOR0

public static final int SEPERATOR0
See Also:
Constant Field Values

TOOL_ZOOMIN

public static final int TOOL_ZOOMIN
Constant for the tool "Zoom In" (110).

See Also:
Constant Field Values

ACTION_ZOOM_DEFAULT

public static final int ACTION_ZOOM_DEFAULT
See Also:
Constant Field Values

TOOL_ZOOMOUT

public static final int TOOL_ZOOMOUT
Constant for the tool "Zoom Out" (120).

See Also:
Constant Field Values

ACTION_ZOOM_BACK

public static final int ACTION_ZOOM_BACK
Constant for the action "Zoom back" (130).

See Also:
Constant Field Values

ACTION_ZOOM_FORWARD

public static final int ACTION_ZOOM_FORWARD
Constant for the action "Zoom forward" (140).

See Also:
Constant Field Values

SEPERATOR1

public static final int SEPERATOR1
See Also:
Constant Field Values

TOOL_SELECTION_CLEAR

public static final int TOOL_SELECTION_CLEAR
Constant for the tool "Selection Reset" which clears the selection (240).

See Also:
Constant Field Values

TOOL_SELECTION_SET

public static final int TOOL_SELECTION_SET
Constant for the tool "Select" which sets the Selection to the selected features (210).

See Also:
Constant Field Values

TOOL_SELECTION_ADD

public static final int TOOL_SELECTION_ADD
Constant for the tool "Selection add" which adds the features to the Selection (220).

See Also:
Constant Field Values

TOOL_SELECTION_REMOVE

public static final int TOOL_SELECTION_REMOVE
Constant for the tool "Selection subtract" which removes the selected features from the selection (230).

See Also:
Constant Field Values

ACTION_CHARTS

public static final int ACTION_CHARTS
See Also:
Constant Field Values

selectedTool

protected int selectedTool
Tool currently selected


toolAndActionButtons

protected final SortedMap<Integer,JComponent> toolAndActionButtons
Holds the tool buttons of the tool bar.


toolButtonGroup

protected ButtonGroup toolButtonGroup
Controls that only one tool button is activated.


mapPane

protected SelectableXMapPane mapPane
Holds the SelectableXMapPane this tool bar controls.


lastZooms

protected ArrayList<Envelope> lastZooms
A List to remember the last Envelopes that have been watched. Used for the zoomBack- and zoomForwardButtons *


zoomBackIndex

protected int zoomBackIndex
Holds the index to the current element in lastZooms.


mapPaneListener

protected JMapPaneListener mapPaneListener
Listener to sniff the zoom actions on the map.


zoomBackForwardButtonInAction

protected boolean zoomBackForwardButtonInAction

toolSelectionListeners

protected Set<MapPaneToolSelectedListener> toolSelectionListeners
Listeners what want to be informed about a change of the selected tool

Constructor Detail

MapPaneToolBar

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


MapPaneToolBar

public MapPaneToolBar(SelectableXMapPane mapPane)
Creates a new tool bar.

Parameters:
mapPane - SelectableXMapPane the tool bar controls
Method Detail

R

public static String R(String key,
                       Object... values)

addButtonSelectedListener

public void addButtonSelectedListener(MapPaneToolSelectedListener listener)

removeButtonSelectedListener

public void removeButtonSelectedListener(MapPaneToolSelectedListener listener)

setMapPane

public void setMapPane(SelectableXMapPane mapPane)
Sets the SelectableXMapPane controlled by this tool bar.

Parameters:
mapPane - SelectableXMapPane to control (if null this tool bar controls NOTHING!)

init

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


initToolsAndActions

protected void initToolsAndActions()
Creates the tool buttons and action buttons and seperators, adds them to toolAndActionButtons and finally creates a button group for all tools. So sub-classes which override this method should FIRST add their new tool buttons to toolAndActionButtons before calling super.initTools().


paint

public void paint(Graphics g)
Overrides:
paint in class JComponent

initToolBar

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


performToolButton

public void performToolButton(int tool,
                              ActionEvent e)
Performs the activation of a tool.

Parameters:
tool - the tool to activate
e - the event of the button

removeId

public JComponent removeId(int id)
Parameters:
id - The ID of the Component to remove. The change will not be visible until initToolBar() is called.
Returns:
null or the component that has been removed.

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

addTool

public void addTool(MapPaneToolBar.MapPaneToolBarAction buttonAction,
                    boolean resetToolBar)
Adds a tool to the tool bar. Does nothing if a tool or action with the specified ID already exists!

Parameters:
buttonAction - action for the toggle 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)

addTool

public void addTool(MapPaneToolBar.MapPaneToolBarAction buttonAction)
Adds a tool to the tool bar and resets the toolbar GUI.

Parameters:
buttonAction - action for the toggle button

addAction

public void addAction(MapPaneToolBar.MapPaneToolBarAction 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)

addJComponent

public void addJComponent(JComponent component,
                          int id,
                          boolean resetToolBar)
Adds any JComponent to the tool bar. Does nothing if a tool or action with the specified ID already exists!

Parameters:
component - A JComponent that shall be added
id - The ID associaded with the JComponent
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)

addSeparator

public void addSeparator(int id,
                         JToolBar.Separator separator)

addAction

public void addAction(MapPaneToolBar.MapPaneToolBarAction 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 any button in the MapPaneToolBar
Returns:
a JButton if id specifies an action button or JToogleButton if id specifies a tool button

getToolButton

public JToggleButton getToolButton(int tool)
Returns the button for a specific tool.

Parameters:
tool - the constant for a tool

getActionButton

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

Parameters:
action - the constant an action

setSelectedTool

public void setSelectedTool(Integer tool)
Sets the selected tool.

Parameters:
tool - ID of the tool

getSelectedTool

public int getSelectedTool()
Returns the selected tool.

Returns:
-1 if no tool is active

setButtonEnabled

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

Parameters:
id - tool or actionID
enabled - if true the tool becomes available

setButtonEnabled

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

Parameters:
id - tool or 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

setAllToolsEnabled

public void setAllToolsEnabled(boolean enabled,
                               boolean hideOnDisable)
Sets the activation for all tools.

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

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

getMaxToolID

public int getMaxToolID()
Returns the maximum ID of tools.


getMinToolID

public int getMinToolID()
Returns the minimum ID of tools.


print

public void print(Graphics g)
Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.

Overrides:
print in class JComponent