List of usage examples for java.awt.print Paper Paper
public Paper()
From source file:MainClass.java
public static void main(String[] args) throws Exception { PrinterJob pj = PrinterJob.getPrinterJob(); PageFormat pf = pj.defaultPage(); Paper paper = new Paper(); double margin = 36; // half inch paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2, paper.getHeight() - margin * 2); pf.setPaper(paper);/*from w ww .j a v a2 s . c om*/ pj.setPrintable(new MyPrintable(), pf); if (pj.printDialog()) { try { pj.print(); } catch (PrinterException e) { System.out.println(e); } } }
From source file:werewolf_off.Server.java
public void sendJSON(JSONObject jobject) throws IOException { JSONObject jobject2 = new JSONObject(); jobject2.put("key", new Paper()); OutputStream out = socket.getOutputStream(); ObjectOutputStream o_out = new ObjectOutputStream(out); o_out.writeObject(jobject2);/*from w ww . java 2s. c om*/ out.flush(); }
From source file:playground.singapore.calibration.charts.CustomChartPanel.java
@Override public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException { System.err.println("PRINTING"); //Divide the current page format into sections based //on the layout instructions received in the constructor //a new pagelayout is created for each cell in the grid //that will then be passed along to the print method of //each chart panel. if (pageIndex != 0) { return NO_SUCH_PAGE; }/*w w w.j a va 2s . c o m*/ List<PageFormat> pageFormats = new ArrayList<PageFormat>(); //setup all the page formats needed for the grid cells. double x = pf.getImageableX(); double y = pf.getImageableY(); double cellWidth = pf.getImageableWidth() / layoutInstructions.getColumns(); double cellHeight = pf.getImageableHeight() / layoutInstructions.getRows(); for (int i = 1; i <= layoutInstructions.getRows(); i++) { double rowOffset = (i - 1) * cellHeight + y; for (int j = 1; j <= layoutInstructions.getColumns(); j++) { PageFormat format = new PageFormat(); Paper paper = new Paper(); double columnOffset = (j - 1) * cellWidth + x; paper.setImageableArea(columnOffset, rowOffset, cellWidth, cellHeight); format.setPaper(paper); pageFormats.add(format); } } //have each chartpanel print on the graphics context using its //particular PageFormat int size = Math.min(pageFormats.size(), panels.size()); for (int i = 0; i < size; i++) { panels.get(i).print(g, pageFormats.get(i), pageIndex); } return PAGE_EXISTS; }
From source file:playground.artemc.calibration.charts.CustomChartPanel.java
@Override public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException { System.err.println("PRINTING"); //Divide the current page format into sections based //on the layout instructions received in the constructor //a new pagelayout is created for each cell in the grid //that will then be passed along to the print method of //each chart panel. if (pageIndex != 0) { return NO_SUCH_PAGE; }//from ww w. j a v a 2 s.co m List<PageFormat> pageFormats = new ArrayList<PageFormat>(); //setup all the page formats needed for the grid cells. double x = pf.getImageableX(); double y = pf.getImageableY(); double cellWidth = pf.getImageableWidth() / layoutInstructions.getColumns(); double cellHeight = pf.getImageableHeight() / layoutInstructions.getRows(); for (int i = 1; i <= layoutInstructions.getRows(); i++) { double rowOffset = (i - 1) * cellHeight + y; for (int j = 1; j <= layoutInstructions.getColumns(); j++) { PageFormat format = new PageFormat(); Paper paper = new Paper(); double columnOffset = (j - 1) * cellWidth + x; paper.setImageableArea(columnOffset, rowOffset, cellWidth, cellHeight); format.setPaper(paper); pageFormats.add(format); } } //have each chartpanel print on the graphics context using its //particular PageFormat int size = Math.min(pageFormats.size(), panels.size()); for (int i = 0; i < size; i++) { panels.get(i).print(g, pageFormats.get(i), pageIndex); } return PAGE_EXISTS; }
From source file:org.pentaho.reporting.engine.classic.extensions.modules.java14print.Java14PrintUtil.java
private static Paper createPaper(final MediaSize mediaSize, final MediaPrintableArea printableArea) { final Paper paper = new Paper(); if (mediaSize != null) { paper.setSize(mediaSize.getX(Size2DSyntax.INCH) * POINTS_PER_INCH, mediaSize.getY(Size2DSyntax.INCH) * POINTS_PER_INCH); }// w w w .j a v a 2s . c o m if (printableArea != null) { paper.setImageableArea(printableArea.getX(Size2DSyntax.INCH) * POINTS_PER_INCH, printableArea.getY(Size2DSyntax.INCH) * POINTS_PER_INCH, printableArea.getWidth(Size2DSyntax.INCH) * POINTS_PER_INCH, printableArea.getHeight(Size2DSyntax.INCH) * POINTS_PER_INCH); } return paper; }
From source file:com.sshtools.sshterm.SshTermSessionPanel.java
/** * * * @param application// w ww . java 2 s . c om * * @throws SshToolsApplicationException */ public void init(SshToolsApplication application) throws SshToolsApplicationException { super.init(application); // Additional connection tabs additionalTabs = new SshToolsConnectionTab[] { new SshTermTerminalTab() }; // 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[] {}); SshTermSessionPanel.this.scrollBar.setValue(SshTermSessionPanel.this.scrollBar.getValue() + (SshTermSessionPanel.this.scrollBar.getUnitIncrement() * ((Integer) m.invoke(evt, new Object[] {})).intValue() * PreferencesStore.getInt(PREF_MOUSE_WHEEL_INCREMENT, 1))); } catch (Throwable t) { } } 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(getApplication().getApplicationName()); 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:org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.internal.LogicalPageDrawable.java
public void init(final LogicalPageBox rootBox, final OutputProcessorMetaData metaData, final ResourceManager resourceManager) { if (rootBox == null) { throw new NullPointerException(); }/* ww w . j ava 2s. c o m*/ if (metaData == null) { throw new NullPointerException(); } if (resourceManager == null) { throw new NullPointerException(); } this.resourceManager = resourceManager; this.metaData = metaData; this.rootBox = rootBox; this.width = StrictGeomUtility.toExternalValue(rootBox.getPageWidth()); this.height = StrictGeomUtility.toExternalValue(rootBox.getPageHeight()); final Paper paper = new Paper(); paper.setImageableArea(0, 0, width, height); this.pageFormat = new PageFormat(); this.pageFormat.setPaper(paper); this.strictClipping = "true".equals(metaData.getConfiguration().getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.StrictClipping")); this.outlineMode = "true".equals(metaData.getConfiguration().getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.debug.OutlineMode")); if ("true".equals(metaData.getConfiguration().getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.debug.PrintPageContents"))) { ModelPrinter.INSTANCE.print(rootBox); } this.unalignedPageBands = metaData.isFeatureSupported(OutputProcessorFeature.UNALIGNED_PAGEBANDS); revalidateTextEllipseProcessStep = new RevalidateTextEllipseProcessStep(metaData); collectSelectedNodesStep = new CollectSelectedNodesStep(); this.clipOnWordBoundary = "true".equals(metaData.getConfiguration() .getConfigProperty("org.pentaho.reporting.engine.classic.core.LastLineBreaksOnWordBoundary")); }
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 ww.jav a 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:PageFormatFactory.java
/** * Creates a paper by using the paper size in points. The created Paper has no ImagableArea defined. * * @param width the width of the paper in points * @param height the height of the paper in points * @return the created paper// ww w.ja va2 s .c om */ public Paper createPaper(final double width, final double height) { final Paper p = new Paper(); p.setSize(width, height); setBorders(p, 0, 0, 0, 0); return p; }
From source file:PageFormatFactory.java
/** * Restores a page format after it has been serialized. * * @param data the serialized page format data. * @return the restored page format.//from ww w . j ava 2 s . c om * @deprecated This functionality is part of JCommon-Serializer */ public PageFormat createPageFormat(final Object[] data) { final Integer orientation = (Integer) data[0]; final float[] dim = (float[]) data[1]; final float[] rect = (float[]) data[2]; final Paper p = new Paper(); p.setSize(dim[0], dim[1]); p.setImageableArea(rect[0], rect[1], rect[2], rect[3]); final PageFormat format = new PageFormat(); format.setPaper(p); format.setOrientation(orientation.intValue()); return format; }