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;
  }
  @Override
  public void paint(Graphics2D graphics, Dimension dimensions) {

    final Color SHADOW_COLOR = new Color(0.0f, 0.0f, 0.0f, 0.65f);

    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    graphics.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
    // graphics.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
    // RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    // graphics.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
    // RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    graphics.setRenderingHint(
        RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    // graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
    // RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    final int imageWidth = (int) dimensions.getWidth();
    final int imageHeight = (int) dimensions.getHeight();

    final GeneralPath pointerShape;

    pointerShape = new GeneralPath();
    pointerShape.setWindingRule(Path2D.WIND_EVEN_ODD);
    pointerShape.moveTo(0.5 * imageWidth, 0.16822429906542055 * imageHeight);
    pointerShape.lineTo(0.48598130841121495 * imageWidth, 0.5 * imageHeight);
    pointerShape.lineTo(0.5 * imageWidth, 0.5046728971962616 * imageHeight);
    pointerShape.lineTo(0.5093457943925234 * imageWidth, 0.5 * imageHeight);
    pointerShape.lineTo(0.5 * imageWidth, 0.16822429906542055 * imageHeight);
    pointerShape.closePath();
    graphics.setColor(SHADOW_COLOR);
    graphics.fill(pointerShape);

    graphics.dispose();
  }
Example #3
0
  public java.awt.geom.GeneralPath appendPath(java.awt.geom.GeneralPath path) {
    double cot = cos(theta);
    double sit = sin(theta);
    double cost, sint;

    if (direct) {
      // Counter-clockwise circle
      for (double t = .1; t < PI * 2; t += .1) {
        cost = cos(t);
        sint = sin(t);
        path.lineTo(
            (float) (xc + r * cost * cot - r * sint * sit),
            (float) (yc + r * cost * sit + r * sint * cot));
      }
    } else {
      // Clockwise circle
      for (double t = .1; t < PI * 2; t += .1) {
        cost = cos(t);
        sint = sin(t);
        path.lineTo(
            (float) (xc + r * cost * cot + r * sint * sit),
            (float) (yc + r * cost * sit - r * sint * cot));
      }
    }

    // line to first point
    path.lineTo((float) (xc + r * cot), (float) (yc + r * sit));

    return path;
  }
Example #4
0
 /**
  * Creates a region surrounding a line segment by 'widening' the line segment. A typical use for
  * this method is the creation of a 'clickable' region for a line that is displayed on-screen.
  *
  * @param line the line (<code>null</code> not permitted).
  * @param width the width of the region.
  * @return A region that surrounds the line.
  */
 public static Shape createLineRegion(final Line2D line, final float width) {
   final GeneralPath result = new GeneralPath();
   final float x1 = (float) line.getX1();
   final float x2 = (float) line.getX2();
   final float y1 = (float) line.getY1();
   final float y2 = (float) line.getY2();
   if ((x2 - x1) != 0.0) {
     final double theta = Math.atan((y2 - y1) / (x2 - x1));
     final float dx = (float) Math.sin(theta) * width;
     final float dy = (float) Math.cos(theta) * width;
     result.moveTo(x1 - dx, y1 + dy);
     result.lineTo(x1 + dx, y1 - dy);
     result.lineTo(x2 + dx, y2 - dy);
     result.lineTo(x2 - dx, y2 + dy);
     result.closePath();
   } else {
     // special case, vertical line
     result.moveTo(x1 - width / 2.0f, y1);
     result.lineTo(x1 + width / 2.0f, y1);
     result.lineTo(x2 + width / 2.0f, y2);
     result.lineTo(x2 - width / 2.0f, y2);
     result.closePath();
   }
   return result;
 }
