- Timestamp:
- 2014-05-14T20:52:13+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PresetListPanel.java
r6986 r7128 2 2 package org.openstreetmap.josm.gui.dialogs.properties; 3 3 4 import java.awt.Cursor; 5 import java.awt.Dimension; 6 import java.awt.Font; 7 import java.awt.GridBagLayout; 8 import java.awt.event.MouseEvent; 9 import java.awt.event.MouseListener; 10 import java.awt.font.TextAttribute; 11 import java.util.Collection; 12 import java.util.Collections; 13 import java.util.List; 14 import java.util.Map; 4 import org.openstreetmap.josm.data.osm.OsmPrimitive; 5 import org.openstreetmap.josm.gui.tagging.PresetHandler; 6 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 7 import org.openstreetmap.josm.gui.tagging.TaggingPresetType; 8 import org.openstreetmap.josm.gui.tagging.PresetLabel; 9 import org.openstreetmap.josm.tools.GBC; 15 10 16 11 import javax.swing.JLabel; 17 12 import javax.swing.JPanel; 13 import java.awt.Dimension; 14 import java.awt.GridBagLayout; 15 import java.awt.event.MouseAdapter; 16 import java.awt.event.MouseEvent; 17 import java.util.Collection; 18 import java.util.Map; 18 19 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 20 import org.openstreetmap.josm.data.osm.Tag; 21 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 22 import org.openstreetmap.josm.gui.tagging.TaggingPresetType; 23 import org.openstreetmap.josm.tools.GBC; 24 20 /** 21 * A list of matching presets for a set of tags. 22 */ 25 23 public class PresetListPanel extends JPanel { 26 24 … … 32 30 } 33 31 34 public interface PresetHandler {35 Collection<OsmPrimitive> getSelection();36 void updateTags(List<Tag> tags);37 }38 39 32 /** 40 * Small helper class that manages the highlighting of the label on hover as well as opening41 * the corresponding preset when clicked33 * Updates the preset list based on the {@code tags} and {@code types}, 34 * and associates an interaction with (matching) presets via {@code presetHandler}. 42 35 */ 43 public static class PresetLabelML implements MouseListener { 44 final JLabel label; 45 final Font hover; 46 final Font normal; 47 final TaggingPreset tag; 48 final PresetHandler presetHandler; 49 50 public PresetLabelML(JLabel lbl, TaggingPreset t, PresetHandler presetHandler) { 51 super(); 52 label = lbl; 53 lbl.setCursor(new Cursor(Cursor.HAND_CURSOR)); 54 normal = label.getFont(); 55 hover = normal.deriveFont(Collections.singletonMap(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DOTTED)); 56 tag = t; 57 this.presetHandler = presetHandler; 58 } 59 @Override 60 public void mouseClicked(MouseEvent arg0) { 61 Collection<OsmPrimitive> selection = tag.createSelection(presetHandler.getSelection()); 62 if (selection == null || selection.isEmpty()) 63 return; 64 int answer = tag.showDialog(selection, false); 65 66 if (answer == TaggingPreset.DIALOG_ANSWER_APPLY) { 67 presetHandler.updateTags(tag.getChangedTags()); 68 } 69 70 } 71 @Override 72 public void mouseEntered(MouseEvent arg0) { 73 label.setFont(hover); 74 } 75 @Override 76 public void mouseExited(MouseEvent arg0) { 77 label.setFont(normal); 78 } 79 @Override 80 public void mousePressed(MouseEvent arg0) {} 81 @Override 82 public void mouseReleased(MouseEvent arg0) {} 83 } 84 85 public static JLabel createLabelForPreset(TaggingPreset t) { 86 JLabel lbl = new JLabel(t.getName() + " …"); 87 lbl.setIcon(t.getIcon()); 88 return lbl; 89 } 90 91 public void updatePresets(final Collection<TaggingPresetType> types, final Map<String, String> tags, PresetHandler presetHandler) { 36 public void updatePresets(final Collection<TaggingPresetType> types, final Map<String, String> tags, final PresetHandler presetHandler) { 92 37 93 38 removeAll(); … … 97 42 } 98 43 99 for (TaggingPreset t : TaggingPreset.getMatchingPresets(types, tags, true)) { 100 final JLabel lbl = createLabelForPreset(t); 101 lbl.addMouseListener(new PresetLabelML(lbl, t, presetHandler)); 44 for (final TaggingPreset t : TaggingPreset.getMatchingPresets(types, tags, true)) { 45 final JLabel lbl = new PresetLabel(t); 46 lbl.addMouseListener(new MouseAdapter() { 47 @Override 48 public void mouseClicked(MouseEvent e) { 49 Collection<OsmPrimitive> selection = t.createSelection(presetHandler.getSelection()); 50 if (selection == null || selection.isEmpty()) 51 return; 52 int answer = t.showDialog(selection, false); 53 54 if (answer == TaggingPreset.DIALOG_ANSWER_APPLY) { 55 presetHandler.updateTags(t.getChangedTags()); 56 } 57 } 58 }); 102 59 add(lbl, GBC.eol().fill(GBC.HORIZONTAL)); 103 60 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r7113 r7128 84 84 import org.openstreetmap.josm.gui.SideButton; 85 85 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 86 import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel.PresetHandler;87 86 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 88 87 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 88 import org.openstreetmap.josm.gui.tagging.PresetHandler; 89 89 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 90 90 import org.openstreetmap.josm.gui.tagging.TaggingPresetType; … … 267 267 membershipTable.getSelectionModel().addListSelectionListener(deleteAction); 268 268 269 JScrollPane scrollPane = (JScrollPane) createLayout(bothTables, true, Arrays.asList(new SideButton[] { 270 this.btnAdd, this.btnEdit, this.btnDel 271 })); 269 JScrollPane scrollPane = (JScrollPane) createLayout(bothTables, true, 270 Arrays.asList(this.btnAdd, this.btnEdit, this.btnDel)); 272 271 273 272 MouseClickWatch mouseClickWatch = new MouseClickWatch(); … … 460 459 // ENTER = editAction, open "edit" dialog 461 460 tagTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) 462 .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "onTableEnter");461 .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "onTableEnter"); 463 462 tagTable.getActionMap().put("onTableEnter",editAction); 464 463 membershipTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r7050 r7128 74 74 import org.openstreetmap.josm.gui.MainMenu; 75 75 import org.openstreetmap.josm.gui.SideButton; 76 import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel.PresetHandler;77 76 import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction; 78 77 import org.openstreetmap.josm.gui.help.HelpUtil; 79 78 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 79 import org.openstreetmap.josm.gui.tagging.PresetHandler; 80 80 import org.openstreetmap.josm.gui.tagging.TagEditorPanel; 81 81 import org.openstreetmap.josm.gui.tagging.TaggingPreset; -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
r7005 r7128 35 35 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent; 36 36 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent; 37 import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel;38 37 import org.openstreetmap.josm.gui.dialogs.relation.sort.RelationSorter; 39 38 import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType; 40 39 import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionTypeCalculator; 41 40 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 41 import org.openstreetmap.josm.gui.tagging.PresetHandler; 42 42 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 43 43 import org.openstreetmap.josm.gui.tagging.TaggingPresetType; … … 55 55 private final CopyOnWriteArrayList<IMemberModelListener> listeners; 56 56 private final OsmDataLayer layer; 57 private final Preset ListPanel.PresetHandler presetHandler;57 private final PresetHandler presetHandler; 58 58 59 59 private final WayConnectionTypeCalculator wayConnectionTypeCalculator = new WayConnectionTypeCalculator(); … … 63 63 * constructor 64 64 */ 65 public MemberTableModel(OsmDataLayer layer, Preset ListPanel.PresetHandler presetHandler) {65 public MemberTableModel(OsmDataLayer layer, PresetHandler presetHandler) { 66 66 members = new ArrayList<>(); 67 67 listeners = new CopyOnWriteArrayList<>(); -
trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java
r6890 r7128 20 20 21 21 import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel; 22 import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel.PresetHandler;23 22 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 24 23 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java
r7118 r7128 12 12 import java.awt.event.ActionEvent; 13 13 import java.awt.event.ActionListener; 14 import java.awt.event.MouseAdapter; 14 15 import java.awt.event.MouseEvent; 15 16 import java.io.File; … … 49 50 import org.openstreetmap.josm.data.osm.Tag; 50 51 import org.openstreetmap.josm.data.preferences.BooleanProperty; 51 import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel;52 52 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField; 53 53 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionItemPriority; … … 68 68 */ 69 69 public final class TaggingPresetItems { 70 private TaggingPresetItems() { } 70 private TaggingPresetItems() { 71 } 71 72 72 73 private static int auto_increment_selected = 0; … … 76 77 77 78 // cache the parsing of types using a LRU cache (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html) 78 private static final Map<String,EnumSet<TaggingPresetType>> typeCache= new LinkedHashMap<>(16, 1.1f, true);79 private static final Map<String,EnumSet<TaggingPresetType>> TYPE_CACHE = new LinkedHashMap<>(16, 1.1f, true); 79 80 80 81 /** 81 82 * Last value of each key used in presets, used for prefilling corresponding fields 82 83 */ 83 private static final Map<String,String> lastValue= new HashMap<>();84 private static final Map<String,String> LAST_VALUES = new HashMap<>(); 84 85 85 86 public static class PresetListEntry { … … 408 409 }).iterator().next(); 409 410 if (t == null) return false; 410 JLabel lbl = PresetListPanel.createLabelForPreset(t);411 lbl.addMouseListener(new PresetListPanel.PresetLabelML(lbl, t, null) {411 JLabel lbl = new PresetLabel(t); 412 lbl.addMouseListener(new MouseAdapter() { 412 413 @Override 413 414 public void mouseClicked(MouseEvent arg0) { … … 597 598 if (auto_increment_selected != 0 && auto_increment != null) { 598 599 try { 599 textField.setText(Integer.toString(Integer.parseInt( lastValue.get(key)) + auto_increment_selected));600 textField.setText(Integer.toString(Integer.parseInt(LAST_VALUES.get(key)) + auto_increment_selected)); 600 601 } catch (NumberFormatException ex) { 601 602 // Ignore - cannot auto-increment if last was non-numeric … … 604 605 else if (!usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) { 605 606 // selected osm primitives are untagged or filling default values feature is enabled 606 if (!"false".equals(use_last_as_default) && lastValue.containsKey(key) && !presetInitiallyMatches) {607 textField.setText( lastValue.get(key));607 if (!"false".equals(use_last_as_default) && LAST_VALUES.containsKey(key) && !presetInitiallyMatches) { 608 textField.setText(LAST_VALUES.get(key)); 608 609 } else { 609 610 textField.setText(default_); … … 724 725 725 726 if (!"false".equals(use_last_as_default) || auto_increment != null) { 726 lastValue.put(key, v);727 LAST_VALUES.put(key, v); 727 728 } 728 729 if (v.equals(originalValue) || (originalValue == null && v.length() == 0)) … … 1093 1094 1094 1095 if (!"false".equals(use_last_as_default)) { 1095 lastValue.put(key, value);1096 LAST_VALUES.put(key, value); 1096 1097 } 1097 1098 changedTags.add(new Tag(key, value)); … … 1235 1236 // all items were unset (and so is default) 1236 1237 originalValue = lhm.get(""); 1237 if ("force".equals(use_last_as_default) && lastValue.containsKey(key) && !presetInitiallyMatches) {1238 combo.setSelectedItem(lhm.get( lastValue.get(key)));1238 if ("force".equals(use_last_as_default) && LAST_VALUES.containsKey(key) && !presetInitiallyMatches) { 1239 combo.setSelectedItem(lhm.get(LAST_VALUES.get(key))); 1239 1240 } else { 1240 1241 combo.setSelectedItem(originalValue); … … 1363 1364 1364 1365 public static EnumSet<TaggingPresetType> getType(String types) throws SAXException { 1365 if ( typeCache.containsKey(types))1366 return typeCache.get(types);1366 if (TYPE_CACHE.containsKey(types)) 1367 return TYPE_CACHE.get(types); 1367 1368 EnumSet<TaggingPresetType> result = EnumSet.noneOf(TaggingPresetType.class); 1368 1369 for (String type : Arrays.asList(types.split(","))) { … … 1374 1375 } 1375 1376 } 1376 typeCache.put(types, result);1377 TYPE_CACHE.put(types, result); 1377 1378 return result; 1378 1379 }
Note:
See TracChangeset
for help on using the changeset viewer.