/[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

branches/1.0-gt2-2.6/src/skrueger/geotools/MapPaneToolBar.java revision 315 by mojays, Wed Aug 26 11:03:27 2009 UTC branches/2.0-RC2/src/skrueger/geotools/MapPaneToolBar.java revision 655 by alfonx, Wed Feb 3 11:47:44 2010 UTC
# Line 30  Line 30 
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.HashSet;
38  import java.util.Locale;  import java.util.Locale;
39    import java.util.Set;
40  import java.util.SortedMap;  import java.util.SortedMap;
41  import java.util.TreeMap;  import java.util.TreeMap;
42    
43  import javax.swing.AbstractAction;  import javax.swing.AbstractAction;
44  import javax.swing.AbstractButton;  import javax.swing.AbstractButton;
45  import javax.swing.Action;  import javax.swing.Action;
 import javax.swing.BorderFactory;  
46  import javax.swing.Icon;  import javax.swing.Icon;
47  import javax.swing.ImageIcon;  import javax.swing.ImageIcon;
48  import javax.swing.JButton;  import javax.swing.JButton;
# Line 51  import javax.swing.JToolBar; Line 52  import javax.swing.JToolBar;
52    
53  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
54    
55  import schmitzm.geotools.gui.JMapPane;  import schmitzm.geotools.gui.SelectableXMapPane;
 import schmitzm.geotools.map.event.JMapPaneEvent;  
56  import schmitzm.geotools.map.event.JMapPaneListener;  import schmitzm.geotools.map.event.JMapPaneListener;
57  import schmitzm.geotools.map.event.MapAreaChangedEvent;  import schmitzm.geotools.map.event.MapAreaChangedEvent;
58    import schmitzm.geotools.map.event.MapPaneEvent;
59  import schmitzm.lang.LangUtil;  import schmitzm.lang.LangUtil;
60  import schmitzm.lang.ResourceProvider;  import schmitzm.lang.ResourceProvider;
61  import schmitzm.swing.ButtonGroup;  import schmitzm.swing.ButtonGroup;
62  import schmitzm.swing.SwingUtil;  import schmitzm.swing.SwingUtil;
63    import skrueger.swing.SmallButton;
64    import skrueger.swing.SmallToggleButton;
65    
66  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
67    
68  /**  /**
69   * A toolbar to control an {@link JMapPane} (Atlas visualization). This contains   * A toolbar to control an {@link SelectableXMapPane} (Atlas visualization). This contains
70   * 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
71   * map represented by {@link JToggleButton JToggleButtons}, where only one tool   * map represented by {@link JToggleButton JToggleButtons}, where only one tool
72   * 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 76  import com.vividsolutions.jts.geom.Envel Line 79  import com.vividsolutions.jts.geom.Envel
79  public class MapPaneToolBar extends JToolBar {  public class MapPaneToolBar extends JToolBar {
80          private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class          private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class
81                          .getName());                          .getName());
82            
83          public static ResourceProvider RESOURCE = new ResourceProvider(LangUtil          public static ResourceProvider RESOURCE = new ResourceProvider(LangUtil
84                          .extendPackagePath(MapPaneToolBar.class,                          .extendPackagePath(MapPaneToolBar.class,
85                                          "resource.locales.mapPaneToolbar"), Locale.ENGLISH);                                          "resource.locales.mapPaneToolbar"), Locale.ENGLISH);
86            
87          public static String R(String key, Object... values) {          public static String R(String key, Object... values) {
88                  return RESOURCE.getString(key, values);                  return RESOURCE.getString(key, values);
89          }          }
# Line 128  public class MapPaneToolBar extends JToo Line 131  public class MapPaneToolBar extends JToo
131          protected int selectedTool = TOOL_ZOOMIN;          protected int selectedTool = TOOL_ZOOMIN;
132    
133          /** Holds the tool buttons of the tool bar. */          /** Holds the tool buttons of the tool bar. */
134          protected SortedMap<Integer, JComponent> toolAndActionButtons = null;          final protected SortedMap<Integer, JComponent> toolAndActionButtons = new TreeMap<Integer, JComponent>();
135          /** Controls that only one tool button is activated. */          /** Controls that only one tool button is activated. */
136          protected ButtonGroup toolButtonGroup = null;          protected ButtonGroup toolButtonGroup = null;
137    
# Line 137  public class MapPaneToolBar extends JToo Line 140  public class MapPaneToolBar extends JToo
140          // /** Holds the action buttons of the bar. */          // /** Holds the action buttons of the bar. */
141          // protected SortedMap<Integer, JButton> actionButtons = null;          // protected SortedMap<Integer, JButton> actionButtons = null;
142    
143          /** Holds the {@link JMapPane} this tool bar controls. */          /** Holds the {@link SelectableXMapPane} this tool bar controls. */
144          protected JMapPane mapPane = null;          protected SelectableXMapPane mapPane = null;
145    
146          /**          /**
147           * 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 153  public class MapPaneToolBar extends JToo Line 156  public class MapPaneToolBar extends JToo
156    
157          protected boolean zoomBackForwardButtonInAction;          protected boolean zoomBackForwardButtonInAction;
158    
159            /** Listeners what want to be informed about a change of the selected tool **/
160            protected Set<MapPaneToolSelectedListener> toolSelectionListeners = new HashSet<MapPaneToolSelectedListener>();
161    
162            /** This listener is added to all {@link JToggleButton} **/
163            private final ActionListener toolSelectedListener = new ActionListener() {
164    
165                    @Override
166                    public void actionPerformed(ActionEvent e) {
167                            JToggleButton tb = (JToggleButton) e.getSource();
168    
169                            // Inform the listeners about a newly selected tool
170                            for (MapPaneToolSelectedListener l : toolSelectionListeners) {
171                                    l.toolSelected(Integer.valueOf(tb.getName()));
172                            }
173                    }
174    
175            };
176    
177          /**          /**
178           * Creates a new toolbar. Notice: This toolbar does nothing until           * Creates a new toolbar. Notice: This toolbar does nothing until
179           * {@link #setMapPane(JMapPane)} is called!           * {@link #setMapPane(SelectableXMapPane)} is called!
180           */           */
181          public MapPaneToolBar() {          public MapPaneToolBar() {
182                  this(null);                  this(null);
183          }          }
184    
185            public void addButtonSelectedListener(MapPaneToolSelectedListener listener) {
186                    toolSelectionListeners.add(listener);
187            }
188    
189            public void removeButtonSelectedListener(
190                            MapPaneToolSelectedListener listener) {
191                    toolSelectionListeners.remove(listener);
192            }
193    
194          /**          /**
195           * Creates a new tool bar.           * Creates a new tool bar.
196           *           *
197           * @param mapPane           * @param mapPane
198           *            {@link JMapPane} the tool bar controls           *            {@link SelectableXMapPane} the tool bar controls
199           */           */
200          public MapPaneToolBar(JMapPane mapPane) {          public MapPaneToolBar(SelectableXMapPane mapPane) {
201                  super("Control the map", JToolBar.HORIZONTAL);                  super("Control the map", JToolBar.HORIZONTAL);
202                  this.toolAndActionButtons = new TreeMap<Integer, JComponent>();  
203                    // I want to see nothing on the background
204                    setOpaque(false);
205                    setBorder(null);
206    
207                  this.toolButtonGroup = new ButtonGroup();                  this.toolButtonGroup = new ButtonGroup();
208                    
209                  // Create a Listener to listen to the zooms on the JMapPane                  // Create a Listener to listen to the zooms on the JMapPane
210                  this.mapPaneListener = new JMapPaneListener() {                  this.mapPaneListener = new JMapPaneListener() {
211                          public void performMapPaneEvent(JMapPaneEvent e) {                          public void performMapPaneEvent(MapPaneEvent e) {
212                                  if (!(e instanceof MapAreaChangedEvent))                                  if (!(e instanceof MapAreaChangedEvent))
213                                          return;                                          return;
214    
# Line 185  public class MapPaneToolBar extends JToo Line 219  public class MapPaneToolBar extends JToo
219    
220                                  final MapAreaChangedEvent mapAreaChangedEvent = (MapAreaChangedEvent) e;                                  final MapAreaChangedEvent mapAreaChangedEvent = (MapAreaChangedEvent) e;
221                                  Envelope oldMapArea = mapAreaChangedEvent.getOldMapArea();                                  Envelope oldMapArea = mapAreaChangedEvent.getOldMapArea();
222                                    
223                                  final Envelope mapArea = mapAreaChangedEvent.getNewMapArea();                                  final Envelope mapArea = mapAreaChangedEvent.getNewMapArea();
224                                  if (mapArea == null || mapArea.equals(oldMapArea) ) {                                  if (mapArea == null || mapArea.equals(oldMapArea)
225                                          // If the MapArea didn't change... we don't want to register it as a zoom action.                                                  || Double.isNaN(mapArea.getMinX())
226                                                    || Double.isNaN(mapArea.getMaxX())
227                                                    || Double.isNaN(mapArea.getMinY())
228                                                    || Double.isNaN(mapArea.getMaxY())) {
229                                            // If the MapArea didn't change... we don't want to register
230                                            // it as a zoom action.
231                                          return;                                          return;
232                                  }                                  }
233                                    
234                                  if (lastZooms.size() == 0 && oldMapArea != null) {                                  if (lastZooms.size() == 0
235                                                    && oldMapArea != null
236                                                    && !oldMapArea.isNull()
237                                                    && !(Double.isNaN(oldMapArea.getMinX())
238                                                                    || Double.isNaN(oldMapArea.getMaxX())
239                                                                    || Double.isNaN(oldMapArea.getMinY()) || Double
240                                                                    .isNaN(oldMapArea.getMaxY()))) {
241                                          lastZooms.add(oldMapArea);                                          lastZooms.add(oldMapArea);
242                                          zoomBackIndex = 1;                                          zoomBackIndex = 1;
243                                  }                                  }
# Line 224  public class MapPaneToolBar extends JToo Line 269  public class MapPaneToolBar extends JToo
269          }          }
270    
271          /**          /**
272           * Sets the {@link JMapPane} controlled by this tool bar.           * Sets the {@link SelectableXMapPane} controlled by this tool bar.
273           *           *
274           * @param mapPane           * @param mapPane
275           *            {@link JMapPane} to control (if {@code null} this tool bar           *            {@link SelectableXMapPane} to control (if {@code null} this tool bar
276           *            controls NOTHING!)           *            controls NOTHING!)
277           */           */
278          public void setMapPane(JMapPane mapPane) {          public void setMapPane(SelectableXMapPane mapPane) {
279                  // Remove listener from old MapPane                  // Remove listener from old MapPane
280                  if (this.mapPane != null)                  if (this.mapPane != null)
281                          this.mapPane.removeMapPaneListener(mapPaneListener);                          this.mapPane.removeMapPaneListener(mapPaneListener);
# Line 244  public class MapPaneToolBar extends JToo Line 289  public class MapPaneToolBar extends JToo
289           * puts all tool buttons and all actions buttons to the tool bar.           * puts all tool buttons and all actions buttons to the tool bar.
290           */           */
291          protected void init() {          protected void init() {
292    
293                  initToolsAndActions();                  initToolsAndActions();
294    
295                  addSeparator(SEPERATOR0, new JToolBar.Separator());                  addSeparator(SEPERATOR0, new JToolBar.Separator());
# Line 261  public class MapPaneToolBar extends JToo Line 307  public class MapPaneToolBar extends JToo
307           */           */
308          protected void initToolsAndActions() {          protected void initToolsAndActions() {
309                  // Panning                  // Panning
310                  addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(  //              addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(
311                                  MapView.class.getResource("resource/icons/pan.png")), R("MapPaneButtons.Pan.TT")), false);  //                              MapView.class.getResource("resource/icons/pan.png")),
312                  // Info  //                              R("MapPaneButtons.Pan.TT")), false);
                 addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(  
                                 MapView.class.getResource("resource/icons/info.png")),R("MapPaneButtons.Info.TT")), false);  
313    
314                    addTool(new MapPaneToolBarAction(TOOL_PAN, this, XMapPaneTool.PAN), false);
315                    
316                    // Info
317    //              addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(
318    //                              MapView.class.getResource("resource/icons/info.png")),
319    //                              R("MapPaneButtons.Info.TT")), false);
320                    addTool(new MapPaneToolBarAction(TOOL_INFO, this, XMapPaneTool.INFO), false);
321                    
322                  // Zoom in                  // Zoom in
323                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, XMapPaneTool.ZOOM_IN), false);
324                                  MapView.class.getResource("resource/icons/zoom_in.png")), R("MapPaneButtons.ZoomIn.TT")),                  
                                 false);  
325                  // Zoom out                  // Zoom out
326                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, XMapPaneTool.ZOOM_OUT), false);
327                                  MapView.class.getResource("resource/icons/zoom_out.png")), R("MapPaneButtons.ZoomOut.TT")),                  
328                                  false);                  
329    //              // Zoom in
330    //              addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(
331    //                              MapView.class.getResource("resource/icons/zoom_in.png")),
332    //                              R("MapPaneButtons.ZoomIn.TT")), false);
333    //              
334    //              // Zoom out
335    //              addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(
336    //                              MapView.class.getResource("resource/icons/zoom_out.png")),
337    //                              R("MapPaneButtons.ZoomOut.TT")), false);
338                    
339                    
340    
341                  // Action button to revert the last zoom                  // Action button to revert the last zoom
342                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",
343                                  new ImageIcon(MapView.class                                  new ImageIcon(MapView.class
344                                                  .getResource("resource/icons/zoom_back.png")), R("MapPaneButtons.LastZoom.TT")), false);                                                  .getResource("resource/icons/zoom_back.png")),
345                                    R("MapPaneButtons.LastZoom.TT")), false);
346                  setButtonEnabled(ACTION_ZOOM_BACK, false);                  setButtonEnabled(ACTION_ZOOM_BACK, false);
347    
348                  // Action button to redo the last zoom                  // Action button to redo the last zoom
349                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "",                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "",
350                                  new ImageIcon(MapView.class                                  new ImageIcon(MapView.class
351                                                  .getResource("resource/icons/zoom_forward.png")), R("MapPaneButtons.NextZoom.TT")),                                                  .getResource("resource/icons/zoom_forward.png")),
352                                  false);                                  R("MapPaneButtons.NextZoom.TT")), false);
353                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);
354    
355                  // set the selected tool enabled                  // set the selected tool enabled
# Line 294  public class MapPaneToolBar extends JToo Line 357  public class MapPaneToolBar extends JToo
357    
358          }          }
359    
360            @Override
361            public void paint(Graphics g) {
362                    super.paint(g);
363            }
364    
365          /**          /**
366           * 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
367           * the tool bar.           * the tool bar.
368           */           */
369          public void initToolBar() {          public void initToolBar() {
370                  setAlignmentY(1f);                  // setOpaque(true);
371                    //              
372                    // setAlignmentY(1f);
373                    // setAlignmentX(0.5f);
374                  removeAll();                  removeAll();
375                  // Separator to the left of the tool actions to start  
376                  // the tool buttons with the map (not with the coordinate grid)                  // // Separator to the left of the tool actions to start
377                  Dimension dimension = new Dimension(49, 10);                  // // the tool buttons with the map (not with the coordinate grid)
378                  addSeparator(dimension);                  // Dimension dimension = new Dimension(49, 10);
379                    // addSeparator(dimension);
380    
381                  // Tool buttons                  // Tool buttons
382                  for (JComponent b : toolAndActionButtons.values())                  for (Integer bKey : toolAndActionButtons.keySet()) {
383    
384                            JComponent b = toolAndActionButtons.get(bKey);
385    
386                            if (b instanceof JToggleButton) {
387                                    JToggleButton tb = (JToggleButton) b;
388                                    tb.setName(bKey.toString());
389                                    tb.addActionListener(toolSelectedListener);
390                            }
391    
392                          add(b);                          add(b);
393                    }
394    
395                  if (!toolAndActionButtons.containsKey(selectedTool)) {                  if (!toolAndActionButtons.containsKey(selectedTool)) {
396                          /**                          /**
# Line 325  public class MapPaneToolBar extends JToo Line 408  public class MapPaneToolBar extends JToo
408                          }                          }
409    
410                  }                  }
411                    
412                  revalidate();                  revalidate();
413                  repaint();                  repaint();
414          }          }
# Line 357  public class MapPaneToolBar extends JToo Line 440  public class MapPaneToolBar extends JToo
440                  switch (tool) {                  switch (tool) {
441                  case TOOL_PAN:                  case TOOL_PAN:
442                          // Set the mouse tool to "Panning"                          // Set the mouse tool to "Panning"
443                          mapPane.setWindowSelectionState(JMapPane.NONE);  //                      mapPane.setState(SelectableXMapPane.PAN);
444                          mapPane.setState(JMapPane.PAN);                          mapPane.setTool(XMapPaneTool.PAN);
445                          mapPane.setHighlight(false);  //                      mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);
                         mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);  
446                          break;                          break;
447                  case TOOL_INFO:                  case TOOL_INFO:
448                          // Set the mouse tool to "Info"                          // Set the mouse tool to "Info"
449                          mapPane.setWindowSelectionState(JMapPane.NONE);                          mapPane.setTool(XMapPaneTool.INFO);
450                          mapPane.setState(JMapPane.SELECT_TOP); // Why not:  //                      mapPane.setState(SelectableXMapPane.SELECT_ONE_FROM_TOP);
451                          // JMapPane.SELECT_TOP_ONEONLY  //                      mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);
                         mapPane.setHighlight(false);// SK: Was true, but since it not works  
                         // properly removed it to save  
                         // performance  
                         mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);  
452                          break;                          break;
453                  case TOOL_ZOOMIN:                  case TOOL_ZOOMIN:
454                          // Set the mouse tool to "Zoom in"                          // Set the mouse tool to "Zoom in"
455                          mapPane.setWindowSelectionState(JMapPane.ZOOM_IN);                          mapPane.setTool(XMapPaneTool.ZOOM_IN);
456                          mapPane.setState(JMapPane.ZOOM_IN);  //                      mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);
                         mapPane.setHighlight(false);  
                         mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);  
457                          break;                          break;
458                  case TOOL_ZOOMOUT:                  case TOOL_ZOOMOUT:
459                          // Set the mouse tool to "Zoom out"                          // Set the mouse tool to "Zoom out"
460                          mapPane.setWindowSelectionState(JMapPane.NONE);                          mapPane.setTool(XMapPaneTool.ZOOM_OUT);
461                          mapPane.setState(JMapPane.ZOOM_OUT);  //                      mapPane.setState(SelectableXMapPane.ZOOM_OUT);
462                          mapPane.setHighlight(false);  //                      mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);
                         mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);  
463                          break;                          break;
464                  default:  //              default:
465                          // Set map actions to default                          // Set map actions to default
466                          mapPane.setWindowSelectionState(JMapPane.NONE);  //                      mapPane.setState(SelectableXMapPane.NONE);
467                          mapPane.setState(JMapPane.NONE);  //                      mapPane.setNormalCursor(null);
468                          mapPane.setHighlight(false);  //                      break;
                         mapPane.setNormalCursor(null);  
                         break;  
469                  }                  }
470                  mapPane.updateCursor();  //              mapPane.updateCursorAndRepaintTimer();
471          }          }
472    
473          /**          /**
# Line 466  public class MapPaneToolBar extends JToo Line 539  public class MapPaneToolBar extends JToo
539                                                          + buttonAction.getID());                                                          + buttonAction.getID());
540                          return;                          return;
541                  }                  }
542                  JToggleButton button = new JToggleButton(buttonAction);                  JToggleButton button = new SmallToggleButton(buttonAction);
543                  button.setBorder(BorderFactory.createRaisedBevelBorder());                  
544    //              button.setBorder(BorderFactory.createRaisedBevelBorder());
545                  toolButtonGroup.add(button);                  toolButtonGroup.add(button);
546                  toolAndActionButtons.put(buttonAction.getID(), button);                  toolAndActionButtons.put(buttonAction.getID(), button);
547                  if (resetToolBar)                  if (resetToolBar)
548                          initToolBar();                          initToolBar();
549          }          }
550    
   
   
551          /**          /**
552           * Adds a tool to the tool bar and resets the toolbar GUI.           * Adds a tool to the tool bar and resets the toolbar GUI.
553           *           *
# Line 505  public class MapPaneToolBar extends JToo Line 577  public class MapPaneToolBar extends JToo
577                                                          + buttonAction.getID());                                                          + buttonAction.getID());
578                          return;                          return;
579                  }                  }
580                  JButton button = new JButton(buttonAction);                  JButton button = new SmallButton(buttonAction);
581                  button.setBorder(BorderFactory.createRaisedBevelBorder());  //              button.setBorder(BorderFactory.createRaisedBevelBorder());
582                  toolAndActionButtons.put(buttonAction.getID(), button);                  toolAndActionButtons.put(buttonAction.getID(), button);
583                  if (resetToolBar)                  if (resetToolBar)
584                          initToolBar();                          initToolBar();
585          }          }
586            
587          /**          /**
588           * Adds any JComponent to the tool bar. Does nothing if a tool or action with the           * Adds any JComponent to the tool bar. Does nothing if a tool or action
589           * specified ID already exists!           * with the specified ID already exists!
590           *           *
591           * @param component A {@link JComponent} that shall be added           * @param component
592           * @param id The ID associaded with the {@link JComponent}           *            A {@link JComponent} that shall be added
593             * @param id
594             *            The ID associaded with the {@link JComponent}
595           * @param resetToolBar           * @param resetToolBar
596           *            indicates whether the toolbar GUI is reset after adding the           *            indicates whether the toolbar GUI is reset after adding the
597           *            button (if adding several actions it useful only to reset the           *            button (if adding several actions it useful only to reset the
598           *            GUI for the last added tool)           *            GUI for the last added tool)
599           */           */
600          public void addJComponent(JComponent component, int id,          public void addJComponent(JComponent component, int id, boolean resetToolBar) {
                         boolean resetToolBar) {  
601    
602                  if (isButtonIDUsed(id)) {                  if (isButtonIDUsed(id)) {
603                          LOGGER                          LOGGER
604                          .warn("addAction(.) ignored because ID already used for tool or action: "                                          .warn("addAction(.) ignored because ID already used for tool or action: "
605                                          + id);                                                          + id);
606                          return;                          return;
607                  }                  }
608                    
609                  toolAndActionButtons.put(id, component);                  toolAndActionButtons.put(id, component);
610                  if (resetToolBar)                  if (resetToolBar)
611                          initToolBar();                          initToolBar();
# Line 568  public class MapPaneToolBar extends JToo Line 641  public class MapPaneToolBar extends JToo
641           *         {@linkplain #getToolButton(int) tool button}           *         {@linkplain #getToolButton(int) tool button}
642           */           */
643          public AbstractButton getButton(int id) {          public AbstractButton getButton(int id) {
644                    
645                    //ACHUTNG: Das ist ein SK QUICK FIX! TODO
646                    if (!(toolAndActionButtons.get(id) instanceof AbstractButton)) return null;
647                    
648                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);
649                  if (button == null)                  if (button == null)
650                          LOGGER.warn("Unknown tool or action ID: " + id);                          LOGGER.warn("Unknown tool or action ID: " + id);
# Line 634  public class MapPaneToolBar extends JToo Line 711  public class MapPaneToolBar extends JToo
711                          return -1;                          return -1;
712                  return selectedTool;                  return selectedTool;
713          }          }
714            
715          /**          /**
716           * 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
717           * of the button is not affected.           * of the button is not affected.
# Line 709  public class MapPaneToolBar extends JToo Line 786  public class MapPaneToolBar extends JToo
786           *            is {@code false}           *            is {@code false}
787           */           */
788          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {
789                  for (int tool : toolAndActionButtons.keySet())                  for (int id : toolAndActionButtons.keySet()) {
790                          setButtonEnabled(tool, enabled, hideOnDisable);                          if (toolAndActionButtons.get(id) instanceof JToggleButton) {
791                            setButtonEnabled(id, enabled, hideOnDisable);
792                            }
793                    }
794          }          }
795            
796          /**          /**
797           * Sets the activation for all actions.           * Sets the activation for all actions.
798           *           *
# Line 804  public class MapPaneToolBar extends JToo Line 884  public class MapPaneToolBar extends JToo
884                   */                   */
885                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
886                                  String name, Icon icon) {                                  String name, Icon icon) {
887                          this (id, toolBar, name, icon, null);                          this(id, toolBar, name, icon, null);
888                  }                  }
889                    
890                  /**                  /**
891                   * Creates a new action.                   * Creates a new action.
892                   *                   *
# Line 824  public class MapPaneToolBar extends JToo Line 904  public class MapPaneToolBar extends JToo
904                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
905                                  String name, Icon icon, String toolTip) {                                  String name, Icon icon, String toolTip) {
906                          super(name, icon);                          super(name, icon);
907                            
908                          if (toolTip != null && !toolTip.trim().isEmpty()){                          if (toolTip != null && !toolTip.trim().isEmpty()) {
909                                  putValue(Action.SHORT_DESCRIPTION, toolTip);                                  putValue(Action.SHORT_DESCRIPTION, toolTip);
910                          }                          }
911                            
912                          this.id = id;                          this.id = id;
913                          this.toolBar = toolBar;                          this.toolBar = toolBar;
914                  }                  }
915    
916                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, XMapPaneTool tool) {
917                            this(id, toolBar, "", tool.icon, tool.toolTip);
918                    }
919    
920                  /**                  /**
921                   * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or                   * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or
922                   * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}                   * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}
# Line 856  public class MapPaneToolBar extends JToo Line 940  public class MapPaneToolBar extends JToo
940                          return id;                          return id;
941                  }                  }
942          }          }
943            
944            /**          /**
945             * 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
946             * Hintergrund auf WEISS gesetzt.           * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.
947             *           *
948             * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons
949             *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
950             */           */
951            @Override          @Override
952            public void print(Graphics g) {          public void print(Graphics g) {
953                Color orig = getBackground();                  Color orig = getBackground();
954                setBackground(Color.WHITE);                  setBackground(Color.WHITE);
955                // wrap in try/finally so that we always restore the state                  // wrap in try/finally so that we always restore the state
956                try {                  try {
957                    super.print(g);                          super.print(g);
958                } finally {                  } finally {
959                    setBackground(orig);                          setBackground(orig);
960                }                  }
961            }          }
962    
963  }  }

Legend:
Removed from v.315  
changed lines
  Added in v.655

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26