/**
   * populates the model with the relation members in relation my and their
   *
   * @param my my relation. Must not be null.
   * @param their their relation. Must not be null.
   * @throws IllegalArgumentException if my is null
   * @throws IllegalArgumentException if their is null
   */
  public void populate(Relation my, Relation their) {
    this.myDataset = my.getDataSet();

    CheckParameterUtil.ensureParameterNotNull(my, "my");
    CheckParameterUtil.ensureParameterNotNull(their, "their");

    getMergedEntries().clear();
    getMyEntries().clear();
    getTheirEntries().clear();

    for (RelationMember n : my.getMembers()) {
      getMyEntries().add(n);
    }
    for (RelationMember n : their.getMembers()) {
      getTheirEntries().add(n);
    }
    if (myAndTheirEntriesEqual()) {
      for (RelationMember m : getMyEntries()) {
        getMergedEntries().add(cloneEntryForMergedList(m));
      }
      setFrozen(true);
    } else {
      setFrozen(false);
    }

    fireModelDataChanged();
  }
Exemple #2
0
  /**
   * Splits the nodes of {@code wayToSplit} into a list of node sequences which are separated at the
   * nodes in {@code splitPoints}.
   *
   * <p>This method displays warning messages if {@code wayToSplit} and/or {@code splitPoints}
   * aren't consistent.
   *
   * <p>Returns null, if building the split chunks fails.
   *
   * @param wayToSplit the way to split. Must not be null.
   * @param splitPoints the nodes where the way is split. Must not be null.
   * @return the list of chunks
   */
  public static List<List<Node>> buildSplitChunks(Way wayToSplit, List<Node> splitPoints) {
    CheckParameterUtil.ensureParameterNotNull(wayToSplit, "wayToSplit");
    CheckParameterUtil.ensureParameterNotNull(splitPoints, "splitPoints");

    Set<Node> nodeSet = new HashSet<>(splitPoints);
    List<List<Node>> wayChunks = new LinkedList<>();
    List<Node> currentWayChunk = new ArrayList<>();
    wayChunks.add(currentWayChunk);

    Iterator<Node> it = wayToSplit.getNodes().iterator();
    while (it.hasNext()) {
      Node currentNode = it.next();
      boolean atEndOfWay = currentWayChunk.isEmpty() || !it.hasNext();
      currentWayChunk.add(currentNode);
      if (nodeSet.contains(currentNode) && !atEndOfWay) {
        currentWayChunk = new ArrayList<>();
        currentWayChunk.add(currentNode);
        wayChunks.add(currentWayChunk);
      }
    }

    // Handle circular ways specially.
    // If you split at a circular way at two nodes, you just want to split
    // it at these points, not also at the former endpoint.
    // So if the last node is the same first node, join the last and the
    // first way chunk.
    List<Node> lastWayChunk = wayChunks.get(wayChunks.size() - 1);
    if (wayChunks.size() >= 2
        && wayChunks.get(0).get(0) == lastWayChunk.get(lastWayChunk.size() - 1)
        && !nodeSet.contains(wayChunks.get(0).get(0))) {
      if (wayChunks.size() == 2) {
        new Notification(tr("You must select two or more nodes to split a circular way."))
            .setIcon(JOptionPane.WARNING_MESSAGE)
            .show();
        return null;
      }
      lastWayChunk.remove(lastWayChunk.size() - 1);
      lastWayChunk.addAll(wayChunks.get(0));
      wayChunks.remove(wayChunks.size() - 1);
      wayChunks.set(0, lastWayChunk);
    }

    if (wayChunks.size() < 2) {
      if (wayChunks.get(0).get(0) == wayChunks.get(0).get(wayChunks.get(0).size() - 1)) {
        new Notification(tr("You must select two or more nodes to split a circular way."))
            .setIcon(JOptionPane.WARNING_MESSAGE)
            .show();
      } else {
        new Notification(
                tr(
                    "The way cannot be split at the selected nodes. (Hint: Select nodes in the middle of the way.)"))
            .setIcon(JOptionPane.WARNING_MESSAGE)
            .show();
      }
      return null;
    }
    return wayChunks;
  }
 /**
  * Builds the command to resolve conflicts in the node list of a way
  *
  * @param my my relation. Must not be null.
  * @param their their relation. Must not be null
  * @return the command
  * @exception IllegalArgumentException thrown, if my is null
  * @exception IllegalArgumentException thrown, if their is null
  * @exception IllegalStateException thrown, if the merge is not yet frozen
  */
 public RelationMemberConflictResolverCommand buildResolveCommand(Relation my, Relation their) {
   CheckParameterUtil.ensureParameterNotNull(my, "my");
   CheckParameterUtil.ensureParameterNotNull(their, "their");
   if (!isFrozen())
     throw new IllegalArgumentException(
         tr("Merged nodes not frozen yet. Cannot build resolution command"));
   List<RelationMember> entries = getMergedEntries();
   return new RelationMemberConflictResolverCommand(my, their, entries);
 }
