/[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

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

Legend:
Removed from v.141  
changed lines
  Added in v.315

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26