Beispiel #1
0
  public Area getArea() {

    if (!isPassed) {

      asMove1.setToIdentity();
      x[0] = x[0] + vx[0];
      y[0] = y[0] + vy[0];

      if ((pointList.size() - 1) % grap == 0) {
        makeSawtooth();
      }

      asMove1.translate(vx[0], vy[0]);
      area = new Area(asMove1.createTransformedShape(area));

      return sinWave(area);
    } else {
      // 生成锯齿状边缘

      cutTheArea(sawtooth);

      asMove1.setToIdentity();
      x[0] = x[0] + vx[0];
      y[0] = y[0] + vy[0];

      asMove1.translate(vx[0], vy[0]);
      area = new Area(asMove1.createTransformedShape(area));

      return sinWave(area);
    }
  }
Beispiel #2
0
  /**
   * Paints the icon.
   *
   * @param c the component on which it is painted
   * @param _g the graphics context
   * @param x the x coordinate of the icon
   * @param y the y coordinate of the icon
   */
  public void paintIcon(Component c, Graphics _g, int x, int y) {
    Graphics2D g = (Graphics2D) _g;
    AffineTransform at = AffineTransform.getTranslateInstance(x + offsetX, y + offsetY);

    // save current graphics paint and clip
    Paint gPaint = g.getPaint();
    Shape gClip = g.getClip();

    // render shape(s)
    g.setPaint(color);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.clipRect(x, y, w, h);

    // paint shape, if any
    if (shape != null) {
      g.fill(at.createTransformedShape(shape));
    }

    // paint decoration, if any
    if (decoration != null) {
      g.setPaint(decoColor);
      g.fill(at.createTransformedShape(decoration));
    }
    // restore graphics paint and clip
    g.setPaint(gPaint);
    g.setClip(gClip);
  }
Beispiel #3
0
  public Rectangle2D getBounds2D() {
    // Check if the TextPaintInfo has changed...
    if ((bounds != null) && TextPaintInfo.equivilent(tpi, cacheTPI)) return bounds;

    AffineTransform tr = AffineTransform.getTranslateInstance(position.getX(), position.getY());
    if (transform != null) {
      tr.concatenate(transform);
    }

    Rectangle2D bounds = null;
    if ((dShape != null) && (tpi != null)) {
      if (tpi.fillPaint != null) bounds = tr.createTransformedShape(dShape).getBounds2D();

      if ((tpi.strokeStroke != null) && (tpi.strokePaint != null)) {
        Shape s = tpi.strokeStroke.createStrokedShape(dShape);
        Rectangle2D r = tr.createTransformedShape(s).getBounds2D();
        if (bounds == null) bounds = r;
        // else                bounds = r.createUnion(bounds);
        else bounds.add(r);
      }
    }

    if (glyphChildrenNode != null) {
      Rectangle2D r = glyphChildrenNode.getTransformedBounds(tr);
      if (bounds == null) bounds = r;
      // else                bounds = r.createUnion(bounds);
      else bounds.add(r);
    }
    if (bounds == null) bounds = new Rectangle2D.Double(position.getX(), position.getY(), 0, 0);

    cacheTPI = new TextPaintInfo(tpi);
    return bounds;
  }
Beispiel #4
0
  public Area getCutArea1() {

    if (alpha[1] < 0.08f) {
      // 假如这部分已经基本透明,那么就把它变成空区域,并把它的位置速度变得和area部分一样,这样下次切割就不会出错。
      cutArea1 = new Area();
      x[1] = x[0];
      y[1] = y[0];
      vx[1] = vx[0];
      vy[1] = vy[0];
      asMove2.setToIdentity();
      asMove2.translate(x[1], y[1]);
      cutArea1 = new Area(asMove2.createTransformedShape(cutArea1));
    }

    if (cutArea1.isEmpty()) {
      alpha[1] = 1f;
    } else {

      alpha[1] = alpha[1] - 0.04f;
    }
    asMove2.setToIdentity();
    x[1] = x[1] + vx[1];
    y[1] = y[1] + vy[1];

    asMove2.translate(vx[1], vy[1]);
    cutArea1 = new Area(asMove2.createTransformedShape(cutArea1));

    return sinWave(cutArea1);
  }
