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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26