1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions.audio;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
5 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
6 | import org.openstreetmap.josm.gui.layer.markerlayer.AudioMarker;
|
---|
7 | import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
|
---|
8 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * Base class for every action related to audio content.
|
---|
12 | * @since 12565
|
---|
13 | */
|
---|
14 | public 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 | protected 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 boolean listenToSelectionChange() {
|
---|
42 | return false;
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | protected void updateEnabledState() {
|
---|
47 | setEnabled(isAudioMarkerPresent());
|
---|
48 | }
|
---|
49 | }
|
---|