Example #5
0
  /**
   * Draws the needle.
   *
   * @param g2 the graphics device.
   * @param plotArea the plot area.
   * @param rotate the rotation point.
   * @param angle the angle.
   */
  @Override
  protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) {

    Area shape;
    GeneralPath pointer = new GeneralPath();

    int minY = (int) (plotArea.getMinY());
    // int maxX = (int) (plotArea.getMaxX());
    int maxY = (int) (plotArea.getMaxY());
    int midX = (int) (plotArea.getMinX() + (plotArea.getWidth() / 2));
    // int midY = (int) (plotArea.getMinY() + (plotArea.getHeight() / 2));
    int lenX = (int) (plotArea.getWidth() / 10);
    if (lenX < 2) {
      lenX = 2;
    }

    pointer.moveTo(midX - lenX, maxY - lenX);
    pointer.lineTo(midX + lenX, maxY - lenX);
    pointer.lineTo(midX, minY + lenX);
    pointer.closePath();

    lenX = 4 * lenX;
    Ellipse2D circle = new Ellipse2D.Double(midX - lenX / 2, plotArea.getMaxY() - lenX, lenX, lenX);

    shape = new Area(circle);
    shape.add(new Area(pointer));
    if ((rotate != null) && (angle != 0)) {
      /// we have rotation
      getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
      shape.transform(getTransform());
    }

    defaultDisplay(g2, shape);
  }
    @Override
    public void paint(Graphics2D graphics) {
      ScrollBar scrollBar = (ScrollBar) getComponent();

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

      graphics.setPaint(scrollButtonImageColor);
      graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

      GeneralPath arrow = new GeneralPath(GeneralPath.WIND_EVEN_ODD);

      if (scrollBar.getOrientation() == Orientation.HORIZONTAL) {
        arrow.moveTo(0, 0);
        arrow.lineTo(width + 0.5f, height / 2.0f);
        arrow.lineTo(0, height);
      } else {
        arrow.moveTo(0, 0);
        arrow.lineTo(width / 2.0f, height + 0.5f);
        arrow.lineTo(width, 0);
      }

      arrow.closePath();
      // TODO Use Graphics#fillPolygon() as optimization?
      graphics.fill(arrow);
    }
Example #7
0
  public void render(int w, int h, Graphics2D g2) {

    g2.translate(w * .2, h * .2);

    GeneralPath p = new GeneralPath(GeneralPath.WIND_NON_ZERO);
    p.moveTo(0.0f, 0.0f);
    p.lineTo(w * .5f, 0.0f);
    p.lineTo(w * .5f, h * .2f);
    p.lineTo(0.0f, h * .2f);
    p.closePath();

    p.moveTo(w * .05f, h * .05f);
    p.lineTo(w * .55f, h * .05f);
    p.lineTo(w * .55f, h * .25f);
    p.lineTo(w * .05f, h * .25f);
    p.closePath();

    g2.setColor(LIGHT_GRAY);
    g2.fill(p);
    g2.setColor(BLACK);
    g2.draw(p);
    g2.drawString("NON_ZERO rule", 0, -5);

    g2.translate(0.0f, h * .45);

    p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
    g2.setColor(LIGHT_GRAY);
    g2.fill(p);
    g2.setColor(BLACK);
    g2.draw(p);
    g2.drawString("EVEN_ODD rule", 0, -5);
  }
Example #8
0
  /**
   * Draws the outline for the plot.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param dataArea the area inside the axes.
   */
  @Override
  public void drawOutline(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea) {

    float x0 = (float) dataArea.getX();
    float x1 = x0 + (float) Math.abs(this.xOffset);
    float x3 = (float) dataArea.getMaxX();
    float x2 = x3 - (float) Math.abs(this.xOffset);

    float y0 = (float) dataArea.getMaxY();
    float y1 = y0 - (float) Math.abs(this.yOffset);
    float y3 = (float) dataArea.getMinY();
    float y2 = y3 + (float) Math.abs(this.yOffset);

    GeneralPath clip = new GeneralPath();
    clip.moveTo(x0, y0);
    clip.lineTo(x0, y2);
    clip.lineTo(x1, y3);
    clip.lineTo(x3, y3);
    clip.lineTo(x3, y1);
    clip.lineTo(x2, y0);
    clip.closePath();

    // put an outline around the data area...
    Stroke outlineStroke = plot.getOutlineStroke();
    Paint outlinePaint = plot.getOutlinePaint();
    if ((outlineStroke != null) && (outlinePaint != null)) {
      g2.setStroke(outlineStroke);
      g2.setPaint(outlinePaint);
      g2.draw(clip);
    }
  }
  public GeneralPath createOutline() {
    GeneralPath outline = new GeneralPath();
    int nLos = 100;
    int nLas = 100;
    boolean first = true;

    for (int lo = 0; lo <= nLos; lo++) {
      float x = (lo - nLos / 2) * (360.0f / nLos);
      float y = -90;
      if (first) outline.moveTo(x, y);
      else outline.lineTo(x, y);
      first = false;
    }

    for (int la = 0; la <= nLos; la++) {
      float x = 180;
      float y = (la - nLas / 2) * (180.0f / nLas);
      outline.lineTo(x, y);
    }

    for (int lo = nLos; lo >= 0; lo--) {
      float x = (lo - nLos / 2) * (360.0f / nLos);
      float y = 90;
      outline.lineTo(x, y);
    }

    for (int la = nLas; la >= 0; la--) {
      float x = -180;
      float y = (la - nLas / 2) * (180.0f / nLas);
      outline.lineTo(x, y);
    }

    return outline;
  }
  public GeneralPath createLines() {
    GeneralPath lines = new GeneralPath();
    int pad = 0;
    int nLos = 24;
    int nLas = 100;
    for (int lo = 0; lo <= nLos; lo++) {
      boolean first = true;
      for (int la = pad; la <= nLas - pad; la++) {
        float x = (lo - nLos / 2) * (360.0f / nLos);
        float y = (la - nLas / 2) * (180.0f / nLas);
        if (first) lines.moveTo(x, y);
        else lines.lineTo(x, y);
        first = false;
      }
    }

    nLos = 100;
    nLas = 12;
    for (int la = 0; la <= nLas; la++) {
      boolean first = true;
      for (int lo = pad; lo <= nLos - pad; lo++) {
        float x = (lo - nLos / 2) * (360.0f / nLos);
        float y = (la - nLas / 2) * (180.0f / nLas);
        if (first) lines.moveTo(x, y);
        else lines.lineTo(x, y);
        first = false;
      }
    }
    return lines;
  }
