/[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 151 by alfonx, Fri Jun 19 16:22:29 2009 UTC revision 180 by alfonx, Thu Jul 2 14:44:57 2009 UTC
# Line 1  Line 1 
1  package skrueger.geotools;  package skrueger.geotools;
2    
3    import java.awt.Color;
4  import java.awt.Dimension;  import java.awt.Dimension;
5    import java.awt.Graphics;
6  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
7  import java.util.ArrayList;  import java.util.ArrayList;
8    import java.util.Locale;
9  import java.util.SortedMap;  import java.util.SortedMap;
10  import java.util.TreeMap;  import java.util.TreeMap;
11    
# Line 23  import schmitzm.geotools.gui.JMapPane; Line 26  import schmitzm.geotools.gui.JMapPane;
26  import schmitzm.geotools.map.event.JMapPaneEvent;  import schmitzm.geotools.map.event.JMapPaneEvent;
27  import schmitzm.geotools.map.event.JMapPaneListener;  import schmitzm.geotools.map.event.JMapPaneListener;
28  import schmitzm.geotools.map.event.MapAreaChangedEvent;  import schmitzm.geotools.map.event.MapAreaChangedEvent;
29    import schmitzm.lang.LangUtil;
30    import schmitzm.lang.ResourceProvider;
31  import schmitzm.swing.ButtonGroup;  import schmitzm.swing.ButtonGroup;
32  import schmitzm.swing.SwingUtil;  import schmitzm.swing.SwingUtil;
33    
# Line 42  import com.vividsolutions.jts.geom.Envel Line 47  import com.vividsolutions.jts.geom.Envel
47  public class MapPaneToolBar extends JToolBar {  public class MapPaneToolBar extends JToolBar {
48          private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class          private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class
49                          .getName());                          .getName());
50            
51            public static ResourceProvider RESOURCE = new ResourceProvider(LangUtil
52                            .extendPackagePath(MapPaneToolBar.class,
53                                            "resource.locales.mapPaneToolbar"), Locale.ENGLISH);
54            
55            public static String R(String key, Object... values) {
56                    return RESOURCE.getString(key, values);
57            }
58    
59          /** Constant for the tool "Panning" (10). */          /** Constant for the tool "Panning" (10). */
60          public static final int TOOL_PAN = 10;          public static final int TOOL_PAN = 10;
61          /** Constant for the tool "Info" (20). */          /** Constant for the tool "Info" (20). */
# Line 126  public class MapPaneToolBar extends JToo Line 140  public class MapPaneToolBar extends JToo
140                  super("Control the map", JToolBar.HORIZONTAL);                  super("Control the map", JToolBar.HORIZONTAL);
141                  this.toolAndActionButtons = new TreeMap<Integer, JComponent>();                  this.toolAndActionButtons = new TreeMap<Integer, JComponent>();
142                  this.toolButtonGroup = new ButtonGroup();                  this.toolButtonGroup = new ButtonGroup();
143                  // Create a Listener to sniff the zooms on the JMapPane                  
144                    // Create a Listener to listen to the zooms on the JMapPane
145                  this.mapPaneListener = new JMapPaneListener() {                  this.mapPaneListener = new JMapPaneListener() {
146                          public void performMapPaneEvent(JMapPaneEvent e) {                          public void performMapPaneEvent(JMapPaneEvent e) {
147                                  if (!(e instanceof MapAreaChangedEvent))                                  if (!(e instanceof MapAreaChangedEvent))
# Line 137  public class MapPaneToolBar extends JToo Line 152  public class MapPaneToolBar extends JToo
152                                          return;                                          return;
153                                  }                                  }
154    
155                                  Envelope oldMapArea = ((MapAreaChangedEvent) e).getOldMapArea();                                  final MapAreaChangedEvent mapAreaChangedEvent = (MapAreaChangedEvent) e;
156                                    Envelope oldMapArea = mapAreaChangedEvent.getOldMapArea();
157                                    
158                                    final Envelope mapArea = mapAreaChangedEvent.getNewMapArea();
159                                    if (mapArea == null || mapArea.equals(oldMapArea) ) {
160                                            // If the MapArea didn't change... we don't want to register it as a zoom action.
161                                            return;
162                                    }
163                                    
164                                  if (lastZooms.size() == 0 && oldMapArea != null) {                                  if (lastZooms.size() == 0 && oldMapArea != null) {
165                                          lastZooms.add(oldMapArea);                                          lastZooms.add(oldMapArea);
166                                          zoomBackIndex = 1;                                          zoomBackIndex = 1;
167                                  }                                  }
   
                                 final Envelope mapArea = ((MapAreaChangedEvent) e)  
                                                 .getNewMapArea();  
168                                  if (mapArea == null)                                  if (mapArea == null)
169                                          return;                                          return;
170    
# Line 211  public class MapPaneToolBar extends JToo Line 231  public class MapPaneToolBar extends JToo
231          protected void initToolsAndActions() {          protected void initToolsAndActions() {
232                  // Panning                  // Panning
233                  addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon(
234                                  MapView.class.getResource("resource/icons/pan.png"))), false);                                  MapView.class.getResource("resource/icons/pan.png")), R("MapPaneButtons.Pan.TT")), false);
235                  // Info                  // Info
236                  addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon(
237                                  MapView.class.getResource("resource/icons/info.png"))), false);                                  MapView.class.getResource("resource/icons/info.png")),R("MapPaneButtons.Info.TT")), false);
238    
239                  // Zoom in                  // Zoom in
240                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon(
241                                  MapView.class.getResource("resource/icons/zoom_in.png"))),                                  MapView.class.getResource("resource/icons/zoom_in.png")), R("MapPaneButtons.ZoomIn.TT")),
242                                  false);                                  false);
243                  // Zoom out                  // Zoom out
244                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(                  addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon(
245                                  MapView.class.getResource("resource/icons/zoom_out.png"))),                                  MapView.class.getResource("resource/icons/zoom_out.png")), R("MapPaneButtons.ZoomOut.TT")),
246                                  false);                                  false);
247    
248                  // Action button to revert the last zoom                  // Action button to revert the last zoom
249                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",
250                                  new ImageIcon(MapView.class                                  new ImageIcon(MapView.class
251                                                  .getResource("resource/icons/zoom_back.png"))), false);                                                  .getResource("resource/icons/zoom_back.png")), R("MapPaneButtons.LastZoom.TT")), false);
252                  setButtonEnabled(ACTION_ZOOM_BACK, false);                  setButtonEnabled(ACTION_ZOOM_BACK, false);
253    
254                  // Action button to redo the last zoom                  // Action button to redo the last zoom
255                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "",                  addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "",
256                                  new ImageIcon(MapView.class                                  new ImageIcon(MapView.class
257                                                  .getResource("resource/icons/zoom_forward.png"))),                                                  .getResource("resource/icons/zoom_forward.png")), R("MapPaneButtons.NextZoom.TT")),
258                                  false);                                  false);
259                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);                  setButtonEnabled(ACTION_ZOOM_FORWARD, false);
260    
# Line 258  public class MapPaneToolBar extends JToo Line 278  public class MapPaneToolBar extends JToo
278                  for (JComponent b : toolAndActionButtons.values())                  for (JComponent b : toolAndActionButtons.values())
279                          add(b);                          add(b);
280    
                 repaint();  
   
