Esempio n. 1
0
    @Override
    void nakresli() {
      vystreduj();

      // Area a1 = new Area([triangle 0,0 => 8,0 => 0,8]);
      // Area a2 = new Area([triangle 0,0 => 8,0 => 8,8]);
      // a1.add(a2);
      final Area poly =
          new Area(new Polygon(new int[] {0, 1, 1, 5, 0}, new int[] {0, 1, 7, 7, 12}, 5));
      final Area a = new Area();

      final AffineTransform rotace = new AffineTransform();
      rotace.rotate(Math.PI / 2);
      final AffineTransform zrcadlo = new AffineTransform();
      zrcadlo.scale(1, -1);
      for (int i = 0; i < 4; i++) {
        a.transform(zrcadlo);
        a.add(poly);
        a.transform(zrcadlo);
        a.add(poly);
        a.transform(rotace);
      }
      g.setColor(Color.GREEN);
      g.fill(a);
      g.setColor(Color.BLACK);
      g.draw(a);
    }
  @Override
  public void paint(Graphics g) {
    Area a = new Area();
    Shape orejad = new Ellipse2D.Double(450, 100, 300, 300);
    Shape orejai = new Ellipse2D.Double(950, 100, 300, 300);
    a.add(new Area(orejai));
    a.add(new Area(orejad));
    Shape cabeza = new Ellipse2D.Double(600, 200, 500, 500);
    a.add(new Area(cabeza));

    Shape ojoi = new Ellipse2D.Double(675, 300, 100, 100);
    a.subtract(new Area(ojoi));

    Shape ojod = new Ellipse2D.Double(925, 300, 100, 100);
    a.subtract(new Area(ojod));

    Shape clip4 = new Ellipse2D.Double(0, 0, 400, 200);
    // super.paint(g);
    Area b = new Area(new Rectangle2D.Double(0, 0, 4000, 4000));
    b.subtract(a);
    g.setClip(b);
    g.setColor(c);
    g.fillRect((int) x, (int) y, (int) (Math.random() * 200), (int) (Math.random() * 200));
    g.fillRect((int) x + 9, (int) y + 9, (int) (Math.random() * 200), (int) (Math.random() * 200));
    g.fillRect(
        (int) x + 18, (int) y + 18, (int) (Math.random() * 200), (int) (Math.random() * 200));
    g.fillRect(
        (int) x + 27, (int) y + 27, (int) (Math.random() * 200), (int) (Math.random() * 200));
    g.setClip(a);
    g.setColor(new Color(255, 123, 0, 5));
    g.fillRect(
        (int) x + 27, (int) y + 27, (int) (Math.random() * 200), (int) (Math.random() * 200));
    x = x + vx;
    y = y + vy;
    if (x < 0) {
      vx = 5.6689f;
      // setBackground(getColorRandom());
      c = getColorRandom();
    }
    if (y < 0) {
      vy = 0.5f;
      // setBackground(getColorRandom());
      c = getColorRandom();
    }
    if (x > 1900) {
      vx = -5.6689f;
      // setBackground(getColorRandom());
      c = getColorRandom();
    }
    if (y > 900) {
      vy = -0.5f;
      // setBackground(getColorRandom());
      c = getColorRandom();
    }

    repaint();
  }
 public void paint(Graphics g) {
   Graphics2D g_2d = (Graphics2D) g;
   Ellipse2D ellipse = new Ellipse2D.Double(0, 2, 80, 80);
   Rectangle2D rect = new Rectangle2D.Double(40, 2, 80, 80);
   Area a1 = new Area(ellipse);
   Area a2 = new Area(rect);
   a1.intersect(a2); // "Óë"
   g_2d.fill(a1);
   ellipse.setFrame(130, 2, 80, 80);
   rect.setFrame(170, 2, 80, 80);
   a1 = new Area(ellipse);
   a2 = new Area(rect);
   a1.add(a2); // "»ò"
   g_2d.draw(a1);
   ellipse.setFrame(0, 90, 80, 80);
   rect.setFrame(40, 90, 80, 80);
   a1 = new Area(ellipse);
   a2 = new Area(rect);
   a1.subtract(a2); // "²î"
   g_2d.draw(a1);
   ellipse.setFrame(130, 90, 80, 80);
   rect.setFrame(170, 90, 80, 80);
   a1 = new Area(ellipse);
   a2 = new Area(rect);
   a1.exclusiveOr(a2); // "Òì»ò"
   g_2d.fill(a1);
 }