Example #11
0
 public GeneralPath getBezieredPoly(Polygon pts) {
   GeneralPath p = new GeneralPath();
   if (pts.npoints > 0) {
     p.moveTo(pts.xpoints[0], pts.ypoints[0]);
     if (pts.npoints >= 4) {
       int counter = 1;
       for (int i = 1; i + 2 < pts.npoints; i += 3) {
         p.curveTo(
             pts.xpoints[i],
             pts.ypoints[i],
             pts.xpoints[i + 1],
             pts.ypoints[i + 1],
             pts.xpoints[i + 2],
             pts.ypoints[i + 2]);
         counter += 3;
       }
       while (counter < pts.npoints) {
         p.lineTo(pts.xpoints[counter], pts.ypoints[counter]);
         counter++;
       }
     } else {
       for (int i = 1; i < pts.npoints; i++) {
         p.lineTo(pts.xpoints[i], pts.ypoints[i]);
       }
     }
   }
   return p;
 }
Example #12
0
 static {
   GeneralPath p = new GeneralPath(new Rectangle2D.Float(-7, -4, 14, 8));
   p.moveTo(-6.5f, -3.5f);
   p.lineTo(0, 1);
   p.lineTo(6.5f, -3.5f);
   SHAPE = p;
 }
  /**
   * 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;
  }
  /**
   * Constructs a new renderer.
   *
   * <p>To specify the type of renderer, use one of the constants: SHAPES, LINES, SHAPES_AND_LINES,
   * AREA or AREA_AND_SHAPES.
   *
   * @param type the type of renderer.
   * @param toolTipGenerator the tool tip generator to use (<code>null</code> permitted).
   * @param urlGenerator the URL generator (<code>null</code> permitted).
   */
  public XYAreaRenderer(
      int type, XYToolTipGenerator toolTipGenerator, XYURLGenerator urlGenerator) {

    super();
    setBaseToolTipGenerator(toolTipGenerator);
    setURLGenerator(urlGenerator);

    if (type == SHAPES) {
      this.plotShapes = true;
    }
    if (type == LINES) {
      this.plotLines = true;
    }
    if (type == SHAPES_AND_LINES) {
      this.plotShapes = true;
      this.plotLines = true;
    }
    if (type == AREA) {
      this.plotArea = true;
    }
    if (type == AREA_AND_SHAPES) {
      this.plotArea = true;
      this.plotShapes = true;
    }
    this.showOutline = false;
    GeneralPath area = new GeneralPath();
    area.moveTo(0.0f, -4.0f);
    area.lineTo(3.0f, -2.0f);
    area.lineTo(4.0f, 4.0f);
    area.lineTo(-4.0f, 4.0f);
    area.lineTo(-3.0f, -2.0f);
    area.closePath();
    this.legendArea = area;
  }
  //    public static Shape getInteriorShapeAsFirstPartTextField(Rectangle bounds) {
  //        int x = bounds.x;
  //        int y = bounds.y;
  //        int w = bounds.width;
  //        int h = bounds.height;
  //        int roundCorner = h;
  //
  //        int x1 = x + w, x2 = x + roundCorner, x3 = x, x4 = x, x5 = x, x6 = x, x7 = x +
  // roundCorner, x8 = x1;
  //        int y1 = y + h, y2 = y1, y3 = y1, y4 = y + h - roundCorner, y5 = y + roundCorner, y6 =
  // y, y7 = y6, y8 = y6;
  //        GeneralPath path = new GeneralPath();
  //        path.moveTo(x1, y1);
  //        path.lineTo(x2, y2);
  //        path.curveTo(x2, y2, x3, y3, x4, y4);
  //        path.lineTo(x5, y5);
  //        path.curveTo(x5, y5, x6, y6, x7, y7);
  //        path.lineTo(x8, y8);
  //        return path;
  //    }
  public static Shape getInteriorShapeAsLastPart(Rectangle bounds) {
    int x = bounds.x;
    int y = bounds.y;
    int w = bounds.width;
    int h = bounds.height;
    int roundCorner = h / 2;

    int x1 = x, x2 = x + w - roundCorner, x3 = x + w, x4 = x3, x5 = x3, x6 = x3, x7 = x2, x8 = x1;
    int y1 = y,
        y2 = y1,
        y3 = 1,
        y4 = y + roundCorner,
        y5 = y + h - roundCorner,
        y6 = y + h,
        y7 = y6,
        y8 = y6;
    GeneralPath path = new GeneralPath();
    path.moveTo(x1, y1);
    path.lineTo(x2, y2);
    path.curveTo(x2, y2, x3, y3, x4, y4);
    path.lineTo(x5, y5);
    path.curveTo(x5, y5, x6, y6, x7, y7);
    path.lineTo(x8, y8);
    return path;
  }
