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 |
|
|
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 |
|
|
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). */ |
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)) |
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 |
|
|
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 |
|
|
412 |
mapPane.refresh(); |
mapPane.refresh(); |
413 |
} |
} |
414 |
} |
} |
|
|
|
415 |
} |
} |
416 |
|
|
417 |
/** |
/** |