Java Code Examples for java.awt.geom.GeneralPath#quadTo()

The following examples show how to use java.awt.geom.GeneralPath#quadTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccuracyTest.java    From pumpernickel with MIT License 6 votes vote down vote up
private GeneralPath getShape(int index) {
	Random r = new Random(index * 100000);
	GeneralPath path = new GeneralPath(
			r.nextBoolean() ? Path2D.WIND_EVEN_ODD : Path2D.WIND_NON_ZERO);
	path.moveTo(r.nextFloat() * 100, r.nextFloat() * 100);
	for (int a = 0; a < 3; a++) {
		int k;
		if (type.getSelectedIndex() == 0) {
			k = r.nextInt(3);
		} else {
			k = type.getSelectedIndex() - 1;
		}

		if (k == 0) {
			path.lineTo(r.nextFloat() * 100, r.nextFloat() * 100);
		} else if (k == 1) {
			path.quadTo(r.nextFloat() * 100, r.nextFloat() * 100,
					r.nextFloat() * 100, r.nextFloat() * 100);
		} else {
			path.curveTo(r.nextFloat() * 100, r.nextFloat() * 100,
					r.nextFloat() * 100, r.nextFloat() * 100,
					r.nextFloat() * 100, r.nextFloat() * 100);
		}
	}
	return path;
}
 
Example 2
Source File: TMRoleEdge.java    From ontopia with Apache License 2.0 6 votes vote down vote up
@Override
protected GeneralPath getCurvedBowTie(int index) {
  double x1 = from.drawx;
  double x2 = to.drawx;
  double y1 = from.drawy;
  double y2 = to.drawy;
  double midx = this.calculateMidPointBetween(x1, x2);
  double midy = this.calculateMidPointBetween(y1, y2);
  int weight = index / 2;
  if (index % 2 == 1) {
    weight++;
    weight = -weight;
  }
  Dimension offset = calculateOffset(x1, x2, y1, y2, LOADING * weight);
  Dimension toExtra = calculateOffset(x2, (int)midx - offset.width, y2, (int)midy + offset.height, getLineWeight());

  GeneralPath path = new GeneralPath(GeneralPath.WIND_NON_ZERO);
  path.moveTo((int)x1, (int)y1);
  path.quadTo((float)midx-offset.width, (float)midy+offset.height, (float)x2-toExtra.width, (float)y2+toExtra.height);
  path.lineTo((int)x2+toExtra.width, (int)y2-toExtra.height);
  path.quadTo((float)midx-offset.width, (float)midy+offset.height, (float)x1, (float)y1);
  
  return path;
}
 
Example 3
Source File: PainterShaped.java    From Logisim with GNU General Public License v3.0 6 votes vote down vote up
private static GeneralPath computeShield(int width, int height) {
	GeneralPath base;
	if (width < 40) {
		base = SHIELD_NARROW;
	} else if (width < 60) {
		base = SHIELD_MEDIUM;
	} else {
		base = SHIELD_WIDE;
	}

	if (height <= width) { // no wings
		return base;
	} else { // we need to add wings
		int wingHeight = (height - width) / 2;
		int dx = Math.min(20, wingHeight / 4);

		GeneralPath path = new GeneralPath();
		path.moveTo(-width, -height / 2);
		path.quadTo(-width + dx, -(width + height) / 4, -width, -width / 2);
		path.append(base, true);
		path.quadTo(-width + dx, (width + height) / 4, -width, height / 2);
		return path;
	}
}
 
Example 4
Source File: AbstractPopupPainter.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates and returns simple popup shape.
 *
 * @param popup     popup component
 * @param popupSize popup size
 * @param fill      whether it is a fill shape or not
 * @return simple popup shape
 */
