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

Legend:
Removed from v.139  
changed lines
  Added in v.180

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26