Esempio n. 4
0
  /**
   * Draws the needle.
   *
   * @param g2 the graphics device.
   * @param plotArea the plot area.
   * @param rotate the rotation point.
   * @param angle the angle.
   */
  @Override
  protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) {

    Area shape;
    GeneralPath pointer = new GeneralPath();

    int minY = (int) (plotArea.getMinY());
    // int maxX = (int) (plotArea.getMaxX());
    int maxY = (int) (plotArea.getMaxY());
    int midX = (int) (plotArea.getMinX() + (plotArea.getWidth() / 2));
    // int midY = (int) (plotArea.getMinY() + (plotArea.getHeight() / 2));
    int lenX = (int) (plotArea.getWidth() / 10);
    if (lenX < 2) {
      lenX = 2;
    }

    pointer.moveTo(midX - lenX, maxY - lenX);
    pointer.lineTo(midX + lenX, maxY - lenX);
    pointer.lineTo(midX, minY + lenX);
    pointer.closePath();

    lenX = 4 * lenX;
    Ellipse2D circle = new Ellipse2D.Double(midX - lenX / 2, plotArea.getMaxY() - lenX, lenX, lenX);

    shape = new Area(circle);
    shape.add(new Area(pointer));
    if ((rotate != null) && (angle != 0)) {
      /// we have rotation
      getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
      shape.transform(getTransform());
    }

    defaultDisplay(g2, shape);
  }
Esempio n. 5
0
 /**
  * Returns the currently-defined blob.
  *
  * @return shape drawn
  */
 public Shape getBlob() {
   Area area = new Area();
   for (Iterator it = blobs_.iterator(); it.hasNext(); ) {
     area.add(new Area((Shape) it.next()));
   }
   return simplify(area);
 }
  /**
   * Gets the shape of this footprint.
   *
   * @param points an array of Points
   * @return the shape
   */
  public Shape getShape(Point[] points) {
    Point p1 = points[0];
    Point p2 = points[1];

    // set up end shapes
    transform.setToTranslation(p1.x, p1.y);
    int scale = FontSizer.getIntegerFactor();
    if (scale > 1) {
      transform.scale(scale, scale);
    }
    Shape target1 = transform.createTransformedShape(targetShape);
    hitShapes[0] = transform.createTransformedShape(hitShape); // end1
    transform.setToTranslation(p2.x, p2.y);
    if (scale > 1) {
      transform.scale(scale, scale);
    }
    Shape target2 = transform.createTransformedShape(targetShape);
    hitShapes[1] = transform.createTransformedShape(hitShape); // end2

    // set up line shapes
    float d = (float) p1.distance(p2); // distance between ends
    float center = d / 2; // center point
    float l = d - scale * 2 * (size + 3); // line length
    float f = 0.45f; // hit shape is 90% of line length
    path.reset();
    path.moveTo(center - f * l, 0);
    path.lineTo(center + f * l, 0);
    double theta = Math.atan2(p1.y - p2.y, p1.x - p2.x);
    transform.setToRotation(theta, p2.x, p2.y);
    transform.translate(p2.x, p2.y);
    hitShapes[2] = transform.createTransformedShape(path); // line
    path.reset();
    path.moveTo(center - l / 2, 0);
    path.lineTo(center + l / 2, 0);
    Shape line = transform.createTransformedShape(path);

    // set up drawing area
    if (stroke == null || stroke.getLineWidth() != scale * baseStroke.getLineWidth()) {
      stroke = new BasicStroke(scale * baseStroke.getLineWidth());
    }
    Area area = new Area(stroke.createStrokedShape(target1));
    area.add(new Area(stroke.createStrokedShape(target2)));
    area.add(new Area(stroke.createStrokedShape(line)));
    return area;
  }
Esempio n. 7
0
  protected void paintComponent(Graphics g) {
    Color oldColor = g.getColor();
    Graphics2D g2 = (Graphics2D) g;

    Area area = new Area();
    for (Iterator it = blobs_.iterator(); it.hasNext(); ) {
      area.add(new Area((Shape) it.next()));
    }
    if (dragPath_ != null) {
      area.add(new Area(dragPath_));
      g2.setColor(pathColor_);
      g2.draw(dragPath_);
    }
    g2.setColor(fillColor_);
    g2.fill(area);

    g.setColor(oldColor);
  }
 private static Area makeBar() {
   int barThickness = 20;
   Rectangle2D.Double body = new Rectangle2D.Double(6, 0, 30, barThickness);
   Ellipse2D.Double head = new Ellipse2D.Double(0, 0, barThickness, barThickness);
   Ellipse2D.Double tail = new Ellipse2D.Double(30, 0, barThickness, barThickness);
   Area tick = new Area(body);
   tick.add(new Area(head));
   tick.add(new Area(tail));
   return tick;
 }
  /** Builds a bar. */
  private Area buildPrimitive() {
    Rectangle2D.Double body = new Rectangle2D.Double(6 / 7, 0, 30 / 7, 12 / 7);
    Ellipse2D.Double head = new Ellipse2D.Double(0, 0, 12 / 7, 12 / 7);
    Ellipse2D.Double tail = new Ellipse2D.Double(30 / 7, 0, 12 / 7, 12 / 7);

    Area tick = new Area(body);
    tick.add(new Area(head));
    tick.add(new Area(tail));

    return tick;
  }