protected GeneralPath createSimpleShape ( final C popup, final Dimension popupSize, final boolean fill )
{
    final int shear = fill ? 1 : 0;
    final GeneralPath shape = new GeneralPath ( GeneralPath.WIND_EVEN_ODD );
    final int top = shadeWidth + shear;
    final int left = shadeWidth + shear;
    final int bottom = popupSize.height - 1 - shadeWidth;
    final int right = popupSize.width - 1 - shadeWidth;
    shape.moveTo ( left, top + round );
    shape.quadTo ( left, top, left + round, top );
    shape.lineTo ( right - round, top );
    shape.quadTo ( right, top, right, top + round );
    shape.lineTo ( right, bottom - round );
    shape.quadTo ( right, bottom, right - round, bottom );
    shape.lineTo ( left + round, bottom );
    shape.quadTo ( left, bottom, left, bottom - round );
    shape.closePath ();
    return shape;
}
 
Example 5
Source File: MouseTrail.java    From Explvs-AIO with MIT License 6 votes vote down vote up
private void drawPath(final Graphics2D g) {

        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setColor(colour);

        GeneralPath path = new GeneralPath();

        Iterator<Point> mousePointIterator = mousePoints.iterator();

        Point firstPoint = mousePointIterator.next();
        path.moveTo(firstPoint.getX(), firstPoint.getY());

        Point prev = firstPoint;
        while (mousePointIterator.hasNext()) {
            Point current = mousePointIterator.next();
            path.quadTo(prev.getX(), prev.getY(), current.getX(), current.getY());
            prev = current;
        }
        g.draw(path);
    }
 
Example 6
Source File: MouseTrail.java    From Explvs-AIO with MIT License 6 votes vote down vote up
private void drawPath(final Graphics2D g) {

        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setColor(colour);

        GeneralPath path = new GeneralPath();

        Iterator<Point> mousePointIterator = mousePoints.iterator();

        Point firstPoint = mousePointIterator.next();
        path.moveTo(firstPoint.getX(), firstPoint.getY());

        Point prev = firstPoint;
        while (mousePointIterator.hasNext()) {
            Point current = mousePointIterator.next();
            path.quadTo(prev.getX(), prev.getY(), current.getX(), current.getY());
            prev = current;
        }
        g.draw(path);
    }
 
