Changeset 5383 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2012-07-30T19:53:01+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r5378 r5383 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; … … 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; … … 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; … … 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; … … 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; … … 93 95 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter; 94 96 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 97 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 95 98 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 96 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;97 99 import org.openstreetmap.josm.gui.DefaultNameFormatter; 98 100 import org.openstreetmap.josm.gui.ExtendedDialog; … … 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; … … 157 160 int row = propertyTable.rowAtPoint(e.getPoint()); 158 161 if (row > -1) { 159 propertyEdit(row);162 editProperty(row); 160 163 } else { 161 add ();164 addProperty(); 162 165 } 163 166 } else if (e.getSource() == membershipTable) { 164 167 int row = membershipTable.rowAtPoint(e.getPoint()); 165 168 if (row > -1) { 166 membershipEdit(row);169 editMembership(row); 167 170 } 168 171 } 169 172 else 170 173 { 171 add ();174 addProperty(); 172 175 } 173 176 } … … 233 236 */ 234 237 @SuppressWarnings("unchecked") 235 void propertyEdit(int row) {238 private void editProperty(int row) { 236 239 Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected(); 237 240 if (sel.isEmpty()) return; … … 434 437 * @return a list of keys 435 438 */ 436 static List<String> getAutocompletionKeys(String key) {439 private static List<String> getAutocompletionKeys(String key) { 437 440 if ("name".equals(key) || "addr:street".equals(key)) 438 441 return Arrays.asList("addr:street", "name"); … … 447 450 * @param row 448 451 */ 449 void membershipEdit(int row) {452 private void editMembership(int row) { 450 453 Relation relation = (Relation)membershipData.getValueAt(row, 0); 451 454 Main.map.relationListDialog.selectRelation(relation); … … 458 461 private static String lastAddKey = null; 459 462 private static String lastAddValue = null; 463 464 public static final int DEFAULT_LRU_TAGS_NUMBER = 5; 465 public static final int MAX_LRU_TAGS_NUMBER = 9; 466 467 // LRU cache for recently added tags (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html) 468 private static final Map<Tag, Void> recentTags = new LinkedHashMap<Tag, Void>(MAX_LRU_TAGS_NUMBER+1, 1.1f, true) { 469 @Override 470 protected boolean removeEldestEntry(Entry<Tag, Void> eldest) { 471 return size() > MAX_LRU_TAGS_NUMBER; 472 } 473 }; 474 460 475 /** 461 476 * Open the add selection dialog and add a new key/value to the table (and 462 477 * to the dataset, of course). 463 478 */ 464 void add() {479 private void addProperty() { 465 480 Collection<OsmPrimitive> sel; 466 481 if (Main.map.mapMode instanceof DrawAction) { … … 473 488 if (sel.isEmpty()) return; 474 489 475 JPanel p = new JPanel(new BorderLayout());490 JPanel p = new JPanel(new GridBagLayout()); 476 491 p.add(new JLabel("<html>"+trn("This will change up to {0} object.", 477 492 "This will change up to {0} objects.", sel.size(),sel.size()) 478 +"<br><br>"+tr("Please select a key")), BorderLayout.NORTH);493 +"<br><br>"+tr("Please select a key")), GBC.eol()); 479 494 final AutoCompletingComboBox keys = new AutoCompletingComboBox(); 480 495 AutoCompletionManager autocomplete = Main.main.getEditLayer().data.getAutoCompletionManager(); … … 504 519 keys.setEditable(true); 505 520 506 p.add(keys, BorderLayout.CENTER); 507 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); 521 p.add(keys, GBC.eop().fill()); 522 523 p.add(new JLabel(tr("Please select a value")), GBC.eol()); 511 524 final AutoCompletingComboBox values = new AutoCompletingComboBox(); 512 525 values.setEditable(true); 513 p 2.add(values, BorderLayout.CENTER);526 p.add(values, GBC.eop().fill()); 514 527 if (itemToSelect != null) { 515 528 keys.setSelectedItem(itemToSelect); … … 519 532 } 520 533 } 534 535 int recentTagsToShow = Main.pref.getInteger("properties.recently-added-tags", DEFAULT_LRU_TAGS_NUMBER); 536 if (recentTagsToShow > MAX_LRU_TAGS_NUMBER) { 537 recentTagsToShow = MAX_LRU_TAGS_NUMBER; 538 } 539 List<JosmAction> recentTagsActions = new ArrayList<JosmAction>(); 540 suggestRecentlyAddedTags(p, keys, values, recentTagsActions, recentTagsToShow); 521 541 522 542 FocusAdapter focus = addFocusAdapter(-1, keys, values, autocomplete, defaultACItemComparator); … … 542 562 dialog.setModalityType(ModalityType.DOCUMENT_MODAL); 543 563 dialog.setVisible(true); 564 565 for (JosmAction action : recentTagsActions) { 566 action.destroy(); 567 } 544 568 545 569 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) … … 551 575 lastAddKey = key; 552 576 lastAddValue = value; 577 recentTags.put(new Tag(key, value), null); 553 578 Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, value)); 554 579 btnAdd.requestFocusInWindow(); 580 } 581 582 private void suggestRecentlyAddedTags(JPanel p, final AutoCompletingComboBox keys, final AutoCompletingComboBox values, List<JosmAction> tagsActions, int tagsToShow) { 583 if (tagsToShow > 0 && !recentTags.isEmpty()) { 584 p.add(new JLabel(tr("Recently added tags")), GBC.eol()); 585 586 int count = 1; 587 // We store the maximum number (9) of recent tags to allow dynamic change of number of tags shown in the preferences. 588 // This implies to iterate in descending order, as the oldest elements will only be removed after we reach the maximum numbern and not the number of tags to show. 589 // However, as Set does not allow to iterate in descending order, we need to copy its elements into a List we can access in reverse order. 590 List<Tag> tags = new LinkedList<Tag>(recentTags.keySet()); 591 for (int i = tags.size()-1; i >= 0 && count <= tagsToShow; i--, count++) { 592 final Tag t = tags.get(i); 593 // Find and display icon 594 ImageIcon icon = MapPaintStyles.getNodeIcon(t, false); // Filters deprecated icon 595 if (icon == null) { 596 icon = new ImageIcon(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)); 597 } 598 GridBagConstraints gbc = new GridBagConstraints(); 599 gbc.ipadx = 5; 600 p.add(new JLabel(icon), gbc); 601 // Create action for reusing the tag, with keyboard shortcut Ctrl+(1-5) 602 String actionShortcutKey = "properties:recent:"+count; 603 Shortcut sc = Shortcut.registerShortcut(actionShortcutKey, null, KeyEvent.VK_0+count, Shortcut.CTRL); 604 final JosmAction action = new JosmAction(actionShortcutKey, null, tr("Use this tag again"), sc, false) { 605 @Override 606 public void actionPerformed(ActionEvent e) { 607 keys.getEditor().setItem(t.getKey()); 608 values.getEditor().setItem(t.getValue()); 609 } 610 }; 611 p.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sc.getKeyStroke(), actionShortcutKey); 612 p.getActionMap().put(actionShortcutKey, action); 613 tagsActions.add(action); 614 // Display clickable tag 615 final JLabel tagLabel = new JLabel("<html>" 616 + "<style>td{border:1px solid gray; font-weight:normal;}</style>" 617 + "<table><tr><td>" + t.toString() + "</td></tr></table></html>"); 618 tagLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 619 tagLabel.setToolTipText((String) action.getValue(Action.SHORT_DESCRIPTION)); 620 tagLabel.addMouseListener(new MouseAdapter() { 621 @Override 622 public void mouseClicked(MouseEvent e) { 623 action.actionPerformed(null); 624 } 625 }); 626 p.add(tagLabel, GBC.eol()); 627 } 628 } 555 629 } 556 630 … … 1189 1263 @Override 1190 1264 public void actionPerformed(ActionEvent e) { 1191 add ();1265 addProperty(); 1192 1266 } 1193 1267 } … … 1207 1281 if (propertyTable.getSelectedRowCount() == 1) { 1208 1282 int row = propertyTable.getSelectedRow(); 1209 propertyEdit(row);1283 editProperty(row); 1210 1284 } else if (membershipTable.getSelectedRowCount() == 1) { 1211 1285 int row = membershipTable.getSelectedRow(); 1212 membershipEdit(row);1286 editMembership(row); 1213 1287 } 1214 1288 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r5219 r5383 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; … … 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; … … 118 122 .setArchive(source.zipIcons) 119 123 .setOptional(true).get(); 124 } 125 126 public static ImageIcon getNodeIcon(Tag tag) { 127 return getNodeIcon(tag, true); 128 } 129 130 public static ImageIcon getNodeIcon(Tag tag, boolean includeDeprecatedIcon) { 131 if (tag != null) { 132 Node virtualNode = new Node(); 133 virtualNode.put(tag.getKey(), tag.getValue()); 134 StyleList styleList = getStyles().generateStyles(virtualNode, 0, null, false).a; 135 if (styleList != null) { 136 for (Iterator<ElemStyle> it = styleList.iterator(); it.hasNext(); ) { 137 ElemStyle style = it.next(); 138 if (style instanceof NodeElemStyle) { 139 MapImage mapImage = ((NodeElemStyle) style).mapImage; 140 if (mapImage != null) { 141 if (includeDeprecatedIcon || mapImage.name == null || !mapImage.name.equals("misc/deprecated.png")) { 142 return new ImageIcon(mapImage.getImage()); 143 } else { 144 return null; // Deprecated icon found but not wanted 145 } 146 } 147 } 148 } 149 } 150 } 151 return null; 120 152 } 121 153
Note:
See TracChangeset
for help on using the changeset viewer.