if (image instanceof PlanarImage) {
image = ((PlanarImage) image).getAsBufferedImage();
}
// Restore the previous layout:
PrintLayoutModel layout = doc.getPrintLayout();
if (layout == null) {
Dimension size = engine.getNaturalSize();
// First try the most recent settings:
if (LastPrintLayout != null) {
layout = LastPrintLayout;
layout.updateImageSize(size.width, size.height);
}
else {
// Last resort is default settings:
layout = new PrintLayoutModel(size.width, size.height);
}
}
// Show the layout dialog:
final PrintLayoutDialog dialog = new PrintLayoutDialog(
(BufferedImage) image, layout, frame, LOCALE.get("PrintDialogTitle")
);
// Hook up behaviors for the dialog buttons:
dialog.addCancelAction(
new ActionListener() {
public void actionPerformed(ActionEvent event) {
dialog.dispose();
if (callback != null)
callback.done();
}
}
);
dialog.addDoneAction(
new ActionListener() {
public void actionPerformed(ActionEvent event) {
PrintLayoutModel layout = dialog.getPrintLayout();
doc.setPrintLayout(layout);
dialog.dispose();
if (callback != null)
callback.done();
LastPrintLayout = layout;
savePrefs();
}
}
);
dialog.addPrintAction(
new ActionListener() {
public void actionPerformed(ActionEvent event) {
PrintLayoutModel layout = dialog.getPrintLayout();
doc.setPrintLayout(layout);
printHeadless(frame, doc);
LastPrintLayout = layout;
savePrefs();
}
}
);
dialog.addPageSetupAction(
new ActionListener() {
public void actionPerformed(ActionEvent event) {
PrintLayoutModel layout = dialog.getPrintLayout();
doc.setPrintLayout(layout);
pageSetup(doc);
layout = doc.getPrintLayout();
PageFormat format = layout.getPageFormat();
dialog.setPageFormat(format);
}
}
);
PrinterLayer printer = Env.getPrinterLayer();