Changes in / [7505:7499] in josm


Ignore:
Location:
/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • /trunk/data/tagging-preset.xsd

    r7505 r7499  
    8686        </complexType>
    8787
    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">
    112104                <choice>
    113105                        <element name="label" type="tns:label" />
    … …  
    125117        </group>
    126118
    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 
    134119        <complexType name="key">
    135120                <attribute name="key" type="string" use="required" />
    … …  
    137122                <attribute name="match" type="string" />
    138123        </complexType>
     124
    139125
    140126        <complexType name="link">
    … …  
    193179                <!-- use either list_entry's or a combination of values/display_values -->
    194180                <sequence>
    195                         <group ref="tns:list_elements" minOccurs="0" maxOccurs="unbounded" />
     181                        <element name="list_entry" type="tns:list_entry" minOccurs="0" maxOccurs="unbounded" />
    196182                </sequence>
    197183                <attribute name="key" type="string" use="required" />
    … …  
    221207                <!-- use either list_entry's or a combination of values/display_values -->
    222208                <sequence>
    223                         <group ref="tns:list_elements" minOccurs="0" maxOccurs="unbounded" />
     209                        <element name="list_entry" type="tns:list_entry" minOccurs="0" maxOccurs="unbounded" />
    224210                </sequence>
    225211                <attribute name="key" type="string" use="required" />
    … …  
    230216                <attribute name="values_context" type="string" />
    231217                <attribute name="display_values" type="string" />
    232                 <attribute name="values_searchable" type="boolean" />
     218        <attribute name="values_searchable" type="boolean" />
    233219                <attribute name="default" type="string" />
    234220                <attribute name="use_last_as_default" type="tns:last_default" />
    … …  
    261247                <attribute name="value_on" type="string" />
    262248                <attribute name="value_off" type="string" />
    263                 <attribute name="disable_off" type="boolean" />
     249        <attribute name="disable_off" type="boolean" />
    264250                <attribute name="match" type="tns:match" />
    265251
  • /trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r7505 r7499  
    102102    private static final int MAX_EVENTS = 1000;
    103103
    104     private final Storage<OsmPrimitive> allPrimitives = new Storage<>(new Storage.PrimitiveIdHash(), true);
    105     private final Map<PrimitiveId, OsmPrimitive> primitivesMap = allPrimitives.foreignKey(new Storage.PrimitiveIdHash());
    106     private final CopyOnWriteArrayList<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<>();
    107107
    108108    // provide means to highlight map elements that are not osm primitives
    … …  
    257257     * conversion of the whole DataSet by iterating over this data structure.
    258258     */
    259     private final QuadBuckets<Node> nodes = new QuadBuckets<>();
     259    private QuadBuckets<Node> nodes = new QuadBuckets<>();
    260260
    261261    private <T extends OsmPrimitive> Collection<T> getPrimitives(Predicate<OsmPrimitive> predicate) {
    … …  
    287287
    288288    /**
    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 search
    293      * @return {@code true} if {@code n} ban be retrieved in this data set, {@code false} otherwise
    294      * @since 7501
    295      */
    296     public boolean containsNode(Node n) {
    297         return nodes.contains(n);
    298     }
    299 
    300     /**
    301289     * All ways (Streets etc.) in the DataSet.
    302290     *
    303291     * The way nodes are stored only in the way list.
    304292     */
    305     private final QuadBuckets<Way> ways = new QuadBuckets<>();
     293    private QuadBuckets<Way> ways = new QuadBuckets<>();
    306294
    307295    /**
    … …  
    329317
    330318    /**
    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 search
    335      * @return {@code true} if {@code w} ban be retrieved in this data set, {@code false} otherwise
    336      * @since 7501
    337      */
    338     public boolean containsWay(Way w) {
    339         return ways.contains(w);
    340     }
    341 
    342     /**
    343319     * All relations/relationships
    344320     */
    345     private final Collection<Relation> relations = new ArrayList<>();
     321    private Collection<Relation> relations = new ArrayList<>();
    346322
    347323    /**
    … …  
    373349            lock.readLock().unlock();
    374350        }
    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 search
    382      * @return {@code true} if {@code r} ban be retrieved in this data set, {@code false} otherwise
    383      * @since 7501
    384      */
    385     public boolean containsRelation(Relation r) {
    386         return relations.contains(r);
    387351    }
    388352
  • /trunk/src/org/openstreetmap/josm/data/osm/DatasetConsistencyTest.java

    r7505 r7499  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.osm;
    3 
    4 import static org.openstreetmap.josm.tools.I18n.tr;
    53
    64import java.io.PrintWriter;
    … …  
    86import java.io.Writer;
    97
    10 import org.openstreetmap.josm.Main;
    11 import org.openstreetmap.josm.tools.Utils;
     8import org.openstreetmap.josm.data.coor.LatLon;
    129
    1310/**
    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
    1512 * <br>
    16  * Texts here should not be translated because they're not intended for users but for josm developers.
    17  * @since 2500
     13 * Texts here should not be translated because they're not intended for users but for josm developers
     14 *
    1815 */
    1916public class DatasetConsistencyTest {
    … …  
    2421    private int errorCount;
    2522
    26     /**
    27      * Constructs a new {@code DatasetConsistencyTest}.
    28      * @param dataSet The dataset to test
    29      * @param writer The writer used to write results
    30      */
    3123    public DatasetConsistencyTest(DataSet dataSet, Writer writer) {
    3224        this.dataSet = dataSet;
    … …  
    4133    }
    4234
    43     /**
    44      * Checks that parent primitive is referred from its child members
    45      */
    4635    public void checkReferrers() {
    47         long startTime = System.currentTimeMillis();
    4836        // 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()) {
    5038            if (!way.isDeleted()) {
    51                 for (Node n : way.getNodes()) {
     39                for (Node n:way.getNodes()) {
    5240                    if (n.getDataSet() != null && !n.getReferrers().contains(way)) {
    5341                        printError("WAY NOT IN REFERRERS", "%s is part of %s but is not in referrers", n, way);
    … …  
    5745        }
    5846
    59         for (Relation relation : dataSet.getRelations()) {
     47        for (Relation relation:dataSet.getRelations()) {
    6048            if (!relation.isDeleted()) {
    61                 for (RelationMember m : relation.getMembers()) {
     49                for (RelationMember m:relation.getMembers()) {
    6250                    if (m.getMember().getDataSet() != null && !m.getMember().getReferrers().contains(relation)) {
    6351                        printError("RELATION NOT IN REFERRERS", "%s is part of %s but is not in referrers", m.getMember(), relation);
    … …  
    6654            }
    6755        }
    68         printElapsedTime(startTime);
    6956    }
    7057
    71     /**
    72      * Checks for womplete ways with incomplete nodes.
    73      */
    7458    public void checkCompleteWaysWithIncompleteNodes() {
    75         long startTime = System.currentTimeMillis();
    76         for (Way way : dataSet.getWays()) {
     59        for (Way way:dataSet.getWays()) {
    7760            if (way.isUsable()) {
    78                 for (Node node : way.getNodes()) {
     61                for (Node node:way.getNodes()) {
    7962                    if (node.isIncomplete()) {
    8063                        printError("USABLE HAS INCOMPLETE", "%s is usable but contains incomplete node '%s'", way, node);
    … …  
    8366            }
    8467        }
    85         printElapsedTime(startTime);
    8668    }
    8769
    88     /**
    89      * Checks for complete nodes without coordinates.
    90      */
    9170    public void checkCompleteNodesWithoutCoordinates() {
    92         long startTime = System.currentTimeMillis();
    93         for (Node node : dataSet.getNodes()) {
     71        for (Node node:dataSet.getNodes()) {
    9472            if (!node.isIncomplete() && node.isVisible() && (node.getCoor() == null || node.getEastNorth() == null)) {
    9573                printError("COMPLETE WITHOUT COORDINATES", "%s is not incomplete but has null coordinates", node);
    9674            }
    9775        }
    98         printElapsedTime(startTime);
    9976    }
    10077
    101     /**
    102      * Checks that nodes can be retrieved through their coordinates.
    103      */
    10478    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                    }
    11287                }
    11388            }
    114         } finally {
    115             dataSet.getReadLock().unlock();
    11689        }
    117         printElapsedTime(startTime);
    11890    }
    11991
    120     /**
    121      * Checks that ways can be retrieved through their bounding box.
    122      */
    12392    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);
    13196            }
    132         } finally {
    133             dataSet.getReadLock().unlock();
    13497        }
    135         printElapsedTime(startTime);
    13698    }
    13799
    … …  
    150112    }
    151113
    152     /**
    153      * Checks that referred primitives are present in dataset.
    154      */
    155114    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()) {
    159117                checkReferredPrimitive(node, way);
    160118            }
    161119        }
    162120
    163         for (Relation relation : dataSet.getRelations()) {
    164             for (RelationMember member : relation.getMembers()) {
     121        for (Relation relation:dataSet.getRelations()) {
     122            for (RelationMember member:relation.getMembers()) {
    165123                checkReferredPrimitive(member.getMember(), relation);
    166124            }
    167125        }
    168         printElapsedTime(startTime);
    169126    }
    170127
    171     /**
    172      * Checks for zero and one-node ways.
    173      */
     128
    174129    public void checkZeroNodesWays() {
    175         long startTime = System.currentTimeMillis();
    176         for (Way way : dataSet.getWays()) {
     130        for (Way way:dataSet.getWays()) {
    177131            if (way.isUsable() && way.getNodesCount() == 0) {
    178132                printError("WARN - ZERO NODES", "Way %s has zero nodes", way);
    … …  
    181135            }
    182136        }
    183         printElapsedTime(startTime);
    184137    }
    185138
    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      */
    199139    public void runTest() {
    200140        try {
    201             long startTime = System.currentTimeMillis();
    202141            referredPrimitiveNotInDataset();
    203142            checkReferrers();
    … …  
    207146            searchWays();
    208147            checkZeroNodesWays();
    209             printElapsedTime(startTime);
    210148            if (errorCount > MAX_ERRORS) {
    211149                writer.println((errorCount - MAX_ERRORS) + " more...");
    212150            }
    213 
    214151        } catch (Exception e) {
    215152            writer.println("Exception during dataset integrity test:");
    … …  
    218155    }
    219156
    220     /**
    221      * Runs test on the given dataset.
    222      * @param dataSet the dataset to test
    223      * @return the errors as string
    224      */
    225157    public static String runTests(DataSet dataSet) {
    226158        StringWriter writer = new StringWriter();
    … …  
    228160        return writer.toString();
    229161    }
     162
    230163}
  • /trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java

    r7505 r7499  
    592592        private JComponent value;
    593593
    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) {
    596595
    597596            // find out if our key is already used in the selection.
    … …  
    603602                initAutoCompletionField(textField, key);
    604603            }
    605             textField.setHint(key);
    606604            if (length != null && !length.isEmpty()) {
    607605                textField.setMaxChars(Integer.valueOf(length));
    … …  
    12211219            AutoCompletingTextField tf = new AutoCompletingTextField();
    12221220            initAutoCompletionField(tf, key);
    1223             tf.setHint(key);
    12241221            if (length != null && !length.isEmpty()) {
    12251222                tf.setMaxChars(Integer.valueOf(length));
  • /trunk/src/org/openstreetmap/josm/gui/widgets/JosmTextField.java

    r7505 r7499  
    11// License: GPL. For details, see LICENSE file.
    22package 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;
    123
    134import javax.swing.JTextField;
    … …  
    156
    167/**
    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).
    199 * @since 5886
    2010 */
    21 public class JosmTextField extends JTextField implements FocusListener {
    22 
    23     private String hint;
     11public class JosmTextField extends JTextField {
    2412
    2513    /**
    … …  
    4634            setMinimumSize(getPreferredSize());
    4735        }
    48         addFocusListener(this);
    4936    }
    5037
    … …  
    9784        this(null, null, 0);
    9885    }
    99 
    100     /**
    101      * Replies the hint displayed when no text has been entered.
    102      * @return the hint
    103      * @since 7505
    104      */
    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 set
    112      * @since 7505
    113      */
    114     public final void setHint(String hint) {
    115         this.hint = hint;
    116     }
    117 
    118     @Override
    119     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/2257172
    123             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     @Override
    137     public void focusGained(FocusEvent e) {
    138         repaint();
    139     }
    140 
    141     @Override
    142     public void focusLost(FocusEvent e) {
    143         repaint();
    144     }
    14586}
Note: See TracChangeset for help on using the changeset viewer.