Exemple #4
0
  /**
   * Deletes the relation in the context of the given layer. Also notifies {@see
   * RelationDialogManager} and {@see OsmDataLayer#fireDataChange()} events.
   *
   * @param layer the layer in whose context the relation is deleted. Must not be null.
   * @param toDelete the relation to be deleted. Must not be null.
   * @exception IllegalArgumentException thrown if layer is null
   * @exception IllegalArgumentException thrown if toDelete is nul
   */
  public static void deleteRelation(OsmDataLayer layer, Relation toDelete) {
    CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    CheckParameterUtil.ensureParameterNotNull(toDelete, "toDelete");

    Command cmd = DeleteCommand.delete(layer, Collections.singleton(toDelete));
    if (cmd != null) {
      // cmd can be null if the user cancels dialogs DialogCommand displays
      Main.main.undoRedo.add(cmd);
      RelationDialogManager.getRelationDialogManager().close(layer, toDelete);
    }
  }
 /**
  * Replies true if {@code tp1} and {@code tp2} have the same tags and the same members
  *
  * @param tp1 a turn restriction. Must not be null.
  * @param tp2 a turn restriction . Must not be null.
  * @return true if {@code tp1} and {@code tp2} have the same tags and the same members
  * @throws IllegalArgumentException thrown if {@code tp1} is null
  * @throws IllegalArgumentException thrown if {@code tp2} is null
  */
 public static boolean hasSameMembersAndTags(Relation tp1, Relation tp2)
     throws IllegalArgumentException {
   CheckParameterUtil.ensureParameterNotNull(tp1, "tp1");
   CheckParameterUtil.ensureParameterNotNull(tp2, "tp2");
   if (!TagCollection.from(tp1).asSet().equals(TagCollection.from(tp2).asSet())) return false;
   if (tp1.getMembersCount() != tp2.getMembersCount()) return false;
   for (int i = 0; i < tp1.getMembersCount(); i++) {
     if (!tp1.getMember(i).equals(tp2.getMember(i))) return false;
   }
   return true;
 }
