當前位置: 首頁>>代碼示例>>Java>>正文


Java GeneralPath類代碼示例

本文整理匯總了Java中java.awt.geom.GeneralPath的典型用法代碼示例。如果您正苦於以下問題:Java GeneralPath類的具體用法?Java GeneralPath怎麽用?Java GeneralPath使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


GeneralPath類屬於java.awt.geom包,在下文中一共展示了GeneralPath類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createConnectionSpline

import java.awt.geom.GeneralPath; //導入依賴的package包/類
/**
 * Creates a spline connector shape from one {@link Point2D} to another.
 *
 * @param from
 *            the starting point
 * @param to
 *            the end point
 * @return the shape representing the connection, never {@code null}
 */
public static Shape createConnectionSpline(final Point2D from, final Point2D to) {
	if (from == null || to == null) {
		throw new IllegalArgumentException("from and to must not be null!");
	}

	int delta = 10;
	GeneralPath connector = new GeneralPath();
	connector.moveTo(from.getX() + 1, from.getY());
	double cx = (from.getX() + to.getX()) / 2;
	double cy = (from.getY() + to.getY()) / 2;
	if (to.getX() >= from.getX() + 2 * delta) {
		connector.curveTo(cx, from.getY(), cx, from.getY(), cx, cy);
		connector.curveTo(cx, to.getY(), cx, to.getY(), to.getX() - 1, to.getY());
	} else {
		connector.curveTo(from.getX() + delta, from.getY(), from.getX() + delta, cy, cx, cy);
		connector.curveTo(to.getX() - delta, cy, to.getX() - delta, to.getY(), to.getX() - 1, to.getY());
	}
	return connector;
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:29,代碼來源:ProcessDrawUtils.java

示例2: paintComponent

import java.awt.geom.GeneralPath; //導入依賴的package包/類
@Override
public void paintComponent(Graphics g) {
	super.paintComponent(g);

	GeneralPath arrow = new GeneralPath();
	int w, h;
	h = (int) (2 * sizeFactor);
	w = (int) (4 * sizeFactor);
	arrow.moveTo(getWidth() / 2 - w, getHeight() / 2);
	arrow.lineTo(getWidth() / 2 + w, getHeight() / 2);
	arrow.lineTo(getWidth() / 2, getHeight() / 2 + 2 * h);
	arrow.closePath();
	if (isEnabled()) {
		g.setColor(Color.BLACK);
	} else {
		g.setColor(Color.GRAY);
	}
	((Graphics2D) g).fill(arrow);
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:20,代碼來源:DropDownButton.java

示例3: createHexagonShape

import java.awt.geom.GeneralPath; //導入依賴的package包/類
/** Creates a hexagonal shape inscribed in the bounds given in the parameters. */
private Shape createHexagonShape(double x, double y, double width, double height) {
    GeneralPath result = new GeneralPath(Path2D.WIND_NON_ZERO, 5);
    double extend = height * NodeShape.HEX_EXTEND_RATIO;
    // stat at top left corner
    result.moveTo(x + extend, y);
    // to top right
    result.lineTo(x + width - extend, y);
    // to right
    result.lineTo(x + width, y + height / 2);
    // to bottom right
    result.lineTo(x + width - extend, y + height);
    // to bottom left
    result.lineTo(x + extend, y + height);
    // to left
    result.lineTo(x, y + height / 2);
    result.closePath();
    return result;
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:20,代碼來源:JVertexView.java

示例4: paintMatcher

import java.awt.geom.GeneralPath; //導入依賴的package包/類
private void paintMatcher(Graphics2D g, Color fillClr, 
        int leftX, int rightX, int upL, int upR, int doR, int doL) {
    int topY = Math.min(upL, upR), bottomY = Math.max(doL, doR);
    // try rendering only curves in viewable area
    if (!g.hitClip(leftX, topY, rightX - leftX, bottomY - topY)) {
        return;
    }
    CubicCurve2D upper = new CubicCurve2D.Float(leftX, upL,
            (rightX -leftX)*.3f, upL,
            (rightX -leftX)*.7f, upR,
            rightX, upR);
    CubicCurve2D bottom = new CubicCurve2D.Float(rightX, doR,
            (rightX - leftX)*.7f, doR,
            (rightX -leftX)*.3f, doL,
            leftX, doL);
    GeneralPath path = new GeneralPath();
    path.append(upper, false);
    path.append(bottom, true);
    path.closePath();
    g.setColor(fillClr);
    g.fill(path);
    g.setColor(master.getColorLines());
    g.draw(upper);
    g.draw(bottom);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:DiffSplitPaneDivider.java

示例5: mapShape

import java.awt.geom.GeneralPath; //導入依賴的package包/類
public Shape mapShape(Shape s) {
    if (LOGMAP) LOG.format("mapshape on path: %s\n", LayoutPathImpl.SegmentPath.this);
    PathIterator pi = s.getPathIterator(null, 1); // cheap way to handle curves.

    if (LOGMAP) LOG.format("start\n");
    init();

    final double[] coords = new double[2];
    while (!pi.isDone()) {
        switch (pi.currentSegment(coords)) {
        case SEG_CLOSE: close(); break;
        case SEG_MOVETO: moveTo(coords[0], coords[1]); break;
        case SEG_LINETO: lineTo(coords[0], coords[1]); break;
        default: break;
        }

        pi.next();
    }
    if (LOGMAP) LOG.format("finish\n\n");

    GeneralPath gp = new GeneralPath();
    for (Segment seg: segments) {
        gp.append(seg.gp, false);
    }
    return gp;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:LayoutPathImpl.java

示例6: getCircleOfStars

import java.awt.geom.GeneralPath; //導入依賴的package包/類
/**
 * Returns either a single star, or a circle of stars with the
 * given radius, centered at the origin.
 *
 * @param radius The radius of the circle.
 * @return The circle of stars.
 */
private GeneralPath getCircleOfStars(double radius) {
    double phi = Math.PI * 2 / stars;
    GeneralPath unionPath = new GeneralPath();
    if (stars == 0) {
        // nothing to do
    } else if (stars == 1) {
        // one double sized star
        unionPath = getStar(2, 0, 0);
    } else if (stars == 2) {
        // two larger stars, on the x axis
        unionPath.append(getStar(1.5, -radius, 0), false);
        unionPath.append(getStar(1.5, radius, 0), false);
    } else {
        // a general circle of stars
        for (int i = 0; i < stars; i++) {
            double x = -radius - radius * Math.sin(i * phi);
            double y = -radius * Math.cos(i * phi);
            unionPath.append(getStar(x, y), false);
        }
    }
    return unionPath;
}
 
開發者ID:wintertime,項目名稱:FreeCol,代碼行數:30,代碼來源:Flag.java

示例7: getUnderlineShape

import java.awt.geom.GeneralPath; //導入依賴的package包/類
Shape getUnderlineShape(float thickness,
                        float x1,
                        float x2,
                        float y) {

    GeneralPath gp = new GeneralPath();

    Line2D.Float line = new Line2D.Float(x1, y, x2, y);
    gp.append(stroke.createStrokedShape(line), false);

    line.y1 += DEFAULT_THICKNESS;
    line.y2 += DEFAULT_THICKNESS;
    line.x1 += DEFAULT_THICKNESS;

    gp.append(stroke.createStrokedShape(line), false);

    return gp;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:Underline.java

示例8: polygon

import java.awt.geom.GeneralPath; //導入依賴的package包/類
/**
 * Draws a polygon with the vertices 
 * (<em>x</em><sub>0</sub>, <em>y</em><sub>0</sub>),
 * (<em>x</em><sub>1</sub>, <em>y</em><sub>1</sub>), ...,
 * (<em>x</em><sub><em>n</em>–1</sub>, <em>y</em><sub><em>n</em>–1</sub>).
 *
 * @param  x an array of all the <em>x</em>-coordinates of the polygon
 * @param  y an array of all the <em>y</em>-coordinates of the polygon
 * @throws IllegalArgumentException unless {@code x[]} and {@code y[]}
 *         are of the same length
 */
public static void polygon(double[] x, double[] y) {
    if (x == null) throw new IllegalArgumentException("x-coordinate array is null");
    if (y == null) throw new IllegalArgumentException("y-coordinate array is null");
    int n1 = x.length;
    int n2 = y.length;
    if (n1 != n2) throw new IllegalArgumentException("arrays must be of the same length");
    int n = n1;
    if (n == 0) return;

    GeneralPath path = new GeneralPath();
    path.moveTo((float) scaleX(x[0]), (float) scaleY(y[0]));
    for (int i = 0; i < n; i++)
        path.lineTo((float) scaleX(x[i]), (float) scaleY(y[i]));
    path.closePath();
    offscreen.draw(path);
    draw();
}
 
開發者ID:DCMMC,項目名稱:Java-Algorithms-Learning,代碼行數:29,代碼來源:StdDraw.java

示例9: drawPerSaltire

import java.awt.geom.GeneralPath; //導入依賴的package包/類
private void drawPerSaltire(Graphics2D g) {
    int colors = backgroundColors.size();
    GeneralPath path = new GeneralPath();
    int[] x = { 0, WIDTH, WIDTH, 0 };
    int[] y = { 0, 0, HEIGHT, HEIGHT };
    double halfWidth = WIDTH / 2;
    double halfHeight = HEIGHT / 2;
    for (int index = 0; index < 4; index++) {
        path.moveTo(x[index], y[index]);
        path.lineTo(halfWidth, halfHeight);
        int nextIndex = (index + 1) % 4;
        path.lineTo(x[nextIndex], y[nextIndex]);
        g.setColor(backgroundColors.get(index % colors));
        g.fill(path);
        path.reset();
    }
}
 
開發者ID:wintertime,項目名稱:FreeCol,代碼行數:18,代碼來源:Flag.java

示例10: getStar

import java.awt.geom.GeneralPath; //導入依賴的package包/類
/**
 * Return the basic five-point star.
 *
 * @return the basic star shape
 */
private static GeneralPath getStar() {
    GeneralPath star = new GeneralPath(GeneralPath.WIND_NON_ZERO);
    double angle = 2 * Math.PI / 5;
    double radius = STAR_SIZE / 2;
    double x = 0;
    double y = -radius;
    star.moveTo(x, y);
    int[] vertex = { 2, 4, 1, 3 };
    for (int i : vertex) {
        double phi = i * angle;
        x = radius * Math.sin(phi);
        y = -radius * Math.cos(phi);
        star.lineTo(x, y);
    }
    star.closePath();
    return star;
}
 
開發者ID:wintertime,項目名稱:FreeCol,代碼行數:23,代碼來源:Flag.java

示例11: createDiamondShape

import java.awt.geom.GeneralPath; //導入依賴的package包/類
/** Creates a diamond shape inscribed in the bounds given in the parameters. */
private Shape createDiamondShape(double x, double y, double width, double height) {
    GeneralPath result = new GeneralPath(Path2D.WIND_NON_ZERO, 5);
    result.moveTo(x + width / 2, y);
    result.lineTo(x + width, y + height / 2);
    result.lineTo(x + width / 2, y + height);
    result.lineTo(x, y + height / 2);
    result.closePath();
    return result;
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:11,代碼來源:JVertexView.java

示例12: getGlyphOutlineBounds

import java.awt.geom.GeneralPath; //導入依賴的package包/類
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        result = gp.getBounds2D();
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:StandardGlyphVector.java

示例13: paintYPin

import java.awt.geom.GeneralPath; //導入依賴的package包/類
private void paintYPin(Graphics2D g, int number) {
    double y = top;
    for (int i = 0; i < number; i++) {
        y += yBounds[i].getSize().getHeight();
    }
    g.setColor(Color.black);

    double max = 6;

    g.setPaint(new GradientPaint(new Point2D.Double(LEFT - max, y - max),
            Color.green, new Point2D.Double(LEFT + max, y + max),
            Color.black));

    GeneralPath path1 = new GeneralPath(Path2D.WIND_EVEN_ODD, 4);
    GeneralPath path2 = new GeneralPath(Path2D.WIND_EVEN_ODD, 4);
    path1.moveTo(LEFT - 5, y);
    path1.lineTo(LEFT - 5 - max, y + max / 2);
    path1.lineTo(LEFT - 5 - max, y - max / 2);
    path1.lineTo(LEFT - 5, y);

    path2.moveTo(5 + LEFT + width, y);
    path2.lineTo(5 + LEFT + width + max, y + max / 2);
    path2.lineTo(5 + LEFT + width + max, y - max / 2);
    path2.lineTo(5 + LEFT + width, y);

    g.fill(path1);
    g.setPaint(new GradientPaint(new Point2D.Double(LEFT + width - max, y
            - max), Color.black, new Point2D.Double(LEFT + max + width, y
            + max), Color.green));
    g.fill(path2);
    g.setColor(Color.gray);
    g.draw(path1);
    g.draw(path2);
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:35,代碼來源:XMLDiagram.java

示例14: getTriangle

import java.awt.geom.GeneralPath; //導入依賴的package包/類
protected int getTriangle(final FloatPoint point) {
    int res = -1;

    FloatPoint l = getLocation();

    for (int type = MovingPanel.RIGHT; type <= MovingPanel.TOP; type++) {
        GeneralPath gp = getTrianglePath(type);
        double y = point.getY() + l.getY();
        double x = point.getX() + l.getX();
        if (gp.contains(new Point2D.Double(x, y))) {
            res = type;
            break;
        }
    }

    return res;
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:18,代碼來源:DFDFunctionEllipse.java

示例15: drawGlassEffect

import java.awt.geom.GeneralPath; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:26,代碼來源:mxLabelShape.java


注:本文中的java.awt.geom.GeneralPath類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。