/**
   * Code to paint the WhiteboardShapeRect.
   *
   * @param g graphics context
   * @param t 2D affine transformation
   */
  public void paintShape(Graphics2D g, AffineTransform t) {
    double x = point.getX();
    double y = point.getY();

    g.setStroke(new BasicStroke(this.getThickness(), BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND));

    Point2D w0 = new Point2D.Double(x, y);
    Point2D v0 = t.transform(w0, null);

    int x0 = (int) v0.getX();
    int y0 = (int) v0.getY();

    Point2D w1 = new Point2D.Double(x + width, y + height);
    Point2D v1 = t.transform(w1, null);

    int xWidth = (int) v1.getX() - x0;
    int yHeight = (int) v1.getY() - y0;

    g.setColor(Color.getColor("", this.getColor()));
    if (fill) {
      g.fillRect(x0, y0, xWidth, yHeight);
    } else {
      g.drawRect(x0, y0, xWidth, yHeight);
    }
  }
  /**
   * WhiteboardShapeRect constructor.
   *
   * @param id String that uniquely identifies this WhiteboardShapeRect
   * @param thickness number of pixels that this object (or its border) should be thick
   * @param color WhiteboardShapeRect's color (or rather it's border)
   * @param point coordinates of this object.
   * @param width width value of this object (in pixel)
   * @param height height value of this object (in pixel)
   * @param fill True is filled, false is unfilled
   * @param transform 2D affine transformation
   */
  public WhiteboardShapeRect(
      String id,
      int thickness,
      Color color,
      WhiteboardPoint point,
      double width,
      double height,
      boolean fill,
      AffineTransform transform) {
    super(id);

    Point2D v0 = new Point2D.Double(point.getX(), point.getY());
    Point2D w0 = transform.transform(v0, null);

    double x = w0.getX();
    double y = w0.getY();

    point.setX(x);
    point.setY(y);

    Point2D v1 = new Point2D.Double(x + width, y + height);
    Point2D w1 = transform.transform(v1, null);

    double transformedWidth = w1.getX() - x;
    double transformedHeight = w1.getY() - y;

    this.initShape(thickness, color, point, transformedWidth, transformedHeight, fill);
  }
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and ellipse.
  *
  * @return Returns true, if the circle is inside of the image bounds.
  */
 private boolean writeCircleAttributes(IXMLElement elem, SVGFigure f, Ellipse2D.Double ellipse) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType() &&
             ellipse.width == ellipse.height
             ) {
         
         Point2D.Double start = new Point2D.Double(ellipse.x, ellipse.y);
         Point2D.Double end = new Point2D.Double(ellipse.x + ellipse.width, ellipse.y + ellipse.height);
         t.transform(start, start);
         t.transform(end, end);
         ellipse.x = Math.min(start.x, end.x);
         ellipse.y = Math.min(start.y, end.y);
         ellipse.width = Math.abs(start.x - end.x);
         ellipse.height = Math.abs(start.y - end.y);
         
         elem.setAttribute("shape", "circle");
         elem.setAttribute("coords",
                 (int) (ellipse.x + ellipse.width / 2d)+","+
                 (int) (ellipse.y + ellipse.height / 2d)+","+
                 (int) (ellipse.width / 2d)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(ellipse.getBounds());
     } else {
         return writePolyAttributes(elem, f, (Shape) ellipse);
     }
 }
Example #4
0
  /**
   * Code to paint the specific shape
   *
   * @param w2v 2D affine transform
   * @param g graphics context
   */
  public void paintShape(Graphics2D g, AffineTransform w2v) {
    double x = startPoint.getX();
    double y = startPoint.getY();
    double xEnd = endPoint.getX();
    double yEnd = endPoint.getY();

    g.setStroke(new BasicStroke(this.getThickness(), BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND));

    Point2D v0 = w2v.transform(new Point2D.Double(x, y), null);
    int ix = (int) v0.getX();
    int iy = (int) v0.getY();

    Point2D v1 = w2v.transform(new Point2D.Double(xEnd, yEnd), null);

    g.drawLine(ix, iy, (int) v1.getX(), (int) v1.getY());
  }
