use of java.awt.geom.RoundRectangle2D in project scriptographer by scriptographer.
the class AbstractGraphics2D method drawRoundRect.
/**
* Draws an outlined round-cornered rectangle using this graphics
* context's current color. The left and right edges of the rectangle
* are at <code>x</code> and <code>x + width</code>,
* respectively. The top and bottom edges of the rectangle are at
* <code>y</code> and <code>y + height</code>.
* @param x the <i>x</i> coordinate of the rectangle to be drawn.
* @param y the <i>y</i> coordinate of the rectangle to be drawn.
* @param width the width of the rectangle to be drawn.
* @param height the height of the rectangle to be drawn.
* @param arcWidth the horizontal diameter of the arc
* at the four corners.
* @param arcHeight the vertical diameter of the arc
* at the four corners.
* @see java.awt.Graphics#fillRoundRect
*/
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
RoundRectangle2D rect = new RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight);
draw(rect);
}
use of java.awt.geom.RoundRectangle2D in project SIMVA-SoS by SESoS.
the class FXGraphics2D method fill.
/**
* Fills the specified shape with the current {@code paint}. There is
* direct handling for {@code RoundRectangle2D},
* {@code Rectangle2D}, {@code Ellipse2D} and {@code Arc2D}.
* All other shapes are mapped to a path outline and then filled.
*
* @param s the shape ({@code null} not permitted).
*
* @see #draw(java.awt.Shape)
*/
@Override
public void fill(Shape s) {
if (s instanceof RoundRectangle2D) {
RoundRectangle2D rr = (RoundRectangle2D) s;
this.gc.fillRoundRect(rr.getX(), rr.getY(), rr.getWidth(), rr.getHeight(), rr.getArcWidth(), rr.getArcHeight());
} else if (s instanceof Rectangle2D) {
Rectangle2D r = (Rectangle2D) s;
this.gc.fillRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
} else if (s instanceof Ellipse2D) {
Ellipse2D e = (Ellipse2D) s;
this.gc.fillOval(e.getX(), e.getY(), e.getWidth(), e.getHeight());
} else if (s instanceof Arc2D) {
Arc2D a = (Arc2D) s;
this.gc.fillArc(a.getX(), a.getY(), a.getWidth(), a.getHeight(), a.getAngleStart(), a.getAngleExtent(), intToArcType(a.getArcType()));
} else {
shapeToPath(s);
this.gc.fill();
}
}
use of java.awt.geom.RoundRectangle2D in project SIMVA-SoS by SESoS.
the class ThermometerPlot method draw.
/**
* Draws the plot on a Java 2D graphics device (such as the screen or a
* printer).
*
* @param g2 the graphics device.
* @param area the area within which the plot should be drawn.
* @param anchor the anchor point (<code>null</code> permitted).
* @param parentState the state from the parent plot, if there is one.
* @param info collects info about the drawing.
*/
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
RoundRectangle2D outerStem = new RoundRectangle2D.Double();
RoundRectangle2D innerStem = new RoundRectangle2D.Double();
RoundRectangle2D mercuryStem = new RoundRectangle2D.Double();
Ellipse2D outerBulb = new Ellipse2D.Double();
Ellipse2D innerBulb = new Ellipse2D.Double();
String temp;
FontMetrics metrics;
if (info != null) {
info.setPlotArea(area);
}
// adjust for insets...
RectangleInsets insets = getInsets();
insets.trim(area);
drawBackground(g2, area);
// adjust for padding...
Rectangle2D interior = (Rectangle2D) area.clone();
this.padding.trim(interior);
int midX = (int) (interior.getX() + (interior.getWidth() / 2));
int midY = (int) (interior.getY() + (interior.getHeight() / 2));
int stemTop = (int) (interior.getMinY() + getBulbRadius());
int stemBottom = (int) (interior.getMaxY() - getBulbDiameter());
Rectangle2D dataArea = new Rectangle2D.Double(midX - getColumnRadius(), stemTop, getColumnRadius(), stemBottom - stemTop);
outerBulb.setFrame(midX - getBulbRadius(), stemBottom, getBulbDiameter(), getBulbDiameter());
outerStem.setRoundRect(midX - getColumnRadius(), interior.getMinY(), getColumnDiameter(), stemBottom + getBulbDiameter() - stemTop, getColumnDiameter(), getColumnDiameter());
Area outerThermometer = new Area(outerBulb);
Area tempArea = new Area(outerStem);
outerThermometer.add(tempArea);
innerBulb.setFrame(midX - getBulbRadius() + getGap(), stemBottom + getGap(), getBulbDiameter() - getGap() * 2, getBulbDiameter() - getGap() * 2);
innerStem.setRoundRect(midX - getColumnRadius() + getGap(), interior.getMinY() + getGap(), getColumnDiameter() - getGap() * 2, stemBottom + getBulbDiameter() - getGap() * 2 - stemTop, getColumnDiameter() - getGap() * 2, getColumnDiameter() - getGap() * 2);
Area innerThermometer = new Area(innerBulb);
tempArea = new Area(innerStem);
innerThermometer.add(tempArea);
if ((this.dataset != null) && (this.dataset.getValue() != null)) {
double current = this.dataset.getValue().doubleValue();
double ds = this.rangeAxis.valueToJava2D(current, dataArea, RectangleEdge.LEFT);
// already calculated
int i = getColumnDiameter() - getGap() * 2;
// already calculated
int j = getColumnRadius() - getGap();
int l = (i / 2);
int k = (int) Math.round(ds);
if (k < (getGap() + interior.getMinY())) {
k = (int) (getGap() + interior.getMinY());
l = getBulbRadius();
}
Area mercury = new Area(innerBulb);
if (k < (stemBottom + getBulbRadius())) {
mercuryStem.setRoundRect(midX - j, k, i, (stemBottom + getBulbRadius()) - k, l, l);
tempArea = new Area(mercuryStem);
mercury.add(tempArea);
}
g2.setPaint(getCurrentPaint());
g2.fill(mercury);
// draw range indicators...
if (this.subrangeIndicatorsVisible) {
g2.setStroke(this.subrangeIndicatorStroke);
Range range = this.rangeAxis.getRange();
// draw start of normal range
double value = this.subrangeInfo[NORMAL][RANGE_LOW];
if (range.contains(value)) {
double x = midX + getColumnRadius() + 2;
double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT);
Line2D line = new Line2D.Double(x, y, x + 10, y);
g2.setPaint(this.subrangePaint[NORMAL]);
g2.draw(line);
}
// draw start of warning range
value = this.subrangeInfo[WARNING][RANGE_LOW];
if (range.contains(value)) {
double x = midX + getColumnRadius() + 2;
double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT);
Line2D line = new Line2D.Double(x, y, x + 10, y);
g2.setPaint(this.subrangePaint[WARNING]);
g2.draw(line);
}
// draw start of critical range
value = this.subrangeInfo[CRITICAL][RANGE_LOW];
if (range.contains(value)) {
double x = midX + getColumnRadius() + 2;
double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT);
Line2D line = new Line2D.Double(x, y, x + 10, y);
g2.setPaint(this.subrangePaint[CRITICAL]);
g2.draw(line);
}
}
// draw the axis...
if ((this.rangeAxis != null) && (this.axisLocation != NONE)) {
int drawWidth = AXIS_GAP;
if (this.showValueLines) {
drawWidth += getColumnDiameter();
}
Rectangle2D drawArea;
double cursor;
switch(this.axisLocation) {
case RIGHT:
cursor = midX + getColumnRadius();
drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1));
this.rangeAxis.draw(g2, cursor, area, drawArea, RectangleEdge.RIGHT, null);
break;
case LEFT:
default:
// cursor = midX - COLUMN_RADIUS - AXIS_GAP;
cursor = midX - getColumnRadius();
drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1));
this.rangeAxis.draw(g2, cursor, area, drawArea, RectangleEdge.LEFT, null);
break;
}
}
// draw text value on screen
g2.setFont(this.valueFont);
g2.setPaint(this.valuePaint);
metrics = g2.getFontMetrics();
switch(this.valueLocation) {
case RIGHT:
g2.drawString(this.valueFormat.format(current), midX + getColumnRadius() + getGap(), midY);
break;
case LEFT:
String valueString = this.valueFormat.format(current);
int stringWidth = metrics.stringWidth(valueString);
g2.drawString(valueString, midX - getColumnRadius() - getGap() - stringWidth, midY);
break;
case BULB:
temp = this.valueFormat.format(current);
i = metrics.stringWidth(temp) / 2;
g2.drawString(temp, midX - i, stemBottom + getBulbRadius() + getGap());
break;
default:
}
/**
*/
}
g2.setPaint(this.thermometerPaint);
g2.setFont(this.valueFont);
// draw units indicator
metrics = g2.getFontMetrics();
int tickX1 = midX - getColumnRadius() - getGap() * 2 - metrics.stringWidth(UNITS[this.units]);
if (tickX1 > area.getMinX()) {
g2.drawString(UNITS[this.units], tickX1, (int) (area.getMinY() + 20));
}
// draw thermometer outline
g2.setStroke(this.thermometerStroke);
g2.draw(outerThermometer);
g2.draw(innerThermometer);
drawOutline(g2, area);
}
use of java.awt.geom.RoundRectangle2D in project omegat by omegat-org.
the class RoundedCornerBorder method paintBorder.
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setStroke(strokeObj);
int r = radius == -1 ? height - stroke : radius;
RoundRectangle2D roundRect = new RoundRectangle2D.Float(x, y, width - (stroke - 0.5f), height - stroke, r, r);
Rectangle2D sharpRect = new Rectangle2D.Float(x, y, width, height);
Area corners = new Area(sharpRect);
corners.subtract(new Area(roundRect));
Color background = c.getParent() == null ? null : c.getParent().getBackground();
if (side == SIDE_ALL) {
drawCorners(g2, background, corners, roundRect);
g2.dispose();
return;
}
Shape initialClip = g2.getClip();
Rectangle2D roundedHalfClip;
Shape line1;
Shape line2;
if (side == SIDE_TOP) {
roundedHalfClip = new Rectangle2D.Float(x, y, width, height / 2);
line1 = new Line2D.Float(x, y, x, y + height);
line2 = new Line2D.Float(x + width - 0.5f, y, x + width - 0.5f, y + height);
} else if (side == SIDE_LEFT) {
roundedHalfClip = new Rectangle2D.Float(x, y, width / 2 + stroke, height);
line1 = new Line2D.Float(x, y, x + width, y);
line2 = new Line2D.Float(x, y + height - stroke, x + width, y + height - stroke);
} else if (side == SIDE_BOTTOM) {
roundedHalfClip = new Rectangle2D.Float(x, y + height / 2, width, height / 2 + stroke);
line1 = new Line2D.Float(x, y, x, y + height);
line2 = new Line2D.Float(x + width - (stroke - 0.5f), y, x + width - (stroke - 0.5f), y + height);
} else if (side == SIDE_RIGHT) {
roundedHalfClip = new Rectangle2D.Float(x + width / 2, y, width / 2 + stroke, height);
line1 = new Line2D.Float(x, y, x + width, y);
line2 = new Line2D.Float(x, y + height - stroke, x + width, y + height - stroke);
} else {
throw new IllegalArgumentException();
}
g2.clip(roundedHalfClip);
drawCorners(g2, background, corners, roundRect);
Area inverseClip = new Area(sharpRect);
inverseClip.subtract(new Area(roundedHalfClip));
g2.setClip(initialClip);
g2.clip(inverseClip);
g2.draw(line1);
g2.draw(line2);
g2.dispose();
}
use of java.awt.geom.RoundRectangle2D in project archi by archimatetool.
the class GraphicsToGraphics2DAdaptor method drawRoundRectangle.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.draw2d.Graphics#drawRoundRectangle(org.eclipse.draw2d.geometry
* .Rectangle, int, int)
*/
@Override
public void drawRoundRectangle(Rectangle rect, int arcWidth, int arcHeight) {
RoundRectangle2D roundRect = new RoundRectangle2D.Float(rect.x + transX, rect.y + transY, rect.width, rect.height, arcWidth, arcHeight);
checkState();
getGraphics2D().setPaint(getColor(swtGraphics.getForegroundColor()));
getGraphics2D().setStroke(createStroke());
getGraphics2D().draw(roundRect);
}
Aggregations