use of java.awt.geom.Line2D in project poi by apache.
the class PPGraphics2D method drawLine.
/**
* Draws a line, using the current color, between the points
* <code>(x1, y1)</code> and <code>(x2, y2)</code>
* in this graphics context's coordinate system.
* @param x1 the first point's <i>x</i> coordinate.
* @param y1 the first point's <i>y</i> coordinate.
* @param x2 the second point's <i>x</i> coordinate.
* @param y2 the second point's <i>y</i> coordinate.
*/
public void drawLine(int x1, int y1, int x2, int y2) {
Line2D line = new Line2D.Float(x1, y1, x2, y2);
draw(line);
}
use of java.awt.geom.Line2D in project beast-mcmc by beast-dev.
the class JChart method paintComponent.
public void paintComponent(Graphics g) {
if (!hasContents())
return;
Graphics2D g2 = (Graphics2D) g;
Dimension size = getSize();
// g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
try {
if (!calibrated) {
calibrate(g2, size);
calibrated = true;
}
g2.setFont(labelFont);
double tickLabelHeight = g2.getFontMetrics().getHeight();
xTickLabelOffset = g2.getFontMetrics().getAscent();
yTickLabelOffset = g2.getFontMetrics().getAscent() / 2;
double maxXTickLabelWidth = getMaxTickLabelWidth(g2, xAxis);
double maxYTickLabelWidth = getMaxTickLabelWidth(g2, yAxis);
double w = size.width - (majorTickSize * 1.25) - maxYTickLabelWidth - (maxXTickLabelWidth / 2);
double h = size.height - yTickLabelOffset - (majorTickSize * 1.25) - tickLabelHeight;
plotBounds = new Rectangle2D.Double((majorTickSize * 1.25) + maxYTickLabelWidth, yTickLabelOffset, w, h);
xOffset = plotBounds.getX();
yOffset = plotBounds.getMaxY();
xScale = w / (xAxis.transform(xAxis.getMaxAxis()) - xAxis.transform(xAxis.getMinAxis()));
yScale = -h / (yAxis.transform(yAxis.getMaxAxis()) - yAxis.transform(yAxis.getMinAxis()));
g2.setPaint(plotBackgroundPaint);
g2.fill(plotBounds);
g2.setClip(plotBounds);
Stroke oldStroke = g2.getStroke();
if (originStroke != null && originPaint != null) {
double minX = xAxis.getMinAxis();
double maxX = xAxis.getMaxAxis();
double minY = yAxis.getMinAxis();
double maxY = yAxis.getMaxAxis();
g2.setPaint(originPaint);
g2.setStroke(originStroke);
if (minX < 0.0 && maxX > 0.0) {
Line2D line = new Line2D.Double(transformX(0.0), transformY(minY), transformX(0.0), transformY(maxY));
g2.draw(line);
}
if (minY < 0.0 && maxY > 0.0) {
Line2D line = new Line2D.Double(transformX(minX), transformY(0.0), transformX(maxX), transformY(0.0));
g2.draw(line);
}
}
g2.setStroke(oldStroke);
paintContents(g2);
if (showLegend) {
paintLegend(g2);
}
if (dragRectangle != null) {
g2.setPaint(new Color(128, 128, 128, 128));
g2.fill(dragRectangle);
}
g2.setClip(null);
paintFrame(g2);
paintAxis(g2, xAxis, true);
paintAxis(g2, yAxis, false);
} catch (ChartRuntimeException cre) {
// ignore (just won't paint chart)
}
}
use of java.awt.geom.Line2D in project beast-mcmc by beast-dev.
the class SquareTreePainter method paintNode.
/**
* Paint a node.
* @param x0 the height of the parent node
* @param x1 the height of the node
*/
private double paintNode(Graphics2D g2, Tree tree, NodeRef node, double x0, double x1, boolean hilight) {
double y;
double ix0 = convertX(x0);
double ix1 = convertX(x1);
double iy;
if (tree.getNodeAttribute(node, "selected") != null) {
hilight = true;
}
if (tree.isExternal(node)) {
if (rememberYPositions) {
// remember the y positions of taxa that you have seen before... AD
String taxonId = tree.getNodeTaxon(node).getId();
Double pos = yPositionMap.get(taxonId);
if (pos != null) {
y = pos;
} else {
y = currentY;
currentY += 1.0;
yPositionMap.put(taxonId, y);
}
} else {
y = currentY;
currentY += 1.0;
}
if (hilight) {
g2.setPaint(hilightLabelPaint);
g2.setFont(hilightLabelFont);
} else {
g2.setPaint(labelPaint);
g2.setFont(labelFont);
}
String label = tree.getTaxonId(node.getNumber());
double labelWidth = g2.getFontMetrics().stringWidth(label);
double labelHeight = g2.getFontMetrics().getAscent();
double labelOffset = labelHeight / 2;
iy = convertY(y);
if (label != null && label.length() > 0 && drawLabels) {
g2.drawString(label, (float) (ix1 + 4), (float) (iy + labelOffset));
}
nodeRectVert[node.getNumber()] = new Rectangle.Double(ix1 + 4, iy, labelWidth, labelHeight);
if (hilight) {
g2.setPaint(hilightPaint);
g2.setStroke(hilightStroke);
} else {
// use tree color attribute if set
if (colorAttribute != null) {
Paint c = (Color) tree.getNodeAttribute(node, colorAttribute);
if (c == null)
c = linePaint;
g2.setPaint(c);
} else {
g2.setPaint(linePaint);
}
if (lineAttribute != null) {
Stroke stroke = (Stroke) tree.getNodeAttribute(node, lineAttribute);
if (stroke == null)
stroke = lineStroke;
g2.setStroke(stroke);
} else
g2.setStroke(lineStroke);
}
} else {
double y0, y1;
NodeRef child = tree.getChild(node, 0);
double length = tree.getNodeHeight(node) - tree.getNodeHeight(child);
y0 = paintNode(g2, tree, child, x1, x1 - length, hilight);
y1 = y0;
for (int i = 1; i < tree.getChildCount(node); i++) {
child = tree.getChild(node, i);
length = tree.getNodeHeight(node) - tree.getNodeHeight(child);
y1 = paintNode(g2, tree, child, x1, x1 - length, hilight);
}
double iy0 = convertY(y0);
double iy1 = convertY(y1);
if (hilight) {
g2.setPaint(hilightPaint);
g2.setStroke(hilightStroke);
} else {
// use tree color attribute if set
if (colorAttribute != null) {
Paint c = (Color) tree.getNodeAttribute(node, colorAttribute);
if (c == null)
c = linePaint;
g2.setPaint(c);
} else {
g2.setPaint(linePaint);
}
if (lineAttribute != null) {
Stroke stroke = (Stroke) tree.getNodeAttribute(node, lineAttribute);
if (stroke == null)
stroke = lineStroke;
g2.setStroke(stroke);
} else
g2.setStroke(lineStroke);
}
if (drawHorizontals) {
Line2D line = new Line2D.Double(ix1, iy0, ix1, iy1);
g2.draw(line);
}
nodeRectVert[node.getNumber()] = new Rectangle.Double(ix1 - 2, iy0 - 2, 5, (iy1 - iy0) + 4);
y = (y1 + y0) / 2;
iy = convertY(y);
}
if (drawVerticals) {
Line2D line = new Line2D.Double(ix0, iy, ix1, iy);
g2.draw(line);
}
nodeRectHoriz[node.getNumber()] = new Rectangle.Double(ix0 - 2, iy - 2, (ix1 - ix0) + 4, 5);
if (shapeAttribute != null) {
Shape shape = (Shape) tree.getNodeAttribute(node, shapeAttribute);
if (shape != null) {
Rectangle bounds = shape.getBounds();
double tx = ix1 - bounds.getWidth() / 2.0;
double ty = iy - bounds.getHeight() / 2.0;
g2.translate(tx, ty);
g2.fill(shape);
g2.translate(-tx, -ty);
}
}
if (labelAttribute != null) {
Object label = tree.getNodeAttribute(node, labelAttribute);
if (label != null) {
Color c = g2.getColor();
Font f = g2.getFont();
Font fsmall = f.deriveFont(f.getSize() - 1.0f);
g2.setFont(fsmall);
String labelString = label.toString();
int width = g2.getFontMetrics().stringWidth(labelString);
g2.setColor(textColor);
g2.drawString(labelString, (float) (ix1 - width - 1.0), (float) (iy - 2.0));
// recover color and font
g2.setColor(c);
g2.setFont(f);
}
}
return y;
}
use of java.awt.geom.Line2D in project beast-mcmc by beast-dev.
the class KMLViewer method drawGrid.
private void drawGrid(int dLat, int dLong, Graphics2D g2d, AffineTransform transform) {
for (double longitude = -180; longitude < 180; longitude += dLong) {
Line2D line = new Line2D.Double(longitude, -90, longitude, 90);
g2d.draw(transform.createTransformedShape(line));
}
for (double lat = -90; lat < 90; lat += dLat) {
Line2D line = new Line2D.Double(-180, lat, 180, lat);
g2d.draw(transform.createTransformedShape(line));
}
}
use of java.awt.geom.Line2D in project processdash by dtuma.
the class RangeXYItemRenderer method gradientStart.
private Point2D gradientStart(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3) {
double dy = x0 - x1;
double dx = y1 - y0;
double startLen = Math.sqrt(dy * dy + dx * dx);
if (startLen == 0)
throw new IllegalArgumentException();
Line2D line = new Line2D.Double(x0, y0, x1, y1);
double len2 = line.ptLineDist(x2, y2);
double len3 = line.ptLineDist(x3, y3);
double len = 10;
len = Math.max(len, len2);
len = Math.max(len, len3);
double fraction = len / startLen;
return new Point2D.Double(x1 + dx * fraction, y1 + dy * fraction);
}
Aggregations