Exemple #6
0
 /**
  * @param a the first selector
  * @param b the second selector
  * @param type the selector type
  */
 public ChildOrParentSelector(
     Selector a, LinkSelector link, Selector b, ChildOrParentSelectorType type) {
   CheckParameterUtil.ensureParameterNotNull(a, "a");
   CheckParameterUtil.ensureParameterNotNull(b, "b");
   CheckParameterUtil.ensureParameterNotNull(link, "link");
   CheckParameterUtil.ensureParameterNotNull(type, "type");
   this.left = a;
   this.link = link;
   this.right = b;
   this.type = type;
 }
 /**
  * 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);
 }
Exemple #8
0
  /**
   * Returns the coordinates of all cells in a grid that a line between 2 nodes intersects with.
   *
   * @param en1 The first EastNorth.
   * @param en2 The second EastNorth.
   * @param gridDetail The detail of the grid. Bigger values give smaller cells, but a bigger number
   *     of them.
   * @return A list with the coordinates of all cells
   * @throws IllegalArgumentException if en1 or en2 is {@code null}
   * @since 6869
   */
  public static List<Point2D> getSegmentCells(EastNorth en1, EastNorth en2, double gridDetail)
      throws IllegalArgumentException {
    CheckParameterUtil.ensureParameterNotNull(en1, "en1");
    CheckParameterUtil.ensureParameterNotNull(en2, "en2");
    List<Point2D> cells = new ArrayList<>();
    double x0 = en1.east() * gridDetail;
    double x1 = en2.east() * gridDetail;
    double y0 = en1.north() * gridDetail + 1;
    double y1 = en2.north() * gridDetail + 1;

    if (x0 > x1) {
      // Move to 1st-4th cuadrants
      double aux;
      aux = x0;
      x0 = x1;
      x1 = aux;
      aux = y0;
      y0 = y1;
      y1 = aux;
    }

    double dx = x1 - x0;
    double dy = y1 - y0;
    long stepY = y0 <= y1 ? 1 : -1;
    long gridX0 = (long) Math.floor(x0);
    long gridX1 = (long) Math.floor(x1);
    long gridY0 = (long) Math.floor(y0);
    long gridY1 = (long) Math.floor(y1);

    long maxSteps = (gridX1 - gridX0) + Math.abs(gridY1 - gridY0) + 1;
    while ((gridX0 <= gridX1 && (gridY0 - gridY1) * stepY <= 0) && maxSteps-- > 0) {
      cells.add(new Point2D.Double(gridX0, gridY0));

      // Is the cross between the segment and next vertical line nearer than the cross with next
      // horizontal line?
      // Note: segment line formula: y=dy/dx(x-x1)+y1
      // Note: if dy < 0, must use *bottom* line. If dy > 0, must use upper line
      double scanY = dy / dx * (gridX0 + 1 - x1) + y1 + (dy < 0 ? -1 : 0);
      double scanX = dx / dy * (gridY0 + (dy < 0 ? 0 : 1) * stepY - y1) + x1;

      double distX = Math.pow(gridX0 + 1 - x0, 2) + Math.pow(scanY - y0, 2);
      double distY = Math.pow(scanX - x0, 2) + Math.pow(gridY0 + stepY - y0, 2);

      if (distX < distY) {
        gridX0 += 1;
      } else {
        gridY0 += stepY;
      }
    }
    return cells;
  }
 /**
  * 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);
 }
Exemple #10
0
  public Bounds(
      String asString, String separator, ParseMethod parseMethod, boolean roundToOsmPrecision) {
    CheckParameterUtil.ensureParameterNotNull(asString, "asString");
    String[] components = asString.split(separator);
    if (components.length != 4)
      throw new IllegalArgumentException(
          MessageFormat.format(
              "Exactly four doubles expected in string, got {0}: {1}",
              components.length, asString));
    double[] values = new double[4];
    for (int i = 0; i < 4; i++) {
      try {
        values[i] = Double.parseDouble(components[i]);
      } catch (NumberFormatException e) {
        throw new IllegalArgumentException(
            MessageFormat.format("Illegal double value ''{0}''", components[i]), e);
      }
    }

    switch (parseMethod) {
      case LEFT_BOTTOM_RIGHT_TOP:
        this.minLat = initLat(values[1], roundToOsmPrecision);
        this.minLon = initLon(values[0], roundToOsmPrecision);
        this.maxLat = initLat(values[3], roundToOsmPrecision);
        this.maxLon = initLon(values[2], roundToOsmPrecision);
        break;
      case MINLAT_MINLON_MAXLAT_MAXLON:
      default:
        this.minLat = initLat(values[0], roundToOsmPrecision);
        this.minLon = initLon(values[1], roundToOsmPrecision);
        this.maxLat = initLat(values[2], roundToOsmPrecision);
        this.maxLon = initLon(values[3], roundToOsmPrecision);
    }
  }
 /**
  * Replies true, if {@code Renderer} is already a registered map renderer class.
  *
  * @param renderer the map renderer class. Must not be null.
  * @return true, if {@code Renderer} is already a registered map renderer class
  * @throws IllegalArgumentException if {@code renderer} is null
  */
 public boolean isRegistered(Class<? extends AbstractMapRenderer> renderer) {
   CheckParameterUtil.ensureParameterNotNull(renderer);
   for (Descriptor d : descriptors) {
     if (d.getRenderer().getName().equals(renderer.getName())) return true;
   }
   return false;
 }
  /**
   * Parse the given input source and return the dataset.
   *
   * @param source the source input stream. Must not be null.
   * @param progressMonitor the progress monitor. If null, {@see NullProgressMonitor#INSTANCE} is
   *     assumed
   * @return the dataset with the parsed data
   * @throws IllegalDataException thrown if the an error was found while parsing the data from the
   *     source
   * @throws IllegalArgumentException thrown if source is null
   */
  public static DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor)
      throws IllegalDataException {
    ProgressMonitor monitor =
        progressMonitor == null ? NullProgressMonitor.INSTANCE : progressMonitor;
    CheckParameterUtil.ensureParameterNotNull(source, "source");

    PbfReader reader = new PbfReader();

    try {
      monitor.beginTask(tr("Prepare OSM data...", 2));
      monitor.indeterminateSubTask(tr("Reading OSM data..."));

      reader.parse(source);
      monitor.worked(1);

      monitor.indeterminateSubTask(tr("Preparing data set..."));
      reader.prepareDataSet();
      monitor.worked(1);
      return reader.getDataSet();
    } catch (IllegalDataException e) {
      throw e;
    } catch (Exception e) {
      throw new IllegalDataException(e);
    } finally {
      monitor.finishTask();
    }
  }
 /**
  * Constructs a new {@code BoundingBoxDownloader}.
  *
  * @param downloadArea The area to download
  */
 public BoundingBoxDownloader(Bounds downloadArea) {
   CheckParameterUtil.ensureParameterNotNull(downloadArea, "downloadArea");
   this.lat1 = downloadArea.getMinLat();
   this.lon1 = downloadArea.getMinLon();
   this.lat2 = downloadArea.getMaxLat();
   this.lon2 = downloadArea.getMaxLon();
   this.crosses180th = downloadArea.crosses180thMeridian();
 }
 /**
  * Builds the "hull" of primitives to be uploaded given a base collection of osm primitives.
  *
  * @param base the base collection. Must not be null.
  * @return the "hull"
  * @throws IllegalArgumentException thrown if base is null
  */
 public Set<OsmPrimitive> build(Collection<OsmPrimitive> base) throws IllegalArgumentException {
   CheckParameterUtil.ensureParameterNotNull(base, "base");
   hull = new HashSet<OsmPrimitive>();
   for (OsmPrimitive p : base) {
     p.visit(this);
   }
   return hull;
 }
