/[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 509 by alfonx, Thu Nov 5 08:51:33 2009 UTC trunk/src/skrueger/geotools/MapPaneToolBar.java revision 888 by alfonx, Thu Jun 3 10:48:43 2010 UTC
# Line 25  Line 25 
25   *   *
26   * Contributors:   * Contributors:
27   *     Martin O. J. Schmitz - initial API and implementation   *     Martin O. J. Schmitz - initial API and implementation
28   *     Stefan A. Krüger - additional utility classes   *     Stefan A. Tzeggai - additional utility classes
29   ******************************************************************************/   ******************************************************************************/
30  package skrueger.geotools;  package skrueger.geotools;
31    
# Line 35  import java.awt.event.ActionEvent; Line 35  import java.awt.event.ActionEvent;
35  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
36  import java.util.ArrayList;  import java.util.ArrayList;
37  import java.util.HashSet;  import java.util.HashSet;
 import java.util.Locale;  
38  import java.util.Set;  import java.util.Set;
39  import java.util.SortedMap;  import java.util.SortedMap;
40  import java.util.TreeMap;  import java.util.TreeMap;
# Line 52  import javax.swing.JToolBar; Line 51  import javax.swing.JToolBar;
51    
52  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
53    
54    import schmitzm.geotools.gui.GeotoolsGUIUtil;
55  import schmitzm.geotools.gui.SelectableXMapPane;  import schmitzm.geotools.gui.SelectableXMapPane;
56  import schmitzm.geotools.map.event.MapPaneEvent;  import schmitzm.geotools.gui.XMapPaneEvent;
57    import schmitzm.geotools.gui.XMapPaneTool;
58  import schmitzm.geotools.map.event.JMapPaneListener;  import schmitzm.geotools.map.event.JMapPaneListener;
59  import schmitzm.geotools.map.event.MapAreaChangedEvent;  import schmitzm.geotools.map.event.MapAreaChangedEvent;
 import schmitzm.lang.LangUtil;  
 import schmitzm.lang.ResourceProvider;  
60  import schmitzm.swing.ButtonGroup;  import schmitzm.swing.ButtonGroup;
 import schmitzm.swing.SwingUtil;  
61  import skrueger.swing.SmallButton;  import skrueger.swing.SmallButton;
62  import skrueger.swing.SmallToggleButton;  import skrueger.swing.SmallToggleButton;
63    
# Line 74  import com.vividsolutions.jts.geom.Envel Line 72  import com.vividsolutions.jts.geom.Envel
72   *   *
73   * @author <a href="mailto:[email protected]">Martin Schmitz</a>   * @author <a href="mailto:[email protected]">Martin Schmitz</a>
74   *         (University of Bonn/Germany)   *         (University of Bonn/Germany)
75   * @version 1.2 Stefan Krüger   * @version 1.2 Stefan Tzeggai
76   */   */
77  public class MapPaneToolBar extends JToolBar {  public class MapPaneToolBar extends JToolBar {
78          private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class          private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class
79                          .getName());                          .getName());
80    
         public static ResourceProvider RESOURCE = new ResourceProvider(LangUtil  
                         .extendPackagePath(MapPaneToolBar.class,  
                                         "resource.locales.mapPaneToolbar"), Locale.ENGLISH);  
   
81          public static String R(String key, Object... values) {          public static String R(String key, Object... values) {
82                  return RESOURCE.getString(key, values);                  return GeotoolsGUIUtil.R(key, values);
83          }          }
84    
85          /** Constant for the tool "Panning" (10). */          /** Constant for the tool "Panning" (10). */
# Line 96  public class MapPaneToolBar extends JToo Line 90  public class MapPaneToolBar extends JToo
90    
91          /** Constant for the tool "Zoom In" (110). */          /** Constant for the tool "Zoom In" (110). */
92          public static final int TOOL_ZOOMIN = 110;          public static final int TOOL_ZOOMIN = 110;
93            public static final int ACTION_ZOOM_DEFAULT = 150;
94          /** Constant for the tool "Zoom Out" (120). */          /** Constant for the tool "Zoom Out" (120). */
95          public static final int TOOL_ZOOMOUT = 120;          public static final int TOOL_ZOOMOUT = 120;
96          /** Constant for the action "Zoom back" (130). */          /** Constant for the action "Zoom back" (130). */
# Line 208  public class MapPaneToolBar extends JToo Line 203  public class MapPaneToolBar extends JToo
203    
204                  // Create a Listener to listen to the zooms on the JMapPane                  // Create a Listener to listen to the zooms on the JMapPane
205                  this.mapPaneListener = new JMapPaneListener() {                  this.mapPaneListener = new JMapPaneListener() {
206                          public void performMapPaneEvent(MapPaneEvent e) {                          public void performMapPaneEvent(XMapPaneEvent e) {
207                                  if (!(e instanceof MapAreaChangedEvent))                                  if (!(e instanceof MapAreaChangedEvent))
208                                          return;                                          return;
209    
# Line 307  public class MapPaneToolBar extends JToo Line 302  public class MapPaneToolBar extends JToo
302           */           */
303          protected void initToolsAndActions() {          protected void initToolsAndActions() {
304                  // Panning                  // Panning
305                  addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(  //              addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(
306                                  MapView.class.getResource("resource/icons/pan.png")),  //                              MapView.class.getResource("resource/icons/pan.png")),
307                                  R("MapPaneButtons.Pan.TT")), false);  //                              R("MapPaneButtons.Pan.TT")), false);
308    
309                    addTool(new MapPaneToolBarAction(TOOL_PAN, this, XMapPaneTool.PAN), false);
310                    
311                  // Info                  // Info
312                  addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(  //              addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(
313                                  MapView.class.getResource("resource/icons/info.png")),  //                              MapView.class.getResource("resource/icons/info.png")),
314                                  R("MapPaneButtons.Info.TT")), false);  //                              R("MapPaneButtons.Info.TT")), false);
315                    addTool(new MapPaneToolBarAction(TOOL_INFO, this, XMapPaneTool.INFO), false);
316    
317                  // Zoom in                  // Zoom in
318                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, XMapPaneTool.ZOOM_IN), false);
319                                  MapView.class.getResource("resource/icons/zoom_in.png")),                  
                                 R("MapPaneButtons.ZoomIn.TT")), false);  