281                  if (!toolAndActionButtons.containsKey(selectedTool)) {                  if (!toolAndActionButtons.containsKey(selectedTool)) {
282                          /**                          /**
283                           * This might be a bit specific, but IF selection buttons are                           * This might be a bit specific, but IF selection buttons are
# Line 276  public class MapPaneToolBar extends JToo Line 294  public class MapPaneToolBar extends JToo
294                          }                          }
295    
296                  }                  }
297                    
298                    revalidate();
299                    repaint();
300          }          }
301    
302          // Space between tool buttons and action buttons          // Space between tool buttons and action buttons
# Line 394  public class MapPaneToolBar extends JToo Line 415  public class MapPaneToolBar extends JToo
415                                  mapPane.refresh();                                  mapPane.refresh();
416                          }                          }
417                  }                  }
   
418          }          }
419    
420          /**          /**
# Line 777  public class MapPaneToolBar extends JToo Line 797  public class MapPaneToolBar extends JToo
797                          return id;                          return id;
798                  }                  }
799          }          }
800            
801              /**
802               * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht wird) wird. Dann werden wird der
803               * Hintergrund auf WEISS gesetzt.
804               *
805               * @author <a href="mailto:[email protected]">Stefan Alfons
806               *         Kr&uuml;ger</a>
807               */
808              @Override
809              public void print(Graphics g) {
810                  Color orig = getBackground();
811                  setBackground(Color.WHITE);
812                  // wrap in try/finally so that we always restore the state
813                  try {
814                      super.print(g);
815                  } finally {
816                      setBackground(orig);
817                  }
818              }
819  }  }

Legend:
Removed from v.151  
changed lines
  Added in v.180

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26