Package java.awt.geom

Examples of java.awt.geom.GeneralPath


   * @param s the size factor (equal to half the height of the triangle).
   * @return A triangle shape.
   */
  public static Shape createUpTriangle(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;
  }
View Full Code Here


   * @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;
  }
View Full Code Here

    }

    private static Shape generateStar(double x, double y,
                                      double innerRadius, double outerRadius,
                                      int branchesCount) {
        GeneralPath path = new GeneralPath();

        double outerAngleIncrement = 2 * Math.PI / branchesCount;

        double outerAngle = 0.0;
        double innerAngle = outerAngleIncrement / 2.0;

        x += outerRadius;
        y += outerRadius;

        float x1 = (float) (Math.cos(outerAngle) * outerRadius + x);
        float y1 = (float) (Math.sin(outerAngle) * outerRadius + y);

        float x2 = (float) (Math.cos(innerAngle) * innerRadius + x);
        float y2 = (float) (Math.sin(innerAngle) * innerRadius + y);

        path.moveTo(x1, y1);
        path.lineTo(x2, y2);

        outerAngle += outerAngleIncrement;
        innerAngle += outerAngleIncrement;

        for (int i = 1; i < branchesCount; i++) {
            x1 = (float) (Math.cos(outerAngle) * outerRadius + x);
            y1 = (float) (Math.sin(outerAngle) * outerRadius + y);

            path.lineTo(x1, y1);

            x2 = (float) (Math.cos(innerAngle) * innerRadius + x);
            y2 = (float) (Math.sin(innerAngle) * innerRadius + y);

            path.lineTo(x2, y2);

            outerAngle += outerAngleIncrement;
            innerAngle += outerAngleIncrement;
        }

        path.closePath();
        return path;
    }