Exemple #15
0
 public BoxTextElemStyle(
     Cascade c,
     TextElement text,
     BoxProvider boxProvider,
     Rectangle box,
     HorizontalTextAlignment hAlign,
     VerticalTextAlignment vAlign) {
   super(c, 5f);
   CheckParameterUtil.ensureParameterNotNull(text);
   CheckParameterUtil.ensureParameterNotNull(hAlign);
   CheckParameterUtil.ensureParameterNotNull(vAlign);
   this.text = text;
   this.boxProvider = boxProvider;
   this.box = box == null ? ZERO_BOX : box;
   this.hAlign = hAlign;
   this.vAlign = vAlign;
 }
Exemple #16
0
 /**
  * Constructor. Deletes a collection of primitives in the current edit layer.
  *
  * @param data the primitives to delete. Must neither be null nor empty.
  * @throws IllegalArgumentException if data is null or empty
  */
 public DeleteCommand(Collection<? extends OsmPrimitive> data) {
   CheckParameterUtil.ensureParameterNotNull(data, "data");
   if (data.isEmpty())
     throw new IllegalArgumentException(
         tr("At least one object to delete required, got empty collection"));
   this.toDelete = data;
   checkConsistency();
 }
 /**
  * Activates a map renderer class.
  *
  * <p>The renderer class must already be registered.
  *
  * @param renderer the map renderer class. Must not be null.
  * @throws IllegalArgumentException if {@code renderer} is null
  * @throws IllegalStateException if {@code renderer} isn't registered yet
  */
 public void activate(Class<? extends AbstractMapRenderer> renderer) {
   CheckParameterUtil.ensureParameterNotNull(renderer);
   if (!isRegistered(renderer))
     throw new IllegalStateException(
         // no I18n required
         MessageFormat.format(
             "Class ''{0}'' not registered as renderer. Can''t activate it.", renderer.getName()));
   this.activeRenderer = renderer;
   Main.pref.put(PREF_KEY_RENDERER_CLASS_NAME, activeRenderer.getName());
 }
 /**
  * Registers a map renderer class.
  *
  * @param renderer the map renderer class. Must not be null.
  * @param displayName the display name to be displayed in UIs (i.e. in the preference dialog)
  * @param description the description
  * @throws IllegalArgumentException if {@code renderer} is null
  * @throws IllegalStateException if {@code renderer} is already registered
  */
 public void register(
     Class<? extends AbstractMapRenderer> renderer, String displayName, String description) {
   CheckParameterUtil.ensureParameterNotNull(renderer);
   if (isRegistered(renderer))
     throw new IllegalStateException(
         // no I18n - this is a technical message
         MessageFormat.format("Class ''{0}'' already registered a renderer", renderer.getName()));
   Descriptor d = new Descriptor(renderer, displayName, description);
   descriptors.add(d);
 }
  /**
   * Wires a {@link JCheckBox} to the adjustment synchronizer, in such a way that:
   *
   * <ol>
   *   <li>state changes in the checkbox control whether the adjustable participates in synchronized
   *       adjustment
   *   <li>state changes in this {@link AdjustmentSynchronizer} are reflected in the {@link
   *       JCheckBox}
   * </ol>
   *
   * @param view the checkbox to control whether an adjustable participates in synchronized
   *     adjustment
   * @param adjustable the adjustable
   * @throws IllegalArgumentException if view is null
   * @throws IllegalArgumentException if adjustable is null
   */
  public void adapt(final JCheckBox view, final Adjustable adjustable) {
    CheckParameterUtil.ensureParameterNotNull(adjustable, "adjustable");
    CheckParameterUtil.ensureParameterNotNull(view, "view");

    if (!synchronizedAdjustables.contains(adjustable)) {
      participateInSynchronizedScrolling(adjustable);
    }

    // register an item lister with the check box
    //
    view.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            switch (e.getStateChange()) {
              case ItemEvent.SELECTED:
                if (!isParticipatingInSynchronizedScrolling(adjustable)) {
                  setParticipatingInSynchronizedScrolling(adjustable, true);
                }
                break;
              case ItemEvent.DESELECTED:
                if (isParticipatingInSynchronizedScrolling(adjustable)) {
                  setParticipatingInSynchronizedScrolling(adjustable, false);
                }
                break;
            }
          }
        });

    observable.addObserver(
        new Observer() {
          @Override
          public void update(Observable o, Object arg) {
            boolean sync = isParticipatingInSynchronizedScrolling(adjustable);
            if (view.isSelected() != sync) {
              view.setSelected(sync);
            }
          }
        });
    setParticipatingInSynchronizedScrolling(adjustable, true);
    view.setSelected(true);
  }
 /**
  * "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;
 }
 /**
  * Populates the turn restriction editor model with a turn restriction. {@code turnRestriction} is
  * an arbitrary relation. A tag type=restriction isn't required. If it is missing, it is added
  * here. {@code turnRestriction} must not be null and it must belong to a dataset.
  *
  * @param turnRestriction the turn restriction
  * @throws IllegalArgumentException thrown if turnRestriction is null
  * @throws IllegalArgumentException thrown if turnRestriction doesn't belong to a dataset
  */
 public void populate(Relation turnRestriction) {
   CheckParameterUtil.ensureParameterNotNull(turnRestriction, "turnRestriction");
   if (turnRestriction.getDataSet() != null && turnRestriction.getDataSet() != layer.data) {
     throw new IllegalArgumentException(
         // don't translate - it's a technical message
         MessageFormat.format(
             "turnRestriction {0} must not belong to a different dataset than the dataset of layer ''{1}''",
             turnRestriction.getId(), layer.getName()));
   }
   initFromTurnRestriction(turnRestriction);
 }
