/[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

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

Legend:
Removed from v.151  
changed lines
  Added in v.256

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26