Esempio n. 10
0
    public void actionPerformed(ActionEvent ae) {
      Area area = null;
      List<Attribute> attrs = new ArrayList<Attribute>();
      boolean fill = false;
      for (Vector v : shapes) {
        Primitive vv = v;
        while (vv instanceof Proxy && !(vv instanceof PaintedPrimitive)) {
          vv = ((Proxy) vv).getProxiedPrimitive();
        }
        if (vv instanceof PaintedPrimitive) {
          PaintedPrimitive pp = (PaintedPrimitive) vv;
          List<Attribute> atts = pp.allAttributes();
          System.err.println("  include attributes " + atts);
          attrs.addAll(pp.allAttributes());
        }
        fill |= v instanceof Fillable && ((Fillable) v).isFill();
        if (area == null) {
          area = new Area(v.toShape());
        } else {
          Area other = new Area(v.toShape());
          switch (kind) {
            case UNION:
              area.add(other);
              break;
            case INTERSECTION:
              area.intersect(other);
              break;
            case SUBTRACTION:
              area.subtract(other);
              break;
            case XOR:
              area.exclusiveOr(other);
              break;
            default:
              throw new AssertionError();
          }
        }
      }
      if (area != null) {
        PathIteratorWrapper wrap =
            new PathIteratorWrapper(
                area.getPathIterator(AffineTransform.getTranslateInstance(0, 0)), fill);
        // XXX probably don't want all attributes, they may be
        // redundant
        PaintedPrimitive pp = PaintedPrimitive.create(wrap, attrs);

        stack.replace(shapes, pp);
        if (repainter != null) {
          repainter.requestRepaint();
          ;
        }
      }
    }
    public void paintBorder(final Graphics g, final int x, final int y, final int w, final int h) {
      ((Graphics2D) g)
          .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

      g.setColor(focusColor);
      rect.setRoundRect(x + 0.6, y + 0.6, w - 1.2, h - 1.2, outsideRadius, outsideRadius);
      area.reset();
      area.add(new Area(rect));
      rect.setRoundRect(x + 2, y + 2, w - 4, h - 4, insideRadius, insideRadius);
      area.subtract(new Area(rect));
      ((Graphics2D) g).fill(area);
    }
Esempio n. 12
0
  private void processSource(Product sourceProduct, SpatialBinner spatialBinner)
      throws IOException {
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    updateDateRangeUtc(sourceProduct);
    metadataAggregator.aggregateMetadata(sourceProduct);

    final String productName = sourceProduct.getName();
    getLogger().info(String.format("Spatial binning of product '%s'...", productName));
    getLogger().fine(String.format("Product start time: '%s'", sourceProduct.getStartTime()));
    getLogger().fine(String.format("Product end time:   '%s'", sourceProduct.getEndTime()));
    if (region != null) {
      SubsetOp subsetOp = new SubsetOp();
      subsetOp.setSourceProduct(sourceProduct);
      subsetOp.setGeoRegion(region);
      sourceProduct = subsetOp.getTargetProduct();
      // TODO mz/nf/mp 2013-11-06: avoid creation of subset products
      //  - replace subset with rectangle as parameter to SpatialProductBinner
      //  - grow rectangle by binSize in pixel units (see lc-tools of LC-CCI project)
    }
    final long numObs =
        SpatialProductBinner.processProduct(
            sourceProduct, spatialBinner, addedVariableBands, ProgressMonitor.NULL);
    stopWatch.stop();

    getLogger()
        .info(
            String.format(
                "Spatial binning of product '%s' done, %d observations seen, took %s",
                productName, numObs, stopWatch));

    if (region == null && regionArea != null) {
      for (GeneralPath generalPath : ProductUtils.createGeoBoundaryPaths(sourceProduct)) {
        try {
          Area area = new Area(generalPath);
          regionArea.add(area);
        } catch (Throwable e) {
          getLogger()
              .log(
                  Level.SEVERE,
                  String.format("Failed to handle product boundary: %s", e.getMessage()),
                  e);
          // sometimes the Area constructor throw an "java.lang.InternalError: Odd number of new
          // curves!"
          // then just ignore this geometry
        }
      }
    }

    ++numProductsAggregated;
  }
Esempio n. 13
0
  /** {@inheritDoc} */
  @Override
  public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHints(GraphicsUtil.ANTIALIAS_HINT);

    // Define the content rectangle
    int x0 = pointerLeft ? pad + pointerWidth : pad;
    RoundRectangle2D.Double content =
        new RoundRectangle2D.Double(
            x0, pad, width - 2 * pad - pointerWidth, height - 2 * pad, cornerRadius, cornerRadius);

    // Define the pointer triangle
    int xp = pointerLeft ? pad + pointerWidth : width - pad - pointerWidth;
    int yp = pad + height - pointerFromBottom;
    Polygon pointer = new Polygon();
    pointer.addPoint(xp, yp);
    pointer.addPoint(xp, yp - pointerHeight);
    pointer.addPoint(xp + pointerWidth * (pointerLeft ? -1 : 1), yp - pointerHeight / 2);

    // Combine content rectangle and pointer into one area
    Area area = new Area(content);
    area.add(new Area(pointer));

    // Fill the pop-up background
    Color col = pointerLeft ? c.getBackground().darker() : c.getBackground().brighter();
    g2.setColor(col);
    g2.fill(area);

    if (message.getSeverity() == MaritimeTextingNotificationSeverity.WARNING
        || message.getSeverity() == MaritimeTextingNotificationSeverity.ALERT
        || message.getSeverity() == MaritimeTextingNotificationSeverity.SAFETY) {
      g2.setStroke(new BasicStroke(2.0f));

      switch (message.getSeverity()) {
        case WARNING:
          g2.setColor(WARN_COLOR);
        case ALERT:
          g2.setColor(ALERT_COLOR);
        case SAFETY:
          g2.setColor(SAFETY_COLOR);
        default:
          g2.setColor(WARN_COLOR);
      }

      // g2.setColor(message.getSeverity() == MaritimeTextingNotificationSeverity.WARNING ?
      // WARN_COLOR : ALERT_COLOR);

      g2.draw(area);
    }
  }
