use of java.awt.geom.Rectangle2D in project processdash by dtuma.
the class RadarPlot method drawLabel.
/**
* Draws the label for one radar axis.
*
* @param g2 The graphics device.
* @param chartArea The area for the radar chart.
* @param data The data for the plot.
* @param axis The axis (zero-based index).
* @param startAngle The starting angle.
*/
protected void drawLabel(Graphics2D g2, Rectangle2D chartArea, String label, int axis, double labelX, double labelY) {
// handle label drawing...
FontRenderContext frc = g2.getFontRenderContext();
Rectangle2D labelBounds = this.axisLabelFont.getStringBounds(label, frc);
LineMetrics lm = this.axisLabelFont.getLineMetrics(label, frc);
double ascent = lm.getAscent();
if (labelX == chartArea.getCenterX())
labelX -= labelBounds.getWidth() / 2;
else if (labelX < chartArea.getCenterX())
labelX -= labelBounds.getWidth();
if (labelY > chartArea.getCenterY())
labelY += ascent;
g2.setPaint(this.axisLabelPaint);
g2.setFont(this.axisLabelFont);
g2.drawString(label, (float) labelX, (float) labelY);
}
use of java.awt.geom.Rectangle2D in project beast-mcmc by beast-dev.
the class JChart method paintLegend.
/*
* Transform a drawing co-ordinate into a chart co-ordinate
* /
private double untransformX(double value) {
return xAxis.untransform(
xAxis.transform(xAxis.getMinAxis()) + ((value - xOffset) / xScale));
}*/
/*
* Transform a drawing co-ordinate into a chart co-ordinate
* /
private double untransformY(double value) {
return yAxis.untransform(
yAxis.transform(yAxis.getMinAxis()) + ((value - yOffset) / yScale));
}*/
protected void paintLegend(Graphics2D g2) {
float width = 0;
int itemCount = 0;
for (int i = 0; i < getPlotCount(); i++) {
String name = getPlot(i).getName();
if (name != null) {
float w = (float) g2.getFontMetrics().stringWidth(name);
if (width < w) {
width = w;
}
itemCount++;
}
}
// no plots have names so just return
if (width == 0)
return;
width += 32;
float height = (float) (g2.getFontMetrics().getAscent() + 8) * itemCount;
float x, y;
if (legendAlignment == SwingConstants.NORTH_WEST || legendAlignment == SwingConstants.WEST || legendAlignment == SwingConstants.SOUTH_WEST) {
x = (float) (plotBounds.getX() + 8);
} else if (legendAlignment == SwingConstants.NORTH_EAST || legendAlignment == SwingConstants.EAST || legendAlignment == SwingConstants.SOUTH_EAST) {
x = (float) (plotBounds.getX() + plotBounds.getWidth() - width - 8);
} else {
// centered
x = (float) (plotBounds.getX() + ((plotBounds.getWidth() - width) / 2));
}
if (legendAlignment == SwingConstants.NORTH_WEST || legendAlignment == SwingConstants.NORTH || legendAlignment == SwingConstants.NORTH_EAST) {
y = (float) (plotBounds.getY() + 8);
} else if (legendAlignment == SwingConstants.SOUTH_EAST || legendAlignment == SwingConstants.SOUTH || legendAlignment == SwingConstants.SOUTH_WEST) {
y = (float) (plotBounds.getY() + plotBounds.getHeight() - height - 8);
} else {
// centered
y = (float) (plotBounds.getY() + ((plotBounds.getHeight() - height) / 2));
}
Rectangle2D legendBounds = new Rectangle2D.Float(x, y, width, height);
g2.setPaint(framePaint);
g2.setStroke(frameStroke);
g2.draw(legendBounds);
x += 8;
float iy = 8 + g2.getFontMetrics().getAscent();
y += g2.getFontMetrics().getAscent() + 4;
for (int i = 0; i < getPlotCount(); i++) {
Plot plot = getPlot(i);
String name = plot.getName();
if (name != null) {
g2.setPaint(plot.getLineColor());
g2.fill(new Rectangle2D.Float(x, y - 8, 8, 8));
g2.setPaint(framePaint);
g2.drawString(name, x + 16, y);
y += iy;
}
}
}
use of java.awt.geom.Rectangle2D in project beast-mcmc by beast-dev.
the class MapperFrameOld method doExportPDF.
public final void doExportPDF() {
FileDialog dialog = new FileDialog(this, "Export PDF Image...", FileDialog.SAVE);
dialog.setVisible(true);
if (dialog.getFile() != null) {
File file = new File(dialog.getDirectory(), dialog.getFile());
Rectangle2D bounds = mapperPanel.getExportableComponent().getBounds();
Document document = new Document(new com.lowagie.text.Rectangle((float) bounds.getWidth(), (float) bounds.getHeight()));
try {
// step 2
PdfWriter writer;
writer = PdfWriter.getInstance(document, new FileOutputStream(file));
// step 3
document.open();
// step 4
PdfContentByte cb = writer.getDirectContent();
PdfTemplate tp = cb.createTemplate((float) bounds.getWidth(), (float) bounds.getHeight());
Graphics2D g2d = tp.createGraphics((float) bounds.getWidth(), (float) bounds.getHeight(), new DefaultFontMapper());
mapperPanel.getExportableComponent().print(g2d);
g2d.dispose();
cb.addTemplate(tp, 0, 0);
} catch (DocumentException de) {
JOptionPane.showMessageDialog(this, "Error writing PDF file: " + de, "Export PDF Error", JOptionPane.ERROR_MESSAGE);
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(this, "Error writing PDF file: " + e, "Export PDF Error", JOptionPane.ERROR_MESSAGE);
}
document.close();
}
}
use of java.awt.geom.Rectangle2D in project beast-mcmc by beast-dev.
the class ScatterPlot method drawMark.
/**
* Draw a mark transforming co-ordinates to each axis
*/
protected void drawMark(Graphics2D g2, float x, float y, Color color) {
Rectangle2D bounds = mark.getBounds2D();
float w = (float) bounds.getWidth();
float h = (float) bounds.getHeight();
x = x - (w / 2);
y = y - (h / 2);
g2.translate(x, y);
if (color == null) {
if (markFillPaint != null) {
g2.setPaint(markFillPaint);
g2.fill(mark);
}
} else {
g2.setPaint(color);
g2.fill(mark);
}
g2.setPaint(markPaint);
g2.setStroke(markStroke);
g2.draw(mark);
g2.translate(-x, -y);
Rectangle2D rect = new Rectangle2D.Float(x, y, w, h);
markBounds.add(rect);
}
use of java.awt.geom.Rectangle2D in project beast-mcmc by beast-dev.
the class ScatterPlot method drawMarkHilighted.
/**
* Draw a mark transforming co-ordinates to each axis
*/
protected void drawMarkHilighted(Graphics2D g2, float x, float y) {
Rectangle2D bounds = mark.getBounds2D();
float w = (float) bounds.getWidth();
float h = (float) bounds.getHeight();
x = x - (w / 2);
y = y - (h / 2);
g2.translate(x, y);
if (hilightedMarkFillPaint != null) {
g2.setPaint(hilightedMarkFillPaint);
g2.fill(mark);
}
g2.setPaint(hilightedMarkPaint);
g2.setStroke(hilightedMarkStroke);
g2.draw(mark);
g2.translate(-x, -y);
Rectangle2D rect = new Rectangle2D.Float(x, y, w, h);
markBounds.add(rect);
}
Aggregations