org.openstreetmap.josm.gui.tagging
Class TaggingPreset

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by org.openstreetmap.josm.gui.tagging.TaggingPreset
All Implemented Interfaces:
java.awt.event.ActionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action, MapView.LayerChangeListener
Direct Known Subclasses:
TaggingPresetMenu, TaggingPresetSeparator

public class TaggingPreset
extends javax.swing.AbstractAction
implements MapView.LayerChangeListener

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.

See Also:
Serialized Form

Nested Class Summary
static class TaggingPreset.Check
           
static class TaggingPreset.Combo
           
static class TaggingPreset.ComboMultiSelect
           
static class TaggingPreset.ConcatenatingJList
          Class that allows list values to be assigned and retrieved as a comma-delimited string.
static class TaggingPreset.Item
           
static class TaggingPreset.Key
           
static class TaggingPreset.KeyedItem
           
static class TaggingPreset.Label
           
static class TaggingPreset.Link
           
private static class TaggingPreset.MatchType
          Enum denoting how a match (see TaggingPreset.Item.matches(java.util.Map)) is performed.
static class TaggingPreset.MultiSelect
           
static class TaggingPreset.Optional
           
static class TaggingPreset.PresetListEntry
           
private static class TaggingPreset.PresetPanel
           
static class TaggingPreset.PresetType
           
static class TaggingPreset.Role
           
static class TaggingPreset.Roles
           
static class TaggingPreset.Space
           
static class TaggingPreset.Text
           
static class TaggingPreset.Usage
           
 
Field Summary
 java.util.List<TaggingPreset.Item> data
           
static int DIALOG_ANSWER_APPLY
           
static int DIALOG_ANSWER_CANCEL
           
static int DIALOG_ANSWER_NEW_RELATION
           
static java.lang.String DIFFERENT
           
 TaggingPresetMenu group
           
private static java.util.HashMap<java.lang.String,java.lang.String> lastValue
           
 java.lang.String locale_name
           
 java.lang.String name
           
 java.lang.String name_context
           
 TemplateEntry nameTemplate
           
 SearchCompiler.Match nameTemplateFilter
           
static java.lang.String OPTIONAL_TOOLTIP_TEXT
           
private  boolean originalSelectionEmpty
          True whenever the original selection given into createSelection was empty
private static BooleanProperty PROP_FILL_DEFAULT
           
private static java.util.Map<java.lang.String,java.util.EnumSet<TaggingPreset.PresetType>> typeCache
           
 java.util.EnumSet<TaggingPreset.PresetType> types
          The types as preparsed collection.
private static java.io.File zipIcons
           
 
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
TaggingPreset()
          Create an empty tagging preset.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
 void activeLayerChange(Layer oldLayer, Layer newLayer)
          Notifies this listener that the active layer has changed.
static Command createCommand(java.util.Collection<OsmPrimitive> sel, java.util.List<Tag> changedTags)
           
 TaggingPreset.PresetPanel createPanel(java.util.Collection<OsmPrimitive> selected)
           
 java.util.Collection<OsmPrimitive> createSelection(java.util.Collection<OsmPrimitive> participants)
          Removes all unsuitable OsmPrimitives from the given list
(package private) static TaggingPreset.Usage determineBooleanUsage(java.util.Collection<OsmPrimitive> sel, java.lang.String key)
           
(package private) static TaggingPreset.Usage determineTextUsage(java.util.Collection<OsmPrimitive> sel, java.lang.String key)
           
private static java.lang.String fixPresetString(java.lang.String s)
           
 java.util.List<Tag> getChangedTags()
           
 java.lang.String getLocaleName()
           
 java.lang.String getName()
           
static java.util.LinkedList<java.lang.String> getPresetSources()
           
 java.lang.String getRawName()
           
static java.util.EnumSet<TaggingPreset.PresetType> getType(java.lang.String types)
           
 boolean isShowable()
           
 void layerAdded(Layer newLayer)
          Notifies this listener that a layer has been added.
 void layerRemoved(Layer oldLayer)
          Notifies this listener that a layer has been removed.
protected static javax.swing.ImageIcon loadImageIcon(java.lang.String iconName, java.io.File zipIcons)
           
 boolean matches(java.util.Collection<TaggingPreset.PresetType> t, java.util.Map<java.lang.String,java.lang.String> tags, boolean onlyShowable)
           
static java.util.Collection<TaggingPreset> readAll(java.util.Collection<java.lang.String> sources, boolean validate)
           
static java.util.List<TaggingPreset> readAll(java.io.Reader in, boolean validate)
           
static java.util.Collection<TaggingPreset> readAll(java.lang.String source, boolean validate)
           
static java.util.Collection<TaggingPreset> readFromPreferences(boolean validate)
           
 void setDisplayName()
          Change the display name without changing the toolbar value.
 void setIcon(java.lang.String iconName)
           
 void setName_template_filter(java.lang.String filter)
           
 void setName_template(java.lang.String pattern)
           
 void setType(java.lang.String types)
           
 int showDialog(java.util.Collection<OsmPrimitive> sel, boolean showNewRelation)
           
private static java.lang.String[] splitEscaped(char delimiter, java.lang.String s)
          allow escaped comma in comma separated list: "A\, B\, C,one\, two" --> ["A, B, C", "one, two"]
private  boolean supportsRelation()
           
 java.lang.String toString()
           
 boolean typeMatches(java.util.Collection<TaggingPreset.PresetType> t)
           
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
 

Field Detail

DIALOG_ANSWER_APPLY