Esempio n. 14
0
 // Morteza2011*****************************************************************
 public static SOSArea reMerge(SOSArea blockade1, SOSArea blockade2) {
   java.awt.geom.Area a1 = new Area(blockade1.getShape());
   java.awt.geom.Area a2 = new Area(blockade2.getShape());
   a1.add(a2);
   int[] apexes = AliGeometryTools.getApexes(a1);
   ArrayList<Edge> edges = new ArrayList<Edge>();
   for (int i = 0; i < apexes.length / 2 - 1; i++) {
     edges.add(new Edge(apexes[i * 2], apexes[i * 2 + 1], apexes[i * 2 + 2], apexes[i * 2 + 3]));
   }
   SOSArea finalArea = new SOSArea(edges);
   finalArea.addReachablityBlockades(blockade1.getReachablityBlockades());
   finalArea.addReachablityBlockades(blockade2.getReachablityBlockades());
   return finalArea;
 }
Esempio n. 15
0
 @Override
 public synchronized Area getAreaAt(final Layer layer) {
   final Area a = new Area();
   for (final Item item : al_items) {
     for (int i = 0; i < item.n_points; i++) {
       if (item.p_layer[i] != layer.getId()) continue;
       a.add(
           new Area(
               new Rectangle2D.Float(
                   (float) (item.p[0][i] - item.radius),
                   (float) (item.p[1][i] - item.radius),
                   item.radius,
                   item.radius)));
     }
   }
   a.transform(this.at);
   return a;
 }
Esempio n. 16
0
 public Shape createStrokedShape(Shape shape) {
   Area area1 = new Area(stroke1.createStrokedShape(shape));
   Area area2 = new Area(stroke2.createStrokedShape(shape));
   switch (operation) {
     case ADD:
       area1.add(area2);
       break;
     case SUBSTRACT:
       area1.subtract(area2);
       break;
     case INTERSECT:
       area1.intersect(area2);
       break;
     case DIFFERENCE:
       area1.exclusiveOr(area2);
       break;
   }
   return area1;
 }
 /**
  * Gets the icon.
  *
  * @param w width of the icon
  * @param h height of the icon
  * @return the icon
  */
 public Icon getIcon(int w, int h) {
   int scale = FontSizer.getIntegerFactor();
   w *= scale;
   h *= scale;
   if (stroke == null || stroke.getLineWidth() != scale * baseStroke.getLineWidth()) {
     stroke = new BasicStroke(scale * baseStroke.getLineWidth());
   }
   transform.setToScale(scale, scale);
   Shape target = stroke.createStrokedShape(transform.createTransformedShape(targetShape));
   Area area = new Area(target);
   double x0 = scale * (size + 2) - w;
   double y0 = h - scale * (size + 2);
   double d = Math.sqrt(x0 * x0 + y0 * y0);
   double x1 = x0 * scale * size / d;
   double y1 = y0 * scale * size / d;
   Line2D line = new Line2D.Double(x0, y0, x1, y1);
   area.add(new Area(stroke.createStrokedShape(line)));
   ShapeIcon icon = new ShapeIcon(area, w, h);
   icon.setColor(color);
   return icon;
 }
Esempio n. 18
0
  private void calculateShape() {
    float t = 360 / blades;
    float a = angle;
    a = a > 360 ? a - 360 : a;
    fan = new Area();
    for (int i = 0; i < blades; i++) {
      Shape b = new Area(blade);
      Rectangle2D bounds = b.getBounds2D();
      b =
          AffineTransform.getTranslateInstance(
                  cx - bounds.getX() - bounds.getWidth() / 2, cy - bounds.getY())
              .createTransformedShape(b);
      bounds = b.getBounds2D();
      float bcx = (float) ((bounds.getWidth() * bladeCx) + bounds.getX());
      b = ShapeUtils.rotate(b, a, bcx, cy);
      ((Area) fan).add(new Area(b));

      a += t;
      a = a > 360 ? a - 360 : a;
    }
  }
