/[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 140 by alfonx, Sun Jun 14 17:24:44 2009 UTC revision 152 by alfonx, Fri Jun 19 18:13:35 2009 UTC
# Line 3  package skrueger.geotools; Line 3  package skrueger.geotools;
3  import java.awt.Dimension;  import java.awt.Dimension;
4  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
5  import java.util.ArrayList;  import java.util.ArrayList;
6    import java.util.Locale;
7  import java.util.SortedMap;  import java.util.SortedMap;
8  import java.util.TreeMap;  import java.util.TreeMap;
9    
10  import javax.swing.AbstractAction;  import javax.swing.AbstractAction;
11  import javax.swing.AbstractButton;  import javax.swing.AbstractButton;
12    import javax.swing.Action;
13  import javax.swing.BorderFactory;  import javax.swing.BorderFactory;
14  import javax.swing.Icon;  import javax.swing.Icon;
15  import javax.swing.ImageIcon;  import javax.swing.ImageIcon;
# Line 22  import schmitzm.geotools.gui.JMapPane; Line 24  import schmitzm.geotools.gui.JMapPane;
24  import schmitzm.geotools.map.event.JMapPaneEvent;  import schmitzm.geotools.map.event.JMapPaneEvent;
25  import schmitzm.geotools.map.event.JMapPaneListener;  import schmitzm.geotools.map.event.JMapPaneListener;
26  import schmitzm.geotools.map.event.MapAreaChangedEvent;  import schmitzm.geotools.map.event.MapAreaChangedEvent;
27    import schmitzm.lang.LangUtil;
28    import schmitzm.lang.ResourceProvider;
29  import schmitzm.swing.ButtonGroup;  import schmitzm.swing.ButtonGroup;
30  import schmitzm.swing.SwingUtil;  import schmitzm.swing.SwingUtil;
31    
# Line 41  import com.vividsolutions.jts.geom.Envel Line 45  import com.vividsolutions.jts.geom.Envel
45  public class MapPaneToolBar extends JToolBar {  public class MapPaneToolBar extends JToolBar {
46          private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class          private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class
47                          .getName());                          .getName());
48            
49            public static ResourceProvider RESOURCE = new ResourceProvider(LangUtil
50                            .extendPackagePath(MapPaneToolBar.class,
51                                            "resource.locales.mapPaneToolbar"), Locale.ENGLISH);
52            
53            public static String R(String key, Object... values) {
54                    return RESOURCE.getString(key, values);
55            }
56    
57          /** Constant for the tool "Panning" (10). */          /** Constant for the tool "Panning" (10). */
58          public static final int TOOL_PAN = 10;          public static final int TOOL_PAN = 10;
59          /** Constant for the tool "Info" (20). */          /** Constant for the tool "Info" (20). */
# Line 125  public class MapPaneToolBar extends JToo Line 138  public class MapPaneToolBar extends JToo
138                  super("Control the map", JToolBar.HORIZONTAL);                  super("Control the map", JToolBar.HORIZONTAL);
139                  this.toolAndActionButtons = new TreeMap<Integer, JComponent>();                  this.toolAndActionButtons = new TreeMap<Integer, JComponent>();
140                  this.toolButtonGroup = new ButtonGroup();                  this.toolButtonGroup = new ButtonGroup();
141                  // Create a Listener to sniff the zooms on the JMapPane                  
142                    // Create a Listener to listen to the zooms on the JMapPane
143                  this.mapPaneListener = new JMapPaneListener() {                  this.mapPaneListener = new JMapPaneListener() {
144                          public void performMapPaneEvent(JMapPaneEvent e) {                          public void performMapPaneEvent(JMapPaneEvent e) {
145                                  if (!(e instanceof MapAreaChangedEvent))                                  if (!(e instanceof MapAreaChangedEvent))
# Line 136  public class MapPaneToolBar extends JToo Line 150  public class MapPaneToolBar extends JToo
150                                          return;                                          return;
151                                  }                                  }
152    
153                                  Envelope oldMapArea = ((MapAreaChangedEvent) e).getOldMapArea();                                  final MapAreaChangedEvent mapAreaChangedEvent = (MapAreaChangedEvent) e;
154                                    Envelope oldMapArea = mapAreaChangedEvent.getOldMapArea();
155                                    
156                                    final Envelope mapArea = mapAreaChangedEvent.getNewMapArea();
157                                    if (mapArea == null || mapArea.equals(oldMapArea) ) {
158                                            // If the MapArea didn't change... we don't want to register it as a zoom action.
159                                            return;
160                                    }
161                                    
162                                  if (lastZooms.size() == 0 && oldMapArea != null) {                                  if (lastZooms.size() == 0 && oldMapArea != null) {
163                                          lastZooms.add(oldMapArea);                                          lastZooms.add(oldMapArea);
164                                          zoomBackIndex = 1;                                          zoomBackIndex = 1;
165                                  }                                  }
   
                                 final Envelope mapArea = ((MapAreaChangedEvent) e)  
                                                 .getNewMapArea();  
166                                  if (mapArea == null)                                  if (mapArea == null)
167                                          return;                                          return;
168    
# Line 210  public class MapPaneToolBar extends JToo Line 229  public class MapPaneToolBar extends JToo
229          protected void initToolsAndActions() {          protected void initToolsAndActions() {
230                  // Panning                  // Panning
231                  addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(
232                                  MapView.class.getResource("resource/icons/pan.png"))), false);                                  MapView.class.getResource("resource/icons/pan.png")), R("MapPaneButtons.Pan.TT")), false);
233                  // Info                  // Info
234                  addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(
235                                  MapView.class.getResource("resource/icons/info.png"))), false);                                  MapView.class.getResource("resource/icons/info.png")),R("MapPaneButtons.Info.TT")), false);
236    
237                  // Zoom in                  // Zoom in
238                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(
239                                  MapView.class.getResource("resource/icons/zoom_in.png"))),                                  MapView.class.getResource("resource/icons/zoom_in.png")), R("MapPaneButtons.ZoomIn.TT")),
240                                  false);                                  false);
241                  // Zoom out                  // Zoom out
242                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(
243                                  MapView.class.getResource("resource/icons/zoom_out.png"))),                                  MapView.class.getResource("resource/icons/zoom_out.png")), R("MapPaneButtons.ZoomOut.TT")),
244                                  false);                                  false);
245    
246                  // Action button to revert the last zoom                  // Action button to revert the last zoom
247                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",
248                                  new ImageIcon(MapView.class                                  new ImageIcon(MapView.class
249                                                  .getResource("resource/icons/zoom_back.png"))), false);                                                  .getResource("resource/icons/zoom_back.png")), R("MapPaneButtons.LastZoom.TT")), false);
250                  setButtonEnabled(ACTION_ZOOM_BACK, false);                  setButtonEnabled(ACTION_ZOOM_BACK, false);
251    
252                  // Action button to redo the last zoom                  // Action button to redo the last zoom
253                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "",                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "",
254                                  new ImageIcon(MapView.class                                  new ImageIcon(MapView.class
255                                                  .getResource("resource/icons/zoom_forward.png"))),                                                  .getResource("resource/icons/zoom_forward.png")), R("MapPaneButtons.NextZoom.TT")),
256                                  false);                                  false);
257                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);
258    
# Line 246  public class MapPaneToolBar extends JToo Line 265  public class MapPaneToolBar extends JToo
265           * 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
266           * the tool bar.           * the tool bar.
267           */           */
268          protected void initToolBar() {          public void initToolBar() {
269                  setAlignmentY(1f);                  setAlignmentY(1f);
270                  removeAll();                  removeAll();
271                  // Separator to the left of the tool actions to start                  // Separator to the left of the tool actions to start
# Line 256  public class MapPaneToolBar extends JToo Line 275  public class MapPaneToolBar extends JToo
275                  // Tool buttons                  // Tool buttons
276                  for (JComponent b : toolAndActionButtons.values())                  for (JComponent b : toolAndActionButtons.values())
277                          add(b);                          add(b);
278    
279                    repaint();
280    
281                    if (!toolAndActionButtons.containsKey(selectedTool)) {
282                            /**
283                             * This might be a bit specific, but IF selection buttons are
284                             * available, select one of them.. if not, select the INFO tool.
285                             */
286    
287                            if (toolAndActionButtons.containsKey(TOOL_SELECTION_SET)) {
288                                    setSelectedTool(TOOL_SELECTION_SET);
289                            } else if (toolAndActionButtons.containsKey(TOOL_INFO)) {
290                                    setSelectedTool(TOOL_INFO);
291                            } else {
292                                    // TODO What to do now?!
293                                    setSelectedTool(null);
294                            }
295    
296                    }
297          }          }
298    
299          // Space between tool buttons and action buttons          // Space between tool buttons and action buttons
# Line 294  public class MapPaneToolBar extends JToo Line 332  public class MapPaneToolBar extends JToo
332                          // Set the mouse tool to "Info"                          // Set the mouse tool to "Info"
333                          mapPane.setWindowSelectionState(JMapPane.NONE);                          mapPane.setWindowSelectionState(JMapPane.NONE);
334                          mapPane.setState(JMapPane.SELECT_TOP); // Why not:                          mapPane.setState(JMapPane.SELECT_TOP); // Why not:
335                                                                                                          // JMapPane.SELECT_TOP_ONEONLY                          // JMapPane.SELECT_TOP_ONEONLY
336                          mapPane.setHighlight(false);// SK: Was true, but since it not works                          mapPane.setHighlight(false);// SK: Was true, but since it not works
337                                                                                  // properly removed it to save                          // properly removed it to save
338                                                                                  // performance                          // performance
339                          mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);                          mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);
340                          break;                          break;
341                  case TOOL_ZOOMIN:                  case TOOL_ZOOMIN:
# Line 314  public class MapPaneToolBar extends JToo Line 352  public class MapPaneToolBar extends JToo
352                          mapPane.setHighlight(false);                          mapPane.setHighlight(false);
353                          mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);                          mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);
354                          break;                          break;
355  //              default:                  default:
356  //                      // Set map actions to default                          // Set map actions to default
357  //                      mapPane.setWindowSelectionState(JMapPane.NONE);                          mapPane.setWindowSelectionState(JMapPane.NONE);
358  //                      mapPane.setState(JMapPane.NONE);                          mapPane.setState(JMapPane.NONE);
359  //                      mapPane.setHighlight(false);                          mapPane.setHighlight(false);
360  //                      mapPane.setNormalCursor(null);                          mapPane.setNormalCursor(null);
361  //                      break;                          break;
362                  }                  }
363                  mapPane.updateCursor();                  mapPane.updateCursor();
364          }          }
365            
366          /**          /**
367           * @param id The ID of the Component to remove           * @param id
368             *            The ID of the Component to remove. The change will not be
369             *            visible until {@link #initToolBar()} is called.
370           * @return <code>null</code> or the component that has been removed.           * @return <code>null</code> or the component that has been removed.
371           */           */
372          public JComponent removeId(int id){          public JComponent removeId(int id) {
373                  return toolAndActionButtons.remove(id);                  return toolAndActionButtons.remove(id);
374          }          }
375    
# Line 372  public class MapPaneToolBar extends JToo Line 412  public class MapPaneToolBar extends JToo
412                                  mapPane.refresh();                                  mapPane.refresh();
413                          }                          }
414                  }                  }
   
