Class TagEditHelper
- java.lang.Object
-
- org.openstreetmap.josm.gui.dialogs.properties.TagEditHelper
-
public class TagEditHelper extends java.lang.Object
Class that helps PropertiesDialog add and edit tag values.- Since:
- 5633
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
TagEditHelper.AbstractTagsDialog
protected class
TagEditHelper.AddTagsDialog
protected class
TagEditHelper.EditTagDialog
protected static interface
TagEditHelper.IEditTagDialog
Extracted interface ofTagEditHelper.EditTagDialog
.private static class
TagEditHelper.RecentExisting
What to do with recent tags where keys already existprivate static class
TagEditHelper.RefreshRecent
What to do after applying tag(package private) static class
TagEditHelper.TEHListCellRenderer
A custom list cell renderer that adds the value count to some items.
-
Field Summary
Fields Modifier and Type Field Description static BooleanProperty
AUTOCOMPLETE_KEYS
Autocomplete keys by defaultstatic BooleanProperty
AUTOCOMPLETE_VALUES
Autocomplete values by defaultprivate static java.lang.String
CANCEL
private static java.lang.String
CANCEL_TR
private java.lang.String
changedKey
(package private) static java.util.Comparator<AutoCompletionItem>
DEFAULT_AC_ITEM_COMPARATOR
static int
DEFAULT_LRU_TAGS_NUMBER
Default number of recent tagsprivate static java.lang.String
DUMMY
private static java.lang.String
HTML
static int
MAX_LRU_TAGS_NUMBER
Maximum number of recent tagsstatic BooleanProperty
PROPERTY_FIX_TAG_LOCALE
Use English language for tag by defaultstatic EnumProperty<TagEditHelper.RecentExisting>
PROPERTY_RECENT_EXISTING
Preference setting for popup menu item "Recent tags with existing key"static ListProperty
PROPERTY_RECENT_TAGS
The preference storage of recent tagsstatic IntegerProperty
PROPERTY_RECENT_TAGS_NUMBER
Number of recent tagsstatic EnumProperty<TagEditHelper.RefreshRecent>
PROPERTY_REFRESH_RECENT
Preference setting for popup menu item "Refresh recent tags list after applying tag"static BooleanProperty
PROPERTY_REMEMBER_TAGS
Whether recent tags must be rememberedstatic StringProperty
PROPERTY_TAGS_TO_IGNORE
The preference list of tags which should not be remembered, since r9940(package private) RecentTagCollection
recentTags
protected java.util.Collection<OsmPrimitive>
sel
private javax.swing.table.DefaultTableModel
tagData
private java.util.List<Tag>
tags
Copy of recently added tags in sorted from newest to oldest order.(package private) SearchSetting
tagsToIgnore
private javax.swing.JTable
tagTable
private java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Integer>>
valueCount
-
Constructor Summary
Constructors Constructor Description TagEditHelper(javax.swing.JTable tagTable, javax.swing.table.DefaultTableModel propertyData, java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Integer>> valueCount)
Constructs a newTagEditHelper
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTag()
Open the add selection dialog and add a new key/value to the table (and to the dataset, of course).private void
cacheRecentTags()
Update cache of recent tags used for displaying tags.(package private) boolean
containsDataKey(java.lang.String key)
Determines if the given tag key is already used (by all selected primitives, not just some of them)void
editTag(int row, boolean focusOnKey)
Edit the value in the tags table row.protected TagEditHelper.AddTagsDialog
getAddTagsDialog()
Returns a newAddTagsDialog
.private static java.util.List<java.lang.String>
getAutocompletionKeys(java.lang.String key)
For a given key k, return a list of keys which are used as keys for auto-completing values to increase the search space.java.lang.String
getChangedKey()
If during last editProperty call user changed the key name, this key will be returned Elsewhere, returns null.java.lang.String
getDataKey(int viewRow)
Finds the key from given row of tag editor.java.util.Map<java.lang.String,java.lang.Integer>
getDataValues(int viewRow)
Finds the values from given row of tag editor.static java.lang.String
getEditItem(AutoCompComboBox<AutoCompletionItem> cb)
Returns the edited item with whitespaces removedprotected TagEditHelper.IEditTagDialog
getEditTagDialog(int row, boolean focusOnKey, java.lang.String key)
static java.lang.String
getSelectedOrEditItem(AutoCompComboBox<AutoCompletionItem> cb)
Returns the selected item or the edited item as stringvoid
loadTagsIfNeeded()
Load recently used tags from preferences if needed.(package private) void
loadTagsToIgnore()
void
resetChangedKey()
Reset last changed key.void
resetSelection()
Forget recently selected primitives to allow GC.void
saveTagsIfNeeded()
Store recently used tags in preferences if needed.private java.util.Collection<OsmPrimitive>
updateSelection()
Update the current selection for this editorprivate static void
warnAboutParseError(SearchParseError parseError)
private static boolean
warnOverwriteKey(java.lang.String action, java.lang.String togglePref)
Warns user about a key being overwritten.private static boolean
warnSelectionChanged()
Warn user about a selection change
-
-
-
Field Detail
-
tagTable
private final javax.swing.JTable tagTable
-
tagData
private final javax.swing.table.DefaultTableModel tagData
-
valueCount
private final java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Integer>> valueCount
-
sel
protected java.util.Collection<OsmPrimitive> sel
-
changedKey
private java.lang.String changedKey
-
DEFAULT_AC_ITEM_COMPARATOR
static final java.util.Comparator<AutoCompletionItem> DEFAULT_AC_ITEM_COMPARATOR
-
CANCEL_TR
private static final java.lang.String CANCEL_TR
-
CANCEL
private static final java.lang.String CANCEL
- See Also:
- Constant Field Values
-
HTML
private static final java.lang.String HTML
- See Also:
- Constant Field Values
-
DUMMY
private static final java.lang.String DUMMY
- See Also:
- Constant Field Values
-
DEFAULT_LRU_TAGS_NUMBER
public static final int DEFAULT_LRU_TAGS_NUMBER
Default number of recent tags- See Also:
- Constant Field Values
-
MAX_LRU_TAGS_NUMBER
public static final int MAX_LRU_TAGS_NUMBER
Maximum number of recent tags- See Also:
- Constant Field Values
-
AUTOCOMPLETE_KEYS
public static final BooleanProperty AUTOCOMPLETE_KEYS
Autocomplete keys by default
-
AUTOCOMPLETE_VALUES
public static final BooleanProperty AUTOCOMPLETE_VALUES
Autocomplete values by default
-
PROPERTY_FIX_TAG_LOCALE
public static final BooleanProperty PROPERTY_FIX_TAG_LOCALE
Use English language for tag by default
-
PROPERTY_REMEMBER_TAGS
public static final BooleanProperty PROPERTY_REMEMBER_TAGS
Whether recent tags must be remembered
-
PROPERTY_RECENT_TAGS_NUMBER
public static final IntegerProperty PROPERTY_RECENT_TAGS_NUMBER
Number of recent tags
-
PROPERTY_RECENT_TAGS
public static final ListProperty PROPERTY_RECENT_TAGS
The preference storage of recent tags
-
PROPERTY_TAGS_TO_IGNORE
public static final StringProperty PROPERTY_TAGS_TO_IGNORE
The preference list of tags which should not be remembered, since r9940
-
PROPERTY_RECENT_EXISTING
public static final EnumProperty<TagEditHelper.RecentExisting> PROPERTY_RECENT_EXISTING
Preference setting for popup menu item "Recent tags with existing key"
-
PROPERTY_REFRESH_RECENT
public static final EnumProperty<TagEditHelper.RefreshRecent> PROPERTY_REFRESH_RECENT
Preference setting for popup menu item "Refresh recent tags list after applying tag"
-
recentTags
final RecentTagCollection recentTags
-
tagsToIgnore
SearchSetting tagsToIgnore
-
-
Constructor Detail
-
TagEditHelper
public TagEditHelper(javax.swing.JTable tagTable, javax.swing.table.DefaultTableModel propertyData, java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Integer>> valueCount)
Constructs a newTagEditHelper
.- Parameters:
tagTable
- tag tablepropertyData
- table modelvalueCount
- tag value count
-
-
Method Detail
-
getDataKey
public final java.lang.String getDataKey(int viewRow)
Finds the key from given row of tag editor.- Parameters:
viewRow
- index of row- Returns:
- key of tag
-
containsDataKey
boolean containsDataKey(java.lang.String key)
Determines if the given tag key is already used (by all selected primitives, not just some of them)- Parameters:
key
- the key to check- Returns:
true
if the key is used by all selected primitives (key not unset for at least one primitive)
-
getDataValues
public final java.util.Map<java.lang.String,java.lang.Integer> getDataValues(int viewRow)
Finds the values from given row of tag editor.- Parameters:
viewRow
- index of row- Returns:
- map of values and number of occurrences
-
addTag
public void addTag()
Open the add selection dialog and add a new key/value to the table (and to the dataset, of course).
-
getAddTagsDialog
protected TagEditHelper.AddTagsDialog getAddTagsDialog()
Returns a newAddTagsDialog
.- Returns:
- a new
AddTagsDialog
-
editTag
public void editTag(int row, boolean focusOnKey)
Edit the value in the tags table row.- Parameters:
row
- The row of the table from which the value is edited.focusOnKey
- Determines if the initial focus should be set on key instead of value- Since:
- 5653
-
getEditTagDialog
protected TagEditHelper.IEditTagDialog getEditTagDialog(int row, boolean focusOnKey, java.lang.String key)
-
getChangedKey
public java.lang.String getChangedKey()
If during last editProperty call user changed the key name, this key will be returned Elsewhere, returns null.- Returns:
- The modified key, or
null
-
resetChangedKey
public void resetChangedKey()
Reset last changed key.
-
updateSelection
private java.util.Collection<OsmPrimitive> updateSelection()
Update the current selection for this editor
-
getAutocompletionKeys
private static java.util.List<java.lang.String> getAutocompletionKeys(java.lang.String key)
For a given key k, return a list of keys which are used as keys for auto-completing values to increase the search space.- Parameters:
key
- the key k- Returns:
- a list of keys
-
loadTagsIfNeeded
public void loadTagsIfNeeded()
Load recently used tags from preferences if needed.
-
loadTagsToIgnore
void loadTagsToIgnore()
-
warnAboutParseError
private static void warnAboutParseError(SearchParseError parseError)
-
saveTagsIfNeeded
public void saveTagsIfNeeded()
Store recently used tags in preferences if needed.
-
resetSelection
public void resetSelection()
Forget recently selected primitives to allow GC.- Since:
- 14509
-
cacheRecentTags
private void cacheRecentTags()
Update cache of recent tags used for displaying tags.
-
getEditItem
public static java.lang.String getEditItem(AutoCompComboBox<AutoCompletionItem> cb)
Returns the edited item with whitespaces removed- Parameters:
cb
- the combobox- Returns:
- the edited item with whitespaces removed
- Since:
- 18173
-
getSelectedOrEditItem
public static java.lang.String getSelectedOrEditItem(AutoCompComboBox<AutoCompletionItem> cb)
Returns the selected item or the edited item as string- Parameters:
cb
- the combobox- Returns:
- the selected item or the edited item as string
- Since:
- 18173
-
warnSelectionChanged
private static boolean warnSelectionChanged()
Warn user about a selection change- Returns:
true
if the user wants to apply the tag change to the old selection
-
warnOverwriteKey
private static boolean warnOverwriteKey(java.lang.String action, java.lang.String togglePref)
Warns user about a key being overwritten.- Parameters:
action
- The action done by the user. Must state what key is changedtogglePref
- The preference to save the checkbox state to- Returns:
true
if the user accepts to overwrite key,false
otherwise
-
-