Esempio n. 19
0
 public Pillar(Rectangle rect, int xOffset, int yOffset, Color color) {
   F = rect;
   B = color;
   C = new Color(color.getRed(), color.getGreen(), color.getBlue(), 100);
   G = color.darker();
   GeneralPath path = new GeneralPath();
   path.moveTo(rect.x, rect.y);
   path.lineTo(rect.x + rect.width, rect.y);
   path.lineTo(rect.x + rect.width + xOffset, rect.y - yOffset);
   path.lineTo(rect.x + xOffset, rect.y - yOffset);
   path.closePath();
   A = path;
   path = new GeneralPath();
   path.moveTo(rect.x + rect.width, rect.y);
   path.lineTo(rect.x + rect.width + xOffset, rect.y - yOffset);
   path.lineTo(rect.x + rect.width + xOffset, (rect.y - yOffset) + rect.height);
   path.lineTo(rect.x + rect.width, rect.y + rect.height);
   path.closePath();
   E = path;
   D = new Area(rect);
   D.add(new Area(A));
   D.add(new Area(E));
 }
Esempio n. 20
0
 /** @param region region (i.e., area contained in vertices) to add to country */
 public final void addRegion(GeographicArea region) {
   regions.add(region);
   area.add(new Area(converter.regionToPolygon(region)));
 }
  /**
   * Creates a continuous legend item for one item in dimensionSet, i.e. dimensionSet must be a set
   * containing exactly one value.
   *
   * @param dateFormat format used to format minValue and maxValue as dates, or null if they should
   *     be displayed numerically instead of as dates
   * @throws ChartPlottimeException
   */
  private LegendItem createContinuousLegendItem(
      PlotInstance plotInstance,
      Set<PlotDimension> dimensionSet,
      double minValue,
      double maxValue,
      DateFormat dateFormat) {
    PlotConfiguration plotConfiguration = plotInstance.getCurrentPlotConfigurationClone();
    PlotDimension dimension = dimensionSet.iterator().next();
    DefaultDimensionConfig dimensionConfig =
        (DefaultDimensionConfig) plotConfiguration.getDimensionConfig(dimension);
    DimensionConfigData dimensionConfigData =
        plotInstance.getPlotData().getDimensionConfigData(dimensionConfig);
    // String label = dimensionConfig.getLabel();
    // if(label == null) {
    // label = I18N.getGUILabel("plotter.unnamed_value_label");
    // }
    String label = "";

    if (dimension == PlotDimension.COLOR) {
      ColorProvider colorProvider = dimensionConfigData.getColorProvider();
      if (!colorProvider.supportsNumericalValues()) {
        throw new RuntimeException(
            "Color provider for continuous legend item does not support numerical values.");
      }

      // shape dimensions
      final int width = 50;
      final int height = 10;

      // create item paint

      // first disable logarithmic scale on color provider ( -> linear gradient in legend)
      // ContinuousColorProvider continuousColorProvider = null;
      // if (dimensionConfig.isLogarithmic() && colorProvider instanceof
      // ContinuousColorProvider) {
      // continuousColorProvider = (ContinuousColorProvider)colorProvider;
      // continuousColorProvider.setLogarithmic(false);
      // }

      // calculate gradient
      float fractions[] = new float[width];
      Color colors[] = new Color[width];
      for (int i = 0; i < width; ++i) {

        float fraction = i / (width - 1.0f);
        double fractionValue;
        if (colorProvider instanceof ContinuousColorProvider
            && ((ContinuousColorProvider) colorProvider)
                .isColorMinMaxValueDifferentFromOriginal(
                    ((ContinuousColorProvider) colorProvider).getMinValue(),
                    ((ContinuousColorProvider) colorProvider).getMaxValue())) {
          fractionValue =
              ((ContinuousColorProvider) colorProvider).getMinValue()
                  + fraction
                      * (((ContinuousColorProvider) colorProvider).getMaxValue()
                          - ((ContinuousColorProvider) colorProvider).getMinValue());
        } else {
          fractionValue = minValue + fraction * (maxValue - minValue);
        }
        colors[i] = colorProvider.getColorForValue(fractionValue);
        fractions[i] = fraction;
      }
      LinearGradientPaint shapeFillPaint =
          new LinearGradientPaint(
              new Point(0, 0), new Point(width, 0), fractions, colors, CycleMethod.REPEAT);

      // reset color provider to logarithmic if necessary
      // if (continuousColorProvider != null && dimensionConfig.isLogarithmic()) {
      // continuousColorProvider.setLogarithmic(true);
      // }

      // create item shape
      Rectangle itemShape = new Rectangle(width, height);

      if (colorProvider instanceof ContinuousColorProvider) {
        return createFlankedShapeLegendItem(
            label,
            ((ContinuousColorProvider) colorProvider).getMinValue(),
            ((ContinuousColorProvider) colorProvider).getMaxValue(),
            itemShape,
            shapeFillPaint,
            true,
            dateFormat);
      } else {
        return createFlankedShapeLegendItem(
            label, minValue, maxValue, itemShape, shapeFillPaint, true, dateFormat);
      }
    } else if (dimension == PlotDimension.SHAPE) {
      // shape provider probably never supports numerical values
      return null;
    } else if (dimension == PlotDimension.SIZE) {
      SizeProvider sizeProvider = dimensionConfigData.getSizeProvider();

      if (!sizeProvider.supportsNumericalValues()) {
        throw new RuntimeException(
            "Size provider for continuous legend item does not support numerical values.");
      }

      double minScalingFactor = sizeProvider.getMinScalingFactor();
      double maxScalingFactor = sizeProvider.getMaxScalingFactor();
      ContinuousSizeProvider legendSizeProvider =
          new ContinuousSizeProvider(
              minScalingFactor,
              maxScalingFactor,
              MIN_LEGEND_ITEM_SCALING_FACTOR,
              MAX_LEGEND_ITEM_SCALING_FACTOR,
              false);

      int legendItemCount = 4;
      Area composedShape = new Area();
      Shape originalShape = UNDEFINED_SHAPE;
      if (dimensionSet.contains(PlotDimension.SIZE) && dimensionSet.size() == 1) {
        originalShape = UNDEFINED_SHAPE_AND_COLOR;
      }
      double maxHeight = originalShape.getBounds().getHeight() * MAX_LEGEND_ITEM_SCALING_FACTOR;
      for (int i = 0; i < legendItemCount; ++i) {
        double fraction =
            minScalingFactor
                + ((double) i / legendItemCount * (maxScalingFactor - minScalingFactor));
        double legendScalingFactor = legendSizeProvider.getScalingFactorForValue(fraction);

        double composedWidth = composedShape.getBounds().getWidth();

        AffineTransform t = new AffineTransform();
        t.scale(legendScalingFactor, legendScalingFactor);
        Shape shape = t.createTransformedShape(originalShape);

        t = new AffineTransform();
        double shapeWidth = shape.getBounds().getWidth();
        double shapeHeight = shape.getBounds().getHeight();
        t.translate(composedWidth + shapeWidth * .1, (maxHeight - shapeHeight) / 2.0);
        t.translate(-shape.getBounds().getMinX(), -shape.getBounds().getMinY());
        shape = t.createTransformedShape(shape);
        composedShape.add(new Area(shape));
      }

      return createFlankedShapeLegendItem(
          label, minValue, maxValue, composedShape, UNDEFINED_COLOR_PAINT, false, dateFormat);

    } else {
      throw new RuntimeException(
          "Unsupported dimension. Execution path should never reach this line.");
    }
  }
