本文整理汇总了Java中java.awt.print.PrinterException类的典型用法代码示例。如果您正苦于以下问题:Java PrinterException类的具体用法?Java PrinterException怎么用?Java PrinterException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PrinterException类属于java.awt.print包,在下文中一共展示了PrinterException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: print
import java.awt.print.PrinterException; //导入依赖的package包/类
public int print(final Graphics graphics,
final PageFormat pageFormat, final int pageIndex)
throws PrinterException {
final int retVal =
printDelegatee.print(graphics, pageFormat, pageIndex);
if (retVal != NO_SUCH_PAGE && !isAborted()) {
if (SwingUtilities.isEventDispatchThread()) {
updateStatusOnEDT(pageIndex);
} else {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
updateStatusOnEDT(pageIndex);
}
});
}
}
return retVal;
}
示例2: print
import java.awt.print.PrinterException; //导入依赖的package包/类
void print(List<Paper> papers) {
PrinterJob job = PrinterJob.getPrinterJob();
myPapers = papers;
//out("SET PAPER: " + myPapers);
if (job == null) {
return;
}
job.setPrintable(this, Config.getDefault().getPageFormat());
try {
if (job.printDialog()) {
job.print();
}
}
catch (PrinterException e) {
printError(i18n(Printer.class, "ERR_Printer_Problem", e.getLocalizedMessage())); // NOI18N
}
myPapers = null;
}
示例3: createChartPrintJob
import java.awt.print.PrinterException; //导入依赖的package包/类
/**
* Creates a print job for the chart.
*/
@Override
public void createChartPrintJob() {
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pf = job.defaultPage();
PageFormat pf2 = job.pageDialog(pf);
if (pf2 != pf) {
job.setPrintable(this, pf2);
if (job.printDialog()) {
try {
job.print();
} catch (PrinterException e) {
JOptionPane.showMessageDialog(this, e);
}
}
}
}
示例4: setAttributes
import java.awt.print.PrinterException; //导入依赖的package包/类
@Override
protected void setAttributes(PrintRequestAttributeSet attributes)
throws PrinterException {
super.setAttributes(attributes);
if (attributes == null) {
return; // now always use attributes, so this shouldn't happen.
}
Attribute attr = attributes.get(Media.class);
if (attr instanceof CustomMediaTray) {
CustomMediaTray customTray = (CustomMediaTray)attr;
String choice = customTray.getChoiceName();
if (choice != null) {
mOptions = " InputSlot="+ choice;
}
}
}
示例5: pageDialogExample
import java.awt.print.PrinterException; //导入依赖的package包/类
public void pageDialogExample() throws PrinterException
{
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat originalPageFormat = job.defaultPage();
PageFormat pageFormat = job.pageDialog(originalPageFormat);
if(originalPageFormat == pageFormat) return;
job.setPrintable(this,pageFormat);
job.print();
}
示例6: print
import java.awt.print.PrinterException; //导入依赖的package包/类
@Override public int print(Graphics default_graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
List<Image> images = getPrintPages(pageFormat);
if(pageIndex>=images.size())
return NO_SUCH_PAGE;
Graphics2D graphics = (Graphics2D)default_graphics.create();
graphics.translate(pageFormat.getImageableX(),
pageFormat.getImageableY());
graphics.drawImage(images.get(pageIndex), 0, 0, null);
Thread.yield(); //yield shortly, so that the image is painted
return PAGE_EXISTS;
}
示例7: print
import java.awt.print.PrinterException; //导入依赖的package包/类
@Override public int print(Graphics default_graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
if(pageIndex!=0)
return NO_SUCH_PAGE;
pageFormat.setOrientation(PageFormat.LANDSCAPE);
Color foreground = this.foreground, background = this.background, grid = this.grid;
this.foreground = Color.BLACK; this.background = Color.WHITE; this.grid = Color.LIGHT_GRAY;
Graphics2D graphics = (Graphics2D) default_graphics;
graphics.translate(pageFormat.getImageableX(),
pageFormat.getImageableY());
this.paint(graphics);
Thread.yield(); //yield shortly that the graphics are printed properly
this.foreground = foreground; this.background = background; this.grid = grid;
return PAGE_EXISTS;
}
示例8: setPrinterNameAttrib
import java.awt.print.PrinterException; //导入依赖的package包/类
private void setPrinterNameAttrib(String printerName) {
PrintService service = this.getPrintService();
if (printerName == null) {
return;
}
if (service != null && printerName.equals(service.getName())) {
return;
} else {
PrintService []services = PrinterJob.lookupPrintServices();
for (int i=0; i<services.length; i++) {
if (printerName.equals(services[i].getName())) {
try {
this.setPrintService(services[i]);
} catch (PrinterException e) {
}
return;
}
}
}
//** END Functions called by native code for querying/updating attributes
}
示例9: redrawRegion
import java.awt.print.PrinterException; //导入依赖的package包/类
/**
* Redraw a rectanglular area using a proxy graphics
*/
public abstract void redrawRegion(Rectangle2D region,
double scaleX, double scaleY,
Shape clip,
AffineTransform devTransform)
throws PrinterException ;
示例10: print
import java.awt.print.PrinterException; //导入依赖的package包/类
/**
* Prints the page at the specified index into the specified
* {@link Graphics} context in the specified
* format. A <code>PrinterJob</code> calls the
* <code>Printable</code> interface to request that a page be
* rendered into the context specified by
* <code>graphics</code>. The format of the page to be drawn is
* specified by <code>pageFormat</code>. The zero based index
* of the requested page is specified by <code>pageIndex</code>.
* If the requested page does not exist then this method returns
* NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned.
* The <code>Graphics</code> class or subclass implements the
* {@link PrinterGraphics} interface to provide additional
* information. If the <code>Printable</code> object
* aborts the print job then it throws a {@link PrinterException}.
* @param graphics the context into which the page is drawn
* @param pageFormat the size and orientation of the page being drawn
* @param pageIndex the zero based index of the page to be drawn
* @return PAGE_EXISTS if the page is rendered successfully
* or NO_SUCH_PAGE if <code>pageIndex</code> specifies a
* non-existent page.
* @exception java.awt.print.PrinterException
* thrown when the print job is terminated.
*/
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
throws PrinterException {
int result;
/* This method will be called by the PrinterJob on a thread other
* that the application's thread. We hold on to the graphics
* until we can rendevous with the application's thread and
* hand over the graphics. The application then does all the
* drawing. When the application is done drawing we rendevous
* again with the PrinterJob thread and release the Graphics
* so that it knows we are done.
*/
/* Add the graphics to the message queue of graphics to
* be rendered. This is really a one slot queue. The
* application's thread will come along and remove the
* graphics from the queue when the app asks for a graphics.
*/
graphicsToBeDrawn.append( (Graphics2D) graphics);
/* We now wait for the app's thread to finish drawing on
* the Graphics. This thread will sleep until the application
* release the graphics by placing it in the graphics drawn
* message queue. If the application signals that it is
* finished drawing the entire document then we'll get null
* returned when we try and pop a finished graphic.
*/
if (graphicsDrawn.pop() != null) {
result = PAGE_EXISTS;
} else {
result = NO_SUCH_PAGE;
}
return result;
}
示例11: print
import java.awt.print.PrinterException; //导入依赖的package包/类
@Override
public int print(Graphics g, PageFormat pf, int i) throws PrinterException
{
if (i > 0) return NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D)g;
// translate to printable area
g2.translate(pf.getImageableX(), pf.getImageableY());
// now attempt to scale if needed
double scale = Math.min(pf.getImageableWidth() / getWidth(), pf.getImageableHeight() / getHeight());
int width = getWidth();
if ((scale > 1.05) || (scale < 0.95)) {
g2.scale(scale, scale);
width *= scale;
}
// final translate to center of printable area after we know scaled size
if (width < pf.getImageableWidth()) {
int centerx = (int) ((pf.getImageableWidth() - width)/2.0);
g2.translate(centerx, 0);
}
paint(g);
return PAGE_EXISTS;
}
示例12: printWithJavaPrintDialog
import java.awt.print.PrinterException; //导入依赖的package包/类
private static void printWithJavaPrintDialog() {
final JTable table = createAuthorTable(50);
Printable printable = table.getPrintable(
JTable.PrintMode.NORMAL,
new MessageFormat("Author Table"),
new MessageFormat("Page - {0}"));
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(printable);
boolean printAccepted = job.printDialog();
if (printAccepted) {
try {
job.print();
closeFrame();
} catch (PrinterException e) {
throw new RuntimeException(e);
}
}
}
示例13: print
import java.awt.print.PrinterException; //导入依赖的package包/类
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;
}
示例14: createChartPrintJob
import java.awt.print.PrinterException; //导入依赖的package包/类
/**
* Creates a print job for the chart.
*/
public void createChartPrintJob() {
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pf = job.defaultPage();
PageFormat pf2 = job.pageDialog(pf);
if (pf2 != pf) {
job.setPrintable(this, pf2);
if (job.printDialog()) {
try {
job.print();
}
catch (PrinterException e) {
JOptionPane.showMessageDialog(this, e);
}
}
}
}
示例15: print
import java.awt.print.PrinterException; //导入依赖的package包/类
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
throws PrinterException {
if (pageIndex != 0) {
return NO_SUCH_PAGE;
}
/*
CairoImage image = new CairoImage(
this.getBounds().width, this.getBounds().height );
Graphics2D g2 = image.createGraphics2D();
double x = pageFormat.getImageableX();
double y = pageFormat.getImageableY();
double w = pageFormat.getImageableWidth();
double h = pageFormat.getImageableHeight();
this.chart.draw(
g2, new Rectangle2D.Double(x, y, w, h), this.anchor, null
);
*/
return PAGE_EXISTS;
}