List of usage examples for java.awt.print Printable NO_SUCH_PAGE
int NO_SUCH_PAGE
To view the source code for java.awt.print Printable NO_SUCH_PAGE.
Click Source Link
From source file:fr.ign.cogit.geoxygene.appli.layer.LayerViewAwtPanel.java
@Override public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { if (pageIndex >= 1) { return Printable.NO_SUCH_PAGE; }/* w w w. j a v a 2s . c o m*/ Graphics2D g2d = (Graphics2D) graphics; // translate to the upper left corner of the page format g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); // translate to the middle of the page format g2d.translate(pageFormat.getImageableWidth() / 2, pageFormat.getImageableHeight() / 2); Dimension d = this.getSize(); double scale = Math.min(pageFormat.getImageableWidth() / d.width, pageFormat.getImageableHeight() / d.height); if (scale < 1.0) { g2d.scale(scale, scale); } // translate of half the size of the graphics to paint for it to be // centered g2d.translate(-d.width / 2.0, -d.height / 2.0); // copy the rendered layers into the graphics this.getRenderingManager().copyTo(g2d); return Printable.PAGE_EXISTS; }
From source file:BookTest.java
public int print(Graphics g, PageFormat pf, int page) throws PrinterException { if (page >= 1) return Printable.NO_SUCH_PAGE; Graphics2D g2 = (Graphics2D) g; g2.setPaint(Color.black);/* w ww .ja v a 2 s. co m*/ g2.translate(pf.getImageableX(), pf.getImageableY()); FontRenderContext context = g2.getFontRenderContext(); Font f = g2.getFont(); TextLayout layout = new TextLayout(title, f, context); float ascent = layout.getAscent(); g2.drawString(title, 0, ascent); return Printable.PAGE_EXISTS; }
From source file:GraphEditorDemo.java
public int print(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex) throws java.awt.print.PrinterException { if (pageIndex > 0) { return (Printable.NO_SUCH_PAGE); } else {/*ww w.j a v a 2 s . com*/ java.awt.Graphics2D g2d = (java.awt.Graphics2D) graphics; vv.setDoubleBuffered(false); g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); vv.paint(g2d); vv.setDoubleBuffered(true); return (Printable.PAGE_EXISTS); } }
From source file:mavn.network.view.JUNGPanelAdapter.java
@Override public int print(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex) throws java.awt.print.PrinterException { if (pageIndex > 0) { return (Printable.NO_SUCH_PAGE); } else {//from ww w. ja va 2s. c o m java.awt.Graphics2D g2d = (java.awt.Graphics2D) graphics; vv.setDoubleBuffered(false); g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); vv.paint(g2d); vv.setDoubleBuffered(true); return (Printable.PAGE_EXISTS); } }
From source file:org.schreibubi.JCombinations.ui.GridChartPanel.java
public int print(Graphics g, PageFormat pageFormat, int pageIndex) { if (pageIndex > 0) return (Printable.NO_SUCH_PAGE); else {/*from ww w . j a v a 2 s . c o m*/ Graphics2D g2d = (Graphics2D) g; g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); print(g2d); return (Printable.PAGE_EXISTS); } }
From source file:PrintCanvas3D.java
public int print(Graphics g, PageFormat pf, int pi) throws PrinterException { if (pi >= 1) { return Printable.NO_SUCH_PAGE; }/*from w w w . j av a 2s. c o m*/ Graphics2D g2d = (Graphics2D) g; //g2d.translate(pf.getImageableX(), pf.getImageableY()); AffineTransform t2d = new AffineTransform(); t2d.translate(pf.getImageableX(), pf.getImageableY()); double xscale = pf.getImageableWidth() / (double) bImage.getWidth(); double yscale = pf.getImageableHeight() / (double) bImage.getHeight(); double scale = Math.min(xscale, yscale); t2d.scale(scale, scale); try { g2d.drawImage(bImage, t2d, this); } catch (Exception ex) { ex.printStackTrace(); return Printable.NO_SUCH_PAGE; } return Printable.PAGE_EXISTS; }
From source file:gui.GraphsPanel.java
/** open PrinterDialog(). * /*from w ww.java2 s.c om*/ */ public void print() { class VVP implements Printable { VisualizationViewer<TreeNode, TreeNode> vv; public VVP(VisualizationViewer<TreeNode, TreeNode> vv) { this.vv = vv; } public int print(Graphics g, PageFormat pf, int pageIndex) { if (pageIndex > 0) { return Printable.NO_SUCH_PAGE; } else { Graphics2D g2d = (Graphics2D) g; vv.setDoubleBuffered(false); g2d.translate(pf.getImageableX(), pf.getImageableX()); vv.paint(g2d); vv.setDoubleBuffered(true); return (Printable.PAGE_EXISTS); } } } Printable[] toPrint = { new VVP(vv) }; new PrinterDialog(toPrint); }
From source file:MyJava3D.java
public int print(Graphics g, PageFormat pf, int pi) throws PrinterException { if (pi >= 1) { return Printable.NO_SUCH_PAGE; }/*from w ww. j a v a2 s . com*/ Graphics2D g2d = (Graphics2D) g; g2d.translate(pf.getImageableX(), pf.getImageableY()); g2d.translate(pf.getImageableWidth() / 2, pf.getImageableHeight() / 2); Dimension d = getSize(); double scale = Math.min(pf.getImageableWidth() / d.width, pf.getImageableHeight() / d.height); if (scale < 1.0) { g2d.scale(scale, scale); } g2d.translate(-d.width / 2.0, -d.height / 2.0); if (bimg == null) { Graphics2D g2 = createGraphics2D(d.width, d.height, null, g2d); render(d.width, d.height, g2); g2.dispose(); } else { g2d.drawImage(bimg, 0, 0, this); } return Printable.PAGE_EXISTS; }
From source file:jhplot.gui.GHPanel.java
/** * Print the canvas//from w ww .j a v a 2 s .co 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:org.gephi.ui.components.ReportSelection.java
/** * * @param graphics/* w w w . j ava2s .co m*/ * @param pageFormat * @param pageIndex * @return */ @Override public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) { boolean last = false; try { View rootView = displayPane.getUI().getRootView(displayPane); double scaleX = pageFormat.getImageableWidth() / displayPane.getMinimumSize().getWidth(); scaleX = Math.min(scaleX, 1.0); double scaleY = scaleX; int end = (int) (pageIndex * ((1.0f / scaleY) * (double) pageFormat.getImageableHeight())); Rectangle allocation = new Rectangle(0, -end, (int) pageFormat.getImageableWidth(), (int) pageFormat.getImageableHeight()); ((Graphics2D) graphics).scale(scaleX, scaleY); graphics.setClip((int) (pageFormat.getImageableX() / scaleX), (int) (pageFormat.getImageableY() / scaleY), (int) (pageFormat.getImageableWidth() / scaleX), (int) (pageFormat.getImageableHeight() / scaleY)); ((Graphics2D) graphics).translate(((Graphics2D) graphics).getClipBounds().getX(), ((Graphics2D) graphics).getClipBounds().getY()); rootView.paint(graphics, allocation); last = end > displayPane.getUI().getPreferredSize(displayPane).getHeight(); if ((last)) { return Printable.NO_SUCH_PAGE; } } catch (Exception e) { e.printStackTrace(); } return Printable.PAGE_EXISTS; }