/[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 486 by alfonx, Tue Oct 20 16:25:26 2009 UTC trunk/src/skrueger/geotools/MapPaneToolBar.java revision 685 by alfonx, Wed Feb 10 15:04:02 2010 UTC
# Line 52  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;
# Line 66  import skrueger.swing.SmallToggleButton; Line 66  import skrueger.swing.SmallToggleButton;
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 96  public class MapPaneToolBar extends JToo Line 96  public class MapPaneToolBar extends JToo
96    
97          /** Constant for the tool "Zoom In" (110). */          /** Constant for the tool "Zoom In" (110). */
98          public static final int TOOL_ZOOMIN = 110;          public static final int TOOL_ZOOMIN = 110;
99            public static final int ACTION_ZOOM_DEFAULT = 150;
100          /** Constant for the tool "Zoom Out" (120). */          /** Constant for the tool "Zoom Out" (120). */
101          public static final int TOOL_ZOOMOUT = 120;          public static final int TOOL_ZOOMOUT = 120;
102          /** Constant for the action "Zoom back" (130). */          /** Constant for the action "Zoom back" (130). */
# Line 140  public class MapPaneToolBar extends JToo Line 141  public class MapPaneToolBar extends JToo
141          // /** Holds the action buttons of the bar. */          // /** Holds the action buttons of the bar. */
142          // protected SortedMap<Integer, JButton> actionButtons = null;          // protected SortedMap<Integer, JButton> actionButtons = null;
143    
144          /** Holds the {@link JMapPane} this tool bar controls. */          /** Holds the {@link SelectableXMapPane} this tool bar controls. */
145          protected JMapPane mapPane = null;          protected SelectableXMapPane mapPane = null;
146    
147          /**          /**
148           * 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 176  public class MapPaneToolBar extends JToo Line 177  public class MapPaneToolBar extends JToo
177    
178          /**          /**
179           * Creates a new toolbar. Notice: This toolbar does nothing until           * Creates a new toolbar. Notice: This toolbar does nothing until
180           * {@link #setMapPane(JMapPane)} is called!           * {@link #setMapPane(SelectableXMapPane)} is called!
181           */           */
182          public MapPaneToolBar() {          public MapPaneToolBar() {
183                  this(null);                  this(null);
# Line 195  public class MapPaneToolBar extends JToo Line 196  public class MapPaneToolBar extends JToo
196           * Creates a new tool bar.           * Creates a new tool bar.
197           *           *
198           * @param mapPane           * @param mapPane
199           *            {@link JMapPane} the tool bar controls           *            {@link SelectableXMapPane} the tool bar controls
200           */           */
201          public MapPaneToolBar(JMapPane mapPane) {          public MapPaneToolBar(SelectableXMapPane mapPane) {
202                  super("Control the map", JToolBar.HORIZONTAL);                  super("Control the map", JToolBar.HORIZONTAL);
203    
204                  // I want to see nothing on the background                  // I want to see nothing on the background
# Line 208  public class MapPaneToolBar extends JToo Line 209  public class MapPaneToolBar extends JToo
209    
210                  // Create a Listener to listen to the zooms on the JMapPane                  // Create a Listener to listen to the zooms on the JMapPane
211                  this.mapPaneListener = new JMapPaneListener() {                  this.mapPaneListener = new JMapPaneListener() {
212                          public void performMapPaneEvent(JMapPaneEvent e) {                          public void performMapPaneEvent(MapPaneEvent e) {
213                                  if (!(e instanceof MapAreaChangedEvent))                                  if (!(e instanceof MapAreaChangedEvent))
214                                          return;                                          return;
215    
# Line 269  public class MapPaneToolBar extends JToo Line 270  public class MapPaneToolBar extends JToo
270          }          }
271    
272          /**          /**
273           * Sets the {@link JMapPane} controlled by this tool bar.           * Sets the {@link SelectableXMapPane} controlled by this tool bar.
274           *           *
275           * @param mapPane           * @param mapPane
276           *            {@link JMapPane} to control (if {@code null} this tool bar           *            {@link SelectableXMapPane} to control (if {@code null} this tool bar
277           *            controls NOTHING!)           *            controls NOTHING!)
278           */           */
279          public void setMapPane(JMapPane mapPane) {          public void setMapPane(SelectableXMapPane mapPane) {
280                  // Remove listener from old MapPane                  // Remove listener from old MapPane
281                  if (this.mapPane != null)                  if (this.mapPane != null)
282                          this.mapPane.removeMapPaneListener(mapPaneListener);                          this.mapPane.removeMapPaneListener(mapPaneListener);
# Line 307  public class MapPaneToolBar extends JToo Line 308  public class MapPaneToolBar extends JToo
308           */           */
309          protected void initToolsAndActions() {          protected void initToolsAndActions() {
310                  // Panning                  // Panning
311                  addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(  //              addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(
312                                  MapView.class.getResource("resource/icons/pan.png")),  //                              MapView.class.getResource("resource/icons/pan.png")),
313                                  R("MapPaneButtons.Pan.TT")), false);  //                              R("MapPaneButtons.Pan.TT")), false);
314    
315                    addTool(new MapPaneToolBarAction(TOOL_PAN, this, XMapPaneTool.PAN), false);
316                    
317                  // Info                  // Info
318                  addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(  //              addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(
319                                  MapView.class.getResource("resource/icons/info.png")),  //                              MapView.class.getResource("resource/icons/info.png")),
320                                  R("MapPaneButtons.Info.TT")), false);  //                              R("MapPaneButtons.Info.TT")), false);
321                    addTool(new MapPaneToolBarAction(TOOL_INFO, this, XMapPaneTool.INFO), false);
322    
323                  // Zoom in                  // Zoom in
324                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, XMapPaneTool.ZOOM_IN), false);
325                                  MapView.class.getResource("resource/icons/zoom_in.png")),                  
                                 R("MapPaneButtons.ZoomIn.TT")), false);  
326                  // Zoom out                  // Zoom out
327                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, XMapPaneTool.ZOOM_OUT), false);
328                                  MapView.class.getResource("resource/icons/zoom_out.png")),                  
329                                  R("MapPaneButtons.ZoomOut.TT")), false);                  
330    //              // Zoom in
331    //              addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(
332    //                              MapView.class.getResource("resource/icons/zoom_in.png")),
333    //                              R("MapPaneButtons.ZoomIn.TT")), false);
334    //              
335    //              // Zoom out
336    //              addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(
337    //                              MapView.class.getResource("resource/icons/zoom_out.png")),
338    //                              R("MapPaneButtons.ZoomOut.TT")), false);
339                    
340                    
341    
342                  // Action button to revert the last zoom                  // Action button to revert the last zoom
343                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",
# Line 426  public class MapPaneToolBar extends JToo Line 441  public class MapPaneToolBar extends JToo
441                  switch (tool) {                  switch (tool) {
442                  case TOOL_PAN:                  case TOOL_PAN:
443                          // Set the mouse tool to "Panning"                          // Set the mouse tool to "Panning"
444                          mapPane.setWindowSelectionState(JMapPane.NONE);  //                      mapPane.setState(SelectableXMapPane.PAN);
445                          mapPane.setState(JMapPane.PAN);                          mapPane.setTool(XMapPaneTool.PAN);
446                          mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);  //                      mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);
447                          break;                          break;
448                  case TOOL_INFO:                  case TOOL_INFO:
449                          // Set the mouse tool to "Info"                          // Set the mouse tool to "Info"
450                          mapPane.setWindowSelectionState(JMapPane.NONE);                          mapPane.setTool(XMapPaneTool.INFO);
451                          mapPane.setState(JMapPane.SELECT_TOP); // Why not:  //                      mapPane.setState(SelectableXMapPane.SELECT_ONE_FROM_TOP);
452                          // JMapPane.SELECT_TOP_ONEONLY  //                      mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);
                         // properly removed it to save  
                         // performance  
                         mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);  
