/[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 888 by alfonx, Thu Jun 3 10:48:43 2010 UTC revision 1220 by alfonx, Wed Nov 3 13:09:32 2010 UTC
# Line 64  import skrueger.swing.SmallToggleButton; Line 64  import skrueger.swing.SmallToggleButton;
64  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
65    
66  /**  /**
67   * A toolbar to control an {@link SelectableXMapPane} (Atlas visualization). This contains   * A toolbar to control an {@link SelectableXMapPane} (Atlas visualization).
68   * two types of buttons. A group of <i>tools</i> for the mouse actions on the   * This contains two types of buttons. A group of <i>tools</i> for the mouse
69   * map represented by {@link JToggleButton JToggleButtons}, where only one tool   * actions on the map represented by {@link JToggleButton JToggleButtons}, where
70   * can be activated every time. And some (general) <i>actions</i>, represented   * only one tool can be activated every time. And some (general) <i>actions</i>,
71   * by normal {@link JButton JButtons}.   * represented by normal {@link JButton JButtons}.
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)
# Line 168  public class MapPaneToolBar extends JToo Line 168  public class MapPaneToolBar extends JToo
168                  }                  }
169    
170          };          };
171            private CrsLabel crsViewer;
172    
173          /**          /**
174           * Creates a new toolbar. Notice: This toolbar does nothing until           * Creates a new toolbar. Notice: This toolbar does nothing until
# Line 204  public class MapPaneToolBar extends JToo Line 205  public class MapPaneToolBar extends JToo
205                  // Create a Listener to listen to the zooms on the JMapPane                  // Create a Listener to listen to the zooms on the JMapPane
206                  this.mapPaneListener = new JMapPaneListener() {                  this.mapPaneListener = new JMapPaneListener() {
207                          public void performMapPaneEvent(XMapPaneEvent e) {                          public void performMapPaneEvent(XMapPaneEvent e) {
208    
209                                  if (!(e instanceof MapAreaChangedEvent))                                  if (!(e instanceof MapAreaChangedEvent))
210                                          return;                                          return;
211    
# Line 254  public class MapPaneToolBar extends JToo Line 256  public class MapPaneToolBar extends JToo
256                                  setButtonEnabled(ACTION_ZOOM_BACK, lastZooms.size() > 1);                                  setButtonEnabled(ACTION_ZOOM_BACK, lastZooms.size() > 1);
257                                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);                                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);
258                          }                          }
259    
260                  };                  };
261    
262                  setMapPane(mapPane);                  setMapPane(mapPane);
# Line 263  public class MapPaneToolBar extends JToo Line 266  public class MapPaneToolBar extends JToo
266                  init();                  init();
267          }          }
268    
269            private CrsLabel getCrsComponent() {
270                    if (crsViewer == null) {
271                            crsViewer = new CrsLabel(this.mapPane);
272                    }
273                    return crsViewer;
274            }
275    
276          /**          /**
277           * Sets the {@link SelectableXMapPane} controlled by this tool bar.           * Sets the {@link SelectableXMapPane} controlled by this tool bar.
278           *           *
279           * @param mapPane           * @param mapPane
280           *            {@link SelectableXMapPane} to control (if {@code null} this tool bar           *            {@link SelectableXMapPane} to control (if {@code null} this
281           *            controls NOTHING!)           *            tool bar controls NOTHING!)
282           */           */
283          public void setMapPane(SelectableXMapPane mapPane) {          public void setMapPane(SelectableXMapPane mapPane) {
284                  // Remove listener from old MapPane                  // Remove listener from old MapPane
# Line 297  public class MapPaneToolBar extends JToo Line 307  public class MapPaneToolBar extends JToo
307           * Creates the tool buttons and action buttons and seperators, adds them to           * Creates the tool buttons and action buttons and seperators, adds them to
308           * {@link #toolAndActionButtons} and finally creates a button group for all           * {@link #toolAndActionButtons} and finally creates a button group for all
309           * tools. So sub-classes which override this method should FIRST add their           * tools. So sub-classes which override this method should FIRST add their
310           * new tool buttons to {@link #toolAndActionButtons} before calling {@code           * new tool buttons to {@link #toolAndActionButtons} before calling
311           * super.initTools()}.           * {@code super.initTools()}.
312           */           */
313          protected void initToolsAndActions() {          protected void initToolsAndActions() {
314                  // Panning                  // Pan
315  //              addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_PAN, this, XMapPaneTool.PAN),
316  //                              MapView.class.getResource("resource/icons/pan.png")),                                  false);
 //                              R("MapPaneButtons.Pan.TT")), false);  
317    
                 addTool(new MapPaneToolBarAction(TOOL_PAN, this, XMapPaneTool.PAN), false);  
                   
318                  // Info                  // Info
319  //              addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_INFO, this, XMapPaneTool.INFO),
320  //                              MapView.class.getResource("resource/icons/info.png")),                                  false);
 //                              R("MapPaneButtons.Info.TT")), false);  
                 addTool(new MapPaneToolBarAction(TOOL_INFO, this, XMapPaneTool.INFO), false);  
321    
322                  // Zoom in                  // Zoom in
323                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, XMapPaneTool.ZOOM_IN), false);                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this,
324                                                    XMapPaneTool.ZOOM_IN), false);
325    
326                  // Zoom out                  // Zoom out
327                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, XMapPaneTool.ZOOM_OUT), false);                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this,
328                                                    XMapPaneTool.ZOOM_OUT), false);
                   
 //              // Zoom in  
 //              addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(  
 //                              MapView.class.getResource("resource/icons/zoom_in.png")),  
 //                              R("MapPaneButtons.ZoomIn.TT")), false);  
 //                
 //              // Zoom out  
 //              addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(  
 //                              MapView.class.getResource("resource/icons/zoom_out.png")),  
 //                              R("MapPaneButtons.ZoomOut.TT")), false);  
                   
                   
