private GeneralPath getVectorShape(VisualEdge e) {
    Vec2 fromPos = e.getFrom().getVisibleAncestor().getPos();
    Vec2 toPos = e.getTo().getVisibleAncestor().getPos();

    // toPos = toPos.plus(toPos.scaled(1 / toPos.length() * 10.0)); // to make it longer
    Vec2 curveCenter = e.getPos();

    double px = 2 * (curveCenter.x - 0.25 * fromPos.x - 0.25 * toPos.x);
    double py = 2 * (curveCenter.y - 0.25 * fromPos.y - 0.25 * toPos.y);

    Vec2 endNormal = toPos.scaled(1 / toPos.length()).normal();
    Vec2 endLeft = toPos.minus(endNormal.scaled(3.0)); // increase to widen vector heads
    Vec2 endRight = toPos.plus(endNormal.scaled(3.0));

    GeneralPath path = new GeneralPath();

    path.moveTo(fromPos.toPoint().getX(), fromPos.toPoint().getY());
    path.quadTo(px, py, endLeft.toPoint().getX(), endLeft.toPoint().getY());

    path.lineTo(endRight.toPoint().getX(), endRight.toPoint().getY());
    path.quadTo(px, py, fromPos.toPoint().getX(), fromPos.toPoint().getY());

    path.closePath();
    return path;
  }
  /**
   * Returns the outline of in-ribbon gallery.
   *
   * @param startX Start X of the in-ribbon gallery.
   * @param endX End X of the in-ribbon gallery.
   * @param topY Top Y of the in-ribbon gallery.
   * @param bottomY Bottom Y of the in-ribbon gallery.
   * @param radius Corner radius.
   * @return The outline of in-ribbon gallery.
   */
  public static GeneralPath getRibbonGalleryOutline(
      int startX, int endX, int topY, int bottomY, float radius) {

    int height = bottomY - topY;
    GeneralPath result = new GeneralPath();
    float radius3 = (float) (radius / (1.5 * Math.pow(height, 0.5)));

    // start in the top left corner at the end of the curve
    result.moveTo(startX + radius, topY);

    // move to the top right corner and curve down
    result.lineTo(endX - radius - 1, topY);
    result.quadTo(endX - radius3 - 1, topY + radius3, endX - 1, topY + radius);

    // move to the bottom right corner and curve left
    result.lineTo(endX - 1, bottomY - radius - 1);
    result.quadTo(endX - radius3 - 1, bottomY - 1 - radius3, endX - radius - 1, bottomY - 1);

    // move to the bottom left corner and curve up
    result.lineTo(startX + radius, bottomY - 1);
    result.quadTo(startX + radius3, bottomY - 1 - radius3, startX, bottomY - radius - 1);

    // move to the top left corner and curve right
    result.lineTo(startX, topY + radius);
    result.quadTo(startX + radius3, topY + radius3, startX + radius, topY);

    return result;
  }
Ejemplo n.º 3
0
 private Shape createTabShape(int x, int y, int w, int h) {
   GeneralPath shape = new GeneralPath();
   shape.moveTo(x, y + h);
   shape.lineTo(x, y + OFFSET);
   shape.quadTo(x, y + OFFSET, x + OFFSET, y);
   shape.lineTo(x + w - OFFSET, y);
   shape.quadTo(x + w - OFFSET, y, x + w, y + OFFSET);
   shape.lineTo(x + w, y + h);
   shape.closePath();
   return shape;
 }
Ejemplo n.º 4
0
  public static GeneralPath createArrowLine(double x0, double y0, double x1, double y1) {

    float theta = (float) Math.atan((double) (y1 - y0) / (double) (x1 - x0));
    float len = (float) Math.sqrt(Math.pow((x1 - x0), 2) + Math.pow((y1 - y0), 2));
    float side = (x1 < x0) ? -1 : 1;

    // Ideally, we should use a fixed distance from the end point,
    // rather than try and calculate a percentage, as that mucks it up
    // for shorter lengths...The easiest way would be to "draw" a
    // circle around the point (x1,y1) and then compute the
    // line-circle intersection point.  I'm too lazy to do the math
    // right now, though...

    GeneralPath gp = new GeneralPath();
    gp.reset();
    gp.moveTo((float) x0, (float) y0);
    gp.lineTo((float) (x0 + ((x1 - x0) * 0.9725f)), (float) (y0 + ((y1 - y0) * 0.9725f)));
    gp.moveTo((float) x1, (float) y1);
    gp.lineTo(
        (float) (x1 - side * ALEN * (float) Math.cos(theta + AANG)),
        (float) (y1 - side * ALEN * (float) Math.sin(theta + AANG)));
    gp.quadTo(
        (float) (x0 + ((x1 - x0) * 0.9725f)),
        (float) (y0 + ((y1 - y0) * 0.9725f)),
        (float) (x1 - side * ALEN * Math.cos(theta - AANG)),
        (float) (y1 - side * ALEN * Math.sin(theta - AANG)));
    gp.closePath();
    return gp;
  }
