Exemplo n.º 1
0
  public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp, Cancellable cancel) {
    switch (markerFillProperties.getFillStyle()) {
      case SINGLE_CENTERED_SYMBOL:
        // case a single marker is used into a polygon shapetype
        Geometry geom = FConverter.java2d_to_jts(shp);
        com.vividsolutions.jts.geom.Point centroid = geom.getCentroid();
        /*
         * Hay ocasiones en que jts no puede calcular un centroide y
         * devuelve NaN (por ejemplo con geometrías poligonales cuyos puntos
         * tienen todos la misma abscisa y distinta ordenada con tan solo
         * una diferencia de 1 ó 2 unidades) entonces, en lugar de utilizar
         * este centroide tomamos el centro del bounds del shp (la geometría
         * es tan pequeña que consideramos que deben coincidir).
         */
        if (!(Double.isNaN(centroid.getX()) || Double.isNaN(centroid.getY()))) {
          double centroidX = centroid.getX() + markerFillProperties.getXOffset();
          double centroidY = centroid.getY() + markerFillProperties.getYOffset();
          FPoint2D p = new FPoint2D(new Point2D.Double(centroidX, centroidY));
          markerSymbol.draw(g, affineTransform, p, null);
        } else {
          double centroidX = shp.getBounds().getCenterX();
          double centroidY = shp.getBounds().getCenterY();
          FPoint2D p = new FPoint2D(new Point2D.Double(centroidX, centroidY));
          markerSymbol.draw(g, affineTransform, p, null);
        }
        break;
      case GRID_FILL:
        // case a grid fill is used
        {
          Rectangle rClip = null;
          if (g.getClipBounds() != null) {
            rClip = (Rectangle) g.getClipBounds().clone();
            g.setClip(rClip.x, rClip.y, rClip.width, rClip.height);
          }
          g.clip(shp);

          int size = (int) markerSymbol.getSize();
          Rectangle rProv = new Rectangle();
          rProv.setFrame(0, 0, size, size);
          Paint resulPatternFill = null;

          double xSeparation = markerFillProperties.getXSeparation(); // TODO
          // apply
          // CartographicSupport
          double ySeparation = markerFillProperties.getYSeparation(); // TODO
          // apply
          // CartographicSupport
          double xOffset = markerFillProperties.getXOffset();
          double yOffset = markerFillProperties.getYOffset();

          BufferedImage sample = null;
          sample = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
          Graphics2D gAux = sample.createGraphics();

          try {
            markerSymbol.drawInsideRectangle(gAux, gAux.getTransform(), rProv, null);
          } catch (SymbolDrawingException e) {
            if (e.getType() == SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) {
              try {
                SymbologyFactory.getWarningSymbol(
                        SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
                        "",
                        SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS)
                    .drawInsideRectangle(gAux, gAux.getTransform(), rProv, null);
              } catch (SymbolDrawingException e1) {
                // IMPOSSIBLE TO REACH THIS
              }
            } else {
              // should be unreachable code
              throw new Error(Messages.getString("symbol_shapetype_mismatch"));
            }
          }
          rProv.setRect(0, 0, rProv.getWidth() + xSeparation, rProv.getHeight() + ySeparation);

          BufferedImage bi =
              new BufferedImage(rProv.width, rProv.height, BufferedImage.TYPE_INT_ARGB);
          gAux = bi.createGraphics();
          gAux.drawImage(sample, null, (int) (xSeparation * 0.5), (int) (ySeparation * 0.5));

          resulPatternFill = new TexturePaint(bi, rProv);
          sample = null;
          gAux.dispose();

          g.setColor(null);
          g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

          g.translate(xOffset, -yOffset);
          g.setPaint(resulPatternFill);
          g.fill(shp);
          g.translate(-xOffset, +yOffset);
          g.setClip(rClip);
          bi = null;
        }
        break;
      case RANDOM_FILL:
        {
          double s = markerSymbol.getSize();
          Rectangle r = shp.getBounds();
          int drawCount = (int) (Math.min(r.getWidth(), r.getHeight()) / s);
          Random random = new Random();

          int minx = r.x;
          int miny = r.y;
          int width = r.width;
          int height = r.height;

          r = new Rectangle();
          g.setClip(shp);

          for (int i = 0; (cancel == null || !cancel.isCanceled()) && i < drawCount; i++) {
            int x = (int) Math.abs(random.nextDouble() * width);
            int y = (int) Math.abs(random.nextDouble() * height);
            x = x + minx;
            y = y + miny;
            markerSymbol.draw(g, new AffineTransform(), new FPoint2D(x, y), cancel);
          }
          g.setClip(null);
        }
        break;
    }
    if (getOutline() != null) {
      getOutline().draw(g, affineTransform, shp, cancel);
    }
  }
Exemplo n.º 2
0
 public String getDescription() {
   return Messages.getString("constant");
 }