Beispiel #5
0
  public Area getCutArea2() {

    if (alpha[2] < 0.08f) {
      cutArea2 = new Area();
      x[2] = x[0];
      y[2] = y[0];
      vx[2] = vx[0];
      vy[2] = vy[0];
      asMove3.setToIdentity();
      asMove3.translate(x[2], y[2]);
      cutArea2 = new Area(asMove3.createTransformedShape(cutArea2));
    }
    if (cutArea2.isEmpty()) {
      alpha[2] = 1f;

    } else {

      alpha[2] = alpha[2] - 0.04f;
    }

    asMove3.setToIdentity();
    x[2] = x[2] + vx[2];
    y[2] = y[2] + vy[2];

    asMove3.translate(vx[2], vy[2]);
    cutArea2 = new Area(asMove3.createTransformedShape(cutArea2));
    return sinWave(cutArea2);
  }
Beispiel #6
0
  /**
   * Draws the annotation. This method is usually called by the {@link XYPlot} class, you shouldn't
   * need to call it directly.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param dataArea the data area.
   * @param domainAxis the domain axis.
   * @param rangeAxis the range axis.
   * @param rendererIndex the renderer index.
   * @param info the plot rendering info.
   */
  public void draw(
      Graphics2D g2,
      XYPlot plot,
      Rectangle2D dataArea,
      ValueAxis domainAxis,
      ValueAxis rangeAxis,
      int rendererIndex,
      PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge =
        Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge =
        Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);

    // compute transform matrix elements via sample points. Assume no
    // rotation or shear.
    Rectangle2D bounds = this.shape.getBounds2D();
    double x0 = bounds.getMinX();
    double x1 = bounds.getMaxX();
    double xx0 = domainAxis.valueToJava2D(x0, dataArea, domainEdge);
    double xx1 = domainAxis.valueToJava2D(x1, dataArea, domainEdge);
    double m00 = (xx1 - xx0) / (x1 - x0);
    double m02 = xx0 - x0 * m00;

    double y0 = bounds.getMaxY();
    double y1 = bounds.getMinY();
    double yy0 = rangeAxis.valueToJava2D(y0, dataArea, rangeEdge);
    double yy1 = rangeAxis.valueToJava2D(y1, dataArea, rangeEdge);
    double m11 = (yy1 - yy0) / (y1 - y0);
    double m12 = yy0 - m11 * y0;

    //  create transform & transform shape
    Shape s = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
      AffineTransform t1 = new AffineTransform(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
      AffineTransform t2 = new AffineTransform(m11, 0.0f, 0.0f, m00, m12, m02);
      s = t1.createTransformedShape(this.shape);
      s = t2.createTransformedShape(s);
    } else if (orientation == PlotOrientation.VERTICAL) {
      AffineTransform t = new AffineTransform(m00, 0, 0, m11, m02, m12);
      s = t.createTransformedShape(this.shape);
    }

    if (this.fillPaint != null) {
      g2.setPaint(this.fillPaint);
      g2.fill(s);
    }

    if (this.stroke != null && this.outlinePaint != null) {
      g2.setPaint(this.outlinePaint);
      g2.setStroke(this.stroke);
      g2.draw(s);
    }
    addEntity(info, s, rendererIndex, getToolTipText(), getURL());
  }