Ejemplo n.º 5
0
  @Override
  public void setPosition(Pointt position) {
    super.setPosition(position);
    generatePaint();
    double startAngle = Maths.randomAngle();
    GeneralPath tempRep = new GeneralPath();

    Pointt next = new Pointt(0, 0);
    for (int i = 0; i < vertices.length; i++) {
      vertices[i] =
          next.getArcPointt(
              radius() * Geometry.DISPLAY_REAL_RATIO,
              startAngle + i * 2 * (Math.PI / NUMBER_OF_VERTICES));
    }

    tempRep.moveTo(vertices[0].getX(), vertices[0].getY());

    for (int i = 0; i < vertices.length; i++) {
      next = vertices[(i + 1) % vertices.length];
      tempRep.quadTo(
          vertices[i].midPoint(next).getX()
              + Maths.randomNegative(radius() * Geometry.DISPLAY_REAL_RATIO / 2),
          vertices[i].midPoint(next).getY()
              + Maths.randomNegative(radius() * Geometry.DISPLAY_REAL_RATIO / 2),
          next.getX(),
          next.getY());
    }

    tempRep.closePath();
    rep = new Area(tempRep);

    for (int i = 0; i < vertices.length; i++) {
      vertices[i].translate(position);
    }
  }
Ejemplo n.º 6
0
  // public void appendPath(ExtendedGeneralPath path, BuildHistory hist)
  public void appendPath(GeneralPath path, BuildHistory hist) {
    float offx = isRelative ? hist.lastPoint.x : 0f;
    float offy = isRelative ? hist.lastPoint.y : 0f;

    path.quadTo(kx + offx, ky + offy, x + offx, y + offy);
    hist.setLastPoint(x + offx, y + offy);
    hist.setLastKnot(kx + offx, ky + offy);
  }
Ejemplo n.º 7
0
 /**
  * Returns a shape whose stroke and fill will give the impression of a "torn tape" sort of
  * structure. The point <CODE>(x,y)</CODE> will be the upper left corner of the torn tape, the
  * structure will be completely enclosed in the bounds <CODE>(x,y,x+width,x+height)</CODE>.
  *
  * @param width the width of the torn tape
  * @param x the <I>x</I> coordinate of the torn
  * @param y the <I>y</I> coordinate of the torn
  * @param height the height of the torn tape
  * @param left <CODE>true</CODE> if this tape is "torn" on the left end
  * @param right <CODE>true</CODE> if this tape is "torn" on the right end
  */
 public static GeneralPath getTorn(
     float x, float y, float width, float height, boolean left, boolean right) {
   GeneralPath path = new GeneralPath();
   path.moveTo(x, y);
   path.lineTo(x + width, y);
   if (right) {
     path.quadTo(x + width - height / 4.0f, y + height / 4.0f, x + width, y + height / 2.0f);
     path.quadTo(x + width - height / 4.0f, y + 3.0f * height / 4.0f, x + width, y + height);
   } else path.lineTo(x + width, y + height);
   path.lineTo(x, y + height);
   if (left) {
     path.quadTo(x + height / 4.0f, y + 3.0f * height / 4.0f, x, y + height / 2.0f);
     path.quadTo(x + height / 4.0f, y + height / 4.0f, x, y);
   }
   path.closePath();
   return path;
 }
 public Shape getShape() {
   Line2D line = getConnectionPoints();
   Point2D control = getControlPoint();
   GeneralPath p = new GeneralPath();
   p.moveTo((float) line.getX1(), (float) line.getY1());
   p.quadTo(
       (float) control.getX(), (float) control.getY(), (float) line.getX2(), (float) line.getY2());
   return p;
 }