Example 7
Source File: DashStrokeTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {

        GeneralPath shape = new GeneralPath();
        int[] pointTypes = {0, 0, 1, 1, 0, 1, 1, 0};
        double[] xpoints = {428, 420, 400, 400, 400, 400, 420, 733};
        double[] ypoints = {180, 180, 180, 160, 30, 10, 10, 10};
        shape.moveTo(xpoints[0], ypoints[0]);
        for (int i = 1; i < pointTypes.length; i++) {
            if (pointTypes[i] == 1 && i < pointTypes.length - 1) {
                shape.quadTo(xpoints[i], ypoints[i],
                             xpoints[i + 1], ypoints[i + 1]);
            } else {
                shape.lineTo(xpoints[i], ypoints[i]);
            }
        }

        BufferedImage image = new
            BufferedImage(1000, 1000, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = image.createGraphics();

        Color color = new Color(124, 0, 124, 255);
        g2.setColor(color);
        Stroke stroke = new BasicStroke(1.0f,
                                        BasicStroke.CAP_BUTT,
                                        BasicStroke.JOIN_BEVEL,
                                        10.0f, new float[] {9, 6}, 0.0f);
        g2.setStroke(stroke);
        g2.draw(shape);
    }
 
Example 8
Source File: DashStrokeTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {

        GeneralPath shape = new GeneralPath();
        int[] pointTypes = {0, 0, 1, 1, 0, 1, 1, 0};
        double[] xpoints = {428, 420, 400, 400, 400, 400, 420, 733};
        double[] ypoints = {180, 180, 180, 160, 30, 10, 10, 10};
        shape.moveTo(xpoints[0], ypoints[0]);
        for (int i = 1; i < pointTypes.length; i++) {
            if (pointTypes[i] == 1 && i < pointTypes.length - 1) {
                shape.quadTo(xpoints[i], ypoints[i],
                             xpoints[i + 1], ypoints[i + 1]);
            } else {
                shape.lineTo(xpoints[i], ypoints[i]);
            }
        }

        BufferedImage image = new
            BufferedImage(1000, 1000, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = image.createGraphics();

        Color color = new Color(124, 0, 124, 255);
        g2.setColor(color);
        Stroke stroke = new BasicStroke(1.0f,
                                        BasicStroke.CAP_BUTT,
                                        BasicStroke.JOIN_BEVEL,
                                        10.0f, new float[] {9, 6}, 0.0f);
        g2.setStroke(stroke);
        g2.draw(shape);
    }
 
Example 9
Source File: TransformTest.java    From pumpernickel with MIT License 5 votes vote down vote up
protected GeneralPath getShape(int randomSeed) {
	random.setSeed(randomSeed);
	GeneralPath path = new GeneralPath();
	path.moveTo(100 * random.nextFloat(), 100 * random.nextFloat());
	for (int a = 0; a < 3; a++) {
		int k;
		if (type.getSelectedIndex() == 0) {
			k = random.nextInt(3);
		} else if (type.getSelectedIndex() == 1) {
			k = 0;
		} else if (type.getSelectedIndex() == 2) {
			k = 1;
		} else {
			k = 2;
		}

		if (k == 0) {
			path.lineTo(100 * random.nextFloat(), 100 * random.nextFloat());
		} else if (k == 1) {
			path.quadTo(100 * random.nextFloat(), 100 * random.nextFloat(),
					100 * random.nextFloat(), 100 * random.nextFloat());
		} else {
			path.curveTo(100 * random.nextFloat(),
					100 * random.nextFloat(), 100 * random.nextFloat(),
					100 * random.nextFloat(), 100 * random.nextFloat(),
					100 * random.nextFloat());
		}
	}
	return path;
}
 
Example 10
Source File: AwtStrokeExample.java    From han3_ji7_tsoo1_kian3 with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Shape createStrokedShape(Shape shape)
{
	GeneralPath newshape = new GeneralPath(); // Start with an empty shape

	// Iterate through the specified shape, perturb its coordinates, and
	// use them to build up the new shape.
	float[] coords = new float[6];
	for (PathIterator i = shape.getPathIterator(null); !i.isDone(); i
			.next())
	{
		int type = i.currentSegment(coords);
		switch (type)
		{
		case PathIterator.SEG_MOVETO:
			perturb(coords, 2);
			newshape.moveTo(coords[0], coords[1]);
			break;
		case PathIterator.SEG_LINETO:
			perturb(coords, 2);
			newshape.lineTo(coords[0], coords[1]);
			break;
		case PathIterator.SEG_QUADTO:
			perturb(coords, 4);
			newshape.quadTo(coords[0], coords[1], coords[2], coords[3]);
			break;
		case PathIterator.SEG_CUBICTO:
			perturb(coords, 6);
			newshape.curveTo(coords[0], coords[1], coords[2], coords[3],
					coords[4], coords[5]);
			break;
		case PathIterator.SEG_CLOSE:
			newshape.closePath();
			break;
		}
	}

	// Finally, stroke the perturbed shape and return the result
	return stroke.createStrokedShape(newshape);
}
 
Example 11
Source File: ArrowBuilder.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
private static Area getArrow (float length, float bendPercent) {

        final int bodyWidth = 10;
        final float headSize = 17;

        float p1x = 0, p1y = 0;
        float p2x = length, p2y = 0;
        float cx = length / 2, cy = length / 8f * bendPercent;

        float adjSize, ex, ey, abs_e;
        adjSize = (float)(bodyWidth / 2 / Math.sqrt(2));
        ex = p2x - cx;
        ey = p2y - cy;
        abs_e = (float)Math.sqrt(ex * ex + ey * ey);
        ex /= abs_e;
        ey /= abs_e;
        GeneralPath bodyPath = new GeneralPath();
        bodyPath.moveTo(p2x + (ey - ex) * adjSize, p2y - (ex + ey) * adjSize);
        bodyPath.quadTo(cx, cy, p1x, p1y - bodyWidth / 2);
        bodyPath.lineTo(p1x, p1y + bodyWidth / 2);
        bodyPath.quadTo(cx, cy, p2x - (ey + ex) * adjSize, p2y + (ex - ey) * adjSize);
        bodyPath.closePath();

        adjSize = (float)(headSize / Math.sqrt(2));
        ex = p2x - cx;
        ey = p2y - cy;
        abs_e = (float)Math.sqrt(ex * ex + ey * ey);
        ex /= abs_e;
        ey /= abs_e;
        GeneralPath headPath = new GeneralPath();
        headPath.moveTo(p2x - (ey + ex) * adjSize, p2y + (ex - ey) * adjSize);
        headPath.lineTo(p2x, p2y);
        headPath.lineTo(p2x + (ey - ex) * adjSize, p2y - (ex + ey) * adjSize);
        headPath.closePath();

        Area area = new Area(headPath);
        area.add(new Area(bodyPath));
        return area;
    }
 
Example 12
Source File: mxLabelShape.java    From blog-codes with Apache License 2.0 5 votes vote down vote up
/**
 * Draws the glass effect
 */
public static void drawGlassEffect(mxGraphics2DCanvas canvas,
		mxCellState state)
{
	double size = 0.4;
	canvas.getGraphics().setPaint(
			new GradientPaint((float) state.getX(), (float) state.getY(),
					new Color(1, 1, 1, 0.9f), (float) (state.getX()),
					(float) (state.getY() + state.getHeight() * size),
					new Color(1, 1, 1, 0.3f)));

	float sw = (float) (mxUtils.getFloat(state.getStyle(),
			mxConstants.STYLE_STROKEWIDTH, 1) * canvas.getScale() / 2);

	GeneralPath path = new GeneralPath();
	path.moveTo((float) state.getX() - sw, (float) state.getY() - sw);
	path.lineTo((float) state.getX() - sw,
			(float) (state.getY() + state.getHeight() * size));
	path.quadTo((float) (state.getX() + state.getWidth() * 0.5),
			(float) (state.getY() + state.getHeight() * 0.7),
			(float) (state.getX() + state.getWidth() + sw),
			(float) (state.getY() + state.getHeight() * size));
	path.lineTo((float) (state.getX() + state.getWidth() + sw),
			(float) state.getY() - sw);
	path.closePath();

	canvas.getGraphics().fill(path);
}
 
Example 13
Source File: GlyphRenderer.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private void quadTo(GeneralPath path, Point ctrlPoint, Point point)
{
    path.quadTo(ctrlPoint.x, ctrlPoint.y, point.x, point.y);
    if (LOG.isDebugEnabled())
    {
        LOG.trace("quadTo: " + String.format(Locale.US, "%d,%d %d,%d", ctrlPoint.x, ctrlPoint.y,
                point.x, point.y));
    }
}
 
Example 14
Source File: MouseDraggedLinePaintableShape.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void buildShape() {
	controls.clear();

	Point start = points.get(0);
	Point p1 = start;
	Point p2 = points.get(1);

	GeneralPath path = new GeneralPath();
	path.moveTo(p1.x, p1.y);
	if (points.size() == 2) {
		path.lineTo(p2.x, p2.y);
		path.closePath();
		this.shape = path;
		return;
	}

	boolean useControl = true;
	for (int i = 2; i < points.size(); i++) {

		Point p3 = points.get(i);

		if (useControl) {
			path.quadTo(p2.x, p2.y, p3.x, p3.y);
		}
		else {
			path.lineTo(p3.x, p3.y);
		}

		useControl = !useControl;

		p1 = p2;
		p2 = p3;
	}

	for (int i = points.size() - 1; i >= 0; i--) {
		Point p = points.get(i);
		path.moveTo(p.x, p.y);
	}

	path.closePath();
	this.shape = path;
}
 
Example 15
Source File: GeneralPathObjectDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Creates an object based on this description.
 *
 * @return The object.
 */
public Object createObject() {
  final int wRule = parseWindingRule();
  if ( wRule == -1 ) {
    return null;
  }

  final PathIteratorSegment[] segments =
      (PathIteratorSegment[]) getParameter( GeneralPathObjectDescription.SEGMENTS_NAME );
  if ( segments == null ) {
    return null;
  }

  final GeneralPath path = new GeneralPath();
  path.setWindingRule( wRule );
  for ( int i = 0; i < segments.length; i++ ) {
    final int segmentType = segments[i].getSegmentType();
    switch ( segmentType ) {
      case PathIterator.SEG_CLOSE: {
        path.closePath();
        break;
      }
      case PathIterator.SEG_CUBICTO: {
        path.curveTo( segments[i].getX1(), segments[i].getY1(), segments[i].getX2(), segments[i].getY2(), segments[i]
            .getX3(), segments[i].getY3() );
        break;
      }
      case PathIterator.SEG_LINETO: {
        path.lineTo( segments[i].getX1(), segments[i].getY1() );
        break;
      }
      case PathIterator.SEG_MOVETO: {
        path.moveTo( segments[i].getX1(), segments[i].getY1() );
        break;
      }
      case PathIterator.SEG_QUADTO: {
        path.quadTo( segments[i].getX1(), segments[i].getY1(), segments[i].getX2(), segments[i].getY2() );
        break;
      }
      default:
        throw new IllegalStateException( "Unexpected result from path iterator." );
    }
  }
  return path;
}
 
Example 16
Source File: ArcDecorationPainter.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Paints the title background.
 * 
 * @param graphics
 *            Graphics context.
 * @param comp
 *            Component.
 * @param width
 *            Width.
 * @param height
 *            Height.
 * @param scheme
 *            Color scheme for painting the title background.
 */
private void paintTitleBackground(Graphics2D graphics, Component comp, int width, int height,
        SubstanceColorScheme scheme) {
    // System.out.println(scheme.getDisplayName());
    // create rectangular background and later draw it on
    // result image with contour clip.
    BufferedImage rectangular = SubstanceCoreUtilities.getBlankImage(width, height);
    Graphics2D rgraphics = (Graphics2D) rectangular.getGraphics();

    // Fill background
    GeneralPath clipTop = new GeneralPath();
    clipTop.moveTo(0, 0);
    clipTop.lineTo(width, 0);
    clipTop.lineTo(width, height / 2);
    clipTop.quadTo(width / 2, height / 4, 0, height / 2);
    clipTop.lineTo(0, 0);

    rgraphics.setClip(clipTop);
    LinearGradientPaint gradientTop = new LinearGradientPaint(0, 0, width, 0,
            new float[] { 0.0f, 0.5f, 1.0f }, new Color[] { scheme.getLightColor(),
                            scheme.getUltraLightColor(), scheme.getLightColor() },
            CycleMethod.REPEAT);
    rgraphics.setPaint(gradientTop);
    rgraphics.fillRect(0, 0, width, height);

    GeneralPath clipBottom = new GeneralPath();
    clipBottom.moveTo(0, height);
    clipBottom.lineTo(width, height);
    clipBottom.lineTo(width, height / 2);
    clipBottom.quadTo(width / 2, height / 4, 0, height / 2);
    clipBottom.lineTo(0, height);

    rgraphics.setClip(clipBottom);
    LinearGradientPaint gradientBottom = new LinearGradientPaint(0, 0, width, 0,
            new float[] { 0.0f, 0.5f, 1.0f },
            new Color[] { scheme.getMidColor(), scheme.getLightColor(), scheme.getMidColor() },
            CycleMethod.REPEAT);
    rgraphics.setPaint(gradientBottom);
    rgraphics.fillRect(0, 0, width, height);

    GeneralPath mid = new GeneralPath();
    mid.moveTo(width, height / 2);
    mid.quadTo(width / 2, height / 4, 0, height / 2);
    // rgraphics.setClip(new Rectangle(0, 0, width / 2, height));
    // rgraphics
    // .setClip(new Rectangle(width / 2, 0, width - width / 2, height));
    rgraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    rgraphics.setClip(new Rectangle(0, 0, width, height));
    rgraphics.draw(mid);

    graphics.drawImage(rectangular, 0, 0, width, height, null);
}
 
Example 17
Source File: SubstanceOutlineUtilities.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Returns outline that has a triangle pointing downwards. The top two
 * corners in the outline are rounded. This function can be used to draw
 * slider thumbs.
 * 
 * @param width
 *            Width of some UI component.
 * @param height
 *            Height of some UI component.
 * @param radius
 *            Corner radius for the top two corners.
 * @param insets
 *            Insets to compute the outline.
 * @return Outline that has a triangle poiting downwards.
 */
public static GeneralPath getTriangleButtonOutline(float width, float height,
		float radius, float insets) {

	float xs = insets;
	float ys = insets + 1;
	float xe = width - insets;
	float ye = height - insets;
	width -= 2 * insets;
	height -= 2 * insets;

	GeneralPath result = new GeneralPath();
	float radius3 = (float) (radius / (1.5 * Math.pow(height, 0.5)));
	if (Math.max(width, height) < 15)
		radius3 /= 2;

	result.moveTo(radius + xs, ys);

	if ((xe - radius) >= radius) {
		result.lineTo(xe - radius, ys);
	}
	result.quadTo(xe - radius3, ys + radius3, xe, ys + radius);

	float h2 = (ye - 1.0f) / 2.0f;
	if (h2 >= radius) {
		result.lineTo(xe, h2);
	}

	result.lineTo((xs + xe) / 2.0f, ye - 1);
	result.lineTo(xs, h2);

	if (h2 >= radius) {
		result.lineTo(xs, h2);
	}

	if ((height - radius - 1) >= radius) {
		result.lineTo(xs, radius + ys);
	}
	result.quadTo(xs + radius3, ys + radius3, xs + radius, ys);

	return result;
}
 
Example 18
Source File: SubstanceLatchWatermark.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Draws the specified portion of the watermark image.
 *
 * @param skin      Skin to use for painting the watermark.
 * @param graphics  Graphic context.
 * @param x         the <i>x</i> coordinate of the watermark to be drawn.
 * @param y         The <i>y</i> coordinate of the watermark to be drawn.
 * @param width     The width of the watermark to be drawn.
 * @param height    The height of the watermark to be drawn.
 * @param isPreview Indication whether the result is a preview image.
 * @return Indication whether the draw succeeded.
 */
private boolean drawWatermarkImage(SubstanceSkin skin, Graphics2D graphics,
        int x, int y, int width, int height, boolean isPreview) {
    Color stampColorDark = null;
    Color stampColorAll = null;
    SubstanceColorScheme scheme = skin.getWatermarkColorScheme();
    if (isPreview) {
        stampColorDark = scheme.isDark() ? Color.white : Color.black;
        stampColorAll = Color.lightGray;
    } else {
        stampColorDark = scheme.getWatermarkDarkColor();
        stampColorAll = scheme.getWatermarkStampColor();
    }

    Color c1 = stampColorDark;
    Color c2 = SubstanceColorUtilities.getInterpolatedColor(stampColorDark,
            stampColorAll, 0.5);
    graphics.setColor(stampColorAll);
    graphics.fillRect(0, 0, width, height);

    int dimension = 12;
    BufferedImage tile = NeonCortex.getBlankUnscaledImage(dimension, dimension);
    GeneralPath latch1 = new GeneralPath();
    latch1.moveTo(0.45f * dimension, 0);
    latch1.quadTo(0.45f * dimension, 0.45f * dimension, 0.05f * dimension, 0.45f * dimension);
    latch1.quadTo(0.15f * dimension, 0.15f * dimension, 0.45f * dimension, 0);
    this.drawLatch(tile, latch1, c1, c2);

    GeneralPath latch2 = new GeneralPath();
    latch2.moveTo(0.55f * dimension, 0.55f * dimension);
    latch2.quadTo(0.75f * dimension, 0.4f * dimension, dimension, dimension);
    latch2.quadTo(0.4f * dimension, 0.75f * dimension, 0.5f * dimension, 0.5f * dimension);
    this.drawLatch(tile, latch2, c1, c2);

    for (int row = 0; row < height; row += dimension) {
        for (int col = 0; col < width; col += dimension) {
            graphics.drawImage(tile, x + col, y + row, null);
        }
    }
    return true;
}
 
Example 19
Source File: MacUIUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void paintComboboxFocusRing(@Nonnull final Graphics2D g2d, @Nonnull final Rectangle bounds) {
  final Color color = getFocusRingColor();
  final Color[] colors =
          new Color[]{ColorUtil.toAlpha(color, 180), ColorUtil.toAlpha(color, 130), ColorUtil.toAlpha(color, 80), ColorUtil.toAlpha(color, 80)};

  final Object oldAntialiasingValue = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
  final Object oldStrokeControlValue = g2d.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);

  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, USE_QUARTZ ? RenderingHints.VALUE_STROKE_PURE : RenderingHints.VALUE_STROKE_NORMALIZE);

  int _y = MAC_COMBO_BORDER_V_OFFSET;

  final GeneralPath path1 = new GeneralPath();
  path1.moveTo(2, _y + 4);
  path1.quadTo(2, +_y + 2, 4, _y + 2);
  path1.lineTo(bounds.width - 7, _y + 2);
  path1.quadTo(bounds.width - 5, _y + 3, bounds.width - 4, _y + 5);
  path1.lineTo(bounds.width - 4, bounds.height - 7 + _y);
  path1.quadTo(bounds.width - 5, bounds.height - 5 + _y, bounds.width - 7, bounds.height - 4 + _y);
  path1.lineTo(4, bounds.height - 4 + _y);
  path1.quadTo(2, bounds.height - 4 + _y, 2, bounds.height - 6 + _y);
  path1.closePath();

  g2d.setColor(colors[0]);
  g2d.draw(path1);

  final GeneralPath path2 = new GeneralPath();
  path2.moveTo(1, 5 + _y);
  path2.quadTo(1, 1 + _y, 5, 1 + _y);
  path2.lineTo(bounds.width - 8, 1 + _y);
  path2.quadTo(bounds.width - 4, 2 + _y, bounds.width - 3, 6 + _y);
  path2.lineTo(bounds.width - 3, bounds.height - 7 + _y);
  path2.quadTo(bounds.width - 4, bounds.height - 4 + _y, bounds.width - 8, bounds.height - 3 + _y);
  path2.lineTo(4, bounds.height - 3 + _y);
  path2.quadTo(1, bounds.height - 3 + _y, 1, bounds.height - 6 + _y);
  path2.closePath();

  g2d.setColor(colors[1]);
  g2d.draw(path2);

  final GeneralPath path3 = new GeneralPath();
  path3.moveTo(0, 4 + _y);
  path3.quadTo(0, _y, 7, _y);
  path3.lineTo(bounds.width - 9, _y);
  path3.quadTo(bounds.width - 2, 1 + _y, bounds.width - 2, 7 + _y);
  path3.lineTo(bounds.width - 2, bounds.height - 8 + _y);
  path3.quadTo(bounds.width - 3, bounds.height - 1 + _y, bounds.width - 12, bounds.height - 2 + _y);
  path3.lineTo(7, bounds.height - 2 + _y);
  path3.quadTo(0, bounds.height - 1 + _y, 0, bounds.height - 7 + _y);
  path3.closePath();

  g2d.setColor(colors[2]);
  g2d.draw(path3);

  // restore rendering hints
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAntialiasingValue);
  g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, oldStrokeControlValue);
}
 
