public void testMaliciousGetIcons() {
    Iterable<WWIcon> icons = createExampleIterable();

    IconLayer layer = new IconLayer();
    layer.addIcons(icons);

    Iterable<WWIcon> layerIcons = layer.getIcons();

    // Test that the returned list cannot be modified.
    try {
      if (layerIcons instanceof java.util.Collection) {
        java.util.Collection<WWIcon> collection = (java.util.Collection<WWIcon>) layerIcons;
        collection.clear();
      } else {
        java.util.Iterator<WWIcon> iter = layerIcons.iterator();
        while (iter.hasNext()) {
          iter.next();
          iter.remove();
        }
      }
    } catch (UnsupportedOperationException e) {
      e.printStackTrace();
    }

    // Test that the layer contents do not change, even if the returned list can be modified.
    assertEquals("", icons, layerIcons);
  }
  /**
   * Generate the positions required to draw the line.
   *
   * @param dc Current draw context.
   * @param positions Positions that define the polygon boundary.
   */
  @Override
  protected void generateIntermediatePositions(
      DrawContext dc, Iterable<? extends Position> positions) {
    Globe globe = dc.getGlobe();

    boolean useDefaultWaveLength = false;
    double waveLength = this.getWaveLength();
    if (waveLength == 0) {
      waveLength = this.computeDefaultWavelength(positions, globe);
      useDefaultWaveLength = true;
    }

    // Generate lines that parallel the control line.
    List<Position> leftPositions = new ArrayList<Position>();
    List<Position> rightPositions = new ArrayList<Position>();
    this.generateParallelLines(
        positions.iterator(), leftPositions, rightPositions, waveLength / 2.0, globe);

    if (useDefaultWaveLength) waveLength = this.computeDefaultWavelength(leftPositions, globe);
    double radius = (waveLength) / 2.0;

    // Generate wavy line to the left of the control line.
    PositionIterator iterator = new PositionIterator(leftPositions, waveLength, globe);
    this.computedPositions =
        this.generateWavePositions(iterator, radius / globe.getRadius(), false);
    this.path.setPositions(this.computedPositions);

    if (useDefaultWaveLength) waveLength = this.computeDefaultWavelength(rightPositions, globe);
    radius = (waveLength) / 2.0;

    // Generate wavy line to the right of the control line.
    iterator = new PositionIterator(rightPositions, waveLength, globe);
    this.path2.setPositions(this.generateWavePositions(iterator, radius / globe.getRadius(), true));
  }
  /**
   * {@inheritDoc}
   *
   * @param positions Control points. This graphic uses only two control point, which determine the
   *     midpoints of two opposite sides of the quad. See Fire Support Area (2.X.4.3.2.1.2) on pg.
   *     652 of MIL-STD-2525C for an example of how these points are interpreted.
   */
  public void setPositions(Iterable<? extends Position> positions) {
    if (positions == null) {
      String message = Logging.getMessage("nullValue.PositionsListIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    Iterator<? extends Position> iterator = positions.iterator();
    try {
      Position pos1 = iterator.next();
      Position pos2 = iterator.next();

      LatLon center = LatLon.interpolateGreatCircle(0.5, pos1, pos2);
      this.quad.setCenter(center);

      Angle heading = LatLon.greatCircleAzimuth(pos2, pos1);
      this.quad.setHeading(heading.subtract(Angle.POS90));

      this.positions = positions;
      this.shapeInvalid = true; // Need to recompute quad size
    } catch (NoSuchElementException e) {
      String message = Logging.getMessage("generic.InsufficientPositions");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }
  }
예제 #4
0
  /**
   * {@inheritDoc}
   *
   * @param positions Control points that orient the graphic. Must provide at least three points.
   */
  public void setPositions(Iterable<? extends Position> positions) {
    if (positions == null) {
      String message = Logging.getMessage("nullValue.PositionsListIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    try {
      Iterator<? extends Position> iterator = positions.iterator();
      this.position1 = iterator.next();
      this.position2 = iterator.next();
      this.position3 = iterator.next();
    } catch (NoSuchElementException e) {
      String message = Logging.getMessage("generic.InsufficientPositions");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    this.paths = null; // Need to recompute path for the new control points
    this.arrowHead1 = null;
    this.arrowHead2 = null;

    if (this.symbol != null) {
      this.symbol.setPosition(this.position1);
    }
  }
예제 #5
0
파일: Dummy.java 프로젝트: ubdsgroup/wglobe
  /**
   * {@inheritDoc}
   *
   * <p>The dummy graphic requires exactly three control points. Any positions beyond the first
   * three will be ignored.
   *
   * @throws IllegalArgumentException if less than three control points are provided.
   */
  public void setPositions(Iterable<? extends Position> positions) {
    if (positions == null) {
      String message = Logging.getMessage("nullValue.PositionsListIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    try {
      Iterator<? extends Position> iterator = positions.iterator();
      Position pt1 = iterator.next();
      Position pt2 = iterator.next();
      Position pt3 = iterator.next();

      this.path.setPositions(Arrays.asList(pt2, pt1, pt3));
    } catch (NoSuchElementException e) {
      String message = Logging.getMessage("generic.InsufficientPositions");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }
  }
  /**
   * {@inheritDoc}
   *
   * @param positions Control points. This graphic uses only one control point, which determines the
   *     center of the circle.
   */
  public void setPositions(Iterable<? extends Position> positions) {
    if (positions == null) {
      String message = Logging.getMessage("nullValue.PositionsListIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    try {
      // Ensure that the iterable provides at least four positions.
      Iterator<? extends Position> iterator = positions.iterator();
      for (int i = 0; i < 3; i++) {
        iterator.next();
      }
    } catch (NoSuchElementException e) {
      String message = Logging.getMessage("generic.InsufficientPositions");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    this.positions = positions;
    this.rings = null;
  }