229 }
230 }
231
232 private void completePrintLoop() {
233 Runnable r = new Runnable() { public void run() {
234 synchronized(this) {
235 performingPrinting = false;
236 }
237 if (printingLoop != null) {
238 printingLoop.exit();
239 }
240 }};
241
242 if (onEventThread) {
243 try { EventQueue.invokeAndWait(r); } catch (Exception e) { e.printStackTrace(); }
244 } else {
245 r.run();
246 }
247 }
248
249 @Override
250 public void print(PrintRequestAttributeSet attributes) throws PrinterException {
251 // NOTE: Some of this code is copied from RasterPrinterJob.
252
253
254 // this code uses javax.print APIs
255 // this will make it print directly to the printer
256 // this will not work if the user clicks on the "Preview" button
257 // However if the printer is a StreamPrintService, its the right path.
258 PrintService psvc = getPrintService();
259
260 if (psvc == null) {
261 throw new PrinterException("No print service found.");
262 }
263
264 if (psvc instanceof StreamPrintService) {
265 spoolToService(psvc, attributes);
266 return;
267 }
268
269
270 setAttributes(attributes);
271 // throw exception for invalid destination
272 if (destinationAttr != null) {
273 validateDestination(destinationAttr);
274 }
275
276 /* Get the range of pages we are to print. If the
277 * last page to print is unknown, then we print to
278 * the end of the document. Note that firstPage
279 * and lastPage are 0 based page indices.
280 */
|
229 }
230 }
231
232 private void completePrintLoop() {
233 Runnable r = new Runnable() { public void run() {
234 synchronized(this) {
235 performingPrinting = false;
236 }
237 if (printingLoop != null) {
238 printingLoop.exit();
239 }
240 }};
241
242 if (onEventThread) {
243 try { EventQueue.invokeAndWait(r); } catch (Exception e) { e.printStackTrace(); }
244 } else {
245 r.run();
246 }
247 }
248
249 boolean isPrintToFile = false;
250 private void setPrintToFile(boolean printToFile) {
251 isPrintToFile = printToFile;
252 }
253
254 @Override
255 public void print(PrintRequestAttributeSet attributes) throws PrinterException {
256 // NOTE: Some of this code is copied from RasterPrinterJob.
257
258
259 // this code uses javax.print APIs
260 // this will make it print directly to the printer
261 // this will not work if the user clicks on the "Preview" button
262 // However if the printer is a StreamPrintService, its the right path.
263 PrintService psvc = getPrintService();
264
265 if (psvc == null && !isPrintToFile) {
266 throw new PrinterException("No print service found.");
267 }
268
269 if (psvc instanceof StreamPrintService) {
270 spoolToService(psvc, attributes);
271 return;
272 }
273
274
275 setAttributes(attributes);
276 // throw exception for invalid destination
277 if (destinationAttr != null) {
278 validateDestination(destinationAttr);
279 }
280
281 /* Get the range of pages we are to print. If the
282 * last page to print is unknown, then we print to
283 * the end of the document. Note that firstPage
284 * and lastPage are 0 based page indices.
285 */
|