Circuit circ = circuits.get(pageIndex);
CircuitState circState = proj.getCircuitState(circ);
Graphics g = base.create();
Graphics2D g2 = g instanceof Graphics2D ? (Graphics2D) g : null;
FontMetrics fm = g.getFontMetrics();
String head = (header != null && !header.equals(""))
? format(header, pageIndex + 1, circuits.size(),
circ.getName())
: null;
int headHeight = (head == null ? 0 : fm.getHeight());
// Compute image size
double imWidth = format.getImageableWidth();
double imHeight = format.getImageableHeight();
// Correct coordinate system for page, including
// translation and possible rotation.
Bounds bds = circ.getBounds(g).expand(4);
double scale = Math.min(imWidth / bds.getWidth(),
(imHeight - headHeight) / bds.getHeight());
if (g2 != null) {
g2.translate(format.getImageableX(), format.getImageableY());
if (rotateToFit && scale < 1.0 / 1.1) {
double scale2 = Math.min(imHeight / bds.getWidth(),
(imWidth - headHeight) / bds.getHeight());
if (scale2 >= scale * 1.1) { // will rotate
scale = scale2;
if (imHeight > imWidth) { // portrait -> landscape
g2.translate(0, imHeight);
g2.rotate(-Math.PI / 2);
} else { // landscape -> portrait
g2.translate(imWidth, 0);
g2.rotate(Math.PI / 2);
}
double t = imHeight;
imHeight = imWidth;
imWidth = t;
}
}
}
// Draw the header line if appropriate
if (head != null) {
g.drawString(head,
(int) Math.round((imWidth - fm.stringWidth(head)) / 2),
fm.getAscent());
if (g2 != null) {
imHeight -= headHeight;
g2.translate(0, headHeight);
}
}