Ejemplo n.º 9
0
 public void quadTo(double x1, double y1, double x2, double y2) {
   if (currentPath != null) {
     currentPath.quadTo(
         (float) ((state.dx + x1) * state.scale),
         (float) ((state.dy + y1) * state.scale),
         (float) ((state.dx + x2) * state.scale),
         (float) ((state.dy + y2) * state.scale));
   }
 }
  /**
   * Returns the clip area of a task toggle button in ribbon component.
   *
   * @param width Toggle tab button width.
   * @param height Toggle tab button height.
   * @param radius Toggle tab button corner radius.
   * @return Clip area of a toggle tab button in ribbon component.
   */
  public static GeneralPath getRibbonTaskToggleButtonOutline(int width, int height, float radius) {
    GeneralPath result = new GeneralPath();
    float radius3 = (float) (radius / (1.5 * Math.pow(height, 0.5)));

    // start at the bottom left
    result.moveTo(0, height);

    // move to the top start and curve right
    result.lineTo(0, radius);
    result.quadTo(radius3, radius3, radius, 0);

    // move to the top end and curve down
    result.lineTo(width - radius - 1, 0);
    result.quadTo(width + radius3 - 1, radius3, width - 1, radius);

    // move to the bottom right end
    result.lineTo(width - 1, height);

    // move to the bottom left end
    result.lineTo(0, height);

    return result;
  }
Ejemplo n.º 11
0
  /**
   * Get the shape that defines this geometry object. If any of the sites have been translated since
   * this shape was set, a new shape will be produced and returned.
   */
  public Shape getShape() {
    if (_path == null) {
      GeneralPath p = new GeneralPath(GeneralPath.WIND_NON_ZERO, _vertexCount + 2);
      int c = 0;

      for (int i = 0; i < _vertexCount; i++) {
        switch (_type[i]) {
          case PathIterator.SEG_CLOSE:
            p.closePath();
            break;

          case PathIterator.SEG_MOVETO:
            p.moveTo(_coordinate[c], _coordinate[c + 1]);
            c += 2;
            break;

          case PathIterator.SEG_LINETO:
            p.lineTo(_coordinate[c], _coordinate[c + 1]);
            c += 2;
            break;

          case PathIterator.SEG_QUADTO:
            p.quadTo(_coordinate[c], _coordinate[c + 1], _coordinate[c + 2], _coordinate[c + 3]);
            c += 4;
            break;

          case PathIterator.SEG_CUBICTO:
            p.curveTo(
                _coordinate[c],
                _coordinate[c + 1],
                _coordinate[c + 2],
                _coordinate[c + 3],
                _coordinate[c + 4],
                _coordinate[c + 5]);
            c += 6;
            break;
        }
      }

      _path = p;
    }

    return _path;
  }
Ejemplo n.º 12
0
 private GeneralPath getGeneralPath(Shape shape) {
   GeneralPath gp = new GeneralPath();
   for (PointFormat pf : shape.getDrawCmds()) {
     if (PointType.MOVE.equals(pf.getPointType())) {
       gp.moveTo(pf.getPosX1(), pf.getPosY1());
     } else if (PointType.LINE.equals(pf.getPointType())) {
       gp.lineTo(pf.getPosX1(), pf.getPosY1());
     } else if (PointType.QUAD.equals(pf.getPointType())) {
       gp.quadTo(pf.getPosX1(), pf.getPosY1(), pf.getPosX2(), pf.getPosY2());
     } else if (PointType.CURVE.equals(pf.getPointType())) {
       gp.curveTo(
           pf.getPosX1(),
           pf.getPosY1(),
           pf.getPosX2(),
           pf.getPosY2(),
           pf.getPosX3(),
           pf.getPosY3());
     }
   }
   return gp;
 }
Ejemplo n.º 13
0
  @Override
  public void readConstructorParams(DataInput in) throws IOException {
    super.readConstructorParams(in);

    String fontName = in.readUTF();
    int style = in.readInt();
    int size = in.readInt();
    font = new Font(fontName, style, size);

    tesselationTolerance = in.readDouble();

    GeneralPath shape = null;
    int segType = in.readInt();
    while (segType != Integer.MIN_VALUE) {
      if (shape == null) shape = new GeneralPath();

      if (segType == PathIterator.SEG_MOVETO) {
        shape.moveTo(in.readFloat(), in.readFloat());
      } else if (segType == PathIterator.SEG_LINETO) {
        shape.lineTo(in.readFloat(), in.readFloat());
      } else if (segType == PathIterator.SEG_QUADTO) {
        shape.quadTo(in.readFloat(), in.readFloat(), in.readFloat(), in.readFloat());
      } else if (segType == PathIterator.SEG_CUBICTO) {
        shape.curveTo(
            in.readFloat(),
            in.readFloat(),
            in.readFloat(),
            in.readFloat(),
            in.readFloat(),
            in.readFloat());
      } else if (segType == PathIterator.SEG_CLOSE) {
        shape.closePath();
      }

      segType = in.readInt();
    }
    if (shape != null) extrudePath = new FontExtrusion(shape, in.readDouble());
    else extrudePath = null;
  }
