/[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 177 by alfonx, Wed Jul 1 15:02:39 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                    if (!toolAndActionButtons.containsKey(selectedTool)) {
280                            /**
281                             * This might be a bit specific, but IF selection buttons are
282                             * available, select one of them.. if not, select the INFO tool.
283                             */
284    
285                            if (toolAndActionButtons.containsKey(TOOL_SELECTION_SET)) {
286                                    setSelectedTool(TOOL_SELECTION_SET);
287                            } else if (toolAndActionButtons.containsKey(TOOL_INFO)) {
288                                    setSelectedTool(TOOL_INFO);
289                            } else {
290                                    // TODO What to do now?!
291                                    setSelectedTool(null);
292                            }
293    
294                    }
295                    
296                    revalidate();
297                    repaint();
298          }          }
299    
300          // Space between tool buttons and action buttons          // Space between tool buttons and action buttons
# Line 294  public class MapPaneToolBar extends JToo Line 333  public class MapPaneToolBar extends JToo
333                          // Set the mouse tool to "Info"                          // Set the mouse tool to "Info"
334                          mapPane.setWindowSelectionState(JMapPane.NONE);                          mapPane.setWindowSelectionState(JMapPane.NONE);
335                          mapPane.setState(JMapPane.SELECT_TOP); // Why not:                          mapPane.setState(JMapPane.SELECT_TOP); // Why not:
336                                                                                                          // JMapPane.SELECT_TOP_ONEONLY                          // JMapPane.SELECT_TOP_ONEONLY
337                          mapPane.setHighlight(false);// SK: Was true, but since it not works                          mapPane.setHighlight(false);// SK: Was true, but since it not works
338                                                                                  // properly removed it to save                          // properly removed it to save
339                                                                                  // performance                          // performance
340                          mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);                          mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR);
341                          break;                          break;
342                  case TOOL_ZOOMIN:                  case TOOL_ZOOMIN:
# Line 314  public class MapPaneToolBar extends JToo Line 353  public class MapPaneToolBar extends JToo
353                          mapPane.setHighlight(false);                          mapPane.setHighlight(false);
354                          mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);                          mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR);
355                          break;                          break;
356  //              default:                  default:
357  //                      // Set map actions to default                          // Set map actions to default
358  //                      mapPane.setWindowSelectionState(JMapPane.NONE);                          mapPane.setWindowSelectionState(JMapPane.NONE);
359  //                      mapPane.setState(JMapPane.NONE);                          mapPane.setState(JMapPane.NONE);
360  //                      mapPane.setHighlight(false);                          mapPane.setHighlight(false);
361  //                      mapPane.setNormalCursor(null);                          mapPane.setNormalCursor(null);
362  //                      break;                          break;
363                  }                  }
364                  mapPane.updateCursor();                  mapPane.updateCursor();
365          }          }
366            
367          /**          /**
368           * @param id The ID of the Component to remove           * @param id
369             *            The ID of the Component to remove. The change will not be
370             *            visible until {@link #initToolBar()} is called.
371           * @return <code>null</code> or the component that has been removed.           * @return <code>null</code> or the component that has been removed.
372           */           */
373          public JComponent removeId(int id){          public JComponent removeId(int id) {
374                  return toolAndActionButtons.remove(id);                  return toolAndActionButtons.remove(id);
375          }          }
376    
# Line 372  public class MapPaneToolBar extends JToo Line 413  public class MapPaneToolBar extends JToo
413                                  mapPane.refresh();                                  mapPane.refresh();
414                          }                          }
415                  }                  }
   
416          }          }
417    
418          /**          /**
# Line 519  public class MapPaneToolBar extends JToo Line 559  public class MapPaneToolBar extends JToo
559                          return;                          return;
560                  button.setSelected(true);                  button.setSelected(true);
561                  button.getAction().actionPerformed(null);                  button.getAction().actionPerformed(null);
562    
563                    selectedTool = tool;
564          }          }
565    
566          /**          /**
# Line 701  public class MapPaneToolBar extends JToo Line 743  public class MapPaneToolBar extends JToo
743                   */                   */
744                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,                  public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
745                                  String name, Icon icon) {                                  String name, Icon icon) {
746                            this (id, toolBar, name, icon, null);
747                    }
748                    
749                    /**
750                     * Creates a new action.
751                     *
752                     * @param id
753                     *            unique ID for the action
754                     * @param toolBar
755                     *            The {@link MapPaneToolBar} this action is made for
756                     * @param name
757                     *            description used for buttons or menus
758                     * @param icon
759                     *            icon used for buttons or menus
760                     * @param toolTip
761                     *            Tooltip to use for the button or menu
762                     */
763                    public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
764                                    String name, Icon icon, String toolTip) {
765                          super(name, icon);                          super(name, icon);
766                            
767                            if (toolTip != null && !toolTip.trim().isEmpty()){
768                                    putValue(Action.SHORT_DESCRIPTION, toolTip);
769                            }
770                            
771                          this.id = id;                          this.id = id;
772                          this.toolBar = toolBar;                          this.toolBar = toolBar;
773                  }                  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26