320                  // Zoom out                  // Zoom out
321                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, XMapPaneTool.ZOOM_OUT), false);
322                                  MapView.class.getResource("resource/icons/zoom_out.png")),                  
323                                  R("MapPaneButtons.ZoomOut.TT")), false);                  
324    //              // Zoom in
325    //              addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(
326    //                              MapView.class.getResource("resource/icons/zoom_in.png")),
327    //                              R("MapPaneButtons.ZoomIn.TT")), false);
328    //              
329    //              // Zoom out
330    //              addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(
331    //                              MapView.class.getResource("resource/icons/zoom_out.png")),
332    //                              R("MapPaneButtons.ZoomOut.TT")), false);
333                    
334                    
335    
336                  // Action button to revert the last zoom                  // Action button to revert the last zoom
337                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",
# Line 426  public class MapPaneToolBar extends JToo Line 435  public class MapPaneToolBar extends JToo
435                  switch (tool) {                  switch (tool) {
436                  case TOOL_PAN:                  case TOOL_PAN:
437                          // Set the mouse tool to "Panning"                          // Set the mouse tool to "Panning"
438                          mapPane.setState(SelectableXMapPane.PAN);  //                      mapPane.setState(SelectableXMapPane.PAN);
439                            mapPane.setTool(XMapPaneTool.PAN);
440  //                      mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);  //                      mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);
441                          break;                          break;
442                  case TOOL_INFO:                  case TOOL_INFO:
443                          // Set the mouse tool to "Info"                          // Set the mouse tool to "Info"
444                          mapPane.setState(SelectableXMapPane.SELECT_ONE_FROM_TOP);                          mapPane.setTool(XMapPaneTool.INFO);
445    //                      mapPane.setState(SelectableXMapPane.SELECT_ONE_FROM_TOP);
446  //                      mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);  //                      mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);
447                          break;                          break;
448                  case TOOL_ZOOMIN:                  case TOOL_ZOOMIN:
449                          // Set the mouse tool to "Zoom in"                          // Set the mouse tool to "Zoom in"
450                          mapPane.setState(SelectableXMapPane.ZOOM_IN);                          mapPane.setTool(XMapPaneTool.ZOOM_IN);
451  //                      mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);  //                      mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);
452                          break;                          break;
453                  case TOOL_ZOOMOUT:                  case TOOL_ZOOMOUT:
454                          // Set the mouse tool to "Zoom out"                          // Set the mouse tool to "Zoom out"
455                          mapPane.setState(SelectableXMapPane.ZOOM_OUT);                          mapPane.setTool(XMapPaneTool.ZOOM_OUT);
456    //                      mapPane.setState(SelectableXMapPane.ZOOM_OUT);
457  //                      mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);  //                      mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);
458                          break;                          break;
459                  default:  //              default:
460                          // Set map actions to default                          // Set map actions to default
461                          mapPane.setState(SelectableXMapPane.NONE);  //                      mapPane.setState(SelectableXMapPane.NONE);
462  //                      mapPane.setNormalCursor(null);  //                      mapPane.setNormalCursor(null);
463                          break;  //                      break;
464                  }                  }
465  //              mapPane.updateCursorAndRepaintTimer();  //              mapPane.updateCursorAndRepaintTimer();
466          }          }
# Line 474  public class MapPaneToolBar extends JToo Line 486  public class MapPaneToolBar extends JToo
486          protected void performActionButton(int action, ActionEvent e) {          protected void performActionButton(int action, ActionEvent e) {
487                  if (mapPane == null)                  if (mapPane == null)
488                          return;                          return;
489                    
490                  // Perform the action "Zoom back": Revert the last zoom                  // Perform the action "Zoom back": Revert the last zoom
491                  if (action == ACTION_ZOOM_BACK) {                  if (action == ACTION_ZOOM_BACK) {
492                          if (zoomBackIndex <= 1)                          if (zoomBackIndex <= 1)
# Line 624  public class MapPaneToolBar extends JToo Line 636  public class MapPaneToolBar extends JToo
636           *         {@linkplain #getToolButton(int) tool button}           *         {@linkplain #getToolButton(int) tool button}
637           */           */
638          public AbstractButton getButton(int id) {          public AbstractButton getButton(int id) {
639                    
640                    //ACHUTNG: Das ist ein SK QUICK FIX! TODO
641                    if (!(toolAndActionButtons.get(id) instanceof AbstractButton)) return null;
642                    
643                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);
644                  if (button == null)                  if (button == null)
645                          LOGGER.warn("Unknown tool or action ID: " + id);                          LOGGER.warn("Unknown tool or action ID: " + id);
# Line 690  public class MapPaneToolBar extends JToo Line 706  public class MapPaneToolBar extends JToo
706                          return -1;                          return -1;
707                  return selectedTool;                  return selectedTool;
708          }          }
709            
710          /**          /**
711           * 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
712           * of the button is not affected.           * of the button is not affected.
# Line 765  public class MapPaneToolBar extends JToo Line 781  public class MapPaneToolBar extends JToo
781           *            is {@code false}           *            is {@code false}
782           */           */
783          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {
784                  for (int tool : toolAndActionButtons.keySet())                  for (int id : toolAndActionButtons.keySet()) {
785                          setButtonEnabled(tool, enabled, hideOnDisable);                          if (toolAndActionButtons.get(id) instanceof JToggleButton) {
786                            setButtonEnabled(id, enabled, hideOnDisable);
787                            }
788                    }
789          }          }
790            
791          /**          /**
792           * Sets the activation for all actions.           * Sets the activation for all actions.
793           *           *
# Line 889  public class MapPaneToolBar extends JToo Line 908  public class MapPaneToolBar extends JToo
908                          this.toolBar = toolBar;                          this.toolBar = toolBar;
909                  }                  }
910    
911                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, XMapPaneTool tool) {
912                            this(id, toolBar, "", tool.getIcon(), tool.getToolTip());
913                    }
914    
915                  /**                  /**
916                   * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or                   * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or
917                   * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}                   * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}
# Line 918  public class MapPaneToolBar extends JToo Line 941  public class MapPaneToolBar extends JToo
941           * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.           * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.
942           *           *
943           * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons
944           *         Kr&uuml;ger</a>           *         Tzeggai</a>
945           */           */
946          @Override          @Override
947          public void print(Graphics g) {          public void print(Graphics g) {

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26