Ejemplo n.º 14
0
  public void paint(Graphics2D g) {
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g.setPaint(Color.black);

    // Rectangle
    g.drawString("Rectangle", 10, 20);
    Rectangle rect = new Rectangle(10, 30, 50, 40);
    g.draw(rect);

    g.translate(0, 90);

    // Round Rectangle
    g.drawString("RoundRectangle", 10, 20);
    RoundRectangle2D roundRect = new RoundRectangle2D.Double(10, 30, 50, 40, 10, 10);
    g.draw(roundRect);

    g.translate(0, 90);

    // Circle
    g.drawString("Circle", 10, 20);
    Ellipse2D circle = new Ellipse2D.Float(10, 30, 50, 50);
    g.draw(circle);

    g.translate(0, 90);

    // CubicCurve2D
    g.drawString("CubicCurve2D", 10, 20);
    CubicCurve2D curve = new CubicCurve2D.Float(10, 55, 22.5f, 00, 38.5f, 110, 60, 55);
    g.draw(curve);

    g.translate(150, -270);

    // Polygon
    g.drawString("Polygon", 10, 20);
    Polygon polygon = new Polygon(new int[] {30, 50, 10}, new int[] {30, 60, 60}, 3);
    g.draw(polygon);

    g.translate(0, 90);

    // General Path
    g.drawString("GeneralPath", 10, 20);
    GeneralPath path = new GeneralPath();
    path.moveTo(30, 30);
    path.quadTo(30, 50, 50, 60);
    path.quadTo(30, 50, 10, 60);
    path.quadTo(30, 50, 30, 30);
    path.closePath();
    g.draw(path);

    g.translate(0, 90);

    // Area
    g.drawString("Area", 10, 20);
    Area area = new Area(new Rectangle(10, 30, 50, 50));
    area.subtract(new Area(new Ellipse2D.Double(12, 32, 46, 46)));
    g.fill(area);

    g.translate(0, 90);

    // QuadCurve 2D
    g.drawString("QuadCurve2D", 10, 20);
    QuadCurve2D quad = new QuadCurve2D.Float(10, 55, 35, 105, 60, 55);
    g.draw(quad);

    g.translate(-75, 70);

    // Line
    g.drawString("Line2D", 10, 20);
    g.draw(new Line2D.Float(10, 30, 60, 30));
  }
