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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26