Java Code Examples for java.awt.geom.RoundRectangle2D#getArcWidth()

The following examples show how to use java.awt.geom.RoundRectangle2D#getArcWidth() . 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: RoundRectangle2DObjectDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Sets the parameters of this description object to match the supplied object.
 *
 * @param o
 *          the object (should be an instance of <code>Rectangle2D</code>).
 * @throws ObjectFactoryException
 *           if the object is not an instance of <code>Rectangle2D</code>.
 */
public void setParameterFromObject( final Object o ) throws ObjectFactoryException {
  if ( !( o instanceof RoundRectangle2D ) ) {
    throw new ObjectFactoryException( "The given object is no java.awt.geom.Rectangle2D." );
  }

  final RoundRectangle2D rect = (RoundRectangle2D) o;
  final float x = (float) rect.getX();
  final float y = (float) rect.getY();
  final float w = (float) rect.getWidth();
  final float h = (float) rect.getHeight();
  final float aw = (float) rect.getArcWidth();
  final float ah = (float) rect.getArcHeight();

  setParameter( "x", new Float( x ) );
  setParameter( "y", new Float( y ) );
  setParameter( "width", new Float( w ) );
  setParameter( "height", new Float( h ) );
  setParameter( "arcWidth", new Float( aw ) );
  setParameter( "arcHeight", new Float( ah ) );
}
 
Example 2
Source File: GraphicsUtils.java    From jfreesvg with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a shape that is (more or less) equivalent to the supplied shape.
 * For some known shape implementations ({@code Line2D}, 
 * {@code Rectangle2D}, {@code RoundRectangle2D}, {@code Arc2D}, 
 * {@code Ellipse2D}, and {@code Polygon}) the copy will be an instance of 
 * that class.  For other shapes, a {@code Path2D} containing the outline 
 * of the shape is returned.
 * 
 * @param shape  the shape ({@code null} not permitted).
 * 
 * @return A copy of the shape or shape outline (never {@code null}). 
 */
public static Shape copyOf(Shape shape) {
   Args.nullNotPermitted(shape, "shape");
   if (shape instanceof Line2D) {
       Line2D l = (Line2D) shape;
       return new Line2D.Double(l.getX1(), l.getY1(), l.getX2(), l.getY2());
   }
   if (shape instanceof Rectangle2D) {
       Rectangle2D r = (Rectangle2D) shape;
       return new Rectangle2D.Double(r.getX(), r.getY(), r.getWidth(), 
               r.getHeight());
   }
   if (shape instanceof RoundRectangle2D) {
       RoundRectangle2D rr = (RoundRectangle2D) shape;
       return new RoundRectangle2D.Double(rr.getX(), rr.getY(), 
               rr.getWidth(), rr.getHeight(), rr.getArcWidth(), 
               rr.getArcHeight());
   }
   if (shape instanceof Arc2D) {
       Arc2D arc = (Arc2D) shape;
       return new Arc2D.Double(arc.getX(), arc.getY(), arc.getWidth(),
               arc.getHeight(), arc.getAngleStart(), arc.getAngleExtent(),
               arc.getArcType());
   }
   if (shape instanceof Ellipse2D) {
       Ellipse2D ell = (Ellipse2D) shape;
       return new Ellipse2D.Double(ell.getX(), ell.getY(), ell.getWidth(),
               ell.getHeight());
   }
   if (shape instanceof Polygon) {
       Polygon p = (Polygon) shape;
       return new Polygon(p.xpoints, p.ypoints, p.npoints);
   }
   return new Path2D.Double(shape);
}
 
Example 3
Source File: SparkLine.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a buffered image that contains the background of the sparkline component
 * @param WIDTH
 * @param HEIGHT
 * @return a buffered image that contains the background of the sparkline component
 */
