source: josm/trunk/src/org/openstreetmap/josm/gui/MapFrame.java@ 5092

Last change on this file since 5092 was 5092, checked in by simon04, 12 years ago

Toggle edit toolbar (in View menu or in popup menu)

  • Property svn:eol-style set to native
File size: 23.8 KB
Line 
1// License: GPL. See LICENSE file for details.
2package org.openstreetmap.josm.gui;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.BorderLayout;
7import java.awt.Component;
8import java.awt.Container;
9import java.awt.Dimension;
10import java.awt.Font;
11import java.awt.GridBagLayout;
12import java.awt.Rectangle;
13import java.awt.event.ActionEvent;
14import java.awt.event.KeyEvent;
15import java.awt.event.MouseWheelEvent;
16import java.awt.event.MouseWheelListener;
17import java.util.ArrayList;
18import java.util.Collection;
19import java.util.HashMap;
20import java.util.List;
21import java.util.Map;
22import java.util.concurrent.CopyOnWriteArrayList;
23
24import javax.swing.AbstractAction;
25import javax.swing.AbstractButton;
26import javax.swing.Action;
27import javax.swing.BoxLayout;
28import javax.swing.ButtonGroup;
29import javax.swing.JButton;
30import javax.swing.JCheckBoxMenuItem;
31import javax.swing.JComponent;
32import javax.swing.JPanel;
33import javax.swing.JPopupMenu;
34import javax.swing.JSplitPane;
35import javax.swing.JToolBar;
36import javax.swing.KeyStroke;
37import javax.swing.SwingUtilities;
38import javax.swing.border.Border;
39import javax.swing.plaf.basic.BasicSplitPaneDivider;
40import javax.swing.plaf.basic.BasicSplitPaneUI;
41
42import org.openstreetmap.josm.Main;
43import org.openstreetmap.josm.actions.mapmode.DeleteAction;
44import org.openstreetmap.josm.actions.mapmode.DrawAction;
45import org.openstreetmap.josm.actions.mapmode.ExtrudeAction;
46import org.openstreetmap.josm.actions.mapmode.ImproveWayAccuracyAction;
47import org.openstreetmap.josm.actions.mapmode.MapMode;
48import org.openstreetmap.josm.actions.mapmode.ParallelWayAction;
49import org.openstreetmap.josm.actions.mapmode.SelectAction;
50import org.openstreetmap.josm.actions.mapmode.ZoomAction;
51import org.openstreetmap.josm.data.Preferences;
52import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
53import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
54import org.openstreetmap.josm.gui.dialogs.ChangesetDialog;
55import org.openstreetmap.josm.gui.dialogs.CommandStackDialog;
56import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
57import org.openstreetmap.josm.gui.dialogs.DialogsPanel;
58import org.openstreetmap.josm.gui.dialogs.FilterDialog;
59import org.openstreetmap.josm.gui.dialogs.HistoryDialog;
60import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
61import org.openstreetmap.josm.gui.dialogs.MapPaintDialog;
62import org.openstreetmap.josm.gui.dialogs.RelationListDialog;
63import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
64import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
65import org.openstreetmap.josm.gui.dialogs.UserListDialog;
66import org.openstreetmap.josm.gui.dialogs.ValidatorDialog;
67import org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog;
68import org.openstreetmap.josm.gui.layer.Layer;
69import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
70import org.openstreetmap.josm.tools.Destroyable;
71import org.openstreetmap.josm.tools.GBC;
72
73/**
74 * One Map frame with one dataset behind. This is the container gui class whose
75 * display can be set to the different views.
76 *
77 * @author imi
78 */
79public class MapFrame extends JPanel implements Destroyable, LayerChangeListener {
80
81 /**
82 * The current mode, this frame operates.
83 */
84 public MapMode mapMode;
85
86 private final List<MapMode> mapModes = new ArrayList<MapMode>();
87 /**
88 * The view control displayed.
89 */
90 public MapView mapView;
91 /**
92 * The toolbar with the action icons. To add new toggle dialog actions, use addToggleDialog
93 * instead of adding directly to this list. To add a new mode use addMapMode.
94 */
95 private JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL);
96 private JToolBar toolBarToggle = new JToolBar(JToolBar.VERTICAL);
97 /**
98 * The status line below the map
99 */
100 public MapStatus statusLine;
101
102 // Toggle dialogs
103 public ConflictDialog conflictDialog;
104 public FilterDialog filterDialog;
105 public RelationListDialog relationListDialog;
106 public ValidatorDialog validatorDialog;
107 public SelectionListDialog selectionListDialog;
108 public PropertiesDialog propertiesDialog;
109
110 // Map modes
111 private final MapMode mapModeSelect;
112 private final MapMode mapModeDraw;
113 private final MapMode mapModeZoom;
114
115 /**
116 * The panel list of all toggle dialog icons. To add new toggle dialog actions, use addToggleDialog
117 * instead of adding directly to this list.
118 */
119 private List<ToggleDialog> allDialogs = new ArrayList<ToggleDialog>();
120 private final JPanel leftPanel;
121 private final DialogsPanel dialogsPanel;
122
123 public final ButtonGroup toolGroup = new ButtonGroup();
124
125 private List<IconToggleButton> allDialogButtons = new ArrayList<IconToggleButton>();
126 private List<IconToggleButton> allMapModeButtons = new ArrayList<IconToggleButton>();
127
128 private final ListAllButtonsAction listAllDialogsAction = new ListAllButtonsAction(allDialogButtons);
129 private final ListAllButtonsAction listAllMapModesAction = new ListAllButtonsAction(allMapModeButtons);
130 private final JButton listAllToggleDialogsButton = new JButton(listAllDialogsAction);
131 private final JButton listAllMapModesButton = new JButton(listAllMapModesAction);
132 {
133 listAllDialogsAction.setButton(listAllToggleDialogsButton);
134 listAllMapModesAction.setButton(listAllMapModesButton);
135 }
136
137 /**
138 * Default width of the toggle dialog area.
139 */
140 public static final int DEF_TOGGLE_DLG_WIDTH = 330;
141
142 private final Map<Layer, MapMode> lastMapMode = new HashMap<Layer, MapMode>();
143
144 public MapFrame(JPanel contentPane) {
145 setSize(400,400);
146 setLayout(new BorderLayout());
147
148
149 mapView = new MapView(contentPane);
150
151 new FileDrop(mapView);
152
153 leftPanel = new JPanel();
154 leftPanel.setLayout(new GridBagLayout());
155
156 leftPanel.add(mapView, GBC.std().fill());
157
158 // toolbar
159 toolBarActions.setFloatable(false);
160 addMapMode(new IconToggleButton(mapModeSelect = new SelectAction(this)));
161 addMapMode(new IconToggleButton(mapModeDraw = new DrawAction(this)));
162 addMapMode(new IconToggleButton(mapModeZoom = new ZoomAction(this)));
163 addMapMode(new IconToggleButton(new DeleteAction(this), true));
164 addMapMode(new IconToggleButton(new ParallelWayAction(this), true));
165 addMapMode(new IconToggleButton(new ExtrudeAction(this), true));
166 addMapMode(new IconToggleButton(new ImproveWayAccuracyAction(Main.map), true));
167
168 toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
169
170 JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
171 dialogsPanel = new DialogsPanel(splitPane);
172 splitPane.setLeftComponent(leftPanel);
173 splitPane.setRightComponent(dialogsPanel);
174
175 /**
176 * All additional space goes to the mapView
177 */
178 splitPane.setResizeWeight(1.0);
179
180 /**
181 * Some beautifications.
182 */
183 splitPane.setDividerSize(5);
184 splitPane.setBorder(null);
185 splitPane.setUI(new BasicSplitPaneUI() {
186 @Override
187 public BasicSplitPaneDivider createDefaultDivider() {
188 return new BasicSplitPaneDivider(this) {
189 @Override
190 public void setBorder(Border b) {
191 }
192 };
193 }
194 });
195
196 // JSplitPane supports F6 and F8 shortcuts by default, but we need them for Audio actions
197 splitPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0), new Object());
198 splitPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0), new Object());
199
200 add(splitPane, BorderLayout.CENTER);
201
202 dialogsPanel.setLayout(new BoxLayout(dialogsPanel, BoxLayout.Y_AXIS));
203 dialogsPanel.setPreferredSize(new Dimension(Main.pref.getInteger("toggleDialogs.width",DEF_TOGGLE_DLG_WIDTH), 0));
204
205 dialogsPanel.setMinimumSize(new Dimension(24, 0));
206 mapView.setMinimumSize(new Dimension(10,0));
207
208 toolBarToggle.setFloatable(false);
209 LayerListDialog.createInstance(this);
210 addToggleDialog(LayerListDialog.getInstance());
211 addToggleDialog(propertiesDialog = new PropertiesDialog(this));
212 addToggleDialog(selectionListDialog = new SelectionListDialog());
213 addToggleDialog(relationListDialog = new RelationListDialog());
214 addToggleDialog(new CommandStackDialog(this));
215 addToggleDialog(new UserListDialog());
216 addToggleDialog(new HistoryDialog(), true);
217 addToggleDialog(conflictDialog = new ConflictDialog());
218 addToggleDialog(validatorDialog = new ValidatorDialog());
219 addToggleDialog(filterDialog = new FilterDialog());
220 addToggleDialog(new ChangesetDialog(this), true);
221 addToggleDialog(new MapPaintDialog());
222
223 // status line below the map
224 statusLine = new MapStatus(this);
225 MapView.addLayerChangeListener(this);
226 }
227
228 public boolean selectSelectTool(boolean onlyIfModeless) {
229 if(onlyIfModeless && !Main.pref.getBoolean("modeless", false))
230 return false;
231
232 return selectMapMode(mapModeSelect);
233 }
234
235 public void selectDrawTool(boolean onlyIfModeless) {
236 if(onlyIfModeless && !Main.pref.getBoolean("modeless", false))
237 return;
238
239 selectMapMode(mapModeDraw);
240 }
241
242 public boolean selectZoomTool(boolean onlyIfModeless) {
243 if(onlyIfModeless && !Main.pref.getBoolean("modeless", false))
244 return false;
245
246 return selectMapMode(mapModeZoom);
247 }
248
249 /**
250 * Called as some kind of destructor when the last layer has been removed.
251 * Delegates the call to all Destroyables within this component (e.g. MapModes)
252 */
253 public void destroy() {
254 MapView.removeLayerChangeListener(this);
255 dialogsPanel.destroy();
256 for (int i = 0; i < toolBarActions.getComponentCount(); ++i) {
257 if (toolBarActions.getComponent(i) instanceof Destroyable) {
258 ((Destroyable)toolBarActions.getComponent(i)).destroy();
259 }
260 }
261 for (int i = 0; i < toolBarToggle.getComponentCount(); ++i) {
262 if (toolBarToggle.getComponent(i) instanceof Destroyable) {
263 ((Destroyable)toolBarToggle.getComponent(i)).destroy();
264 }
265 }
266
267 // MapFrame gets destroyed when the last layer is removed, but the status line background
268 // thread that collects the information doesn't get destroyed automatically.
269 if(statusLine.thread != null) {
270 try {
271 statusLine.thread.interrupt();
272 } catch (Exception e) {
273 e.printStackTrace();
274 }
275 }
276 mapView.destroy();
277 }
278
279 public Action getDefaultButtonAction() {
280 return ((AbstractButton)toolBarActions.getComponent(0)).getAction();
281 }
282
283 /**
284 * Open all ToggleDialogs that have their preferences property set. Close all others.
285 */
286 public void initializeDialogsPane() {
287 dialogsPanel.initialize(allDialogs);
288 }
289
290 public IconToggleButton addToggleDialog(final ToggleDialog dlg) {
291 return addToggleDialog(dlg, false);
292 }
293
294 /**
295 * Call this to add new toggle dialogs to the left button-list
296 * @param dlg The toggle dialog. It must not be in the list already.
297 */
298 public IconToggleButton addToggleDialog(final ToggleDialog dlg, boolean isExpert) {
299 final IconToggleButton button = new IconToggleButton(dlg.getToggleAction(), isExpert);
300 button.setShowHideButtonListener(dlg);
301 addHideContextMenu(button);
302 dlg.setButton(button);
303 toolBarToggle.add(button);
304 allDialogs.add(dlg);
305 allDialogButtons.add(button);
306 button.applyButtonHiddenPreferences();
307 if (dialogsPanel.initialized) {
308 dialogsPanel.add(dlg);
309 }
310 return button;
311 }
312
313
314
315 public void addMapMode(IconToggleButton b) {
316 toolBarActions.add(b);
317 toolGroup.add(b);
318 allMapModeButtons.add(b);
319 if (b.getAction() instanceof MapMode) {
320 mapModes.add((MapMode) b.getAction());
321 } else
322 throw new IllegalArgumentException("MapMode action must be subclass of MapMode");
323 addHideContextMenu(b);
324 b.applyButtonHiddenPreferences();
325 }
326
327 /**
328 * Fires an property changed event "visible".
329 */
330 @Override public void setVisible(boolean aFlag) {
331 boolean old = isVisible();
332 super.setVisible(aFlag);
333 if (old != aFlag) {
334 firePropertyChange("visible", old, aFlag);
335 }
336 }
337
338 /**
339 * Change the operating map mode for the view. Will call unregister on the
340 * old MapMode and register on the new one. Now this function also verifies
341 * if new map mode is correct mode for current layer and does not change mode
342 * in such cases.
343 * @param mapMode The new mode to set.
344 * @return
345 */
346 public boolean selectMapMode(MapMode newMapMode) {
347 return selectMapMode(newMapMode, mapView.getActiveLayer());
348 }
349
350 /**
351 * Another version of the selectMapMode for changing layer action.
352 * Pass newly selected layer to this method.
353 * @param newMapMode
354 * @param newLayer
355 * @return True if mode is really selected
356 */
357 public boolean selectMapMode(MapMode newMapMode, Layer newLayer) {
358 if (newMapMode == null || !newMapMode.layerIsSupported(newLayer))
359 return false;
360
361 MapMode oldMapMode = this.mapMode;
362 if (newMapMode == oldMapMode)
363 return true;
364 if (oldMapMode != null) {
365 oldMapMode.exitMode();
366 }
367 this.mapMode = newMapMode;
368 newMapMode.enterMode();
369 lastMapMode.put(newLayer, newMapMode);
370 fireMapModeChanged(oldMapMode, newMapMode);
371 return true;
372 }
373
374 /**
375 * Fill the given panel by adding all necessary components to the different
376 * locations.
377 *
378 * @param panel The container to fill. Must have an BorderLayout.
379 */
380 public void fillPanel(Container panel) {
381 panel.add(this, BorderLayout.CENTER);
382 JToolBar jb = new JToolBar(JToolBar.VERTICAL);
383 jb.setFloatable(false);
384 toolBarActions.setAlignmentX(0.5f);
385 jb.add(toolBarActions);
386 listAllMapModesButton.setAlignmentX(0.5f);
387 listAllMapModesButton.setBorder(null);
388 listAllMapModesButton.setFont(listAllMapModesButton.getFont().deriveFont(Font.PLAIN));
389 jb.add(listAllMapModesButton);
390
391 if(Main.pref.getBoolean("sidetoolbar.togglevisible", true)) {
392 jb.addSeparator(new Dimension(0,18));
393 toolBarToggle.setAlignmentX(0.5f);
394 jb.add(toolBarToggle);
395 listAllToggleDialogsButton.setAlignmentX(0.5f);
396 listAllToggleDialogsButton.setBorder(null);
397 listAllToggleDialogsButton.setFont(listAllToggleDialogsButton.getFont().deriveFont(Font.PLAIN));
398 jb.add(listAllToggleDialogsButton);
399 }
400
401 final Component toToggle;
402 if (Main.pref.getBoolean("sidetoolbar.scrollable", true)) {
403 final ScrollViewport svp = new ScrollViewport(jb, ScrollViewport.VERTICAL_DIRECTION);
404 toToggle = svp;
405 panel.add(svp, BorderLayout.WEST);
406 jb.addMouseWheelListener(new MouseWheelListener() {
407
408 public void mouseWheelMoved(MouseWheelEvent e) {
409 svp.scroll(0, e.getUnitsToScroll() * 5);
410 }
411 });
412 } else {
413 toToggle = jb;
414 panel.add(jb, BorderLayout.WEST);
415 }
416 toToggle.setVisible(Main.pref.getBoolean("sidetoolbar.visible", true));
417
418 jb.addMouseListener(new PopupMenuLauncher(new JPopupMenu() {
419
420 {
421 add(new AbstractAction(tr("Hide edit toolbar")) {
422
423 @Override
424 public void actionPerformed(ActionEvent e) {
425 Main.pref.put("sidetoolbar.visible", false);
426 }
427 });
428 }
429 }));
430
431 Main.pref.addPreferenceChangeListener(new Preferences.PreferenceChangedListener() {
432
433 @Override
434 public void preferenceChanged(PreferenceChangeEvent e) {
435 if ("sidetoolbar.visible".equals(e.getKey())) {
436 toToggle.setVisible(Main.pref.getBoolean("sidetoolbar.visible"));
437 }
438 }
439 });
440
441 if (statusLine != null && Main.pref.getBoolean("statusline.visible", true)) {
442 panel.add(statusLine, BorderLayout.SOUTH);
443 }
444 }
445
446 private void addHideContextMenu(final IconToggleButton b) {
447 //context menu
448 b.addMouseListener(new PopupMenuLauncher(new JPopupMenu() {
449 {
450 add(new AbstractAction() {
451 {
452 putValue(NAME, tr("Hide this button"));
453 putValue(SHORT_DESCRIPTION, tr("Click the arrow at the bottom to show it again."));
454 }
455 @Override
456 public void actionPerformed(ActionEvent e) {
457 b.setButtonHidden(true);
458 validateToolBarsVisibility();
459 }
460 });
461 }
462 }));
463 }
464
465 class ListAllButtonsAction extends AbstractAction {
466
467 private JButton button;
468 private Collection<? extends HideableButton> buttons;
469
470
471 public ListAllButtonsAction(Collection<? extends HideableButton> buttons) {
472 this.buttons = buttons;
473 putValue(NAME, ">>");
474 }
475
476 public void setButton(JButton button) {
477 this.button = button;
478 }
479
480 @Override
481 public void actionPerformed(ActionEvent e) {
482 JPopupMenu menu = new JPopupMenu();
483 for (HideableButton b : buttons) {
484 final HideableButton t = b;
485 menu.add(new JCheckBoxMenuItem(new AbstractAction() {
486 {
487 putValue(NAME, t.getActionName());
488 putValue(SMALL_ICON, t.getIcon());
489 putValue(SELECTED_KEY, t.isButtonVisible());
490 putValue(SHORT_DESCRIPTION, tr("Hide or show this toggle button"));
491 }
492 @Override
493 public void actionPerformed(ActionEvent e) {
494 if ((Boolean) getValue(SELECTED_KEY)) {
495 t.showButton();
496 } else {
497 t.hideButton();
498 }
499 validateToolBarsVisibility();
500 }
501 }));
502 }
503 Rectangle bounds = button.getBounds();
504 menu.show(button, bounds.x + bounds.width, 0);
505 }
506 }
507
508 public void validateToolBarsVisibility() {
509 for (IconToggleButton b : allDialogButtons) {
510 b.applyButtonHiddenPreferences();
511 }
512 toolBarToggle.repaint();
513 for (IconToggleButton b : allMapModeButtons) {
514 b.applyButtonHiddenPreferences();
515 }
516 toolBarActions.repaint();
517 }
518
519 /**
520 * Replies the instance of a toggle dialog of type <code>type</code> managed by this
521 * map frame
522 *
523 * @param <T>
524 * @param type the class of the toggle dialog, i.e. UserListDialog.class
525 * @return the instance of a toggle dialog of type <code>type</code> managed by this
526 * map frame; null, if no such dialog exists
527 *
528 */
529 public <T> T getToggleDialog(Class<T> type) {
530 return dialogsPanel.getToggleDialog(type);
531 }
532
533 /**
534 * Remember the current width of the (possibly resized) toggle dialog area
535 */
536 public void rememberToggleDialogWidth() {
537 Main.pref.putInteger("toggleDialogs.width", dialogsPanel.getWidth());
538 }
539
540 /*
541 * Remove panel from top of MapView by class
542 */
543 public void removeTopPanel(Class<?> type) {
544 int n = leftPanel.getComponentCount();
545 for (int i=0; i<n; i++) {
546 Component c = leftPanel.getComponent(i);
547 if (type.isInstance(c)) {
548 leftPanel.remove(i);
549 leftPanel.doLayout();
550// repaint();
551 return;
552 }
553 }
554 }
555
556 /*
557 * Find panel on top of MapView by class
558 */
559 public <T> T getTopPanel(Class<T> type) {
560 int n = leftPanel.getComponentCount();
561 for (int i=0; i<n; i++) {
562 Component c = leftPanel.getComponent(i);
563 if (type.isInstance(c)) {
564 return type.cast(c);
565 }
566 }
567 return null;
568 }
569
570 /**
571 * Add component @param c on top of MapView
572 */
573 public void addTopPanel(Component c) {
574 leftPanel.add(c, GBC.eol().fill(GBC.HORIZONTAL), leftPanel.getComponentCount()-1);
575 leftPanel.doLayout();
576 c.doLayout();
577 }
578
579 /**
580 * Interface to notify listeners of the change of the mapMode.
581 */
582 public interface MapModeChangeListener {
583 void mapModeChange(MapMode oldMapMode, MapMode newMapMode);
584 }
585
586 /**
587 * the mapMode listeners
588 */
589 private static final CopyOnWriteArrayList<MapModeChangeListener> mapModeChangeListeners = new CopyOnWriteArrayList<MapModeChangeListener>();
590 /**
591 * Adds a mapMode change listener
592 *
593 * @param listener the listener. Ignored if null or already registered.
594 */
595 public static void addMapModeChangeListener(MapModeChangeListener listener) {
596 if (listener != null) {
597 mapModeChangeListeners.addIfAbsent(listener);
598 }
599 }
600 /**
601 * Removes a mapMode change listener
602 *
603 * @param listener the listener. Ignored if null or already registered.
604 */
605 public static void removeMapModeChangeListener(MapModeChangeListener listener) {
606 mapModeChangeListeners.remove(listener);
607 }
608
609 protected static void fireMapModeChanged(MapMode oldMapMode, MapMode newMapMode) {
610 for (MapModeChangeListener l : mapModeChangeListeners) {
611 l.mapModeChange(oldMapMode, newMapMode);
612 }
613 }
614
615 @Override
616 public void activeLayerChange(Layer oldLayer, Layer newLayer) {
617 boolean modeChanged = false;
618 if (mapMode == null || !mapMode.layerIsSupported(newLayer)) {
619 MapMode newMapMode = getLastMapMode(newLayer);
620 modeChanged = newMapMode != mapMode;
621 if (newMapMode != null) {
622 selectMapMode(newMapMode, newLayer); // it would be nice to select first supported mode when layer is first selected, but it don't work well with for example editgpx layer
623 } else if (mapMode != null) {
624 mapMode.exitMode(); // if new mode is null - simply exit from previous mode
625 }
626 }
627 if (!modeChanged && mapMode != null) {
628 // Let mapmodes know about new active layer
629 mapMode.exitMode();
630 mapMode.enterMode();
631 }
632 // invalidate repaint cache
633 Main.map.mapView.preferenceChanged(null);
634
635 // After all listeners notice new layer, some buttons will be disabled/enabled
636 // and possibly need to be hidden/shown.
637 SwingUtilities.invokeLater(new Runnable() {
638 public void run() {
639 validateToolBarsVisibility();
640 }
641 });
642 }
643
644
645 private MapMode getLastMapMode(Layer newLayer) {
646 MapMode mode = lastMapMode.get(newLayer);
647 if (mode == null) {
648 // if no action is selected - try to select default action
649 Action defaultMode = getDefaultButtonAction();
650 if (defaultMode instanceof MapMode && ((MapMode)defaultMode).layerIsSupported(newLayer)) {
651 mode = (MapMode) defaultMode;
652 }
653 }
654 return mode;
655 }
656
657 @Override
658 public void layerAdded(Layer newLayer) { }
659
660 @Override
661 public void layerRemoved(Layer oldLayer) {
662 lastMapMode.remove(oldLayer);
663 }
664}
Note: See TracBrowser for help on using the repository browser.