415          }          }
416    
417          /**          /**
# Line 519  public class MapPaneToolBar extends JToo Line 558  public class MapPaneToolBar extends JToo
558                          return;                          return;
559                  button.setSelected(true);                  button.setSelected(true);
560                  button.getAction().actionPerformed(null);                  button.getAction().actionPerformed(null);
561    
562                    selectedTool = tool;
563          }          }
564    
565          /**          /**
# Line 701  public class MapPaneToolBar extends JToo Line 742  public class MapPaneToolBar extends JToo
742                   */                   */
743                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
744                                  String name, Icon icon) {                                  String name, Icon icon) {
745                            this (id, toolBar, name, icon, null);
746                    }
747                    
748                    /**
749                     * Creates a new action.
750                     *
751                     * @param id
752                     *            unique ID for the action
753                     * @param toolBar
754                     *            The {@link MapPaneToolBar} this action is made for
755                     * @param name
756                     *            description used for buttons or menus
757                     * @param icon
758                     *            icon used for buttons or menus
759                     * @param toolTip
760                     *            Tooltip to use for the button or menu
761                     */
762                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
763                                    String name, Icon icon, String toolTip) {
764                          super(name, icon);                          super(name, icon);
765                            
766                            if (toolTip != null && !toolTip.trim().isEmpty()){
767                                    putValue(Action.SHORT_DESCRIPTION, toolTip);
768                            }
769                            
770                          this.id = id;                          this.id = id;
771                          this.toolBar = toolBar;                          this.toolBar = toolBar;
772                  }                  }

Legend:
Removed from v.140  
changed lines
  Added in v.152

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26