use of java.awt.geom.Rectangle2D in project android by JetBrains.
the class DrawConnectionUtils method drawVerticalMarginIndicator.
/**
* Utility function to draw a vertical margin indicator
*
* @param g graphics context
* @param text the text to display
* @param x x coordinate
* @param y1 y1 coordinate
* @param y2 y2 coordinate
*/
public static void drawVerticalMarginIndicator(Graphics2D g, String text, boolean isMarginReference, int x, int y1, int y2) {
if (y1 > y2) {
int temp = y1;
y1 = y2;
y2 = temp;
}
if (text == null) {
g.drawLine(x, y1, x, y2);
g.drawLine(x, y1, x - CONNECTION_ARROW_SIZE, y1 + CONNECTION_ARROW_SIZE);
g.drawLine(x, y1, x + CONNECTION_ARROW_SIZE, y1 + CONNECTION_ARROW_SIZE);
g.drawLine(x, y2, x - CONNECTION_ARROW_SIZE, y2 - CONNECTION_ARROW_SIZE);
g.drawLine(x, y2, x + CONNECTION_ARROW_SIZE, y2 - CONNECTION_ARROW_SIZE);
return;
}
Canvas c = new Canvas();
Font previousFont = g.getFont();
Font font = isMarginReference ? sFontReference : sFont;
FontMetrics fm = c.getFontMetrics(font);
g.setFont(font);
int padding = 4;
Rectangle2D bounds = fm.getStringBounds(text, g);
int th = (int) bounds.getHeight();
int offset = 3 * CONNECTION_ARROW_SIZE;
int h = ((y2 - y1) - (th + 2 * padding)) / 2;
if (h <= padding) {
g.drawLine(x, y1, x, y2);
g.drawString(text, (int) (x - bounds.getWidth() / 2) + offset, y2 - h - padding);
g.drawLine(x - CONNECTION_ARROW_SIZE, y1, x + CONNECTION_ARROW_SIZE, y1);
g.drawLine(x - CONNECTION_ARROW_SIZE, y2, x + CONNECTION_ARROW_SIZE, y2);
} else {
g.drawLine(x, y1, x, y1 + h);
g.drawLine(x, y2 - h, x, y2);
g.drawString(text, (int) (x - bounds.getWidth() / 2), y2 - h - padding);
g.drawLine(x, y1, x - CONNECTION_ARROW_SIZE, y1 + CONNECTION_ARROW_SIZE);
g.drawLine(x, y1, x + CONNECTION_ARROW_SIZE, y1 + CONNECTION_ARROW_SIZE);
g.drawLine(x, y2, x - CONNECTION_ARROW_SIZE, y2 - CONNECTION_ARROW_SIZE);
g.drawLine(x, y2, x + CONNECTION_ARROW_SIZE, y2 - CONNECTION_ARROW_SIZE);
}
g.setFont(previousFont);
}
use of java.awt.geom.Rectangle2D in project android by JetBrains.
the class WebViewWidget method fakeUIPaint.
protected void fakeUIPaint(ViewTransform transform, Graphics2D g, int x, int y) {
int tx = transform.getSwingX(x);
int ty = transform.getSwingY(y);
int w = transform.getSwingDimension(mWidget.getDrawWidth());
int h = transform.getSwingDimension(mWidget.getDrawHeight());
int padding = transform.getSwingDimension(mPadding);
int originalSize = mFont.getSize();
int scaleSize = transform.getSwingDimension(originalSize);
g.setFont(mFont.deriveFont((float) scaleSize));
FontMetrics fontMetrics = g.getFontMetrics();
g.setColor(Color.WHITE);
g.drawString("WWW", tx + padding, ty + fontMetrics.getAscent() + padding);
String text = "WebView";
Rectangle2D bounds = fontMetrics.getStringBounds(text, g);
g.drawString(text, tx + (int) ((w - bounds.getWidth()) / 2f), ty + (int) ((h - bounds.getHeight()) / 2f));
}
use of java.awt.geom.Rectangle2D in project android by JetBrains.
the class ConnectionDraw method drawVerticalMarginIndicator.
/**
* Utility function to draw a vertical margin indicator
*
* @param g graphics context
* @param text the text to display
* @param x x coordinate
* @param y1 y1 coordinate
* @param y2 y2 coordinate
*/
public static void drawVerticalMarginIndicator(Graphics2D g, String text, int x, int y1, int y2) {
if (y1 > y2) {
int temp = y1;
y1 = y2;
y2 = temp;
}
if (text == null) {
g.drawLine(x, y1, x, y2);
g.drawLine(x, y1, x - CONNECTION_ARROW_SIZE, y1 + CONNECTION_ARROW_SIZE);
g.drawLine(x, y1, x + CONNECTION_ARROW_SIZE, y1 + CONNECTION_ARROW_SIZE);
g.drawLine(x, y2, x - CONNECTION_ARROW_SIZE, y2 - CONNECTION_ARROW_SIZE);
g.drawLine(x, y2, x + CONNECTION_ARROW_SIZE, y2 - CONNECTION_ARROW_SIZE);
return;
}
Canvas c = new Canvas();
FontMetrics fm = c.getFontMetrics(sFont);
g.setFont(sFont);
int padding = 4;
Rectangle2D bounds = fm.getStringBounds(text, g);
int th = (int) bounds.getHeight();
int offset = 3 * CONNECTION_ARROW_SIZE;
int h = ((y2 - y1) - (th + 2 * padding)) / 2;
if (h <= padding) {
g.drawLine(x, y1, x, y2);
g.drawString(text, (int) (x - bounds.getWidth() / 2) + offset, y2 - h - padding);
g.drawLine(x - CONNECTION_ARROW_SIZE, y1, x + CONNECTION_ARROW_SIZE, y1);
g.drawLine(x - CONNECTION_ARROW_SIZE, y2, x + CONNECTION_ARROW_SIZE, y2);
} else {
g.drawLine(x, y1, x, y1 + h);
g.drawLine(x, y2 - h, x, y2);
g.drawString(text, (int) (x - bounds.getWidth() / 2), y2 - h - padding);
g.drawLine(x, y1, x - CONNECTION_ARROW_SIZE, y1 + CONNECTION_ARROW_SIZE);
g.drawLine(x, y1, x + CONNECTION_ARROW_SIZE, y1 + CONNECTION_ARROW_SIZE);
g.drawLine(x, y2, x - CONNECTION_ARROW_SIZE, y2 - CONNECTION_ARROW_SIZE);
g.drawLine(x, y2, x + CONNECTION_ARROW_SIZE, y2 - CONNECTION_ARROW_SIZE);
}
}
use of java.awt.geom.Rectangle2D in project android by JetBrains.
the class ConnectionDraw method drawRoundRectText.
/**
* Utility function to draw a circle text centered at coordinates (x, y)
* @param g graphics context
* @param font the font we use to draw the text
* @param textColor
* @param text the text to display
* @param x x coordinate
* @param y y coordinate
*/
public static void drawRoundRectText(Graphics2D g, Font font, Color textColor, String text, int x, int y) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setFont(font);
FontMetrics fm = g2.getFontMetrics();
int padding = 2;
Rectangle2D bounds = fm.getStringBounds(text, g2);
double th = bounds.getHeight() + padding * 2;
double tw = bounds.getWidth() + padding * 2;
int radius = (int) (Math.min(th, tw) / 3);
g2.fillRoundRect((int) (x - tw / 2), (int) (y - th / 2), (int) tw, (int) th, radius, radius);
g2.setColor(textColor);
g2.drawString(text, (int) (x - tw / 2 + padding), (int) (y - th / 2 + fm.getAscent()));
if (DEBUG) {
g2.setColor(Color.RED);
g2.drawLine(x - 50, y, x + 50, y);
g2.drawLine(x, y - 50, x, y + 50);
}
g2.dispose();
}
use of java.awt.geom.Rectangle2D in project android by JetBrains.
the class ConnectionDraw method drawHorizontalMarginIndicator.
/**
* Utility function to draw an horizontal margin indicator
*
* @param g graphics context
* @param text the text to display
* @param x1 x1 coordinate
* @param x2 x2 coordinate
* @param y y coordinate
*/
public static void drawHorizontalMarginIndicator(Graphics2D g, String text, int x1, int x2, int y) {
if (x1 > x2) {
int temp = x1;
x1 = x2;
x2 = temp;
}
if (text == null) {
g.drawLine(x1, y, x2, y);
g.drawLine(x1, y, x1 + CONNECTION_ARROW_SIZE, y - CONNECTION_ARROW_SIZE);
g.drawLine(x1, y, x1 + CONNECTION_ARROW_SIZE, y + CONNECTION_ARROW_SIZE);
g.drawLine(x2, y, x2 - CONNECTION_ARROW_SIZE, y - CONNECTION_ARROW_SIZE);
g.drawLine(x2, y, x2 - CONNECTION_ARROW_SIZE, y + CONNECTION_ARROW_SIZE);
return;
}
Canvas c = new Canvas();
FontMetrics fm = c.getFontMetrics(sFont);
g.setFont(sFont);
int padding = 4;
Rectangle2D bounds = fm.getStringBounds(text, g);
int th = (int) bounds.getHeight();
int tw = (int) bounds.getWidth();
int offset = 3 * CONNECTION_ARROW_SIZE;
int w = ((x2 - x1) - (tw + 2 * padding)) / 2;
if (w <= padding) {
g.drawLine(x1, y, x2, y);
g.drawString(text, x1 + w + padding, y + offset);
g.drawLine(x1, y - CONNECTION_ARROW_SIZE, x1, y + CONNECTION_ARROW_SIZE);
g.drawLine(x2, y - CONNECTION_ARROW_SIZE, x2, y + CONNECTION_ARROW_SIZE);
} else {
g.drawLine(x1, y, x1 + w, y);
g.drawLine(x2 - w, y, x2, y);
g.drawString(text, x1 + w + padding, (int) (y + (bounds.getHeight() / 2)));
g.drawLine(x1, y, x1 + CONNECTION_ARROW_SIZE, y - CONNECTION_ARROW_SIZE);
g.drawLine(x1, y, x1 + CONNECTION_ARROW_SIZE, y + CONNECTION_ARROW_SIZE);
g.drawLine(x2, y, x2 - CONNECTION_ARROW_SIZE, y - CONNECTION_ARROW_SIZE);
g.drawLine(x2, y, x2 - CONNECTION_ARROW_SIZE, y + CONNECTION_ARROW_SIZE);
}
}
Aggregations