Exemple #22
0
  /**
   * Delete the primitives and everything they reference.
   *
   * <p>If a node is deleted, the node and all ways and relations the node is part of are deleted as
   * well. If a way is deleted, all relations the way is member of are also deleted. If a way is
   * deleted, only the way and no nodes are deleted.
   *
   * @param layer the {@link OsmDataLayer} in whose context primitives are deleted. Must not be
   *     null.
   * @param selection The list of all object to be deleted.
   * @param silent Set to true if the user should not be bugged with additional dialogs
   * @return command A command to perform the deletions, or null of there is nothing to delete.
   * @throws IllegalArgumentException if layer is null
   */
  public static Command deleteWithReferences(
      OsmDataLayer layer, Collection<? extends OsmPrimitive> selection, boolean silent) {
    CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    if (selection == null || selection.isEmpty()) return null;
    Set<OsmPrimitive> parents = OsmPrimitive.getReferrer(selection);
    parents.addAll(selection);

    if (parents.isEmpty()) return null;
    if (!silent && !checkAndConfirmOutlyingDelete(parents, null)) return null;
    return new DeleteCommand(layer, parents);
  }
 /**
  * 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;
   }
 }
Exemple #24
0
 /**
  * Constructs a new {@code HistoryWay} with a given list of node ids.
  *
  * @param id the id (&gt; 0 required)
  * @param version the version (&gt; 0 required)
  * @param visible whether the node is still visible
  * @param user the user (!= null required)
  * @param changesetId the changeset id (&gt; 0 required if {@code checkHistoricParams} is true)
  * @param timestamp the timestamp (!= null required if {@code checkHistoricParams} is true)
  * @param nodeIdList the node ids (!= null required)
  * @throws IllegalArgumentException if preconditions are violated
  */
 public HistoryWay(
     long id,
     long version,
     boolean visible,
     User user,
     long changesetId,
     Date timestamp,
     List<Long> nodeIdList) {
   this(id, version, visible, user, changesetId, timestamp);
   CheckParameterUtil.ensureParameterNotNull(nodeIdList, "nodeIdList");
   this.nodeIds.addAll(nodeIdList);
 }
  /**
   * Sets whether adjustable participates in adjustment synchronization or not
   *
   * @param adjustable the adjustable
   */
  protected void setParticipatingInSynchronizedScrolling(
      Adjustable adjustable, boolean isParticipating) {
    CheckParameterUtil.ensureParameterNotNull(adjustable, "adjustable");
    if (!synchronizedAdjustables.contains(adjustable))
      throw new IllegalStateException(
          tr(
              "Adjustable {0} not registered yet. Cannot set participation in synchronized adjustment.",
              adjustable));

    enabledMap.put(adjustable, isParticipating);
    observable.notifyObservers();
  }
  /**
   * Construct a PreferencePanel for the preference settings. Layout is GridBagLayout and a centered
   * title label and the description are added.
   *
   * @param inScrollPane if <code>true</code> the added tab will show scroll bars if the panel
   *     content is larger than the available space
   * @return The created panel ready to add other controls.
   */
  public PreferencePanel createPreferenceTab(TabPreferenceSetting caller, boolean inScrollPane) {
    CheckParameterUtil.ensureParameterNotNull(caller);
    PreferencePanel p = new PreferencePanel(caller);

    PreferenceTab tab = p;
    if (inScrollPane) {
      PreferenceScrollPane sp = new PreferenceScrollPane(p);
      tab = sp;
    }
    tabs.add(tab);
    return p;
  }
