/[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 891 by alfonx, Thu Jun 3 12:20:11 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.JMapPane;  import schmitzm.geotools.gui.GeotoolsGUIUtil;
55  import schmitzm.geotools.map.event.JMapPaneEvent;  import schmitzm.geotools.gui.SelectableXMapPane;
56    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    
64  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
65    
66  /**  /**
67   * A toolbar to control an {@link JMapPane} (Atlas visualization). This contains   * A toolbar to control an {@link SelectableXMapPane} (Atlas visualization). This contains
68   * 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
69   * map represented by {@link JToggleButton JToggleButtons}, where only one tool   * map represented by {@link JToggleButton JToggleButtons}, where only one tool
70   * 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 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 140  public class MapPaneToolBar extends JToo Line 135  public class MapPaneToolBar extends JToo
135          // /** Holds the action buttons of the bar. */          // /** Holds the action buttons of the bar. */
136          // protected SortedMap<Integer, JButton> actionButtons = null;          // protected SortedMap<Integer, JButton> actionButtons = null;
137    
138          /** Holds the {@link JMapPane} this tool bar controls. */          /** Holds the {@link SelectableXMapPane} this tool bar controls. */
139          protected JMapPane mapPane = null;          protected SelectableXMapPane mapPane = null;
140    
141          /**          /**
142           * 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 171  public class MapPaneToolBar extends JToo
171    
172          /**          /**
173           * Creates a new toolbar. Notice: This toolbar does nothing until           * Creates a new toolbar. Notice: This toolbar does nothing until
174           * {@link #setMapPane(JMapPane)} is called!           * {@link #setMapPane(SelectableXMapPane)} is called!
175           */           */
176          public MapPaneToolBar() {          public MapPaneToolBar() {
177                  this(null);                  this(null);
# Line 195  public class MapPaneToolBar extends JToo Line 190  public class MapPaneToolBar extends JToo
190           * Creates a new tool bar.           * Creates a new tool bar.
191           *           *
192           * @param mapPane           * @param mapPane
193           *            {@link JMapPane} the tool bar controls           *            {@link SelectableXMapPane} the tool bar controls
194           */           */
195          public MapPaneToolBar(JMapPane mapPane) {          public MapPaneToolBar(SelectableXMapPane mapPane) {
196                  super("Control the map", JToolBar.HORIZONTAL);                  super("Control the map", JToolBar.HORIZONTAL);
197    
198                  // I want to see nothing on the background                  // I want to see nothing on the background
# 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(JMapPaneEvent e) {                          public void performMapPaneEvent(XMapPaneEvent e) {
207                                  if (!(e instanceof MapAreaChangedEvent))                                  if (!(e instanceof MapAreaChangedEvent))
208                                          return;                                          return;
209    
# Line 269  public class MapPaneToolBar extends JToo Line 264  public class MapPaneToolBar extends JToo
264          }          }
265    
266          /**          /**
267           * Sets the {@link JMapPane} controlled by this tool bar.           * Sets the {@link SelectableXMapPane} controlled by this tool bar.
268           *           *
269           * @param mapPane           * @param mapPane
270           *            {@link JMapPane} to control (if {@code null} this tool bar           *            {@link SelectableXMapPane} to control (if {@code null} this tool bar
271           *            controls NOTHING!)           *            controls NOTHING!)
272           */           */
273          public void setMapPane(JMapPane mapPane) {          public void setMapPane(SelectableXMapPane mapPane) {
274                  // Remove listener from old MapPane                  // Remove listener from old MapPane
275                  if (this.mapPane != null)                  if (this.mapPane != null)
276                          this.mapPane.removeMapPaneListener(mapPaneListener);                          this.mapPane.removeMapPaneListener(mapPaneListener);
# Line 306  public class MapPaneToolBar extends JToo Line 301  public class MapPaneToolBar extends JToo
301           * super.initTools()}.           * super.initTools()}.
302           */           */
303          protected void initToolsAndActions() {          protected void initToolsAndActions() {
304                  // Panning                  // Pan
305                  addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_PAN, this, XMapPaneTool.PAN), false);
306                                  MapView.class.getResource("resource/icons/pan.png")),                  
                                 R("MapPaneButtons.Pan.TT")), false);  
