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);
 }
 private Paint decodeGradient10(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.5f * w) + x,
       (0.0f * h) + y,
       (0.5f * w) + x,
       (1.0f * h) + y,
       new float[] {0.0f, 0.024f, 0.06f, 0.276f, 0.6f, 0.65f, 0.7f, 0.856f, 0.96f, 0.98f, 1.0f},
       new Color[] {
         (Color) componentColors[0],
         decodeColor((Color) componentColors[0], (Color) componentColors[1], 0.5f),
         (Color) componentColors[1],
         decodeColor((Color) componentColors[1], (Color) componentColors[2], 0.5f),
         (Color) componentColors[2],
         decodeColor((Color) componentColors[2], (Color) componentColors[2], 0.5f),
         (Color) componentColors[2],
         decodeColor((Color) componentColors[2], (Color) componentColors[3], 0.5f),
         (Color) componentColors[3],
         decodeColor((Color) componentColors[3], (Color) componentColors[3], 0.5f),
         (Color) componentColors[3]
       });
 }
 private Paint decodeGradient6(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.5f * w) + x,
       (0.0f * h) + y,
       (0.5f * w) + x,
       (1.0f * h) + y,
       new float[] {0.0f, 0.03f, 0.06f, 0.33f, 0.6f, 0.65f, 0.7f, 0.825f, 0.95f, 0.975f, 1.0f},
       new Color[] {
         color28,
         decodeColor(color28, color29, 0.5f),
         color29,
         decodeColor(color29, color30, 0.5f),
         color30,
         decodeColor(color30, color30, 0.5f),
         color30,
         decodeColor(color30, color31, 0.5f),
         color31,
         decodeColor(color31, color32, 0.5f),
         color32
       });
 }
Example #4
0
 public float getPreferredSpan(int axis) {
   switch (axis) {
     case View.X_AXIS:
       return (float) bounds.getWidth();
     case View.Y_AXIS:
       return (float) bounds.getHeight();
     default:
       throw new IllegalArgumentException("Invalid axis: " + axis);
   }
 }
 private Paint decodeGradient13(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.5f * w) + x,
       (0.0f * h) + y,
       (0.5f * w) + x,
       (1.0f * h) + y,
       new float[] {0.26047903f, 0.6302395f, 1.0f},
       new Color[] {color62, decodeColor(color62, color63, 0.5f), color63});
 }
 private Paint decodeGradient4(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.5f * w) + x,
       (0.0f * h) + y,
       (0.5f * w) + x,
       (1.0f * h) + y,
       new float[] {0.0f, 0.1684492f, 1.0f},
       new Color[] {color10, decodeColor(color10, color11, 0.5f), color11});
 }
 private Paint decodeGradient3(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.5f * w) + x,
       (0.0f * h) + y,
       (0.5f * w) + x,
       (1.0f * h) + y,
       new float[] {0.0f, 0.49573863f, 0.99147725f},
       new Color[] {color8, decodeColor(color8, color9, 0.5f), color9});
 }
 private Paint decodeGradient5(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.5f * w) + x,
       (0.0f * h) + y,
       (0.5f * w) + x,
       (1.0f * h) + y,
       new float[] {0.1f, 0.49999997f, 0.9f},
       new Color[] {color7, decodeColor(color7, color8, 0.5f), color8});
 }
Example #9
0
 public void paint(Graphics g, Shape a) {
   Graphics2D g2 = (Graphics2D) g;
   Rectangle2D abounds = a.getBounds2D();
   AffineTransform saveTransform = g2.getTransform();
   Paint savePaint = g2.getPaint();
   try {
     g2.translate(abounds.getX() - bounds.getX(), abounds.getY() - bounds.getY());
     g2.setPaint(Color.BLACK); // FIXME
     p.paint(g2);
   } finally {
     g2.setTransform(saveTransform);
     g2.setPaint(savePaint);
   }
 }
 private Paint decodeGradient10(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.24868421f * w) + x,
       (0.0014705883f * h) + y,
       (0.24868421f * w) + x,
       (1.0f * h) + y,
       new float[] {0.0f, 0.5f, 1.0f},
       new Color[] {color48, decodeColor(color48, color49, 0.5f), color49});
 }
 private Paint decodeGradient9(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.5f * w) + x,
       (0.0f * h) + y,
       (0.5f * w) + x,
       (1.0f * h) + y,
       new float[] {0.09f, 0.52f, 0.95f},
       new Color[] {color39, decodeColor(color39, color40, 0.5f), color40});
 }
 private Paint decodeGradient2(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.25f * w) + x,
       (0.0f * h) + y,
       (0.25441176f * w) + x,
       (1.0016667f * h) + y,
       new float[] {0.0f, 0.5f, 1.0f},
       new Color[] {color3, decodeColor(color3, color2, 0.5f), color2});
 }
