From 5de8f6080cff62c7a52128dc3865b740811306fc Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Mon, 5 Feb 2018 19:26:12 +0400 Subject: [PATCH] JPoint 2018 Demo --- src/main/electron/main.js | 2 + src/main/electron/package-lock.json | 12 +++--- src/main/java/demo/AppUI.java | 65 +---------------------------- 3 files changed, 10 insertions(+), 69 deletions(-) diff --git a/src/main/electron/main.js b/src/main/electron/main.js index e38c629..7ec2e0e 100644 --- a/src/main/electron/main.js +++ b/src/main/electron/main.js @@ -41,6 +41,8 @@ function createWindow() { mainWindow.loadURL(appUrl); + mainWindow.webContents.openDevTools(); + mainWindow.on('closed', function () { mainWindow = null; }); diff --git a/src/main/electron/package-lock.json b/src/main/electron/package-lock.json index b491a5e..4ff3919 100644 --- a/src/main/electron/package-lock.json +++ b/src/main/electron/package-lock.json @@ -1100,6 +1100,12 @@ "tweetnacl": "0.14.5" } }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", + "dev": true + }, "string-width": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", @@ -1111,12 +1117,6 @@ "strip-ansi": "3.0.1" } }, - "string_decoder": { - "version": "0.10.31", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", - "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", - "dev": true - }, "stringstream": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", diff --git a/src/main/java/demo/AppUI.java b/src/main/java/demo/AppUI.java index 5fc9a98..94f61c5 100644 --- a/src/main/java/demo/AppUI.java +++ b/src/main/java/demo/AppUI.java @@ -7,15 +7,6 @@ import com.vaadin.ui.*; import com.vaadin.ui.themes.ValoTheme; -import javax.print.*; -import javax.print.attribute.HashPrintRequestAttributeSet; -import javax.print.attribute.PrintRequestAttributeSet; -import javax.swing.*; -import java.io.StringReader; - -import static com.vaadin.ui.Notification.Type.HUMANIZED_MESSAGE; -import static com.vaadin.ui.Notification.Type.WARNING_MESSAGE; - @Push(transport = Transport.WEBSOCKET) @Theme(ValoTheme.THEME_NAME) public class AppUI extends UI { @@ -25,18 +16,7 @@ protected void init(VaadinRequest request) { nameField.setCaption("Your name"); Button button = new Button("Print Hello", event -> { - Runtime runtime = Runtime.getRuntime(); - - printHelloDocument(String.format( - "Hello %s!\n" + - "Your PC is so powerful:\n" + - "%s processors\n" + - "%s free memory\n" + - "%s max memory", - nameField.getValue(), - runtime.availableProcessors(), - runtime.freeMemory(), - runtime.maxMemory())); + printHelloDocument(nameField.getValue()); }); VerticalLayout content = new VerticalLayout(); @@ -45,47 +25,6 @@ protected void init(VaadinRequest request) { } private void printHelloDocument(String value) { - PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); - - DocFlavor flavor = DocFlavor.READER.TEXT_PLAIN; - Doc doc = new SimpleDoc(new StringReader(value), flavor, null); - - PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, aset); - PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); - - if (services.length == 0) { - if (defaultService == null) { - new Notification("No printer found", WARNING_MESSAGE).show(getPage()); - } else { - DocPrintJob job = defaultService.createPrintJob(); - printDocument(doc, aset, job); - } - } else { - SwingUtilities.invokeLater(() -> { - PrintService service = ServiceUI.printDialog(null, 200, 200, - services, defaultService, flavor, aset); - if (service != null) { - DocPrintJob job = service.createPrintJob(); - printDocument(doc, aset, job); - } - }); - } - } - - private void printDocument(Doc doc, PrintRequestAttributeSet aset, DocPrintJob job) { - try { - job.print(doc, aset); - - getUI().access(() -> - new Notification("See the result!", HUMANIZED_MESSAGE) - .show(getPage()) - ); - } catch (PrintException e) { - // may be called from Swing thread - getUI().access(() -> { - new Notification("Unable to print file, please check settings", - WARNING_MESSAGE).show(getPage()); - }); - } + new Notification("Hi " + value).show(getPage()); } } \ No newline at end of file