Changes in / [7505:7499] in josm
- Location:
- /trunk
- Files:
-
- 5 edited
-
data/tagging-preset.xsd (modified) (7 diffs)
-
src/org/openstreetmap/josm/data/osm/DataSet.java (modified) (5 diffs)
-
src/org/openstreetmap/josm/data/osm/DatasetConsistencyTest.java (modified) (12 diffs)
-
src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java (modified) (3 diffs)
-
src/org/openstreetmap/josm/gui/widgets/JosmTextField.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
/trunk/data/tagging-preset.xsd
r7505 r7499 86 86 </complexType> 87 87 88 <complexType name="chunk"> 89 <choice minOccurs="1" maxOccurs="1"> 90 <sequence> 91 <choice minOccurs="1" maxOccurs="unbounded"> 92 <group ref="tns:optional_elements" /> 93 <element name="key" type="tns:key" /> 94 <element name="optional" type="tns:optional" minOccurs="0" /> 95 </choice> 96 </sequence> 97 <sequence> 98 <!-- Cannot use tns:list_elements here because reference is present both in optional_elements and list_elements 99 so it violates cos-nonambig: Unique Particle Attribution : 100 <group ref="tns:list_elements" minOccurs="1" maxOccurs="unbounded" />--> 101 <element name="list_entry" type="tns:list_entry" minOccurs="1" maxOccurs="unbounded" /> 102 </sequence> 103 </choice> 104 <attribute name="id" type="ID" use="required" /> 105 </complexType> 106 107 <complexType name="reference"> 108 <attribute name="ref" type="IDREF" use="required" /> 109 </complexType> 110 111 <group name="optional_elements"> 88 <complexType name="chunk"> 89 <sequence> 90 <choice minOccurs="1" maxOccurs="unbounded"> 91 <group ref="tns:optional_elements" /> 92 <element name="key" type="tns:key" /> 93 <element name="optional" type="tns:optional" minOccurs="0" /> 94 </choice> 95 </sequence> 96 <attribute name="id" type="ID" use="required" /> 97 </complexType> 98 99 <complexType name="reference"> 100 <attribute name="ref" type="IDREF" use="required" /> 101 </complexType> 102 103 <group name="optional_elements"> 112 104 <choice> 113 105 <element name="label" type="tns:label" /> … … 125 117 </group> 126 118 127 <group name="list_elements">128 <choice>129 <element name="list_entry" type="tns:list_entry" />130 <element name="reference" type="tns:reference" />131 </choice>132 </group>133 134 119 <complexType name="key"> 135 120 <attribute name="key" type="string" use="required" /> … … 137 122 <attribute name="match" type="string" /> 138 123 </complexType> 124 139 125 140 126 <complexType name="link"> … … 193 179 <!-- use either list_entry's or a combination of values/display_values --> 194 180 <sequence> 195 < group ref="tns:list_elements" minOccurs="0" maxOccurs="unbounded" />181 <element name="list_entry" type="tns:list_entry" minOccurs="0" maxOccurs="unbounded" /> 196 182 </sequence> 197 183 <attribute name="key" type="string" use="required" /> … … 221 207 <!-- use either list_entry's or a combination of values/display_values --> 222 208 <sequence> 223 < group ref="tns:list_elements" minOccurs="0" maxOccurs="unbounded" />209 <element name="list_entry" type="tns:list_entry" minOccurs="0" maxOccurs="unbounded" /> 224 210 </sequence> 225 211 <attribute name="key" type="string" use="required" /> … … 230 216 <attribute name="values_context" type="string" /> 231 217 <attribute name="display_values" type="string" /> 232 <attribute name="values_searchable" type="boolean" />218 <attribute name="values_searchable" type="boolean" /> 233 219 <attribute name="default" type="string" /> 234 220 <attribute name="use_last_as_default" type="tns:last_default" /> … … 261 247 <attribute name="value_on" type="string" /> 262 248 <attribute name="value_off" type="string" /> 263 <attribute name="disable_off" type="boolean" />249 <attribute name="disable_off" type="boolean" /> 264 250 <attribute name="match" type="tns:match" /> 265 251 -
/trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r7505 r7499 102 102 private static final int MAX_EVENTS = 1000; 103 103 104 private finalStorage<OsmPrimitive> allPrimitives = new Storage<>(new Storage.PrimitiveIdHash(), true);105 private finalMap<PrimitiveId, OsmPrimitive> primitivesMap = allPrimitives.foreignKey(new Storage.PrimitiveIdHash());106 private finalCopyOnWriteArrayList<DataSetListener> listeners = new CopyOnWriteArrayList<>();104 private Storage<OsmPrimitive> allPrimitives = new Storage<>(new Storage.PrimitiveIdHash(), true); 105 private Map<PrimitiveId, OsmPrimitive> primitivesMap = allPrimitives.foreignKey(new Storage.PrimitiveIdHash()); 106 private CopyOnWriteArrayList<DataSetListener> listeners = new CopyOnWriteArrayList<>(); 107 107 108 108 // provide means to highlight map elements that are not osm primitives … … 257 257 * conversion of the whole DataSet by iterating over this data structure. 258 258 */ 259 private finalQuadBuckets<Node> nodes = new QuadBuckets<>();259 private QuadBuckets<Node> nodes = new QuadBuckets<>(); 260 260 261 261 private <T extends OsmPrimitive> Collection<T> getPrimitives(Predicate<OsmPrimitive> predicate) { … … 287 287 288 288 /** 289 * Determines if the given node can be retrieved in the data set through its bounding box. Useful for dataset consistency test.290 * For efficiency reasons this method does not lock the dataset, you have to lock it manually.291 *292 * @param n The node to search293 * @return {@code true} if {@code n} ban be retrieved in this data set, {@code false} otherwise294 * @since 7501295 */296 public boolean containsNode(Node n) {297 return nodes.contains(n);298 }299 300 /**301 289 * All ways (Streets etc.) in the DataSet. 302 290 * 303 291 * The way nodes are stored only in the way list. 304 292 */ 305 private finalQuadBuckets<Way> ways = new QuadBuckets<>();293 private QuadBuckets<Way> ways = new QuadBuckets<>(); 306 294 307 295 /** … … 329 317 330 318 /** 331 * Determines if the given way can be retrieved in the data set through its bounding box. Useful for dataset consistency test.332 * For efficiency reasons this method does not lock the dataset, you have to lock it manually.333 *334 * @param w The way to search335 * @return {@code true} if {@code w} ban be retrieved in this data set, {@code false} otherwise336 * @since 7501337 */338 public boolean containsWay(Way w) {339 return ways.contains(w);340 }341 342 /**343 319 * All relations/relationships 344 320 */ 345 private finalCollection<Relation> relations = new ArrayList<>();321 private Collection<Relation> relations = new ArrayList<>(); 346 322 347 323 /** … … 373 349 lock.readLock().unlock(); 374 350 } 375 }376 377 /**378 * Determines if the given relation can be retrieved in the data set through its bounding box. Useful for dataset consistency test.379 * For efficiency reasons this method does not lock the dataset, you have to lock it manually.380 *381 * @param r The relation to search382 * @return {@code true} if {@code r} ban be retrieved in this data set, {@code false} otherwise383 * @since 7501384 */385 public boolean containsRelation(Relation r) {386 return relations.contains(r);387 351 } 388 352 -
/trunk/src/org/openstreetmap/josm/data/osm/DatasetConsistencyTest.java
r7505 r7499 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.data.osm; 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 3 6 4 import java.io.PrintWriter; … … 8 6 import java.io.Writer; 9 7 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.tools.Utils; 8 import org.openstreetmap.josm.data.coor.LatLon; 12 9 13 10 /** 14 * This class can be used to run consistency tests on dataset. Any errors found will be written to provided PrintWriter .11 * This class can be used to run consistency tests on dataset. Any errors found will be written to provided PrintWriter 15 12 * <br> 16 * Texts here should not be translated because they're not intended for users but for josm developers .17 * @since 250013 * Texts here should not be translated because they're not intended for users but for josm developers 14 * 18 15 */ 19 16 public class DatasetConsistencyTest { … … 24 21 private int errorCount; 25 22 26 /**27 * Constructs a new {@code DatasetConsistencyTest}.28 * @param dataSet The dataset to test29 * @param writer The writer used to write results30 */31 23 public DatasetConsistencyTest(DataSet dataSet, Writer writer) { 32 24 this.dataSet = dataSet; … … 41 33 } 42 34 43 /**44 * Checks that parent primitive is referred from its child members45 */46 35 public void checkReferrers() { 47 long startTime = System.currentTimeMillis();48 36 // It's also error when referred primitive's dataset is null but it's already covered by referredPrimitiveNotInDataset check 49 for (Way way :dataSet.getWays()) {37 for (Way way:dataSet.getWays()) { 50 38 if (!way.isDeleted()) { 51 for (Node n :way.getNodes()) {39 for (Node n:way.getNodes()) { 52 40 if (n.getDataSet() != null && !n.getReferrers().contains(way)) { 53 41 printError("WAY NOT IN REFERRERS", "%s is part of %s but is not in referrers", n, way); … … 57 45 } 58 46 59 for (Relation relation :dataSet.getRelations()) {47 for (Relation relation:dataSet.getRelations()) { 60 48 if (!relation.isDeleted()) { 61 for (RelationMember m :relation.getMembers()) {49 for (RelationMember m:relation.getMembers()) { 62 50 if (m.getMember().getDataSet() != null && !m.getMember().getReferrers().contains(relation)) { 63 51 printError("RELATION NOT IN REFERRERS", "%s is part of %s but is not in referrers", m.getMember(), relation); … … 66 54 } 67 55 } 68 printElapsedTime(startTime);69 56 } 70 57 71 /**72 * Checks for womplete ways with incomplete nodes.73 */74 58 public void checkCompleteWaysWithIncompleteNodes() { 75 long startTime = System.currentTimeMillis(); 76 for (Way way : dataSet.getWays()) { 59 for (Way way:dataSet.getWays()) { 77 60 if (way.isUsable()) { 78 for (Node node :way.getNodes()) {61 for (Node node:way.getNodes()) { 79 62 if (node.isIncomplete()) { 80 63 printError("USABLE HAS INCOMPLETE", "%s is usable but contains incomplete node '%s'", way, node); … … 83 66 } 84 67 } 85 printElapsedTime(startTime);86 68 } 87 69 88 /**89 * Checks for complete nodes without coordinates.90 */91 70 public void checkCompleteNodesWithoutCoordinates() { 92 long startTime = System.currentTimeMillis(); 93 for (Node node : dataSet.getNodes()) { 71 for (Node node:dataSet.getNodes()) { 94 72 if (!node.isIncomplete() && node.isVisible() && (node.getCoor() == null || node.getEastNorth() == null)) { 95 73 printError("COMPLETE WITHOUT COORDINATES", "%s is not incomplete but has null coordinates", node); 96 74 } 97 75 } 98 printElapsedTime(startTime);99 76 } 100 77 101 /**102 * Checks that nodes can be retrieved through their coordinates.103 */104 78 public void searchNodes() { 105 long startTime = System.currentTimeMillis(); 106 dataSet.getReadLock().lock(); 107 try { 108 for (Node n : dataSet.getNodes()) { 109 // Call isDrawable() as an efficient replacement to previous checks (!deleted, !incomplete, getCoor() != null) 110 if (n.isDrawable() && !dataSet.containsNode(n)) { 111 printError("SEARCH NODES", "%s not found using Dataset.containsNode()", n); 79 for (Node n:dataSet.getNodes()) { 80 if (!n.isIncomplete() && !n.isDeleted()) { 81 LatLon c = n.getCoor(); 82 if (c != null) { 83 BBox box = c.toBBox(0.0001); 84 if (!dataSet.searchNodes(box).contains(n)) { 85 printError("SEARCH NODES", "%s not found using Dataset.searchNodes()", n); 86 } 112 87 } 113 88 } 114 } finally {115 dataSet.getReadLock().unlock();116 89 } 117 printElapsedTime(startTime);118 90 } 119 91 120 /**121 * Checks that ways can be retrieved through their bounding box.122 */123 92 public void searchWays() { 124 long startTime = System.currentTimeMillis(); 125 dataSet.getReadLock().lock(); 126 try { 127 for (Way w : dataSet.getWays()) { 128 if (!w.isIncomplete() && !w.isDeleted() && w.getNodesCount() >= 2 && !dataSet.containsWay(w)) { 129 printError("SEARCH WAYS", "%s not found using Dataset.containsWay()", w); 130 } 93 for (Way w:dataSet.getWays()) { 94 if (!w.isIncomplete() && !w.isDeleted() && w.getNodesCount() >= 2 && !dataSet.searchWays(w.getBBox()).contains(w)) { 95 printError("SEARCH WAYS", "%s not found using Dataset.searchWays()", w); 131 96 } 132 } finally {133 dataSet.getReadLock().unlock();134 97 } 135 printElapsedTime(startTime);136 98 } 137 99 … … 150 112 } 151 113 152 /**153 * Checks that referred primitives are present in dataset.154 */155 114 public void referredPrimitiveNotInDataset() { 156 long startTime = System.currentTimeMillis(); 157 for (Way way : dataSet.getWays()) { 158 for (Node node : way.getNodes()) { 115 for (Way way:dataSet.getWays()) { 116 for (Node node:way.getNodes()) { 159 117 checkReferredPrimitive(node, way); 160 118 } 161 119 } 162 120 163 for (Relation relation :dataSet.getRelations()) {164 for (RelationMember member :relation.getMembers()) {121 for (Relation relation:dataSet.getRelations()) { 122 for (RelationMember member:relation.getMembers()) { 165 123 checkReferredPrimitive(member.getMember(), relation); 166 124 } 167 125 } 168 printElapsedTime(startTime);169 126 } 170 127 171 /** 172 * Checks for zero and one-node ways. 173 */ 128 174 129 public void checkZeroNodesWays() { 175 long startTime = System.currentTimeMillis(); 176 for (Way way : dataSet.getWays()) { 130 for (Way way:dataSet.getWays()) { 177 131 if (way.isUsable() && way.getNodesCount() == 0) { 178 132 printError("WARN - ZERO NODES", "Way %s has zero nodes", way); … … 181 135 } 182 136 } 183 printElapsedTime(startTime);184 137 } 185 138 186 private void printElapsedTime(long startTime) {187 if (Main.isDebugEnabled()) {188 StackTraceElement item = Thread.currentThread().getStackTrace()[2];189 String operation = getClass().getSimpleName() + "." + item.getMethodName();190 long elapsedTime = System.currentTimeMillis() - startTime;191 Main.debug(tr("Test ''{0}'' completed in {1}",192 operation, Utils.getDurationString(elapsedTime)));193 }194 }195 196 /**197 * Runs test.198 */199 139 public void runTest() { 200 140 try { 201 long startTime = System.currentTimeMillis();202 141 referredPrimitiveNotInDataset(); 203 142 checkReferrers(); … … 207 146 searchWays(); 208 147 checkZeroNodesWays(); 209 printElapsedTime(startTime);210 148 if (errorCount > MAX_ERRORS) { 211 149 writer.println((errorCount - MAX_ERRORS) + " more..."); 212 150 } 213 214 151 } catch (Exception e) { 215 152 writer.println("Exception during dataset integrity test:"); … … 218 155 } 219 156 220 /**221 * Runs test on the given dataset.222 * @param dataSet the dataset to test223 * @return the errors as string224 */225 157 public static String runTests(DataSet dataSet) { 226 158 StringWriter writer = new StringWriter(); … … 228 160 return writer.toString(); 229 161 } 162 230 163 } -
/trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java
r7505 r7499 592 592 private JComponent value; 593 593 594 @Override 595 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) { 594 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) { 596 595 597 596 // find out if our key is already used in the selection. … … 603 602 initAutoCompletionField(textField, key); 604 603 } 605 textField.setHint(key);606 604 if (length != null && !length.isEmpty()) { 607 605 textField.setMaxChars(Integer.valueOf(length)); … … 1221 1219 AutoCompletingTextField tf = new AutoCompletingTextField(); 1222 1220 initAutoCompletionField(tf, key); 1223 tf.setHint(key);1224 1221 if (length != null && !length.isEmpty()) { 1225 1222 tf.setMaxChars(Integer.valueOf(length)); -
/trunk/src/org/openstreetmap/josm/gui/widgets/JosmTextField.java
r7505 r7499 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.widgets; 3 4 import java.awt.Color;5 import java.awt.FontMetrics;6 import java.awt.Graphics;7 import java.awt.Graphics2D;8 import java.awt.Insets;9 import java.awt.RenderingHints;10 import java.awt.event.FocusEvent;11 import java.awt.event.FocusListener;12 3 13 4 import javax.swing.JTextField; … … 15 6 16 7 /** 17 * Subclass of {@link JTextField} that adds a "native" context menu (cut/copy/paste/select all) 18 * and an optional "hint" displayed when no text has been entered. 8 * Subclass of {@link JTextField} that adds a "native" context menu (cut/copy/paste/select all). 19 9 * @since 5886 20 10 */ 21 public class JosmTextField extends JTextField implements FocusListener { 22 23 private String hint; 11 public class JosmTextField extends JTextField { 24 12 25 13 /** … … 46 34 setMinimumSize(getPreferredSize()); 47 35 } 48 addFocusListener(this);49 36 } 50 37 … … 97 84 this(null, null, 0); 98 85 } 99 100 /**101 * Replies the hint displayed when no text has been entered.102 * @return the hint103 * @since 7505104 */105 public final String getHint() {106 return hint;107 }108 109 /**110 * Sets the hint to display when no text has been entered.111 * @param hint the hint to set112 * @since 7505113 */114 public final void setHint(String hint) {115 this.hint = hint;116 }117 118 @Override119 public void paint(Graphics g) {120 super.paint(g);121 if (hint != null && !hint.isEmpty() && getText().isEmpty() && !isFocusOwner()) {122 // Taken from http://stackoverflow.com/a/24571681/2257172123 int h = getHeight();124 ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);125 Insets ins = getInsets();126 FontMetrics fm = g.getFontMetrics();127 int c0 = getBackground().getRGB();128 int c1 = getForeground().getRGB();129 int m = 0xfefefefe;130 int c2 = ((c0 & m) >>> 1) + ((c1 & m) >>> 1);131 g.setColor(new Color(c2, true));132 g.drawString(hint, ins.left, h / 2 + fm.getAscent() / 2 - 2);133 }134 }135 136 @Override137 public void focusGained(FocusEvent e) {138 repaint();139 }140 141 @Override142 public void focusLost(FocusEvent e) {143 repaint();144 }145 86 }
Note:
See TracChangeset
for help on using the changeset viewer.