Ejemplo n.º 15
0
  /**
   * Appends path gp2 to gp1. Taken from pre-redesign code.
   *
   * @param reversed is true if the segments are added in reverse order
   */
  public static void appendPath(GeneralPath gp1, GeneralPath gp2, boolean reversed) {
    ArrayList<Number[]> points =
        new ArrayList<
            Number[]>(); // Each element is an array consisting of one Integer and six Floats

    PathIterator i = gp2.getPathIterator(new AffineTransform());

    float[] segment = new float[] {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};

    float leftmost = Float.POSITIVE_INFINITY;

    while (!i.isDone()) {
      int type = i.currentSegment(segment);
      i.next();

      points.add(
          new Number[] {
            new Integer(type),
            new Float(segment[0]),
            new Float(segment[1]),
            new Float(segment[2]),
            new Float(segment[3]),
            new Float(segment[4]),
            new Float(segment[5])
          });
    }

    if (reversed) {
      float deltaX = (float) gp1.getCurrentPoint().getX();
      float deltaY = (float) gp1.getCurrentPoint().getY();

      Object[] typeAndPoints = points.get(points.size() - 1);

      int type = ((Integer) typeAndPoints[0]).intValue();

      if (type == PathIterator.SEG_LINETO) {
        deltaX -= ((Float) typeAndPoints[1]).floatValue();
        deltaY -= ((Float) typeAndPoints[2]).floatValue();
      } else if (type == PathIterator.SEG_QUADTO) {
        deltaX -= ((Float) typeAndPoints[3]).floatValue();
        deltaY -= ((Float) typeAndPoints[4]).floatValue();
      } else if (type == PathIterator.SEG_CUBICTO) {
        deltaX -= ((Float) typeAndPoints[5]).floatValue();
        deltaY -= ((Float) typeAndPoints[6]).floatValue();
      } else {
        assert false : type;
      }

      for (int j = points.size() - 1; j >= 1; j--) {
        typeAndPoints = points.get(j);

        type = ((Integer) typeAndPoints[0]).intValue();
        float x1 = ((Float) typeAndPoints[1]).floatValue();
        float y1 = ((Float) typeAndPoints[2]).floatValue();
        float x2 = ((Float) typeAndPoints[3]).floatValue();
        float y2 = ((Float) typeAndPoints[4]).floatValue();

        float prevX = 0.0f, prevY = 0.0f;

        int prevType = ((Integer) points.get(j - 1)[0]).intValue();

        if ((prevType == PathIterator.SEG_MOVETO) || (prevType == PathIterator.SEG_LINETO)) {
          prevX = ((Float) points.get(j - 1)[1]).floatValue();
          prevY = ((Float) points.get(j - 1)[2]).floatValue();
        } else if (prevType == PathIterator.SEG_QUADTO) {
          prevX = ((Float) points.get(j - 1)[3]).floatValue();
          prevY = ((Float) points.get(j - 1)[4]).floatValue();
        } else if (prevType == PathIterator.SEG_CUBICTO) {
          prevX = ((Float) points.get(j - 1)[5]).floatValue();
          prevY = ((Float) points.get(j - 1)[6]).floatValue();
        } else {
          assert false : prevType;
        }

        leftmost = Math.min(leftmost, prevX + deltaX);

        if ((type == PathIterator.SEG_MOVETO) || (type == PathIterator.SEG_LINETO)) {
          gp1.lineTo(prevX + deltaX, prevY + deltaY);
        } else if (type == PathIterator.SEG_QUADTO) {
          gp1.quadTo(x1 + deltaX, y1 + deltaY, prevX + deltaX, prevY + deltaY);
        } else if (type == PathIterator.SEG_CUBICTO) {
          gp1.curveTo(
              x2 + deltaX, y2 + deltaY, x1 + deltaX, y1 + deltaY, prevX + deltaX, prevY + deltaY);
        } else {
          assert false : type;
        }
      }
    } else // Not reversed
    {
      float deltaX = (float) gp1.getCurrentPoint().getX() - ((Float) points.get(0)[1]).floatValue();
      float deltaY = (float) gp1.getCurrentPoint().getY() - ((Float) points.get(0)[2]).floatValue();

      for (int j = 1; j < points.size(); j++) {
        Object[] typeAndPoints = points.get(j);

        int type = ((Integer) typeAndPoints[0]).intValue();
        float x1 = ((Float) typeAndPoints[1]).floatValue();
        float y1 = ((Float) typeAndPoints[2]).floatValue();
        float x2 = ((Float) typeAndPoints[3]).floatValue();
        float y2 = ((Float) typeAndPoints[4]).floatValue();
        float x3 = ((Float) typeAndPoints[5]).floatValue();
        float y3 = ((Float) typeAndPoints[6]).floatValue();

        if (type == PathIterator.SEG_MOVETO) {
        } else if (type == PathIterator.SEG_LINETO) {
          gp1.lineTo(x1 + deltaX, y1 + deltaY);

          leftmost = Math.min(leftmost, x1 + deltaX);
        } else if (type == PathIterator.SEG_QUADTO) {
          gp1.quadTo(x1 + deltaX, y1 + deltaY, x2 + deltaX, y2 + deltaY);

          leftmost = Math.min(leftmost, x2 + deltaX);
        } else if (type == PathIterator.SEG_CUBICTO) {
          gp1.curveTo(x1 + deltaX, y1 + deltaY, x2 + deltaX, y2 + deltaY, x3 + deltaX, y3 + deltaY);

          leftmost = Math.min(leftmost, x3 + deltaX);
        } else {
          assert false : type;
        }
      }
    }
  }
