本文整理汇总了Java中java.awt.print.Printable.NO_SUCH_PAGE属性的典型用法代码示例。如果您正苦于以下问题:Java Printable.NO_SUCH_PAGE属性的具体用法?Java Printable.NO_SUCH_PAGE怎么用?Java Printable.NO_SUCH_PAGE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.awt.print.Printable
的用法示例。
在下文中一共展示了Printable.NO_SUCH_PAGE属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: print
/**
* 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
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;
}
示例3: print
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;
}
示例4: print
public int print(Graphics g, PageFormat pf, int pageIndex)
throws PrinterException {
if (pageIndex > 0) {
return Printable.NO_SUCH_PAGE;
}
g.translate((int) pf.getImageableX(), (int) pf.getImageableY());
g.setFont(new Font("Dialog", Font.PLAIN, 36));
g.drawString("\u4e00\u4e01\u4e02\u4e03\u4e04English", 20, 100);
return Printable.PAGE_EXISTS;
}
示例5: print
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 {
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);
}
}
示例6: print
public int print(Graphics g, PageFormat pf, int pgIndex) {
if (pgIndex > 0) {
return Printable.NO_SUCH_PAGE;
} else {
// "aware" client code can detect that its been passed a
// PrinterGraphics and could theoretically print
// differently. I think this is more likely useful than
// a problem.
applet.printAll(g);
return Printable.PAGE_EXISTS;
}
}
示例7: print
public int print(Graphics graphics,
PageFormat pageFormat,
int pageIndex)
throws PrinterException {
if (pageIndex >= 1) {
return Printable.NO_SUCH_PAGE;
}
this.paint(graphics);
return Printable.PAGE_EXISTS;
}
示例8: print
@Override
public int print(Graphics g, PageFormat pf, int pageIndex)
throws PrinterException {
if (pageIndex == 0) {
g.setColor(Color.RED);
g.drawRect((int)pf.getImageableX(), (int)pf.getImageableY(),
(int)pf.getImageableWidth(), (int)pf.getImageableHeight());
return Printable.PAGE_EXISTS;
} else {
return Printable.NO_SUCH_PAGE;
}
}
示例9: print
@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
throws PrinterException {
if (pageIndex == 0) {
return Printable.PAGE_EXISTS;
} else {
return Printable.NO_SUCH_PAGE;
}
}
示例10: print
@Override
public int print(Graphics base, PageFormat format, int pageIndex) {
if (pageIndex >= circuits.size())
return Printable.NO_SUCH_PAGE;
Circuit circ = circuits.get(pageIndex);
CircuitState circState = proj.getCircuitState(circ);
Graphics g = base.create();
Graphics2D g2 = g instanceof Graphics2D ? (Graphics2D) g : null;
FontMetrics fm = g.getFontMetrics();
String head = (header != null && !header.equals(""))
? format(header, pageIndex + 1, circuits.size(), circ.getName())
: null;
int headHeight = (head == null ? 0 : fm.getHeight());
// Compute image size
double imWidth = format.getImageableWidth();
double imHeight = format.getImageableHeight();
// Correct coordinate system for page, including
// translation and possible rotation.
Bounds bds = circ.getBounds(g).expand(4);
double scale = Math.min(imWidth / bds.getWidth(), (imHeight - headHeight) / bds.getHeight());
if (g2 != null) {
g2.translate(format.getImageableX(), format.getImageableY());
if (rotateToFit && scale < 1.0 / 1.1) {
double scale2 = Math.min(imHeight / bds.getWidth(), (imWidth - headHeight) / bds.getHeight());
if (scale2 >= scale * 1.1) { // will rotate
scale = scale2;
if (imHeight > imWidth) { // portrait -> landscape
g2.translate(0, imHeight);
g2.rotate(-Math.PI / 2);
} else { // landscape -> portrait
g2.translate(imWidth, 0);
g2.rotate(Math.PI / 2);
}
double t = imHeight;
imHeight = imWidth;
imWidth = t;
}
}
}
// Draw the header line if appropriate
if (head != null) {
g.drawString(head, (int) Math.round((imWidth - fm.stringWidth(head)) / 2), fm.getAscent());
if (g2 != null) {
imHeight -= headHeight;
g2.translate(0, headHeight);
}
}
// Now change coordinate system for circuit, including
// translation and possible scaling
if (g2 != null) {
if (scale < 1.0) {
g2.scale(scale, scale);
imWidth /= scale;
imHeight /= scale;
}
double dx = Math.max(0.0, (imWidth - bds.getWidth()) / 2);
g2.translate(-bds.getX() + dx, -bds.getY());
}
// Ensure that the circuit is eligible to be drawn
Rectangle clip = g.getClipBounds();
clip.add(bds.getX(), bds.getY());
clip.add(bds.getX() + bds.getWidth(), bds.getY() + bds.getHeight());
g.setClip(clip);
// And finally draw the circuit onto the page
ComponentDrawContext context = new ComponentDrawContext(proj.getFrame().getCanvas(), circ, circState, base,
g, printerView);
Collection<Component> noComps = Collections.emptySet();
circ.draw(context, noComps);
g.dispose();
return Printable.PAGE_EXISTS;
}