Beispiel #7
0
  /**
   * This implementation calls <code>super.hitTest</code> and returns the result if non-null (this
   * should be a HitInfo.Point), then returns a HitInfo.Interior if the mouse-click occured inside
   * the text bound (as defined by text layout)
   *
   * @return a HitInfo corresponding to the given mouse-event
   */
  public HitInfo hitTest(PEMouseEvent e) {

    // from Bitmap:
    if (image != null) {
      if (getBounds().contains(e.getPicPoint())) {
        return new HitInfo.Interior((PicText) element, e);
      }
      return null;
    }

    // from TextLayout:
    if (!getBounds().contains(e.getPicPoint())) return null;

    PicText te = (PicText) element;
    // recompute textlayout b-box, but store it in a temporary field !
    Rectangle2D tb = textLayout.getBounds();
    Shape text_bounds = text2ModelTr.createTransformedShape(tb);
    if (text_bounds.contains(e.getPicPoint())) {
      // [SR:pending] for the hitInfo to be reliable, getPicPoint() should first be transformed by
      //              inverse text2ModelTr ! (especially when rotationAngle != 0)
      TextHitInfo thi =
          textLayout.hitTestChar(
              (float) (e.getPicPoint().x - strx),
              (float) (e.getPicPoint().y - stry)); // guaranteed to return a non-null thi
      return new HitInfo.Text((PicText) element, thi, e);
    }
    // test hit on textlayout's bounding rectangle :
    // else if (bounds.contains(e.getPicPoint())) return new HitInfo.Interior(element,e);
    return null;
  }
Beispiel #8
0
  /**
   * Draws this glyph.
   *
   * @param graphics2D The Graphics2D object to draw to.
   */
  public void draw(Graphics2D graphics2D) {
    AffineTransform tr = AffineTransform.getTranslateInstance(position.getX(), position.getY());
    if (transform != null) {
      tr.concatenate(transform);
    }

    // paint the dShape first
    if ((dShape != null) && (tpi != null)) {
      Shape tShape = tr.createTransformedShape(dShape);
      if (tpi.fillPaint != null) {
        graphics2D.setPaint(tpi.fillPaint);
        graphics2D.fill(tShape);
      }

      // check if we need to draw the outline of this glyph
      if (tpi.strokeStroke != null && tpi.strokePaint != null) {
        graphics2D.setStroke(tpi.strokeStroke);
        graphics2D.setPaint(tpi.strokePaint);
        graphics2D.draw(tShape);
      }
    }

    // paint the glyph children nodes
    if (glyphChildrenNode != null) {
      glyphChildrenNode.setTransform(tr);
      glyphChildrenNode.paint(graphics2D);
    }
  }
Beispiel #9
0
 /**
  * Returns the outline of this glyph. This will be positioned correctly and any glyph transforms
  * will have been applied.
  *
  * @return the outline of this glyph.
  */
 public Shape getOutline() {
   if (outline == null) {
     AffineTransform tr = AffineTransform.getTranslateInstance(position.getX(), position.getY());
     if (transform != null) {
       tr.concatenate(transform);
     }
     Shape glyphChildrenOutline = null;
     if (glyphChildrenNode != null) {
       glyphChildrenOutline = glyphChildrenNode.getOutline();
     }
     GeneralPath glyphOutline = null;
     if (dShape != null && glyphChildrenOutline != null) {
       glyphOutline = new GeneralPath(dShape);
       glyphOutline.append(glyphChildrenOutline, false);
     } else if (dShape != null && glyphChildrenOutline == null) {
       glyphOutline = new GeneralPath(dShape);
     } else if (dShape == null && glyphChildrenOutline != null) {
       glyphOutline = new GeneralPath(glyphChildrenOutline);
     } else {
       // must be a whitespace glyph, return an empty shape
       glyphOutline = new GeneralPath();
     }
     outline = tr.createTransformedShape(glyphOutline);
   }
   return outline;
 }