453                          break;                          break;
454                  case TOOL_ZOOMIN:                  case TOOL_ZOOMIN:
455                          // Set the mouse tool to "Zoom in"                          // Set the mouse tool to "Zoom in"
456                          mapPane.setWindowSelectionState(JMapPane.ZOOM_IN);                          mapPane.setTool(XMapPaneTool.ZOOM_IN);
457                          mapPane.setState(JMapPane.ZOOM_IN);  //                      mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);
                         mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);  
458                          break;                          break;
459                  case TOOL_ZOOMOUT:                  case TOOL_ZOOMOUT:
460                          // Set the mouse tool to "Zoom out"                          // Set the mouse tool to "Zoom out"
461                          mapPane.setWindowSelectionState(JMapPane.NONE);                          mapPane.setTool(XMapPaneTool.ZOOM_OUT);
462                          mapPane.setState(JMapPane.ZOOM_OUT);  //                      mapPane.setState(SelectableXMapPane.ZOOM_OUT);
463                          mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);  //                      mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);
464                          break;                          break;
465                  default:  //              default:
466                          // Set map actions to default                          // Set map actions to default
467                          mapPane.setWindowSelectionState(JMapPane.NONE);  //                      mapPane.setState(SelectableXMapPane.NONE);
468                          mapPane.setState(JMapPane.NONE);  //                      mapPane.setNormalCursor(null);
469                          mapPane.setNormalCursor(null);  //                      break;
                         break;  