307                  // Info                  // Info
308                  addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_INFO, this, XMapPaneTool.INFO), false);
                                 MapView.class.getResource("resource/icons/info.png")),  
                                 R("MapPaneButtons.Info.TT")), false);  
309    
310                  // Zoom in                  // Zoom in
311                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, XMapPaneTool.ZOOM_IN), false);
312                                  MapView.class.getResource("resource/icons/zoom_in.png")),                  
                                 R("MapPaneButtons.ZoomIn.TT")), false);  
313                  // Zoom out                  // Zoom out
314                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, XMapPaneTool.ZOOM_OUT), false);
315                                  MapView.class.getResource("resource/icons/zoom_out.png")),                  
                                 R("MapPaneButtons.ZoomOut.TT")), false);  
   
316                  // Action button to revert the last zoom                  // Action button to revert the last zoom
317                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",
318                                  new ImageIcon(MapView.class                                  new ImageIcon(MapView.class
# Line 353  public class MapPaneToolBar extends JToo Line 342  public class MapPaneToolBar extends JToo
342           * the tool bar.           * the tool bar.
343           */           */
344          public void initToolBar() {          public void initToolBar() {
                 // setOpaque(true);  
                 //                
                 // setAlignmentY(1f);  
                 // setAlignmentX(0.5f);  
345                  removeAll();                  removeAll();
346    
347                  // // Separator to the left of the tool actions to start                  // // Separator to the left of the tool actions to start
# Line 399  public class MapPaneToolBar extends JToo Line 384  public class MapPaneToolBar extends JToo
384                  repaint();                  repaint();
385          }          }
386    
         // 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);  
         // }  
   
387          /**          /**
388           * Performs the activation of a tool.           * Performs the activation of a tool.
389           *           *
# Line 425  public class MapPaneToolBar extends JToo Line 400  public class MapPaneToolBar extends JToo
400    
401                  switch (tool) {                  switch (tool) {
402                  case TOOL_PAN:                  case TOOL_PAN:
403                          // Set the mouse tool to "Panning"                          mapPane.setTool(XMapPaneTool.PAN);
                         mapPane.setWindowSelectionState(JMapPane.NONE);  
                         mapPane.setState(JMapPane.PAN);  
                         mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);  
404                          break;                          break;
405                  case TOOL_INFO:                  case TOOL_INFO:
406                          // Set the mouse tool to "Info"                          mapPane.setTool(XMapPaneTool.INFO);
                         mapPane.setWindowSelectionState(JMapPane.NONE);  
                         mapPane.setState(JMapPane.SELECT_TOP); // Why not:  
                         // JMapPane.SELECT_TOP_ONEONLY  
                         // properly removed it to save  
                         // performance  
                         mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);  
407                          break;                          break;
408                  case TOOL_ZOOMIN:                  case TOOL_ZOOMIN:
409                          // Set the mouse tool to "Zoom in"                          mapPane.setTool(XMapPaneTool.ZOOM_IN);
                         mapPane.setWindowSelectionState(JMapPane.ZOOM_IN);  
                         mapPane.setState(JMapPane.ZOOM_IN);  
                         mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);  
410                          break;                          break;
411                  case TOOL_ZOOMOUT:                  case TOOL_ZOOMOUT:
412                          // Set the mouse tool to "Zoom out"                          mapPane.setTool(XMapPaneTool.ZOOM_OUT);
                         mapPane.setWindowSelectionState(JMapPane.NONE);  
                         mapPane.setState(JMapPane.ZOOM_OUT);  
                         mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);  
                         break;  
                 default:  
                         // Set map actions to default  
                         mapPane.setWindowSelectionState(JMapPane.NONE);  
                         mapPane.setState(JMapPane.NONE);  
                         mapPane.setNormalCursor(null);  
413                          break;                          break;
414                  }                  }
                 mapPane.updateCursor();  
415          }          }
416    
417          /**          /**
# Line 482  public class MapPaneToolBar extends JToo Line 435  public class MapPaneToolBar extends JToo
435          protected void performActionButton(int action, ActionEvent e) {          protected void performActionButton(int action, ActionEvent e) {
436                  if (mapPane == null)                  if (mapPane == null)
437                          return;                          return;
438                    
439                  // Perform the action "Zoom back": Revert the last zoom                  // Perform the action "Zoom back": Revert the last zoom
440                  if (action == ACTION_ZOOM_BACK) {                  if (action == ACTION_ZOOM_BACK) {
441                          if (zoomBackIndex <= 1)                          if (zoomBackIndex <= 1)
# Line 532  public class MapPaneToolBar extends JToo Line 485  public class MapPaneToolBar extends JToo
485                  }                  }
486                  JToggleButton button = new SmallToggleButton(buttonAction);                  JToggleButton button = new SmallToggleButton(buttonAction);
487                                    
 //              button.setBorder(BorderFactory.createRaisedBevelBorder());  
488                  toolButtonGroup.add(button);                  toolButtonGroup.add(button);
489                  toolAndActionButtons.put(buttonAction.getID(), button);                  toolAndActionButtons.put(buttonAction.getID(), button);
490                  if (resetToolBar)                  if (resetToolBar)
# Line 569  public class MapPaneToolBar extends JToo Line 521  public class MapPaneToolBar extends JToo
521                          return;                          return;
522                  }                  }
523                  JButton button = new SmallButton(buttonAction);                  JButton button = new SmallButton(buttonAction);
 //              button.setBorder(BorderFactory.createRaisedBevelBorder());  
524                  toolAndActionButtons.put(buttonAction.getID(), button);                  toolAndActionButtons.put(buttonAction.getID(), button);
525                  if (resetToolBar)                  if (resetToolBar)
526                          initToolBar();                          initToolBar();
# Line 632  public class MapPaneToolBar extends JToo Line 583  public class MapPaneToolBar extends JToo
583           *         {@linkplain #getToolButton(int) tool button}           *         {@linkplain #getToolButton(int) tool button}
584           */           */
585          public AbstractButton getButton(int id) {          public AbstractButton getButton(int id) {
586                    
587                    //ACHUTNG: Das ist ein SK QUICK FIX! TODO
588                    if (!(toolAndActionButtons.get(id) instanceof AbstractButton)) return null;
589                    
590                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);                  AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);
591                  if (button == null)                  if (button == null)
592                          LOGGER.warn("Unknown tool or action ID: " + id);                          LOGGER.warn("Unknown tool or action ID: " + id);
# Line 698  public class MapPaneToolBar extends JToo Line 653  public class MapPaneToolBar extends JToo
653                          return -1;                          return -1;
654                  return selectedTool;                  return selectedTool;
655          }          }
656            
657          /**          /**
658           * 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
659           * of the button is not affected.           * of the button is not affected.
# Line 773  public class MapPaneToolBar extends JToo Line 728  public class MapPaneToolBar extends JToo
728           *            is {@code false}           *            is {@code false}
729           */           */
730          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {
731                  for (int tool : toolAndActionButtons.keySet())                  for (int id : toolAndActionButtons.keySet()) {
732                          setButtonEnabled(tool, enabled, hideOnDisable);                          if (toolAndActionButtons.get(id) instanceof JToggleButton) {
733                            setButtonEnabled(id, enabled, hideOnDisable);
734                            }
735                    }
736          }          }
737            
738          /**          /**
739           * Sets the activation for all actions.           * Sets the activation for all actions.
740           *           *
# Line 897  public class MapPaneToolBar extends JToo Line 855  public class MapPaneToolBar extends JToo
855                          this.toolBar = toolBar;                          this.toolBar = toolBar;
856                  }                  }
857    
858                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, XMapPaneTool tool) {
859                            this(id, toolBar, "", tool.getIcon(), tool.getToolTip());
860                    }
861    
862                  /**                  /**
863                   * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or                   * Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or
864                   * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}                   * {@link MapPaneToolBar#performActionButton(int, ActionEvent)}
# Line 926  public class MapPaneToolBar extends JToo Line 888  public class MapPaneToolBar extends JToo
888           * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.           * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.
889           *           *
890           * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons
891           *         Kr&uuml;ger</a>           *         Tzeggai</a>
892           */           */
893          @Override          @Override
894          public void print(Graphics g) {          public void print(Graphics g) {

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26