use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.
the class TextBox method draw.
/**
* Draws the text box.
*
* @param g2 the graphics device.
* @param x the x-coordinate.
* @param y the y-coordinate.
* @param anchor the anchor point.
*/
public void draw(Graphics2D g2, float x, float y, RectangleAnchor anchor) {
Size2D d1 = this.textBlock.calculateDimensions(g2);
double w = this.interiorGap.extendWidth(d1.getWidth());
double h = this.interiorGap.extendHeight(d1.getHeight());
Size2D d2 = new Size2D(w, h);
Rectangle2D bounds = RectangleAnchor.createRectangle(d2, x, y, anchor);
double xx = bounds.getX();
double yy = bounds.getY();
if (this.shadowPaint != null) {
Rectangle2D shadow = new Rectangle2D.Double(xx + this.shadowXOffset, yy + this.shadowYOffset, bounds.getWidth(), bounds.getHeight());
g2.setPaint(this.shadowPaint);
g2.fill(shadow);
}
if (this.backgroundPaint != null) {
g2.setPaint(this.backgroundPaint);
g2.fill(bounds);
}
if (this.outlinePaint != null && this.outlineStroke != null) {
g2.setPaint(this.outlinePaint);
g2.setStroke(this.outlineStroke);
g2.draw(bounds);
}
this.textBlock.draw(g2, (float) (xx + this.interiorGap.calculateLeftInset(w)), (float) (yy + this.interiorGap.calculateTopInset(h)), TextBlockAnchor.TOP_LEFT);
}
use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.
the class TextFragment method calculateDimensions.
/**
* Calculates the dimensions of the text fragment.
*
* @param g2 the graphics device.
*
* @return The width and height of the text.
*/
public Size2D calculateDimensions(Graphics2D g2) {
FontMetrics fm = g2.getFontMetrics(this.font);
Rectangle2D bounds = TextUtilities.getTextBounds(this.text, g2, fm);
Size2D result = new Size2D(bounds.getWidth(), bounds.getHeight());
return result;
}
use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.
the class TextLine method calculateDimensions.
/**
* Calculates the width and height of the text line.
*
* @param g2 the graphics device.
*
* @return The width and height.
*/
public Size2D calculateDimensions(Graphics2D g2) {
double width = 0.0;
double height = 0.0;
Iterator iterator = this.fragments.iterator();
while (iterator.hasNext()) {
TextFragment fragment = (TextFragment) iterator.next();
Size2D dimension = fragment.calculateDimensions(g2);
width = width + dimension.getWidth();
height = Math.max(height, dimension.getHeight());
}
return new Size2D(width, height);
}
use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.
the class TextLine method draw.
/**
* Draws the text line.
*
* @param g2 the graphics device.
* @param anchorX the x-coordinate for the anchor point.
* @param anchorY the y-coordinate for the anchor point.
* @param anchor the point on the text line that is aligned to the anchor
* point.
* @param rotateX the x-coordinate for the rotation point.
* @param rotateY the y-coordinate for the rotation point.
* @param angle the rotation angle (in radians).
*/
public void draw(Graphics2D g2, float anchorX, float anchorY, TextAnchor anchor, float rotateX, float rotateY, double angle) {
float x = anchorX;
float yOffset = calculateBaselineOffset(g2, anchor);
Iterator iterator = this.fragments.iterator();
while (iterator.hasNext()) {
TextFragment fragment = (TextFragment) iterator.next();
Size2D d = fragment.calculateDimensions(g2);
fragment.draw(g2, x, anchorY + yOffset, TextAnchor.BASELINE_LEFT, rotateX, rotateY, angle);
x = x + (float) d.getWidth();
}
}
Aggregations