Ticket #7671: 7671v2.patch
File 7671v2.patch, 5.1 KB (added by , 13 years ago) |
---|
-
core/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
6 6 7 7 import java.awt.BorderLayout; 8 8 import java.awt.Component; 9 import java.awt.Cursor; 9 10 import java.awt.Dimension; 10 11 import java.awt.Font; 11 12 import java.awt.GridBagLayout; … … 18 19 import java.awt.event.ActionListener; 19 20 import java.awt.event.FocusAdapter; 20 21 import java.awt.event.FocusEvent; 21 import java.awt.event.InputEvent;22 22 import java.awt.event.KeyEvent; 23 23 import java.awt.event.MouseAdapter; 24 24 import java.awt.event.MouseEvent; … … 34 34 import java.util.HashMap; 35 35 import java.util.HashSet; 36 36 import java.util.Iterator; 37 import java.util.LinkedHashMap; 37 38 import java.util.LinkedList; 38 39 import java.util.List; 39 40 import java.util.Map; … … 47 48 import javax.swing.Action; 48 49 import javax.swing.Box; 49 50 import javax.swing.DefaultListCellRenderer; 50 import javax.swing.InputMap;51 51 import javax.swing.JComboBox; 52 52 import javax.swing.JComponent; 53 53 import javax.swing.JDialog; … … 61 61 import javax.swing.JTable; 62 62 import javax.swing.KeyStroke; 63 63 import javax.swing.ListSelectionModel; 64 import javax.swing.SwingUtilities;65 64 import javax.swing.event.ListSelectionEvent; 66 65 import javax.swing.event.ListSelectionListener; 67 66 import javax.swing.event.PopupMenuListener; … … 456 455 457 456 private static String lastAddKey = null; 458 457 private static String lastAddValue = null; 458 // LRU cache for recently added tags (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html) 459 private static final Map<Tag, Void> recentTags = new LinkedHashMap<Tag, Void>(5, 1.1f, true); 460 459 461 /** 460 462 * Open the add selection dialog and add a new key/value to the table (and 461 463 * to the dataset, of course). … … 466 468 Collection<OsmPrimitive> sel = ds.getSelected(); 467 469 if (sel.isEmpty()) return; 468 470 469 JPanel p = new JPanel(new BorderLayout());471 JPanel p = new JPanel(new GridBagLayout()); 470 472 p.add(new JLabel("<html>"+trn("This will change up to {0} object.", 471 473 "This will change up to {0} objects.", sel.size(),sel.size()) 472 +"<br><br>"+tr("Please select a key")), BorderLayout.NORTH);474 +"<br><br>"+tr("Please select a key")), GBC.eol()); 473 475 final AutoCompletingComboBox keys = new AutoCompletingComboBox(); 474 476 AutoCompletionManager autocomplete = Main.main.getEditLayer().data.getAutoCompletionManager(); 475 477 List<AutoCompletionListItem> keyList = autocomplete.getKeys(); … … 497 499 keys.setPossibleACItems(keyList); 498 500 keys.setEditable(true); 499 501 500 p.add(keys, BorderLayout.CENTER);502 p.add(keys, GBC.eop().fill()); 501 503 502 JPanel p2 = new JPanel(new BorderLayout()); 503 p.add(p2, BorderLayout.SOUTH); 504 p2.add(new JLabel(tr("Please select a value")), BorderLayout.NORTH); 504 p.add(new JLabel(tr("Please select a value")), GBC.eol()); 505 505 final AutoCompletingComboBox values = new AutoCompletingComboBox(); 506 506 values.setEditable(true); 507 p 2.add(values, BorderLayout.CENTER);507 p.add(values, GBC.eop().fill()); 508 508 if (itemToSelect != null) { 509 509 keys.setSelectedItem(itemToSelect); 510 510 /* don't add single chars, as they are no properly selected */ … … 512 512 values.setSelectedItem(lastAddValue); 513 513 } 514 514 } 515 516 if (!recentTags.isEmpty()) { 517 p.add(new JLabel(tr("Recently added tags")), GBC.eol()); 518 } 515 519 520 int count = 1; 521 for (final Tag t : recentTags.keySet()) { 522 final JLabel l = new JLabel("<html>" 523 + "<style>td{border:1px solid gray; font-weight:normal;}</style>" 524 + "<table><tr><td>" + t.toString() + "</td></tr></table></html>"); 525 l.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 526 l.setToolTipText(tr("Click to use this tag again")); 527 l.addMouseListener(new MouseAdapter() { 528 @Override 529 public void mouseClicked(MouseEvent e) { 530 keys.getEditor().setItem(t.getKey()); 531 values.getEditor().setItem(t.getValue()); 532 } 533 }); 534 p.add(new JLabel(Integer.toString(count++)+". ")); 535 p.add(l, GBC.eol()); 536 } 537 516 538 FocusAdapter focus = addFocusAdapter(-1, keys, values, autocomplete, defaultACItemComparator); 517 539 // fire focus event in advance or otherwise the popup list will be too small at first 518 540 focus.focusGained(null); … … 544 566 return; 545 567 lastAddKey = key; 546 568 lastAddValue = value; 569 recentTags.put(new Tag(key, value), null); 547 570 Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, value)); 548 571 btnAdd.requestFocusInWindow(); 549 572 }