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

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

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

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

Legend:
Removed from v.2  
changed lines
  Added in v.336

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26