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

The following examples show how to use java.awt.geom.RoundRectangle2D#getHeight() . 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: TrafficLight.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public BufferedImage createHousingImage(final int WIDTH, final int HEIGHT) {
    final GraphicsConfiguration GFX_CONF = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    if (WIDTH <= 0 || HEIGHT <= 0) {
        return GFX_CONF.createCompatibleImage(1, 1, java.awt.Transparency.TRANSLUCENT);
    }
    final BufferedImage IMAGE = GFX_CONF.createCompatibleImage(WIDTH, HEIGHT, Transparency.TRANSLUCENT);
    final Graphics2D G2 = IMAGE.createGraphics();
    G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    G2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

    final int IMAGE_WIDTH = IMAGE.getWidth();
    final int IMAGE_HEIGHT = IMAGE.getHeight();
    final RoundRectangle2D HOUSING_BACK = new RoundRectangle2D.Double(0.0 * IMAGE_WIDTH, 0.0 * IMAGE_HEIGHT, 1.0 * IMAGE_WIDTH, 1.0 * IMAGE_HEIGHT, 0.21428571428571427 * IMAGE_WIDTH, 0.07553956834532374 * IMAGE_HEIGHT);
    G2.setPaint(new LinearGradientPaint(new Point2D.Double(0.04081632653061224 * IMAGE_WIDTH, 0.007194244604316547 * IMAGE_HEIGHT), new Point2D.Double(0.9521011364730593 * IMAGE_WIDTH, 0.9958824935586308 * IMAGE_HEIGHT), new float[]{0.0f, 0.01f, 0.09f, 0.24f, 0.55f, 0.78f, 0.98f, 1.0f}, new Color[]{new Color(0.5960784314f, 0.5960784314f, 0.6039215686f, 1f), new Color(0.5960784314f, 0.5960784314f, 0.6039215686f, 1f), new Color(0.2f, 0.2f, 0.2f, 1f), new Color(0.5960784314f, 0.5960784314f, 0.6039215686f, 1f), new Color(0.1215686275f, 0.1215686275f, 0.1215686275f, 1f), new Color(0.2117647059f, 0.2117647059f, 0.2117647059f, 1f), new Color(0f, 0f, 0f, 1f), new Color(0f, 0f, 0f, 1f)}));
    G2.fill(HOUSING_BACK);

    final RoundRectangle2D HOUSING_FRONT = new RoundRectangle2D.Double(0.030612244897959183 * IMAGE_WIDTH, 0.01079136690647482 * IMAGE_HEIGHT, 0.9387755102040817 * IMAGE_WIDTH, 0.9784172661870504 * IMAGE_HEIGHT, 0.1683673469387755 * IMAGE_WIDTH, 0.05935251798561151 * IMAGE_HEIGHT);
    G2.setPaint(new LinearGradientPaint(new Point2D.Double(-0.1326530612244898 * IMAGE_WIDTH, -0.0539568345323741 * IMAGE_HEIGHT), new Point2D.Double(2.0614080436330213 * IMAGE_WIDTH, 0.6672932297063833 * IMAGE_HEIGHT), new float[]{0.0f, 0.01f, 0.16f, 0.31f, 0.44f, 0.65f, 0.87f, 0.98f, 1.0f}, new Color[]{new Color(0f, 0f, 0f, 1f), new Color(0f, 0f, 0f, 1f), new Color(0.2156862745f, 0.2156862745f, 0.2078431373f, 1f), new Color(0f, 0f, 0f, 1f), new Color(0.1882352941f, 0.1882352941f, 0.1882352941f, 1f), new Color(0f, 0f, 0f, 1f), new Color(0.2117647059f, 0.2117647059f, 0.2117647059f, 1f), new Color(0f, 0f, 0f, 1f), new Color(0f, 0f, 0f, 1f)}));
    G2.fill(HOUSING_FRONT);

    final Random BW_RND = new Random();
    final Random ALPHA_RND = new Random();
    G2.setClip(HOUSING_FRONT);
    final Color DARK_NOISE = new Color(0.2f, 0.2f, 0.2f);
    final Color BRIGHT_NOISE = new Color(0.8f, 0.8f, 0.8f);
    Color noiseColor;
    int noiseAlpha;
    for (int y = 0 ; y < HOUSING_FRONT.getHeight() ; y ++) {
        for (int x = 0 ; x < HOUSING_FRONT.getWidth() ; x ++) {
            if (BW_RND.nextBoolean()) {
                noiseColor = BRIGHT_NOISE;
            } else {
                noiseColor = DARK_NOISE;
            }
            noiseAlpha = 10 + ALPHA_RND.nextInt(10) - 5;
            G2.setColor(new Color(noiseColor.getRed(), noiseColor.getGreen(), noiseColor.getBlue(), noiseAlpha));
            G2.drawLine((int) (x + HOUSING_FRONT.getMinX()), (int) (y + HOUSING_FRONT.getMinY()), (int) (x + HOUSING_FRONT.getMinX()), (int) (y + HOUSING_FRONT.getMinY()));
        }
    }


    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);
}