本文整理汇总了Java中java.awt.print.PageFormat.getImageableWidth方法的典型用法代码示例。如果您正苦于以下问题:Java PageFormat.getImageableWidth方法的具体用法?Java PageFormat.getImageableWidth怎么用?Java PageFormat.getImageableWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.print.PageFormat
的用法示例。
在下文中一共展示了PageFormat.getImageableWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: print
import java.awt.print.PageFormat; //导入方法依赖的package包/类
/**
* Print the plot to a printer, represented by the specified graphics
* object.
*
* @param graphics The context into which the page is drawn.
* @param format The size and orientation of the page being drawn.
* @param index The zero based index of the page to be drawn.
* @return PAGE_EXISTS if the page is rendered successfully, or
* NO_SUCH_PAGE if pageIndex specifies a non-existent page.
* @exception PrinterException If the print job is terminated.
*/
public synchronized int print(Graphics graphics, PageFormat format,
int index) throws PrinterException {
if (graphics == null) return Printable.NO_SUCH_PAGE;
// We only print on one page.
if (index >= 1) {
return Printable.NO_SUCH_PAGE;
}
Graphics2D graphics2D = (Graphics2D) graphics;
// Scale the printout to fit the pages.
// Contributed by Laurent ETUR, Schlumberger Riboud Product Center
double scalex = format.getImageableWidth() / (double) getWidth();
double scaley = format.getImageableHeight() / (double) getHeight();
double scale = Math.min(scalex, scaley);
graphics2D.translate((int)format.getImageableX(),
(int)format.getImageableY());
graphics2D.scale(scale, scale);
_drawPlot(graphics, true);
return Printable.PAGE_EXISTS;
}
示例2: print
import java.awt.print.PageFormat; //导入方法依赖的package包/类
public int print( Graphics graphics, PageFormat format, int index ) {
Graphics2D g2d = (Graphics2D)graphics;
double scalex = g2d.getTransform().getScaleX();
double scaley = g2d.getTransform().getScaleY();
double centerx = ( format.getImageableX() +
( format.getImageableWidth() / 2 ) ) * scalex;
double centery = ( format.getImageableY() +
( format.getImageableHeight() / 2 ) ) * scaley;
// The following 2 lines cause an error when printing in landscape.
g2d.scale( 1 / scalex, 1 / scaley );
g2d.translate( centerx, centery );
Path2D.Double path = new Path2D.Double();
path.moveTo( -scalex * 72, -scaley * 72 );
path.lineTo( -scalex * 72, scaley * 72 );
path.lineTo( scalex * 72, scaley * 72 );
path.lineTo( scalex * 72, -scaley * 72 );
path.closePath();
g2d.draw( path );
return index == 0 ? PAGE_EXISTS : NO_SUCH_PAGE;
}
示例3: scaleToFit
import java.awt.print.PageFormat; //导入方法依赖的package包/类
/**
* Adjusts the scaling factors in both the horizontal and vertical directions
* to garuntee that the Scene prints onto a single page.
* @param useSymmetricScaling if true, the horizontal and vertical scaling
* factors will be the same whereby preserving the current aspect ration. The
* smallest of the two (horizontal and vertical) scaling factors is used for
* both.
*/
private void scaleToFit(boolean useSymmetricScaling) {
PageFormat format = getPageFormat();
Rectangle componentBounds = scene.getView().getBounds();
if (componentBounds.width * componentBounds.height == 0) {
return;
}
double scaleX = format.getImageableWidth() / componentBounds.width;
double scaleY = format.getImageableHeight() / componentBounds.height;
if (scaleX < 1 || scaleY < 1) {
if (useSymmetricScaling) {
if (scaleX < scaleY) {
scaleY = scaleX;
} else {
scaleX = scaleY;
}
}
setSize((float) (componentBounds.width * scaleX), (float) (componentBounds.height * scaleY));
setScaledSize(scaleX, scaleY);
}
}
示例4: scaleToFitX
import java.awt.print.PageFormat; //导入方法依赖的package包/类
/**
* Set the print size to fit a page in the horizontal direction. The
* vertical is scaled equally but no garuntees are made on the page fit.
*/
private void scaleToFitX() {
PageFormat format = getPageFormat();
Rectangle componentBounds = scene.getBounds();
if (componentBounds.width == 0) {
return;
}
double scaleX = format.getImageableWidth() / componentBounds.width;
double scaleY = scaleX;
if (scaleX < 1) {
setSize((float) format.getImageableWidth(),
(float) (componentBounds.height * scaleY));
setScaledSize(scaleX, scaleY);
}
}
示例5: print
import java.awt.print.PageFormat; //导入方法依赖的package包/类
/**
* Prints the chart on a single page.
*
* @param g
* the graphics context.
* @param pf
* the page format to use.
* @param pageIndex
* the index of the page. If not <code>0</code>, nothing gets print.
*
* @return The result of printing.
*/
@Override
public int print(Graphics g, PageFormat pf, int pageIndex) {
if (pageIndex != 0) {
return NO_SUCH_PAGE;
}
Graphics2D g2 = (Graphics2D) g;
double x = pf.getImageableX();
double y = pf.getImageableY();
double w = pf.getImageableWidth();
double h = pf.getImageableHeight();
this.chart.draw(g2, new Rectangle2D.Double(x, y, w, h), this.anchor, null);
return PAGE_EXISTS;
}
示例6: print
import java.awt.print.PageFormat; //导入方法依赖的package包/类
@Override
public int print(java.awt.Graphics g, PageFormat pf, int page) throws PrinterException {
if (page > 0) {
// We have only one page, and 'page' is zero-based
return NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D) g;
// User (0,0) is typically outside the imageable area, so we must
// translate by the X and Y values in the PageFormat to avoid clipping
g2d.translate(pf.getImageableX(), pf.getImageableY());
// Scale plots to paper size.
double scaleX = pf.getImageableWidth() / canvas.getWidth();
double scaleY = pf.getImageableHeight() / canvas.getHeight();
g2d.scale(scaleX, scaleY);
// Disable double buffering
canvas.setDoubleBuffered(false);
// Now we perform our rendering
canvas.print(g);
// Enable double buffering
canvas.setDoubleBuffered(true);
// tell the caller that this page is part of the printed document
return PAGE_EXISTS;
}
示例7: print
import java.awt.print.PageFormat; //导入方法依赖的package包/类
@Override
public int print(Graphics g, PageFormat format, int index) throws PrinterException {
int pagenum = index + 1;
if ((pagenum >= 1) && (pagenum <= file.getNumPages())) {
Graphics2D g2 = (Graphics2D) g;
PDFPage page = file.getPage(pagenum);
Rectangle imageArea = new Rectangle((int) format.getImageableX(), (int) format.getImageableY(),
(int) format.getImageableWidth() , (int) format.getImageableHeight());
g2.translate(0, 0);
PDFRenderer pgs = new PDFRenderer(page, g2, imageArea, null, null);
try {
page.waitForFinish();
pgs.run();
} catch (InterruptedException ie) {
System.out.println(ie.toString());
}
return PAGE_EXISTS;
} else {
return NO_SUCH_PAGE;
}
}
示例8: print
import java.awt.print.PageFormat; //导入方法依赖的package包/类
public int print(Graphics g, PageFormat fmt, int pageNo) {
printing = true;
if( pageNo>1 ) {
printing = false;
return NO_SUCH_PAGE;
}
Rectangle r = getVisibleRect();
double w = fmt.getImageableWidth();
double h = fmt.getImageableHeight();
double x = fmt.getImageableX();
double y = fmt.getImageableY();
Insets ins = axes.getInsets();
double ww = w - ins.left - ins.right;
double hh = h - ins.top - ins.bottom;
double rw = (double)(r.width - ins.left - ins.right);
double rh = (double)(r.height - ins.top - ins.bottom);
double scale = Math.min( rh/rw, rw/rh);
double newH = ww * scale;
double newW = hh * scale;
if( !tracksWidth || !tracksHeight ) {
int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
scale = 72./dpi;
}
newW = rw*scale;
newH = rh*scale;
x -= (newW-ww)/2;
y -= (newH-hh)/2;
w = newW + ins.left + ins.right;
h = newH +ins.top + ins.bottom;
printRect = new Rectangle( (int)x,
(int)y,
(int)w,
(int)h );
paintComponent(g);
printing = false;
return PAGE_EXISTS;
}
示例9: print
import java.awt.print.PageFormat; //导入方法依赖的package包/类
final public int print(Graphics objPgraphics, PageFormat objPpageFormat, int intPpageIndex) {
if (this.objGimageAL != null && intPpageIndex < this.objGimageAL.size()) {
final RenderedImage imgLrendered = (RenderedImage) this.objGimageAL.get(intPpageIndex);
if (imgLrendered != null) {
final Graphics2D objLgraphics2D = (Graphics2D) objPgraphics;
objLgraphics2D.translate(objPpageFormat.getImageableX(), objPpageFormat.getImageableY());
final double dblLxRatio = objPpageFormat.getImageableWidth() / imgLrendered.getWidth();
final double dblLyRatio = objPpageFormat.getImageableHeight() / imgLrendered.getHeight();
objLgraphics2D.scale(dblLxRatio, dblLyRatio);
final AffineTransform objLaffineTransform =
AffineTransform.getTranslateInstance( objPpageFormat.getImageableX(),
objPpageFormat.getImageableY());
objLgraphics2D.drawRenderedImage(imgLrendered, objLaffineTransform);
return Printable.PAGE_EXISTS;
}
}
return Printable.NO_SUCH_PAGE;
}
示例10: print
import java.awt.print.PageFormat; //导入方法依赖的package包/类
/**
* Prints the chart on a single page.
*
* @param g the graphics context.
* @param pf the page format to use.
* @param pageIndex the index of the page. If not <code>0</code>, nothing gets print.
*
* @return the result of printing.
*/
public int print(Graphics g, PageFormat pf, int pageIndex) {
if (pageIndex != 0) {
return NO_SUCH_PAGE;
}
Graphics2D g2 = (Graphics2D) g;
double x = pf.getImageableX();
double y = pf.getImageableY();
double w = pf.getImageableWidth();
double h = pf.getImageableHeight();
this.chart.draw(g2, new Rectangle2D.Double(x, y, w, h), this.anchor, null);
return PAGE_EXISTS;
}
示例11: print
import java.awt.print.PageFormat; //导入方法依赖的package包/类
public int print(Graphics g, PageFormat fmt, int pageNo) {
if( pageNo>0 ) return NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D)g;
Dimension dim = wwd.getPreferredSize();
Rectangle r = wwd.getBounds();
if(r.width>dim.width) r.width = dim.width;
if(r.height>dim.height) r.height = dim.height;
org.geomapapp.util.DateFmt df = new org.geomapapp.util.DateFmt();
int secs = (int)(System.currentTimeMillis()/1000L);
String date = df.format(secs);
Font font = new Font("SansSerif", Font.PLAIN, 8);
g.setFont( font );
Rectangle2D r2d = font.getStringBounds(date, g2.getFontRenderContext());
// g2.translate( r.getWidth()-20.-r2d.getWidth(), r.getHeight()+18. );
g2.setColor( Color.black);
// g.setClip( new Rectangle( 0, 0, r.width, r.height) );
double w = fmt.getImageableWidth();
double h = fmt.getImageableHeight();
double x = fmt.getImageableX();
double y = fmt.getImageableY();
g2.translate(x, y);
double scale = Math.min( w / r.getWidth(), h / r.getHeight());
int xd = (int)(scale*r.getWidth()-10.-r2d.getWidth());
int yd = (int)(scale*r.getHeight()+18.);
g2.drawString( date, xd, yd);
g2.translate( -r.getX()*scale, -r.getY()*scale );
g2.scale( scale, scale);
wwd.getContext().makeCurrent();
BufferedImage image = Screenshot.readToBufferedImage(r.width, r.height);
g2.drawImage(image, 0, 0, this);
return PAGE_EXISTS;
}
示例12: print
import java.awt.print.PageFormat; //导入方法依赖的package包/类
@Override
public int print(java.awt.Graphics g, PageFormat pf, int page) throws PrinterException {
if (page > 0) {
// We have only one page, and 'page' is zero-based
return NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D) g;
// User (0,0) is typically outside the imageable area, so we must
// translate by the X and Y values in the PageFormat to avoid clipping
g2d.translate(pf.getImageableX(), pf.getImageableY());
// Scale plots to paper size.
double scaleX = pf.getImageableWidth() / contentPane.getWidth();
double scaleY = pf.getImageableHeight() / contentPane.getHeight();
g2d.scale(scaleX, scaleY);
// Disable double buffering
RepaintManager currentManager = RepaintManager.currentManager(this);
currentManager.setDoubleBufferingEnabled(false);
// Now we perform our rendering
contentPane.printAll(g);
// Enable double buffering
currentManager.setDoubleBufferingEnabled(true);
// tell the caller that this page is part of the printed document
return PAGE_EXISTS;
}
示例13: print
import java.awt.print.PageFormat; //导入方法依赖的package包/类
public int print(Graphics g, PageFormat pf, int index) {
if (index > 0 || image == null) {
return Printable.NO_SUCH_PAGE;
}
((Graphics2D)g).translate(pf.getImageableX(), pf.getImageableY());
int w = image.getWidth(null);
int h = image.getHeight(null);
int iw = (int)pf.getImageableWidth();
int ih = (int)pf.getImageableHeight();
// ensure image will fit
int dw = w;
int dh = h;
if (dw > iw) {
dh = (int)(dh * ( (float) iw / (float) dw)) ;
dw = iw;
}
if (dh > ih) {
dw = (int)(dw * ( (float) ih / (float) dh)) ;
dh = ih;
}
// centre on page
int dx = (iw - dw) / 2;
int dy = (ih - dh) / 2;
g.drawImage(image, dx, dy, dx+dw, dy+dh, 0, 0, w, h, null);
return Printable.PAGE_EXISTS;
}
示例14: print
import java.awt.print.PageFormat; //导入方法依赖的package包/类
public int print(Graphics g, PageFormat pf, int pi)
throws PrinterException {
if (pi != 0) {
return NO_SUCH_PAGE;
}
Graphics2D g2 = (Graphics2D) g;
g2.setFont(new Font("Serif", Font.PLAIN, 36));
g2.setPaint(Color.black);
g2.drawString("Java Source and Support", 100, 100);
Rectangle2D outline = new Rectangle2D.Double(pf.getImageableX(), pf
.getImageableY(), pf.getImageableWidth(), pf
.getImageableHeight());
g2.draw(outline);
return PAGE_EXISTS;
}
示例15: setSize
import java.awt.print.PageFormat; //导入方法依赖的package包/类
private void setSize() {
int pageCount = printable.getPageCount();
rowCount = (pageCount - 1) / columnCount + 1;
pageWidth = 0;
pageHeight = 0;
pages = new Page[pageCount];
PageFormat pageFormat = printable.getPageFormat();
for (int i = 0; i < pageCount; i++) {
pageFormat = printable.getPageFormat(pageFormat, i);
double w = pageFormat.getWidth() + 1;
double h = pageFormat.getHeight() + 1;
double iW = pageFormat.getImageableWidth();
double iH = pageFormat.getImageableHeight();
double x = pageFormat.getImageableX();
double y = pageFormat.getImageableY();
reverce = (pageFormat.getOrientation() == PageFormat.REVERSE_LANDSCAPE);
/*
* if (pageFormat.getOrientation() == PageFormat.LANDSCAPE) { double
* t;
*
* t = w; w = h; h = t;
*
* t = iW; iW = iH; iH = t;
*
* t = x; x = y; y = t; }
*/
Page page = new Page(w, h, x, y, iW, iH);
if (pageWidth < w)
pageWidth = w;
if (pageHeight < h)
pageHeight = h;
pages[i] = page;
}
width = (columnCount - 1) * (pageWidth + W_SPACE / zoom) + pageWidth;
height = rowCount * (pageHeight + W_SPACE / zoom);
Dimension size = new Dimension((int) (width * getZoom()),
(int) (height * getZoom()));
this.setSize(size);
this.setPreferredSize(size);
}