Example 20
Source File: AbstractPopupPainter.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates and returns dropdown style shape.
 *
 * @param popup     popup component
 * @param popupSize popup size
 * @param fill      whether it is a fill shape or not
 * @return dropdown style shape
 */
protected GeneralPath createDropdownShape ( final C popup, final Dimension popupSize, final boolean fill )
{
    final boolean topCorner = cornerSide == TOP;
    final boolean bottomCorner = cornerSide == BOTTOM;
    final boolean leftCorner = cornerSide == LEFT || cornerSide == LEADING;
    final boolean rightCorner = cornerSide == RIGHT || cornerSide == TRAILING;

    // Painting shear
    final int shear = fill ? 1 : 0;

    // Side width
    final int sideWidth = getSideWidth ();

    // Corner left spacing
    final int cornerShear = sideWidth + shear + round + cornerWidth * 2;
    final int length = topCorner || bottomCorner ? popupSize.width : popupSize.height;
    final int spacing;
    if ( cornerAlignment == CENTER || length < sideWidth * 2 + round * 2 + cornerWidth * 4 )
    {
        spacing = length / 2 - sideWidth - round - cornerWidth * 2;
    }
    else if ( cornerAlignment == LEFT || cornerAlignment == LEADING && ltr || cornerAlignment == TRAILING && !ltr )
    {
        spacing = 0;
    }
    else if ( cornerAlignment == RIGHT || cornerAlignment == TRAILING && ltr || cornerAlignment == LEADING && !ltr )
    {
        spacing = length - cornerShear * 2;
    }
    else
    {
        spacing = relativeCorner < sideWidth + round + cornerWidth * 2 ? 0 :
                Math.min ( relativeCorner - cornerShear, length - cornerShear * 2 );
    }

    // Side spacings
    final int top = sideWidth + shear;
    final int right = popupSize.width - 1 - sideWidth;
    final int bottom = popupSize.height - 1 - sideWidth;
    final int left = sideWidth + shear;

    final GeneralPath shape = new GeneralPath ( GeneralPath.WIND_EVEN_ODD );
    shape.moveTo ( left, top + round );
    shape.quadTo ( left, top, left + round, top );
    if ( topCorner )
    {
        // Top corner
        shape.lineTo ( left + round + spacing + cornerWidth, top );
        shape.lineTo ( left + round + spacing + cornerWidth * 2, top - cornerWidth );
        shape.lineTo ( left + round + spacing + cornerWidth * 2 + 1, top - cornerWidth );
        shape.lineTo ( left + round + spacing + cornerWidth * 3 + 1, top );
    }
    shape.lineTo ( right - round, top );
    shape.quadTo ( right, top, right, top + round );
    if ( rightCorner )
    {
        // Right corner
        shape.lineTo ( right, top + round + spacing + cornerWidth );
        shape.lineTo ( right + cornerWidth, top + round + spacing + cornerWidth * 2 );
        shape.lineTo ( right + cornerWidth, top + round + spacing + cornerWidth * 2 + 1 );
        shape.lineTo ( right, top + round + spacing + cornerWidth * 3 + 1 );
    }
    shape.lineTo ( right, bottom - round );
    shape.quadTo ( right, bottom, right - round, bottom );
    if ( bottomCorner )
    {
        // Bottom corner
        shape.lineTo ( left + round + spacing + cornerWidth * 3 + 1, bottom );
        shape.lineTo ( left + round + spacing + cornerWidth * 2 + 1, bottom + cornerWidth );
        shape.lineTo ( left + round + spacing + cornerWidth * 2, bottom + cornerWidth );
        shape.lineTo ( left + round + spacing + cornerWidth, bottom );
    }
    shape.lineTo ( left + round, bottom );
    shape.quadTo ( left, bottom, left, bottom - round );
    if ( leftCorner )
    {
        // Left corner
        shape.lineTo ( left, top + round + spacing + cornerWidth * 3 + 1 );
        shape.lineTo ( left - cornerWidth, top + round + spacing + cornerWidth * 2 + 1 );
        shape.lineTo ( left - cornerWidth, top + round + spacing + cornerWidth * 2 );
        shape.lineTo ( left, top + round + spacing + cornerWidth );
    }
    shape.closePath ();

    return shape;
}