Beispiel #10
0
 @Override
 public void paintPreview(JEnvironment env, JRequest req, Graphics2D g) {
   g.setColor(getPreviewColor());
   AffineTransform af = new AffineTransform(totalTransform);
   if (addingTransform != null) af.preConcatenate(addingTransform);
   Shape s = getShape();
   if (addingTransform != null) s = addingTransform.createTransformedShape(s);
   s = env.getToScreenTransform().createTransformedShape(s);
   g.draw(s);
   PathIterator path = s.getPathIterator(null);
   double radius = JEnvironment.PATH_SELECTOR_SIZE / 2;
   Rectangle2D.Double sr = new Rectangle2D.Double(0, 0, radius * 2, radius * 2);
   double[] coords = new double[6];
   while (!path.isDone()) {
     int type = path.currentSegment(coords);
     if (type == path.SEG_MOVETO || type == path.SEG_LINETO) {
       sr.x = coords[0] - radius;
       sr.y = coords[1] - radius;
       g.fill(sr);
     } else if (type == path.SEG_CUBICTO) {
       sr.x = coords[4] - radius;
       sr.y = coords[5] - radius;
       g.fill(sr);
     } else if (type == path.SEG_QUADTO) {
       sr.x = coords[2] - radius;
       sr.y = coords[3] - radius;
       g.fill(sr);
     }
     path.next();
   }
 }
Beispiel #11
0
 public Shape fromMapToWorld(Polygon p) {
   if (transInv != null) {
     return transInv.createTransformedShape(p);
   } else {
     throw new RuntimeException("NonInvertibleMatrix");
   }
 }
Beispiel #12
0
    public void paint(Graphics g) {
      g.setColor(Color.gray);

      Graphics2D g2d = (Graphics2D) g;

      Ellipse2D ellipse = new Ellipse2D.Double();
      for (String v : layout.getGraph().getVertices()) {
        Double radius = layout.getRadii().get(v);
        if (radius == null) {
          continue;
        }
        Point2D p = layout.transform(v);
        ellipse.setFrame(-radius, -radius, 2 * radius, 2 * radius);
        AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
        Shape shape = at.createTransformedShape(ellipse);

        MutableTransformer viewTransformer =
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW);

        if (viewTransformer instanceof MutableTransformerDecorator) {
          shape = vv.getRenderContext().getMultiLayerTransformer().transform(shape);
        } else {
          shape = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, shape);
        }

        g2d.draw(shape);
      }
    }
Beispiel #13
0
  public AffineRed(CachableRed src, AffineTransform src2me, RenderingHints hints) {
    super(); // We _must_ call init...

    this.src2me = src2me;
    this.hints = hints;

    try {
      me2src = src2me.createInverse();
    } catch (NoninvertibleTransformException nite) {
      me2src = null;
    }

    // Calculate my bounds by applying the affine transform to
    // my input data..codec/
    Rectangle srcBounds = src.getBounds();
    // srcBounds.grow(-1,-1);
    Rectangle myBounds;
    myBounds = src2me.createTransformedShape(srcBounds).getBounds();

    // If the output buffer is not premultiplied in certain cases it
    // fails to properly divide out the Alpha (it always does
    // the affine on premultiplied data), hence you get ugly
    // back aliasing effects...
    ColorModel cm = fixColorModel(src);

    // fix my sample model so it makes sense given my size.
    SampleModel sm = fixSampleModel(src, cm, myBounds);

    Point2D pt = new Point2D.Float(src.getTileGridXOffset(), src.getTileGridYOffset());
    pt = src2me.transform(pt, null);

    // Finish initializing our base class...
    init(src, myBounds, cm, sm, (int) pt.getX(), (int) pt.getY(), null);
  }
Beispiel #14
0
  @Override
  public Shape getPointShape(PointData data) {
    Row row = data.row;
    int colLabel = getColumn();
    if (colLabel >= row.size()) {
      return null;
    }

    Comparable<?> labelValue = row.get(colLabel);
    if (labelValue == null) {
      return null;
    }

    Format format = getFormat();
    Font font = getFont();
    String text = format.format(labelValue);
    double alignment = getAlignmentX();
    Shape shape = GraphicsUtils.getOutline(text, font, 0f, alignment);

    double alignX = getAlignmentX();
    double alignY = getAlignmentY();
    Rectangle2D bounds = shape.getBounds2D();
    AffineTransform tx =
        AffineTransform.getTranslateInstance(
            -alignX * bounds.getWidth(), alignY * bounds.getHeight());
    shape = tx.createTransformedShape(shape);

    return shape;
  }