Example #5
0
 /**
  * Transforms the figure.
  *
  * @param tx the transformation.
  */
 public void transform(AffineTransform tx) {
   if (TRANSFORM.get(this) != null
       || tx.getType() != (tx.getType() & AffineTransform.TYPE_TRANSLATION)) {
     if (TRANSFORM.get(this) == null) {
       TRANSFORM.basicSet(this, (AffineTransform) tx.clone());
     } else {
       AffineTransform t = TRANSFORM.getClone(this);
       t.preConcatenate(tx);
       TRANSFORM.basicSet(this, t);
     }
   } else {
     for (int i = 0; i < coordinates.length; i++) {
       tx.transform(coordinates[i], coordinates[i]);
     }
     if (FILL_GRADIENT.get(this) != null && !FILL_GRADIENT.get(this).isRelativeToFigureBounds()) {
       Gradient g = FILL_GRADIENT.getClone(this);
       g.transform(tx);
       FILL_GRADIENT.basicSet(this, g);
     }
     if (STROKE_GRADIENT.get(this) != null
         && !STROKE_GRADIENT.get(this).isRelativeToFigureBounds()) {
       Gradient g = STROKE_GRADIENT.getClone(this);
       g.transform(tx);
       STROKE_GRADIENT.basicSet(this, g);
     }
   }
   invalidate();
 }
Example #6
0
  public synchronized void paint(Graphics gin) {
    Graphics2D g = (Graphics2D) gin;

    if (im == null) return;

    int height = getHeight();
    int width = getWidth();

    if (fit) {
      t = new AffineTransform();
      double scale = Math.min(((double) width) / im.getWidth(), ((double) height) / im.getHeight());
      // we'll re-center the transform in a moment.
      t.scale(scale, scale);
    }

    // if the image (in either X or Y) is smaller than the view port, then center
    // the image with respect to that axis.
    double mwidth = im.getWidth() * t.getScaleX();
    double mheight = im.getHeight() * t.getScaleY();
    if (mwidth < width)
      t.preConcatenate(
          AffineTransform.getTranslateInstance((width - mwidth) / 2.0 - t.getTranslateX(), 0));
    if (mheight < height)
      t.preConcatenate(
          AffineTransform.getTranslateInstance(0, (height - mheight) / 2.0 - t.getTranslateY()));

    // if we're allowing panning (because only a portion of the image is visible),
    // don't allow translations that show less information that is possible.
    Point2D topleft = t.transform(new Point2D.Double(0, 0), null);
    Point2D bottomright = t.transform(new Point2D.Double(im.getWidth(), im.getHeight()), null);

    if (mwidth > width) {
      if (topleft.getX() > 0)
        t.preConcatenate(AffineTransform.getTranslateInstance(-topleft.getX(), 0));
      if (bottomright.getX() < width)
        t.preConcatenate(AffineTransform.getTranslateInstance(width - bottomright.getX(), 0));
      //		    t.translate(width-bottomright.getX(), 0);
    }
    if (mheight > height) {
      if (topleft.getY() > 0)
        t.preConcatenate(AffineTransform.getTranslateInstance(0, -topleft.getY()));
      if (bottomright.getY() < height)
        t.preConcatenate(AffineTransform.getTranslateInstance(0, height - bottomright.getY()));
    }

    g.drawImage(im, t, null);
  }
  private static MeshCoords transformSector(AffineTransform transform, Sector sector) {
    java.awt.geom.Point2D p = new java.awt.geom.Point2D.Double();
    java.awt.geom.Point2D ll = new java.awt.geom.Point2D.Double();
    java.awt.geom.Point2D ur = new java.awt.geom.Point2D.Double();

    p.setLocation(sector.getMinLongitude().degrees, sector.getMinLatitude().degrees);
    transform.transform(p, ll);

    p.setLocation(sector.getMaxLongitude().degrees, sector.getMaxLatitude().degrees);
    transform.transform(p, ur);

    return new MeshCoords(
        (float) ur.getY(), // Top
        (float) ll.getX(), // Left
        (float) ll.getY(), // Bottom
        (float) ur.getX()); // Right
  }
Example #8
0
 public float getFontSize() {
   //   return FONT_SIZE.get(this).floatValue();
   Point2D.Double p = new Point2D.Double(0, FONT_SIZE.get(this));
   AffineTransform tx = TRANSFORM.get(this);
   if (tx != null) {
     tx.transform(p, p);
     Point2D.Double p0 = new Point2D.Double(0, 0);
     tx.transform(p0, p0);
     p.y -= p0.y;
     /*
     try {
         tx.inverseTransform(p, p);
     } catch (NoninvertibleTransformException ex) {
         ex.printStackTrace();
     }*/
   }
   return (float) Math.abs(p.y);
 }