Example #13
0
  /**
   * Render the View to the given graphic context. This implementation render the interior first,
   * then the outline.
   */
  public void paint(Graphics2D g, Rectangle2D a) {
    if (!a.intersects(getBounds())) return;
    if (image != null) { // paint bitmap
      g.drawImage(image, text2ModelTr, null);
      // debug:
      g.setPaint(Color.red);
      g.draw(this.bounds);
      super.paint(g, a); // possibly paint framebox if non-null
    } else { // paint textlayout
      super.paint(g, a); // possibly paint framebox if non-null

      AffineTransform oldAT = g.getTransform();
      // paint text in black
      g.setPaint(Color.black);
      // from now on, we work in Y-direct (<0) coordinates to avoid inextricable problems with font
      // being mirrored...
      g.transform(text2ModelTr); // also include rotation
      textLayout.draw(g, 0.0f, 0.0f);
      // [pending] ajouter un cadre si areDimensionsComputed (wysiwyg du pauvre)
      // get back to previous transform
      g.setTransform(oldAT);
      if (DEBUG) {
        g.setPaint(Color.red);
        g.draw(bounds);
      }
    }
  }
 private Rectangle2D decodeRect2() {
   rect.setRect(
       decodeX(1.2165072f), // x
       decodeY(1.2790405f), // y
       decodeX(1.6746411f) - decodeX(1.2165072f), // width
       decodeY(1.3876263f) - decodeY(1.2790405f)); // height
   return rect;
 }
 private Rectangle2D decodeRect10() {
   rect.setRect(
       decodeX(1.7918661f), // x
       decodeY(1.7752526f), // y
       decodeX(1.8349283f) - decodeX(1.7918661f), // width
       decodeY(1.4217172f) - decodeY(1.7752526f)); // height
   return rect;
 }
 private Rectangle2D decodeRect9() {
   rect.setRect(
       decodeX(1.3815789f), // x
       decodeY(1.6111112f), // y
       decodeX(1.4366028f) - decodeX(1.3815789f), // width
       decodeY(1.7739899f) - decodeY(1.6111112f)); // height
   return rect;
 }
 private Rectangle2D decodeRect8() {
   rect.setRect(
       decodeX(1.5645933f), // x
       decodeY(1.4078283f), // y
       decodeX(1.7870812f) - decodeX(1.5645933f), // width
       decodeY(1.5239899f) - decodeY(1.4078283f)); // height
   return rect;
 }
 private Rectangle2D decodeRect6() {
   rect.setRect(
       decodeX(1.3684211f), // x
       decodeY(1.6111112f), // y
       decodeX(1.4210527f) - decodeX(1.3684211f), // width
       decodeY(1.7777778f) - decodeY(1.6111112f)); // height
   return rect;
 }
 private Rectangle2D decodeRect5() {
   rect.setRect(
       decodeX(1.6267943f), // x
       decodeY(1.3888888f), // y
       decodeX(1.673445f) - decodeX(1.6267943f), // width
       decodeY(1.6085858f) - decodeY(1.3888888f)); // height
   return rect;
 }
 private Rectangle2D decodeRect4() {
   rect.setRect(
       decodeX(1.2643541f), // x
       decodeY(1.5542929f), // y
       decodeX(1.6315789f) - decodeX(1.2643541f), // width
       decodeY(1.5997474f) - decodeY(1.5542929f)); // height
   return rect;
 }
 private Rectangle2D decodeRect6() {
   rect.setRect(
       decodeX(0.22222222f), // x
       decodeY(0.13333334f), // y
       decodeX(2.916668f) - decodeX(0.22222222f), // width
       decodeY(2.75f) - decodeY(0.13333334f)); // height
   return rect;
 }
 private Rectangle2D decodeRect3() {
   rect.setRect(
       decodeX(1.2212919f), // x
       decodeY(1.6047981f), // y
       decodeX(1.270335f) - decodeX(1.2212919f), // width
       decodeY(1.3876263f) - decodeY(1.6047981f)); // height
   return rect;
 }
 private Rectangle2D decodeRect7() {
   rect.setRect(
       decodeX(1.4389952f), // x
       decodeY(1.7209597f), // y
       decodeX(1.7882775f) - decodeX(1.4389952f), // width
       decodeY(1.7765152f) - decodeY(1.7209597f)); // height
   return rect;
 }
 private Rectangle2D decodeRect1() {
   rect.setRect(
       decodeX(0.0f), // x
       decodeY(0.0f), // y
       decodeX(3.0f) - decodeX(0.0f), // width
       decodeY(3.0f) - decodeY(0.0f)); // height
   return rect;
 }
 private Rectangle2D decodeRect11() {
   rect.setRect(
       decodeX(0.6f), // x
       decodeY(2.4f), // y
       decodeX(2.4f) - decodeX(0.6f), // width
       decodeY(2.6f) - decodeY(2.4f)); // height
   return rect;
 }
 private Rectangle2D decodeRect6() {
   rect.setRect(
       decodeX(2.0f), // x
       decodeY(1.0f), // y
       decodeX(2.3333333f) - decodeX(2.0f), // width
       decodeY(2.0f) - decodeY(1.0f)); // height
   return rect;
 }
