package org.evergreen_ils.hatch;
+
+import org.eclipse.jetty.util.log.Log;
+import org.eclipse.jetty.util.log.Logger;
import java.awt.*;
import java.awt.event.*;
public class PrintDriver implements Printable {
private String printText;
+ private static final Logger logger = Log.getLogger("PrintDriver");
public int print(Graphics g, PageFormat pf, int page)
throws PrinterException {
/**
* Spawns standard JAVA-driven print dialog and prints text
*/
- public boolean printWithDialog(String text) {
+ public boolean printWithDialog(String key, String text) {
printText = text;
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(this);
try {
job.print();
} catch (PrinterException ex) {
- // TODO
+ logger.warn("Error printing document for key " + key);
+ logger.warn(ex);
return false;
}
return true;
}
+ /**
+ * Print using defaults
+ *
+ * Sends the print job to the configured printer based on the key
+ * and user settings.
+ */
+ public boolean printWithoutDialog(String key, String text) {
+ printText = text;
+ PrinterJob job = PrinterJob.getPrinterJob();
+ job.setPrintable(this);
+
+ // TODO: load user settings, find the right printer, send the
+ // correct attributes, etc.
+
+ try {
+ job.print();
+ } catch (PrinterException ex) {
+ logger.warn("Error printing document for key " + key);
+ logger.warn(ex);
+ return false;
+ }
+ return true;
+ }
+
+
// experiment
// show our own print dialog before the real print action takes over
// currently just shows Print and Cancel.
// Not sure if there is a need for such a thing..
- public void printWithCustomDialog(String msg) {
+ public void printWithCustomDialog(String key, String msg) {
UIManager.put("swing.boldMetal", Boolean.FALSE);
JFrame f = new JFrame("Hello World Printer");
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
final String printMsg = msg;
+ final String printKey = key;
JButton printButton = new JButton("Print '" + msg + "'");
printButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- printWithDialog(printMsg);
+ printWithDialog(printKey, printMsg);
}
});