Esempio n. 22
0
  /**
   * Builds an Area configured with the polygon information defined in the file.
   *
   * @return A fully configured area.
   */
  public Area loadPolygon() {
    try {
      Area resultArea;
      BufferedReader bufferedReader;
      // Create a new area.
      resultArea = new Area();

      // Open the polygon file.
      bufferedReader = new BufferedReader(fileReader);

      // Read the file header.
      myPolygonName = bufferedReader.readLine();
      if (myPolygonName == null || myPolygonName.trim().length() == 0) {
        throw new OsmosisRuntimeException(
            "The file must begin with a header naming the polygon file.");
      }

      // We now loop until no more sections are available.
      while (true) {
        String sectionHeader;
        boolean positivePolygon;
        Area sectionArea;

        // Read until a non-empty line is obtained.
        do {
          // Read the section header.
          sectionHeader = bufferedReader.readLine();

          // It is invalid for the file to end without a global "END" record.
          if (sectionHeader == null) {
            throw new OsmosisRuntimeException(
                "File terminated prematurely without a section END record.");
          }

          // Remove any whitespace.
          sectionHeader = sectionHeader.trim();

        } while (sectionHeader.length() == 0);

        // Stop reading when the global END record is reached.
        if ("END".equals(sectionHeader)) {
          break;
        }

        // If the section header begins with a ! then the polygon is to
        // be subtracted from the result area.
        positivePolygon = (sectionHeader.charAt(0) != '!');

        // Create an area for this polygon.
        sectionArea = loadSectionPolygon(bufferedReader);

        // Add or subtract the section area from the overall area as
        // appropriate.
        if (positivePolygon) {
          resultArea.add(sectionArea);
        } else {
          resultArea.subtract(sectionArea);
        }
      }

      return resultArea;

    } catch (IOException e) {
      throw new OsmosisRuntimeException("Unable to read from polygon file " + polygonFile + ".", e);
    } finally {
      cleanup();
    }
  }
  public Area getBody() {
    if (body == null) {
      int x = (controlPoints[0].x + controlPoints[1].x + controlPoints[2].x) / 3;
      int y = (controlPoints[0].y + controlPoints[1].y + controlPoints[2].y) / 3;
      int bodyDiameter = getClosestOdd(BODY_DIAMETER.convertToPixels());
      int bodyLength = getClosestOdd(BODY_LENGTH.convertToPixels());
      int edgeRadius = (int) EDGE_RADIUS.convertToPixels();

      if (folded) {
        switch (orientation) {
          case DEFAULT:
            body =
                new Area(
                    new RoundRectangle2D.Double(
                        x - bodyLength,
                        y - bodyDiameter / 2,
                        bodyLength,
                        bodyDiameter,
                        edgeRadius,
                        edgeRadius));
            body.add(
                new Area(
                    new Rectangle2D.Double(
                        x - bodyLength / 2, y - bodyDiameter / 2, bodyLength / 2, bodyDiameter)));
            break;
          case _90:
            body =
                new Area(
                    new RoundRectangle2D.Double(
                        x - bodyDiameter / 2,
                        y - bodyLength,
                        bodyDiameter,
                        bodyLength,
                        edgeRadius,
                        edgeRadius));
            body.add(
                new Area(
                    new Rectangle2D.Double(
                        x - bodyDiameter / 2, y - bodyLength / 2, bodyDiameter, bodyLength / 2)));
            break;
          case _180:
            body =
                new Area(
                    new RoundRectangle2D.Double(
                        x, y - bodyDiameter / 2, bodyLength, bodyDiameter, edgeRadius, edgeRadius));
            body.add(
                new Area(
                    new Rectangle2D.Double(x, y - bodyDiameter / 2, bodyLength / 2, bodyDiameter)));
            break;
          case _270:
            body =
                new Area(
                    new RoundRectangle2D.Double(
                        x - bodyDiameter / 2, y, bodyDiameter, bodyLength, edgeRadius, edgeRadius));
            body.add(
                new Area(
                    new Rectangle2D.Double(x - bodyDiameter / 2, y, bodyDiameter, bodyLength / 2)));
            break;
          default:
            throw new RuntimeException("Unexpected orientation: " + orientation);
        }
      } else {
        body =
            new Area(
                new Ellipse2D.Double(
                    x - bodyDiameter / 2, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
      }
    }
    return body;
  }
Esempio n. 24
0
  protected final void compute() {

    ArrayList<Double> xcoord = new ArrayList<Double>();
    ArrayList<Double> ycoord = new ArrayList<Double>();
    double[] coords = new double[6];
    double[] oldCoords = new double[6];

    // Convert input polygons to Area objects
    Area a1 = getArea(inPoly0.getPoints());
    Area a2 = getArea(inPoly1.getPoints());

    // test for empty intersection
    Area testArea = getArea(inPoly0.getPoints());
    testArea.intersect(a2);
    if (testArea.isEmpty()) {
      poly.setUndefined();
    }
    // if intersection is non-empty perform operation
    else {
      switch (operationType) {
        case TYPE_INTERSECTION:
          a1.intersect(a2);
          break;
        case TYPE_UNION:
          a1.add(a2);
          break;
        case TYPE_DIFFERENCE:
          a1.subtract(a2);
          break;
      }

      // Iterate through the path of the result
      // and recover the polygon vertices.

      PathIterator it = a1.getPathIterator(null);

      int type = it.currentSegment(coords);
      it.next();
      oldCoords = coords.clone();
      double epsilon = 1E-10;

      while (!it.isDone()) {
        type = it.currentSegment(coords);
        if (type == PathIterator.SEG_CLOSE) {
          break;
        }
        // Sometimes the Path iterator gives two almost identical points and
        // we only want one of them.
        // TODO: Why does this happen???
        if ((double) Math.abs(oldCoords[0] - coords[0]) > epsilon
            || (double) Math.abs(oldCoords[1] - coords[1]) > epsilon) {
          xcoord.add(coords[0]);
          ycoord.add(coords[1]);
        }
        oldCoords = coords.clone();

        it.next();
      }
    }

    // Update the points array to the correct size
    int n = xcoord.size();
    // System.out.println("number of points: " + n);
    int oldPointNumber = points.length;
    if (n != oldPointNumber) {
      updatePointsArray(n);
      poly.setPoints(points);
      setOutput();
    }

    // Set the points to the new polygon vertices
    for (int k = 0; k < n; k++) {
      points[k].setCoords(xcoord.get(k), ycoord.get(k), 1);
      // System.out.println("vertices: " + xcoord.get(k) + " , " + ycoord.get(k));

    }

    // Compute area of poly (this will also set our poly geo to be defined)
    poly.calcArea();

    // update new points and segments
    if (n != oldPointNumber) {
      updateSegmentsAndPointsLabels(oldPointNumber);
    }
  }
Esempio n. 25
0
 public Area getArea() {
   Area toReturn = new Area();
   for (Generateable member : members.values()) toReturn.add(member.getArea());
   return toReturn;
 }
Esempio n. 26
0
 /** @param tile AgriculturalUnit to add to country */
 public void addAgriculturalUnit(AgriculturalUnit tile) {
   entities.add(tile);
   area.add(tile.getArea());
 }
Esempio n. 27
0
  public Shape getShape() {

    int R = Integer.parseInt(hexcolor.substring(0, 2), 16);
    int G = Integer.parseInt(hexcolor.substring(2, 4), 16);
    int B = Integer.parseInt(hexcolor.substring(4, 6), 16);
    color = new Color(R, G, B);

    Shape geom;
    if (shape.equals("circle")) {
      geom = new Ellipse2D.Float(-0.05f * size, -0.05f * size, 1.1f * size, 1.1f * size);
      center = new Point2D.Float(size / 2, size / 2);
    } else if (shape.equals("square")) {
      geom = new Rectangle2D.Float(0, 0, size, size);
      center = new Point2D.Float(size / 2, size / 2);
    } else if (shape.equals("roundsquare")) {
      geom = new RoundRectangle2D.Float(0, 0, size, size, size / 2, size / 2);
      center = new Point2D.Float(size / 2, size / 2);
    } else if (shape.equals("triangle")) {
      GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2);
      float height = (float) (Math.sqrt(3) * size / 2);
      path.moveTo(size / 2, size - height);
      path.lineTo(size, size);
      path.lineTo(0, size);
      path.closePath();
      geom = path;
      center = new Point2D.Float(size / 2, size - height / 2);
    } else if (shape.equals("star")) {
      GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2);
      path.moveTo(size / 2, 0);
      path.lineTo(7 * size / 10, 3 * size / 10);
      path.lineTo(size, size / 2);
      path.lineTo(7 * size / 10, 7 * size / 10);
      path.lineTo(size / 2, size);
      path.lineTo(3 * size / 10, 7 * size / 10);
      path.lineTo(0, size / 2);
      path.lineTo(3 * size / 10, 3 * size / 10);
      path.closePath();

      AffineTransform trans = AffineTransform.getRotateInstance(Math.PI / 4, size / 2, size / 2);
      Shape shape = trans.createTransformedShape(path);

      Area area = new Area(path);
      area.add(new Area(shape));

      trans = AffineTransform.getScaleInstance(1.2, 1.2);
      shape = trans.createTransformedShape(area);
      trans = AffineTransform.getTranslateInstance(-0.1 * size, -0.1 * size);
      shape = trans.createTransformedShape(shape);

      geom = shape;

      center = new Point2D.Float(size / 2, size / 2);
    } else if (shape.equals("octagon")) {
      GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2);
      path.moveTo(size / 4, 0);
      path.lineTo(3 * size / 4, 0);
      path.lineTo(size, size / 4);
      path.lineTo(size, 3 * size / 4);
      path.lineTo(3 * size / 4, size);
      path.lineTo(size / 4, size);
      path.lineTo(0, 3 * size / 4);
      path.lineTo(0, size / 4);
      path.closePath();
      geom = path;
      path.closePath();
      geom = path;
      center = new Point2D.Float(size / 2, size / 2);
    } else if (shape.equals("ellipse")) {
      geom = new Ellipse2D.Float(0, 0, 3 * size / 4, size);
      center = new Point2D.Float(3 * size / 8, size / 2);
    } else if (shape.equals("cross")) {
      GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2);
      path.moveTo(size / 4, 0);
      path.lineTo(3 * size / 4, 0);
      path.lineTo(3 * size / 4, size / 4);
      path.lineTo(size, size / 4);
      path.lineTo(size, 3 * size / 4);
      path.lineTo(3 * size / 4, 3 * size / 4);
      path.lineTo(3 * size / 4, size);
      path.lineTo(size / 4, size);
      path.lineTo(size / 4, 3 * size / 4);
      path.lineTo(0, 3 * size / 4);
      path.lineTo(0, size / 4);
      path.lineTo(size / 4, size / 4);
      path.closePath();
      geom = path;
      center = new Point2D.Float(size / 2, size / 2);
    } else if (shape.equals("pentagon")) {
      GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2);
      path.moveTo(size / 2, size);

      float x, y, a;
      for (int i = 1; i < 5; i++) {
        a = (float) ((2 * Math.PI / 5) * i);
        x = (float) (size / 2 + size / 2 * Math.sin(a));
        y = (float) (size / 2 + size / 2 * Math.cos(a));
        path.lineTo(x, y);
      }
      path.closePath();

      AffineTransform trans = AffineTransform.getScaleInstance(1.1, 1.1);
      Shape shape = trans.createTransformedShape(path);
      trans = AffineTransform.getTranslateInstance(-0.05 * size, -0.05 * size);
      shape = trans.createTransformedShape(shape);

      geom = shape;
      center = new Point2D.Float(size / 2, size / 2);
    } else if (shape.equals("hexagon")) {
      GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2);
      path.moveTo(size / 2, size);

      float x, y, a;
      for (int i = 1; i < 6; i++) {
        a = (float) ((2 * Math.PI / 6) * i);
        x = (float) (size / 2 + size / 2 * Math.sin(a));
        y = (float) (size / 2 + size / 2 * Math.cos(a));
        path.lineTo(x, y);
      }
      path.closePath();
      geom = path;
      center = new Point2D.Float(size / 2, size / 2);
    } else {
      geom = new Ellipse2D.Float(0, 0, size, size);
      center = new Point2D.Float(size / 2, size / 2);
    }

    return geom;
  }