View Full Code Here

        return poly;
    }

    // converts circles into polygons
    public static OMPoly convert(OMCircle omCircle, Projection proj) {
        GeneralPath shape = omCircle.getShape();

        // get the PathIterator that defines the outline of the circle
        PathIterator circle = shape.getPathIterator(null);
        Vector initialPoints = new Vector();
        float[] segPoints = new float[2];

        while (!circle.isDone()) {
            // by passing segpoints the array is filled with each x\y
View Full Code Here

    // scan through the datasets
        for(int lRow = 0; lRow < lNumberOfRows; lRow++)
        {
      // scan through the values in the dataset
      GeneralPath filledPolygon = new GeneralPath(GeneralPath.WIND_EVEN_ODD, lNumberOfColumns);
      for (int lCol = 0; lCol < lNumberOfColumns; lCol++)
      {
        // get the value
                double lValue = m.getValueAt(lRow, lCol).doubleValue();
       
            // determine the scale
            double lMaxValue = maxvalues[lCol];
               
                if(lMaxValue == 0.0) {
                    for(int row = 0; row < lNumberOfRows; row++)
                        lMaxValue = Math.max(lMaxValue, m.getValueAt(row, lCol).doubleValue() * 1.1);
                   
                    maxvalues[lCol] = lMaxValue;
                }
               
            double lScaledValue = lValue / lMaxValue;
            double lLineValue = lRadius * lScaledValue;

        // determine rotation: there are 2PI/noOfCols vertexes, this is vertex no lCol   
        // -1 : we want to rotate clockwise
        // + PI: rotate 180 degree to get the first column pointing up
        double lRotation = (-1 * (2 * Math.PI / lNumberOfColumns) * lCol) + Math.PI;

        // determine the end points
        double lX = center_x + (lLineValue * Math.sin(lRotation));
        double lY = center_y + (lLineValue * Math.cos(lRotation));

        // draw the line
        Line2D lLine = new Line2D.Double(center_x, center_y, lX, lY);
            g.setColor(Color.black);
            g.draw(lLine);

        // add to polygone
        if (lCol == 0) filledPolygon.moveTo((float)lX, (float)lY);
        else filledPolygon.lineTo((float)lX, (float)lY);           
      }
     
      // draw the polygone
      filledPolygon.closePath();
      g.setPaint( rcm.getColor(lRow) );
      g.draw(filledPolygon);
        }
       
        double lRotation;
View Full Code Here

                    new double[] { x0, y0, x1, y1 };
    }


    private static GeneralPath pathToShape(double[] path, boolean close, LayoutPathImpl lp) {
        GeneralPath result = new GeneralPath(GeneralPath.WIND_EVEN_ODD, path.length);
        result.moveTo((float)path[0], (float)path[1]);
        for (int i = 2; i < path.length; i += 2) {
            result.lineTo((float)path[i], (float)path[i+1]);
        }
        if (close) {
            result.closePath();
        }

        if (lp != null) {
            result = (GeneralPath)lp.mapShape(result);
        }
View Full Code Here

        // that.  We do need to prevent the two segments which
        // join path0 to path1 from crossing each other.  So, if we
        // traverse path0 from top to bottom, we'll traverse path1 from
        // bottom to top (and vice versa).

        GeneralPath result = pathToShape(path0, false, null);

        boolean sameDirection;
               
        if (isVerticalLine) {
            sameDirection = (path0[1] > path0[path0.length-1]) ==
                            (path1[1] > path1[path1.length-1]);
        }
        else {
            sameDirection = (path0[0] > path0[path0.length-2]) ==
                            (path1[0] > path1[path1.length-2]);
        }

        int start;
        int limit;
        int increment;

        if (sameDirection) {
            start = path1.length-2;
            limit = -2;
            increment = -2;
        }
        else {
            start = 0;
            limit = path1.length;
            increment = 2;
        }

        for (int i = start; i != limit; i += increment) {
            result.lineTo((float)path1[i], (float)path1[i+1]);
        }

        result.closePath();

        return result;
    }
View Full Code Here

        if(bounds == null) {
                throw new IllegalArgumentException("Null Rectangle2D passed to TextLayout.getVisualHighlightShape()");
        }

        GeneralPath result = new GeneralPath(GeneralPath.WIND_EVEN_ODD);

        int firstCaret = hitToCaret(firstEndpoint);
        int secondCaret = hitToCaret(secondEndpoint);

        result.append(caretBoundingShape(firstCaret, secondCaret, bounds),
                      false);

        if (firstCaret == 0 || secondCaret == 0) {
            GeneralPath ls = leftShape(bounds);
            if (!ls.getBounds().isEmpty())
                result.append(ls, false);
        }

        if (firstCaret == characterCount || secondCaret == characterCount) {
            GeneralPath rs = rightShape(bounds);
            if (!rs.getBounds().isEmpty()) {
                result.append(rs, false);
            }
        }

        LayoutPathImpl lp = textLine.getLayoutPath();
View Full Code Here

        if(firstEndpoint < 0 || secondEndpoint > characterCount) {
            throw new IllegalArgumentException("Range is invalid in TextLayout.getLogicalHighlightShape()");
        }

        GeneralPath result = new GeneralPath(GeneralPath.WIND_EVEN_ODD);

        int[] carets = new int[10]; // would this ever not handle all cases?
        int count = 0;

        if (firstEndpoint < secondEndpoint) {
            int logIndex = firstEndpoint;
            do {
                carets[count++] = hitToCaret(TextHitInfo.leading(logIndex));
                boolean ltr = textLine.isCharLTR(logIndex);

                do {
                    logIndex++;
                } while (logIndex < secondEndpoint && textLine.isCharLTR(logIndex) == ltr);

                int hitCh = logIndex;
                carets[count++] = hitToCaret(TextHitInfo.trailing(hitCh - 1));

                if (count == carets.length) {
                    int[] temp = new int[carets.length + 10];
                    System.arraycopy(carets, 0, temp, 0, count);
                    carets = temp;
                }
            } while (logIndex < secondEndpoint);
        }
        else {
            count = 2;
            carets[0] = carets[1] = hitToCaret(TextHitInfo.leading(firstEndpoint));
        }

        // now create paths for pairs of carets

        for (int i = 0; i < count; i += 2) {
            result.append(caretBoundingShape(carets[i], carets[i+1], bounds),
                          false);
        }

        if (firstEndpoint != secondEndpoint) {
            if ((textLine.isDirectionLTR() && firstEndpoint == 0) || (!textLine.isDirectionLTR() &&
                                                                      secondEndpoint == characterCount)) {
                GeneralPath ls = leftShape(bounds);
                if (!ls.getBounds().isEmpty()) {
                    result.append(ls, false);
                }
            }

            if ((textLine.isDirectionLTR() && secondEndpoint == characterCount) ||
                (!textLine.isDirectionLTR() && firstEndpoint == 0)) {

                GeneralPath rs = rightShape(bounds);
                if (!rs.getBounds().isEmpty()) {
                    result.append(rs, false);
                }
            }
        }
View Full Code Here

        /*
         * return an area that consists of the bounding boxes of all the
         * characters from firstEndpoint to limit
         */
        GeneralPath result = new GeneralPath(GeneralPath.WIND_NON_ZERO);

        if (firstEndpoint < characterCount) {
            for (int logIndex = firstEndpoint;
                        logIndex < secondEndpoint;
                        logIndex++) {

                Rectangle2D r = textLine.getCharBounds(logIndex);
                if (!r.isEmpty()) {
                    result.append(r, false);
                }
            }
        }

        if (dx != 0 || dy != 0) {
View Full Code Here

TOP

Related Classes of java.awt.geom.GeneralPath

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.