Exemple #27
0
  protected DataSet doParseDataSet(InputStream source, ProgressMonitor progressMonitor)
      throws IllegalDataException {
    if (progressMonitor == null) {
      progressMonitor = NullProgressMonitor.INSTANCE;
    }
    CheckParameterUtil.ensureParameterNotNull(source, "source");
    try {
      progressMonitor.beginTask(tr("Prepare OSM data...", 2));
      progressMonitor.indeterminateSubTask(tr("Parsing OSM data..."));

      InputStreamReader ir = UTFInputStreamReader.create(source, "UTF-8");
      XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(ir);
      setParser(parser);
      parse();
      progressMonitor.worked(1);

      progressMonitor.indeterminateSubTask(tr("Preparing data set..."));
      prepareDataSet();
      progressMonitor.worked(1);

      // iterate over registered postprocessors and give them each a chance
      // to modify the dataset we have just loaded.
      if (postprocessors != null) {
        for (OsmServerReadPostprocessor pp : postprocessors) {
          pp.postprocessDataSet(getDataSet(), progressMonitor);
        }
      }
      return getDataSet();
    } catch (IllegalDataException e) {
      throw e;
    } catch (OsmParsingException e) {
      throw new IllegalDataException(e.getMessage(), e);
    } catch (XMLStreamException e) {
      String msg = e.getMessage();
      Pattern p = Pattern.compile("Message: (.+)");
      Matcher m = p.matcher(msg);
      if (m.find()) {
        msg = m.group(1);
      }
      if (e.getLocation() != null)
        throw new IllegalDataException(
            tr(
                    "Line {0} column {1}: ",
                    e.getLocation().getLineNumber(), e.getLocation().getColumnNumber())
                + msg,
            e);
      else throw new IllegalDataException(msg, e);
    } catch (Exception e) {
      throw new IllegalDataException(e);
    } finally {
      progressMonitor.finishTask();
    }
  }