Example #16
0
 public void drawTo(Graphics g, Line line) {
   if (!calc.tileOnMap(t1) || !calc.tileOnMap(t2)) return;
   if (calc.tileOnMap(line.getTile1()) && calc.tileOnMap(line.getTile2())) {
     Point p1 = calc.tileToMinimap(t1);
     Point p2 = calc.tileToMinimap(t2);
     Point p3 = calc.tileToMinimap(line.getTile2());
     Point p4 = calc.tileToMinimap(line.getTile1());
     GeneralPath path = new GeneralPath();
     path.moveTo(p1.x, p1.y);
     path.lineTo(p2.x, p2.y);
     path.lineTo(p3.x, p3.y);
     path.lineTo(p4.x, p4.y);
     path.closePath();
     g.setColor(POLY_FILL);
     ((Graphics2D) g).fill(path);
     ((Graphics2D) g).draw(path);
   }
   Point last = null, p;
   g.setColor(Color.ORANGE);
   for (RSTile t : pathList) {
     if (calc.tileOnMap(t)) {
       p = calc.tileToMinimap(t);
       g.fillOval(p.x - 2, p.y - 2, 5, 5);
       if (last != null) g.drawLine(p.x, p.y, last.x, last.y);
       last = p;
     } else last = null;
   }
 }
 void draw(GeneralPath path, Graphics2D g2d) {
   g2d.translate(47, 30);
   path.moveTo(33, 0);
   path.lineTo(0, 33);
   path.lineTo(0, 34);
   path.lineTo(33, 67);
   path.closePath();
 }
Example #18
0
 /**
  * Creates a triangle shape that points downwards.
  *
  * @param s the size factor (equal to half the height of the triangle).
  * @return A triangle shape.
  */
 public static Shape createDownTriangle(final float s) {
   final GeneralPath p0 = new GeneralPath();
   p0.moveTo(0.0f, s);
   p0.lineTo(s, -s);
   p0.lineTo(-s, -s);
   p0.closePath();
   return p0;
 }
 public void quad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
   GeneralPath gp = new GeneralPath();
   gp.moveTo(x1, y1);
   gp.lineTo(x2, y2);
   gp.lineTo(x3, y3);
   gp.lineTo(x4, y4);
   gp.closePath();
   drawShape(gp);
 }
