diff --git a/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java b/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
index 9075624..825af36 100644
a
|
b
|
import java.awt.event.ActionEvent;
|
18 | 18 | import java.awt.event.ActionListener; |
19 | 19 | import java.awt.event.FocusAdapter; |
20 | 20 | import java.awt.event.FocusEvent; |
21 | | import java.awt.event.InputEvent; |
22 | 21 | import java.awt.event.KeyEvent; |
23 | 22 | import java.awt.event.MouseAdapter; |
24 | 23 | import java.awt.event.MouseEvent; |
… |
… |
import java.util.EnumSet;
|
34 | 33 | import java.util.HashMap; |
35 | 34 | import java.util.HashSet; |
36 | 35 | import java.util.Iterator; |
| 36 | import java.util.LinkedHashMap; |
37 | 37 | import java.util.LinkedList; |
38 | 38 | import java.util.List; |
39 | 39 | import java.util.Map; |
… |
… |
import javax.swing.AbstractAction;
|
47 | 47 | import javax.swing.Action; |
48 | 48 | import javax.swing.Box; |
49 | 49 | import javax.swing.DefaultListCellRenderer; |
50 | | import javax.swing.InputMap; |
51 | 50 | import javax.swing.JComboBox; |
52 | 51 | import javax.swing.JComponent; |
53 | 52 | import javax.swing.JDialog; |
… |
… |
public class PropertiesDialog extends ToggleDialog implements SelectionChangedLi
|
451 | 450 | |
452 | 451 | private static String lastAddKey = null; |
453 | 452 | private static String lastAddValue = null; |
| 453 | // LRU cache for recently added tags (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html) |
| 454 | private static final Map<Tag, Void> recentTags = new LinkedHashMap<Tag, Void>(5, 1.1f, true); |
| 455 | |
454 | 456 | /** |
455 | 457 | * Open the add selection dialog and add a new key/value to the table (and |
456 | 458 | * to the dataset, of course). |
… |
… |
public class PropertiesDialog extends ToggleDialog implements SelectionChangedLi
|
461 | 463 | Collection<OsmPrimitive> sel = ds.getSelected(); |
462 | 464 | if (sel.isEmpty()) return; |
463 | 465 | |
464 | | JPanel p = new JPanel(new BorderLayout()); |
| 466 | JPanel p = new JPanel(new GridBagLayout()); |
465 | 467 | p.add(new JLabel("<html>"+trn("This will change up to {0} object.", |
466 | 468 | "This will change up to {0} objects.", sel.size(),sel.size()) |
467 | | +"<br><br>"+tr("Please select a key")), BorderLayout.NORTH); |
| 469 | +"<br><br>"+tr("Please select a key")), GBC.eol()); |
468 | 470 | final AutoCompletingComboBox keys = new AutoCompletingComboBox(); |
469 | 471 | AutoCompletionManager autocomplete = Main.main.getEditLayer().data.getAutoCompletionManager(); |
470 | 472 | List<AutoCompletionListItem> keyList = autocomplete.getKeys(); |
… |
… |
public class PropertiesDialog extends ToggleDialog implements SelectionChangedLi
|
492 | 494 | keys.setPossibleACItems(keyList); |
493 | 495 | keys.setEditable(true); |
494 | 496 | |
495 | | p.add(keys, BorderLayout.CENTER); |
| 497 | p.add(keys, GBC.eop().fill()); |
496 | 498 | |
497 | | JPanel p2 = new JPanel(new BorderLayout()); |
498 | | p.add(p2, BorderLayout.SOUTH); |
499 | | p2.add(new JLabel(tr("Please select a value")), BorderLayout.NORTH); |
| 499 | p.add(new JLabel(tr("Please select a value")), GBC.eol()); |
500 | 500 | final AutoCompletingComboBox values = new AutoCompletingComboBox(); |
501 | 501 | values.setEditable(true); |
502 | | p2.add(values, BorderLayout.CENTER); |
| 502 | p.add(values, GBC.eop().fill()); |
503 | 503 | if (itemToSelect != null) { |
504 | 504 | keys.setSelectedItem(itemToSelect); |
505 | 505 | /* don't add single chars, as they are no properly selected */ |
… |
… |
public class PropertiesDialog extends ToggleDialog implements SelectionChangedLi
|
508 | 508 | } |
509 | 509 | } |
510 | 510 | |
| 511 | if (!recentTags.isEmpty()) { |
| 512 | p.add(new JLabel(tr("Recently added tags")), GBC.eol()); |
| 513 | } |
| 514 | for (final Tag t : recentTags.keySet()) { |
| 515 | final JLabel l = new JLabel("<html>" |
| 516 | + "<style>td{border:1px solid gray; font-weight:normal;}</style>" |
| 517 | + "<table><tr><td>" + t.toString() + "</td></tr></table></html>"); |
| 518 | l.addMouseListener(new MouseAdapter() { |
| 519 | @Override |
| 520 | public void mouseClicked(MouseEvent e) { |
| 521 | keys.getEditor().setItem(t.getKey()); |
| 522 | values.getEditor().setItem(t.getValue()); |
| 523 | } |
| 524 | }); |
| 525 | p.add(l, GBC.eol()); |
| 526 | } |
| 527 | |
511 | 528 | FocusAdapter focus = addFocusAdapter(-1, keys, values, autocomplete, defaultACItemComparator); |
512 | 529 | // fire focus event in advance or otherwise the popup list will be too small at first |
513 | 530 | focus.focusGained(null); |
… |
… |
public class PropertiesDialog extends ToggleDialog implements SelectionChangedLi
|
539 | 556 | return; |
540 | 557 | lastAddKey = key; |
541 | 558 | lastAddValue = value; |
| 559 | recentTags.put(new Tag(key, value), null); |
542 | 560 | Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, value)); |
543 | 561 | btnAdd.requestFocusInWindow(); |
544 | 562 | } |