List of usage examples for java.awt.print PrinterJob print
public abstract void print() throws PrinterException;
From source file:pcgen.gui2.dialog.PrintPreviewDialog.java
@Override public void actionPerformed(ActionEvent e) { if (SHEET_COMMAND.equals(e.getActionCommand())) { new PreviewLoader((URI) sheetBox.getSelectedItem()).execute(); } else if (PAGE_COMMAND.equals(e.getActionCommand())) { previewPanel.setPage(pageBox.getSelectedIndex()); } else if (ZOOM_COMMAND.equals(e.getActionCommand())) { Double zoom = (Double) zoomBox.getSelectedItem(); previewPanel.setScaleFactor(zoom); } else if (ZOOM_IN_COMMAND.equals(e.getActionCommand())) { Double zoom = (Double) zoomBox.getSelectedItem(); zoomBox.setSelectedItem(zoom * ZOOM_MULTIPLIER); } else if (ZOOM_OUT_COMMAND.equals(e.getActionCommand())) { Double zoom = (Double) zoomBox.getSelectedItem(); zoomBox.setSelectedItem(zoom / ZOOM_MULTIPLIER); } else if (PRINT_COMMAND.equals(e.getActionCommand())) { PrinterJob printerJob = PrinterJob.getPrinterJob(); printerJob.setPageable(pageable); if (printerJob.printDialog()) { try { printerJob.print(); dispose();//from www. j av a 2 s.c o m } catch (PrinterException ex) { String message = "Could not print " + character.getNameRef().get(); Logging.errorPrint(message, ex); frame.showErrorMessage(Constants.APPLICATION_NAME, message); } } } else if (CANCEL_COMMAND.equals(e.getActionCommand())) { dispose(); } }
From source file:processing.app.Editor.java
/** * Handler for File → Print./*from w w w.j a v a 2s . c o m*/ */ public void handlePrint() { statusNotice(_("Printing...")); //printerJob = null; PrinterJob printerJob = PrinterJob.getPrinterJob(); if (pageFormat != null) { //System.out.println("setting page format " + pageFormat); printerJob.setPrintable(textarea, pageFormat); } else { printerJob.setPrintable(textarea); } // set the name of the job to the code name printerJob.setJobName(sketch.getCurrentCode().getPrettyName()); if (printerJob.printDialog()) { try { printerJob.print(); statusNotice(_("Done printing.")); } catch (PrinterException pe) { statusError(_("Error while printing.")); pe.printStackTrace(); } } else { statusNotice(_("Printing canceled.")); } //printerJob = null; // clear this out? }
From source file:Samples.Advanced.GraphEditorDemo.java
/** * a driver for this demo//from w w w . j a v a2 s .c o m */ @SuppressWarnings("serial") public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final GraphEditorDemo demo = new GraphEditorDemo(); 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); } } }); 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(); } } } }); JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); JMenu matrixMenu = new JMenu(); matrixMenu.setText("Matrix"); matrixMenu.setIcon(null); matrixMenu.setPreferredSize(new Dimension(80, 20)); menuBar.add(matrixMenu); JMenuItem copyMatrix = new JMenuItem("Copy Matrix to clipboard", KeyEvent.VK_C); copyMatrix.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); menuBar.add(copyMatrix); frame.setJMenuBar(menuBar); frame.getContentPane().add(demo); copyMatrix.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { Vem textTransfer = new Vem(); //Set up Matrix List<Integer[]> graphMatrix = new ArrayList<Integer[]>(); int MatrixSize = graph.getVertexCount(); Integer[] activeV = new Integer[MatrixSize]; int count = 0; int activeVPos = 0; while (activeVPos < MatrixSize) { if (graph.containsVertex(count)) { activeV[activeVPos] = count; activeVPos++; } count++; } // sgv.g.getVertices().toArray() ((Integer[])(sgv.g.getVertices().toArray())) for (int i = 0; i < MatrixSize; i++) { Integer[] tempArray = new Integer[MatrixSize]; for (int j = 0; j < MatrixSize; j++) { if (graph.findEdge(activeV[i], activeV[j]) != null) { tempArray[j] = 1; } else { tempArray[j] = 0; } } graphMatrix.add(tempArray); } //graphMatrix.add(new Integer[]{1, 2, 3}); //graphMatrix.add(new Integer[]{4, 5 , 6, 7}); //System.out.println(matrixToString(graphMatrix)); //System.out.println(matrixToMathematica(graphMatrix)); textTransfer.setClipboardContents("" + matrixToMathematica(graphMatrix)); System.out.println("Clipboard contains:" + textTransfer.getClipboardContents()); } }); frame.pack(); frame.setVisible(true); }
From source file:Samples.Advanced.GraphEditorDemo2.java
/** * a driver for this demo/*from ww w .j a va2 s . c o m*/ */ @SuppressWarnings("serial") public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final GraphEditorDemo2 demo = new GraphEditorDemo2(); 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); } } }); 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(); } } } }); JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); frame.setJMenuBar(menuBar); frame.getContentPane().add(demo); frame.pack(); frame.setVisible(true); }