Example #20
0
 {
   path.moveTo(0, -10);
   path.lineTo(0, -2);
   path.lineTo(-7, -4);
   path.lineTo(0, 10);
   path.lineTo(7, -4);
   path.lineTo(0, -2);
   path.closePath();
 }
Example #21
0
 {
   myShape.moveTo(0, 5);
   myShape.lineTo(-5, 3.5);
   myShape.lineTo(-5, -5);
   myShape.lineTo(5, -5);
   myShape.lineTo(5, 3.5);
   myShape.lineTo(0, 5);
   myShape.closePath();
 }
Example #22
0
 /**
  * Creates a diamond shape.
  *
  * @param s the size factor (equal to half the height of the diamond).
  * @return A diamond shape.
  */
 public static Shape createDiamond(final float s) {
   final GeneralPath p0 = new GeneralPath();
   p0.moveTo(0.0f, -s);
   p0.lineTo(s, 0.0f);
   p0.lineTo(0.0f, s);
   p0.lineTo(-s, 0.0f);
   p0.closePath();
   return p0;
 }
Example #23
0
  /** Constructor for objects of class CoffeeCup */
  public CoffeeCup(double x, double y, double width, double height) {

    // Specify the upper left corner, and the
    //  width and height of the original points used to
    //  plot the *hard-coded* coffee cup

    final double ORIG_ULX = 100.0;
    final double ORIG_ULY = 100.0;
    final double ORIG_HEIGHT = 300.0;
    final double ORIG_WIDTH = 400.0;

    GeneralPath leftSide = new GeneralPath();

    // left side of cup

    leftSide.moveTo(200, 400);
    leftSide.lineTo(160, 360);
    leftSide.lineTo(130, 300);
    leftSide.lineTo(100, 200);
    leftSide.lineTo(100, 100);

    GeneralPath topAndBottom = new GeneralPath();

    topAndBottom.moveTo(100, 100);
    topAndBottom.lineTo(500, 100); // top of cup

    topAndBottom.moveTo(200, 400);
    topAndBottom.lineTo(400, 400); // bottom of cup

    Shape rightSide = ShapeTransforms.horizontallyFlippedCopyOf(leftSide);

    // after flipping around the upper left hand corner of the
    // bounding box, we move this over to the right by 400 pixels

    rightSide = ShapeTransforms.translatedCopyOf(rightSide, 400.0, 0.0);

    // now we put the whole thing together ino a single path.

    GeneralPath wholeCup = new GeneralPath();
    wholeCup.append(topAndBottom, false);
    wholeCup.append(leftSide, false);
    wholeCup.append(rightSide, false);

    // translate to the origin by subtracting the original upper left x and y
    // then translate to (x,y) by adding x and y

    Shape s = ShapeTransforms.translatedCopyOf(wholeCup, -ORIG_ULX + x, -ORIG_ULY + y);

    // scale to correct height and width
    s = ShapeTransforms.scaledCopyOf(s, width / ORIG_WIDTH, height / ORIG_HEIGHT);

    // Use the GeneralPath constructor that takes a shape and returns
    // it as a general path to set our instance variable cup

    this.set(new GeneralPath(s));
  }
  void draw(GeneralPath path, Graphics2D g2d) {

    g2d.translate(31, 47);

    path.moveTo(0, 33);
    path.lineTo(33, 0);
    path.lineTo(34, 0);
    path.lineTo(67, 33);
    path.closePath();
  }
Example #25
0
 /**
  * 刻度尺
  *
  * @param 十字左上角坐标
  * @param 单位像素
  * @return
  */
 public static Shape rule(Point2D point, double pix_cm) {
   double x = point.getX();
   double y = point.getY();
   GeneralPath path = new GeneralPath();
   path.moveTo(x, y);
   path.lineTo(x, y + pix_cm / 5);
   path.lineTo(x + pix_cm, y + pix_cm / 5);
   path.lineTo(x + pix_cm, y);
   return path;
 }
Example #26
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;
 }