Ejemplo n.º 16
0
  private void scan(Graphics2D g, InputStream input) throws IOException {
    Set<String> unknownC = new HashSet<String>();
    Pattern tab = Pattern.compile("[\t]");
    LineIterator in = new LineIteratorImpl(LineReaderUtil.fromBufferedStream(input));
    while (in.hasNext()) {
      String line = in.next();
      String tokens[] = tab.split(line, 5);
      if (tokens.length < 4) {
        warning("Ignoring " + line);
        continue;
      }
      SAMSequenceRecord rec = this.context.getDictionary().getSequence(tokens[0]);
      if (rec == null) {
        warning("unknown chromosome " + tokens[0]);
        continue;
      }
      String country = tokens[3].toLowerCase().replaceAll("[ ]", "");
      Shape shape = this.country2shape.get(country);
      if (shape == null) {
        if (!unknownC.contains(country)) {
          unknownC.add(country);
          warning("unknown country " + country);
        }
        continue;
      }
      seen.incr(country);
      int midpos = (Integer.parseInt(tokens[1]) + Integer.parseInt(tokens[2])) / 2;
      // country center
      Point2D.Double pt1 =
          new Point2D.Double(shape.getBounds2D().getCenterX(), shape.getBounds2D().getCenterY());
      // circle point
      Point2D pt3 = this.context.convertPositionToPoint(tokens[0], midpos, getRadiusInt());
      double angle = this.context.convertPositionToRadian(rec, midpos);
      double angle2 = angle -= Math.PI / 10.0;

      double distance13 =
          context
              .getCenter()
              .distance(
                  new Point2D.Double(
                      (pt1.getX() + pt3.getX()) / 2.0, (pt1.getY() + pt3.getY()) / 2.0));
      // mid point
      Point2D pt2 =
          new Point2D.Double(
              context.getCenterX() + distance13 * Math.cos(angle2),
              context.getCenterX() + distance13 * Math.sin(angle2));

      Composite old = g.getComposite();
      Stroke olds = g.getStroke();
      g.setStroke(new BasicStroke(0.8f));
      g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.02f));
      g.setColor(Color.DARK_GRAY);
      GeneralPath p = new GeneralPath();
      p.moveTo(pt1.getX(), pt1.getY());
      p.quadTo(pt2.getX(), pt2.getY(), pt3.getX(), pt3.getY());
      p.closePath();
      g.draw(p);
      g.setComposite(old);
      g.setStroke(olds);
    }
    CloserUtil.close(in);
  }
Ejemplo n.º 17
0
  private java.awt.image.BufferedImage createSmileyImage(final int SMILEY_SIZE) {
    java.awt.image.BufferedImage smileyImage =
        GFX_CONF.createCompatibleImage(
            SMILEY_SIZE + 4, SMILEY_SIZE + 4, java.awt.Transparency.TRANSLUCENT);
    final java.awt.Graphics2D G2 = (java.awt.Graphics2D) smileyImage.getGraphics();
    G2.setRenderingHint(
        java.awt.RenderingHints.KEY_STROKE_CONTROL, java.awt.RenderingHints.VALUE_STROKE_PURE);
    G2.setRenderingHint(
        java.awt.RenderingHints.KEY_ANTIALIASING, java.awt.RenderingHints.VALUE_ANTIALIAS_ON);

    // Create a GRADIENT that makes the sphere look like a BUBBLE
    final java.awt.geom.Point2D CENTER =
        new java.awt.geom.Point2D.Double((SMILEY_SIZE + 4) / 2.0, (SMILEY_SIZE + 4) / 2.0);

    final float RADIUS = SMILEY_SIZE / 2f;

    // Background fractions
    final float[] FRACTIONS_BACKGROUND1 = {0.0f, 0.75f, 0.85f, 1.0f};

    final float[] FRACTIONS_BACKGROUND2 = {0.0f, 1.0f};

    final float[] FRACTIONS_HIGHLIGHT = {0.0f, 0.5f, 0.85f, 1.0f};

    // Define the COLORS_BUBBLE for the BUBBLE
    // dependent on the variable validated
    final java.awt.Color[] COLORS_BACKGROUND1;
    final java.awt.Color[] COLORS_BACKGROUND2;

    final java.awt.Color[] COLORS_HIGHLIGHT;
    // Yellow radial gradient
    COLORS_BACKGROUND1 =
        new java.awt.Color[] {
          new java.awt.Color(253, 227, 46, 255),
          new java.awt.Color(253, 227, 46, 255),
          new java.awt.Color(239, 205, 0, 255),
          new java.awt.Color(195, 158, 26, 255)
        };

    // Yellow linear gradient
    COLORS_BACKGROUND2 =
        new java.awt.Color[] {
          new java.awt.Color(255, 227, 46, 255), new java.awt.Color(255, 227, 46, 0)
        };

    // White HIGHLIGHT
    COLORS_HIGHLIGHT =
        new java.awt.Color[] {
          new java.awt.Color(1.0f, 1.0f, 1.0f, 1.0f),
          new java.awt.Color(1.0f, 1.0f, 1.0f, 0.0f),
          new java.awt.Color(1.0f, 1.0f, 1.0f, 0.0f),
          new java.awt.Color(1.0f, 1.0f, 1.0f, 0.5f)
        };

    final java.awt.RadialGradientPaint GRADIENT_BACKGROUND1 =
        new java.awt.RadialGradientPaint(CENTER, RADIUS, FRACTIONS_BACKGROUND1, COLORS_BACKGROUND1);
    final java.awt.LinearGradientPaint GRADIENT_BACKGROUND2 =
        new java.awt.LinearGradientPaint(
            new java.awt.geom.Point2D.Float(0, 2),
            new java.awt.geom.Point2D.Float(0, SMILEY_SIZE),
            FRACTIONS_BACKGROUND2,
            COLORS_BACKGROUND2);

    // Draw Background
    final java.awt.geom.Ellipse2D SMILEY =
        new java.awt.geom.Ellipse2D.Double(2, 2, SMILEY_SIZE, SMILEY_SIZE);
    G2.setPaint(GRADIENT_BACKGROUND1);
    G2.fill(SMILEY);

    G2.setPaint(GRADIENT_BACKGROUND2);
    G2.fill(SMILEY);

    // Draw eyes
    G2.setColor(java.awt.Color.BLACK);
    // left
    G2.fillOval(
        (int) (SMILEY_SIZE / 3.6184) + 3,
        (SMILEY_SIZE / 5) + 3,
        (int) (SMILEY_SIZE / 7.6389),
        (int) (SMILEY_SIZE / 4.2308));
    // right
    G2.fillOval(
        (int) (SMILEY_SIZE / 1.6871) + 3,
        (SMILEY_SIZE / 5) + 3,
        (int) (SMILEY_SIZE / 7.6389),
        (int) (SMILEY_SIZE / 4.2308));

    // Draw mouth
    G2.setStroke(new java.awt.BasicStroke(SMILEY_SIZE / 22.92f));
    java.awt.geom.GeneralPath mouth = new java.awt.geom.GeneralPath();
    mouth.moveTo((int) (SMILEY_SIZE / 7.0513) + 3, (int) (SMILEY_SIZE / 1.76282) + 2);
    mouth.quadTo(
        (int) (SMILEY_SIZE / 2.037) + 2,
        (int) (SMILEY_SIZE / 0.95) + 2,
        (int) (SMILEY_SIZE / 1.1752) + 2,
        (int) (SMILEY_SIZE / 1.76282) + 2);
    G2.draw(mouth);

    // Create a HIGHLIGHT effect on top of SMILEY
    final java.awt.LinearGradientPaint GRADIENT_HIGHLIGHT =
        new java.awt.LinearGradientPaint(
            new java.awt.geom.Point2D.Float(0, 2),
            new java.awt.geom.Point2D.Float(0, SMILEY_SIZE - 2),
            FRACTIONS_HIGHLIGHT,
            COLORS_HIGHLIGHT);
    final java.awt.geom.Ellipse2D HIGHLIGHT =
        new java.awt.geom.Ellipse2D.Double(3, 3, SMILEY_SIZE - 3, SMILEY_SIZE - 3);
    G2.setPaint(GRADIENT_HIGHLIGHT);
    G2.fill(HIGHLIGHT);

    G2.dispose();

    return smileyImage;
  }