Beispiel #15
0
  /**
   * Draw some graphics into an Graphics2D object.
   *
   * @param image the image to draw into
   * @throws NoninvertibleTransformException in transform errors.
   */
  private void draw(Graphics2D gr) throws NoninvertibleTransformException {
    gr.setPaint(Color.WHITE);
    gr.fill(new Rectangle(0, 0, tileWidth, tileHeight));

    // AffineTransform[[0.318755336305853, 0.0, 420.03106689453125],
    //                 [0.0, 0.318755336305853, 245.5029296875]]
    AffineTransform transform =
        new AffineTransform(
            0.318755336305853, 0.0, 0.0, 0.318755336305853, 420.03106689453125, 245.5029296875);
    gr.setTransform(transform);

    Shape s = new Rectangle(0, 0, 96, 83);

    // create an enbedded graphics
    Graphics2D grr = (Graphics2D) gr.create();
    // AffineTransform[[1.0, 0.0, -343.9285583496093],
    //                 [0.0, 1.0, -502.5158386230469]]
    grr.clip(s.getBounds());
    transform = new AffineTransform(1.0, 0.0, 0.0, 1.0, -343.9285583496093, -502.5158386230469);
    grr.transform(transform);

    AffineTransform t = transform.createInverse();
    s = t.createTransformedShape(s);

    assertTrue(s.getBounds().intersects(grr.getClip().getBounds2D()));

    grr.setPaint(Color.BLUE);
    grr.draw(s);

    grr.dispose();
    gr.dispose();
  }
  /**
   * Method paint. Paints the rings on the graph.
   *
   * @param g Graphics - the graphics to be painted.
   */
  @Override
  public void paint(Graphics g) {
    Collection<Double> depths = getDepths();
    g.setColor(Color.gray);
    Graphics2D g2d = (Graphics2D) g;
    Point2D center = radialLayout.getCenter();

    Ellipse2D ellipse = new Ellipse2D.Double();
    for (double d : depths) {
      ellipse.setFrameFromDiagonal(
          center.getX() - d, center.getY() - d, center.getX() + d, center.getY() + d);
      AffineTransform at = AffineTransform.getTranslateInstance(0, 0);
      Shape shape = at.createTransformedShape(ellipse);
      // Shape shape =
      //	vv.getRenderContext().getMultiLayerTransformer().transform(ellipse);
      //
      //	vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).transform(ellipse);

      MutableTransformer viewTransformer =
          vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW);

      if (viewTransformer instanceof MutableTransformerDecorator) {
        shape = vv.getRenderContext().getMultiLayerTransformer().transform(shape);
      } else {
        shape = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, shape);
      }
      g2d.draw(shape);
    }
  }
 /**
  * Creates and returns a translated shape.
  *
  * @param shape the shape (<code>null</code> not permitted).
  * @param transX the x translation (in Java2D space).
  * @param transY the y translation (in Java2D space).
  * @return The translated shape.
  */
 public static Shape createTranslatedShape(
     final Shape shape, final double transX, final double transY) {
   if (shape == null) {
     throw new IllegalArgumentException("Null 'shape' argument.");
   }
   final AffineTransform transform = AffineTransform.getTranslateInstance(transX, transY);
   return transform.createTransformedShape(shape);
 }
 private Rectangle getTransformedSize() {
   if (view != null) {
     Dimension viewSize = view.getSize();
     Rectangle viewRect = new Rectangle(viewSize);
     return at.createTransformedShape(viewRect).getBounds();
   }
   return new Rectangle(super.getPreferredSize());
 }
 /**
  * @param input
  * @param xScale
  * @param yScale
  * @return
  */
 public static Shape convertToAWT(FreedomShape input, double xScale, double yScale) {
   if (input instanceof FreedomPolygon) {
     Shape shape = convertToAWT((FreedomPolygon) input);
     transform.scale(xScale, yScale);
     Shape transformed = transform.createTransformedShape(shape);
     return transformed;
   } else {
     if (input instanceof FreedomEllipse) {
       Shape shape = convertToAWT((FreedomEllipse) input);
       transform.scale(xScale, yScale);
       Shape transformed = transform.createTransformedShape(shape);
       return transformed;
     } else {
       throw new IllegalArgumentException("The kind of shape in input is unknown");
     }
   }
 }
