/[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 244 by alfonx, Wed Jul 29 09:33:33 2009 UTC revision 891 by alfonx, Thu Jun 3 12:20:11 2010 UTC
# Line 2  Line 2 
2   * Copyright (c) 2009 Martin O. J. Schmitz.   * Copyright (c) 2009 Martin O. J. Schmitz.
3   *   *
4   * This file is part of the SCHMITZM library - a collection of utility   * This file is part of the SCHMITZM library - a collection of utility
5   * classes based on Java 1.6, focussing (not only) on Java Swing   * classes based on Java 1.6, focusing (not only) on Java Swing
6   * and the Geotools library.   * and the Geotools library.
7   *   *
8   * The SCHMITZM project is hosted at:   * The SCHMITZM project is hosted at:
# Line 25  Line 25 
25   *   *
26   * Contributors:   * Contributors:
27   *     Martin O. J. Schmitz - initial API and implementation   *     Martin O. J. Schmitz - initial API and implementation
28   *     Stefan A. Krüger - additional utility classes   *     Stefan A. Tzeggai - additional utility classes
29   ******************************************************************************/   ******************************************************************************/
30  package skrueger.geotools;  package skrueger.geotools;
31    
32  import java.awt.Color;  import java.awt.Color;
 import java.awt.Dimension;  
33  import java.awt.Graphics;  import java.awt.Graphics;
34  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
35    import java.awt.event.ActionListener;
36  import java.util.ArrayList;  import java.util.ArrayList;
37  import java.util.Locale;  import java.util.HashSet;
38    import java.util.Set;
39  import java.util.SortedMap;  import java.util.SortedMap;
40  import java.util.TreeMap;  import java.util.TreeMap;
41    
42  import javax.swing.AbstractAction;  import javax.swing.AbstractAction;
43  import javax.swing.AbstractButton;  import javax.swing.AbstractButton;
44  import javax.swing.Action;  import javax.swing.Action;
 import javax.swing.BorderFactory;  
45  import javax.swing.Icon;  import javax.swing.Icon;
46  import javax.swing.ImageIcon;  import javax.swing.ImageIcon;
47  import javax.swing.JButton;  import javax.swing.JButton;
# Line 51  import javax.swing.JToolBar; Line 51  import javax.swing.JToolBar;
51    
52  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
53    
54  import schmitzm.geotools.gui.JMapPane;  import schmitzm.geotools.gui.GeotoolsGUIUtil;
55  import schmitzm.geotools.map.event.JMapPaneEvent;  import schmitzm.geotools.gui.SelectableXMapPane;
56    import schmitzm.geotools.gui.XMapPaneEvent;
57    import schmitzm.geotools.gui.XMapPaneTool;
58  import schmitzm.geotools.map.event.JMapPaneListener;  import schmitzm.geotools.map.event.JMapPaneListener;
59  import schmitzm.geotools.map.event.MapAreaChangedEvent;  import schmitzm.geotools.map.event.MapAreaChangedEvent;
 import schmitzm.lang.LangUtil;  
 import schmitzm.lang.ResourceProvider;  
60  import schmitzm.swing.ButtonGroup;  import schmitzm.swing.ButtonGroup;
61  import schmitzm.swing.SwingUtil;  import skrueger.swing.SmallButton;
62    import skrueger.swing.SmallToggleButton;
63    
64  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
65    
66  /**  /**
67   * A toolbar to control an {@link JMapPane} (Atlas visualization). This contains   * A toolbar to control an {@link SelectableXMapPane} (Atlas visualization). This contains
68   * two types of buttons. A group of <i>tools</i> for the mouse actions on the   * two types of buttons. A group of <i>tools</i> for the mouse actions on the
69   * map represented by {@link JToggleButton JToggleButtons}, where only one tool   * map represented by {@link JToggleButton JToggleButtons}, where only one tool
70   * can be activated every time. And some (general) <i>actions</i>, represented   * can be activated every time. And some (general) <i>actions</i>, represented
# Line 71  import com.vividsolutions.jts.geom.Envel Line 72  import com.vividsolutions.jts.geom.Envel
72   *   *
73   * @author <a href="mailto:[email protected]">Martin Schmitz</a>   * @author <a href="mailto:[email protected]">Martin Schmitz</a>
74   *         (University of Bonn/Germany)   *         (University of Bonn/Germany)
75   * @version 1.2 Stefan Krüger   * @version 1.2 Stefan Tzeggai
76   */   */
77  public class MapPaneToolBar extends JToolBar {  public class MapPaneToolBar extends JToolBar {
78          private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class          private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class
79                          .getName());                          .getName());
80            
         public static ResourceProvider RESOURCE = new ResourceProvider(LangUtil  
                         .extendPackagePath(MapPaneToolBar.class,  
                                         "resource.locales.mapPaneToolbar"), Locale.ENGLISH);  
           
81          public static String R(String key, Object... values) {          public static String R(String key, Object... values) {
82                  return RESOURCE.getString(key, values);                  return GeotoolsGUIUtil.R(key, values);
83          }          }
84    
85          /** Constant for the tool "Panning" (10). */          /** Constant for the tool "Panning" (10). */
# Line 93  public class MapPaneToolBar extends JToo Line 90  public class MapPaneToolBar extends JToo
90    
91          /** Constant for the tool "Zoom In" (110). */          /** Constant for the tool "Zoom In" (110). */
92          public static final int TOOL_ZOOMIN = 110;          public static final int TOOL_ZOOMIN = 110;
93            public static final int ACTION_ZOOM_DEFAULT = 150;
94          /** Constant for the tool "Zoom Out" (120). */          /** Constant for the tool "Zoom Out" (120). */
95          public static final int TOOL_ZOOMOUT = 120;          public static final int TOOL_ZOOMOUT = 120;
96          /** Constant for the action "Zoom back" (130). */          /** Constant for the action "Zoom back" (130). */
# Line 122  public class MapPaneToolBar extends JToo Line 120  public class MapPaneToolBar extends JToo
120           */           */
121          public static final int TOOL_SELECTION_REMOVE = 230;          public static final int TOOL_SELECTION_REMOVE = 230;
122    
123            public static final int ACTION_CHARTS = 401;
124    
125          /** Tool currently selected */          /** Tool currently selected */
126          protected int selectedTool = TOOL_ZOOMIN;          protected int selectedTool = TOOL_ZOOMIN;
127    
128          /** Holds the tool buttons of the tool bar. */          /** Holds the tool buttons of the tool bar. */
129          protected SortedMap<Integer, JComponent> toolAndActionButtons = null;          final protected SortedMap<Integer, JComponent> toolAndActionButtons = new TreeMap<Integer, JComponent>();
130          /** Controls that only one tool button is activated. */          /** Controls that only one tool button is activated. */
131          protected ButtonGroup toolButtonGroup = null;          protected ButtonGroup toolButtonGroup = null;
132    
# Line 135  public class MapPaneToolBar extends JToo Line 135  public class MapPaneToolBar extends JToo
135          // /** Holds the action buttons of the bar. */          // /** Holds the action buttons of the bar. */
136          // protected SortedMap<Integer, JButton> actionButtons = null;          // protected SortedMap<Integer, JButton> actionButtons = null;
137    
138          /** Holds the {@link JMapPane} this tool bar controls. */          /** Holds the {@link SelectableXMapPane} this tool bar controls. */
139          protected JMapPane mapPane = null;          protected SelectableXMapPane mapPane = null;
140    
141          /**          /**
142           * A List to remember the last Envelopes that have been watched. Used for           * A List to remember the last Envelopes that have been watched. Used for
# Line 151  public class MapPaneToolBar extends JToo Line 151  public class MapPaneToolBar extends JToo
151    
152          protected boolean zoomBackForwardButtonInAction;          protected boolean zoomBackForwardButtonInAction;
153    
154            /** Listeners what want to be informed about a change of the selected tool **/
155            protected Set<MapPaneToolSelectedListener> toolSelectionListeners = new HashSet<MapPaneToolSelectedListener>();
156    
157            /** This listener is added to all {@link JToggleButton} **/
158            private final ActionListener toolSelectedListener = new ActionListener() {
159    
160                    @Override
161                    public void actionPerformed(ActionEvent e) {
162                            JToggleButton tb = (JToggleButton) e.getSource();
163    
164                            // Inform the listeners about a newly selected tool
165                            for (MapPaneToolSelectedListener l : toolSelectionListeners) {
166                                    l.toolSelected(Integer.valueOf(tb.getName()));
167                            }
168                    }
169    
170            };
171    
172          /**          /**
173           * Creates a new toolbar. Notice: This toolbar does nothing until           * Creates a new toolbar. Notice: This toolbar does nothing until
174           * {@link #setMapPane(JMapPane)} is called!           * {@link #setMapPane(SelectableXMapPane)} is called!
175           */           */
176          public MapPaneToolBar() {          public MapPaneToolBar() {
177                  this(null);                  this(null);
178          }          }
179    
180            public void addButtonSelectedListener(MapPaneToolSelectedListener listener) {
181                    toolSelectionListeners.add(listener);
182            }
183    
184            public void removeButtonSelectedListener(
185                            MapPaneToolSelectedListener listener) {
186                    toolSelectionListeners.remove(listener);
187            }
188    
189          /**          /**
190           * Creates a new tool bar.           * Creates a new tool bar.
191           *           *
192           * @param mapPane           * @param mapPane
193           *            {@link JMapPane} the tool bar controls           *            {@link SelectableXMapPane} the tool bar controls
194           */           */
195          public MapPaneToolBar(JMapPane mapPane) {          public MapPaneToolBar(SelectableXMapPane mapPane) {
196                  super("Control the map", JToolBar.HORIZONTAL);                  super("Control the map", JToolBar.HORIZONTAL);
197                  this.toolAndActionButtons = new TreeMap<Integer, JComponent>();  
198                    // I want to see nothing on the background
199                    setOpaque(false);
200                    setBorder(null);
201    
202                  this.toolButtonGroup = new ButtonGroup();                  this.toolButtonGroup = new ButtonGroup();
203                    
204                  // Create a Listener to listen to the zooms on the JMapPane                  // Create a Listener to listen to the zooms on the JMapPane
205                  this.mapPaneListener = new JMapPaneListener() {                  this.mapPaneListener = new JMapPaneListener() {
206                          public void performMapPaneEvent(JMapPaneEvent e) {                          public void performMapPaneEvent(XMapPaneEvent e) {
207                                  if (!(e instanceof MapAreaChangedEvent))                                  if (!(e instanceof MapAreaChangedEvent))
208                                          return;                                          return;
209    
# Line 183  public class MapPaneToolBar extends JToo Line 214  public class MapPaneToolBar extends JToo
214    
215                                  final MapAreaChangedEvent mapAreaChangedEvent = (MapAreaChangedEvent) e;                                  final MapAreaChangedEvent mapAreaChangedEvent = (MapAreaChangedEvent) e;
216                                  Envelope oldMapArea = mapAreaChangedEvent.getOldMapArea();                                  Envelope oldMapArea = mapAreaChangedEvent.getOldMapArea();
217                                    
218                                  final Envelope mapArea = mapAreaChangedEvent.getNewMapArea();                                  final Envelope mapArea = mapAreaChangedEvent.getNewMapArea();
219                                  if (mapArea == null || mapArea.equals(oldMapArea) ) {                                  if (mapArea == null || mapArea.equals(oldMapArea)
220                                          // If the MapArea didn't change... we don't want to register it as a zoom action.                                                  || Double.isNaN(mapArea.getMinX())
221                                                    || Double.isNaN(mapArea.getMaxX())
222                                                    || Double.isNaN(mapArea.getMinY())
223                                                    || Double.isNaN(mapArea.getMaxY())) {
224                                            // If the MapArea didn't change... we don't want to register
225                                            // it as a zoom action.
226                                          return;                                          return;
227                                  }                                  }
228                                    
229                                  if (lastZooms.size() == 0 && oldMapArea != null) {                                  if (lastZooms.size() == 0
230                                                    && oldMapArea != null
231                                                    && !oldMapArea.isNull()
232                                                    && !(Double.isNaN(oldMapArea.getMinX())
233                                                                    || Double.isNaN(oldMapArea.getMaxX())
234                                                                    || Double.isNaN(oldMapArea.getMinY()) || Double
235                                                                    .isNaN(oldMapArea.getMaxY()))) {
236                                          lastZooms.add(oldMapArea);                                          lastZooms.add(oldMapArea);
237                                          zoomBackIndex = 1;                                          zoomBackIndex = 1;
238                                  }                                  }
# Line 222  public class MapPaneToolBar extends JToo Line 264  public class MapPaneToolBar extends JToo
264          }          }
265    
266          /**          /**
267           * Sets the {@link JMapPane} controlled by this tool bar.           * Sets the {@link SelectableXMapPane} controlled by this tool bar.
268           *           *
269           * @param mapPane           * @param mapPane
270           *            {@link JMapPane} to control (if {@code null} this tool bar           *            {@link SelectableXMapPane} to control (if {@code null} this tool bar
271           *            controls NOTHING!)           *            controls NOTHING!)
272           */           */
273          public void setMapPane(JMapPane mapPane) {          public void setMapPane(SelectableXMapPane mapPane) {
274                  // Remove listener from old MapPane                  // Remove listener from old MapPane
275                  if (this.mapPane != null)                  if (this.mapPane != null)
276                          this.mapPane.removeMapPaneListener(mapPaneListener);                          this.mapPane.removeMapPaneListener(mapPaneListener);
# Line 242  public class MapPaneToolBar extends JToo Line 284  public class MapPaneToolBar extends JToo
284           * puts all tool buttons and all actions buttons to the tool bar.           * puts all tool buttons and all actions buttons to the tool bar.
285           */           */
286          protected void init() {          protected void init() {
287    
288                  initToolsAndActions();                  initToolsAndActions();
289    
290                  addSeparator(SEPERATOR0, new JToolBar.Separator());                  addSeparator(SEPERATOR0, new JToolBar.Separator());
# Line 258  public class MapPaneToolBar extends JToo Line 301  public class MapPaneToolBar extends JToo
301           * super.initTools()}.           * super.initTools()}.
302           */           */
303          protected void initToolsAndActions() {          protected void initToolsAndActions() {
304                  // Panning                  // Pan
305                  addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_PAN, this, XMapPaneTool.PAN), false);
306                                  MapView.class.getResource("resource/icons/pan.png")), R("MapPaneButtons.Pan.TT")), false);                  
307                  // Info                  // Info
308                  addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_INFO, this, XMapPaneTool.INFO), false);
                                 MapView.class.getResource("resource/icons/info.png")),R("MapPaneButtons.Info.TT")), false);  
