Changeset 18814 in josm


Ignore:
Timestamp:
2023-08-17T17:42:58+02:00 (10 months ago)
Author:
taylor.smock
Message:

Fix #23105: Add action to select shared/common child objects (patch by Woazboat, modified)

Modifications are as follows:

  • Basic test added
  • Icon added (copied and modified from selectall.svg)
  • default methods for IPrimitive.getChildren were moved to the appropriate locations
  • Lint cleanups in modified files

Additional notes:

  • The behavior when only one way is selected is very similar to SelectWayNodesAction from utilsplugin2
Location:
trunk
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/InvertSelectionAction.java

    r17062 r18814  
    2323                Shortcut.registerShortcut("selection:invertselection",
    2424                tr("Selection: {0}", tr("Invert Selection")), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), true);
    25                 setHelpId(ht("/Action/InvertSelection"));
     25        setHelpId(ht("/Action/InvertSelection"));
    2626    }
    2727
  • trunk/src/org/openstreetmap/josm/data/osm/IPrimitive.java

    r18801 r18814  
    33
    44import java.time.Instant;
     5import java.util.Collections;
    56import java.util.Date;
    67import java.util.List;
     
    2021     * Replies <code>true</code> if the object has been modified since it was loaded from
    2122     * the server. In this case, on next upload, this object will be updated.
    22      *
     23     * <p>
    2324     * Deleted objects are deleted from the server. If the objects are added (id=0),
    2425     * the modified is ignored and the object is added to the server.
     
    6869    /**
    6970     * Sets whether this primitive is deleted or not.
    70      *
     71     * <p>
    7172     * Also marks this primitive as modified if deleted is true.
    7273     *
     
    244245    /**
    245246     * Sets the id and the version of this primitive if it is known to the OSM API.
    246      *
     247     * <p>
    247248     * Since we know the id and its version it can't be incomplete anymore. incomplete
    248249     * is set to false.
     
    277278     * @return date of last modification
    278279     * @see #setTimestamp
    279      * @deprecated Use {@link #getInstant}
     280     * @deprecated since 17749, use {@link #getInstant} instead
    280281     */
    281282    @Deprecated
     
    306307     * @param timestamp date of last modification
    307308     * @see #getTimestamp
    308      * @deprecated Use {@link #setInstant}
     309     * @deprecated since 17749, use {@link #setInstant} instead
    309310     */
    310311    @Deprecated
     
    546547        }
    547548    }
     549
     550    /**
     551     * Get child primitives that are referred by this primitive.
     552     * {@link Relation}: Members of the relation
     553     * {@link Way}: Nodes used by the way
     554     * {@link Node}: None
     555     * @return List of child primitives
     556     * @since 18814
     557     */
     558    default List<? extends IPrimitive> getChildren() {
     559        return Collections.emptyList();
     560    }
    548561}
  • trunk/src/org/openstreetmap/josm/data/osm/IRelation.java

    r18413 r18814  
    116116    }
    117117
     118    @Override
     119    default List<? extends IPrimitive> getChildren() {
     120        return getMemberPrimitivesList();
     121    }
     122
    118123    /**
    119124     * Replies a collection with the incomplete children this relation refers to.
  • trunk/src/org/openstreetmap/josm/data/osm/IWay.java

    r18019 r18814  
    6161     */
    6262    List<N> getNodes();
     63
     64    @Override
     65    default List<N> getChildren() {
     66        return this.getNodes();
     67    }
    6368
    6469    /**
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r18801 r18814  
    148148        boolean locked = writeLock();
    149149        try {
    150             List<RelationMember> members = getMembers();
    151             RelationMember result = members.remove(index);
    152             setMembers(members);
     150            List<RelationMember> currentMembers = getMembers();
     151            RelationMember result = currentMembers.remove(index);
     152            setMembers(currentMembers);
    153153            return result;
    154154        } finally {
     
    390390        boolean locked = writeLock();
    391391        try {
    392             List<RelationMember> members = getMembers();
    393             members.removeAll(getMembersFor(primitives));
    394             setMembers(members);
     392            List<RelationMember> currentMembers = getMembers();
     393            currentMembers.removeAll(getMembersFor(primitives));
     394            setMembers(currentMembers);
    395395        } finally {
    396396            writeUnlock(locked);
     
    428428
    429429    @Override
     430    public List<OsmPrimitive> getChildren() {
     431        return getMemberPrimitivesList();
     432    }
     433
     434    @Override
    430435    public OsmPrimitiveType getType() {
    431436        return OsmPrimitiveType.RELATION;
     
    444449
    445450        BBox box = new BBox();
    446         addToBBox(box, new HashSet<PrimitiveId>());
     451        addToBBox(box, new HashSet<>());
    447452        if (getDataSet() == null) {
    448453            return box;
     
    494499                for (RelationMember rm: members) {
    495500                    if (rm.getMember().isDeleted())
    496                         throw new DataIntegrityProblemException("Deleted member referenced: " + toString(), null, this, rm.getMember());
     501                        throw new DataIntegrityProblemException("Deleted member referenced: " + this, null, this, rm.getMember());
    497502                }
    498503            }
     
    560565    public List<? extends OsmPrimitive> findRelationMembers(String role) {
    561566        return IRelation.super.findRelationMembers(role).stream()
    562                 .filter(m -> m instanceof OsmPrimitive)
    563                 .map(m -> (OsmPrimitive) m).collect(Collectors.toList());
     567                .filter(OsmPrimitive.class::isInstance)
     568                .map(OsmPrimitive.class::cast).collect(Collectors.toList());
    564569    }
    565570
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r18616 r18814  
    9797import org.openstreetmap.josm.actions.SelectAllAction;
    9898import org.openstreetmap.josm.actions.SelectNonBranchingWaySequencesAction;
     99import org.openstreetmap.josm.actions.SelectSharedChildObjectsAction;
    99100import org.openstreetmap.josm.actions.SessionSaveAction;
    100101import org.openstreetmap.josm.actions.SessionSaveAsAction;
     
    143144 * This is the JOSM main menu bar. It is overwritten to initialize itself and provide all menu
    144145 * entries as member variables (sort of collect them).
    145  *
     146 * <p>
    146147 * It also provides possibilities to attach new menu entries (used by plugins).
    147148 *
     
    320321    /** Selection / Non-branching way sequences */
    321322    public final SelectNonBranchingWaySequencesAction nonBranchingWaySequences = new SelectNonBranchingWaySequencesAction();
     323    /** Selection / Shared Child Objects */
     324    public final SelectSharedChildObjectsAction sharedChildObjects = new SelectSharedChildObjectsAction();
    322325
    323326    /* Audio menu */
     
    471474            for (int i = 0; i < m.getComponentCount()-1; i++) {
    472475                // hide separator if the next menu item is one as well
    473                 if (m.getComponent(i) instanceof JSeparator && m.getComponent(i+1) instanceof JSeparator) {
    474                     ((JSeparator) m.getComponent(i)).setVisible(false);
     476                if (m.getComponent(i) instanceof JSeparator && m.getComponent(i + 1) instanceof JSeparator) {
     477                    m.getComponent(i).setVisible(false);
    475478                }
    476479            }
    477480            // hide separator at the end of the menu
    478             if (m.getComponent(m.getComponentCount()-1) instanceof JSeparator) {
    479                 ((JSeparator) m.getComponent(m.getComponentCount()-1)).setVisible(false);
     481            if (m.getComponent(m.getComponentCount() - 1) instanceof JSeparator) {
     482                m.getComponent(m.getComponentCount() - 1).setVisible(false);
    480483            }
    481484        }
     
    493496    /**
    494497     * Add a JosmAction at the end of a menu.
    495      *
     498     * <p>
    496499     * This method handles all the shortcut handling. It also makes sure that actions that are
    497500     * handled by the OS are not duplicated on the menu.
     
    506509    /**
    507510     * Add a JosmAction at the end of a menu.
    508      *
     511     * <p>
    509512     * This method handles all the shortcut handling. It also makes sure that actions that are
    510513     * handled by the OS are not duplicated on the menu.
     
    520523    /**
    521524     * Add a JosmAction at the end of a menu.
    522      *
     525     * <p>
    523526     * This method handles all the shortcut handling. It also makes sure that actions that are
    524527     * handled by the OS are not duplicated on the menu.
     
    552555    /**
    553556     * Add the JosmAction {@code actionToBeInserted} directly below {@code existingMenuEntryAction}.
    554      *
     557     * <p>
    555558     * This method handles all the shortcut handling. It also makes sure that actions that are
    556559     * handled by the OS are not duplicated on the menu.
     
    575578    /**
    576579     * Add a JosmAction to a menu.
    577      *
     580     * <p>
    578581     * This method handles all the shortcut handling. It also makes sure that actions that are
    579582     * handled by the OS are not duplicated on the menu.
     
    864867        add(selectionMenu, invertSelection, true);
    865868        add(selectionMenu, nonBranchingWaySequences);
     869        add(selectionMenu, sharedChildObjects, true);
    866870
    867871        add(toolsMenu, splitWay);
     
    948952    public Optional<JCheckBoxMenuItem> findMapModeMenuItem(MapMode mode) {
    949953        return Arrays.stream(modeMenu.getMenuComponents())
    950                 .filter(m -> m instanceof JCheckBoxMenuItem)
    951                 .map(m -> (JCheckBoxMenuItem) m)
     954                .filter(JCheckBoxMenuItem.class::isInstance)
     955                .map(JCheckBoxMenuItem.class::cast)
    952956                .filter(m -> Objects.equals(mode, m.getAction()))
    953957                .findFirst();
Note: See TracChangeset for help on using the changeset viewer.