Ejemplo n.º 18
0
  /**
   * if the edge is reflexive its painted as a cyclic edge if there are 2 controlpoints the
   * connection is painted as a straight line from the source to the targetanchor if there are more
   * as 2 controlpoints the connection path between 2 control points is painted as bezier curve
   */
  @Override
  protected void paintWidget() {

    List<Point> contrPoints = this.getControlPoints();
    int listSize = contrPoints.size();

    Graphics2D gr = getGraphics();

    if (listSize <= 2) {
      if (isReflexive()) { // special case for reflexive connection widgets
        Widget related = this.getTargetAnchor().getRelatedWidget();
        int position = this.edgeBalance(related);
        Rectangle bounds = related.convertLocalToScene(related.getBounds());
        gr.setColor(getLineColor());
        Point first = new Point();
        Point last = new Point();
        double centerX = bounds.getCenterX();
        first.x = (int) (centerX + bounds.width / 4);
        first.y = bounds.y + bounds.height;
        last.x = first.x;
        last.y = bounds.y;

        gr.setStroke(this.getStroke());

        double cutDistance = this.getTargetAnchorShape().getCutDistance();
        double anchorAngle = Math.PI / -3.0;
        double cutX = Math.abs(Math.cos(anchorAngle) * cutDistance);
        double cutY = Math.abs(Math.sin(anchorAngle) * cutDistance);
        int ydiff = first.y - last.y;
        int endy = -ydiff;
        double height = bounds.getHeight();
        double cy = height / 4.0;
        double cx = bounds.getWidth() / 5.0;
        double dcx = cx * 2;
        GeneralPath gp = new GeneralPath();
        gp.moveTo(0, 0);
        gp.quadTo(0, cy, cx, cy);
        gp.quadTo(dcx, cy, dcx, -height / 2.0);
        gp.quadTo(dcx, endy - cy, cy, -(cy + ydiff));
        gp.quadTo(cutX * 1.5, endy - cy, cutX, endy - cutY);

        AffineTransform af = new AffineTransform();
        AnchorShape anchorShape = this.getTargetAnchorShape();

        if (position < 0) {
          first.x = (int) (centerX - bounds.width / 4);
          af.translate(first.x, first.y);
          af.scale(-1.0, 1.0);
          last.x = first.x;
        } else {
          af.translate(first.x, first.y);
        }
        Shape s = gp.createTransformedShape(af);
        gr.draw(s);

        if (last != null) {
          AffineTransform previousTransform = gr.getTransform();
          gr.translate(last.x, last.y);

          if (position < 0) gr.rotate(Math.PI - anchorAngle);
          else gr.rotate(anchorAngle);

          anchorShape.paint(gr, false);
          gr.setTransform(previousTransform);
        }

      } else {
        super.paintWidget();
      }
      return;
    }

    // bezier curve...
    GeneralPath curvePath = new GeneralPath();
    Point lastControlPoint = null;
    double lastControlPointRotation = 0.0;

    Point prev = null;
    for (int i = 0; i < listSize - 1; i++) {
      Point cur = contrPoints.get(i);
      Point next = contrPoints.get(i + 1);
      Point nextnext = null;
      if (i < listSize - 2) {
        nextnext = contrPoints.get(i + 2);
      }

      double len = cur.distance(next);
      double scale = len * BEZIER_SCALE;
      Point bezierFrom = null; // first ControlPoint
      Point bezierTo = null; // second ControlPoint

      if (prev == null) {
        // first point
        curvePath.moveTo(cur.x, cur.y); // startpoint
        bezierFrom = cur;
      } else {
        bezierFrom = new Point(next.x - prev.x, next.y - prev.y);
        bezierFrom = scaleVector(bezierFrom, scale);
        bezierFrom.translate(cur.x, cur.y);
      }

      if (nextnext == null) { // next== last point (curve to)
        lastControlPoint = next;
        bezierTo = next; // set 2nd intermediate point to endpoint
        GeneralPath lastseg = this.subdivide(cur, bezierFrom, bezierTo, next);
        if (lastseg != null) curvePath.append(lastseg, true);
        break;
      } else {
        bezierTo = new Point(cur.x - nextnext.x, cur.y - nextnext.y);
        bezierTo = scaleVector(bezierTo, scale);
        bezierTo.translate(next.x, next.y);
      }

      curvePath.curveTo(
          bezierFrom.x, bezierFrom.y, // controlPoint1
          bezierTo.x, bezierTo.y, // controlPoint2
          next.x, next.y);
      prev = cur;
    }
    Point2D cur = curvePath.getCurrentPoint();
    Point next = lastControlPoint;

    lastControlPointRotation = // anchor anchorAngle
        Math.atan2(cur.getY() - next.y, cur.getX() - next.x);

    Color previousColor = gr.getColor();
    gr.setColor(getLineColor());
    Stroke s = this.getStroke();
    gr.setStroke(s);
    gr.setColor(this.getLineColor());
    gr.draw(curvePath);

    AffineTransform previousTransform = gr.getTransform();
    gr.translate(lastControlPoint.x, lastControlPoint.y);
    gr.rotate(lastControlPointRotation);
    AnchorShape targetAnchorShape = this.getTargetAnchorShape();
    targetAnchorShape.paint(gr, false);
    gr.setTransform(previousTransform);

    // paint ControlPoints if enabled
    if (isPaintControlPoints()) {
      int last = listSize - 1;
      for (int index = 0; index <= last; index++) {
        Point point = contrPoints.get(index);
        previousTransform = gr.getTransform();
        gr.translate(point.x, point.y);
        if (index == 0 || index == last) getEndPointShape().paint(gr);
        else getControlPointShape().paint(gr);
        gr.setTransform(previousTransform);
      }
    }
    gr.setColor(previousColor);
  }
Ejemplo n.º 19
0
 @Override
 public void curveTo(double controlX, double controlY, double anchorX, double anchorY) {
   path.quadTo(controlX, controlY, anchorX, anchorY);
 }
Ejemplo n.º 20
0
 public GeneralPath getPath(Point p1, Point p2, float zoom) {
   GeneralPath p = new GeneralPath();
   p.moveTo(p1.x * zoom, p1.y * zoom);
   p.quadTo(bezierpoint.x * zoom, bezierpoint.y * zoom, p2.x * zoom, p2.y * zoom);
   return p;
 }