329    
330                  // Action button to revert the last zoom                  // Action button to revert the last zoom
331                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",                  addAction(
332                                  new ImageIcon(MapView.class                                  new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",
333                                                  .getResource("resource/icons/zoom_back.png")),                                                  new ImageIcon(MapView.class
334                                  R("MapPaneButtons.LastZoom.TT")), false);                                                                  .getResource("resource/icons/zoom_back.png")),
335                                                    R("MapPaneButtons.LastZoom.TT")), false);
336                  setButtonEnabled(ACTION_ZOOM_BACK, false);                  setButtonEnabled(ACTION_ZOOM_BACK, false);
337    
338                  // Action button to redo the last zoom                  // Action button to redo the last zoom
339                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "",                  addAction(
340                                  new ImageIcon(MapView.class                                  new MapPaneToolBarAction(
341                                                  .getResource("resource/icons/zoom_forward.png")),                                                  ACTION_ZOOM_FORWARD,
342                                  R("MapPaneButtons.NextZoom.TT")), false);                                                  this,
343                                                    "",
344                                                    new ImageIcon(MapView.class
345                                                                    .getResource("resource/icons/zoom_forward.png")),
346                                                    R("MapPaneButtons.NextZoom.TT")), false);
347                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);
348    
349                  // set the selected tool enabled                  // set the selected tool enabled
350                  setSelectedTool(selectedTool);                  setSelectedTool(selectedTool);
351    
352                    add(getCrsComponent());
353    
354          }          }
355    
356          @Override          @Override
# Line 362  public class MapPaneToolBar extends JToo Line 363  public class MapPaneToolBar extends JToo
363           * the tool bar.           * the tool bar.
364           */           */
365          public void initToolBar() {          public void initToolBar() {
                 // setOpaque(true);  
                 //                
                 // setAlignmentY(1f);  
                 // setAlignmentX(0.5f);  
366                  removeAll();                  removeAll();
367    
368                  // // Separator to the left of the tool actions to start                  // // Separator to the left of the tool actions to start
# Line 408  public class MapPaneToolBar extends JToo Line 405  public class MapPaneToolBar extends JToo
405                  repaint();                  repaint();
406          }          }
407    
         // 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);  
         // }  
   
