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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26