Class TaggingPreset
- java.lang.Object
-
- javax.swing.AbstractAction
-
- org.openstreetmap.josm.gui.tagging.presets.TaggingPreset
-
- All Implemented Interfaces:
ActionListener
,Serializable
,Cloneable
,EventListener
,Predicate<IPrimitive>
,Action
,AdaptableAction
,MainLayerManager.ActiveLayerChangeListener
- Direct Known Subclasses:
TaggingPresetMenu
,TaggingPresetSeparator
public class TaggingPreset extends AbstractAction implements MainLayerManager.ActiveLayerChangeListener, AdaptableAction, Predicate<IPrimitive>
This class read encapsulate one tagging preset. A class method can read in all predefined presets, either shipped with JOSM or that are in the config directory. It is also able to construct dialogs out of preset definitions.- Since:
- 294
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
TaggingPreset.PresetDialog
private static class
TaggingPreset.PresetPanel
class
TaggingPreset.ToolbarButtonAction
Action that adds or removes the button on main toolbar
-
Field Summary
Fields Modifier and Type Field Description List<TaggingPresetItem>
data
The list of preset itemsstatic int
DIALOG_ANSWER_APPLY
The user pressed the "Apply" buttonstatic int
DIALOG_ANSWER_CANCEL
The user pressed the "Cancel" buttonstatic int
DIALOG_ANSWER_NEW_RELATION
The user pressed the "New Relation" buttonTaggingPresetMenu
group
The preset group this preset belongs to.private CompletableFuture<Void>
iconFuture
The completable future task of asynchronous icon loadingString
iconName
The icon name assigned to this preset.protected TaggingPresetItemGuiSupport
itemGuiSupport
Support functionsString
locale_name
A cache for the local name.SearchCompiler.Match
matchExpression
The match_expressionString
name
The name of the tagging preset.String
name_context
Translation context for nameTemplateEntry
nameTemplate
The name_template custom name formatter.SearchCompiler.Match
nameTemplateFilter
The name_template_filterstatic String
OPTIONAL_TOOLTIP_TEXT
The action key for optional tooltipsprivate boolean
originalSelectionEmpty
True whenever the original selection given into createSelection was emptystatic String
PRESET_ICON_ERROR_MSG_PREFIX
Prefix of preset icon loading failure error messageboolean
preset_name_label
Show the preset name if trueRoles
roles
The roles for this relation (if we are editing a relation).Set<TaggingPresetType>
types
The types as preparsed collection.static BooleanProperty
USE_VALIDATOR
Defines whether the validator should be active in the preset dialog-
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
-
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON
-
-
Constructor Summary
Constructors Constructor Description TaggingPreset()
Create an empty tagging preset.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(ActionEvent e)
void
activeOrEditLayerChanged(MainLayerManager.ActiveLayerChangeEvent e)
Called whenever the active or edit layer changed.static Command
createCommand(Collection<OsmPrimitive> sel, List<Tag> changedTags)
Create a command to change the given list of tags.TaggingPreset.PresetPanel
createPanel(Collection<OsmPrimitive> selected)
Creates a panel for this preset.Collection<OsmPrimitive>
createSelection(Collection<OsmPrimitive> participants)
Removes all unsuitable OsmPrimitives from the given listList<Tag>
getChangedTags()
Gets a list of tags that are set by this preset.ImageIcon
getIcon()
Returns the preset icon (16px).ImageIcon
getIcon(String key)
Returns the preset icon (16 or 24px).CompletableFuture<Void>
getIconLoadingTask()
Returns the completable future task that performs icon loading, if any.ImageResource
getImageResource()
Returns theImageResource
attached to this preset, if any.String
getLocaleName()
Gets the localized version of the nameString
getName()
Returns the translated name of this preset, prefixed with the group names it belongs to.String
getRawName()
Returns the non translated name of this preset, prefixed with the (non translated) group names it belongs to.String
getToolbarString()
Gets a string describing this preset that can be used for the toolbarboolean
isShowable()
Determines whether a dialog can be shown for this preset, i.e., at least one tag can/must be set by the user.boolean
matches(Collection<TaggingPresetType> t, Map<String,String> tags, boolean onlyShowable)
Determines whether this preset matches the parameters.void
setDisplayName()
Change the display name without changing the toolbar value.void
setIcon(String iconName)
Called from the XML parser to set the icon.void
setMatch_expression(String filter)
Sets the match_expression additional criteria for matching primitives.void
setName_template(String template)
Sets the name_template custom name formatter.void
setName_template_filter(String filter)
Sets the name_template_filter.void
setType(String types)
Called from the XML parser to set the types this preset affects.void
showAndApply(Collection<OsmPrimitive> primitives)
Show preset dialog, apply changesint
showDialog(Collection<OsmPrimitive> sel, boolean showNewRelation)
Shows the preset dialog.String
suggestRoleForOsmPrimitive(OsmPrimitive osm)
Suggests a relation role for this primitiveprivate boolean
supportsRelation()
boolean
test(IPrimitive p)
Determines whether this preset matches the given primitive, i.e., whether thetype matches
and thetags match
.String
toString()
boolean
typeMatches(Collection<TaggingPresetType> t)
Determines whether this preset matches the types.boolean
typeMatches(IPrimitive primitive)
Determines whether this preset matches the OSM primitive type.protected void
updateEnabledState()
-
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface javax.swing.Action
accept, addPropertyChangeListener, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
-
-
-
-
Field Detail
-
DIALOG_ANSWER_APPLY
public static final int DIALOG_ANSWER_APPLY
The user pressed the "Apply" button- See Also:
- Constant Field Values
-
DIALOG_ANSWER_NEW_RELATION
public static final int DIALOG_ANSWER_NEW_RELATION
The user pressed the "New Relation" button- See Also:
- Constant Field Values
-
DIALOG_ANSWER_CANCEL
public static final int DIALOG_ANSWER_CANCEL
The user pressed the "Cancel" button- See Also:
- Constant Field Values
-
OPTIONAL_TOOLTIP_TEXT
public static final String OPTIONAL_TOOLTIP_TEXT
The action key for optional tooltips- See Also:
- Constant Field Values
-
PRESET_ICON_ERROR_MSG_PREFIX
public static final String PRESET_ICON_ERROR_MSG_PREFIX
Prefix of preset icon loading failure error message- See Also:
- Constant Field Values
-
USE_VALIDATOR
public static final BooleanProperty USE_VALIDATOR
Defines whether the validator should be active in the preset dialog- See Also:
TaggingPresetValidation
-
group
public TaggingPresetMenu group
The preset group this preset belongs to.
-
name
public String name
The name of the tagging preset.- See Also:
getRawName()
-
name_context
public String name_context
Translation context for name
-
locale_name
public String locale_name
A cache for the local name. Should never be accessed directly.- See Also:
getLocaleName()
-
preset_name_label
public boolean preset_name_label
Show the preset name if true
-
types
public transient Set<TaggingPresetType> types
The types as preparsed collection.
-
data
public final transient List<TaggingPresetItem> data
The list of preset items
-
roles
public transient Roles roles
The roles for this relation (if we are editing a relation). See: JOSM wiki
-
nameTemplate
public transient TemplateEntry nameTemplate
The name_template custom name formatter. See: JOSM wiki
-
nameTemplateFilter
public transient SearchCompiler.Match nameTemplateFilter
The name_template_filter
-
matchExpression
public transient SearchCompiler.Match matchExpression
The match_expression
-
originalSelectionEmpty
private boolean originalSelectionEmpty
True whenever the original selection given into createSelection was empty
-
iconFuture
private CompletableFuture<Void> iconFuture
The completable future task of asynchronous icon loading
-
itemGuiSupport
protected TaggingPresetItemGuiSupport itemGuiSupport
Support functions
-
-
Constructor Detail
-
TaggingPreset
public TaggingPreset()
Create an empty tagging preset. This will not have any items and will be an empty string as text. createPanel will return null. Use this as default item for "do not select anything".
-
-
Method Detail
-
setDisplayName
public void setDisplayName()
Change the display name without changing the toolbar value.
-
getLocaleName
public String getLocaleName()
Gets the localized version of the name- Returns:
- The name that should be displayed to the user.
-
getName
public String getName()
Returns the translated name of this preset, prefixed with the group names it belongs to.- Returns:
- the translated name of this preset, prefixed with the group names it belongs to
-
getRawName
public String getRawName()
Returns the non translated name of this preset, prefixed with the (non translated) group names it belongs to.- Returns:
- the non translated name of this preset, prefixed with the (non translated) group names it belongs to
-
getIcon
public final ImageIcon getIcon()
Returns the preset icon (16px).- Returns:
- The preset icon, or
null
if none defined - Since:
- 6403
-
getIcon
public final ImageIcon getIcon(String key)
Returns the preset icon (16 or 24px).- Parameters:
key
- Key determining icon size:Action.SMALL_ICON
for 16x,Action.LARGE_ICON_KEY
for 24px- Returns:
- The preset icon, or
null
if none defined - Since:
- 10849
-
getImageResource
public final ImageResource getImageResource()
Returns theImageResource
attached to this preset, if any.- Returns:
- the
ImageResource
attached to this preset, ornull
- Since:
- 16060
-
setIcon
public void setIcon(String iconName)
Called from the XML parser to set the icon. The loading task is performed in the background in order to speedup startup.- Parameters:
iconName
- icon name
-
setType
public void setType(String types) throws SAXException
Called from the XML parser to set the types this preset affects.- Parameters:
types
- comma-separated primitive types ("node", "way", "relation" or "closedway")- Throws:
SAXException
- if any SAX error occurs- See Also:
TaggingPresetType.fromString(java.lang.String)
-
setName_template
public void setName_template(String template) throws SAXException
Sets the name_template custom name formatter.- Parameters:
template
- The format template- Throws:
SAXException
- on template parse error- See Also:
- JOSM wiki
-
setName_template_filter
public void setName_template_filter(String filter) throws SAXException
Sets the name_template_filter.- Parameters:
filter
- The search pattern- Throws:
SAXException
- on search patern parse error- See Also:
- JOSM wiki
-
setMatch_expression
public void setMatch_expression(String filter) throws SAXException
Sets the match_expression additional criteria for matching primitives.- Parameters:
filter
- The search pattern- Throws:
SAXException
- on search patern parse error- See Also:
- JOSM wiki
-
createPanel
public TaggingPreset.PresetPanel createPanel(Collection<OsmPrimitive> selected)
Creates a panel for this preset. This includes general information such as name and supportedtypes
. This includes the elements from the individualitems
.- Parameters:
selected
- the selected primitives- Returns:
- the newly created panel
-
isShowable
public boolean isShowable()
Determines whether a dialog can be shown for this preset, i.e., at least one tag can/must be set by the user.- Returns:
true
if a dialog can be shown for this preset
-
suggestRoleForOsmPrimitive
public String suggestRoleForOsmPrimitive(OsmPrimitive osm)
Suggests a relation role for this primitive- Parameters:
osm
- The primitive- Returns:
- the suggested role or null
-
actionPerformed
public void actionPerformed(ActionEvent e)
- Specified by:
actionPerformed
in interfaceActionListener
-
showAndApply
public void showAndApply(Collection<OsmPrimitive> primitives)
Show preset dialog, apply changes- Parameters:
primitives
- the primitives
-
showDialog
public int showDialog(Collection<OsmPrimitive> sel, boolean showNewRelation)
Shows the preset dialog.- Parameters:
sel
- selectionshowNewRelation
- whether to display "New relation" button- Returns:
- the user choice after the dialog has been closed
-
createSelection
public Collection<OsmPrimitive> createSelection(Collection<OsmPrimitive> participants)
Removes all unsuitable OsmPrimitives from the given list- Parameters:
participants
- List of possible OsmPrimitives to tag- Returns:
- Cleaned list with suitable OsmPrimitives only
-
getChangedTags
public List<Tag> getChangedTags()
Gets a list of tags that are set by this preset.- Returns:
- The list of tags.
-
createCommand
public static Command createCommand(Collection<OsmPrimitive> sel, List<Tag> changedTags)
Create a command to change the given list of tags.- Parameters:
sel
- The primitives to change the tags forchangedTags
- The tags to change- Returns:
- A command that changes the tags.
-
supportsRelation
private boolean supportsRelation()
-
updateEnabledState
protected final void updateEnabledState()
-
activeOrEditLayerChanged
public void activeOrEditLayerChanged(MainLayerManager.ActiveLayerChangeEvent e)
Description copied from interface:MainLayerManager.ActiveLayerChangeListener
Called whenever the active or edit layer changed.You can be sure that this layer is still contained in this set.
Listeners are called in the EDT thread and you can manipulate the layer manager in the current thread.
- Specified by:
activeOrEditLayerChanged
in interfaceMainLayerManager.ActiveLayerChangeListener
- Parameters:
e
- The change event.
-
typeMatches
public final boolean typeMatches(IPrimitive primitive)
Determines whether this preset matches the OSM primitive type.- Parameters:
primitive
- The OSM primitive for which type must match- Returns:
true
if type matches.- Since:
- 15640
-
typeMatches
public boolean typeMatches(Collection<TaggingPresetType> t)
Determines whether this preset matches the types.- Parameters:
t
- The types that must match- Returns:
true
if all types match.
-
test
public boolean test(IPrimitive p)
Determines whether this preset matches the given primitive, i.e., whether thetype matches
and thetags match
.- Specified by:
test
in interfacePredicate<IPrimitive>
- Parameters:
p
- the primitive- Returns:
true
if this preset matches the primitive- Since:
- 13623 (signature)
-
matches
public boolean matches(Collection<TaggingPresetType> t, Map<String,String> tags, boolean onlyShowable)
Determines whether this preset matches the parameters.- Parameters:
t
- the preset types to include, seetypeMatches(Collection)
tags
- the tags to perform matching on, seeTaggingPresetItem.matches(Map)
onlyShowable
- whether the preset must beshowable
- Returns:
true
if this preset matches the parameters.
-
getToolbarString
public String getToolbarString()
Gets a string describing this preset that can be used for the toolbar- Returns:
- A String that can be passed on to the toolbar
- See Also:
ToolbarPreferences.addCustomButton(String, int, boolean)
-
getIconLoadingTask
public CompletableFuture<Void> getIconLoadingTask()
Returns the completable future task that performs icon loading, if any.- Returns:
- the completable future task that performs icon loading, or null
- Since:
- 14449
-
-