Ticket #7671: 7671v3.patch
File 7671v3.patch, 10.5 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; 10 import java.awt.Dialog.ModalityType; 9 11 import java.awt.Dimension; 10 12 import java.awt.Font; 13 import java.awt.GridBagConstraints; 11 14 import java.awt.GridBagLayout; 12 15 import java.awt.Point; 13 16 import java.awt.Toolkit; 14 import java.awt.Dialog.ModalityType;15 17 import java.awt.datatransfer.Clipboard; 16 18 import java.awt.datatransfer.Transferable; 17 19 import java.awt.event.ActionEvent; 18 20 import java.awt.event.ActionListener; 19 21 import java.awt.event.FocusAdapter; 20 22 import java.awt.event.FocusEvent; 21 import java.awt.event.InputEvent;22 23 import java.awt.event.KeyEvent; 23 24 import java.awt.event.MouseAdapter; 24 25 import java.awt.event.MouseEvent; 26 import java.awt.image.BufferedImage; 25 27 import java.net.HttpURLConnection; 26 28 import java.net.URI; 27 29 import java.net.URLEncoder; … … 34 36 import java.util.HashMap; 35 37 import java.util.HashSet; 36 38 import java.util.Iterator; 39 import java.util.LinkedHashMap; 37 40 import java.util.LinkedList; 38 41 import java.util.List; 39 42 import java.util.Map; 43 import java.util.Map.Entry; 40 44 import java.util.Set; 41 45 import java.util.TreeMap; 42 46 import java.util.TreeSet; 43 47 import java.util.Vector; 44 import java.util.Map.Entry;45 48 46 49 import javax.swing.AbstractAction; 47 50 import javax.swing.Action; 48 51 import javax.swing.Box; 49 52 import javax.swing.DefaultListCellRenderer; 50 import javax.swing.I nputMap;53 import javax.swing.ImageIcon; 51 54 import javax.swing.JComboBox; 52 55 import javax.swing.JComponent; 53 56 import javax.swing.JDialog; … … 61 64 import javax.swing.JTable; 62 65 import javax.swing.KeyStroke; 63 66 import javax.swing.ListSelectionModel; 64 import javax.swing.SwingUtilities;65 67 import javax.swing.event.ListSelectionEvent; 66 68 import javax.swing.event.ListSelectionListener; 67 69 import javax.swing.event.PopupMenuListener; … … 92 94 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 93 95 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter; 94 96 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 95 import org.openstreetmap.josm.data.osm.event.SelectionEventManager;96 97 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 98 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 97 99 import org.openstreetmap.josm.gui.DefaultNameFormatter; 98 100 import org.openstreetmap.josm.gui.ExtendedDialog; 99 101 import org.openstreetmap.josm.gui.MapFrame; … … 104 106 import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask; 105 107 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 106 108 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 109 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 107 110 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 108 111 import org.openstreetmap.josm.gui.tagging.TaggingPreset.PresetType; 109 112 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox; … … 457 460 458 461 private static String lastAddKey = null; 459 462 private static String lastAddValue = null; 463 // LRU cache for recently added tags (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html) 464 private static final Map<Tag, Void> recentTags = new LinkedHashMap<Tag, Void>(5, 1.1f, true); 465 460 466 /** 461 467 * Open the add selection dialog and add a new key/value to the table (and 462 468 * to the dataset, of course). … … 472 478 } 473 479 if (sel.isEmpty()) return; 474 480 475 JPanel p = new JPanel(new BorderLayout());481 JPanel p = new JPanel(new GridBagLayout()); 476 482 p.add(new JLabel("<html>"+trn("This will change up to {0} object.", 477 483 "This will change up to {0} objects.", sel.size(),sel.size()) 478 +"<br><br>"+tr("Please select a key")), BorderLayout.NORTH);484 +"<br><br>"+tr("Please select a key")), GBC.eol()); 479 485 final AutoCompletingComboBox keys = new AutoCompletingComboBox(); 480 486 AutoCompletionManager autocomplete = Main.main.getEditLayer().data.getAutoCompletionManager(); 481 487 List<AutoCompletionListItem> keyList = autocomplete.getKeys(); … … 503 509 keys.setPossibleACItems(keyList); 504 510 keys.setEditable(true); 505 511 506 p.add(keys, BorderLayout.CENTER);512 p.add(keys, GBC.eop().fill()); 507 513 508 JPanel p2 = new JPanel(new BorderLayout()); 509 p.add(p2, BorderLayout.SOUTH); 510 p2.add(new JLabel(tr("Please select a value")), BorderLayout.NORTH); 514 p.add(new JLabel(tr("Please select a value")), GBC.eol()); 511 515 final AutoCompletingComboBox values = new AutoCompletingComboBox(); 512 516 values.setEditable(true); 513 p 2.add(values, BorderLayout.CENTER);517 p.add(values, GBC.eop().fill()); 514 518 if (itemToSelect != null) { 515 519 keys.setSelectedItem(itemToSelect); 516 520 /* don't add single chars, as they are no properly selected */ … … 518 522 values.setSelectedItem(lastAddValue); 519 523 } 520 524 } 525 526 if (!recentTags.isEmpty()) { 527 p.add(new JLabel(tr("Recently added tags")), GBC.eol()); 528 } 529 530 List<JosmAction> recentTagsActions = new ArrayList<JosmAction>(); 531 532 int count = 1; 533 for (final Tag t : recentTags.keySet()) { 534 // Find and display icon 535 ImageIcon icon = MapPaintStyles.getNodeIcon(t); 536 if (icon == null) { 537 icon = new ImageIcon(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)); 538 } 539 GridBagConstraints gbc = new GridBagConstraints(); 540 gbc.ipadx = 5; 541 p.add(new JLabel(icon), gbc); 542 // Create action for reusing the tag, with keyboard shortcut Ctrl+(1-5) 543 String actionShortcutKey = "properties:recent:"+count; 544 Shortcut sc = Shortcut.registerShortcut(actionShortcutKey, null, KeyEvent.VK_0+count, Shortcut.CTRL); 545 final JosmAction action = new JosmAction(actionShortcutKey, null, tr("Use this tag again"), sc, false) { 546 @Override 547 public void actionPerformed(ActionEvent e) { 548 keys.getEditor().setItem(t.getKey()); 549 values.getEditor().setItem(t.getValue()); 550 } 551 }; 552 p.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sc.getKeyStroke(), actionShortcutKey); 553 p.getActionMap().put(actionShortcutKey, action); 554 recentTagsActions.add(action); 555 // Display clickable tag 556 final JLabel tagLabel = new JLabel("<html>" 557 + "<style>td{border:1px solid gray; font-weight:normal;}</style>" 558 + "<table><tr><td>" + t.toString() + "</td></tr></table></html>"); 559 tagLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 560 tagLabel.setToolTipText((String) action.getValue(Action.SHORT_DESCRIPTION)); 561 tagLabel.addMouseListener(new MouseAdapter() { 562 @Override 563 public void mouseClicked(MouseEvent e) { 564 action.actionPerformed(null); 565 } 566 }); 567 p.add(tagLabel, GBC.eol()); 568 count++; 569 } 521 570 522 571 FocusAdapter focus = addFocusAdapter(-1, keys, values, autocomplete, defaultACItemComparator); 523 572 // fire focus event in advance or otherwise the popup list will be too small at first … … 541 590 JDialog dialog = pane.createDialog(Main.parent, tr("Add value?")); 542 591 dialog.setModalityType(ModalityType.DOCUMENT_MODAL); 543 592 dialog.setVisible(true); 593 594 for (JosmAction action : recentTagsActions) { 595 action.destroy(); 596 } 544 597 545 598 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) 546 599 return; … … 550 603 return; 551 604 lastAddKey = key; 552 605 lastAddValue = value; 606 recentTags.put(new Tag(key, value), null); 553 607 Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, value)); 554 608 btnAdd.requestFocusInWindow(); 555 609 } 556 610 557 611 /** 558 612 * @param allData 559 613 * @param keys -
core/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
10 10 import java.util.ArrayList; 11 11 import java.util.Arrays; 12 12 import java.util.Collection; 13 import java.util.Iterator; 13 14 import java.util.LinkedList; 14 15 import java.util.List; 15 16 import java.util.concurrent.CopyOnWriteArrayList; … … 18 19 import javax.swing.SwingUtilities; 19 20 20 21 import org.openstreetmap.josm.Main; 22 import org.openstreetmap.josm.data.osm.Node; 23 import org.openstreetmap.josm.data.osm.Tag; 21 24 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 25 import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList; 22 26 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 23 27 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource; 24 28 import org.openstreetmap.josm.gui.preferences.SourceEntry; … … 118 122 .setArchive(source.zipIcons) 119 123 .setOptional(true).get(); 120 124 } 125 126 public static ImageIcon getNodeIcon(Tag tag) { 127 if (tag != null) { 128 Node virtualNode = new Node(); 129 virtualNode.put(tag.getKey(), tag.getValue()); 130 StyleList styleList = getStyles().generateStyles(virtualNode, 0, null, false).a; 131 if (styleList != null) { 132 for (Iterator<ElemStyle> it = styleList.iterator(); it.hasNext(); ) { 133 ElemStyle style = styleList.iterator().next(); 134 if (style instanceof NodeElemStyle) { 135 MapImage mapImage = ((NodeElemStyle) style).mapImage; 136 if (mapImage != null) { 137 return new ImageIcon(mapImage.getImage()); 138 } 139 } 140 } 141 } 142 } 143 return null; 144 } 121 145 122 146 public static List<String> getIconSourceDirs(StyleSource source) { 123 147 List<String> dirs = new LinkedList<String>();