33 |
import java.awt.Dimension; |
import java.awt.Dimension; |
34 |
import java.awt.Graphics; |
import java.awt.Graphics; |
35 |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
36 |
|
import java.awt.event.ActionListener; |
37 |
import java.util.ArrayList; |
import java.util.ArrayList; |
38 |
|
import java.util.HashSet; |
39 |
import java.util.Locale; |
import java.util.Locale; |
40 |
|
import java.util.Set; |
41 |
import java.util.SortedMap; |
import java.util.SortedMap; |
42 |
import java.util.TreeMap; |
import java.util.TreeMap; |
43 |
|
|
131 |
protected int selectedTool = TOOL_ZOOMIN; |
protected int selectedTool = TOOL_ZOOMIN; |
132 |
|
|
133 |
/** Holds the tool buttons of the tool bar. */ |
/** Holds the tool buttons of the tool bar. */ |
134 |
protected SortedMap<Integer, JComponent> toolAndActionButtons = null; |
final protected SortedMap<Integer, JComponent> toolAndActionButtons = new TreeMap<Integer, JComponent>(); |
135 |
/** Controls that only one tool button is activated. */ |
/** Controls that only one tool button is activated. */ |
136 |
protected ButtonGroup toolButtonGroup = null; |
protected ButtonGroup toolButtonGroup = null; |
137 |
|
|
156 |
|
|
157 |
protected boolean zoomBackForwardButtonInAction; |
protected boolean zoomBackForwardButtonInAction; |
158 |
|
|
159 |
|
/** Listeners what want to be informed about a change of the selected tool **/ |
160 |
|
protected Set<MapPaneToolSelectedListener> toolSelectionListeners = new HashSet<MapPaneToolSelectedListener>(); |
161 |
|
|
162 |
|
/** This listener is added to all {@link JToggleButton} **/ |
163 |
|
private final ActionListener toolSelectedListener = new ActionListener(){ |
164 |
|
|
165 |
|
@Override |
166 |
|
public void actionPerformed(ActionEvent e) { |
167 |
|
JToggleButton tb = (JToggleButton) e.getSource(); |
168 |
|
|
169 |
|
// Inform the listeners about a newly selected tool |
170 |
|
for (MapPaneToolSelectedListener l : toolSelectionListeners) { |
171 |
|
l.toolSelected(Integer.valueOf( tb.getName() ) ) ; |
172 |
|
} |
173 |
|
} |
174 |
|
|
175 |
|
}; |
176 |
|
|
177 |
/** |
/** |
178 |
* Creates a new toolbar. Notice: This toolbar does nothing until |
* Creates a new toolbar. Notice: This toolbar does nothing until |
179 |
* {@link #setMapPane(JMapPane)} is called! |
* {@link #setMapPane(JMapPane)} is called! |
181 |
public MapPaneToolBar() { |
public MapPaneToolBar() { |
182 |
this(null); |
this(null); |
183 |
} |
} |
184 |
|
|
185 |
|
public void addButtonSelectedListener(MapPaneToolSelectedListener listener ) { |
186 |
|
toolSelectionListeners.add(listener); |
187 |
|
} |
188 |
|
|
189 |
|
public void removeButtonSelectedListener(MapPaneToolSelectedListener listener ) { |
190 |
|
toolSelectionListeners .remove(listener); |
191 |
|
} |
192 |
|
|
193 |
/** |
/** |
194 |
* Creates a new tool bar. |
* Creates a new tool bar. |
198 |
*/ |
*/ |
199 |
public MapPaneToolBar(JMapPane mapPane) { |
public MapPaneToolBar(JMapPane mapPane) { |
200 |
super("Control the map", JToolBar.HORIZONTAL); |
super("Control the map", JToolBar.HORIZONTAL); |
|
this.toolAndActionButtons = new TreeMap<Integer, JComponent>(); |
|
201 |
this.toolButtonGroup = new ButtonGroup(); |
this.toolButtonGroup = new ButtonGroup(); |
202 |
|
|
203 |
// Create a Listener to listen to the zooms on the JMapPane |
// Create a Listener to listen to the zooms on the JMapPane |
334 |
Dimension dimension = new Dimension(49, 10); |
Dimension dimension = new Dimension(49, 10); |
335 |
addSeparator(dimension); |
addSeparator(dimension); |
336 |
// Tool buttons |
// Tool buttons |
337 |
for (JComponent b : toolAndActionButtons.values()) |
for (Integer bKey : toolAndActionButtons.keySet()) { |
338 |
|
|
339 |
|
JComponent b = toolAndActionButtons.get(bKey); |
340 |
|
|
341 |
|
if (b instanceof JToggleButton) { |
342 |
|
JToggleButton tb = (JToggleButton) b; |
343 |
|
tb.setName(bKey.toString()); |
344 |
|
tb.addActionListener( toolSelectedListener ); |
345 |
|
} |
346 |
|
|
347 |
add(b); |
add(b); |
348 |
|
} |
349 |
|
|
350 |
if (!toolAndActionButtons.containsKey(selectedTool)) { |
if (!toolAndActionButtons.containsKey(selectedTool)) { |
351 |
/** |
/** |
908 |
setBackground(orig); |
setBackground(orig); |
909 |
} |
} |
910 |
} |
} |
911 |
|
|
912 |
} |
} |