Exemple #28
0
  /**
   * Initializes the auto completion infrastructure used in this tag editor panel. {@code layer} is
   * the data layer from whose data set tag values are proposed as auto completion items.
   *
   * @param layer the data layer. Must not be null.
   * @throws IllegalArgumentException if {@code layer} is null
   */
  public void initAutoCompletion(OsmDataLayer layer) {
    CheckParameterUtil.ensureParameterNotNull(layer, "layer");

    AutoCompletionManager autocomplete = layer.data.getAutoCompletionManager();
    AutoCompletionList acList = new AutoCompletionList();

    TagCellEditor editor = (TagCellEditor) tagTable.getColumnModel().getColumn(0).getCellEditor();
    editor.setAutoCompletionManager(autocomplete);
    editor.setAutoCompletionList(acList);
    editor = ((TagCellEditor) tagTable.getColumnModel().getColumn(1).getCellEditor());
    editor.setAutoCompletionManager(autocomplete);
    editor.setAutoCompletionList(acList);
  }
 @Override
 public List<Note> parseNotes(int noteLimit, int daysClosed, ProgressMonitor progressMonitor)
     throws OsmTransferException, MoreNotesException {
   progressMonitor.beginTask("Downloading notes");
   CheckParameterUtil.ensureThat(noteLimit > 0, "Requested note limit is less than 1.");
   // see result_limit in
   // https://github.com/openstreetmap/openstreetmap-website/blob/master/app/controllers/notes_controller.rb
   CheckParameterUtil.ensureThat(
       noteLimit <= 10000, "Requested note limit is over API hard limit of 10000.");
   CheckParameterUtil.ensureThat(daysClosed >= -1, "Requested note limit is less than -1.");
   String url =
       "notes?limit="
           + noteLimit
           + "&closed="
           + daysClosed
           + "&bbox="
           + lon1
           + ','
           + lat1
           + ','
           + lon2
           + ','
           + lat2;
   try {
     InputStream is = getInputStream(url, progressMonitor.createSubTaskMonitor(1, false));
     NoteReader reader = new NoteReader(is);
     final List<Note> notes = reader.parse();
     if (notes.size() == noteLimit) {
       throw new MoreNotesException(notes, noteLimit);
     }
     return notes;
   } catch (IOException e) {
     throw new OsmTransferException(e);
   } catch (SAXException e) {
     throw new OsmTransferException(e);
   } finally {
     progressMonitor.finishTask();
   }
 }
 public RelationMemberConflictDecision(Relation relation, int pos) {
   CheckParameterUtil.ensureParameterNotNull(relation, "relation");
   RelationMember member = relation.getMember(pos);
   if (member == null)
     throw new IndexOutOfBoundsException(
         tr(
             "Position {0} is out of range. Current number of members is {1}.",
             pos, relation.getMembersCount()));
   this.relation = relation;
   this.pos = pos;
   this.originalPrimitive = member.getMember();
   this.role = member.hasRole() ? member.getRole() : "";
   this.decision = UNDECIDED;
 }