Changeset 16574 in osm
- Timestamp:
- 2009-07-19T12:17:51+02:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/TagEditorDialog.java
r15319 r16574 43 43 import org.openstreetmap.josm.plugins.tageditor.tagspec.ui.ITagSelectorListener; 44 44 import org.openstreetmap.josm.plugins.tageditor.tagspec.ui.TabularTagSelector; 45 45 import static org.openstreetmap.josm.plugins.tageditor.josm.CompatibilityUtil.getCurrentDataSet; 46 46 /** 47 47 * The dialog for editing name/value-pairs (aka <em>tags</em>) associated with {@link OsmPrimitive}s. … … 345 345 model.updateJOSMSelection(); 346 346 347 Collection<OsmPrimitive> sel = Main.ds.getSelected();347 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 348 348 DataSet.fireSelectionChanged(sel); 349 349 Main.parent.repaint(); // repaint all - drawing could have been changed -
applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/ac/AutoCompletionCache.java
r14324 r16574 8 8 import org.openstreetmap.josm.Main; 9 9 import org.openstreetmap.josm.data.osm.OsmPrimitive; 10 10 import static org.openstreetmap.josm.plugins.tageditor.josm.CompatibilityUtil.getCurrentDataSet; 11 11 /** 12 12 * AutoCompletionCache temporarily holds a cache of keys with a list of … … 18 18 * <li>any value used in a tag for a specific key is part of the autocompletion list of 19 19 * this key</li> 20 * </ol> 20 * </ol> 21 21 * 22 22 * Building up auto completion lists should not 23 23 * slow down tabbing from input field to input field. Looping through the complete 24 24 * data set in order to build up the auto completion list for a specific input 25 * field is not efficient enough, hence this cache. 25 * field is not efficient enough, hence this cache. 26 26 * 27 27 */ 28 28 public class AutoCompletionCache { 29 29 30 30 /** the cache */ 31 31 private HashMap<String, ArrayList<String>> cache; 32 32 33 33 /** 34 * constructor 34 * constructor 35 35 */ 36 36 public AutoCompletionCache() { … … 39 39 40 40 /** 41 * make sure, <code>key</code> is in the cache 41 * make sure, <code>key</code> is in the cache 42 42 * 43 * @param key the key 43 * @param key the key 44 44 */ 45 45 protected void cacheKey(String key) { 46 if (cache.containsKey(key)) {46 if (cache.containsKey(key)) 47 47 return; 48 }else {48 else { 49 49 cache.put(key, new ArrayList<String>()); 50 50 } 51 51 } 52 52 53 53 /** 54 * make sure, value is one of the auto completion values allowed for key 54 * make sure, value is one of the auto completion values allowed for key 55 55 * 56 * @param key the key 57 * @param value the value 56 * @param key the key 57 * @param value the value 58 58 */ 59 59 protected void cacheValue(String key, String value) { … … 64 64 } 65 65 } 66 66 67 67 /** 68 68 * make sure, the keys and values of all tags held by primitive are 69 * in the auto completion cache 70 * 71 * @param primitive an OSM primitive 69 * in the auto completion cache 70 * 71 * @param primitive an OSM primitive 72 72 */ 73 73 protected void cachePrimitive(OsmPrimitive primitive) { … … 77 77 } 78 78 } 79 79 80 80 /** 81 81 * initializes the cache from the current JOSM dataset {@link OsmPrimitive}s. … … 84 84 public void initFromJOSMDataset() { 85 85 cache = new HashMap<String, ArrayList<String>>(); 86 Collection<OsmPrimitive> ds = Main.ds.allNonDeletedPrimitives();86 Collection<OsmPrimitive> ds = getCurrentDataSet().allNonDeletedPrimitives(); 87 87 for (OsmPrimitive primitive : ds) { 88 88 cachePrimitive(primitive); 89 89 } 90 90 } 91 91 92 92 /** 93 93 * replies the keys held by the cache 94 * 95 * @return the list of keys held by the cache 94 * 95 * @return the list of keys held by the cache 96 96 */ 97 97 public List<String> getKeys() { 98 98 return new ArrayList<String>(cache.keySet()); 99 99 } 100 101 100 101 102 102 /** 103 103 * replies the auto completion values allowed for a specific key. Replies 104 104 * an empty list if key is null or if key is not in {@link #getKeys()}. 105 105 * 106 * @param key 107 * @return the list of auto completion values 106 * @param key 107 * @return the list of auto completion values 108 108 */ 109 109 public List<String> getValues(String key) { 110 if (!cache.containsKey(key)) {110 if (!cache.containsKey(key)) 111 111 return new ArrayList<String>(); 112 } else {112 else 113 113 return cache.get(key); 114 }115 114 } 116 115 } -
applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/ac/AutoCompletionContext.java
r14324 r16574 2 2 3 3 import org.openstreetmap.josm.Main; 4 import static org.openstreetmap.josm.plugins.tageditor.josm.CompatibilityUtil.getCurrentDataSet; 4 5 5 6 public class AutoCompletionContext { 6 7 7 8 private boolean selectionIncludesNodes = false; 8 9 private boolean selectionIncludesWays = false; 9 10 private boolean selectionIncludesRelations = false; 10 private boolean selectionEmpty = false; 11 11 private boolean selectionEmpty = false; 12 12 13 public AutoCompletionContext(){ 13 14 } 14 15 15 16 public void initFromJOSMSelection() { 16 selectionIncludesNodes = ! Main.ds.getSelectedNodes().isEmpty();17 selectionIncludesWays = ! Main.ds.getSelectedWays().isEmpty();18 selectionIncludesRelations = ! Main.ds.getSelectedRelations().isEmpty();19 selectionEmpty = ( Main.ds.getSelected().size() == 0);17 selectionIncludesNodes = ! getCurrentDataSet().getSelectedNodes().isEmpty(); 18 selectionIncludesWays = !getCurrentDataSet().getSelectedWays().isEmpty(); 19 selectionIncludesRelations = !getCurrentDataSet().getSelectedRelations().isEmpty(); 20 selectionEmpty = (getCurrentDataSet().getSelected().size() == 0); 20 21 } 21 22 22 23 23 24 public boolean isSelectionEmpty() { 24 25 return selectionEmpty; … … 48 49 this.selectionIncludesRelations = selectionIncludesRelations; 49 50 } 50 51 52 51 52 53 53 54 54 55 } -
applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/editor/TagEditorModel.java
r15319 r16574 23 23 import org.openstreetmap.josm.plugins.tageditor.preset.Tag; 24 24 import org.openstreetmap.josm.plugins.tageditor.tagspec.KeyValuePair; 25 25 import static org.openstreetmap.josm.plugins.tageditor.josm.CompatibilityUtil.getCurrentDataSet; 26 26 27 27 /** … … 273 273 */ 274 274 public void initFromJOSMSelection() { 275 Collection<OsmPrimitive> selection = Main.ds.getSelected();275 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 276 276 clear(); 277 277 for (OsmPrimitive element : selection) { … … 354 354 public void updateJOSMSelection() { 355 355 ArrayList<Command> commands = new ArrayList<Command>(); 356 Collection<OsmPrimitive> selection = Main.ds.getSelected();356 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 357 357 if (selection == null) 358 358 return; -
applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/editor/TagFieldEditor.java
r14325 r16574 20 20 /** 21 21 * TagFieldEditor is an editor for tag names or tag values. It supports auto completion 22 * from a list of auto completion items. 22 * from a list of auto completion items. 23 23 * 24 24 */ 25 25 public class TagFieldEditor extends JTextField { 26 26 27 27 static private Logger logger = Logger.getLogger(TagFieldEditor.class.getName()); 28 29 28 29 30 30 /** 31 * The document model for the editor 31 * The document model for the editor 32 32 */ 33 33 class AutoCompletionDocument extends PlainDocument { 34 35 /** 36 * inserts a string at a specific position 37 * 38 */ 39 public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { 40 if (autoCompletionList == null) { 41 super.insertString(offs, str, a); 42 return; 43 } 44 String currentText = getText(0, getLength()); 45 String prefix = currentText.substring(0, offs); 46 autoCompletionList.applyFilter(prefix+str); 47 if (autoCompletionList.getFilteredSize()>0) { 48 // there are matches. Insert the new text and highlight the 49 // auto completed suffix 50 // 51 String matchingString = autoCompletionList.getFilteredItem(0).getValue(); 52 remove(0,getLength()); 53 super.insertString(0,matchingString,a); 54 55 // highlight from end to insert position 56 // 57 setCaretPosition(getLength()); 58 moveCaretPosition(offs + str.length()); 59 } else { 60 // there are no matches. Insert the new text, do not highlight 61 // 62 String newText = prefix + str; 63 remove(0,getLength()); 64 super.insertString(0,newText,a); 65 setCaretPosition(getLength()); 66 } 67 } 68 69 34 35 /** 36 * inserts a string at a specific position 37 * 38 */ 39 @Override 40 public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { 41 if (autoCompletionList == null) { 42 super.insertString(offs, str, a); 43 return; 44 } 45 // if the current offset isn't at the end of the document we don't autocomplete. 46 // If a highlighted autocompleted suffix was present and we get here Swing has 47 // already removed it from the document. getLength() therefore doesn't include the 48 // autocompleted suffix. 49 // 50 if (offs < getLength()) { 51 super.insertString(offs, str, a); 52 return; 53 } 54 55 String currentText = getText(0, getLength()); 56 String prefix = currentText.substring(0, offs); 57 autoCompletionList.applyFilter(prefix+str); 58 if (autoCompletionList.getFilteredSize()>0) { 59 // there are matches. Insert the new text and highlight the 60 // auto completed suffix 61 // 62 String matchingString = autoCompletionList.getFilteredItem(0).getValue(); 63 remove(0,getLength()); 64 super.insertString(0,matchingString,a); 65 66 // highlight from end to insert position 67 // 68 setCaretPosition(getLength()); 69 moveCaretPosition(offs + str.length()); 70 } else { 71 // there are no matches. Insert the new text, do not highlight 72 // 73 String newText = prefix + str; 74 remove(0,getLength()); 75 super.insertString(0,newText,a); 76 setCaretPosition(getLength()); 77 } 78 } 79 80 70 81 } 71 82 72 83 73 84 /** the auto completion list user input is matched against */ 74 85 protected AutoCompletionList autoCompletionList = null; 75 86 76 87 /** 77 88 * creates the default document model for this editor 78 89 * 79 90 */ 91 @Override 80 92 protected Document createDefaultModel() { 81 93 return new AutoCompletionDocument(); 82 94 } 83 95 84 96 /** 85 * constructor 97 * constructor 86 98 */ 87 99 public TagFieldEditor() { 88 100 89 101 addFocusListener( 90 91 @Override public void focusGained(FocusEvent e) { 92 selectAll(); 93 applyFilter(getText()); 94 }95 96 ); 97 102 new FocusAdapter() { 103 @Override public void focusGained(FocusEvent e) { 104 selectAll(); 105 applyFilter(getText()); 106 } 107 } 108 ); 109 98 110 addKeyListener( 99 new KeyAdapter() { 111 new KeyAdapter() { 100 112 101 @Override 102 public void keyReleased(KeyEvent e) { 103 if (getText().equals("")) { 104 applyFilter(""); 105 }106 }107 } 113 @Override 114 public void keyReleased(KeyEvent e) { 115 if (getText().equals("")) { 116 applyFilter(""); 117 } 118 } 119 } 108 120 ); 109 } 110 121 } 122 111 123 protected void applyFilter(String filter) { 112 124 if (autoCompletionList != null) { … … 114 126 } 115 127 } 116 128 117 129 /** 118 130 * 119 * @return the auto completion list; may be null, if no auto completion list is set 131 * @return the auto completion list; may be null, if no auto completion list is set 120 132 */ 121 133 public AutoCompletionList getAutoCompletionList() { 122 134 return autoCompletionList; 123 135 } 124 125 136 126 137 /** 127 * sets the auto completion list 128 * @param autoCompletionList the auto completion list; if null, auto completion is 138 * sets the auto completion list 139 * @param autoCompletionList the auto completion list; if null, auto completion is 129 140 * disabled 130 141 */ … … 133 144 } 134 145 135 136 137 138 139 146 } -
applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/preset/Item.java
r14326 r16574 20 20 21 21 private static Logger logger = Logger.getLogger(Item.class.getName()); 22 22 23 23 private String name; 24 24 private String iconName; … … 28 28 private Group parent; 29 29 30 public Item() { 30 public Item() { 31 31 tags = new ArrayList<Tag>(); 32 32 } 33 33 34 34 public Group getParent() { 35 35 return parent; … … 40 40 } 41 41 42 42 43 43 public String getLabel() { 44 44 return label; … … 49 49 } 50 50 51 51 52 52 public Item(String name) { 53 53 setName(name); … … 69 69 this.iconName = iconName; 70 70 } 71 71 72 72 public Icon getIcon() { 73 73 if (icon == null) { 74 74 // load the icon from the JOSM resources, use Main classloader 75 // for loading 75 // for loading 76 76 URL url = Main.class.getResource("/images/" + getIconName()); 77 77 if (url == null) { … … 83 83 Image i = icon.getImage().getScaledInstance(16, 16, Image.SCALE_DEFAULT); 84 84 icon = new ImageIcon(i); 85 85 86 86 } 87 return icon; 87 return icon; 88 88 } 89 89 90 90 public void addTag(Tag tag) { 91 91 tags.add(tag); 92 92 } 93 93 94 94 public List<Tag> getTags() { 95 return tags; 95 return tags; 96 96 } 97 97 98 98 public void dump(IndentWriter writer) throws IOException { 99 99 writer.indent(); … … 110 110 writer.decLevel(); 111 111 writer.writeLine("</item>"); 112 } 113 112 } 113 114 @Override 114 115 public String toString() { 115 116 StringBuilder builder = new StringBuilder(); 116 117 builder.append("[") 117 118 119 120 121 122 118 .append(getClass().getName()) 119 .append(":") 120 .append("name=") 121 .append(name) 122 .append("]"); 123 123 124 return builder.toString(); 124 125 } 125 126 127 126 } -
applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/tagspec/TagSpecification.java
r14329 r16574 9 9 /** 10 10 * A TagSpecifications specifies a tag. The specifications consists of the following 11 * elements: 11 * elements: 12 12 * <ul> 13 13 * <li>the <strong>key</strong> the of the tag</li> 14 14 * <li>the <strong>type</strong> of the tag</li> 15 * <li>whether the tag is applicable to a node, a way or a relation</li> 15 * <li>whether the tag is applicable to a node, a way or a relation</li> 16 16 * </ul> 17 17 * @author Gubaer … … 19 19 */ 20 20 public class TagSpecification { 21 21 22 22 /** the key of the tag */ 23 23 private String key; 24 24 25 25 /** the type of the tag */ 26 26 private String type; 27 27 28 28 /** the type of the tag */ 29 29 30 30 private boolean applicableToNode = true; 31 31 private boolean applicableToWay = true; 32 32 private boolean applicableToRelation = true; 33 33 34 34 private ArrayList<LableSpecification> lables = null; 35 36 35 36 37 37 /** 38 38 * constructor … … 41 41 lables = new ArrayList<LableSpecification>(); 42 42 } 43 44 43 44 @Override 45 45 public String toString() { 46 46 StringBuilder builder = new StringBuilder(); … … 54 54 return builder.toString(); 55 55 } 56 56 57 57 /** 58 * @return the list of predefined labels for this tag; an empty list if no 59 * labels are defined 58 * @return th e list of predefined labels for this tag; an empty list if no 59 * labels are defined 60 60 */ 61 61 public List<LableSpecification> getLables() { 62 62 return lables; 63 63 } 64 65 64 65 66 66 /** 67 67 * sets the list of lables for this tag specification 68 68 * 69 69 * @param lables the list of lables; must not be null 70 * @exception IllegalArgumentException thrown, if lables is null 70 * @exception IllegalArgumentException thrown, if lables is null 71 71 */ 72 72 public void setLables(List<LableSpecification> lables) throws IllegalArgumentException { 73 if (lables == null) {73 if (lables == null) 74 74 throw new IllegalArgumentException("argument 'lables' must not be null"); 75 }76 75 this.lables.clear(); 77 76 for (LableSpecification l : lables) { … … 79 78 } 80 79 } 81 82 80 81 83 82 /** 84 83 * adds a lable to the list of lables for this tag specification. The lable 85 84 * is only added if i 86 * 85 * 87 86 * @param lable the lable to add; must not be null 88 87 * @exception IllegalArgumentException thrown, if lable is null 89 88 */ 90 89 public void addLable(LableSpecification lable) throws IllegalArgumentException { 91 if (lable == null) {90 if (lable == null) 92 91 throw new IllegalArgumentException("argument 'lable' must not be null"); 93 }94 92 if (!this.lables.contains(lable)) { 95 93 this.lables.add(lable); 96 94 } 97 95 } 98 96 99 97 public boolean isApplicable(AutoCompletionContext context) { 100 98 boolean ret = false; 101 99 if (context.isSelectionEmpty()) { 102 ret = true; 100 ret = true; 103 101 } else { 104 102 ret = ret || (applicableToNode && context.isSelectionIncludesNodes()); … … 108 106 return ret; 109 107 } 110 108 111 109 /* --------------------------------------------------------------------------- */ 112 110 /* setters/getters */ … … 141 139 public void setApplicableToRelation(boolean applicableToRelation) { 142 140 this.applicableToRelation = applicableToRelation; 143 } 144 145 146 147 141 } 148 142 }
Note:
See TracChangeset
for help on using the changeset viewer.