/[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 160 by alfonx, Mon Jun 22 17:15:45 2009 UTC branches/1.0-gt2-2.6/src/skrueger/geotools/MapPaneToolBar.java revision 336 by alfonx, Thu Aug 27 09:10:10 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          }          /**
298             * Clears the GUI of all components and adds all tool and action buttons to
299          // Space between tool buttons and action buttons           * the tool bar.
300          // SK: Seperators are now als manages like actions and tools           */
301          // Dimension dimension2 = new Dimension( 10,10);          public void initToolBar() {
302          // this.addSeparator(dimension2);                  setAlignmentY(1f);
303                    removeAll();
304          // // Action buttons                  // Separator to the left of the tool actions to start
305          // for (JButton b : actionButtons.values())                  // the tool buttons with the map (not with the coordinate grid)
306          // add(b);                  Dimension dimension = new Dimension(49, 10);
307          // }                  addSeparator(dimension);
308                    // Tool buttons
309          /**                  for (JComponent b : toolAndActionButtons.values())
310           * Performs the activation of a tool.                          add(b);
311           *  
312           * @param tool                  if (!toolAndActionButtons.containsKey(selectedTool)) {
313           *            the tool to activate                          /**
314           * @param e                           * This might be a bit specific, but IF selection buttons are
315           *            the event of the button                           * available, select one of them.. if not, select the INFO tool.
316           */                           */
317          public void performToolButton(int tool, ActionEvent e) {  
318                  if (mapPane == null)                          if (toolAndActionButtons.containsKey(TOOL_SELECTION_SET)) {
319                          return;                                  setSelectedTool(TOOL_SELECTION_SET);
320                            } else if (toolAndActionButtons.containsKey(TOOL_INFO)) {
321                  selectedTool = tool;                                  setSelectedTool(TOOL_INFO);
322                            } else {
323                  switch (tool) {                                  // TODO What to do now?!
324                  case TOOL_PAN:                                  setSelectedTool(null);
325                          // Set the mouse tool to "Panning"                          }
326                          mapPane.setWindowSelectionState(JMapPane.NONE);  
327                          mapPane.setState(JMapPane.PAN);                  }
328                          mapPane.setHighlight(false);                  
329                          mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);                  revalidate();
330                          break;                  repaint();
331                  case TOOL_INFO:          }
332                          // Set the mouse tool to "Info"  
333                          mapPane.setWindowSelectionState(JMapPane.NONE);          // Space between tool buttons and action buttons
334                          mapPane.setState(JMapPane.SELECT_TOP); // Why not:          // SK: Seperators are now als manages like actions and tools
335                          // JMapPane.SELECT_TOP_ONEONLY          // Dimension dimension2 = new Dimension( 10,10);
336                          mapPane.setHighlight(false);// SK: Was true, but since it not works          // this.addSeparator(dimension2);
337                          // properly removed it to save  
338                          // performance          // // Action buttons
339                          mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);          // for (JButton b : actionButtons.values())
340                          break;          // add(b);
341                  case TOOL_ZOOMIN:          // }
342                          // Set the mouse tool to "Zoom in"  
343                          mapPane.setWindowSelectionState(JMapPane.ZOOM_IN);          /**
344                          mapPane.setState(JMapPane.ZOOM_IN);           * Performs the activation of a tool.
345                          mapPane.setHighlight(false);           *
346                          mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);           * @param tool
347                          break;           *            the tool to activate
348                  case TOOL_ZOOMOUT:           * @param e
349                          // Set the mouse tool to "Zoom out"           *            the event of the button
350                          mapPane.setWindowSelectionState(JMapPane.NONE);           */
351                          mapPane.setState(JMapPane.ZOOM_OUT);          public void performToolButton(int tool, ActionEvent e) {
352                          mapPane.setHighlight(false);                  if (mapPane == null)
353                          mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);                          return;
354                          break;  
355                  default:                  selectedTool = tool;
356                          // Set map actions to default  
357                          mapPane.setWindowSelectionState(JMapPane.NONE);                  switch (tool) {
358                          mapPane.setState(JMapPane.NONE);                  case TOOL_PAN:
359                          mapPane.setHighlight(false);                          // Set the mouse tool to "Panning"
360                          mapPane.setNormalCursor(null);                          mapPane.setWindowSelectionState(JMapPane.NONE);
361                          break;                          mapPane.setState(JMapPane.PAN);
362                  }                          mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);
363                  mapPane.updateCursor();                          break;
364          }                  case TOOL_INFO:
365                            // Set the mouse tool to "Info"
366          /**                          mapPane.setWindowSelectionState(JMapPane.NONE);
367           * @param id                          mapPane.setState(JMapPane.SELECT_TOP); // Why not:
368           *            The ID of the Component to remove. The change will not be                          // JMapPane.SELECT_TOP_ONEONLY
369           *            visible until {@link #initToolBar()} is called.                          // properly removed it to save
370           * @return <code>null</code> or the component that has been removed.                          // performance
371           */                          mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);
372          public JComponent removeId(int id) {                          break;
373                  return toolAndActionButtons.remove(id);                  case TOOL_ZOOMIN:
374          }                          // Set the mouse tool to "Zoom in"
375                            mapPane.setWindowSelectionState(JMapPane.ZOOM_IN);
376          /**                          mapPane.setState(JMapPane.ZOOM_IN);
377           * Performs the action of an action button.                          mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);
378           *                          break;
379           * @param tool                  case TOOL_ZOOMOUT:
380           *            the action                          // Set the mouse tool to "Zoom out"
381           * @param e                          mapPane.setWindowSelectionState(JMapPane.NONE);
382           *            the event of the button                          mapPane.setState(JMapPane.ZOOM_OUT);
383           */                          mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);
384          protected void performActionButton(int action, ActionEvent e) {                          break;
385                  if (mapPane == null)                  default:
386                          return;                          // Set map actions to default
387                            mapPane.setWindowSelectionState(JMapPane.NONE);
388                  // Perform the action "Zoom back": Revert the last zoom                          mapPane.setState(JMapPane.NONE);
389                  if (action == ACTION_ZOOM_BACK) {                          mapPane.setNormalCursor(null);
390                          if (zoomBackIndex <= 1)                          break;
391                                  return;                  }
392                    mapPane.updateCursor();
393                          zoomBackForwardButtonInAction = true;          }
394                          zoomBackIndex--;  
395                          getButton(ACTION_ZOOM_FORWARD).setEnabled(true);          /**
396                          getButton(ACTION_ZOOM_BACK).setEnabled(zoomBackIndex > 1);           * @param id
397             *            The ID of the Component to remove. The change will not be
398                          mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1));           *            visible until {@link #initToolBar()} is called.
399                          mapPane.refresh();           * @return <code>null</code> or the component that has been removed.
400                  }           */
401            public JComponent removeId(int id) {
402                  // Perform the action "Zoom forward": Re-do the last zoom                  return toolAndActionButtons.remove(id);
403                  if (action == ACTION_ZOOM_FORWARD) {          }
404                          if (zoomBackIndex < lastZooms.size()) {  
405                                  zoomBackForwardButtonInAction = true;          /**
406                                  zoomBackIndex++;           * Performs the action of an action button.
407                                  getButton(ACTION_ZOOM_BACK).setEnabled(true);           *
408                                  getButton(ACTION_ZOOM_FORWARD).setEnabled(           * @param tool
409                                                  zoomBackIndex < lastZooms.size());           *            the action
410             * @param e
411                                  mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1));           *            the event of the button
412                                  mapPane.refresh();           */
413                          }          protected void performActionButton(int action, ActionEvent e) {
414                  }                  if (mapPane == null)
415          }                          return;
416    
417          /**                  // Perform the action "Zoom back": Revert the last zoom
418           * Adds a tool to the tool bar. Does nothing if a tool or action with the                  if (action == ACTION_ZOOM_BACK) {
419           * specified ID already exists!                          if (zoomBackIndex <= 1)
420           *                                  return;
421           * @param buttonAction  
422           *            action for the toggle button                          zoomBackForwardButtonInAction = true;
423           * @param resetToolBar                          zoomBackIndex--;
424           *            indicates whether the toolbar GUI is reset after adding the                          getButton(ACTION_ZOOM_FORWARD).setEnabled(true);
425           *            button (if adding several actions it useful only to reset the                          getButton(ACTION_ZOOM_BACK).setEnabled(zoomBackIndex > 1);
426           *            GUI for the last added tool)  
427           */                          mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1));
428          public void addTool(MapPaneToolBarAction buttonAction, boolean resetToolBar) {                          mapPane.refresh();
429                  if (isButtonIDUsed(buttonAction.getID())) {                  }
430                          LOGGER  
431                                          .warn("addTool(.) ignored because ID already used for tool or action: "                  // Perform the action "Zoom forward": Re-do the last zoom
432                                                          + buttonAction.getID());                  if (action == ACTION_ZOOM_FORWARD) {
433                          return;                          if (zoomBackIndex < lastZooms.size()) {
434                  }                                  zoomBackForwardButtonInAction = true;
435                  JToggleButton button = new JToggleButton(buttonAction);                                  zoomBackIndex++;
436                  button.setBorder(BorderFactory.createRaisedBevelBorder());                                  getButton(ACTION_ZOOM_BACK).setEnabled(true);
437                  toolButtonGroup.add(button);                                  getButton(ACTION_ZOOM_FORWARD).setEnabled(
438                  toolAndActionButtons.put(buttonAction.getID(), button);                                                  zoomBackIndex < lastZooms.size());
439                  if (resetToolBar)  
440                          initToolBar();                                  mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1));
441          }                                  mapPane.refresh();
442                            }
443          /**                  }
444           * Adds a tool to the tool bar and resets the toolbar GUI.          }
445           *  
446           * @param buttonAction          /**
447           *            action for the toggle button           * Adds a tool to the tool bar. Does nothing if a tool or action with the
448           */           * specified ID already exists!
449          public void addTool(MapPaneToolBarAction buttonAction) {           *
450                  addTool(buttonAction, true);           * @param buttonAction
451          }           *            action for the toggle button
452             * @param resetToolBar
453          /**           *            indicates whether the toolbar GUI is reset after adding the
454           * Adds an action to the tool bar. Does nothing if a tool or action with the           *            button (if adding several actions it useful only to reset the
455           * specified ID already exists!           *            GUI for the last added tool)
456           *           */
457           * @param buttonAction          public void addTool(MapPaneToolBarAction buttonAction, boolean resetToolBar) {
458           *            action for the button                  if (isButtonIDUsed(buttonAction.getID())) {
459           * @param resetToolBar                          LOGGER
460           *            indicates whether the toolbar GUI is reset after adding the                                          .warn("addTool(.) ignored because ID already used for tool or action: "
461           *            button (if adding several actions it useful only to reset the                                                          + buttonAction.getID());
462           *            GUI for the last added tool)                          return;
463           */                  }
464          public void addAction(MapPaneToolBarAction buttonAction,                  JToggleButton button = new JToggleButton(buttonAction);
465                          boolean resetToolBar) {                  button.setBorder(BorderFactory.createRaisedBevelBorder());
466                  if (isButtonIDUsed(buttonAction.getID())) {                  toolButtonGroup.add(button);
467                          LOGGER                  toolAndActionButtons.put(buttonAction.getID(), button);
468                                          .warn("addAction(.) ignored because ID already used for tool or action: "                  if (resetToolBar)
469                                                          + buttonAction.getID());                          initToolBar();
470                          return;          }
471                  }  
472                  JButton button = new JButton(buttonAction);  
473                  button.setBorder(BorderFactory.createRaisedBevelBorder());  
474                  toolAndActionButtons.put(buttonAction.getID(), button);          /**
475                  if (resetToolBar)           * Adds a tool to the tool bar and resets the toolbar GUI.
476                          initToolBar();           *
477          }           * @param buttonAction
478             *            action for the toggle button
479          public void addSeparator(int id, Separator separator) {           */
480                  if (isButtonIDUsed(id)) {          public void addTool(MapPaneToolBarAction buttonAction) {
481                          LOGGER                  addTool(buttonAction, true);
482                                          .warn("addSeparator(.) ignored because ID already used for tool or action. ");          }
483                          return;  
484                  }          /**
485                  toolAndActionButtons.put(id, separator);           * Adds an action to the tool bar. Does nothing if a tool or action with the
486          }           * specified ID already exists!
487             *
488          /**           * @param buttonAction
489           * Adds an action to the tool bar and resets the toolbar GUI.           *            action for the button
490           *           * @param resetToolBar
491           * @param buttonAction           *            indicates whether the toolbar GUI is reset after adding the
492           *            action for the toggle button           *            button (if adding several actions it useful only to reset the
493           */           *            GUI for the last added tool)
494          public void addAction(MapPaneToolBarAction buttonAction) {           */
495                  addAction(buttonAction, true);          public void addAction(MapPaneToolBarAction buttonAction,
496          }                          boolean resetToolBar) {
497                    if (isButtonIDUsed(buttonAction.getID())) {
498          /**                          LOGGER
499           * Returns the button for a specific tool or action.                                          .warn("addAction(.) ignored because ID already used for tool or action: "
500           *                                                          + buttonAction.getID());
501           * @param id                          return;
502           *            the constant for any button in the {@link MapPaneToolBar}                  }
503           * @return a {@link JButton} if {@code id} specifies an                  JButton button = new JButton(buttonAction);
504           *         {@linkplain #getActionButton(int) action button} or                  button.setBorder(BorderFactory.createRaisedBevelBorder());
505           *         {@link JToogleButton} if {@code id} specifies a                  toolAndActionButtons.put(buttonAction.getID(), button);
506           *         {@linkplain #getToolButton(int) tool button}                  if (resetToolBar)
507           */                          initToolBar();
508          public AbstractButton getButton(int id) {          }
509                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);          
510                  if (button == null)          /**
511                          LOGGER.warn("Unknown tool or action ID: " + id);           * Adds any JComponent to the tool bar. Does nothing if a tool or action with the
512                  return button;           * specified ID already exists!
513          }           *
514             * @param component A {@link JComponent} that shall be added
515          /**           * @param id The ID associaded with the {@link JComponent}
516           * Returns the button for a specific tool.           * @param resetToolBar
517           *           *            indicates whether the toolbar GUI is reset after adding the
518           * @param tool           *            button (if adding several actions it useful only to reset the
519           *            the constant for a tool           *            GUI for the last added tool)
520           */           */
521          public JToggleButton getToolButton(int tool) {          public void addJComponent(JComponent component, int id,
522                  AbstractButton button = getButton(tool);                          boolean resetToolBar) {
523                  if (button != null && !(button instanceof JToggleButton)) {  
524                          LOGGER.warn("ID specifies no tool: " + tool);                  if (isButtonIDUsed(id)) {
525                          button = null;                          LOGGER
526                  }                          .warn("addAction(.) ignored because ID already used for tool or action: "
527                  return (JToggleButton) button;                                          + id);
528          }                          return;
529                    }
530          /**                  
531           * Returns the button for a specific action.                  toolAndActionButtons.put(id, component);
532           *                  if (resetToolBar)
533           * @param action                          initToolBar();
534           *            the constant an action          }
535           */  
536          public JButton getActionButton(int action) {          public void addSeparator(int id, Separator separator) {
537                  AbstractButton button = getButton(action);                  if (isButtonIDUsed(id)) {
538                  if (button != null && !(button instanceof JButton)) {                          LOGGER
539                          LOGGER.warn("ID specifies no action: " + action);                                          .warn("addSeparator(.) ignored because ID already used for tool or action. ");
540                          button = null;                          return;
541                  }                  }
542                  return (JButton) button;                  toolAndActionButtons.put(id, separator);
543            }
544          }  
545            /**
546          /**           * Adds an action to the tool bar and resets the toolbar GUI.
547           * Sets the selected tool.           *
548           *           * @param buttonAction
549           * @param tool           *            action for the toggle button
550           *            ID of the tool           */
551           */          public void addAction(MapPaneToolBarAction buttonAction) {
552          public void setSelectedTool(Integer tool) {                  addAction(buttonAction, true);
553                  if (tool == null)          }
554                          toolButtonGroup.setUnselected();  
555            /**
556                  JToggleButton button = getToolButton(tool);           * Returns the button for a specific tool or action.
557                  if (button == null)           *
558                          return;           * @param id
559                  button.setSelected(true);           *            the constant for any button in the {@link MapPaneToolBar}
560                  button.getAction().actionPerformed(null);           * @return a {@link JButton} if {@code id} specifies an
561             *         {@linkplain #getActionButton(int) action button} or
562                  selectedTool = tool;           *         {@link JToogleButton} if {@code id} specifies a
563          }           *         {@linkplain #getToolButton(int) tool button}
564             */
565          /**          public AbstractButton getButton(int id) {
566           * Returns the selected tool.                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);
567           *                  if (button == null)
568           * @return -1 if no tool is active                          LOGGER.warn("Unknown tool or action ID: " + id);
569           */                  return button;
570          public int getSelectedTool() {          }
571                  if (toolButtonGroup.getSelectedButton() == null)  
572                          return -1;          /**
573                  return selectedTool;           * Returns the button for a specific tool.
574          }           *
575             * @param tool
576          /**           *            the constant for a tool
577           * Sets whether a tool or action is activated or not. The visible property           */
578           * of the button is not affected.          public JToggleButton getToolButton(int tool) {
579           *                  AbstractButton button = getButton(tool);
580           * @param id                  if (button != null && !(button instanceof JToggleButton)) {
581           *            tool or actionID                          LOGGER.warn("ID specifies no tool: " + tool);
582           * @param enabled                          button = null;
583           *            if {@code true} the tool becomes available                  }
584           */                  return (JToggleButton) button;
585          public void setButtonEnabled(int id, boolean enabled) {          }
586                  AbstractButton button = getButton(id);  
587                  if (button == null)          /**
588                          return;           * Returns the button for a specific action.
589                  button.setEnabled(enabled);           *
590          }           * @param action
591             *            the constant an action
592          /**           */
593           * Sets whether a tool or action is activated or not.          public JButton getActionButton(int action) {
594           *                  AbstractButton button = getButton(action);
595           * @param id                  if (button != null && !(button instanceof JButton)) {
596           *            tool or actionID                          LOGGER.warn("ID specifies no action: " + action);
597           * @param enabled                          button = null;
598           *            if {@code true} the tool becomes available                  }
599           * @param hideOnDisable                  return (JButton) button;
600           *            if {@code true} the button is also hidden if {@code enabled}  
601           *            is {@code false}          }
602           */  
603          public void setButtonEnabled(int id, boolean enabled, boolean hideOnDisable) {          /**
604                  AbstractButton button = getButton(id);           * Sets the selected tool.
605                  if (button == null)           *
606                          return;           * @param tool
607                  button.setEnabled(enabled);           *            ID of the tool
608                  // if button is enabled, it becomes visible anyway           */
609                  // if button is disabled and the "hide" option is set, it is also hidden          public void setSelectedTool(Integer tool) {
610                  if (enabled)                  if (tool == null)
611                          button.setVisible(true);                          toolButtonGroup.setUnselected();
612                  else  
613                          button.setVisible(!hideOnDisable);                  JToggleButton button = getToolButton(tool);
614          }                  if (button == null)
615                            return;
616          /**                  button.setSelected(true);
617           * Checks whether a ID is already used for a tool or action.                  button.getAction().actionPerformed(null);
618           *  
619           * @param tool                  selectedTool = tool;
620           *            tool ID          }
621           */  
622          public boolean isButtonIDUsed(int id) {          /**
623                  return toolAndActionButtons.get(id) != null;           * Returns the selected tool.
624          }           *
625             * @return -1 if no tool is active
626          /**           */
627           * Checks whether a tool is activated.          public int getSelectedTool() {
628           *                  if (toolButtonGroup.getSelectedButton() == null)
629           * @param tool                          return -1;
630           *            tool ID                  return selectedTool;
631           * @return {@code false} if an unknown ID is specified          }
632           */  
633          public boolean isButtonEnabled(int id) {          /**
634                  AbstractButton button = getButton(id);           * Sets whether a tool or action is activated or not. The visible property
635                  if (button != null)           * of the button is not affected.
636                          return button.isEnabled();           *
637                  return false;           * @param id
638          }           *            tool or actionID
639             * @param enabled
640          /**           *            if {@code true} the tool becomes available
641           * Sets the activation for all tools.           */
642           *          public void setButtonEnabled(int id, boolean enabled) {
643           * @param enabled                  AbstractButton button = getButton(id);
644           *            if {@code true} all tools becomes available                  if (button == null)
645           * @param hideOnDisable                          return;
646           *            if {@code true} the buttons are also hidden if {@code enabled}                  button.setEnabled(enabled);
647           *            is {@code false}          }
648           */  
649          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {          /**
650                  for (int tool : toolAndActionButtons.keySet())           * Sets whether a tool or action is activated or not.
651                          setButtonEnabled(tool, enabled, hideOnDisable);           *
652          }           * @param id
653             *            tool or actionID
654          /**           * @param enabled
655           * Sets the activation for all actions.           *            if {@code true} the tool becomes available
656           *           * @param hideOnDisable
657           * @param enabled           *            if {@code true} the button is also hidden if {@code enabled}
658           *            if {@code true} all actions becomes available           *            is {@code false}
659           * @param hideOnDisable           */
660           *            if {@code true} the buttons are also hidden if {@code enabled}          public void setButtonEnabled(int id, boolean enabled, boolean hideOnDisable) {
661           *            is {@code false}                  AbstractButton button = getButton(id);
662           */                  if (button == null)
663          public void setAllActionsEnabled(boolean enabled, boolean hideOnDisable) {                          return;
664                  for (int id : toolAndActionButtons.keySet()) {                  button.setEnabled(enabled);
665                          if (toolAndActionButtons.get(id) instanceof JButton) {                  // if button is enabled, it becomes visible anyway
666                                  setButtonEnabled(id, enabled, hideOnDisable);                  // if button is disabled and the "hide" option is set, it is also hidden
667                          }                  if (enabled)
668                  }                          button.setVisible(true);
669                    else
670          }                          button.setVisible(!hideOnDisable);
671            }
672          /**  
673           * Returns the maximum ID of tools.          /**
674           */           * Checks whether a ID is already used for a tool or action.
675          public int getMaxToolID() {           *
676                  return toolAndActionButtons.lastKey();           * @param tool
677          }           *            tool ID
678             */
679          /**          public boolean isButtonIDUsed(int id) {
680           * Returns the minimum ID of tools.                  return toolAndActionButtons.get(id) != null;
681           */          }
682          public int getMinToolID() {  
683                  return toolAndActionButtons.firstKey();          /**
684          }           * Checks whether a tool is activated.
685             *
686          /**           * @param tool
687           * Extends the {@link AbstractAction} with maintaining an ID and the           *            tool ID
688           * {@link MapPaneToolBar} the actions controls. Additionally this class           * @return {@code false} if an unknown ID is specified
689           * automatically calls           */
690           * {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or          public boolean isButtonEnabled(int id) {
691           * {@link MapPaneToolBar#performActionButton(int, ActionEvent)} depending on                  AbstractButton button = getButton(id);
692           * whether the action is added via                  if (button != null)
693           * {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or                          return button.isEnabled();
694           * {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.                  return false;
695           *          }
696           * @author <a href="mailto:[email protected]">Martin Schmitz</a>  
697           *         (University of Bonn/Germany)          /**
698           */           * Sets the activation for all tools.
699          public static class MapPaneToolBarAction extends AbstractAction {           *
700                  /** The ID of the action */           * @param enabled
701                  protected int id = -1;           *            if {@code true} all tools becomes available
702                  /** The tool bar, this action is made for. */           * @param hideOnDisable
703                  protected MapPaneToolBar toolBar = null;           *            if {@code true} the buttons are also hidden if {@code enabled}
704             *            is {@code false}
705                  /**           */
706                   * Creates a new action with a dummy description and no icon.          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {
707                   *                  for (int tool : toolAndActionButtons.keySet())
708                   * @param id                          setButtonEnabled(tool, enabled, hideOnDisable);
709                   *            unique ID for the action          }
710                   * @param toolBar  
711                   *            toolbar this action is made for          /**
712                   */           * Sets the activation for all actions.
713                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar) {           *
714                          this(id, toolBar, "" + id);           * @param enabled
715                  }           *            if {@code true} all actions becomes available
716             * @param hideOnDisable
717                  /**           *            if {@code true} the buttons are also hidden if {@code enabled}
718                   * Creates a new action without an icon.           *            is {@code false}
719                   *           */
720                   * @param id          public void setAllActionsEnabled(boolean enabled, boolean hideOnDisable) {
721                   *            unique ID for the action                  for (int id : toolAndActionButtons.keySet()) {
722                   * @param toolBar                          if (toolAndActionButtons.get(id) instanceof JButton) {
723                   *            toolbar this action is made for                                  setButtonEnabled(id, enabled, hideOnDisable);
724                   * @param name                          }
725                   *            description used for buttons or menus                  }
726                   */  
727                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, String name) {          }
728                          this(id, toolBar, name, null);  
729                  }          /**
730             * Returns the maximum ID of tools.
731                  /**           */
732                   * Creates a new action.          public int getMaxToolID() {
733                   *                  return toolAndActionButtons.lastKey();
734                   * @param id          }
735                   *            unique ID for the action  
736                   * @param toolBar          /**
737                   *            toolbar this action is made for           * Returns the minimum ID of tools.
738                   * @param name           */
739                   *            description used for buttons or menus          public int getMinToolID() {
740                   * @param icon                  return toolAndActionButtons.firstKey();
741                   *            icon used for buttons or menus          }
742                   */  
743                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,          /**
744                                  String name, Icon icon) {           * Extends the {@link AbstractAction} with maintaining an ID and the
745                          this (id, toolBar, name, icon, null);           * {@link MapPaneToolBar} the actions controls. Additionally this class
746                  }           * automatically calls
747                             * {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or
748                  /**           * {@link MapPaneToolBar#performActionButton(int, ActionEvent)} depending on
749                   * Creates a new action.           * whether the action is added via
750                   *           * {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or
751                   * @param id           * {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.
752                   *            unique ID for the action           *
753                   * @param toolBar           * @author <a href="mailto:[email protected]">Martin Schmitz</a>
754                   *            The {@link MapPaneToolBar} this action is made for           *         (University of Bonn/Germany)
755                   * @param name           */
756                   *            description used for buttons or menus          public static class MapPaneToolBarAction extends AbstractAction {
757                   * @param icon                  /** The ID of the action */
758                   *            icon used for buttons or menus                  protected int id = -1;
759                   * @param toolTip                  /** The tool bar, this action is made for. */
760                   *            Tooltip to use for the button or menu                  protected MapPaneToolBar toolBar = null;
761                   */  
762                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,                  /**
763                                  String name, Icon icon, String toolTip) {                   * Creates a new action with a dummy description and no icon.
764                          super(name, icon);                   *
765                                             * @param id
766                          if (toolTip != null && !toolTip.trim().isEmpty()){                   *            unique ID for the action
767                                  putValue(Action.SHORT_DESCRIPTION, toolTip);                   * @param toolBar
768                          }                   *            toolbar this action is made for
769                                             */
770                          this.id = id;                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar) {
771                          this.toolBar = toolBar;                          this(id, toolBar, "" + id);
772                  }                  }
773    
774                  /**                  /**
775                   * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or                   * Creates a new action without an icon.
776                   * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}                   *
777                   * depending on whether the action is added to the toolbar via                   * @param id
778                   * {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or                   *            unique ID for the action
779                   * {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.                   * @param toolBar
780                   */                   *            toolbar this action is made for
781                  public void actionPerformed(ActionEvent e) {                   * @param name
782                          if (toolBar.toolAndActionButtons.get(id) instanceof JToggleButton)                   *            description used for buttons or menus
783                                  toolBar.performToolButton(id, e);                   */
784                          else if (toolBar.toolAndActionButtons.get(id) instanceof JButton)                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, String name) {
785                                  toolBar.performActionButton(id, e);                          this(id, toolBar, name, null);
786                  }                  }
787    
788                  /**                  /**
789                   * Returns the (unique) id of this action.                   * Creates a new action.
790                   *                   *
791                   * @return                   * @param id
792                   */                   *            unique ID for the action
793                  public int getID() {                   * @param toolBar
794                          return id;                   *            toolbar this action is made for
795                  }                   * @param name
796          }                   *            description used for buttons or menus
797  }                   * @param icon
798                     *            icon used for buttons or menus
799                     */
800                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
801                                    String name, Icon icon) {
802                            this (id, toolBar, name, icon, null);
803                    }
804                    
805                    /**
806                     * Creates a new action.
807                     *
808                     * @param id
809                     *            unique ID for the action
810                     * @param toolBar
811                     *            The {@link MapPaneToolBar} this action is made for
812                     * @param name
813                     *            description used for buttons or menus
814                     * @param icon
815                     *            icon used for buttons or menus
816                     * @param toolTip
817                     *            Tooltip to use for the button or menu
818                     */
819                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
820                                    String name, Icon icon, String toolTip) {
821                            super(name, icon);
822                            
823                            if (toolTip != null && !toolTip.trim().isEmpty()){
824                                    putValue(Action.SHORT_DESCRIPTION, toolTip);
825                            }
826                            
827                            this.id = id;
828                            this.toolBar = toolBar;
829                    }
830    
831                    /**
832                     * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or
833                     * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}
834                     * depending on whether the action is added to the toolbar via
835                     * {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or
836                     * {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}.
837                     */
838                    public void actionPerformed(ActionEvent e) {
839                            if (toolBar.toolAndActionButtons.get(id) instanceof JToggleButton)
840                                    toolBar.performToolButton(id, e);
841                            else if (toolBar.toolAndActionButtons.get(id) instanceof JButton)
842                                    toolBar.performActionButton(id, e);
843                    }
844    
845                    /**
846                     * Returns the (unique) id of this action.
847                     *
848                     * @return
849                     */
850                    public int getID() {
851                            return id;
852                    }
853            }
854            
855              /**
856               * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht wird) wird. Dann werden wird der
857               * Hintergrund auf WEISS gesetzt.
858               *
859               * @author <a href="mailto:[email protected]">Stefan Alfons
860               *         Kr&uuml;ger</a>
861               */
862              @Override
863              public void print(Graphics g) {
864                  Color orig = getBackground();
865                  setBackground(Color.WHITE);
866                  // wrap in try/finally so that we always restore the state
867                  try {
868                      super.print(g);
869                  } finally {
870                      setBackground(orig);
871                  }
872              }
873    }

Legend:
Removed from v.160  
changed lines
  Added in v.336

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26