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

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

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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26