/[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 315 by mojays, Wed Aug 26 11:03:27 2009 UTC revision 414 by alfonx, Thu Sep 24 13:23:08 2009 UTC
# Line 33  import java.awt.Color; Line 33  import java.awt.Color;
33  import java.awt.Dimension;  import java.awt.Dimension;
34  import java.awt.Graphics;  import java.awt.Graphics;
35  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
36    import java.awt.event.ActionListener;
37  import java.util.ArrayList;  import java.util.ArrayList;
38    import java.util.HashSet;
39  import java.util.Locale;  import java.util.Locale;
40    import java.util.Set;
41  import java.util.SortedMap;  import java.util.SortedMap;
42  import java.util.TreeMap;  import java.util.TreeMap;
43    
# Line 128  public class MapPaneToolBar extends JToo Line 131  public class MapPaneToolBar extends JToo
131          protected int selectedTool = TOOL_ZOOMIN;          protected int selectedTool = TOOL_ZOOMIN;
132    
133          /** Holds the tool buttons of the tool bar. */          /** Holds the tool buttons of the tool bar. */
134          protected SortedMap<Integer, JComponent> toolAndActionButtons = null;          final protected SortedMap<Integer, JComponent> toolAndActionButtons = new TreeMap<Integer, JComponent>();
135          /** Controls that only one tool button is activated. */          /** Controls that only one tool button is activated. */
136          protected ButtonGroup toolButtonGroup = null;          protected ButtonGroup toolButtonGroup = null;
137    
# Line 153  public class MapPaneToolBar extends JToo Line 156  public class MapPaneToolBar extends JToo
156    
157          protected boolean zoomBackForwardButtonInAction;          protected boolean zoomBackForwardButtonInAction;
158    
159            /** Listeners what want to be informed about a change of the selected tool **/
160            protected Set<MapPaneToolSelectedListener> toolSelectionListeners = new HashSet<MapPaneToolSelectedListener>();
161    
162            /** This listener is added to all {@link JToggleButton}  **/
163            private final ActionListener toolSelectedListener = new ActionListener(){
164    
165                    @Override
166                    public void actionPerformed(ActionEvent e) {
167                            JToggleButton tb = (JToggleButton) e.getSource();
168                            
169                            // Inform the listeners about a newly selected tool
170                            for (MapPaneToolSelectedListener l : toolSelectionListeners) {
171                                    l.toolSelected(Integer.valueOf( tb.getName() ) ) ;
172                            }
173                    }
174                    
175            };
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(JMapPane)} is called!
# Line 160  public class MapPaneToolBar extends JToo Line 181  public class MapPaneToolBar extends JToo
181          public MapPaneToolBar() {          public MapPaneToolBar() {
182                  this(null);                  this(null);
183          }          }
184            
185            public void addButtonSelectedListener(MapPaneToolSelectedListener listener ) {
186                    toolSelectionListeners.add(listener);
187            }
188    
189            public void removeButtonSelectedListener(MapPaneToolSelectedListener listener ) {
190                    toolSelectionListeners .remove(listener);
191            }
192    
193          /**          /**
194           * Creates a new tool bar.           * Creates a new tool bar.
# Line 169  public class MapPaneToolBar extends JToo Line 198  public class MapPaneToolBar extends JToo
198           */           */
199          public MapPaneToolBar(JMapPane mapPane) {          public MapPaneToolBar(JMapPane mapPane) {
200                  super("Control the map", JToolBar.HORIZONTAL);                  super("Control the map", JToolBar.HORIZONTAL);
                 this.toolAndActionButtons = new TreeMap<Integer, JComponent>();  
201                  this.toolButtonGroup = new ButtonGroup();                  this.toolButtonGroup = new ButtonGroup();
202                                    
203                  // Create a Listener to listen to the zooms on the JMapPane                  // Create a Listener to listen to the zooms on the JMapPane
# Line 306  public class MapPaneToolBar extends JToo Line 334  public class MapPaneToolBar extends JToo
334                  Dimension dimension = new Dimension(49, 10);                  Dimension dimension = new Dimension(49, 10);
335                  addSeparator(dimension);                  addSeparator(dimension);
336                  // Tool buttons                  // Tool buttons
337                  for (JComponent b : toolAndActionButtons.values())                  for (Integer bKey : toolAndActionButtons.keySet()) {
338                            
339                            JComponent b = toolAndActionButtons.get(bKey);
340                            
341                            if (b instanceof JToggleButton) {
342                                    JToggleButton tb = (JToggleButton) b;
343                                    tb.setName(bKey.toString());
344                                    tb.addActionListener( toolSelectedListener );
345                            }
346                            
347                          add(b);                          add(b);
348                    }
349    
350                  if (!toolAndActionButtons.containsKey(selectedTool)) {                  if (!toolAndActionButtons.containsKey(selectedTool)) {
351                          /**                          /**
# Line 359  public class MapPaneToolBar extends JToo Line 397  public class MapPaneToolBar extends JToo
397                          // Set the mouse tool to "Panning"                          // Set the mouse tool to "Panning"
398                          mapPane.setWindowSelectionState(JMapPane.NONE);                          mapPane.setWindowSelectionState(JMapPane.NONE);
399                          mapPane.setState(JMapPane.PAN);                          mapPane.setState(JMapPane.PAN);
                         mapPane.setHighlight(false);  
400                          mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);                          mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);
401                          break;                          break;
402                  case TOOL_INFO:                  case TOOL_INFO:
# Line 367  public class MapPaneToolBar extends JToo Line 404  public class MapPaneToolBar extends JToo
404                          mapPane.setWindowSelectionState(JMapPane.NONE);                          mapPane.setWindowSelectionState(JMapPane.NONE);
405                          mapPane.setState(JMapPane.SELECT_TOP); // Why not:                          mapPane.setState(JMapPane.SELECT_TOP); // Why not:
406                          // JMapPane.SELECT_TOP_ONEONLY                          // JMapPane.SELECT_TOP_ONEONLY
                         mapPane.setHighlight(false);// SK: Was true, but since it not works  
407                          // properly removed it to save                          // properly removed it to save
408                          // performance                          // performance
409                          mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);                          mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);
# Line 376  public class MapPaneToolBar extends JToo Line 412  public class MapPaneToolBar extends JToo
412                          // Set the mouse tool to "Zoom in"                          // Set the mouse tool to "Zoom in"
413                          mapPane.setWindowSelectionState(JMapPane.ZOOM_IN);                          mapPane.setWindowSelectionState(JMapPane.ZOOM_IN);
414                          mapPane.setState(JMapPane.ZOOM_IN);                          mapPane.setState(JMapPane.ZOOM_IN);
                         mapPane.setHighlight(false);  
415                          mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);                          mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);
416                          break;                          break;
417                  case TOOL_ZOOMOUT:                  case TOOL_ZOOMOUT:
418                          // Set the mouse tool to "Zoom out"                          // Set the mouse tool to "Zoom out"
419                          mapPane.setWindowSelectionState(JMapPane.NONE);                          mapPane.setWindowSelectionState(JMapPane.NONE);
420                          mapPane.setState(JMapPane.ZOOM_OUT);                          mapPane.setState(JMapPane.ZOOM_OUT);
                         mapPane.setHighlight(false);  
421                          mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);                          mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);
422                          break;                          break;
423                  default:                  default:
424                          // Set map actions to default                          // Set map actions to default
425                          mapPane.setWindowSelectionState(JMapPane.NONE);                          mapPane.setWindowSelectionState(JMapPane.NONE);
426                          mapPane.setState(JMapPane.NONE);                          mapPane.setState(JMapPane.NONE);
                         mapPane.setHighlight(false);  
427                          mapPane.setNormalCursor(null);                          mapPane.setNormalCursor(null);
428                          break;                          break;
429                  }                  }
# Line 875  public class MapPaneToolBar extends JToo Line 908  public class MapPaneToolBar extends JToo
908                    setBackground(orig);                    setBackground(orig);
909                }                }
910            }            }
911    
912  }  }

Legend:
Removed from v.315  
changed lines
  Added in v.414

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26