示例#1
0
文件: Way.java 项目: codesman/josm
  /**
   * Removes the given set of {@link Node nodes} from this way. Ignored, if selection is null.
   *
   * @param selection The selection of nodes to remove. Ignored, if null
   * @since 5408
   */
  public void removeNodes(Set<? extends Node> selection) {
    if (selection == null || isIncomplete()) return;
    boolean locked = writeLock();
    try {
      boolean closed = isClosed() && selection.contains(lastNode());
      List<Node> copy = new ArrayList<>();

      for (Node n : nodes) {
        if (!selection.contains(n)) {
          copy.add(n);
        }
      }

      int i = copy.size();
      if (closed && i > 2) {
        copy.add(copy.get(0));
      } else if (i >= 2 && i <= 3 && copy.get(0) == copy.get(i - 1)) {
        copy.remove(i - 1);
      }
      setNodes(removeDouble(copy));
      for (Node n : selection) {
        n.clearCachedStyle();
      }
    } finally {
      writeUnlock(locked);
    }
  }
示例#2
0
文件: Way.java 项目: codesman/josm
  /**
   * Set new list of nodes to way. This method is preferred to multiple calls to addNode/removeNode
   * and similar methods because nodes are internally saved as array which means lower memory
   * overhead but also slower modifying operations.
   *
   * @param nodes New way nodes. Can be null, in that case all way nodes are removed
   * @since 1862
   */
  public void setNodes(List<Node> nodes) {
    boolean locked = writeLock();
    try {
      for (Node node : this.nodes) {
        node.removeReferrer(this);
        node.clearCachedStyle();
      }

      if (nodes == null) {
        this.nodes = new Node[0];
      } else {
        this.nodes = nodes.toArray(new Node[nodes.size()]);
      }
      for (Node node : this.nodes) {
        node.addReferrer(this);
        node.clearCachedStyle();
      }

      clearCachedStyle();
      fireNodesChanged();
    } finally {
      writeUnlock(locked);
    }
  }
示例#3
0
文件: Way.java 项目: codesman/josm
  /**
   * Adds a node to the end of the list of nodes. Ignored, if n is null.
   *
   * @param n the node. Ignored, if null
   * @throws IllegalStateException if this way is marked as incomplete. We can't add a node to an
   *     incomplete way
   * @since 1313
   */
  public void addNode(Node n) {
    if (n == null) return;

    boolean locked = writeLock();
    try {
      if (isIncomplete())
        throw new IllegalStateException(
            tr("Cannot add node {0} to incomplete way {1}.", n.getId(), getId()));
      clearCachedStyle();
      n.addReferrer(this);
      nodes = Utils.addInArrayCopy(nodes, n);
      n.clearCachedStyle();
      fireNodesChanged();
    } finally {
      writeUnlock(locked);
    }
  }
示例#4
0
文件: Way.java 项目: codesman/josm
 @Override
 public void setDeleted(boolean deleted) {
   boolean locked = writeLock();
   try {
     for (Node n : nodes) {
       if (deleted) {
         n.removeReferrer(this);
       } else {
         n.addReferrer(this);
       }
       n.clearCachedStyle();
     }
     fireNodesChanged();
     super.setDeleted(deleted);
   } finally {
     writeUnlock(locked);
   }
 }
示例#5
0
文件: Way.java 项目: codesman/josm
  /**
   * Adds a node at position offs.
   *
   * @param offs the offset
   * @param n the node. Ignored, if null.
   * @throws IllegalStateException if this way is marked as incomplete. We can't add a node to an
   *     incomplete way
   * @throws IndexOutOfBoundsException if offs is out of bounds
   * @since 1313
   */
  public void addNode(int offs, Node n) throws IndexOutOfBoundsException {
    if (n == null) return;

    boolean locked = writeLock();
    try {
      if (isIncomplete())
        throw new IllegalStateException(
            tr("Cannot add node {0} to incomplete way {1}.", n.getId(), getId()));

      clearCachedStyle();
      n.addReferrer(this);
      Node[] newNodes = new Node[nodes.length + 1];
      System.arraycopy(nodes, 0, newNodes, 0, offs);
      System.arraycopy(nodes, offs, newNodes, offs + 1, nodes.length - offs);
      newNodes[offs] = n;
      nodes = newNodes;
      n.clearCachedStyle();
      fireNodesChanged();
    } finally {
      writeUnlock(locked);
    }
  }
示例#6
0
文件: Way.java 项目: codesman/josm
 /**
  * Removes the given {@link Node} from this way. Ignored, if n is null.
  *
  * @param n The node to remove. Ignored, if null
  * @since 1463
  */
 public void removeNode(Node n) {
   if (n == null || isIncomplete()) return;
   boolean locked = writeLock();
   try {
     boolean closed = lastNode() == n && firstNode() == n;
     int i;
     List<Node> copy = getNodes();
     while ((i = copy.indexOf(n)) >= 0) {
       copy.remove(i);
     }
     i = copy.size();
     if (closed && i > 2) {
       copy.add(copy.get(0));
     } else if (i >= 2 && i <= 3 && copy.get(0) == copy.get(i - 1)) {
       copy.remove(i - 1);
     }
     setNodes(removeDouble(copy));
     n.clearCachedStyle();
   } finally {
     writeUnlock(locked);
   }
 }
示例#7
0
文件: Way.java 项目: codesman/josm
 public void clearCachedNodeStyles() {
   for (final Node n : nodes) {
     n.clearCachedStyle();
   }
 }