309    
310                  // Zoom in                  // Zoom in
311                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, XMapPaneTool.ZOOM_IN), false);
312                                  MapView.class.getResource("resource/icons/zoom_in.png")), R("MapPaneButtons.ZoomIn.TT")),                  
                                 false);  
313                  // Zoom out                  // Zoom out
314                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, XMapPaneTool.ZOOM_OUT), false);
315                                  MapView.class.getResource("resource/icons/zoom_out.png")), R("MapPaneButtons.ZoomOut.TT")),                  
                                 false);  
   
316                  // Action button to revert the last zoom                  // Action button to revert the last zoom
317                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",
318                                  new ImageIcon(MapView.class                                  new ImageIcon(MapView.class
319                                                  .getResource("resource/icons/zoom_back.png")), R("MapPaneButtons.LastZoom.TT")), false);                                                  .getResource("resource/icons/zoom_back.png")),
320                                    R("MapPaneButtons.LastZoom.TT")), false);
321                  setButtonEnabled(ACTION_ZOOM_BACK, false);                  setButtonEnabled(ACTION_ZOOM_BACK, false);
322    
323                  // Action button to redo the last zoom                  // Action button to redo the last zoom
324                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "",                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "",
325                                  new ImageIcon(MapView.class                                  new ImageIcon(MapView.class
326                                                  .getResource("resource/icons/zoom_forward.png")), R("MapPaneButtons.NextZoom.TT")),                                                  .getResource("resource/icons/zoom_forward.png")),
327                                  false);                                  R("MapPaneButtons.NextZoom.TT")), false);
328                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);
329    
330                  // set the selected tool enabled                  // set the selected tool enabled
# Line 292  public class MapPaneToolBar extends JToo Line 332  public class MapPaneToolBar extends JToo
332    
333          }          }
334    
335            @Override
336            public void paint(Graphics g) {
337                    super.paint(g);
338            }
339    
340          /**          /**
341           * Clears the GUI of all components and adds all tool and action buttons to           * Clears the GUI of all components and adds all tool and action buttons to
342           * the tool bar.           * the tool bar.
343           */           */
344          public void initToolBar() {          public void initToolBar() {
                 setAlignmentY(1f);  
345                  removeAll();                  removeAll();
346                  // Separator to the left of the tool actions to start  
347                  // the tool buttons with the map (not with the coordinate grid)                  // // Separator to the left of the tool actions to start
348                  Dimension dimension = new Dimension(49, 10);                  // // the tool buttons with the map (not with the coordinate grid)
349                  addSeparator(dimension);                  // Dimension dimension = new Dimension(49, 10);
350                    // addSeparator(dimension);
351    
352                  // Tool buttons                  // Tool buttons
353                  for (JComponent b : toolAndActionButtons.values())                  for (Integer bKey : toolAndActionButtons.keySet()) {
354    
355                            JComponent b = toolAndActionButtons.get(bKey);
356    
357                            if (b instanceof JToggleButton) {
358                                    JToggleButton tb = (JToggleButton) b;
359                                    tb.setName(bKey.toString());
360                                    tb.addActionListener(toolSelectedListener);
361                            }
362    
363                          add(b);                          add(b);
364                    }
365    
366                  if (!toolAndActionButtons.containsKey(selectedTool)) {                  if (!toolAndActionButtons.containsKey(selectedTool)) {
367                          /**                          /**
# Line 323  public class MapPaneToolBar extends JToo Line 379  public class MapPaneToolBar extends JToo
379                          }                          }
380    
381                  }                  }
382                    
383                  revalidate();                  revalidate();
384                  repaint();                  repaint();
385          }          }
386    
         // 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);  
         // }  
   
387          /**          /**
388           * Performs the activation of a tool.           * Performs the activation of a tool.
389           *           *
# Line 354  public class MapPaneToolBar extends JToo Line 400  public class MapPaneToolBar extends JToo
400    
401                  switch (tool) {                  switch (tool) {
402                  case TOOL_PAN:                  case TOOL_PAN:
403                          // Set the mouse tool to "Panning"                          mapPane.setTool(XMapPaneTool.PAN);
                         mapPane.setWindowSelectionState(JMapPane.NONE);  
                         mapPane.setState(JMapPane.PAN);  
                         mapPane.setHighlight(false);  
                         mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);  
404                          break;                          break;
405                  case TOOL_INFO:                  case TOOL_INFO:
406                          // Set the mouse tool to "Info"                          mapPane.setTool(XMapPaneTool.INFO);
                         mapPane.setWindowSelectionState(JMapPane.NONE);  
                         mapPane.setState(JMapPane.SELECT_TOP); // Why not:  
                         // JMapPane.SELECT_TOP_ONEONLY  
                         mapPane.setHighlight(false);// SK: Was true, but since it not works  
                         // properly removed it to save  
                         // performance  
                         mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);  
407                          break;                          break;
408                  case TOOL_ZOOMIN:                  case TOOL_ZOOMIN:
409                          // Set the mouse tool to "Zoom in"                          mapPane.setTool(XMapPaneTool.ZOOM_IN);
                         mapPane.setWindowSelectionState(JMapPane.ZOOM_IN);  
                         mapPane.setState(JMapPane.ZOOM_IN);  
                         mapPane.setHighlight(false);  
                         mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);  
410                          break;                          break;
411                  case TOOL_ZOOMOUT:                  case TOOL_ZOOMOUT:
412                          // Set the mouse tool to "Zoom out"                          mapPane.setTool(XMapPaneTool.ZOOM_OUT);
                         mapPane.setWindowSelectionState(JMapPane.NONE);  
                         mapPane.setState(JMapPane.ZOOM_OUT);  
                         mapPane.setHighlight(false);  
                         mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);  
                         break;  
                 default:  
                         // Set map actions to default  
                         mapPane.setWindowSelectionState(JMapPane.NONE);  
                         mapPane.setState(JMapPane.NONE);  
                         mapPane.setHighlight(false);  
                         mapPane.setNormalCursor(null);  
413                          break;                          break;
414                  }                  }
                 mapPane.updateCursor();  
415          }          }
416    
417          /**          /**
# Line 416  public class MapPaneToolBar extends JToo Line 435  public class MapPaneToolBar extends JToo
435          protected void performActionButton(int action, ActionEvent e) {          protected void performActionButton(int action, ActionEvent e) {
436                  if (mapPane == null)                  if (mapPane == null)
437                          return;                          return;
438                    
439                  // Perform the action "Zoom back": Revert the last zoom                  // Perform the action "Zoom back": Revert the last zoom
440                  if (action == ACTION_ZOOM_BACK) {                  if (action == ACTION_ZOOM_BACK) {
441                          if (zoomBackIndex <= 1)                          if (zoomBackIndex <= 1)
# Line 464  public class MapPaneToolBar extends JToo Line 483  public class MapPaneToolBar extends JToo
483                                                          + buttonAction.getID());                                                          + buttonAction.getID());
484                          return;                          return;
485                  }                  }
486                  JToggleButton button = new JToggleButton(buttonAction);                  JToggleButton button = new SmallToggleButton(buttonAction);
487                  button.setBorder(BorderFactory.createRaisedBevelBorder());                  
488                  toolButtonGroup.add(button);                  toolButtonGroup.add(button);
489                  toolAndActionButtons.put(buttonAction.getID(), button);                  toolAndActionButtons.put(buttonAction.getID(), button);
490                  if (resetToolBar)                  if (resetToolBar)
# Line 501  public class MapPaneToolBar extends JToo Line 520  public class MapPaneToolBar extends JToo
520                                                          + buttonAction.getID());                                                          + buttonAction.getID());
521                          return;                          return;
522                  }                  }
523                  JButton button = new JButton(buttonAction);                  JButton button = new SmallButton(buttonAction);
                 button.setBorder(BorderFactory.createRaisedBevelBorder());  
524                  toolAndActionButtons.put(buttonAction.getID(), button);                  toolAndActionButtons.put(buttonAction.getID(), button);
525                  if (resetToolBar)                  if (resetToolBar)
526                          initToolBar();                          initToolBar();
527          }          }
528    
529            /**
530             * Adds any JComponent to the tool bar. Does nothing if a tool or action
531             * with the specified ID already exists!
532             *
533             * @param component
534             *            A {@link JComponent} that shall be added
535             * @param id
536             *            The ID associaded with the {@link JComponent}
537             * @param resetToolBar
538             *            indicates whether the toolbar GUI is reset after adding the
539             *            button (if adding several actions it useful only to reset the
540             *            GUI for the last added tool)
541             */
542            public void addJComponent(JComponent component, int id, boolean resetToolBar) {
543    
544                    if (isButtonIDUsed(id)) {
545                            LOGGER
546                                            .warn("addAction(.) ignored because ID already used for tool or action: "
547                                                            + id);
548                            return;
549                    }
550    
551                    toolAndActionButtons.put(id, component);
552                    if (resetToolBar)
553                            initToolBar();
554            }
555    
556          public void addSeparator(int id, Separator separator) {          public void addSeparator(int id, Separator separator) {
557                  if (isButtonIDUsed(id)) {                  if (isButtonIDUsed(id)) {
558                          LOGGER                          LOGGER
# Line 538  public class MapPaneToolBar extends JToo Line 583  public class MapPaneToolBar extends JToo
583           *         {@linkplain #getToolButton(int) tool button}           *         {@linkplain #getToolButton(int) tool button}
584           */           */
585          public AbstractButton getButton(int id) {          public AbstractButton getButton(int id) {
586                    
587                    //ACHUTNG: Das ist ein SK QUICK FIX! TODO
588                    if (!(toolAndActionButtons.get(id) instanceof AbstractButton)) return null;
589                    
590                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);
591                  if (button == null)                  if (button == null)
592                          LOGGER.warn("Unknown tool or action ID: " + id);                          LOGGER.warn("Unknown tool or action ID: " + id);
# Line 604  public class MapPaneToolBar extends JToo Line 653  public class MapPaneToolBar extends JToo
653                          return -1;                          return -1;
654                  return selectedTool;                  return selectedTool;
655          }          }
656            
657          /**          /**
658           * 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
659           * of the button is not affected.           * of the button is not affected.
# Line 679  public class MapPaneToolBar extends JToo Line 728  public class MapPaneToolBar extends JToo
728           *            is {@code false}           *            is {@code false}
729           */           */
730          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {
731                  for (int tool : toolAndActionButtons.keySet())                  for (int id : toolAndActionButtons.keySet()) {
732                          setButtonEnabled(tool, enabled, hideOnDisable);                          if (toolAndActionButtons.get(id) instanceof JToggleButton) {
733                            setButtonEnabled(id, enabled, hideOnDisable);
734                            }
735                    }
736          }          }
737            
738          /**          /**
739           * Sets the activation for all actions.           * Sets the activation for all actions.
740           *           *
# Line 774  public class MapPaneToolBar extends JToo Line 826  public class MapPaneToolBar extends JToo
826                   */                   */
827                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
828                                  String name, Icon icon) {                                  String name, Icon icon) {
829                          this (id, toolBar, name, icon, null);                          this(id, toolBar, name, icon, null);
830                  }                  }
831                    
832                  /**                  /**
833                   * Creates a new action.                   * Creates a new action.
834                   *                   *
# Line 794  public class MapPaneToolBar extends JToo Line 846  public class MapPaneToolBar extends JToo
846                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
847                                  String name, Icon icon, String toolTip) {                                  String name, Icon icon, String toolTip) {
848                          super(name, icon);                          super(name, icon);
849                            
850                          if (toolTip != null && !toolTip.trim().isEmpty()){                          if (toolTip != null && !toolTip.trim().isEmpty()) {
851                                  putValue(Action.SHORT_DESCRIPTION, toolTip);                                  putValue(Action.SHORT_DESCRIPTION, toolTip);
852                          }                          }
853                            
854                          this.id = id;                          this.id = id;
855                          this.toolBar = toolBar;                          this.toolBar = toolBar;
856                  }                  }
857    
858                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, XMapPaneTool tool) {
859                            this(id, toolBar, "", tool.getIcon(), tool.getToolTip());
860                    }
861    
862                  /**                  /**
863                   * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or                   * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or
864                   * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}                   * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}
# Line 826  public class MapPaneToolBar extends JToo Line 882  public class MapPaneToolBar extends JToo
882                          return id;                          return id;
883                  }                  }
884          }          }
885            
886            /**          /**
887             * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht wird) wird. Dann werden wird der           * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht
888             * Hintergrund auf WEISS gesetzt.           * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.
889             *           *
890             * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons
891             *         Kr&uuml;ger</a>           *         Tzeggai</a>
892             */           */
893            @Override          @Override
894            public void print(Graphics g) {          public void print(Graphics g) {
895                Color orig = getBackground();                  Color orig = getBackground();
896                setBackground(Color.WHITE);                  setBackground(Color.WHITE);
897                // wrap in try/finally so that we always restore the state                  // wrap in try/finally so that we always restore the state
898                try {                  try {
899                    super.print(g);                          super.print(g);
900                } finally {                  } finally {
901                    setBackground(orig);                          setBackground(orig);
902                }                  }
903            }          }
904    
905  }  }

Legend:
Removed from v.244  
changed lines
  Added in v.891

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26