Beispiel #20
0
 @Override
 public Rectangle2D getOriginalSelectionBounds(double x, double y) {
   Shape s = getShape();
   AffineTransform af = new AffineTransform();
   af.setToRotation(-totalRotation, x, y);
   Area a = new Area(af.createTransformedShape(s));
   return a.getBounds2D();
 }
Beispiel #21
0
 public GEShape deepCopy() {
   AffineTransform affineTransform = new AffineTransform();
   Shape newShape = affineTransform.createTransformedShape(myShape);
   GEEllipse shape = new GEEllipse();
   shape.setShape(newShape);
   shape.setGraphicsAttributes(this);
   return shape;
 }
Beispiel #22
0
 Area sinWave(Area oneArea) {
   double thetaSpeed = 0.04;
   double height = 0.4;
   delta = delta + thetaSpeed;
   asSin.translate(0, height * Math.cos(delta));
   oneArea = new Area(asSin.createTransformedShape(oneArea));
   return oneArea;
 }
Beispiel #23
0
  private Shape scaleWorld(Shape shape) {
    Dimension svgDim = new Dimension(800, 400);

    double diag = Math.sqrt(Math.pow(svgDim.width / 2, 2) + Math.pow(svgDim.height / 2, 2));
    double ratio = getRadiusInt() / diag;

    // move to center of figure
    AffineTransform tr =
        AffineTransform.getTranslateInstance(-svgDim.width / 2, -svgDim.height / 2);
    shape = tr.createTransformedShape(shape);
    tr = AffineTransform.getScaleInstance(ratio, ratio);
    shape = tr.createTransformedShape(shape);
    tr = AffineTransform.getTranslateInstance(viewRect.width / 2, viewRect.height / 2);
    shape = tr.createTransformedShape(shape);

    return shape;
  }
Beispiel #24
0
 public Shape getShape(double mw, double mh) {
   // now scale the path so it has proper w and h.
   Rectangle r = sh.getBounds();
   AffineTransform at = new AffineTransform();
   at.translate(-r.x, -r.y);
   at.scale(mw / r.width, mh / r.height);
   return at.createTransformedShape(sh);
 }
 /**
  * Rotates a shape about the specified coordinates.
  *
  * @param base the shape (<code>null</code> permitted, returns <code>null</code>).
  * @param angle the angle (in radians).
  * @param x the x coordinate for the rotation point (in Java2D space).
  * @param y the y coordinate for the rotation point (in Java2D space).
  * @return the rotated shape.
  */
 public static Shape rotateShape(
     final Shape base, final double angle, final float x, final float y) {
   if (base == null) {
     return null;
   }
   final AffineTransform rotate = AffineTransform.getRotateInstance(angle, x, y);
   final Shape result = rotate.createTransformedShape(base);
   return result;
 }
 public Rectangle2D convertPDF2ImageCoord(Rectangle2D r) {
   if (currentImage == null) return null;
   int imwid = currentImage.getWidth(null);
   int imhgt = currentImage.getHeight(null);
   AffineTransform t = currentPage.getInitialTransform(imwid, imhgt, prevClip);
   Rectangle2D tr = t.createTransformedShape(r).getBounds2D();
   tr.setFrame(tr.getX(), tr.getY(), tr.getWidth(), tr.getHeight());
   return tr;
 }