private BufferedImage create_SPARK_LINE_BACKGROUND_Image(final int WIDTH, final int HEIGHT) {
    if (WIDTH <= 0 || HEIGHT <= 0) {
        return null;
    }

    final BufferedImage IMAGE = UTIL.createImage(WIDTH, HEIGHT, Transparency.TRANSLUCENT);
    final Graphics2D G2 = IMAGE.createGraphics();
    G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    G2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    final int IMAGE_WIDTH = IMAGE.getWidth();
    final int IMAGE_HEIGHT = IMAGE.getHeight();

    // Background rectangle
    final Point2D BACKGROUND_START = new Point2D.Double(0.0, 0.0);
    final Point2D BACKGROUND_STOP = new Point2D.Double(0.0, IMAGE_HEIGHT);
    if (BACKGROUND_START.equals(BACKGROUND_STOP)) {
        BACKGROUND_STOP.setLocation(0.0, BACKGROUND_START.getY() + 1);
    }

    final float[] BACKGROUND_FRACTIONS = {
        0.0f,
        0.08f,
        0.92f,
        1.0f
    };

    final Color[] BACKGROUND_COLORS = {
        new Color(0.4f, 0.4f, 0.4f, 1.0f),
        new Color(0.5f, 0.5f, 0.5f, 1.0f),
        new Color(0.5f, 0.5f, 0.5f, 1.0f),
        new Color(0.9f, 0.9f, 0.9f, 1.0f)
    };

    final LinearGradientPaint BACKGROUND_GRADIENT = new LinearGradientPaint(BACKGROUND_START, BACKGROUND_STOP, BACKGROUND_FRACTIONS, BACKGROUND_COLORS);
    final double BACKGROUND_CORNER_RADIUS = WIDTH > HEIGHT ? (HEIGHT * 0.12) : (WIDTH * 0.12);
    final RoundRectangle2D BACKGROUND = new RoundRectangle2D.Double(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, BACKGROUND_CORNER_RADIUS, BACKGROUND_CORNER_RADIUS);
    G2.setPaint(BACKGROUND_GRADIENT);
    G2.fill(BACKGROUND);

    // Foreground rectangle
    final Point2D FOREGROUND_START = new Point2D.Double(0.0, 1.0);
    final Point2D FOREGROUND_STOP = new Point2D.Double(0.0, IMAGE_HEIGHT - 1);
    if (FOREGROUND_START.equals(FOREGROUND_STOP)) {
        FOREGROUND_STOP.setLocation(0.0, FOREGROUND_START.getY() + 1);
    }

    final float[] FOREGROUND_FRACTIONS = {
        0.0f,
        0.03f,
        0.49f,
        0.5f,
        1.0f
    };

    final Color[] FOREGROUND_COLORS = {
        sparkLineColor.GRADIENT_START_COLOR,
        sparkLineColor.GRADIENT_FRACTION1_COLOR,
        sparkLineColor.GRADIENT_FRACTION2_COLOR,
        sparkLineColor.GRADIENT_FRACTION3_COLOR,
        sparkLineColor.GRADIENT_STOP_COLOR
    };

    if (customSparkLineColor != null && sparkLineColor == LcdColor.CUSTOM) {
        G2.setPaint(customSparkLineColor);
    } else {
        final LinearGradientPaint FOREGROUND_GRADIENT = new LinearGradientPaint(FOREGROUND_START, FOREGROUND_STOP, FOREGROUND_FRACTIONS, FOREGROUND_COLORS);
        G2.setPaint(FOREGROUND_GRADIENT);
    }
    final double FOREGROUND_CORNER_RADIUS = BACKGROUND.getArcWidth() - 1;
    final RoundRectangle2D FOREGROUND = new RoundRectangle2D.Double(1, 1, IMAGE_WIDTH - 2, IMAGE_HEIGHT - 2, FOREGROUND_CORNER_RADIUS, FOREGROUND_CORNER_RADIUS);
    G2.fill(FOREGROUND);

    G2.dispose();

    return IMAGE;
}
 
Example 4
Source File: AWT2Geometry.java    From gef with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * <p>
 * Converts an AWT {@link RoundRectangle2D} into a GEF
 * {@link RoundedRectangle}. Note that the new {@link RoundedRectangle} is
 * simply constructed by using the values of the passed-in
 * {@link RoundRectangle2D}, not compensating the fact that the width and
 * height of a rectangle are interpreted differently in Java2D and GEF.
 * </p>
 * <p>
 * In Java2D, the width and height of a {@link RoundRectangle2D} are
 * oversized by exactly 1, i.e. the right and bottom edges of a
 * {@link RoundRectangle2D} are not regarded to belong to the visual object.
 * </p>
 * <p>
 * If you wish to retain this interpretation, you have to modify the
 * resulting GEF {@link RoundedRectangle} object as follows:<br>
 * <code>roundedRectangle.shrink(0, 0, 1, 1);</code><br>
 * (see also {@link RoundedRectangle#shrink(double, double, double, double)}
 * , {@link RoundedRectangle#getShrinked(double, double, double, double)})
 * </p>
 *
 * @param r
 *            the {@link RoundRectangle2D} to convert
 * @return a new {@link RoundedRectangle}, which is constructed using the x,
 *         y, width, height, arcWidth, and arcHeight values of the passed in
 *         {@link RoundRectangle2D}
 */
public static RoundedRectangle toRoundedRectangle(RoundRectangle2D r) {
	return new RoundedRectangle(r.getX(), r.getY(), r.getWidth(),
			r.getHeight(), r.getArcWidth() * 2, r.getArcHeight() * 2);
}