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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26