/** * "Officially" a turn restriction should have exactly one member with role {@link * TurnRestrictionLegRole#FROM FROM} and one member with role {@link TurnRestrictionLegRole#TO * TO}, both referring to an OSM {@link Way}. In order to deals with turn restrictions where these * integrity constraints are violated, this model also supports relation with multiple or no * 'from' or 'to' members. * * <p>Replies the turn restriction legs with role {@code role}. If no leg with this role exists, * an empty set is returned. If multiple legs exists, the set of referred primitives is returned. * * @param role the role. Must not be null. * @return the set of turn restriction legs with role {@code role}. The empty set, if no such turn * restriction leg exists * @throws IllegalArgumentException thrown if role is null */ public Set<OsmPrimitive> getTurnRestrictionLeg(TurnRestrictionLegRole role) { CheckParameterUtil.ensureParameterNotNull(role, "role"); switch (role) { case FROM: return memberModel.getFromPrimitives(); case TO: return memberModel.getToPrimitives(); } // should not happen return null; }
/** * Sets the way participating in the turn restriction in a given role. * * @param role the role. Must not be null. * @param way the way which participates in the turn restriction in the respective role. null, to * remove the way with the given role. * @exception IllegalArgumentException thrown if role is null */ public void setTurnRestrictionLeg(TurnRestrictionLegRole role, Way way) throws IllegalArgumentException { CheckParameterUtil.ensureParameterNotNull(role, "role"); switch (role) { case FROM: memberModel.setFromPrimitive(way); break; case TO: memberModel.setToPrimitive(way); break; } }
/** * Applies the current state in the model to a turn restriction * * @param turnRestriction the turn restriction. Must not be null. */ public void apply(Relation turnRestriction) { CheckParameterUtil.ensureParameterNotNull(turnRestriction, "turnRestriction"); TagCollection tags = tagEditorModel.getTagCollection(); turnRestriction.removeAll(); tags.applyTo(turnRestriction); memberModel.applyTo(turnRestriction); }
/* ----------------------------------------------------------------------------------------- */ protected boolean isAffectedByDataSetUpdate( DataSet ds, List<? extends OsmPrimitive> updatedPrimitives) { if (ds != layer.data) return false; if (updatedPrimitives == null || updatedPrimitives.isEmpty()) return false; Set<OsmPrimitive> myPrimitives = memberModel.getMemberPrimitives(); int size1 = myPrimitives.size(); myPrimitives.retainAll(updatedPrimitives); return size1 != myPrimitives.size(); }
/** * Creates a model in the context of a {@link OsmDataLayer} * * @param layer the layer. Must not be null. * @param navigationControler control to direct the user to specific UI components. Must not be * null * @throws IllegalArgumentException thrown if {@code layer} is null */ public TurnRestrictionEditorModel(OsmDataLayer layer, NavigationControler navigationControler) throws IllegalArgumentException { CheckParameterUtil.ensureParameterNotNull(layer, "layer"); CheckParameterUtil.ensureParameterNotNull(navigationControler, "navigationControler"); this.layer = layer; this.navigationControler = navigationControler; memberModel = new RelationMemberEditorModel(layer); memberModel.addTableModelListener(new RelationMemberModelListener()); issuesModel = new IssuesModel(this); addObserver(issuesModel); tagEditorModel.addTableModelListener(new TagEditorModelObserver()); selectionModel = new JosmSelectionListModel(layer); }
/** * Initializes the model from a relation representing a turn restriction * * @param turnRestriction the turn restriction */ protected void initFromTurnRestriction(Relation turnRestriction) { // populate the member model memberModel.populate(turnRestriction); // make sure we have a restriction tag TagCollection tags = TagCollection.from(turnRestriction); tags.setUniqueForKey("type", "restriction"); tagEditorModel.initFromTags(tags); setChanged(); notifyObservers(); }
/** * Sets the list of vias for the edited turn restriction. * * <p>If {@code vias} is null, all vias are removed. All primitives in {@code vias} must be * assigned to a dataset and the dataset must be equal to the dataset of this editor model, see * {@link #getDataSet()} * * <p>null values in {@link vias} are skipped. * * @param vias the list of vias * @throws IllegalArgumentException thrown if one of the via objects belongs to the wrong dataset */ public void setVias(List<OsmPrimitive> vias) throws IllegalArgumentException { memberModel.setVias(vias); }
/** * Replies the list of 'via' objects. The return value is an unmodifiable list. * * @return the list of 'via' objects */ public List<OsmPrimitive> getVias() { return memberModel.getVias(); }