Example #27
0
  public Shape createStrokedShape(Shape shape) {
    GeneralPath result = new GeneralPath();
    PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS);
    float points[] = new float[6];
    float moveX = 0, moveY = 0;
    float lastX = 0, lastY = 0;
    float thisX = 0, thisY = 0;
    int type = 0;
    float next = 0;
    int phase = 0;

    while (!it.isDone()) {
      type = it.currentSegment(points);
      switch (type) {
        case PathIterator.SEG_MOVETO:
          moveX = lastX = points[0];
          moveY = lastY = points[1];
          result.moveTo(moveX, moveY);
          next = wavelength / 2;
          break;

        case PathIterator.SEG_CLOSE:
          points[0] = moveX;
          points[1] = moveY;
          // Fall into....

        case PathIterator.SEG_LINETO:
          thisX = points[0];
          thisY = points[1];
          float dx = thisX - lastX;
          float dy = thisY - lastY;
          float distance = (float) Math.sqrt(dx * dx + dy * dy);
          if (distance >= next) {
            float r = 1.0f / distance;
            while (distance >= next) {
              float x = lastX + next * dx * r;
              float y = lastY + next * dy * r;
              if ((phase & 1) == 0) result.lineTo(x + amplitude * dy * r, y - amplitude * dx * r);
              else result.lineTo(x - amplitude * dy * r, y + amplitude * dx * r);
              next += wavelength;
              phase++;
            }
          }
          next -= distance;
          lastX = thisX;
          lastY = thisY;
          if (type == PathIterator.SEG_CLOSE) result.closePath();
          break;
      }
      it.next();
    }

    return stroke.createStrokedShape(result);
  }
Example #28
0
  /**
   * ************************************************************************* The method which
   * testing, if the triangle contains the point
   *
   * @param P - point which will be tested
   * @return boolean true - the triangle contains the point false - the triangle doesn't contains
   *     point
   */
  public boolean contains(PointDT P) {
    GeneralPath triangle = new GeneralPath();

    triangle.moveTo((float) A.x, (float) A.y);
    triangle.lineTo((float) B.x, (float) B.y);
    triangle.lineTo((float) C.x, (float) C.y);
    triangle.lineTo((float) A.x, (float) A.y);
    triangle.closePath();
    // System.out.println("Je uvnitr + " +triangle.contains(P.x, P.y));
    return triangle.contains(P.x, P.y);
  }
  private static GeneralPath createAreaShape() {
    GeneralPath areaShape = new GeneralPath();
    areaShape.moveTo(0, 0);
    areaShape.lineTo(0, -5);
    areaShape.lineTo(5, -10);
    areaShape.lineTo(10, -5);
    areaShape.lineTo(15, -7);
    areaShape.lineTo(15, 0);

    areaShape.closePath();
    return areaShape;
  }
Example #30
0
  public static void createShapeBevel(
      Graphics2D g2,
      Shape theShape,
      double flatness,
      int numBands,
      float bevelSize,
      float light[]) {
    // draw bands from inside of shape to outside (important)
    for (int i = numBands - 1; i >= 0; i--) {
      // get the path around the block area, flattening any curves
      // 0.2 is flattening tolerance, big == faster, small == smoother
      BevelIterator bi = new BevelIterator(theShape, flatness);

      // cos and sin of angle between surface normal and screen plane
      float theCos = 1f - ((float) i + 0.5f) / numBands; // center of band
      float theSin = (float) Math.sqrt(1 - theCos * theCos);

      float from = 0; // draw strips from outer edge,
      float to = 1f / numBands * (i + 1) * bevelSize; // to this distance
      // the overlap makes sure there is no tiny space between the bands

      g2.setStroke(new BasicStroke(to - from));

      float[] p = {0, 0};
      float norm[] = {0, 0, 0};
      float grayAlpha[] = {0, 0}; // receives gray and alpha

      while (!bi.isDone()) {
        // count++;
        bi.nextSegment();

        norm[0] = bi.perpVec[0] * theCos;
        norm[1] = bi.perpVec[1] * theCos;
        norm[2] = theSin;
        getLightingOverlay(norm, light, grayAlpha);
        g2.setColor(new Color(grayAlpha[0], grayAlpha[0], grayAlpha[0], grayAlpha[1]));
        g2.setComposite(AlphaComposite.Src);

        GeneralPath gp = new GeneralPath();
        bi.insetPoint2(from, p);
        gp.moveTo(p[0], p[1]);
        bi.insetPoint3(from, p);
        gp.lineTo(p[0], p[1]);
        bi.insetPoint3(to, p);
        gp.lineTo(p[0], p[1]);
        bi.insetPoint2(to, p);
        gp.lineTo(p[0], p[1]);
        gp.closePath();
        g2.fill(gp);
      }
    }
  }