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 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-selector-intellij-plugin by importre.
the class ColorIcon method paintIcon.
public void paintIcon(Component c, Graphics g, int x, int y) {
JBColor color = getColor();
if (color == null) {
g.setColor(JBColor.WHITE);
g.fillRect(1, 1, getIconWidth(), getIconHeight());
g.setColor(JBColor.DARK_GRAY);
if (g instanceof Graphics2D) {
RenderingHints.Key key = RenderingHints.KEY_TEXT_ANTIALIASING;
Object value = RenderingHints.VALUE_TEXT_ANTIALIAS_ON;
((Graphics2D) g).setRenderingHint(key, value);
}
String q = "?";
FontMetrics fm = g.getFontMetrics();
Rectangle2D r = fm.getStringBounds(q, g);
x = (int) ((getIconWidth() - (int) r.getWidth()) * 0.7f);
y = (getIconHeight() - (int) r.getHeight()) / 2 + fm.getAscent();
g.drawString(q, x, y);
} else {
g.setColor(color);
g.fillRect(1, 1, getIconWidth(), getIconHeight());
}
g.setColor(JBColor.DARK_GRAY);
g.drawRect(1, 1, getIconWidth(), getIconHeight());
}
use of java.awt.geom.Rectangle2D in project openblocks by mikaelhg.
the class CBorderlessButton method paint.
/**
* re paints this
*/
@Override
public void paint(Graphics g) {
// Set up graphics and buffer
//super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// Set up first layer
int buttonHeight = this.getHeight() - (INSET * 2);
int buttonWidth = this.getWidth() - (INSET * 2);
if (this.focus) {
int arc = buttonHeight / 3;
Color topColoring;
Color bottomColoring;
if (this.pressed || this.selected) {
topColoring = this.selectedColor.darker();
bottomColoring = CGraphite.blue;
} else {
topColoring = this.buttonColor;
bottomColoring = this.buttonColor;
}
// Paint the first layer
g2.setPaint(new GradientPaint(0, 0, topColoring, 0, buttonHeight, bottomColoring, false));
g2.fillRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
g2.setColor(Color.darkGray);
g2.drawRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
// set up paint data fields for second layer
int highlightHeight = buttonHeight / 2 - HIGHLIGHT_INSET;
int highlightWidth = buttonWidth - (HIGHLIGHT_INSET * 2) + 1;
if (this.pressed || this.selected) {
topColoring = Color.white;
bottomColoring = this.selectedColor;
} else {
topColoring = Color.white;
bottomColoring = Color.darkGray;
}
// Paint the second layer
g2.setPaint(new GradientPaint(0, 0, topColoring, 0, buttonHeight, bottomColoring, false));
g2.fillRoundRect(INSET + HIGHLIGHT_INSET, INSET + HIGHLIGHT_INSET + 1, highlightWidth, highlightHeight, arc, arc);
}
// Draw the text (if any)
if (this.getText() != null) {
g2.setColor(Color.white);
Font font = g2.getFont().deriveFont((float) (((float) buttonHeight) * .5));
g2.setFont(font);
FontMetrics metrics = g2.getFontMetrics();
Rectangle2D textBounds = metrics.getStringBounds(this.getText(), g2);
float x = (float) ((this.getWidth() / 2) - (textBounds.getWidth() / 2));
float y = (float) ((this.getHeight() / 2) + (textBounds.getHeight() / 2)) - metrics.getDescent();
g2.drawString(this.getText(), x, y);
}
}
Aggregations