List of usage examples for java.awt Desktop print
public void print(File file) throws IOException
From source file:Test.java
public static void main(String[] a) { try {/* w w w .j av a2 s . co m*/ Desktop desktop = null; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); } desktop.print(new File("c:\\a.txt")); } catch (IOException ioe) { ioe.printStackTrace(); } }
From source file:de.xirp.managers.PrintManager.java
/** * Prints the given {@link java.io.File} using the * {@link java.awt.Desktop} class./* w w w . java2s .co m*/ * * @param document * The file to print. * @throws IOException * if something went wrong printing. * @see java.awt.Desktop */ public static void print(final File document) throws IOException { // TODO: remove awt print stuff, use swt. Desktop desktop; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); try { desktop.print(document); } catch (IOException e) { throw e; } } else { logClass.error(I18n.getString("PrintManager.log.printingNotSupported") + Constants.LINE_SEPARATOR); //$NON-NLS-1$ } }
From source file:entity.files.SYSFilesTools.java
/** * Diese Methode ermittelt zu einer gebenen Datei und einer gewnschten Aktion das passende Anzeigeprogramm. * Falls die Desktop API nicht passendes hat, werdne die lokal definierten Anzeigeprogramme verwendet. * <p>//from www.j av a2 s .c o m * Bei Linux mssen dafr unbedingt die Gnome Libraries installiert sein. * apt-get install libgnome2-0 * * @param file * @param action */ public static void handleFile(File file, java.awt.Desktop.Action action) { if (file == null) { return; } Desktop desktop = null; if (getLocalDefinedApp(file) != null) { try { Runtime.getRuntime().exec(getLocalDefinedApp(file)); } catch (IOException ex) { OPDE.getLogger().error(ex); } } else { if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); if (action == Desktop.Action.OPEN && desktop.isSupported(Desktop.Action.OPEN)) { try { desktop.open(file); } catch (IOException ex) { OPDE.getDisplayManager().addSubMessage( new DisplayMessage(SYSTools.xx("misc.msg.noviewer"), DisplayMessage.WARNING)); } } else if (action == Desktop.Action.PRINT && desktop.isSupported(Desktop.Action.PRINT)) { try { desktop.print(file); } catch (IOException ex) { OPDE.getDisplayManager().addSubMessage( new DisplayMessage(SYSTools.xx("misc.msg.noprintprog"), DisplayMessage.WARNING)); } } else { OPDE.getDisplayManager().addSubMessage( new DisplayMessage(SYSTools.xx("misc.msg.nofilehandler"), DisplayMessage.WARNING)); } } else { OPDE.getDisplayManager().addSubMessage( new DisplayMessage(SYSTools.xx("misc.msg.nojavadesktop"), DisplayMessage.WARNING)); } } }