Beispiel #27
0
 /**
  * Returns {@code true} if the rectangle (in device space) intersects with the shape (the
  * interior, if {@code onStroke} is false, otherwise the stroked outline of the shape).
  *
  * @param rect a rectangle (in device space).
  * @param s the shape.
  * @param onStroke test the stroked outline only?
  * @return A boolean.
  */
 @Override
 public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
   AffineTransform transform = getTransform();
   Shape ts;
   if (onStroke) {
     Stroke stroke = getStroke();
     ts = transform.createTransformedShape(stroke.createStrokedShape(s));
   } else {
     ts = transform.createTransformedShape(s);
   }
   if (!rect.getBounds2D().intersects(ts.getBounds2D())) {
     return false;
   }
   Area a1 = new Area(rect);
   Area a2 = new Area(ts);
   a1.intersect(a2);
   return !a1.isEmpty();
 }
Beispiel #28
0
  /**
   * Gets the mark for the specified panel.
   *
   * @param trackerPanel the tracker panel
   * @return the mark
   */
  protected Mark getMark(TrackerPanel trackerPanel) {
    Mark mark = marks.get(trackerPanel);
    TPoint selection = null;
    if (mark == null) {
      selection = trackerPanel.getSelectedPoint();
      Point p = null;
      valid = true; // assume true
      for (int n = 0; n < points.length; n++) {
        if (!valid) continue;
        // determine if point is valid (ie not NaN)
        valid = valid && !Double.isNaN(points[n].getX()) && !Double.isNaN(points[n].getY());
        screenPoints[n] = points[n].getScreenPosition(trackerPanel);
        if (valid && selection == points[n]) p = screenPoints[n];
      }
      mark = footprint.getMark(screenPoints);
      if (p != null) { // point is selected, so draw selection shape
        transform.setToTranslation(p.x, p.y);
        int scale = FontSizer.getIntegerFactor();
        if (scale > 1) {
          transform.scale(scale, scale);
        }
        final Color color = footprint.getColor();
        final Mark stepMark = mark;
        final Shape selectedShape = transform.createTransformedShape(selectionShape);
        mark =
            new Mark() {
              public void draw(Graphics2D g, boolean highlighted) {
                stepMark.draw(g, false);
                Paint gpaint = g.getPaint();
                g.setPaint(color);
                g.fill(selectedShape);
                g.setPaint(gpaint);
              }

              public Rectangle getBounds(boolean highlighted) {
                Rectangle bounds = selectedShape.getBounds();
                bounds.add(stepMark.getBounds(false));
                return bounds;
              }
            };
      }
      final Mark theMark = mark;
      mark =
          new Mark() {
            public void draw(Graphics2D g, boolean highlighted) {
              if (!valid) return;
              theMark.draw(g, false);
            }

            public Rectangle getBounds(boolean highlighted) {
              return theMark.getBounds(highlighted);
            }
          };
      marks.put(trackerPanel, mark);
    }
    return mark;
  }
Beispiel #29
0
 /** @see Graphics2D#hit(Rectangle, Shape, boolean) */
 public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
   if (onStroke) {
     s = stroke.createStrokedShape(s);
   }
   s = transform.createTransformedShape(s);
   Area area = new Area(s);
   if (clip != null) area.intersect(clip);
   return area.intersects(rect.x, rect.y, rect.width, rect.height);
 }
 private Rectangle getScaledRectangle(Rectangle rectangle) {
   final AffineTransform i2mTransform =
       ImageManager.getImageToModelTransform(product.getGeoCoding());
   final double scaleX = i2mTransform.getScaleX();
   final double scaleY = i2mTransform.getScaleY();
   double scaleFactorY = Math.abs(scaleY / scaleX);
   final AffineTransform scaleTransform = AffineTransform.getScaleInstance(1.0, scaleFactorY);
   return scaleTransform.createTransformedShape(rectangle).getBounds();
 }