408          /**          /**
409           * Performs the activation of a tool.           * Performs the activation of a tool.
410           *           *
# Line 434  public class MapPaneToolBar extends JToo Line 421  public class MapPaneToolBar extends JToo
421    
422                  switch (tool) {                  switch (tool) {
423                  case TOOL_PAN:                  case TOOL_PAN:
                         // Set the mouse tool to "Panning"  
 //                      mapPane.setState(SelectableXMapPane.PAN);  
424                          mapPane.setTool(XMapPaneTool.PAN);                          mapPane.setTool(XMapPaneTool.PAN);
 //                      mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);  
425                          break;                          break;
426                  case TOOL_INFO:                  case TOOL_INFO:
                         // Set the mouse tool to "Info"  
427                          mapPane.setTool(XMapPaneTool.INFO);                          mapPane.setTool(XMapPaneTool.INFO);
 //                      mapPane.setState(SelectableXMapPane.SELECT_ONE_FROM_TOP);  
 //                      mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);  
428                          break;                          break;
429                  case TOOL_ZOOMIN:                  case TOOL_ZOOMIN:
                         // Set the mouse tool to "Zoom in"  
430                          mapPane.setTool(XMapPaneTool.ZOOM_IN);                          mapPane.setTool(XMapPaneTool.ZOOM_IN);
 //                      mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);  
431                          break;                          break;
432                  case TOOL_ZOOMOUT:                  case TOOL_ZOOMOUT:
                         // Set the mouse tool to "Zoom out"  
433                          mapPane.setTool(XMapPaneTool.ZOOM_OUT);                          mapPane.setTool(XMapPaneTool.ZOOM_OUT);
 //                      mapPane.setState(SelectableXMapPane.ZOOM_OUT);  
 //                      mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);  
434                          break;                          break;
 //              default:  
                         // Set map actions to default  
 //                      mapPane.setState(SelectableXMapPane.NONE);  
 //                      mapPane.setNormalCursor(null);  
 //                      break;  
435                  }                  }
 //              mapPane.updateCursorAndRepaintTimer();  
436          }          }
437    
438          /**          /**
# Line 486  public class MapPaneToolBar extends JToo Line 456  public class MapPaneToolBar extends JToo
456          protected void performActionButton(int action, ActionEvent e) {          protected void performActionButton(int action, ActionEvent e) {
457                  if (mapPane == null)                  if (mapPane == null)
458                          return;                          return;
459                    
460                  // Perform the action "Zoom back": Revert the last zoom                  // Perform the action "Zoom back": Revert the last zoom
461                  if (action == ACTION_ZOOM_BACK) {                  if (action == ACTION_ZOOM_BACK) {
462                          if (zoomBackIndex <= 1)                          if (zoomBackIndex <= 1)
# Line 529  public class MapPaneToolBar extends JToo Line 499  public class MapPaneToolBar extends JToo
499           */           */
500          public void addTool(MapPaneToolBarAction buttonAction, boolean resetToolBar) {          public void addTool(MapPaneToolBarAction buttonAction, boolean resetToolBar) {
501                  if (isButtonIDUsed(buttonAction.getID())) {                  if (isButtonIDUsed(buttonAction.getID())) {
502                          LOGGER                          LOGGER.warn("addTool(.) ignored because ID already used for tool or action: "
503                                          .warn("addTool(.) ignored because ID already used for tool or action: "                                          + buttonAction.getID());
                                                         + buttonAction.getID());  
504                          return;                          return;
505                  }                  }
506                  JToggleButton button = new SmallToggleButton(buttonAction);                  JToggleButton button = new SmallToggleButton(buttonAction);
507                    
 //              button.setBorder(BorderFactory.createRaisedBevelBorder());  
508                  toolButtonGroup.add(button);                  toolButtonGroup.add(button);
509                  toolAndActionButtons.put(buttonAction.getID(), button);                  toolAndActionButtons.put(buttonAction.getID(), button);
510                  if (resetToolBar)                  if (resetToolBar)
# Line 567  public class MapPaneToolBar extends JToo Line 535  public class MapPaneToolBar extends JToo
535          public void addAction(MapPaneToolBarAction buttonAction,          public void addAction(MapPaneToolBarAction buttonAction,
536                          boolean resetToolBar) {                          boolean resetToolBar) {
537                  if (isButtonIDUsed(buttonAction.getID())) {                  if (isButtonIDUsed(buttonAction.getID())) {
538                          LOGGER                          LOGGER.warn("addAction(.) ignored because ID already used for tool or action: "
539                                          .warn("addAction(.) ignored because ID already used for tool or action: "                                          + buttonAction.getID());
                                                         + buttonAction.getID());  
540                          return;                          return;
541                  }                  }
542                  JButton button = new SmallButton(buttonAction);                  JButton button = new SmallButton(buttonAction);
 //              button.setBorder(BorderFactory.createRaisedBevelBorder());  
543                  toolAndActionButtons.put(buttonAction.getID(), button);                  toolAndActionButtons.put(buttonAction.getID(), button);
544                  if (resetToolBar)                  if (resetToolBar)
545                          initToolBar();                          initToolBar();
# Line 595  public class MapPaneToolBar extends JToo Line 561  public class MapPaneToolBar extends JToo
561          public void addJComponent(JComponent component, int id, boolean resetToolBar) {          public void addJComponent(JComponent component, int id, boolean resetToolBar) {
562    
563                  if (isButtonIDUsed(id)) {                  if (isButtonIDUsed(id)) {
564                          LOGGER                          LOGGER.warn("addAction(.) ignored because ID already used for tool or action: "
565                                          .warn("addAction(.) ignored because ID already used for tool or action: "                                          + id);
                                                         + id);  
566                          return;                          return;
567                  }                  }
568    
# Line 608  public class MapPaneToolBar extends JToo Line 573  public class MapPaneToolBar extends JToo
573    
574          public void addSeparator(int id, Separator separator) {          public void addSeparator(int id, Separator separator) {
575                  if (isButtonIDUsed(id)) {                  if (isButtonIDUsed(id)) {
576                          LOGGER                          LOGGER.warn("addSeparator(.) ignored because ID already used for tool or action. ");
                                         .warn("addSeparator(.) ignored because ID already used for tool or action. ");  
577                          return;                          return;
578                  }                  }
579                  toolAndActionButtons.put(id, separator);                  toolAndActionButtons.put(id, separator);
# Line 636  public class MapPaneToolBar extends JToo Line 600  public class MapPaneToolBar extends JToo
600           *         {@linkplain #getToolButton(int) tool button}           *         {@linkplain #getToolButton(int) tool button}
601           */           */
602          public AbstractButton getButton(int id) {          public AbstractButton getButton(int id) {
603                    
604                  //ACHUTNG: Das ist ein SK QUICK FIX! TODO                  // ACHUTNG: Das ist ein SK QUICK FIX! TODO
605                  if (!(toolAndActionButtons.get(id) instanceof AbstractButton)) return null;                  if (!(toolAndActionButtons.get(id) instanceof AbstractButton))
606                                            return null;
607    
608                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);
609                  if (button == null)                  if (button == null)
610                          LOGGER.warn("Unknown tool or action ID: " + id);                          LOGGER.warn("Unknown tool or action ID: " + id);
# Line 706  public class MapPaneToolBar extends JToo Line 671  public class MapPaneToolBar extends JToo
671                          return -1;                          return -1;
672                  return selectedTool;                  return selectedTool;
673          }          }
674            
675          /**          /**
676           * 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
677           * of the button is not affected.           * of the button is not affected.
# Line 783  public class MapPaneToolBar extends JToo Line 748  public class MapPaneToolBar extends JToo
748          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {
749                  for (int id : toolAndActionButtons.keySet()) {                  for (int id : toolAndActionButtons.keySet()) {
750                          if (toolAndActionButtons.get(id) instanceof JToggleButton) {                          if (toolAndActionButtons.get(id) instanceof JToggleButton) {
751                          setButtonEnabled(id, enabled, hideOnDisable);                                  setButtonEnabled(id, enabled, hideOnDisable);
752                          }                          }
753                  }                  }
754          }          }
755            
756          /**          /**
757           * Sets the activation for all actions.           * Sets the activation for all actions.
758           *           *
# Line 908  public class MapPaneToolBar extends JToo Line 873  public class MapPaneToolBar extends JToo
873                          this.toolBar = toolBar;                          this.toolBar = toolBar;
874                  }                  }
875    
876                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, XMapPaneTool tool) {                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
877                                    XMapPaneTool tool) {
878                          this(id, toolBar, "", tool.getIcon(), tool.getToolTip());                          this(id, toolBar, "", tool.getIcon(), tool.getToolTip());
879                  }                  }
880    
# Line 940  public class MapPaneToolBar extends JToo Line 906  public class MapPaneToolBar extends JToo
906           * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht           * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht
907           * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.           * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.
908           *           *
909           * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons Tzeggai</a>
          *         Tzeggai</a>  
910           */           */
911          @Override          @Override
912          public void print(Graphics g) {          public void print(Graphics g) {
# Line 955  public class MapPaneToolBar extends JToo Line 920  public class MapPaneToolBar extends JToo
920                  }                  }
921          }          }
922    
923            @Override
924            protected void finalize() throws Throwable {
925                    super.finalize();
926    
927                    if (mapPane != null && mapPaneListener != null)
928                            mapPane.removeMapPaneListener(mapPaneListener);
929            }
930    
931  }  }

Legend:
Removed from v.888  
changed lines
  Added in v.1220

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26