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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26