KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > apollo > dev > DevPrintService


1 /*
2 ** Apollo - Test Skeleton Toolkit for Web Start/JNLP
3 ** Copyright (c) 2001, 2002, 2003 by Gerald Bauer
4 **
5 ** This program is free software.
6 **
7 ** You may redistribute it and/or modify it under the terms of the GNU
8 ** General Public License as published by the Free Software Foundation.
9 ** Version 2 of the license should be included with this distribution in
10 ** the file LICENSE, as well as License.html. If the license is not
11 ** included with this distribution, you may find a copy at the FSF web
12 ** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
13 ** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.
14 **
15 ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,
16 ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR
17 ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY
18 ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR
19 ** REDISTRIBUTION OF THIS SOFTWARE.
20 **
21 */

22
23 package apollo.dev;
24
25 import java.awt.print.*;
26 import apollo.*;
27 import houston.*;
28
29 public class DevPrintService implements PrintService
30 {
31    PrinterJob _job;
32
33    public DevPrintService()
34    {
35       _job = PrinterJob.getPrinterJob();
36    }
37
38    public PageFormat getDefaultPage()
39    {
40       return _job.defaultPage();
41    }
42
43    public boolean print( Pageable page )
44    {
45       try
46       {
47          _job.setPageable( page );
48          _job.print();
49          return true;
50       }
51       catch( PrinterException pex )
52       {
53          Status.error( "*** failed to print document: " + pex.toString() );
54          return false;
55       }
56    }
57
58    public boolean print( Printable painter )
59    {
60       try
61       {
62          _job.setPrintable( painter );
63          _job.print();
64          return true;
65       }
66       catch( PrinterException pex )
67       {
68          Status.error( "*** failed to print document: " + pex.toString() );
69          return false;
70       }
71    }
72
73    public PageFormat showPageFormatDialog( PageFormat format )
74    {
75       return _job.pageDialog( format );
76    }
77 }
78
Popular Tags