/[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 445 by alfonx, Wed Oct 7 13:17:02 2009 UTC branches/2.0-RC2/src/skrueger/geotools/MapPaneToolBar.java revision 654 by alfonx, Mon Feb 1 18:13:14 2010 UTC
# Line 43  import java.util.TreeMap; Line 43  import java.util.TreeMap;
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 53  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 139  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 175  public class MapPaneToolBar extends JToo Line 176  public class MapPaneToolBar extends JToo
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);
# Line 194  public class MapPaneToolBar extends JToo Line 195  public class MapPaneToolBar extends JToo
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    
203                  // I want to see nothing on the background                  // I want to see nothing on the background
# Line 207  public class MapPaneToolBar extends JToo Line 208  public class MapPaneToolBar extends JToo
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 268  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 306  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")),  //                              MapView.class.getResource("resource/icons/pan.png")),
312                                  R("MapPaneButtons.Pan.TT")), false);  //                              R("MapPaneButtons.Pan.TT")), false);
                 // Info  
                 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")),                  
328                                  R("MapPaneButtons.ZoomOut.TT")), 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, "",
# Line 425  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.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);
                         // 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.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.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.setNormalCursor(null);  //                      break;
                         break;  
469                  }                  }
470                  mapPane.updateCursor();  //              mapPane.updateCursorAndRepaintTimer();
471          }          }
472    
473          /**          /**
# Line 529  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)
# Line 566  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();
# Line 696  public class MapPaneToolBar extends JToo Line 707  public class MapPaneToolBar extends JToo
707                          return -1;                          return -1;
708                  return selectedTool;                  return selectedTool;
709          }          }
710            
711          /**          /**
712           * 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
713           * of the button is not affected.           * of the button is not affected.
# Line 895  public class MapPaneToolBar extends JToo Line 906  public class MapPaneToolBar extends JToo
906                          this.toolBar = toolBar;                          this.toolBar = toolBar;
907                  }                  }
908    
909                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, XMapPaneTool tool) {
910                            this(id, toolBar, "", tool.icon, tool.toolTip);
911                    }
912    
913                  /**                  /**
914                   * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or                   * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or
915                   * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}                   * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}

Legend:
Removed from v.445  
changed lines
  Added in v.654

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26