/[schmitzm]/trunk/src/skrueger/geotools/MapPaneToolBar.java
ViewVC logotype

Diff of /trunk/src/skrueger/geotools/MapPaneToolBar.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 48 by alfonx, Fri Apr 17 12:49:33 2009 UTC revision 888 by alfonx, Thu Jun 3 10:48:43 2010 UTC
# Line 1  Line 1 
1  package skrueger.geotools;  /*******************************************************************************
2     * Copyright (c) 2009 Martin O. J. Schmitz.
3  import java.awt.Dimension;   *
4  import java.awt.event.ActionEvent;   * This file is part of the SCHMITZM library - a collection of utility
5  import java.util.ArrayList;   * classes based on Java 1.6, focusing (not only) on Java Swing
6  import java.util.SortedMap;   * and the Geotools library.
7  import java.util.TreeMap;   *
8     * The SCHMITZM project is hosted at:
9  import javax.swing.AbstractAction;   * http://wald.intevation.org/projects/schmitzm/
10  import javax.swing.AbstractButton;   *
11  import javax.swing.BorderFactory;   * This program is free software; you can redistribute it and/or
12  import javax.swing.Icon;   * modify it under the terms of the GNU Lesser General Public License
13  import javax.swing.ImageIcon;   * as published by the Free Software Foundation; either version 3
14  import javax.swing.JButton;   * of the License, or (at your option) any later version.
15  import javax.swing.JToggleButton;   *
16  import javax.swing.JToolBar;   * This program is distributed in the hope that it will be useful,
17     * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  import org.apache.log4j.Logger;   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19     * GNU General Public License for more details.
20  import schmitzm.geotools.gui.JMapPane;   *
21  import schmitzm.geotools.map.event.JMapPaneEvent;   * You should have received a copy of the GNU Lesser General Public License (license.txt)
22  import schmitzm.geotools.map.event.JMapPaneListener;   * along with this program; if not, write to the Free Software
23  import schmitzm.geotools.map.event.MapAreaChangedEvent;   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24  import schmitzm.swing.ButtonGroup;   * or try this link: http://www.gnu.org/licenses/lgpl.html
25  import schmitzm.swing.SwingUtil;   *
26     * Contributors:
27  import com.vividsolutions.jts.geom.Envelope;   *     Martin O. J. Schmitz - initial API and implementation
28     *     Stefan A. Tzeggai - additional utility classes
29  /**   ******************************************************************************/
30   * A toolbar to controll a {@link JMapPane} (Atlas visualization). This contains two types  package skrueger.geotools;
31   * of buttons. A group of <i>tools</i> for the mouse actions on the map represented  
32   * by {@link JToggleButton JToggleButtons}, where only one tool can be activated  import java.awt.Color;
33   * every time. And some (general) <i>actions</i>, represented by normal  import java.awt.Graphics;
34   * {@link JButton JButtons}.  import java.awt.event.ActionEvent;
35   * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)  import java.awt.event.ActionListener;
36   */  import java.util.ArrayList;
37  public class MapPaneToolBar extends JToolBar {  import java.util.HashSet;
38          private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class.getName());  import java.util.Set;
39          /** Constant for the tool "Panning" (10). */  import java.util.SortedMap;
40          public static final int TOOL_PAN = 10;  import java.util.TreeMap;
41          /** Constant for the tool "Zoom In" (30). */  
42          public static final int TOOL_ZOOMIN = 30;  import javax.swing.AbstractAction;
43          /** Constant for the tool "Zoom Out" (40). */  import javax.swing.AbstractButton;
44          public static final int TOOL_ZOOMOUT = 40;  import javax.swing.Action;
45          /** Constant for the tool "Info" (20). */  import javax.swing.Icon;
46          public static final int TOOL_INFO = 20;  import javax.swing.ImageIcon;
47    import javax.swing.JButton;
48          /** Tool currently selected */  import javax.swing.JComponent;
49      protected int selectedTool = TOOL_ZOOMIN;  import javax.swing.JToggleButton;
50      /** Holds the tool buttons of the tool bar. */  import javax.swing.JToolBar;
51      protected SortedMap<Integer, JToggleButton> toolButtons = null;  
52      /** Controls that only one tool button is activated. */  import org.apache.log4j.Logger;
53      protected ButtonGroup toolButtonGroup = null;  
54      /** Constant for the action "Zoom back" (100). */  import schmitzm.geotools.gui.GeotoolsGUIUtil;
55      public static final int ACTION_ZOOM_BACK = 100;  import schmitzm.geotools.gui.SelectableXMapPane;
56      /** Constant for the action "Zoom forward" (110). */  import schmitzm.geotools.gui.XMapPaneEvent;
57      public static final int ACTION_ZOOM_FORWARD = 110;  import schmitzm.geotools.gui.XMapPaneTool;
58      /** Constant for the action "Search Labels" (120). */  import schmitzm.geotools.map.event.JMapPaneListener;
59      public static final int ACTION_SEARCH = 120;  import schmitzm.geotools.map.event.MapAreaChangedEvent;
60    import schmitzm.swing.ButtonGroup;
61      /** Holds the action buttons of the bar. */  import skrueger.swing.SmallButton;
62      protected SortedMap<Integer, JButton> actionButtons = null;  import skrueger.swing.SmallToggleButton;
63    
64          /** Holds the {@link JMapPane} this tool bar controls. */  import com.vividsolutions.jts.geom.Envelope;
65          protected JMapPane mapPane = null;  
66    /**
67          /**   * A toolbar to control an {@link SelectableXMapPane} (Atlas visualization). This contains
68           * A List to remember the last Envelopes that have been watched. Used for   * two types of buttons. A group of <i>tools</i> for the mouse actions on the
69           * the zoomBack- and zoomForwardButtons *   * map represented by {@link JToggleButton JToggleButtons}, where only one tool
70           */   * can be activated every time. And some (general) <i>actions</i>, represented
71          protected ArrayList<Envelope> lastZooms = new ArrayList<Envelope>();   * by normal {@link JButton JButtons}.
72          /** Holds the index to the current element in {@link #lastZooms}. */   *
73          protected int zoomBackIndex = 0;   * @author <a href="mailto:[email protected]">Martin Schmitz</a>
74     *         (University of Bonn/Germany)
75          /** Listener to sniff the zoom actions on the map. */   * @version 1.2 Stefan Tzeggai
76          protected JMapPaneListener mapPaneListener = null;   */
77            public class MapPaneToolBar extends JToolBar {
78          protected boolean zoomBackForwardButtonInAction;          private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class
79                            .getName());
80      /**  
81       * Creates a new toolbar. Notice: This toolbar does nothing          public static String R(String key, Object... values) {
82       * until {@link #setMapPane(JMapPane)} is called!                  return GeotoolsGUIUtil.R(key, values);
83       */          }
84      public MapPaneToolBar() {  
85        this(null);          /** Constant for the tool "Panning" (10). */
86      }          public static final int TOOL_PAN = 10;
87                /** Constant for the tool "Info" (20). */
88      /**          public static final int TOOL_INFO = 20;
89           * Creates a new tool bar.          public static final int SEPERATOR0 = 99;
90           * @param mapPane {@link JMapPane} the tool bar controls  
91           */          /** Constant for the tool "Zoom In" (110). */
92          public MapPaneToolBar(JMapPane mapPane) {          public static final int TOOL_ZOOMIN = 110;
93            super("Control the map", JToolBar.HORIZONTAL);          public static final int ACTION_ZOOM_DEFAULT = 150;
94        this.toolButtons     = new TreeMap<Integer,JToggleButton>();          /** Constant for the tool "Zoom Out" (120). */
95        this.toolButtonGroup = new ButtonGroup();          public static final int TOOL_ZOOMOUT = 120;
96        this.actionButtons   = new TreeMap<Integer,JButton>();          /** Constant for the action "Zoom back" (130). */
97        // Create a Listener to sniff the zooms on the JMapPane          public static final int ACTION_ZOOM_BACK = 130;
98        this.mapPaneListener = new JMapPaneListener() {          /** Constant for the action "Zoom forward" (140). */
99            public void performMapPaneEvent(JMapPaneEvent e) {          public static final int ACTION_ZOOM_FORWARD = 140;
100                if ( !(e instanceof MapAreaChangedEvent) )          public static final int SEPERATOR1 = 199;
101                  return;  
102                            /**
103                if ( zoomBackForwardButtonInAction ) {           * Constant for the tool "Selection Reset" which clears the selection (240).
104                  zoomBackForwardButtonInAction = false;           */
105                  return;          public static final int TOOL_SELECTION_CLEAR = 240;
106                }  
107                        /**
108                Envelope oldMapArea = ((MapAreaChangedEvent)e).getOldMapArea();           * Constant for the tool "Select" which sets the Selection to the selected
109                if (lastZooms.size() == 0 && oldMapArea != null ) {           * features (210).
110                  lastZooms.add(oldMapArea);           */
111                  zoomBackIndex = 1;          public static final int TOOL_SELECTION_SET = 210;
112                }          /**
113             * Constant for the tool "Selection add" which adds the features to the
114                final Envelope mapArea = ((MapAreaChangedEvent)e).getNewMapArea();           * Selection (220).
115                if (mapArea == null)           */
116                  return;          public static final int TOOL_SELECTION_ADD = 220;
117                          /**
118                if (lastZooms.size() > 0 && mapArea.equals(lastZooms.get(lastZooms.size() - 1))) {           * Constant for the tool "Selection subtract" which removes the selected
119                  // LOGGER.debug("MapAreaChangedEvent ausgelassen bei der Zaehlung der Zoomschritt weil identisch");           * features from the selection (230).
120                  return;           */
121                }          public static final int TOOL_SELECTION_REMOVE = 230;
122    
123                if (lastZooms.size() > 0)          public static final int ACTION_CHARTS = 401;
124                  while (zoomBackIndex < lastZooms.size())  
125                    lastZooms.remove(lastZooms.size() - 1);          /** Tool currently selected */
126            protected int selectedTool = TOOL_ZOOMIN;
127                lastZooms.add(mapArea);  
128                zoomBackIndex = lastZooms.size();          /** Holds the tool buttons of the tool bar. */
129                setButtonEnabled(ACTION_ZOOM_BACK, lastZooms.size() > 1);          final protected SortedMap<Integer, JComponent> toolAndActionButtons = new TreeMap<Integer, JComponent>();
130                setButtonEnabled(ACTION_ZOOM_FORWARD, false);          /** Controls that only one tool button is activated. */
131            }          protected ButtonGroup toolButtonGroup = null;
132        };      
133                // SK: Musste ich ändern damit man Tools und Actions in der Reihenfolge
134        setMapPane(mapPane);          // mischen kann.
135            setFloatable(false);          // /** Holds the action buttons of the bar. */
136            setRollover(true);          // protected SortedMap<Integer, JButton> actionButtons = null;
137              
138            init();          /** Holds the {@link SelectableXMapPane} this tool bar controls. */
139          }          protected SelectableXMapPane mapPane = null;
140            
141          /**          /**
142           * Sets the {@link JMapPane} controlled by this tool bar.           * A List to remember the last Envelopes that have been watched. Used for
143           * @param mapPane {@link JMapPane} to control (if {@code null} this           * the zoomBack- and zoomForwardButtons *
144           *                tool bar controls NOTHING!)           */
145           */          protected ArrayList<Envelope> lastZooms = new ArrayList<Envelope>();
146          public void setMapPane(JMapPane mapPane) {          /** Holds the index to the current element in {@link #lastZooms}. */
147            // Remove listener from old MapPane          protected int zoomBackIndex = 0;
148            if ( this.mapPane != null )  
149              this.mapPane.removeMapPaneListener( mapPaneListener );          /** Listener to sniff the zoom actions on the map. */
150        this.mapPane = mapPane;          protected JMapPaneListener mapPaneListener = null;
151        if ( this.mapPane != null && mapPaneListener != null )  
152          this.mapPane.addMapPaneListener( mapPaneListener );          protected boolean zoomBackForwardButtonInAction;
153          }  
154                    /** Listeners what want to be informed about a change of the selected tool **/
155          /**          protected Set<MapPaneToolSelectedListener> toolSelectionListeners = new HashSet<MapPaneToolSelectedListener>();
156           * Calls {@link #initTools()} and {@link #initActions()} and then puts  
157           * all tool buttons and all actions buttons to the tool bar.          /** This listener is added to all {@link JToggleButton} **/
158           */          private final ActionListener toolSelectedListener = new ActionListener() {
159          protected void init() {  
160            initTools();                  @Override
161            initActions();                  public void actionPerformed(ActionEvent e) {
162            initToolBar();                          JToggleButton tb = (JToggleButton) e.getSource();
163          }  
164                            // Inform the listeners about a newly selected tool
165                            for (MapPaneToolSelectedListener l : toolSelectionListeners) {
166          /**                                  l.toolSelected(Integer.valueOf(tb.getName()));
167           * Creates the tool buttons, adds them to {@link #toolButtons} and finally                          }
168           * creates a button group for all tools. So sub-classes which override this                  }
169           * method should FIRST add their new tool buttons to {@link #toolButtons}  
170           * before calling {@code super.initTools()}.          };
171           */  
172          protected void initTools() {          /**
173        // Panning           * Creates a new toolbar. Notice: This toolbar does nothing until
174        addTool( new MapPaneToolBarAction(           * {@link #setMapPane(SelectableXMapPane)} is called!
175            TOOL_PAN,           */
176            this,          public MapPaneToolBar() {
177            "",                  this(null);
178            new ImageIcon(MapView.class.getResource("pan.png"))          }
179        ), false );  
180        // Info          public void addButtonSelectedListener(MapPaneToolSelectedListener listener) {
181        addTool( new MapPaneToolBarAction(                  toolSelectionListeners.add(listener);
182            TOOL_INFO,          }
183            this,  
184            "",          public void removeButtonSelectedListener(
185            new ImageIcon(MapView.class.getResource("info.png"))                          MapPaneToolSelectedListener listener) {
186        ), false );                  toolSelectionListeners.remove(listener);
187        // Zoom in          }
188        addTool( new MapPaneToolBarAction(  
189            TOOL_ZOOMIN,          /**
190            this,           * Creates a new tool bar.
191            "",           *
192            new ImageIcon(MapView.class.getResource("zoom_in.png"))           * @param mapPane
193        ), false );           *            {@link SelectableXMapPane} the tool bar controls
194        // Zoom out           */
195        addTool( new MapPaneToolBarAction(          public MapPaneToolBar(SelectableXMapPane mapPane) {
196            TOOL_ZOOMOUT,                  super("Control the map", JToolBar.HORIZONTAL);
197            this,  
198            "",                  // I want to see nothing on the background
199            new ImageIcon(MapView.class.getResource("zoom_out.png"))                  setOpaque(false);
200        ), false );                  setBorder(null);
201          
202            // set the selected tool enabled                  this.toolButtonGroup = new ButtonGroup();
203        setSelectedTool(selectedTool);  
204                          // Create a Listener to listen to the zooms on the JMapPane
205          }                  this.mapPaneListener = new JMapPaneListener() {
206                            public void performMapPaneEvent(XMapPaneEvent e) {
207      /**                                  if (!(e instanceof MapAreaChangedEvent))
208       * Creates the action buttons and adds them to {@link #actionButtons}.                                          return;
209       */  
210      protected void initActions() {                                  if (zoomBackForwardButtonInAction) {
211        // Action button to revert the last zoom                                          zoomBackForwardButtonInAction = false;
212        addAction( new MapPaneToolBarAction(                                          return;
213            ACTION_ZOOM_BACK,                                  }
214            this,  
215            "",                                  final MapAreaChangedEvent mapAreaChangedEvent = (MapAreaChangedEvent) e;
216            new ImageIcon(MapView.class.getResource("zoom_back.png"))                                  Envelope oldMapArea = mapAreaChangedEvent.getOldMapArea();
217        ), false);  
218        setButtonEnabled( ACTION_ZOOM_BACK, false );                                  final Envelope mapArea = mapAreaChangedEvent.getNewMapArea();
219                                    if (mapArea == null || mapArea.equals(oldMapArea)
220        // Action button to redo the last zoom                                                  || Double.isNaN(mapArea.getMinX())
221        addAction( new MapPaneToolBarAction(                                                  || Double.isNaN(mapArea.getMaxX())
222            ACTION_ZOOM_FORWARD,                                                  || Double.isNaN(mapArea.getMinY())
223            this,                                                  || Double.isNaN(mapArea.getMaxY())) {
224            "",                                          // If the MapArea didn't change... we don't want to register
225            new ImageIcon(MapView.class.getResource("zoom_forward.png"))                                          // it as a zoom action.
226        ), false);                                          return;
227        setButtonEnabled( ACTION_ZOOM_FORWARD, false );                                  }
228    
229      }                                  if (lastZooms.size() == 0
230                                                        && oldMapArea != null
231      /**                                                  && !oldMapArea.isNull()
232       * Clears the GUI of all components and adds all tool and action buttons to the                                                  && !(Double.isNaN(oldMapArea.getMinX())
233       * tool bar.                                                                  || Double.isNaN(oldMapArea.getMaxX())
234       */                                                                  || Double.isNaN(oldMapArea.getMinY()) || Double
235      protected void initToolBar() {                                                                  .isNaN(oldMapArea.getMaxY()))) {
236        setAlignmentY( 1f );                                          lastZooms.add(oldMapArea);
237        removeAll();                                          zoomBackIndex = 1;
238        // Separator to the left of the tool actions to start                                  }
239        // the tool buttons with the map (not with the coordinate grid)                                  if (mapArea == null)
240        Dimension dimension = new Dimension( 49,10);                                          return;
241        addSeparator(dimension);  
242        // Tool buttons                                  if (lastZooms.size() > 0
243        for (JToggleButton b : toolButtons.values())                                                  && mapArea.equals(lastZooms.get(lastZooms.size() - 1))) {
244          add(b);                                          // LOGGER.debug("MapAreaChangedEvent ausgelassen bei der Zaehlung der Zoomschritt weil identisch");
245        // Space between tool buttons and action buttons                                          return;
246        Dimension dimension2 = new Dimension( 10,10);                                  }
247        this.addSeparator(dimension2);  
248        // Action buttons                                  if (lastZooms.size() > 0)
249        for (JButton b : actionButtons.values())                                          while (zoomBackIndex < lastZooms.size())
250          add(b);                                                  lastZooms.remove(lastZooms.size() - 1);
251      }  
252                                        lastZooms.add(mapArea);
253          /**                                  zoomBackIndex = lastZooms.size();
254           * Performs the activation of a tool.                                  setButtonEnabled(ACTION_ZOOM_BACK, lastZooms.size() > 1);
255           * @param tool the tool to activate                                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);
256           * @param e    the event of the button                          }
257           */                  };
258          public void performToolButton(int tool, ActionEvent e) {  
259            if ( mapPane == null )                  setMapPane(mapPane);
260              return;                  setFloatable(false);
261                              setRollover(true);
262            selectedTool = tool;  
263                              init();
264        switch( tool ) {          }
265          case TOOL_PAN:  
266            // Set the mouse tool to "Panning"          /**
267            mapPane.setWindowSelectionState(JMapPane.NONE);           * Sets the {@link SelectableXMapPane} controlled by this tool bar.
268            mapPane.setState(JMapPane.PAN);           *
269            mapPane.setHighlight(false);           * @param mapPane
270            mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);           *            {@link SelectableXMapPane} to control (if {@code null} this tool bar
271            break;           *            controls NOTHING!)
272          case TOOL_INFO:           */
273            // Set the mouse tool to "Info"          public void setMapPane(SelectableXMapPane mapPane) {
274            mapPane.setWindowSelectionState(JMapPane.NONE);                  // Remove listener from old MapPane
275            mapPane.setState(JMapPane.SELECT_TOP);                  if (this.mapPane != null)
276            mapPane.setHighlight(true);                          this.mapPane.removeMapPaneListener(mapPaneListener);
277            mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);                  this.mapPane = mapPane;
278            break;                  if (this.mapPane != null && mapPaneListener != null)
279          case TOOL_ZOOMIN:                          this.mapPane.addMapPaneListener(mapPaneListener);
280            // Set the mouse tool to "Zoom in"          }
281            mapPane.setWindowSelectionState(JMapPane.ZOOM_IN);  
282            mapPane.setState(JMapPane.ZOOM_IN);          /**
283            mapPane.setHighlight(false);           * Calls {@link #initToolsAndActions()} and {@link #initActions()} and then
284            mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);           * puts all tool buttons and all actions buttons to the tool bar.
285            break;           */
286          case TOOL_ZOOMOUT:          protected void init() {
287            // Set the mouse tool to "Zoom out"  
288            mapPane.setWindowSelectionState(JMapPane.NONE);                  initToolsAndActions();
289            mapPane.setState(JMapPane.ZOOM_OUT);  
290            mapPane.setHighlight(false);                  addSeparator(SEPERATOR0, new JToolBar.Separator());
291            mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);                  addSeparator(SEPERATOR1, new JToolBar.Separator());
292            break;  
293          default:                  initToolBar();
294            // Set map actions to default          }
295            mapPane.setWindowSelectionState(JMapPane.NONE);  
296            mapPane.setState(JMapPane.NONE);          /**
297            mapPane.setHighlight(false);           * Creates the tool buttons and action buttons and seperators, adds them to
298            mapPane.setNormalCursor(null);           * {@link #toolAndActionButtons} and finally creates a button group for all
299            break;           * tools. So sub-classes which override this method should FIRST add their
300        }           * new tool buttons to {@link #toolAndActionButtons} before calling {@code
301        mapPane.updateCursor();           * super.initTools()}.
302          }           */
303                    protected void initToolsAndActions() {
304      /**                  // Panning
305       * Performs the action of an action button.  //              addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(
306       * @param tool the action  //                              MapView.class.getResource("resource/icons/pan.png")),
307       * @param e    the event of the button  //                              R("MapPaneButtons.Pan.TT")), false);
308       */  
309          protected void performActionButton(int action, ActionEvent e) {                  addTool(new MapPaneToolBarAction(TOOL_PAN, this, XMapPaneTool.PAN), false);
310        if ( mapPane == null )                  
311          return;                  // Info
312    //              addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(
313        // Perform the action "Zoom back": Revert the last zoom  //                              MapView.class.getResource("resource/icons/info.png")),
314        if ( action == ACTION_ZOOM_BACK ) {  //                              R("MapPaneButtons.Info.TT")), false);
315              if (zoomBackIndex <= 1)                  addTool(new MapPaneToolBarAction(TOOL_INFO, this, XMapPaneTool.INFO), false);
316            return;  
317                      // Zoom in
318          zoomBackForwardButtonInAction = true;                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, XMapPaneTool.ZOOM_IN), false);
319          zoomBackIndex--;                  
320          getButton(ACTION_ZOOM_FORWARD).setEnabled(true);                  // Zoom out
321          getButton(ACTION_ZOOM_BACK).setEnabled( zoomBackIndex > 1 );                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, XMapPaneTool.ZOOM_OUT), false);
322                      
323          mapPane.setMapArea( lastZooms.get(zoomBackIndex-1) );                  
324          mapPane.refresh();  //              // Zoom in
325        }  //              addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(
326    //                              MapView.class.getResource("resource/icons/zoom_in.png")),
327        // Perform the action "Zoom forward": Redo the last zoom  //                              R("MapPaneButtons.ZoomIn.TT")), false);
328        if ( action == ACTION_ZOOM_FORWARD ) {  //              
329          if (zoomBackIndex < lastZooms.size()) {  //              // Zoom out
330            zoomBackForwardButtonInAction = true;  //              addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(
331            zoomBackIndex++;  //                              MapView.class.getResource("resource/icons/zoom_out.png")),
332            getButton(ACTION_ZOOM_BACK).setEnabled(true);  //                              R("MapPaneButtons.ZoomOut.TT")), false);
333            getButton(ACTION_ZOOM_FORWARD).setEnabled(zoomBackIndex < lastZooms.size());                  
334                    
335            mapPane.setMapArea( lastZooms.get(zoomBackIndex-1) );  
336            mapPane.refresh();                  // Action button to revert the last zoom
337          }                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",
338        }                                  new ImageIcon(MapView.class
339          }                                                  .getResource("resource/icons/zoom_back.png")),
340                                            R("MapPaneButtons.LastZoom.TT")), false);
341                            setButtonEnabled(ACTION_ZOOM_BACK, false);
342          /**  
343           * Adds a tool to the tool bar. Does nothing if a tool or action with the                  // Action button to redo the last zoom
344           * specified ID already exists!                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "",
345           * @param buttonAction action for the toggle button                                  new ImageIcon(MapView.class
346           * @param resetToolBar indicates whether the toolbar GUI is reset after adding                                                  .getResource("resource/icons/zoom_forward.png")),
347           *                     the button (if adding several actions it useful only to                                  R("MapPaneButtons.NextZoom.TT")), false);
348           *                     reset the GUI for the last added tool)                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);
349           */  
350          public void addTool(MapPaneToolBarAction buttonAction, boolean resetToolBar) {                  // set the selected tool enabled
351            if ( isButtonIDUsed(buttonAction.getID()) ) {                  setSelectedTool(selectedTool);
352              LOGGER.warn("addTool(.) ignored because ID already used for tool or action: "+buttonAction.getID());  
353              return;          }
354            }  
355            JToggleButton button = new JToggleButton(buttonAction);          @Override
356            button.setBorder( BorderFactory.createRaisedBevelBorder() );          public void paint(Graphics g) {
357            toolButtonGroup.add(button);                  super.paint(g);
358            toolButtons.put(buttonAction.getID(), button);          }
359            if ( resetToolBar )  
360              initToolBar();          /**
361          }           * Clears the GUI of all components and adds all tool and action buttons to
362             * the tool bar.
363      /**           */
364       * Adds a tool to the tool bar and resets the toolbar GUI.          public void initToolBar() {
365       * @param buttonAction action for the toggle button                  // setOpaque(true);
366       */                  //              
367      public void addTool(MapPaneToolBarAction buttonAction) {                  // setAlignmentY(1f);
368        addTool(buttonAction, true);                  // setAlignmentX(0.5f);
369      }                  removeAll();
370    
371      /**                  // // Separator to the left of the tool actions to start
372       * Adds an action to the tool bar. Does nothing if a tool or action with the                  // // the tool buttons with the map (not with the coordinate grid)
373       * specified ID already exists!                  // Dimension dimension = new Dimension(49, 10);
374       * @param buttonAction action for the button                  // addSeparator(dimension);
375       * @param resetToolBar indicates whether the toolbar GUI is reset after adding  
376       *                     the button (if adding several actions it useful only to                  // Tool buttons
377       *                     reset the GUI for the last added tool)                  for (Integer bKey : toolAndActionButtons.keySet()) {
378       */  
379      public void addAction(MapPaneToolBarAction buttonAction, boolean resetToolBar) {                          JComponent b = toolAndActionButtons.get(bKey);
380        if ( isButtonIDUsed(buttonAction.getID()) ) {  
381          LOGGER.warn("addAction(.) ignored because ID already used for tool or action: "+buttonAction.getID());                          if (b instanceof JToggleButton) {
382          return;                                  JToggleButton tb = (JToggleButton) b;
383        }                                  tb.setName(bKey.toString());
384        JButton button = new JButton(buttonAction);                                  tb.addActionListener(toolSelectedListener);
385        actionButtons.put( buttonAction.getID(), button );                          }
386        if ( resetToolBar )  
387          initToolBar();                          add(b);
388      }                  }
389    
390      /**                  if (!toolAndActionButtons.containsKey(selectedTool)) {
391       * Adds an action to the tool bar and resets the toolbar GUI.                          /**
392       * @param buttonAction action for the toggle button                           * This might be a bit specific, but IF selection buttons are
393       */                           * available, select one of them.. if not, select the INFO tool.
394      public void addAction(MapPaneToolBarAction buttonAction) {                           */
395        addAction(buttonAction, true);  
396      }                          if (toolAndActionButtons.containsKey(TOOL_SELECTION_SET)) {
397                                        setSelectedTool(TOOL_SELECTION_SET);
398      /**                          } else if (toolAndActionButtons.containsKey(TOOL_INFO)) {
399       * Returns the button for a specific tool or action.                                  setSelectedTool(TOOL_INFO);
400       * @param id the constant for a tool                          } else {
401       * @return a {@link JButton} if {@code id} specifies an {@linkplain #getActionButton(int) action button}                                  // TODO What to do now?!
402       *         or {@link JToogleButton} if {@code id} specifies a {@linkplain #getToolButton(int) tool button}                                  setSelectedTool(null);
403       */                          }
404      public AbstractButton getButton(int id) {  
405        AbstractButton button = toolButtons.get(id);                  }
406        if ( button == null )  
407          button = actionButtons.get(id);                  revalidate();
408        if ( button == null )                  repaint();
409          LOGGER.warn("Unknown tool or action ID: "+id);          }
410        return button;  
411      }          // Space between tool buttons and action buttons
412            // SK: Seperators are now als manages like actions and tools
413      /**          // Dimension dimension2 = new Dimension( 10,10);
414       * Returns the button for a specific tool.          // this.addSeparator(dimension2);
415       * @param tool the constant for a tool  
416       */          // // Action buttons
417          public JToggleButton getToolButton(int tool) {          // for (JButton b : actionButtons.values())
418        AbstractButton button = getButton(tool);          // add(b);
419        if ( button != null && !(button instanceof JToggleButton) ) {          // }
420          LOGGER.warn("ID specifies no tool: "+tool);  
421          button = null;          /**
422        }           * Performs the activation of a tool.
423        return (JToggleButton)button;           *
424      }           * @param tool
425             *            the tool to activate
426      /**           * @param e
427       * Returns the button for a specific action.           *            the event of the button
428       * @param action the constant an action           */
429       */          public void performToolButton(int tool, ActionEvent e) {
430      public JButton getActionButton(int action) {                  if (mapPane == null)
431        AbstractButton button = getButton(action);                          return;
432        if ( button != null && !(button instanceof JButton) ) {  
433          LOGGER.warn("ID specifies no action: "+action);                  selectedTool = tool;
434          button = null;  
435        }                  switch (tool) {
436        return (JButton)button;                  case TOOL_PAN:
437                            // Set the mouse tool to "Panning"
438      }  //                      mapPane.setState(SelectableXMapPane.PAN);
439                            mapPane.setTool(XMapPaneTool.PAN);
440          /**  //                      mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);
441           * Sets the selected tool.                          break;
442           * @param tool ID of the tool                  case TOOL_INFO:
443           */                          // Set the mouse tool to "Info"
444          public void setSelectedTool(Integer tool) {                          mapPane.setTool(XMapPaneTool.INFO);
445            if ( tool == null )  //                      mapPane.setState(SelectableXMapPane.SELECT_ONE_FROM_TOP);
446              toolButtonGroup.setUnselected();  //                      mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);
447                                      break;
448            JToggleButton button = getToolButton(tool);                  case TOOL_ZOOMIN:
449            if ( button == null )                          // Set the mouse tool to "Zoom in"
450              return;                          mapPane.setTool(XMapPaneTool.ZOOM_IN);
451            button.setSelected( true );  //                      mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);
452            button.getAction().actionPerformed(null);                          break;
453          }                  case TOOL_ZOOMOUT:
454                                    // Set the mouse tool to "Zoom out"
455          /**                          mapPane.setTool(XMapPaneTool.ZOOM_OUT);
456           * Returns the selected tool.  //                      mapPane.setState(SelectableXMapPane.ZOOM_OUT);
457           * @return -1 if no tool is active  //                      mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);
458           */                          break;
459          public int getSelectedTool() {  //              default:
460            if ( toolButtonGroup.getSelectedButton() == null )                          // Set map actions to default
461              return -1;  //                      mapPane.setState(SelectableXMapPane.NONE);
462            return selectedTool;  //                      mapPane.setNormalCursor(null);
463          }  //                      break;
464                            }
465      /**  //              mapPane.updateCursorAndRepaintTimer();
466       * Sets whether a tool or action is activated or not. The visible property          }
467       * of the button is not affected.  
468       * @param id tool or actionID          /**
469       * @param enabled if {@code true} the tool becomes available           * @param id
470       */           *            The ID of the Component to remove. The change will not be
471      public void setButtonEnabled(int id, boolean enabled) {           *            visible until {@link #initToolBar()} is called.
472        AbstractButton button = getButton(id);           * @return <code>null</code> or the component that has been removed.
473        if ( button == null )           */
474          return;          public JComponent removeId(int id) {
475        button.setEnabled( enabled );                  return toolAndActionButtons.remove(id);
476      }          }
477    
478      /**          /**
479       * Sets whether a tool or action is activated or not.           * Performs the action of an action button.
480       * @param id tool or actionID           *
481       * @param enabled if {@code true} the tool becomes available           * @param tool
482       * @param hideOnDisable if {@code true} the button is also hidden if           *            the action
483       *                      {@code enabled} is {@code false}           * @param e
484       */           *            the event of the button
485          public void setButtonEnabled(int id, boolean enabled, boolean hideOnDisable) {           */
486            AbstractButton button = getButton(id);          protected void performActionButton(int action, ActionEvent e) {
487            if ( button == null )                  if (mapPane == null)
488              return;                          return;
489            button.setEnabled( enabled );                  
490            // if button is enabled, it becomes visible anyway                  // Perform the action "Zoom back": Revert the last zoom
491            // if button is disabled and the "hide" option is set, it is also hidden                  if (action == ACTION_ZOOM_BACK) {
492            if ( enabled )                          if (zoomBackIndex <= 1)
493              button.setVisible( true );                                  return;
494            else  
495              button.setVisible( !hideOnDisable );                          zoomBackForwardButtonInAction = true;
496          }                          zoomBackIndex--;
497                            getButton(ACTION_ZOOM_FORWARD).setEnabled(true);
498      /**                          getButton(ACTION_ZOOM_BACK).setEnabled(zoomBackIndex > 1);
499       * Checks whether a ID is already used for a tool or action.  
500       * @param tool tool ID                          mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1));
501       */                          mapPane.refresh();
502      public boolean isButtonIDUsed(int id) {                  }
503        return toolButtons.get(id) != null || actionButtons.get(id) != null;  
504      }                  // Perform the action "Zoom forward": Re-do the last zoom
505                    if (action == ACTION_ZOOM_FORWARD) {
506      /**                          if (zoomBackIndex < lastZooms.size()) {
507       * Checks whether a tool is activated.                                  zoomBackForwardButtonInAction = true;
508       * @param tool tool ID                                  zoomBackIndex++;
509       * @return {@code false} if an unknown ID is specified                                  getButton(ACTION_ZOOM_BACK).setEnabled(true);
510       */                                  getButton(ACTION_ZOOM_FORWARD).setEnabled(
511      public boolean isButtonEnabled(int id) {                                                  zoomBackIndex < lastZooms.size());
512        AbstractButton button = getButton(id);  
513        if ( button != null )                                  mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1));
514          return button.isEnabled();                                  mapPane.refresh();
515        return false;                          }
516      }                  }
517            }
518      /**  
519       * Sets the activation for all tools.          /**
520       * @param enabled if {@code true} all tools becomes available           * Adds a tool to the tool bar. Does nothing if a tool or action with the
521       * @param hideOnDisable if {@code true} the buttons are also hidden if           * specified ID already exists!
522       *                      {@code enabled} is {@code false}           *
523       */           * @param buttonAction
524      public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {           *            action for the toggle button
525        for (int tool : toolButtons.keySet())           * @param resetToolBar
526          setButtonEnabled(tool,enabled,hideOnDisable);           *            indicates whether the toolbar GUI is reset after adding the
527      }             *            button (if adding several actions it useful only to reset the
528             *            GUI for the last added tool)
529      /**           */
530       * Sets the activation for all actions.          public void addTool(MapPaneToolBarAction buttonAction, boolean resetToolBar) {
531       * @param enabled if {@code true} all actions becomes available                  if (isButtonIDUsed(buttonAction.getID())) {
532       * @param hideOnDisable if {@code true} the buttons are also hidden if                          LOGGER
533       *                      {@code enabled} is {@code false}                                          .warn("addTool(.) ignored because ID already used for tool or action: "
534       */                                                          + buttonAction.getID());
535      public void setAllActionsEnabled(boolean enabled, boolean hideOnDisable) {                          return;
536        for (int tool : actionButtons.keySet())                  }
537          setButtonEnabled(tool,enabled,hideOnDisable);                  JToggleButton button = new SmallToggleButton(buttonAction);
538      }                    
539        //              button.setBorder(BorderFactory.createRaisedBevelBorder());
540      /**                  toolButtonGroup.add(button);
541       * Returns the maximum ID of tools.                  toolAndActionButtons.put(buttonAction.getID(), button);
542       */                  if (resetToolBar)
543      public int getMaxToolID() {                          initToolBar();
544        return toolButtons.lastKey();          }
545      }  
546            /**
547      /**           * Adds a tool to the tool bar and resets the toolbar GUI.
548       * Returns the minimum ID of tools.           *
549       */           * @param buttonAction
550      public int getMinToolID() {           *            action for the toggle button
551        return toolButtons.firstKey();           */
552      }          public void addTool(MapPaneToolBarAction buttonAction) {
553                    addTool(buttonAction, true);
554      /**          }
555       * Returns the maximum ID of actions.  
556       */          /**
557      public int getMaxActionID() {           * Adds an action to the tool bar. Does nothing if a tool or action with the
558        return actionButtons.lastKey();           * specified ID already exists!
559      }           *
560             * @param buttonAction
561      /**           *            action for the button
562       * Returns the minimum ID of actions.           * @param resetToolBar
563       */           *            indicates whether the toolbar GUI is reset after adding the
564      public int getMinActionID() {           *            button (if adding several actions it useful only to reset the
565        return actionButtons.firstKey();           *            GUI for the last added tool)
566      }           */
567                public void addAction(MapPaneToolBarAction buttonAction,
568      /**                          boolean resetToolBar) {
569       * Extends the {@link AbstractAction} with maintaining an ID and                  if (isButtonIDUsed(buttonAction.getID())) {
570       * the {@link MapPaneToolBar} the actions controls.                          LOGGER
571       * Additionally this class automatically calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)}                                          .warn("addAction(.) ignored because ID already used for tool or action: "
572       * or {@link MapPaneToolBar#performActionButton(int, ActionEvent)}                                                          + buttonAction.getID());
573       * depending on whether the action is added via {@link MapPaneToolBar#addTool(MapPaneToolBarAction)}                          return;
574       * or {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.                  }
575       * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)                  JButton button = new SmallButton(buttonAction);
576       */  //              button.setBorder(BorderFactory.createRaisedBevelBorder());
577      public static class MapPaneToolBarAction extends AbstractAction {                  toolAndActionButtons.put(buttonAction.getID(), button);
578        /** The ID of the action */                  if (resetToolBar)
579        protected int id = -1;                          initToolBar();
580        /** The tool bar, this action is made for. */          }
581        protected MapPaneToolBar toolBar = null;  
582            /**
583        /**           * Adds any JComponent to the tool bar. Does nothing if a tool or action
584         * Creates a new action with a dummy description and no icon.           * with the specified ID already exists!
585         * @param id      unique ID for the action           *
586         * @param toolBar toolbar this action is made for           * @param component
587         */           *            A {@link JComponent} that shall be added
588        public MapPaneToolBarAction(int id, MapPaneToolBar toolBar) {           * @param id
589          this(id,toolBar,""+id);           *            The ID associaded with the {@link JComponent}
590        }           * @param resetToolBar
591             *            indicates whether the toolbar GUI is reset after adding the
592        /**           *            button (if adding several actions it useful only to reset the
593         * Creates a new action without an icon.           *            GUI for the last added tool)
594         * @param id      unique ID for the action           */
595         * @param toolBar toolbar this action is made for          public void addJComponent(JComponent component, int id, boolean resetToolBar) {
596         * @param name    description used for buttons or menus  
597         */                  if (isButtonIDUsed(id)) {
598        public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, String name) {                          LOGGER
599          this(id,toolBar,name,null);                                          .warn("addAction(.) ignored because ID already used for tool or action: "
600        }                                                          + id);
601                            return;
602        /**                  }
603         * Creates a new action.  
604         * @param id      unique ID for the action                  toolAndActionButtons.put(id, component);
605         * @param toolBar toolbar this action is made for                  if (resetToolBar)
606         * @param name    description used for buttons or menus                          initToolBar();
607         * @param icon    icon used for buttons or menus          }
608         */  
609        public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, String name, Icon icon) {          public void addSeparator(int id, Separator separator) {
610          super(name,icon);                  if (isButtonIDUsed(id)) {
611          this.id      = id;                          LOGGER
612          this.toolBar = toolBar;                                          .warn("addSeparator(.) ignored because ID already used for tool or action. ");
613        }                          return;
614                          }
615        /**                  toolAndActionButtons.put(id, separator);
616         * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)}          }
617         * or {@link MapPaneToolBar#performActionButton(int, ActionEvent)}  
618         * depending on whether the action is added to the toolbar via          /**
619         * {@link MapPaneToolBar#addTool(MapPaneToolBarAction)}           * Adds an action to the tool bar and resets the toolbar GUI.
620         * or {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.           *
621         */           * @param buttonAction
622        public void actionPerformed(ActionEvent e) {           *            action for the toggle button
623          if ( toolBar.toolButtons.get(id) != null )           */
624            toolBar.performToolButton(id, e);          public void addAction(MapPaneToolBarAction buttonAction) {
625          if ( toolBar.actionButtons.get(id) != null )                  addAction(buttonAction, true);
626            toolBar.performActionButton(id, e);          }
627        }  
628                  /**
629        /**           * Returns the button for a specific tool or action.
630         * Returns the (unique) id of this action.           *
631         * @return           * @param id
632         */           *            the constant for any button in the {@link MapPaneToolBar}
633        public int getID() {           * @return a {@link JButton} if {@code id} specifies an
634          return id;           *         {@linkplain #getActionButton(int) action button} or
635        }           *         {@link JToogleButton} if {@code id} specifies a
636      }           *         {@linkplain #getToolButton(int) tool button}
637  }           */
638            public AbstractButton getButton(int id) {
639                    
640                    //ACHUTNG: Das ist ein SK QUICK FIX! TODO
641                    if (!(toolAndActionButtons.get(id) instanceof AbstractButton)) return null;
642                    
643                    AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);
644                    if (button == null)
645                            LOGGER.warn("Unknown tool or action ID: " + id);
646                    return button;
647            }
648    
649            /**
650             * Returns the button for a specific tool.
651             *
652             * @param tool
653             *            the constant for a tool
654             */
655            public JToggleButton getToolButton(int tool) {
656                    AbstractButton button = getButton(tool);
657                    if (button != null && !(button instanceof JToggleButton)) {
658                            LOGGER.warn("ID specifies no tool: " + tool);
659                            button = null;
660                    }
661                    return (JToggleButton) button;
662            }
663    
664            /**
665             * Returns the button for a specific action.
666             *
667             * @param action
668             *            the constant an action
669             */
670            public JButton getActionButton(int action) {
671                    AbstractButton button = getButton(action);
672                    if (button != null && !(button instanceof JButton)) {
673                            LOGGER.warn("ID specifies no action: " + action);
674                            button = null;
675                    }
676                    return (JButton) button;
677    
678            }
679    
680            /**
681             * Sets the selected tool.
682             *
683             * @param tool
684             *            ID of the tool
685             */
686            public void setSelectedTool(Integer tool) {
687                    if (tool == null)
688                            toolButtonGroup.setUnselected();
689    
690                    JToggleButton button = getToolButton(tool);
691                    if (button == null)
692                            return;
693                    button.setSelected(true);
694                    button.getAction().actionPerformed(null);
695    
696                    selectedTool = tool;
697            }
698    
699            /**
700             * Returns the selected tool.
701             *
702             * @return -1 if no tool is active
703             */
704            public int getSelectedTool() {
705                    if (toolButtonGroup.getSelectedButton() == null)
706                            return -1;
707                    return selectedTool;
708            }
709            
710            /**
711             * Sets whether a tool or action is activated or not. The visible property
712             * of the button is not affected.
713             *
714             * @param id
715             *            tool or actionID
716             * @param enabled
717             *            if {@code true} the tool becomes available
718             */
719            public void setButtonEnabled(int id, boolean enabled) {
720                    AbstractButton button = getButton(id);
721                    if (button == null)
722                            return;
723                    button.setEnabled(enabled);
724            }
725    
726            /**
727             * Sets whether a tool or action is activated or not.
728             *
729             * @param id
730             *            tool or actionID
731             * @param enabled
732             *            if {@code true} the tool becomes available
733             * @param hideOnDisable
734             *            if {@code true} the button is also hidden if {@code enabled}
735             *            is {@code false}
736             */
737            public void setButtonEnabled(int id, boolean enabled, boolean hideOnDisable) {
738                    AbstractButton button = getButton(id);
739                    if (button == null)
740                            return;
741                    button.setEnabled(enabled);
742                    // if button is enabled, it becomes visible anyway
743                    // if button is disabled and the "hide" option is set, it is also hidden
744                    if (enabled)
745                            button.setVisible(true);
746                    else
747                            button.setVisible(!hideOnDisable);
748            }
749    
750            /**
751             * Checks whether a ID is already used for a tool or action.
752             *
753             * @param tool
754             *            tool ID
755             */
756            public boolean isButtonIDUsed(int id) {
757                    return toolAndActionButtons.get(id) != null;
758            }
759    
760            /**
761             * Checks whether a tool is activated.
762             *
763             * @param tool
764             *            tool ID
765             * @return {@code false} if an unknown ID is specified
766             */
767            public boolean isButtonEnabled(int id) {
768                    AbstractButton button = getButton(id);
769                    if (button != null)
770                            return button.isEnabled();
771                    return false;
772            }
773    
774            /**
775             * Sets the activation for all tools.
776             *
777             * @param enabled
778             *            if {@code true} all tools becomes available
779             * @param hideOnDisable
780             *            if {@code true} the buttons are also hidden if {@code enabled}
781             *            is {@code false}
782             */
783            public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {
784                    for (int id : toolAndActionButtons.keySet()) {
785                            if (toolAndActionButtons.get(id) instanceof JToggleButton) {
786                            setButtonEnabled(id, enabled, hideOnDisable);
787                            }
788                    }
789            }
790            
791            /**
792             * Sets the activation for all actions.
793             *
794             * @param enabled
795             *            if {@code true} all actions becomes available
796             * @param hideOnDisable
797             *            if {@code true} the buttons are also hidden if {@code enabled}
798             *            is {@code false}
799             */
800            public void setAllActionsEnabled(boolean enabled, boolean hideOnDisable) {
801                    for (int id : toolAndActionButtons.keySet()) {
802                            if (toolAndActionButtons.get(id) instanceof JButton) {
803                                    setButtonEnabled(id, enabled, hideOnDisable);
804                            }
805                    }
806    
807            }
808    
809            /**
810             * Returns the maximum ID of tools.
811             */
812            public int getMaxToolID() {
813                    return toolAndActionButtons.lastKey();
814            }
815    
816            /**
817             * Returns the minimum ID of tools.
818             */
819            public int getMinToolID() {
820                    return toolAndActionButtons.firstKey();
821            }
822    
823            /**
824             * Extends the {@link AbstractAction} with maintaining an ID and the
825             * {@link MapPaneToolBar} the actions controls. Additionally this class
826             * automatically calls
827             * {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or
828             * {@link MapPaneToolBar#performActionButton(int, ActionEvent)} depending on
829             * whether the action is added via
830             * {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or
831             * {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.
832             *
833             * @author <a href="mailto:[email protected]">Martin Schmitz</a>
834             *         (University of Bonn/Germany)
835             */
836            public static class MapPaneToolBarAction extends AbstractAction {
837                    /** The ID of the action */
838                    protected int id = -1;
839                    /** The tool bar, this action is made for. */
840                    protected MapPaneToolBar toolBar = null;
841    
842                    /**
843                     * Creates a new action with a dummy description and no icon.
844                     *
845                     * @param id
846                     *            unique ID for the action
847                     * @param toolBar
848                     *            toolbar this action is made for
849                     */
850                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar) {
851                            this(id, toolBar, "" + id);
852                    }
853    
854                    /**
855                     * Creates a new action without an icon.
856                     *
857                     * @param id
858                     *            unique ID for the action
859                     * @param toolBar
860                     *            toolbar this action is made for
861                     * @param name
862                     *            description used for buttons or menus
863                     */
864                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, String name) {
865                            this(id, toolBar, name, null);
866                    }
867    
868                    /**
869                     * Creates a new action.
870                     *
871                     * @param id
872                     *            unique ID for the action
873                     * @param toolBar
874                     *            toolbar this action is made for
875                     * @param name
876                     *            description used for buttons or menus
877                     * @param icon
878                     *            icon used for buttons or menus
879                     */
880                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
881                                    String name, Icon icon) {
882                            this(id, toolBar, name, icon, null);
883                    }
884    
885                    /**
886                     * Creates a new action.
887                     *
888                     * @param id
889                     *            unique ID for the action
890                     * @param toolBar
891                     *            The {@link MapPaneToolBar} this action is made for
892                     * @param name
893                     *            description used for buttons or menus
894                     * @param icon
895                     *            icon used for buttons or menus
896                     * @param toolTip
897                     *            Tooltip to use for the button or menu
898                     */
899                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
900                                    String name, Icon icon, String toolTip) {
901                            super(name, icon);
902    
903                            if (toolTip != null && !toolTip.trim().isEmpty()) {
904                                    putValue(Action.SHORT_DESCRIPTION, toolTip);
905                            }
906    
907                            this.id = id;
908                            this.toolBar = toolBar;
909                    }
910    
911                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, XMapPaneTool tool) {
912                            this(id, toolBar, "", tool.getIcon(), tool.getToolTip());
913                    }
914    
915                    /**
916                     * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or
917                     * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}
918                     * depending on whether the action is added to the toolbar via
919                     * {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or
920                     * {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.
921                     */
922                    public void actionPerformed(ActionEvent e) {
923                            if (toolBar.toolAndActionButtons.get(id) instanceof JToggleButton)
924                                    toolBar.performToolButton(id, e);
925                            else if (toolBar.toolAndActionButtons.get(id) instanceof JButton)
926                                    toolBar.performActionButton(id, e);
927                    }
928    
929                    /**
930                     * Returns the (unique) id of this action.
931                     *
932                     * @return
933                     */
934                    public int getID() {
935                            return id;
936                    }
937            }
938    
939            /**
940             * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht
941             * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.
942             *
943             * @author <a href="mailto:[email protected]">Stefan Alfons
944             *         Tzeggai</a>
945             */
946            @Override
947            public void print(Graphics g) {
948                    Color orig = getBackground();
949                    setBackground(Color.WHITE);
950                    // wrap in try/finally so that we always restore the state
951                    try {
952                            super.print(g);
953                    } finally {
954                            setBackground(orig);
955                    }
956            }
957    
958    }

Legend:
Removed from v.48  
changed lines
  Added in v.888

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26