use of java.awt.geom.Rectangle2D in project antlrworks by antlr.
the class XJRotableToggleButton method paint.
@Override
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
AffineTransform tr = g2d.getTransform();
switch(rotation) {
case ROTATE_90:
tr.rotate(Math.PI / 2);
tr.translate(0, -computedHeight);
g2d.setTransform(tr);
break;
case ROTATE_270:
tr.rotate(-Math.PI / 2);
tr.translate(-computedWidth, 0);
g2d.setTransform(tr);
break;
}
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
drawAquaBackground(g2d);
TextLayout layout = new TextLayout(title, g2d.getFont(), g2d.getFontRenderContext());
Rectangle2D r = layout.getBounds();
int offset = MARGIN_WIDTH;
if (icon != null) {
int voffset = (computedHeight - icon.getIconHeight()) / 2;
g2d.drawImage(icon.getImage(), offset, voffset, null);
offset += icon.getIconWidth();
offset += SEPARATOR;
} else {
offset = (int) ((computedWidth - r.getWidth()) / 2);
}
int voffset = (int) ((computedHeight - r.getHeight()) / 2);
g2d.setColor(Color.black);
layout.draw(g2d, offset, computedHeight - voffset - layout.getDescent() / 2);
}
use of java.awt.geom.Rectangle2D in project tomcat by apache.
the class DrawMessage method draw.
/**
* Draws this DrawMessage onto the given Graphics2D.
*
* @param g The target for the DrawMessage
*/
public void draw(Graphics2D g) {
g.setStroke(new BasicStroke((float) thickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
g.setColor(new Color(colorR & 0xFF, colorG & 0xFF, colorB & 0xFF, colorA & 0xFF));
if (x1 == x2 && y1 == y2) {
// Always draw as arc to meet the behavior in the HTML5 Canvas.
Arc2D arc = new Arc2D.Double(x1, y1, 0, 0, 0d, 360d, Arc2D.OPEN);
g.draw(arc);
} else if (type == 1 || type == 2) {
// Draw a line.
Line2D line = new Line2D.Double(x1, y1, x2, y2);
g.draw(line);
} else if (type == 3 || type == 4) {
double x1 = this.x1, x2 = this.x2, y1 = this.y1, y2 = this.y2;
if (x1 > x2) {
x1 = this.x2;
x2 = this.x1;
}
if (y1 > y2) {
y1 = this.y2;
y2 = this.y1;
}
if (type == 3) {
// Draw a rectangle.
Rectangle2D rect = new Rectangle2D.Double(x1, y1, x2 - x1, y2 - y1);
g.draw(rect);
} else if (type == 4) {
// Draw an ellipse.
Arc2D arc = new Arc2D.Double(x1, y1, x2 - x1, y2 - y1, 0d, 360d, Arc2D.OPEN);
g.draw(arc);
}
}
}
use of java.awt.geom.Rectangle2D in project WordCram by danbernier.
the class PlacerHeatMap method draw.
public void draw(PApplet sketch) {
RectStack rectStack = new RectStack();
for (int i = 0; i < words.length; i++) {
Word word = words[i];
PFont wordFont = word.getFont(fonter);
float wordSize = word.getSize(sizer, i, words.length);
float wordAngle = word.getAngle(angler);
Shape shape = shaper.getShapeFor(word.word, wordFont, wordSize, wordAngle);
Rectangle2D rect = shape.getBounds2D();
//return r.getHeight() < minShapeSize || r.getWidth() < minShapeSize;
int wordImageWidth = (int) rect.getWidth();
int wordImageHeight = (int) rect.getHeight();
PVector desiredLocation = word.getTargetPlace(placer, i, words.length, wordImageWidth, wordImageHeight, sketch.width, sketch.height);
//sketch.rect(desiredLocation.x, desiredLocation.y, wordImageWidth, wordImageHeight);
rectStack.add((int) desiredLocation.x, (int) desiredLocation.y, wordImageWidth, wordImageHeight);
}
RectGrid grid = new RectGrid(rectStack);
grid.draw(sketch);
}
use of java.awt.geom.Rectangle2D in project Fling by entertailion.
the class DragHereIcon method paintIcon.
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.translate(x, y);
g2.setStroke(new BasicStroke(a));
g2.setPaint(linec);
g2.draw(new RoundRectangle2D.Float(a, a, size - 2 * a - 1, size - 2 * a - 1, r, r));
// draw bounding box
g2.setStroke(new BasicStroke(b));
g2.setColor(UIManager.getColor("Panel.background"));
g2.drawLine(1 * f, 0 * f, 1 * f, 4 * f);
g2.drawLine(2 * f, 0 * f, 2 * f, 4 * f);
g2.drawLine(3 * f, 0 * f, 3 * f, 4 * f);
g2.drawLine(0 * f, 1 * f, 4 * f, 1 * f);
g2.drawLine(0 * f, 2 * f, 4 * f, 2 * f);
g2.drawLine(0 * f, 3 * f, 4 * f, 3 * f);
// draw arrow
g2.setPaint(linec);
Rectangle2D b = s.getBounds();
Point2D.Double p = new Point2D.Double(b.getX() + b.getWidth() / 2d, b.getY() + b.getHeight() / 2d);
AffineTransform toCenterAT = AffineTransform.getTranslateInstance(size / 2d - p.getX(), size / 2d - p.getY());
g2.fill(toCenterAT.createTransformedShape(s));
g2.translate(-x, -y);
g2.dispose();
}
use of java.awt.geom.Rectangle2D in project android_frameworks_base by ParanoidAndroid.
the class Paint_Delegate method nativeGetCharArrayBounds.
@LayoutlibDelegate
static /*package*/
void nativeGetCharArrayBounds(int nativePaint, char[] text, int index, int count, int bidiFlags, Rect bounds) {
// get the delegate from the native int.
Paint_Delegate delegate = sManager.getDelegate(nativePaint);
if (delegate == null) {
return;
}
// See MeasureText
if (delegate.mFonts.size() > 0) {
FontInfo mainInfo = delegate.mFonts.get(0);
Rectangle2D rect = mainInfo.mFont.getStringBounds(text, index, index + count, delegate.mFontContext);
bounds.set(0, 0, (int) rect.getWidth(), (int) rect.getHeight());
}
}
Aggregations