source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java@ 18173

Last change on this file since 18173 was 18173, checked in by Don-vip, 3 years ago

fix #20690 - fix #21240 - Refactoring of UploadDialog, HistoryComboBox and AutoCompletingComboBox (patch by marcello)

  • Property svn:eol-style set to native
File size: 49.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.properties;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5import static org.openstreetmap.josm.tools.I18n.trn;
6
7import java.awt.BorderLayout;
8import java.awt.Component;
9import java.awt.Container;
10import java.awt.Cursor;
11import java.awt.Dimension;
12import java.awt.FlowLayout;
13import java.awt.Font;
14import java.awt.GridBagConstraints;
15import java.awt.GridBagLayout;
16import java.awt.datatransfer.Clipboard;
17import java.awt.datatransfer.Transferable;
18import java.awt.event.ActionEvent;
19import java.awt.event.FocusAdapter;
20import java.awt.event.FocusEvent;
21import java.awt.event.InputEvent;
22import java.awt.event.KeyEvent;
23import java.awt.event.MouseAdapter;
24import java.awt.event.MouseEvent;
25import java.awt.event.WindowAdapter;
26import java.awt.event.WindowEvent;
27import java.awt.image.BufferedImage;
28import java.text.Normalizer;
29import java.util.ArrayList;
30import java.util.Arrays;
31import java.util.Collection;
32import java.util.Collections;
33import java.util.Comparator;
34import java.util.Iterator;
35import java.util.List;
36import java.util.Map;
37import java.util.Objects;
38import java.util.Optional;
39import java.util.TreeMap;
40import java.util.stream.Collectors;
41import java.util.stream.IntStream;
42
43import javax.swing.AbstractAction;
44import javax.swing.Action;
45import javax.swing.Box;
46import javax.swing.ButtonGroup;
47import javax.swing.ComboBoxModel;
48import javax.swing.DefaultListCellRenderer;
49import javax.swing.ImageIcon;
50import javax.swing.JCheckBoxMenuItem;
51import javax.swing.JComponent;
52import javax.swing.JLabel;
53import javax.swing.JList;
54import javax.swing.JMenu;
55import javax.swing.JOptionPane;
56import javax.swing.JPanel;
57import javax.swing.JPopupMenu;
58import javax.swing.JRadioButtonMenuItem;
59import javax.swing.JTable;
60import javax.swing.KeyStroke;
61import javax.swing.ListCellRenderer;
62import javax.swing.SwingUtilities;
63import javax.swing.table.DefaultTableModel;
64import javax.swing.text.JTextComponent;
65
66import org.openstreetmap.josm.actions.JosmAction;
67import org.openstreetmap.josm.actions.search.SearchAction;
68import org.openstreetmap.josm.command.ChangePropertyCommand;
69import org.openstreetmap.josm.command.Command;
70import org.openstreetmap.josm.command.SequenceCommand;
71import org.openstreetmap.josm.data.UndoRedoHandler;
72import org.openstreetmap.josm.data.osm.DataSet;
73import org.openstreetmap.josm.data.osm.OsmDataManager;
74import org.openstreetmap.josm.data.osm.OsmPrimitive;
75import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
76import org.openstreetmap.josm.data.osm.Tag;
77import org.openstreetmap.josm.data.osm.search.SearchCompiler;
78import org.openstreetmap.josm.data.osm.search.SearchParseError;
79import org.openstreetmap.josm.data.osm.search.SearchSetting;
80import org.openstreetmap.josm.data.preferences.BooleanProperty;
81import org.openstreetmap.josm.data.preferences.EnumProperty;
82import org.openstreetmap.josm.data.preferences.IntegerProperty;
83import org.openstreetmap.josm.data.preferences.ListProperty;
84import org.openstreetmap.josm.data.preferences.StringProperty;
85import org.openstreetmap.josm.data.tagging.ac.AutoCompletionItem;
86import org.openstreetmap.josm.gui.ExtendedDialog;
87import org.openstreetmap.josm.gui.IExtendedDialog;
88import org.openstreetmap.josm.gui.MainApplication;
89import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
90import org.openstreetmap.josm.gui.tagging.ac.AutoCompComboBox;
91import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
92import org.openstreetmap.josm.gui.util.GuiHelper;
93import org.openstreetmap.josm.gui.util.WindowGeometry;
94import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
95import org.openstreetmap.josm.io.XmlWriter;
96import org.openstreetmap.josm.tools.GBC;
97import org.openstreetmap.josm.tools.ImageProvider;
98import org.openstreetmap.josm.tools.Logging;
99import org.openstreetmap.josm.tools.OsmPrimitiveImageProvider;
100import org.openstreetmap.josm.tools.PlatformManager;
101import org.openstreetmap.josm.tools.Shortcut;
102import org.openstreetmap.josm.tools.Utils;
103
104/**
105 * Class that helps PropertiesDialog add and edit tag values.
106 * @since 5633
107 */
108public class TagEditHelper {
109
110 private final JTable tagTable;
111 private final DefaultTableModel tagData;
112 private final Map<String, Map<String, Integer>> valueCount;
113
114 // Selection that we are editing by using both dialogs
115 protected Collection<OsmPrimitive> sel;
116
117 private String changedKey;
118 private String objKey;
119
120 static final Comparator<AutoCompletionItem> DEFAULT_AC_ITEM_COMPARATOR =
121 (o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getValue(), o2.getValue());
122
123 /** Default number of recent tags */
124 public static final int DEFAULT_LRU_TAGS_NUMBER = 5;
125 /** Maximum number of recent tags */
126 public static final int MAX_LRU_TAGS_NUMBER = 30;
127
128 /** Autocomplete keys by default */
129 public static final BooleanProperty AUTOCOMPLETE_KEYS = new BooleanProperty("properties.autocomplete-keys", true);
130 /** Autocomplete values by default */
131 public static final BooleanProperty AUTOCOMPLETE_VALUES = new BooleanProperty("properties.autocomplete-values", true);
132 /** Use English language for tag by default */
133 public static final BooleanProperty PROPERTY_FIX_TAG_LOCALE = new BooleanProperty("properties.fix-tag-combobox-locale", false);
134 /** Whether recent tags must be remembered */
135 public static final BooleanProperty PROPERTY_REMEMBER_TAGS = new BooleanProperty("properties.remember-recently-added-tags", true);
136 /** Number of recent tags */
137 public static final IntegerProperty PROPERTY_RECENT_TAGS_NUMBER = new IntegerProperty("properties.recently-added-tags",
138 DEFAULT_LRU_TAGS_NUMBER);
139 /** The preference storage of recent tags */
140 public static final ListProperty PROPERTY_RECENT_TAGS = new ListProperty("properties.recent-tags",
141 Collections.<String>emptyList());
142 /** The preference list of tags which should not be remembered, since r9940 */
143 public static final StringProperty PROPERTY_TAGS_TO_IGNORE = new StringProperty("properties.recent-tags.ignore",
144 new SearchSetting().writeToString());
145
146 /**
147 * What to do with recent tags where keys already exist
148 */
149 private enum RecentExisting {
150 ENABLE,
151 DISABLE,
152 HIDE
153 }
154
155 /**
156 * Preference setting for popup menu item "Recent tags with existing key"
157 */
158 public static final EnumProperty<RecentExisting> PROPERTY_RECENT_EXISTING = new EnumProperty<>(
159 "properties.recently-added-tags-existing-key", RecentExisting.class, RecentExisting.DISABLE);
160
161 /**
162 * What to do after applying tag
163 */
164 private enum RefreshRecent {
165 NO,
166 STATUS,
167 REFRESH
168 }
169
170 /**
171 * Preference setting for popup menu item "Refresh recent tags list after applying tag"
172 */
173 public static final EnumProperty<RefreshRecent> PROPERTY_REFRESH_RECENT = new EnumProperty<>(
174 "properties.refresh-recently-added-tags", RefreshRecent.class, RefreshRecent.STATUS);
175
176 final RecentTagCollection recentTags = new RecentTagCollection(MAX_LRU_TAGS_NUMBER);
177 SearchSetting tagsToIgnore;
178
179 /**
180 * Copy of recently added tags in sorted from newest to oldest order.
181 *
182 * We store the maximum number of recent tags to allow dynamic change of number of tags shown in the preferences.
183 * Used to cache initial status.
184 */
185 private List<Tag> tags;
186
187 static {
188 // init user input based on recent tags
189 final RecentTagCollection recentTags = new RecentTagCollection(MAX_LRU_TAGS_NUMBER);
190 recentTags.loadFromPreference(PROPERTY_RECENT_TAGS);
191 recentTags.toList().forEach(tag -> AutoCompletionManager.rememberUserInput(tag.getKey(), tag.getValue(), false));
192 }
193
194 /**
195 * Constructs a new {@code TagEditHelper}.
196 * @param tagTable tag table
197 * @param propertyData table model
198 * @param valueCount tag value count
199 */
200 public TagEditHelper(JTable tagTable, DefaultTableModel propertyData, Map<String, Map<String, Integer>> valueCount) {
201 this.tagTable = tagTable;
202 this.tagData = propertyData;
203 this.valueCount = valueCount;
204 }
205
206 /**
207 * Finds the key from given row of tag editor.
208 * @param viewRow index of row
209 * @return key of tag
210 */
211 public final String getDataKey(int viewRow) {
212 return tagData.getValueAt(tagTable.convertRowIndexToModel(viewRow), 0).toString();
213 }
214
215 /**
216 * Determines if the given tag key is already used (by all selected primitives, not just some of them)
217 * @param key the key to check
218 * @return {@code true} if the key is used by all selected primitives (key not unset for at least one primitive)
219 */
220 @SuppressWarnings("unchecked")
221 boolean containsDataKey(String key) {
222 return IntStream.range(0, tagData.getRowCount())
223 .anyMatch(i -> key.equals(tagData.getValueAt(i, 0)) /* sic! do not use getDataKey*/
224 && !((Map<String, Integer>) tagData.getValueAt(i, 1)).containsKey("") /* sic! do not use getDataValues*/);
225 }
226
227 /**
228 * Finds the values from given row of tag editor.
229 * @param viewRow index of row
230 * @return map of values and number of occurrences
231 */
232 @SuppressWarnings("unchecked")
233 public final Map<String, Integer> getDataValues(int viewRow) {
234 return (Map<String, Integer>) tagData.getValueAt(tagTable.convertRowIndexToModel(viewRow), 1);
235 }
236
237 /**
238 * Open the add selection dialog and add a new key/value to the table (and
239 * to the dataset, of course).
240 */
241 public void addTag() {
242 changedKey = null;
243 DataSet activeDataSet = OsmDataManager.getInstance().getActiveDataSet();
244 if (activeDataSet == null)
245 return;
246 try {
247 activeDataSet.beginUpdate();
248 sel = OsmDataManager.getInstance().getInProgressSelection();
249 if (sel == null || sel.isEmpty())
250 return;
251
252 final AddTagsDialog addDialog = getAddTagsDialog();
253
254 addDialog.showDialog();
255
256 addDialog.destroyActions();
257 if (addDialog.getValue() == 1)
258 addDialog.performTagAdding();
259 else
260 addDialog.undoAllTagsAdding();
261 } finally {
262 activeDataSet.endUpdate();
263 }
264 }
265
266 /**
267 * Returns a new {@code AddTagsDialog}.
268 * @return a new {@code AddTagsDialog}
269 */
270 protected AddTagsDialog getAddTagsDialog() {
271 return new AddTagsDialog();
272 }
273
274 /**
275 * Edit the value in the tags table row.
276 * @param row The row of the table from which the value is edited.
277 * @param focusOnKey Determines if the initial focus should be set on key instead of value
278 * @since 5653
279 */
280 public void editTag(final int row, boolean focusOnKey) {
281 changedKey = null;
282 sel = OsmDataManager.getInstance().getInProgressSelection();
283 if (sel == null || sel.isEmpty())
284 return;
285
286 String key = getDataKey(row);
287 objKey = key;
288
289 final IEditTagDialog editDialog = getEditTagDialog(row, focusOnKey, key);
290 editDialog.showDialog();
291 if (editDialog.getValue() != 1)
292 return;
293 editDialog.performTagEdit();
294 }
295
296 /**
297 * Extracted interface of {@link EditTagDialog}.
298 */
299 protected interface IEditTagDialog extends IExtendedDialog {
300 /**
301 * Edit tags of multiple selected objects according to selected ComboBox values
302 * If value == "", tag will be deleted
303 * Confirmations may be needed.
304 */
305 void performTagEdit();
306 }
307
308 protected IEditTagDialog getEditTagDialog(int row, boolean focusOnKey, String key) {
309 return new EditTagDialog(key, getDataValues(row), focusOnKey);
310 }
311
312 /**
313 * If during last editProperty call user changed the key name, this key will be returned
314 * Elsewhere, returns null.
315 * @return The modified key, or {@code null}
316 */
317 public String getChangedKey() {
318 return changedKey;
319 }
320
321 /**
322 * Reset last changed key.
323 */
324 public void resetChangedKey() {
325 changedKey = null;
326 }
327
328 /**
329 * For a given key k, return a list of keys which are used as keys for
330 * auto-completing values to increase the search space.
331 * @param key the key k
332 * @return a list of keys
333 */
334 private static List<String> getAutocompletionKeys(String key) {
335 if ("name".equals(key) || "addr:street".equals(key))
336 return Arrays.asList("addr:street", "name");
337 else
338 return Arrays.asList(key);
339 }
340
341 /**
342 * Load recently used tags from preferences if needed.
343 */
344 public void loadTagsIfNeeded() {
345 loadTagsToIgnore();
346 if (PROPERTY_REMEMBER_TAGS.get() && recentTags.isEmpty()) {
347 recentTags.loadFromPreference(PROPERTY_RECENT_TAGS);
348 }
349 }
350
351 void loadTagsToIgnore() {
352 final SearchSetting searchSetting = Utils.firstNonNull(
353 SearchSetting.readFromString(PROPERTY_TAGS_TO_IGNORE.get()), new SearchSetting());
354 if (!Objects.equals(tagsToIgnore, searchSetting)) {
355 try {
356 tagsToIgnore = searchSetting;
357 recentTags.setTagsToIgnore(tagsToIgnore);
358 } catch (SearchParseError parseError) {
359 warnAboutParseError(parseError);
360 tagsToIgnore = new SearchSetting();
361 recentTags.setTagsToIgnore(SearchCompiler.Never.INSTANCE);
362 }
363 }
364 }
365
366 private static void warnAboutParseError(SearchParseError parseError) {
367 Logging.warn(parseError);
368 JOptionPane.showMessageDialog(
369 MainApplication.getMainFrame(),
370 parseError.getMessage(),
371 tr("Error"),
372 JOptionPane.ERROR_MESSAGE
373 );
374 }
375
376 /**
377 * Store recently used tags in preferences if needed.
378 */
379 public void saveTagsIfNeeded() {
380 if (PROPERTY_REMEMBER_TAGS.get() && !recentTags.isEmpty()) {
381 recentTags.saveToPreference(PROPERTY_RECENT_TAGS);
382 }
383 }
384
385 /**
386 * Forget recently selected primitives to allow GC.
387 * @since 14509
388 */
389 public void resetSelection() {
390 sel = null;
391 }
392
393 /**
394 * Update cache of recent tags used for displaying tags.
395 */
396 private void cacheRecentTags() {
397 tags = recentTags.toList();
398 Collections.reverse(tags);
399 }
400
401 /**
402 * Returns the edited item with whitespaces removed
403 * @param cb the combobox
404 * @return the edited item with whitespaces removed
405 * @since 18173
406 */
407 public static String getEditItem(AutoCompComboBox<AutoCompletionItem> cb) {
408 return Utils.removeWhiteSpaces(cb.getEditor().getItem().toString());
409 }
410
411 /**
412 * Returns the selected item or the edited item as string
413 * @param cb the combobox
414 * @return the selected item or the edited item as string
415 * @since 18173
416 */
417 public static String getSelectedOrEditItem(AutoCompComboBox<AutoCompletionItem> cb) {
418 final Object selectedItem = cb.getSelectedItem();
419 if (selectedItem != null)
420 return selectedItem.toString();
421 return getEditItem(cb);
422 }
423
424 /**
425 * Warns user about a key being overwritten.
426 * @param action The action done by the user. Must state what key is changed
427 * @param togglePref The preference to save the checkbox state to
428 * @return {@code true} if the user accepts to overwrite key, {@code false} otherwise
429 */
430 private static boolean warnOverwriteKey(String action, String togglePref) {
431 return new ExtendedDialog(
432 MainApplication.getMainFrame(),
433 tr("Overwrite tag"),
434 tr("Overwrite"), tr("Cancel"))
435 .setButtonIcons("ok", "cancel")
436 .setContent(action)
437 .setCancelButton(2)
438 .toggleEnable(togglePref)
439 .showDialog().getValue() == 1;
440 }
441
442 protected class EditTagDialog extends AbstractTagsDialog implements IEditTagDialog {
443 private final String key;
444 private final transient Map<String, Integer> m;
445 private final transient Comparator<AutoCompletionItem> usedValuesAwareComparator;
446
447 private final transient ListCellRenderer<AutoCompletionItem> cellRenderer = new ListCellRenderer<AutoCompletionItem>() {
448 private final DefaultListCellRenderer def = new DefaultListCellRenderer();
449 @Override
450 public Component getListCellRendererComponent(JList<? extends AutoCompletionItem> list,
451 AutoCompletionItem value, int index, boolean isSelected, boolean cellHasFocus) {
452 Component c = def.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
453 if (c instanceof JLabel) {
454 String str = value.getValue();
455 if (valueCount.containsKey(objKey)) {
456 Map<String, Integer> map = valueCount.get(objKey);
457 if (map.containsKey(str)) {
458 str = tr("{0} ({1})", str, map.get(str));
459 c.setFont(c.getFont().deriveFont(Font.ITALIC + Font.BOLD));
460 }
461 }
462 ((JLabel) c).setText(str);
463 }
464 return c;
465 }
466 };
467
468 protected EditTagDialog(String key, Map<String, Integer> map, final boolean initialFocusOnKey) {
469 super(MainApplication.getMainFrame(), trn("Change value?", "Change values?", map.size()), tr("OK"), tr("Cancel"));
470 setButtonIcons("ok", "cancel");
471 setCancelButton(2);
472 configureContextsensitiveHelp("/Dialog/EditValue", true /* show help button */);
473 this.key = key;
474 this.m = map;
475
476 usedValuesAwareComparator = (o1, o2) -> {
477 boolean c1 = m.containsKey(o1.getValue());
478 boolean c2 = m.containsKey(o2.getValue());
479 if (c1 == c2)
480 return String.CASE_INSENSITIVE_ORDER.compare(o1.getValue(), o2.getValue());
481 else if (c1)
482 return -1;
483 else
484 return +1;
485 };
486
487 JPanel mainPanel = new JPanel(new BorderLayout());
488
489 String msg = "<html>"+trn("This will change {0} object.",
490 "This will change up to {0} objects.", sel.size(), sel.size())
491 +"<br><br>("+tr("An empty value deletes the tag.", key)+")</html>";
492
493 mainPanel.add(new JLabel(msg), BorderLayout.NORTH);
494
495 JPanel p = new JPanel(new GridBagLayout());
496 mainPanel.add(p, BorderLayout.CENTER);
497
498 AutoCompletionManager autocomplete = AutoCompletionManager.of(OsmDataManager.getInstance().getActiveDataSet());
499 List<AutoCompletionItem> keyList = autocomplete.getTagKeys(DEFAULT_AC_ITEM_COMPARATOR);
500
501 keys = new AutoCompComboBox<>();
502 keys.getModel().setComparator(Comparator.naturalOrder()); // according to Comparable
503 keys.setPrototypeDisplayValue(new AutoCompletionItem(key));
504 keys.setEditable(true);
505 keys.getModel().addAllElements(keyList);
506 keys.setSelectedItem(key);
507
508 p.add(Box.createVerticalStrut(5), GBC.eol());
509 p.add(new JLabel(tr("Key")), GBC.std());
510 p.add(Box.createHorizontalStrut(10), GBC.std());
511 p.add(keys, GBC.eol().fill(GBC.HORIZONTAL));
512
513 List<AutoCompletionItem> valueList = autocomplete.getTagValues(getAutocompletionKeys(key), usedValuesAwareComparator);
514
515 final String selection = m.size() != 1 ? tr("<different>") : m.entrySet().iterator().next().getKey();
516
517 values = new AutoCompComboBox<>();
518 values.getModel().setComparator(Comparator.naturalOrder());
519 values.setPrototypeDisplayValue(new AutoCompletionItem(selection));
520 values.setRenderer(cellRenderer);
521 values.setEditable(true);
522 values.getModel().addAllElements(valueList);
523 values.setSelectedItem(selection);
524 values.getEditor().setItem(selection);
525
526 p.add(Box.createVerticalStrut(5), GBC.eol());
527 p.add(new JLabel(tr("Value")), GBC.std());
528 p.add(Box.createHorizontalStrut(10), GBC.std());
529 p.add(values, GBC.eol().fill(GBC.HORIZONTAL));
530 values.getEditor().addActionListener(e -> buttonAction(0, null));
531 addFocusAdapter(autocomplete, usedValuesAwareComparator);
532
533 addUpdateIconListener();
534
535 setContent(mainPanel, false);
536
537 addWindowListener(new WindowAdapter() {
538 @Override
539 public void windowOpened(WindowEvent e) {
540 if (initialFocusOnKey) {
541 selectKeysComboBox();
542 } else {
543 selectValuesCombobox();
544 }
545 }
546 });
547 }
548
549 @Override
550 public void performTagEdit() {
551 String value = getEditItem(values);
552 value = Normalizer.normalize(value, Normalizer.Form.NFC);
553 if (value.isEmpty()) {
554 value = null; // delete the key
555 }
556 String newkey = getEditItem(keys);
557 newkey = Normalizer.normalize(newkey, Normalizer.Form.NFC);
558 if (newkey.isEmpty()) {
559 newkey = key;
560 value = null; // delete the key instead
561 }
562 if (key.equals(newkey) && tr("<different>").equals(value))
563 return;
564 if (key.equals(newkey) || value == null) {
565 UndoRedoHandler.getInstance().add(new ChangePropertyCommand(sel, newkey, value));
566 if (value != null) {
567 AutoCompletionManager.rememberUserInput(newkey, value, true);
568 recentTags.add(new Tag(key, value));
569 }
570 } else {
571 for (OsmPrimitive osm: sel) {
572 if (osm.get(newkey) != null) {
573 if (!warnOverwriteKey(tr("You changed the key from ''{0}'' to ''{1}''.", key, newkey)
574 + "\n" + tr("The new key is already used, overwrite values?"),
575 "overwriteEditKey"))
576 return;
577 break;
578 }
579 }
580 Collection<Command> commands = new ArrayList<>();
581 commands.add(new ChangePropertyCommand(sel, key, null));
582 if (value.equals(tr("<different>"))) {
583 String newKey = newkey;
584 sel.stream()
585 .filter(osm -> osm.hasKey(key))
586 .collect(Collectors.groupingBy(osm -> osm.get(key)))
587 .forEach((newValue, osmPrimitives) -> commands.add(new ChangePropertyCommand(osmPrimitives, newKey, newValue)));
588 } else {
589 commands.add(new ChangePropertyCommand(sel, newkey, value));
590 AutoCompletionManager.rememberUserInput(newkey, value, false);
591 }
592 UndoRedoHandler.getInstance().add(new SequenceCommand(
593 trn("Change properties of up to {0} object",
594 "Change properties of up to {0} objects", sel.size(), sel.size()),
595 commands));
596 }
597
598 changedKey = newkey;
599 }
600 }
601
602 protected abstract class AbstractTagsDialog extends ExtendedDialog {
603 protected AutoCompComboBox<AutoCompletionItem> keys;
604 protected AutoCompComboBox<AutoCompletionItem> values;
605
606 AbstractTagsDialog(Component parent, String title, String... buttonTexts) {
607 super(parent, title, buttonTexts);
608 addMouseListener(new PopupMenuLauncher(popupMenu));
609 }
610
611 @Override
612 public void setupDialog() {
613 super.setupDialog();
614 buttons.get(0).setEnabled(!OsmDataManager.getInstance().getActiveDataSet().isLocked());
615 final Dimension size = getSize();
616 // Set resizable only in width
617 setMinimumSize(size);
618 setPreferredSize(size);
619 // setMaximumSize does not work, and never worked, but still it seems not to bother Oracle to fix this 10-year-old bug
620 // https://bugs.openjdk.java.net/browse/JDK-6200438
621 // https://bugs.openjdk.java.net/browse/JDK-6464548
622
623 setRememberWindowGeometry(getClass().getName() + ".geometry",
624 WindowGeometry.centerInWindow(MainApplication.getMainFrame(), size));
625 }
626
627 @Override
628 public void setVisible(boolean visible) {
629 // Do not want dialog to be resizable in height, as its size may increase each time because of the recently added tags
630 // So need to modify the stored geometry (size part only) in order to use the automatic positioning mechanism
631 if (visible) {
632 WindowGeometry geometry = initWindowGeometry();
633 Dimension storedSize = geometry.getSize();
634 Dimension size = getSize();
635 if (!storedSize.equals(size)) {
636 if (storedSize.width < size.width) {
637 storedSize.width = size.width;
638 }
639 if (storedSize.height != size.height) {
640 storedSize.height = size.height;
641 }
642 rememberWindowGeometry(geometry);
643 }
644 keys.setFixedLocale(PROPERTY_FIX_TAG_LOCALE.get());
645 updateOkButtonIcon();
646 }
647 super.setVisible(visible);
648 }
649
650 private void selectACComboBoxSavingUnixBuffer(AutoCompComboBox<AutoCompletionItem> cb) {
651 // select combobox with saving unix system selection (middle mouse paste)
652 Clipboard sysSel = ClipboardUtils.getSystemSelection();
653 if (sysSel != null) {
654 Transferable old = ClipboardUtils.getClipboardContent(sysSel);
655 cb.requestFocusInWindow();
656 cb.getEditor().selectAll();
657 if (old != null) {
658 sysSel.setContents(old, null);
659 }
660 } else {
661 cb.requestFocusInWindow();
662 cb.getEditor().selectAll();
663 }
664 }
665
666 public void selectKeysComboBox() {
667 selectACComboBoxSavingUnixBuffer(keys);
668 }
669
670 public void selectValuesCombobox() {
671 selectACComboBoxSavingUnixBuffer(values);
672 }
673
674 /**
675 * Create a focus handling adapter and apply in to the editor component of value
676 * autocompletion box.
677 * @param autocomplete Manager handling the autocompletion
678 * @param comparator Class to decide what values are offered on autocompletion
679 * @return The created adapter
680 */
681 protected FocusAdapter addFocusAdapter(final AutoCompletionManager autocomplete, final Comparator<AutoCompletionItem> comparator) {
682 // get the combo box' editor component
683 final JTextComponent editor = values.getEditorComponent();
684 // Refresh the values model when focus is gained
685 FocusAdapter focus = new FocusAdapter() {
686 @Override
687 public void focusGained(FocusEvent e) {
688 Logging.trace("Focus gained by {0}, e={1}", values, e);
689 String key = keys.getEditor().getItem().toString();
690 List<AutoCompletionItem> correctItems = autocomplete.getTagValues(getAutocompletionKeys(key), comparator);
691 ComboBoxModel<AutoCompletionItem> currentModel = values.getModel();
692 final int size = correctItems.size();
693 boolean valuesOK = size == currentModel.getSize()
694 && IntStream.range(0, size).allMatch(i -> Objects.equals(currentModel.getElementAt(i), correctItems.get(i)));
695 if (!valuesOK) {
696 values.getModel().removeAllElements();
697 values.getModel().addAllElements(correctItems);
698 }
699 if (!Objects.equals(key, objKey)) {
700 values.getEditor().selectAll();
701 objKey = key;
702 }
703 }
704 };
705 editor.addFocusListener(focus);
706 return focus;
707 }
708
709 protected void addUpdateIconListener() {
710 keys.addActionListener(ignore -> updateOkButtonIcon());
711 values.addActionListener(ignore -> updateOkButtonIcon());
712 }
713
714 private void updateOkButtonIcon() {
715 if (buttons.isEmpty()) {
716 return;
717 }
718 buttons.get(0).setIcon(findIcon(getSelectedOrEditItem(keys), getSelectedOrEditItem(values))
719 .orElse(ImageProvider.get("ok", ImageProvider.ImageSizes.LARGEICON)));
720 }
721
722 protected Optional<ImageIcon> findIcon(String key, String value) {
723 final Iterator<OsmPrimitive> osmPrimitiveIterator = sel.iterator();
724 final OsmPrimitiveType type = osmPrimitiveIterator.hasNext() ? osmPrimitiveIterator.next().getType() : OsmPrimitiveType.NODE;
725 return OsmPrimitiveImageProvider.getResource(key, value, type)
726 .map(resource -> resource.getPaddedIcon(ImageProvider.ImageSizes.LARGEICON.getImageDimension()));
727 }
728
729 protected JPopupMenu popupMenu = new JPopupMenu() {
730 private final JCheckBoxMenuItem fixTagLanguageCb = new JCheckBoxMenuItem(
731 new AbstractAction(tr("Use English language for tag by default")) {
732 @Override
733 public void actionPerformed(ActionEvent e) {
734 boolean use = ((JCheckBoxMenuItem) e.getSource()).getState();
735 PROPERTY_FIX_TAG_LOCALE.put(use);
736 keys.setFixedLocale(use);
737 }
738 });
739 {
740 add(fixTagLanguageCb);
741 fixTagLanguageCb.setState(PROPERTY_FIX_TAG_LOCALE.get());
742 }
743 };
744 }
745
746 protected class AddTagsDialog extends AbstractTagsDialog {
747 private final List<JosmAction> recentTagsActions = new ArrayList<>();
748 protected final transient FocusAdapter focus;
749 private final JPanel mainPanel;
750 private JPanel recentTagsPanel;
751
752 // Counter of added commands for possible undo
753 private int commandCount;
754
755 protected AddTagsDialog() {
756 super(MainApplication.getMainFrame(), tr("Add tag"), tr("OK"), tr("Cancel"));
757 setButtonIcons("ok", "cancel");
758 setCancelButton(2);
759 configureContextsensitiveHelp("/Dialog/AddValue", true /* show help button */);
760
761 mainPanel = new JPanel(new GridBagLayout());
762 keys = new AutoCompComboBox<>();
763 values = new AutoCompComboBox<>();
764 keys.getModel().setComparator(Comparator.naturalOrder()); // according to Comparable
765 values.getModel().setComparator(Comparator.naturalOrder());
766 keys.setPrototypeDisplayValue(new AutoCompletionItem("dummy"));
767 values.setPrototypeDisplayValue(new AutoCompletionItem("dummy"));
768 keys.setAutocompleteEnabled(AUTOCOMPLETE_KEYS.get());
769 values.setAutocompleteEnabled(AUTOCOMPLETE_VALUES.get());
770
771 mainPanel.add(new JLabel("<html>"+trn("This will change up to {0} object.",
772 "This will change up to {0} objects.", sel.size(), sel.size())
773 +"<br><br>"+tr("Please select a key")), GBC.eol().fill(GBC.HORIZONTAL));
774
775 cacheRecentTags();
776 AutoCompletionManager autocomplete = AutoCompletionManager.of(OsmDataManager.getInstance().getActiveDataSet());
777 List<AutoCompletionItem> keyList = autocomplete.getTagKeys(DEFAULT_AC_ITEM_COMPARATOR);
778
779 // remove the object's tag keys from the list
780 keyList.removeIf(item -> containsDataKey(item.getValue()));
781
782 keys.getModel().removeAllElements();
783 keys.getModel().addAllElements(keyList);
784 keys.setEditable(true);
785
786 mainPanel.add(keys, GBC.eop().fill(GBC.HORIZONTAL));
787
788 mainPanel.add(new JLabel(tr("Choose a value")), GBC.eol());
789 values.setEditable(true);
790 mainPanel.add(values, GBC.eop().fill(GBC.HORIZONTAL));
791
792 // pre-fill first recent tag for which the key is not already present
793 tags.stream()
794 .filter(tag -> !containsDataKey(tag.getKey()))
795 .findFirst()
796 .ifPresent(tag -> {
797 keys.setSelectedItem(tag.getKey());
798 values.setSelectedItem(tag.getValue());
799 });
800
801 focus = addFocusAdapter(autocomplete, DEFAULT_AC_ITEM_COMPARATOR);
802 // fire focus event in advance or otherwise the popup list will be too small at first
803 focus.focusGained(null);
804
805 addUpdateIconListener();
806
807 // Add tag on Shift-Enter
808 mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
809 KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK), "addAndContinue");
810 mainPanel.getActionMap().put("addAndContinue", new AbstractAction() {
811 @Override
812 public void actionPerformed(ActionEvent e) {
813 performTagAdding();
814 refreshRecentTags();
815 selectKeysComboBox();
816 }
817 });
818
819 suggestRecentlyAddedTags();
820
821 mainPanel.add(Box.createVerticalGlue(), GBC.eop().fill());
822 setContent(mainPanel, false);
823
824 selectKeysComboBox();
825
826 popupMenu.add(new AbstractAction(tr("Set number of recently added tags")) {
827 @Override
828 public void actionPerformed(ActionEvent e) {
829 selectNumberOfTags();
830 suggestRecentlyAddedTags();
831 }
832 });
833
834 popupMenu.add(buildMenuRecentExisting());
835 popupMenu.add(buildMenuRefreshRecent());
836
837 JCheckBoxMenuItem rememberLastTags = new JCheckBoxMenuItem(
838 new AbstractAction(tr("Remember last used tags after a restart")) {
839 @Override
840 public void actionPerformed(ActionEvent e) {
841 boolean state = ((JCheckBoxMenuItem) e.getSource()).getState();
842 PROPERTY_REMEMBER_TAGS.put(state);
843 if (state)
844 saveTagsIfNeeded();
845 }
846 });
847 rememberLastTags.setState(PROPERTY_REMEMBER_TAGS.get());
848 popupMenu.add(rememberLastTags);
849 }
850
851 private JMenu buildMenuRecentExisting() {
852 JMenu menu = new JMenu(tr("Recent tags with existing key"));
853 TreeMap<RecentExisting, String> radios = new TreeMap<>();
854 radios.put(RecentExisting.ENABLE, tr("Enable"));
855 radios.put(RecentExisting.DISABLE, tr("Disable"));
856 radios.put(RecentExisting.HIDE, tr("Hide"));
857 ButtonGroup buttonGroup = new ButtonGroup();
858 for (final Map.Entry<RecentExisting, String> entry : radios.entrySet()) {
859 JRadioButtonMenuItem radio = new JRadioButtonMenuItem(new AbstractAction(entry.getValue()) {
860 @Override
861 public void actionPerformed(ActionEvent e) {
862 PROPERTY_RECENT_EXISTING.put(entry.getKey());
863 suggestRecentlyAddedTags();
864 }
865 });
866 buttonGroup.add(radio);
867 radio.setSelected(PROPERTY_RECENT_EXISTING.get() == entry.getKey());
868 menu.add(radio);
869 }
870 return menu;
871 }
872
873 private JMenu buildMenuRefreshRecent() {
874 JMenu menu = new JMenu(tr("Refresh recent tags list after applying tag"));
875 TreeMap<RefreshRecent, String> radios = new TreeMap<>();
876 radios.put(RefreshRecent.NO, tr("No refresh"));
877 radios.put(RefreshRecent.STATUS, tr("Refresh tag status only (enabled / disabled)"));
878 radios.put(RefreshRecent.REFRESH, tr("Refresh tag status and list of recently added tags"));
879 ButtonGroup buttonGroup = new ButtonGroup();
880 for (final Map.Entry<RefreshRecent, String> entry : radios.entrySet()) {
881 JRadioButtonMenuItem radio = new JRadioButtonMenuItem(new AbstractAction(entry.getValue()) {
882 @Override
883 public void actionPerformed(ActionEvent e) {
884 PROPERTY_REFRESH_RECENT.put(entry.getKey());
885 }
886 });
887 buttonGroup.add(radio);
888 radio.setSelected(PROPERTY_REFRESH_RECENT.get() == entry.getKey());
889 menu.add(radio);
890 }
891 return menu;
892 }
893
894 @Override
895 public void setContentPane(Container contentPane) {
896 final int commandDownMask = PlatformManager.getPlatform().getMenuShortcutKeyMaskEx();
897 List<String> lines = new ArrayList<>();
898 Shortcut.findShortcut(KeyEvent.VK_1, commandDownMask).ifPresent(sc ->
899 lines.add(sc.getKeyText() + ' ' + tr("to apply first suggestion"))
900 );
901 lines.add(Shortcut.getKeyText(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK)) + ' '
902 +tr("to add without closing the dialog"));
903 Shortcut.findShortcut(KeyEvent.VK_1, commandDownMask | KeyEvent.SHIFT_DOWN_MASK).ifPresent(sc ->
904 lines.add(sc.getKeyText() + ' ' + tr("to add first suggestion without closing the dialog"))
905 );
906 final JLabel helpLabel = new JLabel("<html>" + String.join("<br>", lines) + "</html>");
907 helpLabel.setFont(helpLabel.getFont().deriveFont(Font.PLAIN));
908 contentPane.add(helpLabel, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 5, 5, 5));
909 super.setContentPane(contentPane);
910 }
911
912 protected void selectNumberOfTags() {
913 String s = String.format("%d", PROPERTY_RECENT_TAGS_NUMBER.get());
914 while (true) {
915 s = JOptionPane.showInputDialog(this, tr("Please enter the number of recently added tags to display"), s);
916 if (s == null || s.isEmpty()) {
917 return;
918 }
919 try {
920 int v = Integer.parseInt(s);
921 if (v >= 0 && v <= MAX_LRU_TAGS_NUMBER) {
922 PROPERTY_RECENT_TAGS_NUMBER.put(v);
923 return;
924 }
925 } catch (NumberFormatException ex) {
926 Logging.warn(ex);
927 }
928 JOptionPane.showMessageDialog(this, tr("Please enter integer number between 0 and {0}", MAX_LRU_TAGS_NUMBER));
929 }
930 }
931
932 protected void suggestRecentlyAddedTags() {
933 if (recentTagsPanel == null) {
934 recentTagsPanel = new JPanel(new GridBagLayout());
935 buildRecentTagsPanel();
936 mainPanel.add(recentTagsPanel, GBC.eol().fill(GBC.HORIZONTAL));
937 } else {
938 Dimension panelOldSize = recentTagsPanel.getPreferredSize();
939 recentTagsPanel.removeAll();
940 buildRecentTagsPanel();
941 Dimension panelNewSize = recentTagsPanel.getPreferredSize();
942 Dimension dialogOldSize = getMinimumSize();
943 Dimension dialogNewSize = new Dimension(dialogOldSize.width, dialogOldSize.height-panelOldSize.height+panelNewSize.height);
944 setMinimumSize(dialogNewSize);
945 setPreferredSize(dialogNewSize);
946 setSize(dialogNewSize);
947 revalidate();
948 repaint();
949 }
950 }
951
952 protected void buildRecentTagsPanel() {
953 final int tagsToShow = Math.min(PROPERTY_RECENT_TAGS_NUMBER.get(), MAX_LRU_TAGS_NUMBER);
954 if (!(tagsToShow > 0 && !recentTags.isEmpty()))
955 return;
956 recentTagsPanel.add(new JLabel(tr("Recently added tags")), GBC.eol());
957
958 int count = 0;
959 destroyActions();
960 for (int i = 0; i < tags.size() && count < tagsToShow; i++) {
961 final Tag t = tags.get(i);
962 boolean keyExists = containsDataKey(t.getKey());
963 if (keyExists && PROPERTY_RECENT_EXISTING.get() == RecentExisting.HIDE)
964 continue;
965 count++;
966 // Create action for reusing the tag, with keyboard shortcut
967 /* POSSIBLE SHORTCUTS: 1,2,3,4,5,6,7,8,9,0=10 */
968 final Shortcut sc = count > 10 ? null : Shortcut.registerShortcut("properties:recent:" + count,
969 tr("Choose recent tag {0}", count), KeyEvent.VK_0 + (count % 10), Shortcut.CTRL);
970 final JosmAction action = new JosmAction(
971 tr("Choose recent tag {0}", count), null, tr("Use this tag again"), sc, false) {
972 @Override
973 public void actionPerformed(ActionEvent e) {
974 keys.setSelectedItem(t.getKey());
975 // fix #7951, #8298 - update list of values before setting value (?)
976 focus.focusGained(null);
977 values.setSelectedItem(t.getValue());
978 selectValuesCombobox();
979 }
980 };
981 /* POSSIBLE SHORTCUTS: 1,2,3,4,5,6,7,8,9,0=10 */
982 final Shortcut scShift = count > 10 ? null : Shortcut.registerShortcut("properties:recent:apply:" + count,
983 tr("Apply recent tag {0}", count), KeyEvent.VK_0 + (count % 10), Shortcut.CTRL_SHIFT);
984 final JosmAction actionShift = new JosmAction(
985 tr("Apply recent tag {0}", count), null, tr("Use this tag again"), scShift, false) {
986 @Override
987 public void actionPerformed(ActionEvent e) {
988 action.actionPerformed(null);
989 performTagAdding();
990 refreshRecentTags();
991 selectKeysComboBox();
992 }
993 };
994 recentTagsActions.add(action);
995 recentTagsActions.add(actionShift);
996 if (keyExists && PROPERTY_RECENT_EXISTING.get() == RecentExisting.DISABLE) {
997 action.setEnabled(false);
998 }
999 ImageIcon icon = findIcon(t.getKey(), t.getValue())
1000 // If still nothing display an empty icon
1001
1002 .orElseGet(() -> new ImageIcon(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)));
1003 GridBagConstraints gbc = new GridBagConstraints();
1004 gbc.ipadx = 5;
1005 recentTagsPanel.add(new JLabel(action.isEnabled() ? icon : GuiHelper.getDisabledIcon(icon)), gbc);
1006 // Create tag label
1007 final String color = action.isEnabled() ? "" : "; color:gray";
1008 final JLabel tagLabel = new JLabel("<html>"
1009 + "<style>td{" + color + "}</style>"
1010 + "<table><tr>"
1011 + "<td>" + count + ".</td>"
1012 + "<td style='border:1px solid gray'>" + XmlWriter.encode(t.toString(), true) + '<' +
1013 "/td></tr></table></html>");
1014 tagLabel.setFont(tagLabel.getFont().deriveFont(Font.PLAIN));
1015 if (action.isEnabled() && sc != null && scShift != null) {
1016 // Register action
1017 recentTagsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sc.getKeyStroke(), "choose"+count);
1018 recentTagsPanel.getActionMap().put("choose"+count, action);
1019 recentTagsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scShift.getKeyStroke(), "apply"+count);
1020 recentTagsPanel.getActionMap().put("apply"+count, actionShift);
1021 }
1022 if (action.isEnabled()) {
1023 // Make the tag label clickable and set tooltip to the action description (this displays also the keyboard shortcut)
1024 tagLabel.setToolTipText((String) action.getValue(Action.SHORT_DESCRIPTION));
1025 tagLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1026 tagLabel.addMouseListener(new MouseAdapter() {
1027 @Override
1028 public void mouseClicked(MouseEvent e) {
1029 action.actionPerformed(null);
1030 if (SwingUtilities.isRightMouseButton(e)) {
1031 Component component = e.getComponent();
1032 if (component.isShowing()) {
1033 new TagPopupMenu(t).show(component, e.getX(), e.getY());
1034 }
1035 } else if (e.isShiftDown()) {
1036 // add tags on Shift-Click
1037 performTagAdding();
1038 refreshRecentTags();
1039 selectKeysComboBox();
1040 } else if (e.getClickCount() > 1) {
1041 // add tags and close window on double-click
1042 buttonAction(0, null); // emulate OK click and close the dialog
1043 }
1044 }
1045 });
1046 } else {
1047 // Disable tag label
1048 tagLabel.setEnabled(false);
1049 // Explain in the tooltip why
1050 tagLabel.setToolTipText(tr("The key ''{0}'' is already used", t.getKey()));
1051 }
1052 // Finally add label to the resulting panel
1053 JPanel tagPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
1054 tagPanel.add(tagLabel);
1055 recentTagsPanel.add(tagPanel, GBC.eol().fill(GBC.HORIZONTAL));
1056 }
1057 // Clear label if no tags were added
1058 if (count == 0) {
1059 recentTagsPanel.removeAll();
1060 }
1061 }
1062
1063 class TagPopupMenu extends JPopupMenu {
1064
1065 TagPopupMenu(Tag t) {
1066 add(new IgnoreTagAction(tr("Ignore key ''{0}''", t.getKey()), new Tag(t.getKey(), "")));
1067 add(new IgnoreTagAction(tr("Ignore tag ''{0}''", t), t));
1068 add(new EditIgnoreTagsAction());
1069 }
1070 }
1071
1072 class IgnoreTagAction extends AbstractAction {
1073 final transient Tag tag;
1074
1075 IgnoreTagAction(String name, Tag tag) {
1076 super(name);
1077 this.tag = tag;
1078 }
1079
1080 @Override
1081 public void actionPerformed(ActionEvent e) {
1082 try {
1083 if (tagsToIgnore != null) {
1084 recentTags.ignoreTag(tag, tagsToIgnore);
1085 PROPERTY_TAGS_TO_IGNORE.put(tagsToIgnore.writeToString());
1086 }
1087 } catch (SearchParseError parseError) {
1088 throw new IllegalStateException(parseError);
1089 }
1090 }
1091 }
1092
1093 class EditIgnoreTagsAction extends AbstractAction {
1094
1095 EditIgnoreTagsAction() {
1096 super(tr("Edit ignore list"));
1097 }
1098
1099 @Override
1100 public void actionPerformed(ActionEvent e) {
1101 final SearchSetting newTagsToIngore = SearchAction.showSearchDialog(tagsToIgnore);
1102 if (newTagsToIngore == null) {
1103 return;
1104 }
1105 try {
1106 tagsToIgnore = newTagsToIngore;
1107 recentTags.setTagsToIgnore(tagsToIgnore);
1108 PROPERTY_TAGS_TO_IGNORE.put(tagsToIgnore.writeToString());
1109 } catch (SearchParseError parseError) {
1110 warnAboutParseError(parseError);
1111 }
1112 }
1113 }
1114
1115 /**
1116 * Destroy the recentTagsActions.
1117 */
1118 public void destroyActions() {
1119 for (JosmAction action : recentTagsActions) {
1120 action.destroy();
1121 }
1122 recentTagsActions.clear();
1123 }
1124
1125 /**
1126 * Read tags from comboboxes and add it to all selected objects
1127 */
1128 public final void performTagAdding() {
1129 String key = getEditItem(keys);
1130 String value = getEditItem(values);
1131 if (key.isEmpty() || value.isEmpty())
1132 return;
1133 for (OsmPrimitive osm : sel) {
1134 String val = osm.get(key);
1135 if (val != null && !val.equals(value)) {
1136 String valueHtmlString = Utils.joinAsHtmlUnorderedList(Arrays.asList("<strike>" + val + "</strike>", value));
1137 if (!warnOverwriteKey("<html>"
1138 + tr("You changed the value of ''{0}'': {1}", key, valueHtmlString)
1139 + tr("Overwrite?"), "overwriteAddKey"))
1140 return;
1141 break;
1142 }
1143 }
1144 recentTags.add(new Tag(key, value));
1145 valueCount.put(key, new TreeMap<String, Integer>());
1146 AutoCompletionManager.rememberUserInput(key, value, false);
1147 commandCount++;
1148 UndoRedoHandler.getInstance().add(new ChangePropertyCommand(sel, key, value));
1149 changedKey = key;
1150 clearEntries();
1151 }
1152
1153 protected void clearEntries() {
1154 keys.getEditor().setItem("");
1155 values.getEditor().setItem("");
1156 }
1157
1158 public void undoAllTagsAdding() {
1159 UndoRedoHandler.getInstance().undo(commandCount);
1160 }
1161
1162 private void refreshRecentTags() {
1163 switch (PROPERTY_REFRESH_RECENT.get()) {
1164 case REFRESH:
1165 cacheRecentTags();
1166 suggestRecentlyAddedTags();
1167 break;
1168 case STATUS:
1169 suggestRecentlyAddedTags();
1170 break;
1171 default: // Do nothing
1172 }
1173 }
1174 }
1175}
Note: See TracBrowser for help on using the repository browser.