/[schmitzm]/trunk/src/skrueger/geotools/MapPaneToolBar.java
ViewVC logotype

Diff of /trunk/src/skrueger/geotools/MapPaneToolBar.java

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

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

Legend:
Removed from v.180  
changed lines
  Added in v.315

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26