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

Legend:
Removed from v.48  
changed lines
  Added in v.297

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26