Ignore:
Timestamp:
2009-09-13T22:23:19+02:00 (15 years ago)
Author:
stoecker
Message:

see #3475 - patch by Petr Dlouhý - code rework for display filtering

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r2115 r2120  
    184184    }
    185185
     186    public void setFiltered(Collection<? extends OsmPrimitive> selection) {
     187        clearFiltered(nodes);
     188        clearFiltered(ways);
     189        clearFiltered(relations);
     190        for (OsmPrimitive osm : selection) {
     191            osm.setFiltered(true);
     192        }
     193    }
     194
     195    public void setFiltered(OsmPrimitive... osm) {
     196        if (osm.length == 1 && osm[0] == null) {
     197            setFiltered();
     198            return;
     199        }
     200        clearFiltered(nodes);
     201        clearFiltered(ways);
     202        clearFiltered(relations);
     203        for (OsmPrimitive o : osm)
     204            if (o != null) {
     205                o.setFiltered(true);
     206            }
     207    }
     208
     209    public void setDisabled(Collection<? extends OsmPrimitive> selection) {
     210        clearDisabled(nodes);
     211        clearDisabled(ways);
     212        clearDisabled(relations);
     213        for (OsmPrimitive osm : selection) {
     214            osm.setDisabled(true);
     215        }
     216    }
     217
     218    public void setDisabled(OsmPrimitive... osm) {
     219        if (osm.length == 1 && osm[0] == null) {
     220            setDisabled();
     221            return;
     222        }
     223        clearDisabled(nodes);
     224        clearDisabled(ways);
     225        clearDisabled(relations);
     226        for (OsmPrimitive o : osm)
     227            if (o != null) {
     228                o.setDisabled(true);
     229            }
     230    }
     231
    186232    public void setSelected(Collection<? extends OsmPrimitive> selection) {
    187233        clearSelection(nodes);
     
    207253            }
    208254        fireSelectionChanged(Arrays.asList(osm));
     255    }
     256
     257    /**
     258     * Remove the filtered parameter from every value in the collection.
     259     * @param list The collection to remove the filtered parameter from.
     260     */
     261    private void clearFiltered(Collection<? extends OsmPrimitive> list) {
     262        if (list == null)
     263            return;
     264        for (OsmPrimitive osm : list) {
     265            osm.setFiltered(false);
     266        }
     267    }
     268    /**
     269     * Remove the disabled parameter from every value in the collection.
     270     * @param list The collection to remove the disabled parameter from.
     271     */
     272    private void clearDisabled(Collection<? extends OsmPrimitive> list) {
     273        if (list == null)
     274            return;
     275        for (OsmPrimitive osm : list) {
     276            osm.setDisabled(false);
     277        }
    209278    }
    210279
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r2115 r2120  
    9696     * new to the server! To create a new object, call the default constructor of
    9797     * the respective class.
    98      * 
     98     *
    9999     */
    100100    private long id = 0;
     
    105105     * Deleted objects are deleted from the server. If the objects are added (id=0),
    106106     * the modified is ignored and the object is added to the server.
    107      * 
     107     *
    108108     */
    109109    private boolean modified = false;
     
    111111    /**
    112112     * <code>true</code>, if the object has been deleted.
    113      * 
     113     *
    114114     */
    115115    private boolean deleted = false;
     
    119119     * introduced with the 0.4 API to be able to communicate deleted objects
    120120     * (they will have visible=false).
    121      * 
     121     *
    122122     */
    123123    private boolean visible = true;
     124
     125    /**
     126     * <code>true</code>, if the object has been set inactive
     127     *
     128     */
     129    private boolean disabled = false;
     130
     131    /**
     132     * <code>true</code>, if the object has been filtered out
     133     *
     134     */
     135    private boolean filtered = false;
    124136
    125137    /**
     
    131143    /**
    132144     * If set to true, this object is currently selected.
    133      * 
     145     *
    134146     */
    135147    private volatile boolean selected = false;
     
    149161    /**
    150162     * Creates a new primitive with id 0.
    151      * 
     163     *
    152164     */
    153165    public OsmPrimitive() {
     
    158170     * Creates a new primitive for the given id. If the id > 0, the primitive is marked
    159171     * as incomplete.
    160      * 
     172     *
    161173     * @param id the id. > 0 required
    162174     * @throws IllegalArgumentException thrown if id < 0
     
    173185    /* accessors                                                                            */
    174186    /* ------------------------------------------------------------------------------------ */
     187    /**
     188     * Sets whether this primitive is disabled or not.
     189     *
     190     * @param selected  true, if this primitive is disabled; false, otherwise
     191     */
     192    public void setDisabled(boolean disabled) {
     193        this.disabled = disabled;
     194    }
     195
     196    /**
     197     * Replies true, if this primitive is disabled.
     198     *
     199     * @return true, if this primitive is disabled
     200     */
     201    public boolean isDisabled() {
     202        return disabled;
     203    }
     204    /**
     205     * Sets whether this primitive is filtered out or not.
     206     *
     207     * @param selected  true, if this primitive is filtered out; false, otherwise
     208     */
     209    public void setFiltered(boolean filtered) {
     210        this.filtered = filtered;
     211    }
     212    /**
     213     * Replies true, if this primitive is filtered out.
     214     *
     215     * @return true, if this primitive is filtered out
     216     */
     217    public boolean isFiltered() {
     218        return filtered;
     219    }
    175220
    176221    /**
    177222     * Sets whether this primitive is selected or not.
    178      * 
     223     *
    179224     * @param selected  true, if this primitive is selected; false, otherwise
    180225     * @since 1899
     
    185230    /**
    186231     * Replies true, if this primitive is selected.
    187      * 
     232     *
    188233     * @return true, if this primitive is selected
    189234     * @since 1899
     
    195240    /**
    196241     * Marks this primitive as being modified.
    197      * 
     242     *
    198243     * @param modified true, if this primitive is to be modified
    199244     */
     
    205250     * Replies <code>true</code> if the object has been modified since it was loaded from
    206251     * the server. In this case, on next upload, this object will be updated.
    207      * 
     252     *
    208253     * @return <code>true</code> if the object has been modified since it was loaded from
    209254     * the server
     
    230275     */
    231276    public boolean isUsable() {
    232         return !deleted && !incomplete;
     277        return !deleted && !incomplete && !disabled;
    233278    }
    234279
     
    238283     * Replies false, if this primitive is known on the server and has been deleted
    239284     * on the server.
    240      * 
     285     *
    241286     * @see #setVisible(boolean)
    242287     */
     
    248293     * Sets whether this primitive is visible, i.e. whether it is known on the server
    249294     * and not deleted on the server.
    250      * 
     295     *
    251296     * @see #isVisible()
    252297     * @throws IllegalStateException thrown if visible is set to false on an primitive with
     
    262307     * Replies the version number as returned by the API. The version is 0 if the id is 0 or
    263308     * if this primitive is incomplete.
    264      * 
     309     *
    265310     * @see #setVersion(int)
    266311     */
     
    271316    /**
    272317     * Replies the id of this primitive.
    273      * 
     318     *
    274319     * @return the id of this primitive.
    275320     */
     
    280325    /**
    281326     * Sets the id and the version of this primitive if it is known to the OSM API.
    282      * 
     327     *
    283328     * Since we know the id and its version it can't be incomplete anymore. incomplete
    284329     * is set to false.
    285      * 
     330     *
    286331     * @param id the id. > 0 required
    287332     * @param version the version > 0 required
     
    302347     * Clears the id and version known to the OSM API. The id and the version is set to 0.
    303348     * incomplete is set to false.
    304      * 
     349     *
    305350     * <strong>Caution</strong>: Do not use this method on primitives which are already added to a {@see DataSet}.
    306351     * Ways and relations might already refer to the primitive and clearing the OSM ID
    307352     * result in corrupt data.
    308      * 
     353     *
    309354     * Here's an example use case:
    310355     * <pre>
    311356     *     // create a clone of an already existing node
    312357     *     Node copy = new Node(otherExistingNode);
    313      * 
     358     *
    314359     *     // reset the clones OSM id
    315360     *     copy.clearOsmId();
    316361     * </pre>
    317      * 
     362     *
    318363     */
    319364    public void clearOsmId() {
     
    388433    /**
    389434     * Sets whether this primitive is deleted or not.
    390      * 
     435     *
    391436     * Also marks this primitive as modified if deleted is true and sets selected to false.
    392      * 
     437     *
    393438     * @param deleted  true, if this primitive is deleted; false, otherwise
    394439     */
     
    442487    /**
    443488     * Replies the map of key/value pairs. Never replies null. The map can be empty, though.
    444      * 
     489     *
    445490     * @return Keys of this primitive. Changes made in returned map are not mapped
    446491     * back to the primitive, use setKeys() to modify the keys
     
    459504     * Sets the keys of this primitives to the key/value pairs in <code>keys</code>.
    460505     * If <code>keys</code> is null removes all existing key/value pairs.
    461      * 
     506     *
    462507     * @param keys the key/value pairs to set. If null, removes all existing key/value pairs.
    463508     * @since 1924
     
    474519     * Set the given value to the given key. If key is null, does nothing. If value is null,
    475520     * removes the key and behaves like {@see #remove(String)}.
    476      * 
     521     *
    477522     * @param key  The key, for which the value is to be set. Can be null, does nothing in this case.
    478523     * @param value The value for the key. If null, removes the respective key/value pair.
    479      * 
     524     *
    480525     * @see #remove(String)
    481526     */
     
    495540    /**
    496541     * Remove the given key from the list
    497      * 
     542     *
    498543     * @param key  the key to be removed. Ignored, if key is null.
    499544     */
     
    510555    /**
    511556     * Removes all keys from this primitive.
    512      * 
     557     *
    513558     * @since 1843
    514559     */
     
    521566     * Replies the value for key <code>key</code>. Replies null, if <code>key</code> is null.
    522567     * Replies null, if there is no value for the given key.
    523      * 
     568     *
    524569     * @param key the key. Can be null, replies null in this case.
    525570     * @return the value for key <code>key</code>.
     
    544589    /**
    545590     * Replies true, if the map of key/value pairs of this primitive is not empty.
    546      * 
     591     *
    547592     * @return true, if the map of key/value pairs of this primitive is not empty; false
    548593     *   otherwise
    549      * 
     594     *
    550595     * @since 1843
    551596     */
     
    656701     * Replies the name of this primitive. The default implementation replies the value
    657702     * of the tag <tt>name</tt> or null, if this tag is not present.
    658      * 
     703     *
    659704     * @return the name of this primitive
    660705     */
     
    673718     *   <li>name of the current locale</li>
    674719     * </ul>
    675      * 
     720     *
    676721     * null, if no such tag exists
    677      * 
     722     *
    678723     * @return the name of this primitive
    679724     */
     
    693738    /**
    694739     * Replies the display name of a primitive formatted by <code>formatter</code>
    695      * 
     740     *
    696741     * @return the display name
    697742     */
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java

    r2087 r2120  
    159159        } else if (n.isTagged()) {
    160160            drawNode(n, nodeColor, taggedNodeSize, taggedNodeRadius, fillUnselectedNode);
     161        } else if (n.isDisabled()) {
     162            drawNode(n, inactiveColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode);
    161163        } else {
    162164            drawNode(n, nodeColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode);
     
    307309        } else if(w.isSelected()) {
    308310            color = selectedColor;
     311        } else if(w.isDisabled()) {
     312            color = inactiveColor;
    309313        }
    310314
     
    530534            for (RelationMember m : r.getMembers())
    531535            {
    532                 if (m.isNode() && !m.getMember().incomplete && !m.getMember().isDeleted())
     536                if (m.isNode() && !m.getMember().incomplete && !m.getMember().isDeleted() && !m.getMember().isFiltered())
    533537                {
    534538                    drawSelectedMember(m.getMember(), styles != null ? getPrimitiveStyle(m.getMember()) : null, true, true);
     
    13951399            for (final Relation osm : data.relations)
    13961400            {
    1397                 if(!osm.isDeleted() && !osm.incomplete && osm.mappaintVisibleCode != viewid)
     1401                if(!osm.isDeleted() && !osm.isFiltered() && !osm.incomplete && osm.mappaintVisibleCode != viewid)
    13981402                {
    13991403                    osm.visit(this);
     
    14121416            for (final Way osm : data.ways)
    14131417            {
    1414                 if (!osm.incomplete && !osm.isDeleted()
     1418                if (!osm.incomplete && !osm.isDeleted() && !osm.isFiltered()
    14151419                        && osm.mappaintVisibleCode != viewid && osm.mappaintDrawnCode != paintid)
    14161420                {
     
    14531457            //    profilerN = 0;
    14541458            for (final OsmPrimitive osm : data.ways)
    1455                 if (!osm.incomplete && !osm.isDeleted() && !osm.isSelected()
     1459                if (!osm.incomplete && !osm.isDeleted() && !osm.isFiltered() && !osm.isSelected()
    14561460                        && osm.mappaintVisibleCode != viewid )
    14571461                {
     
    14921496        //profilerN = 0;
    14931497        for (final OsmPrimitive osm : data.nodes)
    1494             if (!osm.incomplete && !osm.isDeleted()
     1498            if (!osm.incomplete && !osm.isDeleted() && (osm.isSelected() || !osm.isFiltered())
    14951499                    && osm.mappaintVisibleCode != viewid && osm.mappaintDrawnCode != paintid)
    14961500            {
     
    15121516            currentColor = nodeColor;
    15131517            for (final OsmPrimitive osm : data.ways)
    1514                 if (!osm.incomplete && !osm.isDeleted()
     1518                if (osm.isUsable() && !osm.isFiltered()
    15151519                        && osm.mappaintVisibleCode != viewid )
    15161520                {
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r2025 r2120  
    149149        //profilerN = 0;
    150150        for (final OsmPrimitive osm : data.relations)
    151             if (!osm.isDeleted() && !osm.isSelected())
     151            if (!osm.isDeleted() && !osm.isSelected() && !osm.isFiltered())
    152152            {
    153153                osm.visit(this);
     
    163163        //profilerN = 0;
    164164        for (final OsmPrimitive osm : data.ways)
    165             if (!osm.isDeleted() && !osm.isSelected() && osm.isTagged())
     165            if (!osm.isDeleted() && !osm.isSelected() && !osm.isFiltered() && osm.isTagged())
    166166            {
    167167                osm.visit(this);
     
    171171
    172172        for (final OsmPrimitive osm : data.ways)
    173             if (!osm.isDeleted() && !osm.isSelected() && !osm.isTagged())
     173            if (!osm.isDeleted() && !osm.isSelected() && !osm.isFiltered() && !osm.isTagged())
    174174            {
    175175                osm.visit(this);
     
    202202        //profilerN = 0;
    203203        for (final OsmPrimitive osm : data.nodes)
    204             if (!osm.isDeleted() && !osm.isSelected())
     204            if (!osm.isDeleted() && !osm.isSelected() && !osm.isFiltered())
    205205            {
    206206                osm.visit(this);
     
    220220            currentColor = nodeColor;
    221221            for (final OsmPrimitive osm : data.ways)
    222                 if (!osm.isDeleted())
     222                if (!osm.isDeleted() && !osm.isDisabled() && !osm.isFiltered())
    223223                {
    224224                    visitVirtual((Way)osm);
     
    249249        if (n.incomplete) return;
    250250
    251         if (inactive) {
     251        if (inactive || n.isDisabled()) {
    252252            drawNode(n, inactiveColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode);
    253253        } else if (n.highlighted) {
     
    312312        Color wayColor;
    313313
    314         if (inactive) {
     314        if (inactive || w.isDisabled()) {
    315315            wayColor = inactiveColor;
    316316        } else if(w.highlighted) {
     
    345345
    346346        Color col;
    347         if (inactive) {
     347        if (inactive || r.isDisabled()) {
    348348            col = inactiveColor;
    349349        } else if (r.isSelected()) {
Note: See TracChangeset for help on using the changeset viewer.