470                  }                  }
471                  mapPane.updateCursor();  //              mapPane.updateCursorAndRepaintTimer();
472          }          }
473    
474          /**          /**
# Line 482  public class MapPaneToolBar extends JToo Line 492  public class MapPaneToolBar extends JToo
492          protected void performActionButton(int action, ActionEvent e) {          protected void performActionButton(int action, ActionEvent e) {
493                  if (mapPane == null)                  if (mapPane == null)
494                          return;                          return;
495                    
496                  // Perform the action "Zoom back": Revert the last zoom                  // Perform the action "Zoom back": Revert the last zoom
497                  if (action == ACTION_ZOOM_BACK) {                  if (action == ACTION_ZOOM_BACK) {
498                          if (zoomBackIndex <= 1)                          if (zoomBackIndex <= 1)
# Line 632  public class MapPaneToolBar extends JToo Line 642  public class MapPaneToolBar extends JToo
642           *         {@linkplain #getToolButton(int) tool button}           *         {@linkplain #getToolButton(int) tool button}
643           */           */
644          public AbstractButton getButton(int id) {          public AbstractButton getButton(int id) {
645                    
646                    //ACHUTNG: Das ist ein SK QUICK FIX! TODO
647                    if (!(toolAndActionButtons.get(id) instanceof AbstractButton)) return null;
648                    
649                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);
650                  if (button == null)                  if (button == null)
651                          LOGGER.warn("Unknown tool or action ID: " + id);                          LOGGER.warn("Unknown tool or action ID: " + id);
# Line 698  public class MapPaneToolBar extends JToo Line 712  public class MapPaneToolBar extends JToo
712                          return -1;                          return -1;
713                  return selectedTool;                  return selectedTool;
714          }          }
715            
716          /**          /**
717           * 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
718           * of the button is not affected.           * of the button is not affected.
# Line 773  public class MapPaneToolBar extends JToo Line 787  public class MapPaneToolBar extends JToo
787           *            is {@code false}           *            is {@code false}
788           */           */
789          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {
790                  for (int tool : toolAndActionButtons.keySet())                  for (int id : toolAndActionButtons.keySet()) {
791                          setButtonEnabled(tool, enabled, hideOnDisable);                          if (toolAndActionButtons.get(id) instanceof JToggleButton) {
792                            setButtonEnabled(id, enabled, hideOnDisable);
793                            }
794                    }
795          }          }
796            
797          /**          /**
798           * Sets the activation for all actions.           * Sets the activation for all actions.
799           *           *
# Line 897  public class MapPaneToolBar extends JToo Line 914  public class MapPaneToolBar extends JToo
914                          this.toolBar = toolBar;                          this.toolBar = toolBar;
915                  }                  }
916    
917                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, XMapPaneTool tool) {
918                            this(id, toolBar, "", tool.getIcon(), tool.getToolTip());
919                    }
920    
921                  /**                  /**
922                   * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or                   * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or
923                   * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}                   * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}

Legend:
Removed from v.486  
changed lines
  Added in v.685

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26