Example #27
0
  public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    String message = "Hello, World!";

    Font f = new Font("Serif", Font.BOLD, 36);
    g2.setFont(f);

    FontRenderContext context = g2.getFontRenderContext();
    Rectangle2D bounds = f.getStringBounds(message, context);

    double x = (getWidth() - bounds.getWidth()) / 2;
    double y = (getHeight() - bounds.getHeight()) / 2;

    double ascent = -bounds.getY();
    double baseY = y + ascent;

    g2.drawString(message, (int) x, (int) baseY);

    g2.setPaint(Color.LIGHT_GRAY);

    g2.draw(new Line2D.Double(x, baseY, x + bounds.getWidth(), baseY));
    Rectangle2D rect = new Rectangle2D.Double(x, y, bounds.getWidth(), bounds.getHeight());
    g2.draw(rect);
  }
 private Paint decodeGradient4(Shape s) {
   Rectangle2D bounds = s.getBounds2D();
   float x = (float) bounds.getX();
   float y = (float) bounds.getY();
   float w = (float) bounds.getWidth();
   float h = (float) bounds.getHeight();
   return decodeGradient(
       (0.5f * w) + x,
       (0.0f * h) + y,
       (0.5f * w) + x,
       (1.0f * h) + y,
       new float[] {0.1f, 0.49999997f, 0.9f},
       new Color[] {
         (Color) componentColors[0],
         decodeColor((Color) componentColors[0], (Color) componentColors[1], 0.5f),
         (Color) componentColors[1]
       });
 }
Example #29
0
 @Override
 public Rectangle2D.Double getDrawingArea() {
   if (cachedDrawingArea == null) {
     Rectangle2D rx = getBounds();
     Rectangle2D.Double r =
         (rx instanceof Rectangle2D.Double)
             ? (Rectangle2D.Double) rx
             : new Rectangle2D.Double(rx.getX(), rx.getY(), rx.getWidth(), rx.getHeight());
     double g = SVGAttributeKeys.getPerpendicularHitGrowth(this);
     Geom.grow(r, g, g);
     if (TRANSFORM.get(this) == null) {
       cachedDrawingArea = r;
     } else {
       cachedDrawingArea = new Rectangle2D.Double();
       cachedDrawingArea.setRect(TRANSFORM.get(this).createTransformedShape(r).getBounds2D());
     }
   }
   return (Rectangle2D.Double) cachedDrawingArea.clone();
 }
Example #30
0
  /** Synchronizes bounding box with the model ; */
  protected void syncBounds() {
    PicText te = (PicText) element;
    // [pending] Il faut tenir compte de la rotation !

    Rectangle2D latexBB =
        null; // BB relative to latex dimensions (including rotation) (without frame)
    Rectangle2D textLayoutBB =
        null; // BB relative to textLayout dimensions (including rotation) (without frame)
    Rectangle2D textBB = null; // BB of the text (including rotation), without frame

    if (areDimensionsComputed) { // compute latexBB
      Rectangle2D nonRotated =
          new Rectangle2D.Double(
              te.getLeftX(), te.getBottomY(), te.getWidth(), te.getHeight() + te.getDepth());
      AffineTransform tr =
          new AffineTransform(); // maps Image coordinates to Model coordinates (see paint)
      tr.setToIdentity(); // reset
      PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf);
      tr.rotate(getRotation(), anchor.x, anchor.y); // rotate along P_ANCHOR !
      latexBB = tr.createTransformedShape(nonRotated).getBounds2D();
    }

    if (image == null) { // compute textLayoutBB
      Rectangle2D nonRotated = textLayout.getBounds();
      textLayoutBB = text2ModelTr.createTransformedShape(nonRotated).getBounds2D();
    }

    // use textLayoutBB or latexBB or their union
    if (image != null) textBB = latexBB;
    else {
      if (!areDimensionsComputed) textBB = textLayoutBB;
      else {
        textBB = latexBB.createUnion(textLayoutBB);
      }
    }

    // union with frame BB
    if (te.isFramed()) {
      super.syncBounds(); // update bounds of the frame if necessary
      Rectangle2D.union(super.bounds, textBB, this.bounds);
    } else this.bounds = textBB;
  }