/[schmitzm]/branches/2.0-RC1/src/skrueger/geotools/MapPaneToolBar.java
ViewVC logotype

Diff of /branches/2.0-RC1/src/skrueger/geotools/MapPaneToolBar.java

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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26