Changeset 13926 in josm for trunk/src


Ignore:
Timestamp:
2018-06-13T01:33:47+02:00 (6 years ago)
Author:
Don-vip
Message:

add AbstractOsmDataLayer, MainLayerManager.getActiveData, Main.getInProgressISelection

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
25 edited

Legend:

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

    r13838 r13926  
    3232import org.openstreetmap.josm.data.coor.conversion.ICoordinateFormat;
    3333import org.openstreetmap.josm.data.osm.DataSet;
     34import org.openstreetmap.josm.data.osm.IPrimitive;
     35import org.openstreetmap.josm.data.osm.OsmData;
    3436import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3537import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
     
    265267
    266268    /**
     269     * Replies the current selected OSM primitives, from a end-user point of view.
     270     * It is not always technically the same collection of primitives than {@link DataSet#getSelected()}.
     271     * @return The current selected OSM primitives, from a end-user point of view. Can be {@code null}.
     272     * @since 6546
     273     */
     274    public Collection<OsmPrimitive> getInProgressSelection() {
     275        return Collections.emptyList();
     276    }
     277
     278    /**
    267279     * Replies the current selected primitives, from a end-user point of view.
    268      * It is not always technically the same collection of primitives than {@link DataSet#getSelected()}.
     280     * It is not always technically the same collection of primitives than {@link OsmData#getSelected()}.
    269281     * @return The current selected primitives, from a end-user point of view. Can be {@code null}.
    270      * @since 6546
    271      */
    272     public Collection<OsmPrimitive> getInProgressSelection() {
     282     * @since 13926
     283     */
     284    public Collection<? extends IPrimitive> getInProgressISelection() {
    273285        return Collections.emptyList();
    274286    }
  • trunk/src/org/openstreetmap/josm/actions/AbstractInfoAction.java

    r13842 r13926  
    1616import org.openstreetmap.josm.data.osm.AbstractPrimitive;
    1717import org.openstreetmap.josm.data.osm.DataSet;
     18import org.openstreetmap.josm.data.osm.OsmData;
    1819import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1920import org.openstreetmap.josm.gui.HelpAwareOptionPane;
     
    155156    @Override
    156157    protected void updateEnabledState() {
    157         DataSet ds = getLayerManager().getActiveDataSet();
     158        OsmData<?, ?, ?, ?> ds = getLayerManager().getActiveData();
    158159        setEnabled(ds != null && !ds.selectionEmpty());
    159160    }
  • trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java

    r13905 r13926  
    2626import org.openstreetmap.josm.data.conflict.Conflict;
    2727import org.openstreetmap.josm.data.osm.DataSet;
     28import org.openstreetmap.josm.data.osm.IPrimitive;
     29import org.openstreetmap.josm.data.osm.OsmData;
    2830import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2931import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     
    7779     */
    7880    public static void zoomToSelection() {
    79         DataSet dataSet = MainApplication.getLayerManager().getActiveDataSet();
     81        OsmData<?, ?, ?, ?> dataSet = MainApplication.getLayerManager().getActiveData();
    8082        if (dataSet == null) {
    8183            return;
    8284        }
    83         Collection<OsmPrimitive> sel = dataSet.getSelected();
     85        Collection<? extends IPrimitive> sel = dataSet.getSelected();
    8486        if (sel.isEmpty()) {
    8587            JOptionPane.showMessageDialog(
     
    9799     * @param sel The primitives to zoom to, e.g. the current selection.
    98100     */
    99     public static void zoomTo(Collection<OsmPrimitive> sel) {
     101    public static void zoomTo(Collection<? extends IPrimitive> sel) {
    100102        BoundingXYVisitor bboxCalculator = new BoundingXYVisitor();
    101103        bboxCalculator.computeBoundingBox(sel);
     
    354356    @Override
    355357    protected void updateEnabledState() {
    356         DataSet ds = getLayerManager().getActiveDataSet();
     358        OsmData<?, ?, ?, ?> ds = getLayerManager().getActiveData();
    357359        MapFrame map = MainApplication.getMap();
    358360        switch (mode) {
  • trunk/src/org/openstreetmap/josm/actions/HistoryInfoAction.java

    r13434 r13926  
    99
    1010import org.openstreetmap.josm.Main;
    11 import org.openstreetmap.josm.data.osm.DataSet;
     11import org.openstreetmap.josm.data.osm.OsmData;
    1212import org.openstreetmap.josm.gui.MainApplication;
    1313import org.openstreetmap.josm.gui.dialogs.OsmIdSelectionDialog;
     
    3838    @Override
    3939    public void actionPerformed(ActionEvent ae) {
    40         DataSet set = getLayerManager().getActiveDataSet();
     40        OsmData<?, ?, ?, ?> set = getLayerManager().getActiveData();
    4141        if (set != null && !set.selectionEmpty()) {
    4242            HistoryBrowserDialogManager.getInstance().showHistory(set.getAllSelected());
  • trunk/src/org/openstreetmap/josm/actions/InfoAction.java

    r13434 r13926  
    99import java.util.Collection;
    1010
    11 import org.openstreetmap.josm.data.osm.DataSet;
     11import org.openstreetmap.josm.data.osm.OsmData;
    1212import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1313import org.openstreetmap.josm.gui.dialogs.InspectPrimitiveDialog;
     
    3434    @Override
    3535    public void actionPerformed(ActionEvent ae) {
    36         DataSet set = getLayerManager().getActiveDataSet();
     36        OsmData<?, ?, ?, ?> set = getLayerManager().getActiveData();
    3737        if (set != null) {
    3838            new InspectPrimitiveDialog(set.getAllSelected(), set).showDialog();
  • trunk/src/org/openstreetmap/josm/actions/SelectAllAction.java

    r13434 r13926  
    88import java.awt.event.KeyEvent;
    99
    10 import org.openstreetmap.josm.data.osm.DataSet;
    11 import org.openstreetmap.josm.data.osm.OsmPrimitive;
     10import org.openstreetmap.josm.data.osm.IPrimitive;
     11import org.openstreetmap.josm.data.osm.OsmData;
    1212import org.openstreetmap.josm.tools.Shortcut;
    1313
     
    3030        if (!isEnabled())
    3131            return;
    32         DataSet ds = getLayerManager().getActiveDataSet();
    33         ds.setSelected(ds.getPrimitives(OsmPrimitive::isSelectable));
     32        OsmData<?, ?, ?, ?> ds = getLayerManager().getActiveData();
     33        ds.setSelected(ds.getPrimitives(IPrimitive::isSelectable));
    3434    }
    3535
     
    3939    @Override
    4040    protected void updateEnabledState() {
    41         setEnabled(getLayerManager().getActiveDataSet() != null);
     41        setEnabled(getLayerManager().getActiveData() != null);
    4242    }
    4343}
  • trunk/src/org/openstreetmap/josm/actions/TaggingPresetSearchAction.java

    r13434 r13926  
    3131    public void actionPerformed(ActionEvent e) {
    3232
    33         if (MainApplication.getLayerManager().getActiveDataSet() == null)
     33        if (MainApplication.getLayerManager().getActiveData() == null)
    3434            return;
    3535
  • trunk/src/org/openstreetmap/josm/actions/UnselectAllAction.java

    r13434 r13926  
    3030        if (!isEnabled())
    3131            return;
    32         getLayerManager().getActiveDataSet().setSelected();
     32        getLayerManager().getActiveData().setSelected();
    3333    }
    3434
     
    3838    @Override
    3939    protected void updateEnabledState() {
    40         setEnabled(getLayerManager().getActiveDataSet() != null);
     40        setEnabled(getLayerManager().getActiveData() != null);
    4141    }
    4242}
  • trunk/src/org/openstreetmap/josm/actions/WireframeToggleAction.java

    r13434 r13926  
    3838    @Override
    3939    protected void updateEnabledState() {
    40         setEnabled(getLayerManager().getActiveDataSet() != null);
     40        setEnabled(getLayerManager().getActiveData() != null);
    4141    }
    4242
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r13849 r13926  
    3535import org.openstreetmap.josm.data.osm.DataSet;
    3636import org.openstreetmap.josm.data.osm.Node;
     37import org.openstreetmap.josm.data.osm.OsmData;
    3738import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3839import org.openstreetmap.josm.data.osm.Way;
     
    354355    private boolean removeHighlighting() {
    355356        boolean needsRepaint = false;
    356         DataSet ds = getLayerManager().getActiveDataSet();
     357        OsmData<?, ?, ?, ?> ds = getLayerManager().getActiveData();
    357358        if (ds != null && !ds.getHighlightedVirtualNodes().isEmpty()) {
    358359            needsRepaint = true;
  • trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java

    r13761 r13926  
    885885    @Override
    886886    protected void updateEnabledState() {
    887         setEnabled(getLayerManager().getActiveDataSet() != null);
     887        setEnabled(getLayerManager().getActiveData() != null);
    888888    }
    889889
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r13654 r13926  
    9393import org.openstreetmap.josm.data.oauth.OAuthAccessTokenHolder;
    9494import org.openstreetmap.josm.data.osm.DataSet;
     95import org.openstreetmap.josm.data.osm.IPrimitive;
     96import org.openstreetmap.josm.data.osm.OsmData;
    9597import org.openstreetmap.josm.data.osm.OsmPrimitive;
    9698import org.openstreetmap.josm.data.osm.UserInfo;
     
    523525    }
    524526
    525     /**
    526      * Replies the current selected primitives, from a end-user point of view.
    527      * It is not always technically the same collection of primitives than {@link DataSet#getSelected()}.
    528      * Indeed, if the user is currently in drawing mode, only the way currently being drawn is returned,
    529      * see {@link DrawAction#getInProgressSelection()}.
    530      *
    531      * @return The current selected primitives, from a end-user point of view. Can be {@code null}.
    532      * @since 6546
    533      */
    534527    @Override
    535528    public Collection<OsmPrimitive> getInProgressSelection() {
     
    538531        } else {
    539532            DataSet ds = layerManager.getActiveDataSet();
     533            if (ds == null) return null;
     534            return ds.getSelected();
     535        }
     536    }
     537
     538    @Override
     539    public Collection<? extends IPrimitive> getInProgressISelection() {
     540        if (map != null && map.mapMode instanceof DrawAction) {
     541            return ((DrawAction) map.mapMode).getInProgressSelection();
     542        } else {
     543            OsmData<?, ?, ?, ?> ds = layerManager.getActiveData();
    540544            if (ds == null) return null;
    541545            return ds.getSelected();
  • trunk/src/org/openstreetmap/josm/gui/MapStatus.java

    r13925 r13926  
    7070import org.openstreetmap.josm.data.osm.DataSet;
    7171import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
     72import org.openstreetmap.josm.data.osm.IPrimitive;
    7273import org.openstreetmap.josm.data.osm.Node;
    7374import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    602603         * @param osm The primitive to derive the colors from
    603604         */
    604         private void popupSetLabelColors(JLabel lbl, OsmPrimitive osm) {
    605             DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    606             if (ds.isSelected(osm)) {
     605        private void popupSetLabelColors(JLabel lbl, IPrimitive osm) {
     606            if (osm.isSelected()) {
    607607                lbl.setBackground(SystemColor.textHighlight);
    608608                lbl.setForeground(SystemColor.textHighlightText);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDataText.java

    r13761 r13926  
    1515import org.openstreetmap.josm.data.osm.BBox;
    1616import org.openstreetmap.josm.data.osm.DataSet;
    17 import org.openstreetmap.josm.data.osm.Node;
     17import org.openstreetmap.josm.data.osm.INode;
     18import org.openstreetmap.josm.data.osm.IPrimitive;
     19import org.openstreetmap.josm.data.osm.IRelation;
     20import org.openstreetmap.josm.data.osm.IRelationMember;
     21import org.openstreetmap.josm.data.osm.IWay;
     22import org.openstreetmap.josm.data.osm.OsmData;
    1823import org.openstreetmap.josm.data.osm.OsmPrimitive;
    19 import org.openstreetmap.josm.data.osm.Relation;
    20 import org.openstreetmap.josm.data.osm.RelationMember;
    2124import org.openstreetmap.josm.data.osm.Way;
    2225import org.openstreetmap.josm.data.projection.proj.TransverseMercator;
     
    3639
    3740    private final StringBuilder s = new StringBuilder();
    38     private final DataSet ds;
    39 
    40     InspectPrimitiveDataText(DataSet ds) {
     41    private final OsmData<?, ?, ?, ?> ds;
     42
     43    InspectPrimitiveDataText(OsmData<?, ?, ?, ?> ds) {
    4144        this.ds = ds;
    4245    }
     
    6366     * @param o primitive to add
    6467     */
    65     public void addPrimitive(OsmPrimitive o) {
     68    public void addPrimitive(IPrimitive o) {
    6669
    6770        addHeadline(o);
     
    8285        addSpecial(o);
    8386        addReferrers(s, o);
    84         addConflicts(o);
     87        if (o instanceof OsmPrimitive) {
     88            addConflicts((OsmPrimitive) o);
     89        }
    8590        s.append(NL);
    8691    }
    8792
    88     void addHeadline(OsmPrimitive o) {
     93    void addHeadline(IPrimitive o) {
    8994        addType(o);
    9095        addNameAndId(o);
    9196    }
    9297
    93     void addType(OsmPrimitive o) {
    94         if (o instanceof Node) {
     98    void addType(IPrimitive o) {
     99        if (o instanceof INode) {
    95100            s.append(tr("Node: "));
    96         } else if (o instanceof Way) {
     101        } else if (o instanceof IWay) {
    97102            s.append(tr("Way: "));
    98         } else if (o instanceof Relation) {
     103        } else if (o instanceof IRelation) {
    99104            s.append(tr("Relation: "));
    100105        }
    101106    }
    102107
    103     void addNameAndId(OsmPrimitive o) {
     108    void addNameAndId(IPrimitive o) {
    104109        String name = o.get("name");
    105110        if (name == null) {
     
    110115    }
    111116
    112     void addState(OsmPrimitive o) {
     117    void addState(IPrimitive o) {
    113118        StringBuilder sb = new StringBuilder(INDENT);
    114119        /* selected state is left out: not interesting as it is always selected */
     
    141146    }
    142147
    143     void addCommon(OsmPrimitive o) {
     148    void addCommon(IPrimitive o) {
    144149        add(tr("Data Set: "), Integer.toHexString(o.getDataSet().hashCode()));
    145150        add(tr("Edited at: "), o.isTimestampEmpty() ? tr("<new object>")
     
    151156    }
    152157
    153     void addAttributes(OsmPrimitive o) {
     158    void addAttributes(IPrimitive o) {
    154159        if (o.hasKeys()) {
    155160            add(tr("Tags: "));
     
    161166    }
    162167
    163     void addSpecial(OsmPrimitive o) {
    164         if (o instanceof Node) {
    165             addCoordinates((Node) o);
    166         } else if (o instanceof Way) {
     168    void addSpecial(IPrimitive o) {
     169        if (o instanceof INode) {
     170            addCoordinates((INode) o);
     171        } else if (o instanceof IWay) {
    167172            addBbox(o);
    168173            add(tr("Centroid: "),
    169174                    toStringCSV(", ", Main.getProjection().eastNorth2latlon(
    170175                            Geometry.getCentroid(((Way) o).getNodes()))));
    171             addWayNodes((Way) o);
    172         } else if (o instanceof Relation) {
     176            addWayNodes((IWay<?>) o);
     177        } else if (o instanceof IRelation) {
    173178            addBbox(o);
    174             addRelationMembers((Relation) o);
    175         }
    176     }
    177 
    178     void addRelationMembers(Relation r) {
     179            addRelationMembers((IRelation<?>) o);
     180        }
     181    }
     182
     183    void addRelationMembers(IRelation<?> r) {
    179184        add(trn("{0} Member: ", "{0} Members: ", r.getMembersCount(), r.getMembersCount()));
    180         for (RelationMember m : r.getMembers()) {
     185        for (IRelationMember<?> m : r.getMembers()) {
    181186            s.append(INDENT).append(INDENT);
    182187            addHeadline(m.getMember());
     
    186191    }
    187192
    188     void addWayNodes(Way w) {
     193    void addWayNodes(IWay<?> w) {
    189194        add(tr("{0} Nodes: ", w.getNodesCount()));
    190         for (Node n : w.getNodes()) {
     195        for (INode n : w.getNodes()) {
    191196            s.append(INDENT).append(INDENT);
    192197            addNameAndId(n);
     
    195200    }
    196201
    197     void addBbox(OsmPrimitive o) {
     202    void addBbox(IPrimitive o) {
    198203        BBox bbox = o.getBBox();
    199204        if (bbox != null) {
     
    210215    }
    211216
    212     void addCoordinates(Node n) {
     217    void addCoordinates(INode n) {
    213218        if (n.isLatLonKnown()) {
    214219            add(tr("Coordinates:"), " ",
     
    225230    }
    226231
    227     void addReferrers(StringBuilder s, OsmPrimitive o) {
    228         List<OsmPrimitive> refs = o.getReferrers();
     232    void addReferrers(StringBuilder s, IPrimitive o) {
     233        List<? extends IPrimitive> refs = o.getReferrers();
    229234        if (!refs.isEmpty()) {
    230235            add(tr("Part of: "));
    231             for (OsmPrimitive p : refs) {
     236            for (IPrimitive p : refs) {
    232237                s.append(INDENT).append(INDENT);
    233238                addHeadline(p);
     
    238243
    239244    void addConflicts(OsmPrimitive o) {
    240         Conflict<?> c = ds.getConflicts().getConflictForMy(o);
     245        Conflict<?> c = ((DataSet) ds).getConflicts().getConflictForMy(o);
    241246        if (c != null) {
    242247            add(tr("In conflict with: "));
  • trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java

    r13636 r13926  
    2222
    2323import org.openstreetmap.josm.Main;
    24 import org.openstreetmap.josm.data.osm.DataSet;
    2524import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
     25import org.openstreetmap.josm.data.osm.IPrimitive;
     26import org.openstreetmap.josm.data.osm.OsmData;
    2627import org.openstreetmap.josm.data.osm.OsmPrimitive;
    27 import org.openstreetmap.josm.data.osm.OsmPrimitiveComparator;
     28import org.openstreetmap.josm.data.osm.PrimitiveComparator;
    2829import org.openstreetmap.josm.gui.ExtendedDialog;
    2930import org.openstreetmap.josm.gui.MainApplication;
     
    5253public class InspectPrimitiveDialog extends ExtendedDialog {
    5354
    54     protected transient List<OsmPrimitive> primitives;
     55    protected transient List<IPrimitive> primitives;
    5556    private boolean mappaintTabLoaded;
    5657    private boolean editcountTabLoaded;
     
    6263     * @since 12672 (signature)
    6364     */
    64     public InspectPrimitiveDialog(final Collection<OsmPrimitive> primitives, DataSet data) {
     65    public InspectPrimitiveDialog(final Collection<? extends IPrimitive> primitives, OsmData<?, ?, ?, ?> data) {
    6566        super(Main.parent, tr("Advanced object info"), tr("Close"));
    6667        this.primitives = new ArrayList<>(primitives);
     
    105106    }
    106107
    107     protected static String buildDataText(DataSet data, List<OsmPrimitive> primitives) {
     108    protected static String buildDataText(OsmData<?, ?, ?, ?> data, List<IPrimitive> primitives) {
    108109        InspectPrimitiveDataText dt = new InspectPrimitiveDataText(data);
    109110        primitives.stream()
    110                 .sorted(OsmPrimitiveComparator.orderingWaysRelationsNodes().thenComparing(OsmPrimitiveComparator.comparingNames()))
     111                .sorted(PrimitiveComparator.orderingWaysRelationsNodes().thenComparing(PrimitiveComparator.comparingNames()))
    111112                .forEachOrdered(dt::addPrimitive);
    112113        return dt.toString();
     
    171172        Count only tagged nodes (so empty way nodes don't inflate counts).
    172173    */
    173     protected static String buildListOfEditorsText(Iterable<OsmPrimitive> primitives) {
     174    protected static String buildListOfEditorsText(Iterable<? extends IPrimitive> primitives) {
    174175        final Map<String, Integer> editCountByUser = new TreeMap<>(Collator.getInstance(Locale.getDefault()));
    175176
    176177        // Count who edited each selected object
    177         for (OsmPrimitive o : primitives) {
     178        for (IPrimitive o : primitives) {
    178179            if (o.getUser() != null) {
    179180                String username = o.getUser().getName();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r13925 r13926  
    344344
    345345        protected void setCurrentRelationAsSelection() {
    346             MainApplication.getLayerManager().getActiveDataSet().setSelected(displaylist.getSelectedValue());
     346            MainApplication.getLayerManager().getActiveData().setSelected(displaylist.getSelectedValue());
    347347        }
    348348
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r13925 r13926  
    4646import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    4747import org.openstreetmap.josm.data.osm.Node;
     48import org.openstreetmap.josm.data.osm.OsmData;
    4849import org.openstreetmap.josm.data.osm.OsmPrimitive;
    4950import org.openstreetmap.josm.data.osm.OsmPrimitiveComparator;
     
    295296
    296297        protected void updateEnabledState() {
    297             setEnabled(MainApplication.getLayerManager().getActiveDataSet() != null);
     298            setEnabled(MainApplication.getLayerManager().getActiveData() != null);
    298299        }
    299300
     
    320321            Collection<OsmPrimitive> sel = model.getSelected();
    321322            if (sel.isEmpty()) return;
    322             DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     323            OsmData<?, ?, ?, ?> ds = MainApplication.getLayerManager().getActiveData();
    323324            if (ds == null) return;
    324325            ds.setSelected(sel);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java

    r13817 r13926  
    3434import org.openstreetmap.josm.actions.AbstractInfoAction;
    3535import org.openstreetmap.josm.data.osm.DataSelectionListener;
    36 import org.openstreetmap.josm.data.osm.DataSet;
     36import org.openstreetmap.josm.data.osm.IPrimitive;
     37import org.openstreetmap.josm.data.osm.OsmData;
    3738import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3839import org.openstreetmap.josm.data.osm.User;
     
    364365                users.add(data.get(index).user);
    365366            }
    366             DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    367             Collection<OsmPrimitive> selected = ds.getAllSelected();
    368             Collection<OsmPrimitive> byUser = new LinkedList<>();
    369             for (OsmPrimitive p : selected) {
     367            OsmData<?, ?, ?, ?> ds = MainApplication.getLayerManager().getActiveData();
     368            Collection<? extends IPrimitive> selected = ds.getAllSelected();
     369            Collection<IPrimitive> byUser = new LinkedList<>();
     370            for (IPrimitive p : selected) {
    370371                if (users.contains(p.getUser())) {
    371372                    byUser.add(p);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r13925 r13926  
    6363import org.openstreetmap.josm.data.osm.DataSet;
    6464import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
     65import org.openstreetmap.josm.data.osm.IPrimitive;
    6566import org.openstreetmap.josm.data.osm.IRelation;
     67import org.openstreetmap.josm.data.osm.IRelationMember;
    6668import org.openstreetmap.josm.data.osm.Node;
    6769import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    230232
    231233    private final PreferenceChangedListener preferenceListener = e -> {
    232                 if (MainApplication.getLayerManager().getActiveDataSet() != null) {
     234                if (MainApplication.getLayerManager().getActiveData() != null) {
    233235                    // Re-load data when display preference change
    234236                    updateSelection();
     
    488490        OsmDataLayer layer = MainApplication.getLayerManager().getActiveDataLayer();
    489491        if (!layer.isLocked()) {
    490             RelationEditor.getEditor(
    491                     layer, relation, ((MemberInfo) membershipData.getValueAt(row, 1)).role).setVisible(true);
     492            List<RelationMember> members = new ArrayList<>();
     493            for (IRelationMember<?> rm : ((MemberInfo) membershipData.getValueAt(row, 1)).role) {
     494                if (rm instanceof RelationMember) {
     495                    members.add((RelationMember) rm);
     496                }
     497            }
     498            RelationEditor.getEditor(layer, relation, members).setVisible(true);
    492499        }
    493500    }
     
    533540    public void setVisible(boolean b) {
    534541        super.setVisible(b);
    535         if (b && MainApplication.getLayerManager().getActiveDataSet() != null) {
     542        if (b && MainApplication.getLayerManager().getActiveData() != null) {
    536543            updateSelection();
    537544        }
     
    559566
    560567        // Ignore parameter as we do not want to operate always on real selection here, especially in draw mode
    561         Collection<OsmPrimitive> newSel = Optional.ofNullable(Main.main.getInProgressSelection()).orElseGet(Collections::emptyList);
     568        Collection<? extends IPrimitive> newSel = Optional.ofNullable(Main.main.getInProgressISelection()).orElseGet(Collections::emptyList);
    562569        String selectedTag;
    563570        Relation selectedRelation = null;
     
    578585        valueCount.clear();
    579586        Set<TaggingPresetType> types = EnumSet.noneOf(TaggingPresetType.class);
    580         for (OsmPrimitive osm : newSel) {
     587        for (IPrimitive osm : newSel) {
    581588            types.add(TaggingPresetType.forPrimitive(osm));
    582589            for (String key : osm.keySet()) {
     
    610617        membershipData.setRowCount(0);
    611618
    612         Map<Relation, MemberInfo> roles = new HashMap<>();
    613         for (OsmPrimitive primitive: newSel) {
    614             for (OsmPrimitive ref: primitive.getReferrers(true)) {
    615                 if (ref instanceof Relation && !ref.isIncomplete() && !ref.isDeleted()) {
    616                     Relation r = (Relation) ref;
     619        Map<IRelation<?>, MemberInfo> roles = new HashMap<>();
     620        for (IPrimitive primitive: newSel) {
     621            for (IPrimitive ref: primitive.getReferrers(true)) {
     622                if (ref instanceof IRelation && !ref.isIncomplete() && !ref.isDeleted()) {
     623                    IRelation<?> r = (IRelation<?>) ref;
    617624                    MemberInfo mi = Optional.ofNullable(roles.get(r)).orElseGet(() -> new MemberInfo(newSel));
    618625                    roles.put(r, mi);
    619626                    int i = 1;
    620                     for (RelationMember m : r.getMembers()) {
     627                    for (IRelationMember<?> m : r.getMembers()) {
    621628                        if (m.getMember() == primitive) {
    622629                            mi.add(m, i);
     
    628635        }
    629636
    630         List<Relation> sortedRelations = new ArrayList<>(roles.keySet());
     637        List<IRelation<?>> sortedRelations = new ArrayList<>(roles.keySet());
    631638        sortedRelations.sort((o1, o2) -> {
    632639            int comp = Boolean.compare(o1.isDisabledAndHidden(), o2.isDisabledAndHidden());
     
    634641        });
    635642
    636         for (Relation r: sortedRelations) {
     643        for (IRelation<?> r: sortedRelations) {
    637644            membershipData.addRow(new Object[]{r, roles.get(r)});
    638645        }
     
    888895
    889896    static class MemberInfo {
    890         private final List<RelationMember> role = new ArrayList<>();
    891         private Set<OsmPrimitive> members = new HashSet<>();
     897        private final List<IRelationMember<?>> role = new ArrayList<>();
     898        private Set<IPrimitive> members = new HashSet<>();
    892899        private List<Integer> position = new ArrayList<>();
    893         private Collection<OsmPrimitive> selection;
     900        private Collection<? extends IPrimitive> selection;
    894901        private String positionString;
    895902        private String roleString;
    896903
    897         MemberInfo(Collection<OsmPrimitive> selection) {
     904        MemberInfo(Collection<? extends IPrimitive> selection) {
    898905            this.selection = selection;
    899906        }
    900907
    901         void add(RelationMember r, Integer p) {
     908        void add(IRelationMember<?> r, Integer p) {
    902909            role.add(r);
    903910            members.add(r.getMember());
     
    921928        String getRoleString() {
    922929            if (roleString == null) {
    923                 for (RelationMember r : role) {
     930                for (IRelationMember<?> r : role) {
    924931                    if (roleString == null) {
    925932                        roleString = r.getRole();
     
    11751182                return;
    11761183            String key = editHelper.getDataKey(tagTable.getSelectedRow());
    1177             Collection<OsmPrimitive> sel = Main.main.getInProgressSelection();
     1184            Collection<? extends IPrimitive> sel = Main.main.getInProgressISelection();
    11781185            if (sel.isEmpty())
    11791186                return;
     
    11831190    }
    11841191
    1185     static SearchSetting createSearchSetting(String key, Collection<OsmPrimitive> sel, boolean sameType) {
     1192    static SearchSetting createSearchSetting(String key, Collection<? extends IPrimitive> sel, boolean sameType) {
    11861193        String sep = "";
    11871194        StringBuilder s = new StringBuilder();
    11881195        Set<String> consideredTokens = new TreeSet<>();
    1189         for (OsmPrimitive p : sel) {
     1196        for (IPrimitive p : sel) {
    11901197            String val = p.get(key);
    11911198            if (val == null || (!sameType && consideredTokens.contains(val))) {
  • trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java

    r13434 r13926  
    2222
    2323import org.openstreetmap.josm.actions.AutoScaleAction;
    24 import org.openstreetmap.josm.data.osm.DataSet;
     24import org.openstreetmap.josm.data.osm.IPrimitive;
     25import org.openstreetmap.josm.data.osm.OsmData;
    2526import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2627import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    247248            if (!isEnabled())
    248249                return;
    249             OsmPrimitive p = getPrimitiveToZoom();
     250            IPrimitive p = getPrimitiveToZoom();
    250251            if (p != null) {
    251                 DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     252                OsmData<?, ?, ?, ?> ds = MainApplication.getLayerManager().getActiveData();
    252253                if (ds != null) {
    253254                    ds.setSelected(p.getPrimitiveId());
     
    262263        }
    263264
    264         protected OsmPrimitive getPrimitiveToZoom() {
     265        protected IPrimitive getPrimitiveToZoom() {
    265266            if (primitiveId == null)
    266267                return null;
    267             DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     268            OsmData<?, ?, ?, ?> ds = MainApplication.getLayerManager().getActiveData();
    268269            if (ds == null)
    269270                return null;
     
    272273
    273274        public void updateEnabledState() {
    274             setEnabled(MainApplication.getLayerManager().getActiveDataSet() != null && getPrimitiveToZoom() != null);
     275            setEnabled(MainApplication.getLayerManager().getActiveData() != null && getPrimitiveToZoom() != null);
    275276        }
    276277    }
  • trunk/src/org/openstreetmap/josm/gui/layer/MainLayerManager.java

    r13654 r13926  
    1414
    1515import org.openstreetmap.josm.data.osm.DataSet;
     16import org.openstreetmap.josm.data.osm.OsmData;
    1617import org.openstreetmap.josm.gui.MainApplication;
    1718import org.openstreetmap.josm.gui.io.AsynchronousUploadPrimitivesTask;
     
    175176     * The current active data layer. It might be editable or not, based on its read-only status.
    176177     */
    177     private OsmDataLayer dataLayer;
     178    private AbstractOsmDataLayer dataLayer;
     179
     180    /**
     181     * The current active OSM data layer. It might be editable or not, based on its read-only status.
     182     */
     183    private OsmDataLayer osmDataLayer;
    178184
    179185    private final List<ActiveLayerChangeListener> activeLayerChangeListeners = new CopyOnWriteArrayList<>();
     
    262268
    263269    private void setActiveLayer(Layer layer, boolean forceEditLayerUpdate) {
    264         ActiveLayerChangeEvent event = new ActiveLayerChangeEvent(this, dataLayer, activeLayer);
     270        ActiveLayerChangeEvent event = new ActiveLayerChangeEvent(this, osmDataLayer, activeLayer);
    265271        activeLayer = layer;
     272        if (activeLayer instanceof AbstractOsmDataLayer) {
     273            dataLayer = (AbstractOsmDataLayer) layer;
     274        }
    266275        if (activeLayer instanceof OsmDataLayer) {
    267             dataLayer = (OsmDataLayer) activeLayer;
     276            osmDataLayer = (OsmDataLayer) activeLayer;
    268277        } else if (forceEditLayerUpdate) {
    269             dataLayer = null;
     278            osmDataLayer = null;
    270279        }
    271280        fireActiveLayerChange(event);
     
    274283    private void fireActiveLayerChange(ActiveLayerChangeEvent event) {
    275284        GuiHelper.assertCallFromEdt();
    276         if (event.getPreviousActiveLayer() != activeLayer || event.getPreviousDataLayer() != dataLayer) {
     285        if (event.getPreviousActiveLayer() != activeLayer || event.getPreviousDataLayer() != osmDataLayer) {
    277286            for (ActiveLayerChangeListener l : activeLayerChangeListeners) {
    278287                l.activeOrEditLayerChanged(event);
     
    307316        }
    308317
    309         if (layer == activeLayer || layer == dataLayer) {
     318        if (layer == activeLayer || layer == osmDataLayer) {
    310319            Layer nextActive = suggestNextActiveLayer(layer);
    311320            setActiveLayer(nextActive, true);
     
    376385     */
    377386    public synchronized OsmDataLayer getEditLayer() {
    378         if (dataLayer != null && !dataLayer.isLocked())
    379             return dataLayer;
     387        if (osmDataLayer != null && !osmDataLayer.isLocked())
     388            return osmDataLayer;
    380389        else
    381390            return null;
     
    390399     */
    391400    public synchronized OsmDataLayer getActiveDataLayer() {
    392         if (dataLayer != null)
    393             return dataLayer;
     401        if (osmDataLayer != null)
     402            return osmDataLayer;
    394403        else
    395404            return null;
     
    402411     */
    403412    public synchronized DataSet getEditDataSet() {
    404         if (dataLayer != null && !dataLayer.isLocked()) {
     413        if (osmDataLayer != null && !osmDataLayer.isLocked()) {
     414            return osmDataLayer.getDataSet();
     415        } else {
     416            return null;
     417        }
     418    }
     419
     420    /**
     421     * Gets the data set of the active data layer. The dataset can be read-only.
     422     * @return That data set, <code>null</code> if there is no active data layer.
     423     * @since 13926
     424     */
     425    public synchronized OsmData<?, ?, ?, ?> getActiveData() {
     426        if (dataLayer != null) {
    405427            return dataLayer.getDataSet();
    406428        } else {
     
    410432
    411433    /**
    412      * Gets the data set of the active data layer. The dataset can be read-only.
     434     * Gets the data set of the active {@link OsmDataLayer}. The dataset can be read-only.
    413435     * @return That data set, <code>null</code> if there is no active data layer.
    414436     * @see #getEditDataSet
     
    416438     */
    417439    public synchronized DataSet getActiveDataSet() {
    418         if (dataLayer != null) {
    419             return dataLayer.getDataSet();
     440        if (osmDataLayer != null) {
     441            return osmDataLayer.getDataSet();
    420442        } else {
    421443            return null;
     
    475497     */
    476498    public void invalidateEditLayer() {
    477         if (dataLayer != null) {
    478             dataLayer.invalidate();
     499        if (osmDataLayer != null) {
     500            osmDataLayer.invalidate();
    479501        }
    480502    }
     
    512534
    513535        // Reset only the edit layer as empty
    514         if (dataLayer == layer) {
    515             ActiveLayerChangeEvent activeLayerChangeEvent = new ActiveLayerChangeEvent(this, dataLayer, activeLayer);
    516             dataLayer = null;
     536        if (osmDataLayer == layer) {
     537            ActiveLayerChangeEvent activeLayerChangeEvent = new ActiveLayerChangeEvent(this, osmDataLayer, activeLayer);
     538            osmDataLayer = null;
    517539            fireActiveLayerChange(activeLayerChangeEvent);
    518540        }
     
    532554
    533555        // Set the layer as edit layer if the edit layer is empty.
    534         if (dataLayer == null) {
    535             ActiveLayerChangeEvent layerChangeEvent = new ActiveLayerChangeEvent(this, dataLayer, activeLayer);
    536             dataLayer = layer;
     556        if (osmDataLayer == null) {
     557            ActiveLayerChangeEvent layerChangeEvent = new ActiveLayerChangeEvent(this, osmDataLayer, activeLayer);
     558            osmDataLayer = layer;
    537559            fireActiveLayerChange(layerChangeEvent);
    538560        }
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r13855 r13926  
    123123 * @since 17
    124124 */
    125 public class OsmDataLayer extends AbstractModifiableLayer implements Listener, DataSelectionListener, HighlightUpdateListener {
     125public class OsmDataLayer extends AbstractOsmDataLayer implements Listener, DataSelectionListener, HighlightUpdateListener {
    126126    private static final int HATCHED_SIZE = 15;
    127127    /** Property used to know if this layer has to be saved on disk */
     
    420420     * @since 13558
    421421     */
     422    @Override
    422423    public DataSet getDataSet() {
    423424        return data;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintMenu.java

    r13434 r13926  
    6767        public void updateEnabledState() {
    6868            setEnabled(MainApplication.isDisplayingMapView()
    69                     && (MainApplication.getLayerManager().getActiveDataSet() != null || mapHasGpxorMarkerLayer()));
     69                    && (MainApplication.getLayerManager().getActiveData() != null || mapHasGpxorMarkerLayer()));
    7070        }
    7171
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java

    r13623 r13926  
    3939import org.openstreetmap.josm.data.osm.DataSet;
    4040import org.openstreetmap.josm.data.osm.IPrimitive;
     41import org.openstreetmap.josm.data.osm.OsmData;
    4142import org.openstreetmap.josm.data.osm.OsmPrimitive;
    4243import org.openstreetmap.josm.data.osm.Relation;
     
    495496            boolean disableApply = false;
    496497            if (!sel.isEmpty()) {
    497                 DataSet ds = sel.iterator().next().getDataSet();
     498                OsmData<?, ?, ?, ?> ds = sel.iterator().next().getDataSet();
    498499                disableApply = ds != null && ds.isLocked();
    499500            }
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java

    r13434 r13926  
    4343        @Override
    4444        public void actionPerformed(ActionEvent e) {
    45             if (MainApplication.getLayerManager().getActiveDataSet() != null) {
     45            if (MainApplication.getLayerManager().getActiveData() != null) {
    4646                TaggingPresetSearchPrimitiveDialog.getInstance().showDialog();
    4747            }
     
    5050        @Override
    5151        protected void updateEnabledState() {
    52             setEnabled(getLayerManager().getActiveDataSet() != null);
     52            setEnabled(getLayerManager().getActiveData() != null);
    5353        }
    5454    }
Note: See TracChangeset for help on using the changeset viewer.