/[schmitzm]/branches/1.0-gt2-2.6/src/skrueger/geotools/MapPaneToolBar.java
ViewVC logotype

Diff of /branches/1.0-gt2-2.6/src/skrueger/geotools/MapPaneToolBar.java

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

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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26