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

Last change on this file since 5448 was 5448, checked in by Don-vip, 12 years ago

Prevents MapView from being repainted multiple times when adding the first active layer

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