1 |
package skrueger.geotools; |
/******************************************************************************* |
2 |
|
* Copyright (c) 2009 Martin O. J. Schmitz. |
3 |
import java.awt.Color; |
* |
4 |
import java.awt.Dimension; |
* This file is part of the SCHMITZM library - a collection of utility |
5 |
import java.awt.Graphics; |
* classes based on Java 1.6, focussing (not only) on Java Swing |
6 |
import java.awt.event.ActionEvent; |
* and the Geotools library. |
7 |
import java.util.ArrayList; |
* |
8 |
import java.util.Locale; |
* The SCHMITZM project is hosted at: |
9 |
import java.util.SortedMap; |
* http://wald.intevation.org/projects/schmitzm/ |
10 |
import java.util.TreeMap; |
* |
11 |
|
* This program is free software; you can redistribute it and/or |
12 |
import javax.swing.AbstractAction; |
* modify it under the terms of the GNU Lesser General Public License |
13 |
import javax.swing.AbstractButton; |
* as published by the Free Software Foundation; either version 3 |
14 |
import javax.swing.Action; |
* of the License, or (at your option) any later version. |
15 |
import javax.swing.BorderFactory; |
* |
16 |
import javax.swing.Icon; |
* This program is distributed in the hope that it will be useful, |
17 |
import javax.swing.ImageIcon; |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 |
import javax.swing.JButton; |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 |
import javax.swing.JComponent; |
* GNU General Public License for more details. |
20 |
import javax.swing.JToggleButton; |
* |
21 |
import javax.swing.JToolBar; |
* You should have received a copy of the GNU Lesser General Public License (license.txt) |
22 |
|
* along with this program; if not, write to the Free Software |
23 |
import org.apache.log4j.Logger; |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
|
* or try this link: http://www.gnu.org/licenses/lgpl.html |
25 |
import schmitzm.geotools.gui.JMapPane; |
* |
26 |
import schmitzm.geotools.map.event.JMapPaneEvent; |
* Contributors: |
27 |
import schmitzm.geotools.map.event.JMapPaneListener; |
* Martin O. J. Schmitz - initial API and implementation |
28 |
import schmitzm.geotools.map.event.MapAreaChangedEvent; |
* Stefan A. Krüger - additional utility classes |
29 |
import schmitzm.lang.LangUtil; |
******************************************************************************/ |
30 |
import schmitzm.lang.ResourceProvider; |
package skrueger.geotools; |
31 |
import schmitzm.swing.ButtonGroup; |
|
32 |
import schmitzm.swing.SwingUtil; |
import java.awt.Color; |
33 |
|
import java.awt.Dimension; |
34 |
import com.vividsolutions.jts.geom.Envelope; |
import java.awt.Graphics; |
35 |
|
import java.awt.event.ActionEvent; |
36 |
/** |
import java.util.ArrayList; |
37 |
* A toolbar to control an {@link JMapPane} (Atlas visualization). This contains |
import java.util.Locale; |
38 |
* two types of buttons. A group of <i>tools</i> for the mouse actions on the |
import java.util.SortedMap; |
39 |
* map represented by {@link JToggleButton JToggleButtons}, where only one tool |
import java.util.TreeMap; |
40 |
* can be activated every time. And some (general) <i>actions</i>, represented |
|
41 |
* by normal {@link JButton JButtons}. |
import javax.swing.AbstractAction; |
42 |
* |
import javax.swing.AbstractButton; |
43 |
* @author <a href="mailto:[email protected]">Martin Schmitz</a> |
import javax.swing.Action; |
44 |
* (University of Bonn/Germany) |
import javax.swing.BorderFactory; |
45 |
* @version 1.2 Stefan Krüger |
import javax.swing.Icon; |
46 |
*/ |
import javax.swing.ImageIcon; |
47 |
public class MapPaneToolBar extends JToolBar { |
import javax.swing.JButton; |
48 |
private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class |
import javax.swing.JComponent; |
49 |
.getName()); |
import javax.swing.JToggleButton; |
50 |
|
import javax.swing.JToolBar; |
51 |
public static ResourceProvider RESOURCE = new ResourceProvider(LangUtil |
|
52 |
.extendPackagePath(MapPaneToolBar.class, |
import org.apache.log4j.Logger; |
53 |
"resource.locales.mapPaneToolbar"), Locale.ENGLISH); |
|
54 |
|
import schmitzm.geotools.gui.JMapPane; |
55 |
public static String R(String key, Object... values) { |
import schmitzm.geotools.map.event.JMapPaneEvent; |
56 |
return RESOURCE.getString(key, values); |
import schmitzm.geotools.map.event.JMapPaneListener; |
57 |
} |
import schmitzm.geotools.map.event.MapAreaChangedEvent; |
58 |
|
import schmitzm.lang.LangUtil; |
59 |
/** Constant for the tool "Panning" (10). */ |
import schmitzm.lang.ResourceProvider; |
60 |
public static final int TOOL_PAN = 10; |
import schmitzm.swing.ButtonGroup; |
61 |
/** Constant for the tool "Info" (20). */ |
import schmitzm.swing.SwingUtil; |
62 |
public static final int TOOL_INFO = 20; |
|
63 |
public static final int SEPERATOR0 = 99; |
import com.vividsolutions.jts.geom.Envelope; |
64 |
|
|
65 |
/** Constant for the tool "Zoom In" (110). */ |
/** |
66 |
public static final int TOOL_ZOOMIN = 110; |
* A toolbar to control an {@link JMapPane} (Atlas visualization). This contains |
67 |
/** Constant for the tool "Zoom Out" (120). */ |
* two types of buttons. A group of <i>tools</i> for the mouse actions on the |
68 |
public static final int TOOL_ZOOMOUT = 120; |
* map represented by {@link JToggleButton JToggleButtons}, where only one tool |
69 |
/** Constant for the action "Zoom back" (130). */ |
* can be activated every time. And some (general) <i>actions</i>, represented |
70 |
public static final int ACTION_ZOOM_BACK = 130; |
* by normal {@link JButton JButtons}. |
71 |
/** Constant for the action "Zoom forward" (140). */ |
* |
72 |
public static final int ACTION_ZOOM_FORWARD = 140; |
* @author <a href="mailto:[email protected]">Martin Schmitz</a> |
73 |
public static final int SEPERATOR1 = 199; |
* (University of Bonn/Germany) |
74 |
|
* @version 1.2 Stefan Krüger |
75 |
/** |
*/ |
76 |
* Constant for the tool "Selection Reset" which clears the selection (240). |
public class MapPaneToolBar extends JToolBar { |
77 |
*/ |
private static final Logger LOGGER = Logger.getLogger(MapPaneToolBar.class |
78 |
public static final int TOOL_SELECTION_CLEAR = 240; |
.getName()); |
79 |
|
|
80 |
/** |
public static ResourceProvider RESOURCE = new ResourceProvider(LangUtil |
81 |
* Constant for the tool "Select" which sets the Selection to the selected |
.extendPackagePath(MapPaneToolBar.class, |
82 |
* features (210). |
"resource.locales.mapPaneToolbar"), Locale.ENGLISH); |
83 |
*/ |
|
84 |
public static final int TOOL_SELECTION_SET = 210; |
public static String R(String key, Object... values) { |
85 |
/** |
return RESOURCE.getString(key, values); |
86 |
* Constant for the tool "Selection add" which adds the features to the |
} |
87 |
* Selection (220). |
|
88 |
*/ |
/** Constant for the tool "Panning" (10). */ |
89 |
public static final int TOOL_SELECTION_ADD = 220; |
public static final int TOOL_PAN = 10; |
90 |
/** |
/** Constant for the tool "Info" (20). */ |
91 |
* Constant for the tool "Selection subtract" which removes the selected |
public static final int TOOL_INFO = 20; |
92 |
* features from the selection (230). |
public static final int SEPERATOR0 = 99; |
93 |
*/ |
|
94 |
public static final int TOOL_SELECTION_REMOVE = 230; |
/** Constant for the tool "Zoom In" (110). */ |
95 |
|
public static final int TOOL_ZOOMIN = 110; |
96 |
/** Tool currently selected */ |
/** Constant for the tool "Zoom Out" (120). */ |
97 |
protected int selectedTool = TOOL_ZOOMIN; |
public static final int TOOL_ZOOMOUT = 120; |
98 |
|
/** Constant for the action "Zoom back" (130). */ |
99 |
/** Holds the tool buttons of the tool bar. */ |
public static final int ACTION_ZOOM_BACK = 130; |
100 |
protected SortedMap<Integer, JComponent> toolAndActionButtons = null; |
/** Constant for the action "Zoom forward" (140). */ |
101 |
/** Controls that only one tool button is activated. */ |
public static final int ACTION_ZOOM_FORWARD = 140; |
102 |
protected ButtonGroup toolButtonGroup = null; |
public static final int SEPERATOR1 = 199; |
103 |
|
|
104 |
// SK: Musste ich ändern damit man Tools und Actions in der Reihenfolge |
/** |
105 |
// mischen kann. |
* Constant for the tool "Selection Reset" which clears the selection (240). |
106 |
// /** Holds the action buttons of the bar. */ |
*/ |
107 |
// protected SortedMap<Integer, JButton> actionButtons = null; |
public static final int TOOL_SELECTION_CLEAR = 240; |
108 |
|
|
109 |
/** Holds the {@link JMapPane} this tool bar controls. */ |
/** |
110 |
protected JMapPane mapPane = null; |
* Constant for the tool "Select" which sets the Selection to the selected |
111 |
|
* features (210). |
112 |
/** |
*/ |
113 |
* A List to remember the last Envelopes that have been watched. Used for |
public static final int TOOL_SELECTION_SET = 210; |
114 |
* the zoomBack- and zoomForwardButtons * |
/** |
115 |
*/ |
* Constant for the tool "Selection add" which adds the features to the |
116 |
protected ArrayList<Envelope> lastZooms = new ArrayList<Envelope>(); |
* Selection (220). |
117 |
/** Holds the index to the current element in {@link #lastZooms}. */ |
*/ |
118 |
protected int zoomBackIndex = 0; |
public static final int TOOL_SELECTION_ADD = 220; |
119 |
|
/** |
120 |
/** Listener to sniff the zoom actions on the map. */ |
* Constant for the tool "Selection subtract" which removes the selected |
121 |
protected JMapPaneListener mapPaneListener = null; |
* features from the selection (230). |
122 |
|
*/ |
123 |
protected boolean zoomBackForwardButtonInAction; |
public static final int TOOL_SELECTION_REMOVE = 230; |
124 |
|
|
125 |
/** |
/** Tool currently selected */ |
126 |
* Creates a new toolbar. Notice: This toolbar does nothing until |
protected int selectedTool = TOOL_ZOOMIN; |
127 |
* {@link #setMapPane(JMapPane)} is called! |
|
128 |
*/ |
/** Holds the tool buttons of the tool bar. */ |
129 |
public MapPaneToolBar() { |
protected SortedMap<Integer, JComponent> toolAndActionButtons = null; |
130 |
this(null); |
/** Controls that only one tool button is activated. */ |
131 |
} |
protected ButtonGroup toolButtonGroup = null; |
132 |
|
|
133 |
/** |
// SK: Musste ich ändern damit man Tools und Actions in der Reihenfolge |
134 |
* Creates a new tool bar. |
// mischen kann. |
135 |
* |
// /** Holds the action buttons of the bar. */ |
136 |
* @param mapPane |
// protected SortedMap<Integer, JButton> actionButtons = null; |
137 |
* {@link JMapPane} the tool bar controls |
|
138 |
*/ |
/** Holds the {@link JMapPane} this tool bar controls. */ |
139 |
public MapPaneToolBar(JMapPane mapPane) { |
protected JMapPane mapPane = null; |
140 |
super("Control the map", JToolBar.HORIZONTAL); |
|
141 |
this.toolAndActionButtons = new TreeMap<Integer, JComponent>(); |
/** |
142 |
this.toolButtonGroup = new ButtonGroup(); |
* A List to remember the last Envelopes that have been watched. Used for |
143 |
|
* the zoomBack- and zoomForwardButtons * |
144 |
// Create a Listener to listen to the zooms on the JMapPane |
*/ |
145 |
this.mapPaneListener = new JMapPaneListener() { |
protected ArrayList<Envelope> lastZooms = new ArrayList<Envelope>(); |
146 |
public void performMapPaneEvent(JMapPaneEvent e) { |
/** Holds the index to the current element in {@link #lastZooms}. */ |
147 |
if (!(e instanceof MapAreaChangedEvent)) |
protected int zoomBackIndex = 0; |
148 |
return; |
|
149 |
|
/** Listener to sniff the zoom actions on the map. */ |
150 |
if (zoomBackForwardButtonInAction) { |
protected JMapPaneListener mapPaneListener = null; |
151 |
zoomBackForwardButtonInAction = false; |
|
152 |
return; |
protected boolean zoomBackForwardButtonInAction; |
153 |
} |
|
154 |
|
/** |
155 |
final MapAreaChangedEvent mapAreaChangedEvent = (MapAreaChangedEvent) e; |
* Creates a new toolbar. Notice: This toolbar does nothing until |
156 |
Envelope oldMapArea = mapAreaChangedEvent.getOldMapArea(); |
* {@link #setMapPane(JMapPane)} is called! |
157 |
|
*/ |
158 |
final Envelope mapArea = mapAreaChangedEvent.getNewMapArea(); |
public MapPaneToolBar() { |
159 |
if (mapArea == null || mapArea.equals(oldMapArea) ) { |
this(null); |
160 |
// If the MapArea didn't change... we don't want to register it as a zoom action. |
} |
161 |
return; |
|
162 |
} |
/** |
163 |
|
* Creates a new tool bar. |
164 |
if (lastZooms.size() == 0 && oldMapArea != null) { |
* |
165 |
lastZooms.add(oldMapArea); |
* @param mapPane |
166 |
zoomBackIndex = 1; |
* {@link JMapPane} the tool bar controls |
167 |
} |
*/ |
168 |
if (mapArea == null) |
public MapPaneToolBar(JMapPane mapPane) { |
169 |
return; |
super("Control the map", JToolBar.HORIZONTAL); |
170 |
|
this.toolAndActionButtons = new TreeMap<Integer, JComponent>(); |
171 |
if (lastZooms.size() > 0 |
this.toolButtonGroup = new ButtonGroup(); |
172 |
&& mapArea.equals(lastZooms.get(lastZooms.size() - 1))) { |
|
173 |
// LOGGER.debug("MapAreaChangedEvent ausgelassen bei der Zaehlung der Zoomschritt weil identisch"); |
// Create a Listener to listen to the zooms on the JMapPane |
174 |
return; |
this.mapPaneListener = new JMapPaneListener() { |
175 |
} |
public void performMapPaneEvent(JMapPaneEvent e) { |
176 |
|
if (!(e instanceof MapAreaChangedEvent)) |
177 |
if (lastZooms.size() > 0) |
return; |
178 |
while (zoomBackIndex < lastZooms.size()) |
|
179 |
lastZooms.remove(lastZooms.size() - 1); |
if (zoomBackForwardButtonInAction) { |
180 |
|
zoomBackForwardButtonInAction = false; |
181 |
lastZooms.add(mapArea); |
return; |
182 |
zoomBackIndex = lastZooms.size(); |
} |
183 |
setButtonEnabled(ACTION_ZOOM_BACK, lastZooms.size() > 1); |
|
184 |
setButtonEnabled(ACTION_ZOOM_FORWARD, false); |
final MapAreaChangedEvent mapAreaChangedEvent = (MapAreaChangedEvent) e; |
185 |
} |
Envelope oldMapArea = mapAreaChangedEvent.getOldMapArea(); |
186 |
}; |
|
187 |
|
final Envelope mapArea = mapAreaChangedEvent.getNewMapArea(); |
188 |
setMapPane(mapPane); |
if (mapArea == null || mapArea.equals(oldMapArea) ) { |
189 |
setFloatable(false); |
// If the MapArea didn't change... we don't want to register it as a zoom action. |
190 |
setRollover(true); |
return; |
191 |
|
} |
192 |
init(); |
|
193 |
} |
if (lastZooms.size() == 0 && oldMapArea != null) { |
194 |
|
lastZooms.add(oldMapArea); |
195 |
/** |
zoomBackIndex = 1; |
196 |
* Sets the {@link JMapPane} controlled by this tool bar. |
} |
197 |
* |
if (mapArea == null) |
198 |
* @param mapPane |
return; |
199 |
* {@link JMapPane} to control (if {@code null} this tool bar |
|
200 |
* controls NOTHING!) |
if (lastZooms.size() > 0 |
201 |
*/ |
&& mapArea.equals(lastZooms.get(lastZooms.size() - 1))) { |
202 |
public void setMapPane(JMapPane mapPane) { |
// LOGGER.debug("MapAreaChangedEvent ausgelassen bei der Zaehlung der Zoomschritt weil identisch"); |
203 |
// Remove listener from old MapPane |
return; |
204 |
if (this.mapPane != null) |
} |
205 |
this.mapPane.removeMapPaneListener(mapPaneListener); |
|
206 |
this.mapPane = mapPane; |
if (lastZooms.size() > 0) |
207 |
if (this.mapPane != null && mapPaneListener != null) |
while (zoomBackIndex < lastZooms.size()) |
208 |
this.mapPane.addMapPaneListener(mapPaneListener); |
lastZooms.remove(lastZooms.size() - 1); |
209 |
} |
|
210 |
|
lastZooms.add(mapArea); |
211 |
/** |
zoomBackIndex = lastZooms.size(); |
212 |
* Calls {@link #initToolsAndActions()} and {@link #initActions()} and then |
setButtonEnabled(ACTION_ZOOM_BACK, lastZooms.size() > 1); |
213 |
* puts all tool buttons and all actions buttons to the tool bar. |
setButtonEnabled(ACTION_ZOOM_FORWARD, false); |
214 |
*/ |
} |
215 |
protected void init() { |
}; |
216 |
initToolsAndActions(); |
|
217 |
|
setMapPane(mapPane); |
218 |
addSeparator(SEPERATOR0, new JToolBar.Separator()); |
setFloatable(false); |
219 |
addSeparator(SEPERATOR1, new JToolBar.Separator()); |
setRollover(true); |
220 |
|
|
221 |
initToolBar(); |
init(); |
222 |
} |
} |
223 |
|
|
224 |
/** |
/** |
225 |
* Creates the tool buttons and action buttons and seperators, adds them to |
* Sets the {@link JMapPane} controlled by this tool bar. |
226 |
* {@link #toolAndActionButtons} and finally creates a button group for all |
* |
227 |
* tools. So sub-classes which override this method should FIRST add their |
* @param mapPane |
228 |
* new tool buttons to {@link #toolAndActionButtons} before calling {@code |
* {@link JMapPane} to control (if {@code null} this tool bar |
229 |
* super.initTools()}. |
* controls NOTHING!) |
230 |
*/ |
*/ |
231 |
protected void initToolsAndActions() { |
public void setMapPane(JMapPane mapPane) { |
232 |
// Panning |
// Remove listener from old MapPane |
233 |
addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon( |
if (this.mapPane != null) |
234 |
MapView.class.getResource("resource/icons/pan.png")), R("MapPaneButtons.Pan.TT")), false); |
this.mapPane.removeMapPaneListener(mapPaneListener); |
235 |
// Info |
this.mapPane = mapPane; |
236 |
addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon( |
if (this.mapPane != null && mapPaneListener != null) |
237 |
MapView.class.getResource("resource/icons/info.png")),R("MapPaneButtons.Info.TT")), false); |
this.mapPane.addMapPaneListener(mapPaneListener); |
238 |
|
} |
239 |
// Zoom in |
|
240 |
addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon( |
/** |
241 |
MapView.class.getResource("resource/icons/zoom_in.png")), R("MapPaneButtons.ZoomIn.TT")), |
* Calls {@link #initToolsAndActions()} and {@link #initActions()} and then |
242 |
false); |
* puts all tool buttons and all actions buttons to the tool bar. |
243 |
// Zoom out |
*/ |
244 |
addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon( |
protected void init() { |
245 |
MapView.class.getResource("resource/icons/zoom_out.png")), R("MapPaneButtons.ZoomOut.TT")), |
initToolsAndActions(); |
246 |
false); |
|
247 |
|
addSeparator(SEPERATOR0, new JToolBar.Separator()); |
248 |
// Action button to revert the last zoom |
addSeparator(SEPERATOR1, new JToolBar.Separator()); |
249 |
addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "", |
|
250 |
new ImageIcon(MapView.class |
initToolBar(); |
251 |
.getResource("resource/icons/zoom_back.png")), R("MapPaneButtons.LastZoom.TT")), false); |
} |
252 |
setButtonEnabled(ACTION_ZOOM_BACK, false); |
|
253 |
|
/** |
254 |
// Action button to redo the last zoom |
* Creates the tool buttons and action buttons and seperators, adds them to |
255 |
addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "", |
* {@link #toolAndActionButtons} and finally creates a button group for all |
256 |
new ImageIcon(MapView.class |
* tools. So sub-classes which override this method should FIRST add their |
257 |
.getResource("resource/icons/zoom_forward.png")), R("MapPaneButtons.NextZoom.TT")), |
* new tool buttons to {@link #toolAndActionButtons} before calling {@code |
258 |
false); |
* super.initTools()}. |
259 |
setButtonEnabled(ACTION_ZOOM_FORWARD, false); |
*/ |
260 |
|
protected void initToolsAndActions() { |
261 |
// set the selected tool enabled |
// Panning |
262 |
setSelectedTool(selectedTool); |
addTool(new MapPaneToolBarAction(TOOL_PAN, this, "", new ImageIcon( |
263 |
|
MapView.class.getResource("resource/icons/pan.png")), R("MapPaneButtons.Pan.TT")), false); |
264 |
} |
// Info |
265 |
|
addTool(new MapPaneToolBarAction(TOOL_INFO, this, "", new ImageIcon( |
266 |
/** |
MapView.class.getResource("resource/icons/info.png")),R("MapPaneButtons.Info.TT")), false); |
267 |
* Clears the GUI of all components and adds all tool and action buttons to |
|
268 |
* the tool bar. |
// Zoom in |
269 |
*/ |
addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, "", new ImageIcon( |
270 |
public void initToolBar() { |
MapView.class.getResource("resource/icons/zoom_in.png")), R("MapPaneButtons.ZoomIn.TT")), |
271 |
setAlignmentY(1f); |
false); |
272 |
removeAll(); |
// Zoom out |
273 |
// Separator to the left of the tool actions to start |
addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, "", new ImageIcon( |
274 |
// the tool buttons with the map (not with the coordinate grid) |
MapView.class.getResource("resource/icons/zoom_out.png")), R("MapPaneButtons.ZoomOut.TT")), |
275 |
Dimension dimension = new Dimension(49, 10); |
false); |
276 |
addSeparator(dimension); |
|
277 |
// Tool buttons |
// Action button to revert the last zoom |
278 |
for (JComponent b : toolAndActionButtons.values()) |
addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "", |
279 |
add(b); |
new ImageIcon(MapView.class |
280 |
|
.getResource("resource/icons/zoom_back.png")), R("MapPaneButtons.LastZoom.TT")), false); |
281 |
if (!toolAndActionButtons.containsKey(selectedTool)) { |
setButtonEnabled(ACTION_ZOOM_BACK, false); |
282 |
/** |
|
283 |
* This might be a bit specific, but IF selection buttons are |
// Action button to redo the last zoom |
284 |
* available, select one of them.. if not, select the INFO tool. |
addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "", |
285 |
*/ |
new ImageIcon(MapView.class |
286 |
|
.getResource("resource/icons/zoom_forward.png")), R("MapPaneButtons.NextZoom.TT")), |
287 |
if (toolAndActionButtons.containsKey(TOOL_SELECTION_SET)) { |
false); |
288 |
setSelectedTool(TOOL_SELECTION_SET); |
setButtonEnabled(ACTION_ZOOM_FORWARD, false); |
289 |
} else if (toolAndActionButtons.containsKey(TOOL_INFO)) { |
|
290 |
setSelectedTool(TOOL_INFO); |
// set the selected tool enabled |
291 |
} else { |
setSelectedTool(selectedTool); |
292 |
// TODO What to do now?! |
|
293 |
setSelectedTool(null); |
} |
294 |
} |
|
295 |
|
/** |
296 |
} |
* Clears the GUI of all components and adds all tool and action buttons to |
297 |
|
* the tool bar. |
298 |
revalidate(); |
*/ |
299 |
repaint(); |
public void initToolBar() { |
300 |
} |
setAlignmentY(1f); |
301 |
|
removeAll(); |
302 |
// Space between tool buttons and action buttons |
// Separator to the left of the tool actions to start |
303 |
// SK: Seperators are now als manages like actions and tools |
// the tool buttons with the map (not with the coordinate grid) |
304 |
// Dimension dimension2 = new Dimension( 10,10); |
Dimension dimension = new Dimension(49, 10); |
305 |
// this.addSeparator(dimension2); |
addSeparator(dimension); |
306 |
|
// Tool buttons |
307 |
// // Action buttons |
for (JComponent b : toolAndActionButtons.values()) |
308 |
// for (JButton b : actionButtons.values()) |
add(b); |
309 |
// add(b); |
|
310 |
// } |
if (!toolAndActionButtons.containsKey(selectedTool)) { |
311 |
|
/** |
312 |
/** |
* This might be a bit specific, but IF selection buttons are |
313 |
* Performs the activation of a tool. |
* available, select one of them.. if not, select the INFO tool. |
314 |
* |
*/ |
315 |
* @param tool |
|
316 |
* the tool to activate |
if (toolAndActionButtons.containsKey(TOOL_SELECTION_SET)) { |
317 |
* @param e |
setSelectedTool(TOOL_SELECTION_SET); |
318 |
* the event of the button |
} else if (toolAndActionButtons.containsKey(TOOL_INFO)) { |
319 |
*/ |
setSelectedTool(TOOL_INFO); |
320 |
public void performToolButton(int tool, ActionEvent e) { |
} else { |
321 |
if (mapPane == null) |
// TODO What to do now?! |
322 |
return; |
setSelectedTool(null); |
323 |
|
} |
324 |
selectedTool = tool; |
|
325 |
|
} |
326 |
switch (tool) { |
|
327 |
case TOOL_PAN: |
revalidate(); |
328 |
// Set the mouse tool to "Panning" |
repaint(); |
329 |
mapPane.setWindowSelectionState(JMapPane.NONE); |
} |
330 |
mapPane.setState(JMapPane.PAN); |
|
331 |
mapPane.setHighlight(false); |
// Space between tool buttons and action buttons |
332 |
mapPane.setNormalCursor(SwingUtil.PAN_CURSOR); |
// SK: Seperators are now als manages like actions and tools |
333 |
break; |
// Dimension dimension2 = new Dimension( 10,10); |
334 |
case TOOL_INFO: |
// this.addSeparator(dimension2); |
335 |
// Set the mouse tool to "Info" |
|
336 |
mapPane.setWindowSelectionState(JMapPane.NONE); |
// // Action buttons |
337 |
mapPane.setState(JMapPane.SELECT_TOP); // Why not: |
// for (JButton b : actionButtons.values()) |
338 |
// JMapPane.SELECT_TOP_ONEONLY |
// add(b); |
339 |
mapPane.setHighlight(false);// SK: Was true, but since it not works |
// } |
340 |
// properly removed it to save |
|
341 |
// performance |
/** |
342 |
mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR); |
* Performs the activation of a tool. |
343 |
break; |
* |
344 |
case TOOL_ZOOMIN: |
* @param tool |
345 |
// Set the mouse tool to "Zoom in" |
* the tool to activate |
346 |
mapPane.setWindowSelectionState(JMapPane.ZOOM_IN); |
* @param e |
347 |
mapPane.setState(JMapPane.ZOOM_IN); |
* the event of the button |
348 |
mapPane.setHighlight(false); |
*/ |
349 |
mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR); |
public void performToolButton(int tool, ActionEvent e) { |
350 |
break; |
if (mapPane == null) |
351 |
case TOOL_ZOOMOUT: |
return; |
352 |
// Set the mouse tool to "Zoom out" |
|
353 |
mapPane.setWindowSelectionState(JMapPane.NONE); |
selectedTool = tool; |
354 |
mapPane.setState(JMapPane.ZOOM_OUT); |
|
355 |
mapPane.setHighlight(false); |
switch (tool) { |
356 |
mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR); |
case TOOL_PAN: |
357 |
break; |
// Set the mouse tool to "Panning" |
358 |
default: |
mapPane.setWindowSelectionState(JMapPane.NONE); |
359 |
// Set map actions to default |
mapPane.setState(JMapPane.PAN); |
360 |
mapPane.setWindowSelectionState(JMapPane.NONE); |
mapPane.setHighlight(false); |
361 |
mapPane.setState(JMapPane.NONE); |
mapPane.setNormalCursor(SwingUtil.PAN_CURSOR); |
362 |
mapPane.setHighlight(false); |
break; |
363 |
mapPane.setNormalCursor(null); |
case TOOL_INFO: |
364 |
break; |
// Set the mouse tool to "Info" |
365 |
} |
mapPane.setWindowSelectionState(JMapPane.NONE); |
366 |
mapPane.updateCursor(); |
mapPane.setState(JMapPane.SELECT_TOP); // Why not: |
367 |
} |
// JMapPane.SELECT_TOP_ONEONLY |
368 |
|
mapPane.setHighlight(false);// SK: Was true, but since it not works |
369 |
/** |
// properly removed it to save |
370 |
* @param id |
// performance |
371 |
* The ID of the Component to remove. The change will not be |
mapPane.setNormalCursor(SwingUtil.CROSSHAIR_CURSOR); |
372 |
* visible until {@link #initToolBar()} is called. |
break; |
373 |
* @return <code>null</code> or the component that has been removed. |
case TOOL_ZOOMIN: |
374 |
*/ |
// Set the mouse tool to "Zoom in" |
375 |
public JComponent removeId(int id) { |
mapPane.setWindowSelectionState(JMapPane.ZOOM_IN); |
376 |
return toolAndActionButtons.remove(id); |
mapPane.setState(JMapPane.ZOOM_IN); |
377 |
} |
mapPane.setHighlight(false); |
378 |
|
mapPane.setNormalCursor(SwingUtil.ZOOMIN_CURSOR); |
379 |
/** |
break; |
380 |
* Performs the action of an action button. |
case TOOL_ZOOMOUT: |
381 |
* |
// Set the mouse tool to "Zoom out" |
382 |
* @param tool |
mapPane.setWindowSelectionState(JMapPane.NONE); |
383 |
* the action |
mapPane.setState(JMapPane.ZOOM_OUT); |
384 |
* @param e |
mapPane.setHighlight(false); |
385 |
* the event of the button |
mapPane.setNormalCursor(SwingUtil.ZOOMOUT_CURSOR); |
386 |
*/ |
break; |
387 |
protected void performActionButton(int action, ActionEvent e) { |
default: |
388 |
if (mapPane == null) |
// Set map actions to default |
389 |
return; |
mapPane.setWindowSelectionState(JMapPane.NONE); |
390 |
|
mapPane.setState(JMapPane.NONE); |
391 |
// Perform the action "Zoom back": Revert the last zoom |
mapPane.setHighlight(false); |
392 |
if (action == ACTION_ZOOM_BACK) { |
mapPane.setNormalCursor(null); |
393 |
if (zoomBackIndex <= 1) |
break; |
394 |
return; |
} |
395 |
|
mapPane.updateCursor(); |
396 |
zoomBackForwardButtonInAction = true; |
} |
397 |
zoomBackIndex--; |
|
398 |
getButton(ACTION_ZOOM_FORWARD).setEnabled(true); |
/** |
399 |
getButton(ACTION_ZOOM_BACK).setEnabled(zoomBackIndex > 1); |
* @param id |
400 |
|
* The ID of the Component to remove. The change will not be |
401 |
mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1)); |
* visible until {@link #initToolBar()} is called. |
402 |
mapPane.refresh(); |
* @return <code>null</code> or the component that has been removed. |
403 |
} |
*/ |
404 |
|
public JComponent removeId(int id) { |
405 |
// Perform the action "Zoom forward": Re-do the last zoom |
return toolAndActionButtons.remove(id); |
406 |
if (action == ACTION_ZOOM_FORWARD) { |
} |
407 |
if (zoomBackIndex < lastZooms.size()) { |
|
408 |
zoomBackForwardButtonInAction = true; |
/** |
409 |
zoomBackIndex++; |
* Performs the action of an action button. |
410 |
getButton(ACTION_ZOOM_BACK).setEnabled(true); |
* |
411 |
getButton(ACTION_ZOOM_FORWARD).setEnabled( |
* @param tool |
412 |
zoomBackIndex < lastZooms.size()); |
* the action |
413 |
|
* @param e |
414 |
mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1)); |
* the event of the button |
415 |
mapPane.refresh(); |
*/ |
416 |
} |
protected void performActionButton(int action, ActionEvent e) { |
417 |
} |
if (mapPane == null) |
418 |
} |
return; |
419 |
|
|
420 |
/** |
// Perform the action "Zoom back": Revert the last zoom |
421 |
* Adds a tool to the tool bar. Does nothing if a tool or action with the |
if (action == ACTION_ZOOM_BACK) { |
422 |
* specified ID already exists! |
if (zoomBackIndex <= 1) |
423 |
* |
return; |
424 |
* @param buttonAction |
|
425 |
* action for the toggle button |
zoomBackForwardButtonInAction = true; |
426 |
* @param resetToolBar |
zoomBackIndex--; |
427 |
* indicates whether the toolbar GUI is reset after adding the |
getButton(ACTION_ZOOM_FORWARD).setEnabled(true); |
428 |
* button (if adding several actions it useful only to reset the |
getButton(ACTION_ZOOM_BACK).setEnabled(zoomBackIndex > 1); |
429 |
* GUI for the last added tool) |
|
430 |
*/ |
mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1)); |
431 |
public void addTool(MapPaneToolBarAction buttonAction, boolean resetToolBar) { |
mapPane.refresh(); |
432 |
if (isButtonIDUsed(buttonAction.getID())) { |
} |
433 |
LOGGER |
|
434 |
.warn("addTool(.) ignored because ID already used for tool or action: " |
// Perform the action "Zoom forward": Re-do the last zoom |
435 |
+ buttonAction.getID()); |
if (action == ACTION_ZOOM_FORWARD) { |
436 |
return; |
if (zoomBackIndex < lastZooms.size()) { |
437 |
} |
zoomBackForwardButtonInAction = true; |
438 |
JToggleButton button = new JToggleButton(buttonAction); |
zoomBackIndex++; |
439 |
button.setBorder(BorderFactory.createRaisedBevelBorder()); |
getButton(ACTION_ZOOM_BACK).setEnabled(true); |
440 |
toolButtonGroup.add(button); |
getButton(ACTION_ZOOM_FORWARD).setEnabled( |
441 |
toolAndActionButtons.put(buttonAction.getID(), button); |
zoomBackIndex < lastZooms.size()); |
442 |
if (resetToolBar) |
|
443 |
initToolBar(); |
mapPane.setMapArea(lastZooms.get(zoomBackIndex - 1)); |
444 |
} |
mapPane.refresh(); |
445 |
|
} |
446 |
/** |
} |
447 |
* Adds a tool to the tool bar and resets the toolbar GUI. |
} |
448 |
* |
|
449 |
* @param buttonAction |
/** |
450 |
* action for the toggle button |
* Adds a tool to the tool bar. Does nothing if a tool or action with the |
451 |
*/ |
* specified ID already exists! |
452 |
public void addTool(MapPaneToolBarAction buttonAction) { |
* |
453 |
addTool(buttonAction, true); |
* @param buttonAction |
454 |
} |
* action for the toggle button |
455 |
|
* @param resetToolBar |
456 |
/** |
* indicates whether the toolbar GUI is reset after adding the |
457 |
* Adds an action to the tool bar. Does nothing if a tool or action with the |
* button (if adding several actions it useful only to reset the |
458 |
* specified ID already exists! |
* GUI for the last added tool) |
459 |
* |
*/ |
460 |
* @param buttonAction |
public void addTool(MapPaneToolBarAction buttonAction, boolean resetToolBar) { |
461 |
* action for the button |
if (isButtonIDUsed(buttonAction.getID())) { |
462 |
* @param resetToolBar |
LOGGER |
463 |
* indicates whether the toolbar GUI is reset after adding the |
.warn("addTool(.) ignored because ID already used for tool or action: " |
464 |
* button (if adding several actions it useful only to reset the |
+ buttonAction.getID()); |
465 |
* GUI for the last added tool) |
return; |
466 |
*/ |
} |
467 |
public void addAction(MapPaneToolBarAction buttonAction, |
JToggleButton button = new JToggleButton(buttonAction); |
468 |
boolean resetToolBar) { |
button.setBorder(BorderFactory.createRaisedBevelBorder()); |
469 |
if (isButtonIDUsed(buttonAction.getID())) { |
toolButtonGroup.add(button); |
470 |
LOGGER |
toolAndActionButtons.put(buttonAction.getID(), button); |
471 |
.warn("addAction(.) ignored because ID already used for tool or action: " |
if (resetToolBar) |
472 |
+ buttonAction.getID()); |
initToolBar(); |
473 |
return; |
} |
474 |
} |
|
475 |
JButton button = new JButton(buttonAction); |
/** |
476 |
button.setBorder(BorderFactory.createRaisedBevelBorder()); |
* Adds a tool to the tool bar and resets the toolbar GUI. |
477 |
toolAndActionButtons.put(buttonAction.getID(), button); |
* |
478 |
if (resetToolBar) |
* @param buttonAction |
479 |
initToolBar(); |
* action for the toggle button |
480 |
} |
*/ |
481 |
|
public void addTool(MapPaneToolBarAction buttonAction) { |
482 |
public void addSeparator(int id, Separator separator) { |
addTool(buttonAction, true); |
483 |
if (isButtonIDUsed(id)) { |
} |
484 |
LOGGER |
|
485 |
.warn("addSeparator(.) ignored because ID already used for tool or action. "); |
/** |
486 |
return; |
* Adds an action to the tool bar. Does nothing if a tool or action with the |
487 |
} |
* specified ID already exists! |
488 |
toolAndActionButtons.put(id, separator); |
* |
489 |
} |
* @param buttonAction |
490 |
|
* action for the button |
491 |
/** |
* @param resetToolBar |
492 |
* Adds an action to the tool bar and resets the toolbar GUI. |
* indicates whether the toolbar GUI is reset after adding the |
493 |
* |
* button (if adding several actions it useful only to reset the |
494 |
* @param buttonAction |
* GUI for the last added tool) |
495 |
* action for the toggle button |
*/ |
496 |
*/ |
public void addAction(MapPaneToolBarAction buttonAction, |
497 |
public void addAction(MapPaneToolBarAction buttonAction) { |
boolean resetToolBar) { |
498 |
addAction(buttonAction, true); |
if (isButtonIDUsed(buttonAction.getID())) { |
499 |
} |
LOGGER |
500 |
|
.warn("addAction(.) ignored because ID already used for tool or action: " |
501 |
/** |
+ buttonAction.getID()); |
502 |
* Returns the button for a specific tool or action. |
return; |
503 |
* |
} |
504 |
* @param id |
JButton button = new JButton(buttonAction); |
505 |
* the constant for any button in the {@link MapPaneToolBar} |
button.setBorder(BorderFactory.createRaisedBevelBorder()); |
506 |
* @return a {@link JButton} if {@code id} specifies an |
toolAndActionButtons.put(buttonAction.getID(), button); |
507 |
* {@linkplain #getActionButton(int) action button} or |
if (resetToolBar) |
508 |
* {@link JToogleButton} if {@code id} specifies a |
initToolBar(); |
509 |
* {@linkplain #getToolButton(int) tool button} |
} |
510 |
*/ |
|
511 |
public AbstractButton getButton(int id) { |
public void addSeparator(int id, Separator separator) { |
512 |
AbstractButton button = (AbstractButton) toolAndActionButtons.get(id); |
if (isButtonIDUsed(id)) { |
513 |
if (button == null) |
LOGGER |
514 |
LOGGER.warn("Unknown tool or action ID: " + id); |
.warn("addSeparator(.) ignored because ID already used for tool or action. "); |
515 |
return button; |
return; |
516 |
} |
} |
517 |
|
toolAndActionButtons.put(id, separator); |
518 |
/** |
} |
519 |
* Returns the button for a specific tool. |
|
520 |
* |
/** |
521 |
* @param tool |
* Adds an action to the tool bar and resets the toolbar GUI. |
522 |
* the constant for a tool |
* |
523 |
*/ |
* @param buttonAction |
524 |
public JToggleButton getToolButton(int tool) { |
* action for the toggle button |
525 |
AbstractButton button = getButton(tool); |
*/ |
526 |
if (button != null && !(button instanceof JToggleButton)) { |
public void addAction(MapPaneToolBarAction buttonAction) { |
527 |
LOGGER.warn("ID specifies no tool: " + tool); |
addAction(buttonAction, true); |
528 |
button = null; |
} |
529 |
} |
|
530 |
return (JToggleButton) button; |
/** |
531 |
} |
* Returns the button for a specific tool or action. |
532 |
|
* |
533 |
/** |
* @param id |
534 |
* Returns the button for a specific action. |
* the constant for any button in the {@link MapPaneToolBar} |
535 |
* |
* @return a {@link JButton} if {@code id} specifies an |
536 |
* @param action |
* {@linkplain #getActionButton(int) action button} or |
537 |
* the constant an action |
* {@link JToogleButton} if {@code id} specifies a |
538 |
*/ |
* {@linkplain #getToolButton(int) tool button} |
539 |
public JButton getActionButton(int action) { |
*/ |
540 |
AbstractButton button = getButton(action); |
public AbstractButton getButton(int id) { |
541 |
if (button != null && !(button instanceof JButton)) { |
AbstractButton button = (AbstractButton) toolAndActionButtons.get(id); |
542 |
LOGGER.warn("ID specifies no action: " + action); |
if (button == null) |
543 |
button = null; |
LOGGER.warn("Unknown tool or action ID: " + id); |
544 |
} |
return button; |
545 |
return (JButton) button; |
} |
546 |
|
|
547 |
} |
/** |
548 |
|
* Returns the button for a specific tool. |
549 |
/** |
* |
550 |
* Sets the selected tool. |
* @param tool |
551 |
* |
* the constant for a tool |
552 |
* @param tool |
*/ |
553 |
* ID of the tool |
public JToggleButton getToolButton(int tool) { |
554 |
*/ |
AbstractButton button = getButton(tool); |
555 |
public void setSelectedTool(Integer tool) { |
if (button != null && !(button instanceof JToggleButton)) { |
556 |
if (tool == null) |
LOGGER.warn("ID specifies no tool: " + tool); |
557 |
toolButtonGroup.setUnselected(); |
button = null; |
558 |
|
} |
559 |
JToggleButton button = getToolButton(tool); |
return (JToggleButton) button; |
560 |
if (button == null) |
} |
561 |
return; |
|
562 |
button.setSelected(true); |
/** |
563 |
button.getAction().actionPerformed(null); |
* Returns the button for a specific action. |
564 |
|
* |
565 |
selectedTool = tool; |
* @param action |
566 |
} |
* the constant an action |
567 |
|
*/ |
568 |
/** |
public JButton getActionButton(int action) { |
569 |
* Returns the selected tool. |
AbstractButton button = getButton(action); |
570 |
* |
if (button != null && !(button instanceof JButton)) { |
571 |
* @return -1 if no tool is active |
LOGGER.warn("ID specifies no action: " + action); |
572 |
*/ |
button = null; |
573 |
public int getSelectedTool() { |
} |
574 |
if (toolButtonGroup.getSelectedButton() == null) |
return (JButton) button; |
575 |
return -1; |
|
576 |
return selectedTool; |
} |
577 |
} |
|
578 |
|
/** |
579 |
/** |
* Sets the selected tool. |
580 |
* Sets whether a tool or action is activated or not. The visible property |
* |
581 |
* of the button is not affected. |
* @param tool |
582 |
* |
* ID of the tool |
583 |
* @param id |
*/ |
584 |
* tool or actionID |
public void setSelectedTool(Integer tool) { |
585 |
* @param enabled |
if (tool == null) |
586 |
* if {@code true} the tool becomes available |
toolButtonGroup.setUnselected(); |
587 |
*/ |
|
588 |
public void setButtonEnabled(int id, boolean enabled) { |
JToggleButton button = getToolButton(tool); |
589 |
AbstractButton button = getButton(id); |
if (button == null) |
590 |
if (button == null) |
return; |
591 |
return; |
button.setSelected(true); |
592 |
button.setEnabled(enabled); |
button.getAction().actionPerformed(null); |
593 |
} |
|
594 |
|
selectedTool = tool; |
595 |
/** |
} |
596 |
* Sets whether a tool or action is activated or not. |
|
597 |
* |
/** |
598 |
* @param id |
* Returns the selected tool. |
599 |
* tool or actionID |
* |
600 |
* @param enabled |
* @return -1 if no tool is active |
601 |
* if {@code true} the tool becomes available |
*/ |
602 |
* @param hideOnDisable |
public int getSelectedTool() { |
603 |
* if {@code true} the button is also hidden if {@code enabled} |
if (toolButtonGroup.getSelectedButton() == null) |
604 |
* is {@code false} |
return -1; |
605 |
*/ |
return selectedTool; |
606 |
public void setButtonEnabled(int id, boolean enabled, boolean hideOnDisable) { |
} |
607 |
AbstractButton button = getButton(id); |
|
608 |
if (button == null) |
/** |
609 |
return; |
* Sets whether a tool or action is activated or not. The visible property |
610 |
button.setEnabled(enabled); |
* of the button is not affected. |
611 |
// if button is enabled, it becomes visible anyway |
* |
612 |
// if button is disabled and the "hide" option is set, it is also hidden |
* @param id |
613 |
if (enabled) |
* tool or actionID |
614 |
button.setVisible(true); |
* @param enabled |
615 |
else |
* if {@code true} the tool becomes available |
616 |
button.setVisible(!hideOnDisable); |
*/ |
617 |
} |
public void setButtonEnabled(int id, boolean enabled) { |
618 |
|
AbstractButton button = getButton(id); |
619 |
/** |
if (button == null) |
620 |
* Checks whether a ID is already used for a tool or action. |
return; |
621 |
* |
button.setEnabled(enabled); |
622 |
* @param tool |
} |
623 |
* tool ID |
|
624 |
*/ |
/** |
625 |
public boolean isButtonIDUsed(int id) { |
* Sets whether a tool or action is activated or not. |
626 |
return toolAndActionButtons.get(id) != null; |
* |
627 |
} |
* @param id |
628 |
|
* tool or actionID |
629 |
/** |
* @param enabled |
630 |
* Checks whether a tool is activated. |
* if {@code true} the tool becomes available |
631 |
* |
* @param hideOnDisable |
632 |
* @param tool |
* if {@code true} the button is also hidden if {@code enabled} |
633 |
* tool ID |
* is {@code false} |
634 |
* @return {@code false} if an unknown ID is specified |
*/ |
635 |
*/ |
public void setButtonEnabled(int id, boolean enabled, boolean hideOnDisable) { |
636 |
public boolean isButtonEnabled(int id) { |
AbstractButton button = getButton(id); |
637 |
AbstractButton button = getButton(id); |
if (button == null) |
638 |
if (button != null) |
return; |
639 |
return button.isEnabled(); |
button.setEnabled(enabled); |
640 |
return false; |
// if button is enabled, it becomes visible anyway |
641 |
} |
// if button is disabled and the "hide" option is set, it is also hidden |
642 |
|
if (enabled) |
643 |
/** |
button.setVisible(true); |
644 |
* Sets the activation for all tools. |
else |
645 |
* |
button.setVisible(!hideOnDisable); |
646 |
* @param enabled |
} |
647 |
* if {@code true} all tools becomes available |
|
648 |
* @param hideOnDisable |
/** |
649 |
* if {@code true} the buttons are also hidden if {@code enabled} |
* Checks whether a ID is already used for a tool or action. |
650 |
* is {@code false} |
* |
651 |
*/ |
* @param tool |
652 |
public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) { |
* tool ID |
653 |
for (int tool : toolAndActionButtons.keySet()) |
*/ |
654 |
setButtonEnabled(tool, enabled, hideOnDisable); |
public boolean isButtonIDUsed(int id) { |
655 |
} |
return toolAndActionButtons.get(id) != null; |
656 |
|
} |
657 |
/** |
|
658 |
* Sets the activation for all actions. |
/** |
659 |
* |
* Checks whether a tool is activated. |
660 |
* @param enabled |
* |
661 |
* if {@code true} all actions becomes available |
* @param tool |
662 |
* @param hideOnDisable |
* tool ID |
663 |
* if {@code true} the buttons are also hidden if {@code enabled} |
* @return {@code false} if an unknown ID is specified |
664 |
* is {@code false} |
*/ |
665 |
*/ |
public boolean isButtonEnabled(int id) { |
666 |
public void setAllActionsEnabled(boolean enabled, boolean hideOnDisable) { |
AbstractButton button = getButton(id); |
667 |
for (int id : toolAndActionButtons.keySet()) { |
if (button != null) |
668 |
if (toolAndActionButtons.get(id) instanceof JButton) { |
return button.isEnabled(); |
669 |
setButtonEnabled(id, enabled, hideOnDisable); |
return false; |
670 |
} |
} |
671 |
} |
|
672 |
|
/** |
673 |
} |
* Sets the activation for all tools. |
674 |
|
* |
675 |
/** |
* @param enabled |
676 |
* Returns the maximum ID of tools. |
* if {@code true} all tools becomes available |
677 |
*/ |
* @param hideOnDisable |
678 |
public int getMaxToolID() { |
* if {@code true} the buttons are also hidden if {@code enabled} |
679 |
return toolAndActionButtons.lastKey(); |
* is {@code false} |
680 |
} |
*/ |
681 |
|
public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) { |
682 |
/** |
for (int tool : toolAndActionButtons.keySet()) |
683 |
* Returns the minimum ID of tools. |
setButtonEnabled(tool, enabled, hideOnDisable); |
684 |
*/ |
} |
685 |
public int getMinToolID() { |
|
686 |
return toolAndActionButtons.firstKey(); |
/** |
687 |
} |
* Sets the activation for all actions. |
688 |
|
* |
689 |
/** |
* @param enabled |
690 |
* Extends the {@link AbstractAction} with maintaining an ID and the |
* if {@code true} all actions becomes available |
691 |
* {@link MapPaneToolBar} the actions controls. Additionally this class |
* @param hideOnDisable |
692 |
* automatically calls |
* if {@code true} the buttons are also hidden if {@code enabled} |
693 |
* {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or |
* is {@code false} |
694 |
* {@link MapPaneToolBar#performActionButton(int, ActionEvent)} depending on |
*/ |
695 |
* whether the action is added via |
public void setAllActionsEnabled(boolean enabled, boolean hideOnDisable) { |
696 |
* {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or |
for (int id : toolAndActionButtons.keySet()) { |
697 |
* {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}. |
if (toolAndActionButtons.get(id) instanceof JButton) { |
698 |
* |
setButtonEnabled(id, enabled, hideOnDisable); |
699 |
* @author <a href="mailto:[email protected]">Martin Schmitz</a> |
} |
700 |
* (University of Bonn/Germany) |
} |
701 |
*/ |
|
702 |
public static class MapPaneToolBarAction extends AbstractAction { |
} |
703 |
/** The ID of the action */ |
|
704 |
protected int id = -1; |
/** |
705 |
/** The tool bar, this action is made for. */ |
* Returns the maximum ID of tools. |
706 |
protected MapPaneToolBar toolBar = null; |
*/ |
707 |
|
public int getMaxToolID() { |
708 |
/** |
return toolAndActionButtons.lastKey(); |
709 |
* Creates a new action with a dummy description and no icon. |
} |
710 |
* |
|
711 |
* @param id |
/** |
712 |
* unique ID for the action |
* Returns the minimum ID of tools. |
713 |
* @param toolBar |
*/ |
714 |
* toolbar this action is made for |
public int getMinToolID() { |
715 |
*/ |
return toolAndActionButtons.firstKey(); |
716 |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar) { |
} |
717 |
this(id, toolBar, "" + id); |
|
718 |
} |
/** |
719 |
|
* Extends the {@link AbstractAction} with maintaining an ID and the |
720 |
/** |
* {@link MapPaneToolBar} the actions controls. Additionally this class |
721 |
* Creates a new action without an icon. |
* automatically calls |
722 |
* |
* {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or |
723 |
* @param id |
* {@link MapPaneToolBar#performActionButton(int, ActionEvent)} depending on |
724 |
* unique ID for the action |
* whether the action is added via |
725 |
* @param toolBar |
* {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or |
726 |
* toolbar this action is made for |
* {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}. |
727 |
* @param name |
* |
728 |
* description used for buttons or menus |
* @author <a href="mailto:[email protected]">Martin Schmitz</a> |
729 |
*/ |
* (University of Bonn/Germany) |
730 |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, String name) { |
*/ |
731 |
this(id, toolBar, name, null); |
public static class MapPaneToolBarAction extends AbstractAction { |
732 |
} |
/** The ID of the action */ |
733 |
|
protected int id = -1; |
734 |
/** |
/** The tool bar, this action is made for. */ |
735 |
* Creates a new action. |
protected MapPaneToolBar toolBar = null; |
736 |
* |
|
737 |
* @param id |
/** |
738 |
* unique ID for the action |
* Creates a new action with a dummy description and no icon. |
739 |
* @param toolBar |
* |
740 |
* toolbar this action is made for |
* @param id |
741 |
* @param name |
* unique ID for the action |
742 |
* description used for buttons or menus |
* @param toolBar |
743 |
* @param icon |
* toolbar this action is made for |
744 |
* icon used for buttons or menus |
*/ |
745 |
*/ |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar) { |
746 |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, |
this(id, toolBar, "" + id); |
747 |
String name, Icon icon) { |
} |
748 |
this (id, toolBar, name, icon, null); |
|
749 |
} |
/** |
750 |
|
* Creates a new action without an icon. |
751 |
/** |
* |
752 |
* Creates a new action. |
* @param id |
753 |
* |
* unique ID for the action |
754 |
* @param id |
* @param toolBar |
755 |
* unique ID for the action |
* toolbar this action is made for |
756 |
* @param toolBar |
* @param name |
757 |
* The {@link MapPaneToolBar} this action is made for |
* description used for buttons or menus |
758 |
* @param name |
*/ |
759 |
* description used for buttons or menus |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, String name) { |
760 |
* @param icon |
this(id, toolBar, name, null); |
761 |
* icon used for buttons or menus |
} |
762 |
* @param toolTip |
|
763 |
* Tooltip to use for the button or menu |
/** |
764 |
*/ |
* Creates a new action. |
765 |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, |
* |
766 |
String name, Icon icon, String toolTip) { |
* @param id |
767 |
super(name, icon); |
* unique ID for the action |
768 |
|
* @param toolBar |
769 |
if (toolTip != null && !toolTip.trim().isEmpty()){ |
* toolbar this action is made for |
770 |
putValue(Action.SHORT_DESCRIPTION, toolTip); |
* @param name |
771 |
} |
* description used for buttons or menus |
772 |
|
* @param icon |
773 |
this.id = id; |
* icon used for buttons or menus |
774 |
this.toolBar = toolBar; |
*/ |
775 |
} |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, |
776 |
|
String name, Icon icon) { |
777 |
/** |
this (id, toolBar, name, icon, null); |
778 |
* Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or |
} |
779 |
* {@link MapPaneToolBar#performActionButton(int, ActionEvent)} |
|
780 |
* depending on whether the action is added to the toolbar via |
/** |
781 |
* {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or |
* Creates a new action. |
782 |
* {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}. |
* |
783 |
*/ |
* @param id |
784 |
public void actionPerformed(ActionEvent e) { |
* unique ID for the action |
785 |
if (toolBar.toolAndActionButtons.get(id) instanceof JToggleButton) |
* @param toolBar |
786 |
toolBar.performToolButton(id, e); |
* The {@link MapPaneToolBar} this action is made for |
787 |
else if (toolBar.toolAndActionButtons.get(id) instanceof JButton) |
* @param name |
788 |
toolBar.performActionButton(id, e); |
* description used for buttons or menus |
789 |
} |
* @param icon |
790 |
|
* icon used for buttons or menus |
791 |
/** |
* @param toolTip |
792 |
* Returns the (unique) id of this action. |
* Tooltip to use for the button or menu |
793 |
* |
*/ |
794 |
* @return |
public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, |
795 |
*/ |
String name, Icon icon, String toolTip) { |
796 |
public int getID() { |
super(name, icon); |
797 |
return id; |
|
798 |
} |
if (toolTip != null && !toolTip.trim().isEmpty()){ |
799 |
} |
putValue(Action.SHORT_DESCRIPTION, toolTip); |
800 |
|
} |
801 |
/** |
|
802 |
* Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht wird) wird. Dann werden wird der |
this.id = id; |
803 |
* Hintergrund auf WEISS gesetzt. |
this.toolBar = toolBar; |
804 |
* |
} |
805 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
|
806 |
* Krüger</a> |
/** |
807 |
*/ |
* Calls {@link MapPaneToolBar#performToolButton(int, ActionEvent)} or |
808 |
@Override |
* {@link MapPaneToolBar#performActionButton(int, ActionEvent)} |
809 |
public void print(Graphics g) { |
* depending on whether the action is added to the toolbar via |
810 |
Color orig = getBackground(); |
* {@link MapPaneToolBar#addTool(MapPaneToolBarAction)} or |
811 |
setBackground(Color.WHITE); |
* {@link MapPaneToolBar#addAction(MapPaneToolBarAction)}. |
812 |
// wrap in try/finally so that we always restore the state |
*/ |
813 |
try { |
public void actionPerformed(ActionEvent e) { |
814 |
super.print(g); |
if (toolBar.toolAndActionButtons.get(id) instanceof JToggleButton) |
815 |
} finally { |
toolBar.performToolButton(id, e); |
816 |
setBackground(orig); |
else if (toolBar.toolAndActionButtons.get(id) instanceof JButton) |
817 |
} |
toolBar.performActionButton(id, e); |
818 |
} |
} |
819 |
} |
|
820 |
|
/** |
821 |
|
* Returns the (unique) id of this action. |
822 |
|
* |
823 |
|
* @return |
824 |
|
*/ |
825 |
|
public int getID() { |
826 |
|
return id; |
827 |
|
} |
828 |
|
} |
829 |
|
|
830 |
|
/** |
831 |
|
* Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht wird) wird. Dann werden wird der |
832 |
|
* Hintergrund auf WEISS gesetzt. |
833 |
|
* |
834 |
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
835 |
|
* Krüger</a> |
836 |
|
*/ |
837 |
|
@Override |
838 |
|
public void print(Graphics g) { |
839 |
|
Color orig = getBackground(); |
840 |
|
setBackground(Color.WHITE); |
841 |
|
// wrap in try/finally so that we always restore the state |
842 |
|
try { |
843 |
|
super.print(g); |
844 |
|
} finally { |
845 |
|
setBackground(orig); |
846 |
|
} |
847 |
|
} |
848 |
|
} |