Class ComboMultiSelect
- java.lang.Object
-
- org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem
-
- org.openstreetmap.josm.gui.tagging.presets.items.TextItem
-
- org.openstreetmap.josm.gui.tagging.presets.items.KeyedItem
-
- org.openstreetmap.josm.gui.tagging.presets.items.ComboMultiSelect
-
- Direct Known Subclasses:
Combo
,MultiSelect
public abstract class ComboMultiSelect extends KeyedItem
Abstract superclass for combo box and multi-select list types.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
ComboMultiSelect.ComboMultiSelectListCellRenderer
A list cell renderer that paints a short text in the current value pane and and a longer text in the dropdown list.-
Nested classes/interfaces inherited from class org.openstreetmap.josm.gui.tagging.presets.items.KeyedItem
KeyedItem.MatchType, KeyedItem.Usage
-
-
Field Summary
Fields Modifier and Type Field Description String
default_
The default value for the item.char
delimiter
The character that separates values.String
display_values
A list of entries that is displayed to the user.String
locale_display_values
The localized version ofdisplay_values
.String
locale_short_descriptions
The localized version ofshort_descriptions
.protected String
originalValue
Used to see if the user edited the value.protected List<PresetListEntry>
presetListEntries
The standard entries in the combobox dropdown or multiselect list.protected Map<String,PresetListEntry>
seenValues
Helps avoid duplicate list entriesString
short_descriptions
A delimiter-separated list of texts to be displayed below eachdisplay_value
.protected KeyedItem.Usage
usage
byte
use_last_as_default
whether the last value is used as default.String
values
A list of entries.String
values_context
The context used for translatingvalues
String
values_from
To use instead ofvalues
if the list of values has to be obtained with a Java method of this form:boolean
values_no_i18n
Disabled internationalisation for value to avoid mistakes, see #11696boolean
values_searchable
whether to use values for search viaTaggingPresetSelector
boolean
values_sort
Whether to sort the values, defaults to true.-
Fields inherited from class org.openstreetmap.josm.gui.tagging.presets.items.KeyedItem
DIFFERENT, DIFFERENT_I18N, key, LAST_VALUES, match, PROP_FILL_DEFAULT
-
Fields inherited from class org.openstreetmap.josm.gui.tagging.presets.items.TextItem
icon, icon_size, locale_text, text, text_context
-
Fields inherited from class org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem
DISPLAY_KEYS_AS_HINT
-
-
Constructor Summary
Constructors Constructor Description ComboMultiSelect()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addCommands(List<Tag> changedTags)
Adds the new tags to apply to selected OSM primitives when the preset holding this item is applied.protected JLabel
addLabel(JPanel p)
Adds the label to the panelvoid
addListEntries(Collection<PresetListEntry> e)
Adds a collection of preset list entries.void
addListEntry(PresetListEntry e)
Adds a preset list entry.private List<String>
checkListsSameLength(List<String> a, List<String> b, String name)
Checks if lista
is either null or the same length as listb
.KeyedItem.MatchType
getDefaultMatch()
Returns the default match.Collection<String>
getDisplayValues()
Returns the values to display.protected String
getInitialValue(KeyedItem.Usage usage, TaggingPresetItemGuiSupport support)
Returns the initial value to use for this preset.protected abstract PresetListEntry
getSelectedItem()
Returns the value selected in the combobox or a synthetic value if a multiselect.Collection<String>
getValues()
Returns the list of values.private List<String>
getValuesFromCode(String valuesFrom)
protected void
initListEntries()
protected void
initListEntriesFromAttributes()
protected boolean
isForceUseLastAsDefault()
Returns true if the last entered value should be used as default also on primitives that already have tags.protected boolean
isUseLastAsDefault()
Returns true if the last entered value should be used as default.void
setUse_last_as_default(String v)
Sets whether the last value is used as default.static List<String>
splitEscaped(char delimiter, String s)
allow escaped comma in comma separated list: "A\, B\, C,one\, two" --> ["A, B, C", "one, two"]-
Methods inherited from class org.openstreetmap.josm.gui.tagging.presets.items.KeyedItem
determineBooleanUsage, determineTextUsage, getKeyTooltipText, getPopupMenu, isKeyRequired, matches, toString
-
Methods inherited from class org.openstreetmap.josm.gui.tagging.presets.items.TextItem
addIcon, fieldsToString, getIcon, initializeLocaleText
-
Methods inherited from class org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem
addToPanel, fixPresetString, getAllForKeys, getLocaleText, getType, initAutoCompletionField, initAutoCompletionField, loadImageIcon, matches, parseInteger
-
-
-
-
Field Detail
-
values
public String values
A list of entries. The list has to be separated by commas (for theCombo
box) or by the specified delimiter (for theMultiSelect
). If a value contains the delimiter, the delimiter may be escaped with a backslash. If a value contains a backslash, it must also be escaped with a backslash.
-
values_from
public String values_from
To use instead ofvalues
if the list of values has to be obtained with a Java method of this form:public static String[] getValues();
The value must be:
full.package.name.ClassName#methodName
.
-
values_context
public String values_context
The context used for translatingvalues
-
values_no_i18n
public boolean values_no_i18n
Disabled internationalisation for value to avoid mistakes, see #11696
-
values_sort
public boolean values_sort
Whether to sort the values, defaults to true.
-
display_values
public String display_values
-
locale_display_values
public String locale_display_values
The localized version ofdisplay_values
.
-
short_descriptions
public String short_descriptions
A delimiter-separated list of texts to be displayed below eachdisplay_value
. (Only if it is not possible to describe the entry in 2-3 words.) Instead of comma separated list instead usingvalues
,display_values
andshort_descriptions
, the following form is also supported:<list_entry value="" display_value="" short_description="" icon="" icon_size="" />
-
locale_short_descriptions
public String locale_short_descriptions
The localized version ofshort_descriptions
.
-
default_
public String default_
The default value for the item. If not specified, the current value of the key is chosen as default (if applicable).
-
delimiter
public char delimiter
The character that separates values. In case ofCombo
the default is comma. In case ofMultiSelect
the default is semicolon and this will also be used to separate selected values in the tag.
-
use_last_as_default
public byte use_last_as_default
whether the last value is used as default. Using "force" (2) enforces this behaviour also for already tagged objects. Default is "false" (0).
-
values_searchable
public boolean values_searchable
whether to use values for search viaTaggingPresetSelector
-
presetListEntries
protected final List<PresetListEntry> presetListEntries
The standard entries in the combobox dropdown or multiselect list. These entries are defined indefaultpresets.xml
(or in other custom preset files).
-
seenValues
protected final Map<String,PresetListEntry> seenValues
Helps avoid duplicate list entries
-
usage
protected KeyedItem.Usage usage
-
originalValue
protected String originalValue
Used to see if the user edited the value.
-
-
Constructor Detail
-
ComboMultiSelect
public ComboMultiSelect()
-
-
Method Detail
-
splitEscaped
public static List<String> splitEscaped(char delimiter, 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 entrys
- the string- Returns:
- splitted items
-
getSelectedItem
protected abstract PresetListEntry getSelectedItem()
Returns the value selected in the combobox or a synthetic value if a multiselect.- Returns:
- the value
-
getValues
public Collection<String> getValues()
Description copied from class:KeyedItem
Returns the list of values.
-
getDisplayValues
public Collection<String> getDisplayValues()
Returns the values to display.- Returns:
- the values to display
-
addLabel
protected JLabel addLabel(JPanel p)
Adds the label to the panel- Parameters:
p
- the panel- Returns:
- the label
-
initListEntries
protected void initListEntries()
-
getValuesFromCode
private List<String> getValuesFromCode(String valuesFrom)
-
checkListsSameLength
private List<String> checkListsSameLength(List<String> a, List<String> b, String name)
Checks if lista
is either null or the same length as listb
.- Parameters:
a
- The list to checkb
- The other listname
- The name of the list for error reporting- Returns:
a
if both lists have the same length ornull
-
initListEntriesFromAttributes
protected void initListEntriesFromAttributes()
-
getInitialValue
protected String getInitialValue(KeyedItem.Usage usage, TaggingPresetItemGuiSupport support)
Returns the initial value to use for this preset.The initial value is the value shown in the control when the preset dialog opens. For a discussion of all the options see the enclosed tickets.
- Parameters:
usage
- The key Usagesupport
- The support- Returns:
- The initial value to use.
- See Also:
- "https://josm.openstreetmap.de/ticket/5564", "https://josm.openstreetmap.de/ticket/12733", "https://josm.openstreetmap.de/ticket/17324"
-
addCommands
public void addCommands(List<Tag> changedTags)
Description copied from class:TaggingPresetItem
Adds the new tags to apply to selected OSM primitives when the preset holding this item is applied.- Overrides:
addCommands
in classTextItem
- Parameters:
changedTags
- The list of changed tags to modify if needed
-
setUse_last_as_default
public void setUse_last_as_default(String v)
Sets whether the last value is used as default.- Parameters:
v
- Using "force" (2) enforces this behaviour also for already tagged objects. Default is "false" (0).
-
isUseLastAsDefault
protected boolean isUseLastAsDefault()
Returns true if the last entered value should be used as default.Note: never used in
defaultpresets.xml
.- Returns:
- true if the last entered value should be used as default.
-
isForceUseLastAsDefault
protected boolean isForceUseLastAsDefault()
Returns true if the last entered value should be used as default also on primitives that already have tags.Note: used for
addr:*
tags indefaultpresets.xml
.- Returns:
- true if see above
-
addListEntry
public void addListEntry(PresetListEntry e)
Adds a preset list entry.- Parameters:
e
- list entry to add
-
addListEntries
public void addListEntries(Collection<PresetListEntry> e)
Adds a collection of preset list entries.- Parameters:
e
- list entries to add
-
getDefaultMatch
public KeyedItem.MatchType getDefaultMatch()
Description copied from class:KeyedItem
Returns the default match.- Specified by:
getDefaultMatch
in classKeyedItem
- Returns:
- the default match
-
-