diff --git a/src/main/java/tigerworkshop/webapphardwarebridge/websocketservices/PrinterWebSocketService.java b/src/main/java/tigerworkshop/webapphardwarebridge/websocketservices/PrinterWebSocketService.java index 1abc4af..3194d7e 100644 --- a/src/main/java/tigerworkshop/webapphardwarebridge/websocketservices/PrinterWebSocketService.java +++ b/src/main/java/tigerworkshop/webapphardwarebridge/websocketservices/PrinterWebSocketService.java @@ -7,7 +7,7 @@ import org.apache.pdfbox.printing.Scaling; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import tigerworkshop.webapphardwarebridge.Config; +import tigerworkshop.webapphardwarebridge.interfaces.NotificationListenerInterface; import tigerworkshop.webapphardwarebridge.interfaces.WebSocketServerInterface; import tigerworkshop.webapphardwarebridge.interfaces.WebSocketServiceInterface; import tigerworkshop.webapphardwarebridge.responses.PrintDocument; @@ -25,16 +25,21 @@ import java.io.IOException; public class PrinterWebSocketService implements WebSocketServiceInterface { - private Logger logger = LoggerFactory.getLogger(getClass()); + private final Logger logger = LoggerFactory.getLogger(getClass()); private WebSocketServerInterface server = null; - private Gson gson = new Gson(); + private final Gson gson = new Gson(); - private SettingService settingService = SettingService.getInstance(); + private final SettingService settingService = SettingService.getInstance(); + private NotificationListenerInterface notificationListener; public PrinterWebSocketService() { logger.info("Starting PrinterWebSocketService"); } + public void setNotificationListener(NotificationListenerInterface notificationListener) { + this.notificationListener = notificationListener; + } + @Override public void start() { server.subscribe(this, getChannel()); @@ -72,6 +77,10 @@ private String getChannel() { */ public void printDocument(PrintDocument printDocument) throws Exception { try { + if (notificationListener != null) { + notificationListener.notify("Printing " + printDocument.getType(), printDocument.getUrl(), TrayIcon.MessageType.INFO); + } + if (isRaw(printDocument)) { printRaw(printDocument); } else if (isImage(printDocument)) { @@ -87,6 +96,10 @@ public void printDocument(PrintDocument printDocument) throws Exception { logger.error("Document Print Error, deleting downloaded document"); DocumentService.deleteFileFromUrl(printDocument.getUrl()); + if (notificationListener != null) { + notificationListener.notify("Printing Error " + printDocument.getType(), e.getMessage(), TrayIcon.MessageType.ERROR); + } + server.onDataReceived(getChannel(), gson.toJson(new PrintResult(1, printDocument.getId(), e.getClass().getName() + " - " + e.getMessage()))); throw e; @@ -226,7 +239,7 @@ private void printPDF(PrintDocument printDocument) throws PrinterException, IOEx Book book = new Book(); for (int i = 0; i < document.getNumberOfPages(); i += 1) { // Rotate Page Automatically - if (Config.PDF_AUTO_ROTATE) { + if (settingService.getSetting().getAutoRotation()) { if (document.getPage(i).getCropBox().getWidth() > document.getPage(i).getCropBox().getHeight()) { pageFormat.setOrientation(PageFormat.LANDSCAPE); } else {