Example #9
0
  /**
   * WhiteboardShapeLine constructor
   *
   * @param id String that uniquely identifies this WhiteboardObject.
   * @param t number of pixels that this object (or its border)
   * @param c WhiteboardShapeLine's color (or rather it's border)
   * @param startPoint the start coordinates of this line.
   * @param endPoint the end coordinates of this line.
   * @param v2w 2D affine transform
   */
  public WhiteboardShapeLine(
      String id,
      int t,
      Color c,
      WhiteboardPoint startPoint,
      WhiteboardPoint endPoint,
      AffineTransform v2w) {
    super(id);
    this.setThickness(t);
    setColor(c);

    Point2D v0 = new Point2D.Double(startPoint.getX(), startPoint.getY());
    Point2D w0 = v2w.transform(v0, null);

    this.startPoint = new WhiteboardPoint(w0.getX(), w0.getY());

    Point2D v1 = new Point2D.Double(endPoint.getX(), endPoint.getY());
    Point2D w1 = v2w.transform(v1, null);

    this.endPoint = new WhiteboardPoint(w1.getX(), w1.getY());
  }
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and rectangle.
  *
  * @return Returns true, if the rect is inside of the image bounds.
  */
 private boolean writeRectAttributes(IXMLElement elem, SVGFigure f, Rectangle2D.Double rect) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType()
             ) {
         
         Point2D.Double start = new Point2D.Double(rect.x, rect.y);
         Point2D.Double end = new Point2D.Double(rect.x + rect.width, rect.y + rect.height);
         t.transform(start, start);
         t.transform(end, end);
         Rectangle r = new Rectangle(
                 (int) Math.min(start.x, end.x),
                 (int) Math.min(start.y, end.y),
                 (int) Math.abs(start.x - end.x),
                 (int) Math.abs(start.y - end.y)
                 );
         
         elem.setAttribute("shape", "rect");
         elem.setAttribute("coords",
                 r.x + ","+
                 r.y + ","+
                 (r.x + r.width) + ","+
                 (r.y + r.height)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(r);
     } else {
         return writePolyAttributes(elem, f, (Shape) rect);
     }
 }
 /**
  * Returns the coordinates and type of the current path segment in the iteration. The return value
  * is the path segment type: SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. A
  * double array of length 6 must be passed in and may be used to store the coordinates of the
  * point(s). Each point is stored as a pair of double x,y coordinates. SEG_MOVETO and SEG_LINETO
  * types will return one point, SEG_QUADTO will return two points, SEG_CUBICTO will return 3
  * points and SEG_CLOSE will not return any points.
  *
  * @see #SEG_MOVETO
  * @see #SEG_LINETO
  * @see #SEG_QUADTO
  * @see #SEG_CUBICTO
  * @see #SEG_CLOSE
  */
 public int currentSegment(double[] coords) {
   if (isDone()) {
     throw new NoSuchElementException("roundrect iterator out of bounds");
   }
   double ctrls[] = ctrlpts[index];
   int nc = 0;
   for (int i = 0; i < ctrls.length; i += 4) {
     coords[nc++] = (x + ctrls[i + 0] * w + ctrls[i + 1] * aw);
     coords[nc++] = (y + ctrls[i + 2] * h + ctrls[i + 3] * ah);
   }
   if (affine != null) {
     affine.transform(coords, 0, coords, 0, nc / 2);
   }
   return types[index];
 }
Example #12
0
 public void vec2FieldMagnitude(Field field, AffineTransform ftoi) {
   AffineTransform itof = null;
   try {
     itof = ftoi.createInverse();
   } catch (NoninvertibleTransformException niv) {
     TDebug.println(0, "NoninvertibleTransformException: " + niv);
   }
   Vector3d v = new Vector3d();
   Point2D.Double p = new Point2D.Double();
   for (int j = 0, k = 0; j < height; ++j)
     for (int i = 0; i < width; ++i, ++k) {
       p.x = i;
       p.y = j;
       itof.transform(p, p);
       v = field.get(p.x, p.y, 0.0);
       f[k] = (float) Math.sqrt(v.x * v.x + v.y * v.y);
     }
 }
Example #13
0
 public void vec2FieldZero(Field field, AffineTransform ftoi) {
   AffineTransform itof = null;
   try {
     itof = ftoi.createInverse();
   } catch (NoninvertibleTransformException niv) {
     TDebug.println(0, "NoninvertibleTransformException: " + niv);
   }
   Vector3d v = new Vector3d();
   Point2D.Double p = new Point2D.Double();
   for (int j = 0, k = 0; j < height; ++j)
     for (int i = 0; i < width; ++i, ++k) {
       p.x = i;
       p.y = j;
       itof.transform(p, p);
       v = field.get(p.x, p.y, 0.0);
       if ((v.x == 0.0) && (v.y == 0.0)) f[k] = 1.0f;
       else f[k] = 0.0f;
     }
 }
Example #14
0
 // SHAPE AND BOUNDS
 @Override
 public void transform(AffineTransform tx) {
   tx.transform(origin, origin);
 }