/[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

trunk/src/skrueger/geotools/MapPaneToolBar.java revision 297 by alfonx, Mon Aug 10 22:10:07 2009 UTC branches/1.0-gt2-2.6/src/skrueger/geotools/MapPaneToolBar.java revision 417 by alfonx, Fri Sep 25 16:34:10 2009 UTC
# Line 30  Line 30 
30  package skrueger.geotools;  package skrueger.geotools;
31    
32  import java.awt.Color;  import java.awt.Color;
 import java.awt.Dimension;  
33  import java.awt.Graphics;  import java.awt.Graphics;
34  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
35    import java.awt.event.ActionListener;
36  import java.util.ArrayList;  import java.util.ArrayList;
37    import java.util.HashSet;
38  import java.util.Locale;  import java.util.Locale;
39    import java.util.Set;
40  import java.util.SortedMap;  import java.util.SortedMap;
41  import java.util.TreeMap;  import java.util.TreeMap;
42    
# Line 128  public class MapPaneToolBar extends JToo Line 130  public class MapPaneToolBar extends JToo
130          protected int selectedTool = TOOL_ZOOMIN;          protected int selectedTool = TOOL_ZOOMIN;
131    
132          /** Holds the tool buttons of the tool bar. */          /** Holds the tool buttons of the tool bar. */
133          protected SortedMap<Integer, JComponent> toolAndActionButtons = null;          final protected SortedMap<Integer, JComponent> toolAndActionButtons = new TreeMap<Integer, JComponent>();
134          /** Controls that only one tool button is activated. */          /** Controls that only one tool button is activated. */
135          protected ButtonGroup toolButtonGroup = null;          protected ButtonGroup toolButtonGroup = null;
136    
# Line 153  public class MapPaneToolBar extends JToo Line 155  public class MapPaneToolBar extends JToo
155    
156          protected boolean zoomBackForwardButtonInAction;          protected boolean zoomBackForwardButtonInAction;
157    
158            /** Listeners what want to be informed about a change of the selected tool **/
159            protected Set<MapPaneToolSelectedListener> toolSelectionListeners = new HashSet<MapPaneToolSelectedListener>();
160    
161            /** This listener is added to all {@link JToggleButton}  **/
162            private final ActionListener toolSelectedListener = new ActionListener(){
163    
164                    @Override
165                    public void actionPerformed(ActionEvent e) {
166                            JToggleButton tb = (JToggleButton) e.getSource();
167                            
168                            // Inform the listeners about a newly selected tool
169                            for (MapPaneToolSelectedListener l : toolSelectionListeners) {
170                                    l.toolSelected(Integer.valueOf( tb.getName() ) ) ;
171                            }
172                    }
173                    
174            };
175    
176          /**          /**
177           * Creates a new toolbar. Notice: This toolbar does nothing until           * Creates a new toolbar. Notice: This toolbar does nothing until
178           * {@link #setMapPane(JMapPane)} is called!           * {@link #setMapPane(JMapPane)} is called!
# Line 160  public class MapPaneToolBar extends JToo Line 180  public class MapPaneToolBar extends JToo
180          public MapPaneToolBar() {          public MapPaneToolBar() {
181                  this(null);                  this(null);
182          }          }
183            
184            public void addButtonSelectedListener(MapPaneToolSelectedListener listener ) {
185                    toolSelectionListeners.add(listener);
186            }
187    
188            public void removeButtonSelectedListener(MapPaneToolSelectedListener listener ) {
189                    toolSelectionListeners .remove(listener);
190            }
191    
192          /**          /**
193           * Creates a new tool bar.           * Creates a new tool bar.
# Line 169  public class MapPaneToolBar extends JToo Line 197  public class MapPaneToolBar extends JToo
197           */           */
198          public MapPaneToolBar(JMapPane mapPane) {          public MapPaneToolBar(JMapPane mapPane) {
199                  super("Control the map", JToolBar.HORIZONTAL);                  super("Control the map", JToolBar.HORIZONTAL);
200                  this.toolAndActionButtons = new TreeMap<Integer, JComponent>();                  
201                    // I want to see nothing on the background
202                    setOpaque(false);
203                    setBorder(null);
204                    
205                  this.toolButtonGroup = new ButtonGroup();                  this.toolButtonGroup = new ButtonGroup();
206                                    
207                  // Create a Listener to listen to the zooms on the JMapPane                  // Create a Listener to listen to the zooms on the JMapPane
# Line 244  public class MapPaneToolBar extends JToo Line 276  public class MapPaneToolBar extends JToo
276           * puts all tool buttons and all actions buttons to the tool bar.           * puts all tool buttons and all actions buttons to the tool bar.
277           */           */
278          protected void init() {          protected void init() {
279                    
280                  initToolsAndActions();                  initToolsAndActions();
281    
282                  addSeparator(SEPERATOR0, new JToolBar.Separator());                  addSeparator(SEPERATOR0, new JToolBar.Separator());
# Line 293  public class MapPaneToolBar extends JToo Line 326  public class MapPaneToolBar extends JToo
326                  setSelectedTool(selectedTool);                  setSelectedTool(selectedTool);
327    
328          }          }
329            
330            @Override
331            public void paint(Graphics g) {
332                    super.paint(g);
333            }
334    
335          /**          /**
336           * Clears the GUI of all components and adds all tool and action buttons to           * Clears the GUI of all components and adds all tool and action buttons to
337           * the tool bar.           * the tool bar.
338           */           */
339          public void initToolBar() {          public void initToolBar() {
340                  setAlignmentY(1f);  //              setOpaque(true);
341    //              
342    //              setAlignmentY(1f);
343    //              setAlignmentX(0.5f);
344                  removeAll();                  removeAll();
345                  // Separator to the left of the tool actions to start                  
346                  // the tool buttons with the map (not with the coordinate grid)  //              // Separator to the left of the tool actions to start
347                  Dimension dimension = new Dimension(49, 10);  //              // the tool buttons with the map (not with the coordinate grid)
348                  addSeparator(dimension);  //              Dimension dimension = new Dimension(49, 10);
349    //              addSeparator(dimension);
350                    
351                    
352                  // Tool buttons                  // Tool buttons
353                  for (JComponent b : toolAndActionButtons.values())                  for (Integer bKey : toolAndActionButtons.keySet()) {
354                            
355                            JComponent b = toolAndActionButtons.get(bKey);
356                            
357                            if (b instanceof JToggleButton) {
358                                    JToggleButton tb = (JToggleButton) b;
359                                    tb.setName(bKey.toString());
360                                    tb.addActionListener( toolSelectedListener );
361                            }
362                            
363                          add(b);                          add(b);
364                    }
365    
366                  if (!toolAndActionButtons.containsKey(selectedTool)) {                  if (!toolAndActionButtons.containsKey(selectedTool)) {
367                          /**                          /**
# Line 359  public class MapPaneToolBar extends JToo Line 413  public class MapPaneToolBar extends JToo
413                          // Set the mouse tool to "Panning"                          // Set the mouse tool to "Panning"
414                          mapPane.setWindowSelectionState(JMapPane.NONE);                          mapPane.setWindowSelectionState(JMapPane.NONE);
415                          mapPane.setState(JMapPane.PAN);                          mapPane.setState(JMapPane.PAN);
                         mapPane.setHighlight(false);  
416                          mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);                          mapPane.setNormalCursor(SwingUtil.PAN_CURSOR);
417                          break;                          break;
418                  case TOOL_INFO:                  case TOOL_INFO:
# Line 367  public class MapPaneToolBar extends JToo Line 420  public class MapPaneToolBar extends JToo
420                          mapPane.setWindowSelectionState(JMapPane.NONE);                          mapPane.setWindowSelectionState(JMapPane.NONE);
421                          mapPane.setState(JMapPane.SELECT_TOP); // Why not:                          mapPane.setState(JMapPane.SELECT_TOP); // Why not:
422                          // JMapPane.SELECT_TOP_ONEONLY                          // JMapPane.SELECT_TOP_ONEONLY
                         mapPane.setHighlight(false);// SK: Was true, but since it not works  
423                          // properly removed it to save                          // properly removed it to save
424                          // performance                          // performance
425                          mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);                          mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);
# Line 376  public class MapPaneToolBar extends JToo Line 428  public class MapPaneToolBar extends JToo
428                          // Set the mouse tool to "Zoom in"                          // Set the mouse tool to "Zoom in"
429                          mapPane.setWindowSelectionState(JMapPane.ZOOM_IN);                          mapPane.setWindowSelectionState(JMapPane.ZOOM_IN);
430                          mapPane.setState(JMapPane.ZOOM_IN);                          mapPane.setState(JMapPane.ZOOM_IN);
                         mapPane.setHighlight(false);  
431                          mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);                          mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR);
432                          break;                          break;
433                  case TOOL_ZOOMOUT:                  case TOOL_ZOOMOUT:
434                          // Set the mouse tool to "Zoom out"                          // Set the mouse tool to "Zoom out"
435                          mapPane.setWindowSelectionState(JMapPane.NONE);                          mapPane.setWindowSelectionState(JMapPane.NONE);
436                          mapPane.setState(JMapPane.ZOOM_OUT);                          mapPane.setState(JMapPane.ZOOM_OUT);
                         mapPane.setHighlight(false);  
437                          mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);                          mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);
438                          break;                          break;
439                  default:                  default:
440                          // Set map actions to default                          // Set map actions to default
441                          mapPane.setWindowSelectionState(JMapPane.NONE);                          mapPane.setWindowSelectionState(JMapPane.NONE);
442                          mapPane.setState(JMapPane.NONE);                          mapPane.setState(JMapPane.NONE);
                         mapPane.setHighlight(false);  
443                          mapPane.setNormalCursor(null);                          mapPane.setNormalCursor(null);
444                          break;                          break;
445                  }                  }
# Line 875  public class MapPaneToolBar extends JToo Line 924  public class MapPaneToolBar extends JToo
924                    setBackground(orig);                    setBackground(orig);
925                }                }
926            }            }
927    
928  }  }

Legend:
Removed from v.297  
changed lines
  Added in v.417

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26