source: josm/trunk/src/org/openstreetmap/josm/actions/audio/AbstractAudioAction.java@ 12636

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

see #15182 - deprecate Main.getLayerManager(). Replacement: gui.MainApplication.getLayerManager()

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions.audio;
3
4import org.openstreetmap.josm.actions.JosmAction;
5import org.openstreetmap.josm.gui.MainApplication;
6import org.openstreetmap.josm.gui.layer.markerlayer.AudioMarker;
7import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
8import org.openstreetmap.josm.tools.Shortcut;
9
10/**
11 * Base class for every action related to audio content.
12 * @since 12565
13 */
14public abstract class AbstractAudioAction extends JosmAction {
15
16 /**
17 * Constructs a new {@code BaseAudioAction}.
18 * @param name the action's text as displayed on the menu (if it is added to a menu)
19 * @param iconName the filename of the icon to use
20 * @param tooltip a longer description of the action that will be displayed in the tooltip
21 * @param shortcut a ready-created shortcut object or null if you don't want a shortcut
22 * @param registerInToolbar register this action for the toolbar preferences?
23 */
24 public AbstractAudioAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean registerInToolbar) {
25 super(name, iconName, tooltip, shortcut, registerInToolbar);
26 updateEnabledState();
27 }
28
29 /**
30 * Checks if there is at least one {@link AudioMarker} is present in the current layout.
31 * @return {@code true} if at least one {@link AudioMarker} is present in the current
32 * layout, {@code false} otherwise.
33 */
34 protected static boolean isAudioMarkerPresent() {
35 return MainApplication.getLayerManager().getLayersOfType(MarkerLayer.class).stream()
36 .flatMap(ml -> ml.data.stream())
37 .anyMatch(m -> m instanceof AudioMarker);
38 }
39
40 @Override
41 protected void updateEnabledState() {
42 setEnabled(isAudioMarkerPresent());
43 }
44}
Note: See TracBrowser for help on using the repository browser.