List of usage examples for java.awt.print PrinterJob getPrinterJob
public static PrinterJob getPrinterJob()
From source file:com.alvermont.terraj.planet.ui.TerrainFrame.java
private void printItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_printItemActionPerformed {//GEN-HEADEREND:event_printItemActionPerformed final PrinterJob printJob = PrinterJob.getPrinterJob(); final PageFormat pf = printJob.pageDialog(printJob.defaultPage()); printJob.setPrintable(new ImagePrinter(image, pf), pf); if (printJob.printDialog()) { try {// ww w. j a v a 2 s . c o m printJob.print(); } catch (Exception e) { log.error("Error printing", e); JOptionPane.showMessageDialog(this, "Error: " + e.getMessage() + "\nCheck log file for full details", "Error Printing", JOptionPane.ERROR_MESSAGE); } } }
From source file:org.martus.client.swingui.actions.ActionMenuCharts.java
private boolean printToPrinter(JFreeChart chart) throws PrinterException { PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(new PrintableChart(chart)); HashPrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); removeJavaLogoFromTitle(attributes); if (!printJob.printDialog(attributes)) return false; printJob.print(attributes);// ww w .j a va2 s . co m return true; }
From source file:com.sshtools.sshterm.SshTerminalPanel.java
public void init(SshToolsApplication application) throws SshToolsApplicationException { super.init(application); boolean kerb_support = false; if (PreferencesStore.get(PREF_KRB5_MYPROXY_USE, "NONE").indexOf("true") >= 0) kerb_support = true;//w w w . j a va 2 s .c o m // Additional connection tabs if (kerb_support == true) { additionalTabs = new SshToolsConnectionTab[] { new SshTermCommandTab(), new SshTermTerminalTab(), new GSIAuthTab(), new XForwardingTab(), new SshToolsConnectionKerberosTab() }; SshTerminalPanel.PREF_KRB5_MYPROXY_ENABLED = true; } else { additionalTabs = new SshToolsConnectionTab[] { new SshTermCommandTab(), new SshTermTerminalTab(), new GSIAuthTab(), new XForwardingTab() }; SshTerminalPanel.PREF_KRB5_MYPROXY_ENABLED = false; } // //portForwardingPane = new PortForwardingPane(); // Printing page format try { if (System.getSecurityManager() != null) { AccessController.checkPermission(new RuntimePermission("queuePrintJob")); } try { PrinterJob job = PrinterJob.getPrinterJob(); if (job == null) { throw new IOException("Could not get print page format."); } pageFormat = job.defaultPage(); if (PreferencesStore.preferenceExists(PREF_PAGE_FORMAT_ORIENTATION)) { pageFormat.setOrientation( PreferencesStore.getInt(PREF_PAGE_FORMAT_ORIENTATION, PageFormat.LANDSCAPE)); Paper paper = new Paper(); paper.setImageableArea(PreferencesStore.getDouble(PREF_PAGE_FORMAT_IMAGEABLE_X, 0), PreferencesStore.getDouble(PREF_PAGE_FORMAT_IMAGEABLE_Y, 0), PreferencesStore.getDouble(PREF_PAGE_FORMAT_IMAGEABLE_W, 0), PreferencesStore.getDouble(PREF_PAGE_FORMAT_IMAGEABLE_H, 0)); paper.setSize(PreferencesStore.getDouble(PREF_PAGE_FORMAT_SIZE_W, 0), PreferencesStore.getDouble(PREF_PAGE_FORMAT_SIZE_H, 0)); pageFormat.setPaper(paper); } } catch (Exception e) { showExceptionMessage("Error", e.getMessage()); } } catch (AccessControlException ace) { ace.printStackTrace(); } enableEvents(VDU_EVENTS); // Set up the actions initActions(); // Create the status bar statusBar = new StatusBar(); dataListener = new DataNotificationListener(statusBar); // Create our terminal emulation object try { emulation = createEmulation(); } catch (IOException ioe) { throw new SshToolsApplicationException(ioe); } emulation.addTerminalListener(this); // Set a scrollbar for the terminal - doesn't seem to be as simple as this scrollBar = new JScrollBar(JScrollBar.VERTICAL); emulation.setBufferSize(1000); // Create our swing terminal and add it to the main frame terminal = new TerminalPanel(emulation) { public void processEvent(AWTEvent evt) { /** We can't add a MouseWheelListener because it was not available in 1.3, so direct processing of events is necessary */ if (evt instanceof MouseEvent && evt.getID() == 507) { try { Method m = evt.getClass().getMethod("getWheelRotation", new Class[] {}); SshTerminalPanel.this.scrollBar.setValue(SshTerminalPanel.this.scrollBar.getValue() + (SshTerminalPanel.this.scrollBar.getUnitIncrement() * ((Integer) m.invoke(evt, new Object[] {})).intValue() * PreferencesStore.getInt(PREF_MOUSE_WHEEL_INCREMENT, 1))); } catch (Throwable t) { // In theory, this should never happen } } else { super.processEvent(evt); } } public void copyNotify() { copyAction.actionPerformed(null); } }; terminal.requestFocus(); terminal.setScrollbar(scrollBar); terminal.addMouseMotionListener(this); //terminal.addMouseWheelListener(this); // Center panel with terminal and scrollbar JPanel center = new JPanel(new BorderLayout()); center.setBackground(Color.red); center.add(terminal, BorderLayout.CENTER); center.add(scrollBar, BorderLayout.EAST); // Show the context menu on mouse button 3 (right click) terminal.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if ((evt.getModifiers() & MouseEvent.BUTTON3_MASK) > 0) { getContextMenu() .setLabel((getCurrentConnectionFile() == null) ? getApplication().getApplicationName() : getCurrentConnectionFile().getName()); getContextMenu().show(terminal, evt.getX(), evt.getY()); } else if ((evt.getModifiers() & MouseEvent.BUTTON2_MASK) > 0) { pasteAction.actionPerformed(null); } } }); // // JPanel top = new JPanel(new BorderLayout()); // top.add(getJMenuBar(), BorderLayout.NORTH); // top.add(north, BorderLayout.SOUTH); setLayout(new BorderLayout()); add(center, BorderLayout.CENTER); // add(top, BorderLayout.NORTH); // Make sure that the swing terminal has focus terminal.requestFocus(); }
From source file:PrintCanvas3D.java
void print() { PrinterJob printJob = PrinterJob.getPrinterJob(); PageFormat pageFormat = printJob.defaultPage(); pageFormat.setOrientation(PageFormat.LANDSCAPE); pageFormat = printJob.validatePage(pageFormat); printJob.setPrintable(this, pageFormat); if (printJob.printDialog()) { try {/*from www .j a va2s . c o m*/ printJob.print(); } catch (PrinterException ex) { ex.printStackTrace(); } } }
From source file:org.gumtree.vis.awt.CompositePanel.java
@Override public void createChartPrintJob() { setCursor(StaticValues.WAIT_CURSOR); PrinterJob job = PrinterJob.getPrinterJob(); PageFormat pf = job.defaultPage(); PageFormat pf2 = job.pageDialog(pf); if (pf2 != pf) { job.setPrintable(this, pf2); try {//from ww w . j av a 2 s. com job.print(); } catch (PrinterException e) { JOptionPane.showMessageDialog(this, e); } finally { setCursor(StaticValues.defaultCursor); } } setCursor(StaticValues.defaultCursor); }
From source file:com.alvermont.terraj.stargen.ui.SystemFrame.java
private void printMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_printMenuItemActionPerformed {//GEN-HEADEREND:event_printMenuItemActionPerformed try {//from w w w .j av a 2 s .c om List<BufferedImage> images = UIUtils.getPlanetImages(this.planets); BufferedImage collage = UIUtils.combineImagesHorizontal(images); final PrinterJob printJob = PrinterJob.getPrinterJob(); final PageFormat pf = printJob.pageDialog(printJob.defaultPage()); printJob.setPrintable(new ImagePrinter(collage, pf), pf); if (printJob.printDialog()) { printJob.print(); } } catch (Exception e) { log.error("Error printing", e); JOptionPane.showMessageDialog(this, "Error: " + e.getMessage() + "\nCheck log file for full details", "Error Printing", JOptionPane.ERROR_MESSAGE); } }
From source file:com.imag.nespros.gui.plugin.GraphEditor.java
private static void initMenu() { JMenu menu = new JMenu("File"); menu.add(new AbstractAction("Make Image") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showSaveDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); demo.writeJPEGImage(file); }//from w w w. j ava2 s . co m } }); menu.add(new AbstractAction("Print") { public void actionPerformed(ActionEvent e) { PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(demo); if (printJob.printDialog()) { try { printJob.print(); } catch (Exception ex) { ex.printStackTrace(); } } } }); menu.add(new AbstractAction("Save topology") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showSaveDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { demo.save(file); frame.setTitle(file.getName()); } catch (IOException ex) { Logger.getLogger(GraphEditor.class.getName()).log(Level.SEVERE, null, ex); } } } }); menu.add(new AbstractAction("Load topology") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showOpenDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { //EPGraph.getInstance().resetMapping(); simu.resetMapping(); demo.load(file); frame.setTitle("Simulator - " + file.getName()); } catch (FileNotFoundException ex) { Logger.getLogger(GraphEditor.class.getName()).log(Level.SEVERE, null, ex); } } } }); JMenu menu2 = new JMenu("View"); menu2.add(new AbstractAction("Layout") { @Override public void actionPerformed(ActionEvent e) { Layout l = new CircleLayout<Device, ComLink>(Topology.getInstance().getGraph()); l.setInitializer(vv.getGraphLayout()); l.setSize(vv.getSize()); LayoutTransition<Device, ComLink> lt = new LayoutTransition<>(vv, vv.getGraphLayout(), l); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.repaint(); } }); menu2.add(new AbstractAction("Event Composition Networks") { @Override public void actionPerformed(ActionEvent e) { showEPGraph(EPGraph.getInstance().getGraph()); } }); JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); menuBar.add(menu2); frame.setJMenuBar(menuBar); frame.getContentPane().add(demo); frame.pack(); frame.setVisible(true); buildEPGraphs(); showEPGraph(EPGraph.getInstance().getGraph()); }
From source file:com.sshtools.sshterm.SshTermSessionPanel.java
/** * *//* ww w . j a va 2 s . c o m*/ public void printScreen() { try { PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(terminal, pageFormat); if (job.printDialog()) { setCursor(Cursor.getPredefinedCursor(3)); job.print(); setCursor(Cursor.getPredefinedCursor(0)); } } catch (PrinterException pe) { JOptionPane.showMessageDialog(this, pe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:jhplot.gui.GHPanel.java
/** * Print the canvas//from w ww.j a va2 s. c o m * */ public void printGraph() { if (isBorderShown()) showBorders(false); CanvasPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); Thread t = new Thread() { public void run() { try { PrinterJob prnJob = PrinterJob.getPrinterJob(); // set the Printable to the PrinterJob prnJob.setPrintable(new Printable() { public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) { if (pageIndex == 0) { Graphics2D g2d = (Graphics2D) graphics; double ratioX = pageFormat.getImageableWidth() / CanvasPanel.getSize().width; double ratioY = pageFormat.getImageableHeight() / CanvasPanel.getSize().height; double factor = Math.min(ratioX, ratioY); g2d.scale(factor, factor); g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); disableDoubleBuffering(CanvasPanel); CanvasPanel.print(g2d); enableDoubleBuffering(CanvasPanel); return Printable.PAGE_EXISTS; } return Printable.NO_SUCH_PAGE; } }); if (prnJob.printDialog()) { JHPlot.showStatusBarText("Printing.."); prnJob.print(); } } catch (PrinterException e) { e.printStackTrace(); } } }; t.start(); CanvasPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); }
From source file:freemind.controller.Controller.java
private boolean acquirePrinterJobAndPageFormat() { if (printerJob == null) { try {//ww w. j a v a2 s. co m printerJob = PrinterJob.getPrinterJob(); } catch (SecurityException ex) { isPrintingAllowed = false; return false; } } if (pageFormat == null) { pageFormat = printerJob.defaultPage(); if (Tools.safeEquals(getProperty("page_orientation"), "landscape")) { pageFormat.setOrientation(PageFormat.LANDSCAPE); } else if (Tools.safeEquals(getProperty("page_orientation"), "portrait")) { pageFormat.setOrientation(PageFormat.PORTRAIT); } else if (Tools.safeEquals(getProperty("page_orientation"), "reverse_landscape")) { pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE); } } return true; }