public static final int DIALOG_ANSWER_APPLY
See Also:
Constant Field Values

DIALOG_ANSWER_NEW_RELATION

public static final int DIALOG_ANSWER_NEW_RELATION
See Also:
Constant Field Values

DIALOG_ANSWER_CANCEL

public static final int DIALOG_ANSWER_CANCEL
See Also:
Constant Field Values

group

public TaggingPresetMenu group

name

public java.lang.String name

name_context

public java.lang.String name_context

locale_name

public java.lang.String locale_name

OPTIONAL_TOOLTIP_TEXT

public static final java.lang.String OPTIONAL_TOOLTIP_TEXT
See Also:
Constant Field Values

zipIcons

private static java.io.File zipIcons

PROP_FILL_DEFAULT

private static final BooleanProperty PROP_FILL_DEFAULT

DIFFERENT

public static final java.lang.String DIFFERENT

types

public java.util.EnumSet<TaggingPreset.PresetType> types
The types as preparsed collection.


data

public java.util.List<TaggingPreset.Item> data

nameTemplate

public TemplateEntry nameTemplate

nameTemplateFilter

public SearchCompiler.Match nameTemplateFilter

lastValue

private static java.util.HashMap<java.lang.String,java.lang.String> lastValue

typeCache

private static final java.util.Map<java.lang.String,java.util.EnumSet<TaggingPreset.PresetType>> typeCache

originalSelectionEmpty

private boolean originalSelectionEmpty
True whenever the original selection given into createSelection was empty

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

determineTextUsage

static TaggingPreset.Usage determineTextUsage(java.util.Collection<OsmPrimitive> sel,
                                              java.lang.String key)

determineBooleanUsage

static TaggingPreset.Usage determineBooleanUsage(java.util.Collection<OsmPrimitive> sel,
                                                 java.lang.String key)

splitEscaped

private static java.lang.String[] splitEscaped(char delimiter,
                                               java.lang.String s)
allow escaped comma in comma separated list: "A\, B\, C,one\, two" --> ["A, B, C", "one, two"]

Parameters:
delimiter - the delimiter, e.g. a comma. separates the entries and must be escaped within one entry
s - the string

setDisplayName

public void setDisplayName()
Change the display name without changing the toolbar value.


getLocaleName

public java.lang.String getLocaleName()

getName

public java.lang.String getName()

getRawName

public java.lang.String getRawName()

loadImageIcon

protected static javax.swing.ImageIcon loadImageIcon(java.lang.String iconName,
                                                     java.io.File zipIcons)

setIcon

public void setIcon(java.lang.String iconName)

getType

public static java.util.EnumSet<TaggingPreset.PresetType> getType(java.lang.String types)
                                                           throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

setType

public void setType(java.lang.String types)
             throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

setName_template

public void setName_template(java.lang.String pattern)
                      throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

setName_template_filter

public void setName_template_filter(java.lang.String filter)
                             throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

readAll

public static java.util.List<TaggingPreset> readAll(java.io.Reader in,
                                                    boolean validate)
                                             throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

readAll

public static java.util.Collection<TaggingPreset> readAll(java.lang.String source,
                                                          boolean validate)
                                                   throws org.xml.sax.SAXException,
                                                          java.io.IOException
Throws:
org.xml.sax.SAXException
java.io.IOException

readAll

public static java.util.Collection<TaggingPreset> readAll(java.util.Collection<java.lang.String> sources,
                                                          boolean validate)

getPresetSources

public static java.util.LinkedList<java.lang.String> getPresetSources()

readFromPreferences

public static java.util.Collection<TaggingPreset> readFromPreferences(boolean validate)

createPanel

public TaggingPreset.PresetPanel createPanel(java.util.Collection<OsmPrimitive> selected)

isShowable

public boolean isShowable()

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

showDialog

public int showDialog(java.util.Collection<OsmPrimitive> sel,
                      boolean showNewRelation)

createSelection

public java.util.Collection<OsmPrimitive> createSelection(java.util.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 java.util.List<Tag> getChangedTags()

fixPresetString

private static java.lang.String fixPresetString(java.lang.String s)

createCommand

public static Command createCommand(java.util.Collection<OsmPrimitive> sel,
                                    java.util.List<Tag> changedTags)

supportsRelation

private boolean supportsRelation()

updateEnabledState

protected void updateEnabledState()

activeLayerChange

public void activeLayerChange(Layer oldLayer,
                              Layer newLayer)
Description copied from interface: MapView.LayerChangeListener
Notifies this listener that the active layer has changed.

Specified by:
activeLayerChange in interface MapView.LayerChangeListener
Parameters:
oldLayer - The previous active layer
newLayer - The new activer layer

layerAdded

public void layerAdded(Layer newLayer)
Description copied from interface: MapView.LayerChangeListener
Notifies this listener that a layer has been added.

Specified by:
layerAdded in interface MapView.LayerChangeListener
Parameters:
newLayer - The new added layer

layerRemoved

public void layerRemoved(Layer oldLayer)
Description copied from interface: MapView.LayerChangeListener
Notifies this listener that a layer has been removed.

Specified by:
layerRemoved in interface MapView.LayerChangeListener
Parameters:
oldLayer - The old removed layer

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

typeMatches

public boolean typeMatches(java.util.Collection<TaggingPreset.PresetType> t)

matches

public boolean matches(java.util.Collection<TaggingPreset.PresetType> t,
                       java.util.Map<java.lang.String,java.lang.String> tags,
                       boolean onlyShowable)


JOSM