Source Code Cross Referenced for WinPrinterFactory.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » x » print » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.x.print 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        package org.apache.harmony.x.print;
018:
019:        import java.security.AccessController;
020:        import java.security.PrivilegedAction;
021:        import java.util.Vector;
022:
023:        import javax.print.PrintException;
024:        import javax.print.attribute.ResolutionSyntax;
025:        import javax.print.attribute.Size2DSyntax;
026:        import javax.print.attribute.standard.MediaSize;
027:        import javax.print.attribute.standard.MediaSizeName;
028:        import javax.print.attribute.standard.OrientationRequested;
029:        import javax.print.attribute.standard.PrinterResolution;
030:        import javax.print.attribute.standard.PrinterState;
031:        import javax.print.attribute.standard.QueuedJobCount;
032:
033:        public class WinPrinterFactory {
034:
035:            public static final int PRINTER_STATUS_PAUSED = 1;
036:            public static final int PRINTER_STATUS_ERROR = 2;
037:            public static final int PRINTER_STATUS_PENDING_DELETION = 4;
038:            public static final int PRINTER_STATUS_PAPER_JAM = 8;
039:            public static final int PRINTER_STATUS_PAPER_OUT = 0x10;
040:            public static final int PRINTER_STATUS_MANUAL_FEED = 0x20;
041:            public static final int PRINTER_STATUS_PAPER_PROBLEM = 0x40;
042:            public static final int PRINTER_STATUS_OFFLINE = 0x80;
043:            public static final int PRINTER_STATUS_IO_ACTIVE = 0x100;
044:            public static final int PRINTER_STATUS_BUSY = 0x200;
045:            public static final int PRINTER_STATUS_PRINTING = 0x400;
046:            public static final int PRINTER_STATUS_OUTPUT_BIN_FULL = 0x800;
047:            public static final int PRINTER_STATUS_NOT_AVAILABLE = 0x1000;
048:            public static final int PRINTER_STATUS_WAITING = 0x2000;
049:            public static final int PRINTER_STATUS_PROCESSING = 0x4000;
050:            public static final int PRINTER_STATUS_INITIALIZING = 0x8000;
051:            public static final int PRINTER_STATUS_WARMING_UP = 0x10000;
052:            public static final int PRINTER_STATUS_TONER_LOW = 0x20000;
053:            public static final int PRINTER_STATUS_NO_TONER = 0x40000;
054:            public static final int PRINTER_STATUS_PAGE_PUNT = 0x80000;
055:            public static final int PRINTER_STATUS_USER_INTERVENTION = 0x100000;
056:            public static final int PRINTER_STATUS_OUT_OF_MEMORY = 0x200000;
057:            public static final int PRINTER_STATUS_DOOR_OPEN = 0x400000;
058:            public static final int PRINTER_STATUS_SERVER_UNKNOWN = 0x800000;
059:            public static final int PRINTER_STATUS_POWER_SAVE = 0x1000000;
060:
061:            static {
062:                checkPrintJobAccess();
063:                AccessController.doPrivileged(new PrivilegedAction<Object>() {
064:                    public Object run() {
065:                        System.loadLibrary("print"); //$NON-NLS-1$
066:                        return null;
067:                    }
068:                });
069:            }
070:
071:            public static PrinterState getPrinterState(final long handle)
072:                    throws PrintException {
073:                final long status = getPrinterStatus(handle);
074:
075:                if ((status & (PRINTER_STATUS_PRINTING | PRINTER_STATUS_PROCESSING)) != 0) {
076:                    return PrinterState.PROCESSING;
077:                } else if ((status & (PRINTER_STATUS_DOOR_OPEN
078:                        | PRINTER_STATUS_ERROR | PRINTER_STATUS_NO_TONER
079:                        | PRINTER_STATUS_NOT_AVAILABLE | PRINTER_STATUS_OFFLINE
080:                        | PRINTER_STATUS_OUT_OF_MEMORY
081:                        | PRINTER_STATUS_OUTPUT_BIN_FULL
082:                        | PRINTER_STATUS_PAPER_JAM | PRINTER_STATUS_PAPER_OUT
083:                        | PRINTER_STATUS_PAPER_PROBLEM | PRINTER_STATUS_USER_INTERVENTION)) != 0) {
084:                    return PrinterState.STOPPED;
085:                } else if ((status & PRINTER_STATUS_SERVER_UNKNOWN) != 0) {
086:                    return PrinterState.UNKNOWN;
087:                } else {
088:                    return PrinterState.IDLE;
089:                }
090:            }
091:
092:            public static QueuedJobCount getQueuedJobCount(final long handle)
093:                    throws PrintException {
094:                return new QueuedJobCount(getQueuedJobs(handle));
095:            }
096:
097:            public static MediaSizeName[] getSupportedMediaSizeNames(
098:                    final long handle) throws PrintException {
099:                final MediaSizeName[] names;
100:                final int[] sizes = getSupportedPaperSizes(handle);
101:                final Vector<MediaSizeName> v = new Vector<MediaSizeName>(
102:                        sizes.length / 2);
103:
104:                for (int i = 0; i < sizes.length; i += 2) {
105:                    if ((sizes[i] > 0) && (sizes[i + 1] > 0)) {
106:                        final MediaSizeName name = MediaSize.findMedia(
107:                                sizes[i] / 10, sizes[i + 1] / 10,
108:                                Size2DSyntax.MM);
109:
110:                        if ((name != null) && !v.contains(name)) {
111:                            v.add(name);
112:                        }
113:                    }
114:                }
115:
116:                names = new MediaSizeName[v.size()];
117:                return v.toArray(names);
118:            }
119:
120:            public static MediaSize[] getSupportedMediaSizes(final long handle)
121:                    throws PrintException {
122:                final MediaSizeName[] names = getSupportedMediaSizeNames(handle);
123:                final MediaSize[] sizes = new MediaSize[names.length];
124:
125:                for (int i = 0; i < names.length; i++) {
126:                    sizes[i] = MediaSize.getMediaSizeForName(names[i]);
127:                }
128:
129:                return sizes;
130:            }
131:
132:            public static OrientationRequested[] getSupportedOrientations(
133:                    final long handle) throws PrintException {
134:                if (getLandscapeOrientationDegree(handle) == 270) {
135:                    return new OrientationRequested[] {
136:                            OrientationRequested.PORTRAIT,
137:                            OrientationRequested.REVERSE_LANDSCAPE };
138:                }
139:                return new OrientationRequested[] {
140:                        OrientationRequested.PORTRAIT,
141:                        OrientationRequested.LANDSCAPE };
142:            }
143:
144:            public static PrinterResolution[] getSupportedPrinterResolutions(
145:                    final long handle) throws PrintException {
146:                final int[] res = getSupportedResolutions(handle);
147:                final PrinterResolution[] resolutions = new PrinterResolution[res.length / 2];
148:
149:                for (int i = 0; i < res.length; i += 2) {
150:                    resolutions[i / 2] = new PrinterResolution(res[i],
151:                            res[i + 1], ResolutionSyntax.DPI);
152:                }
153:                return resolutions;
154:            }
155:
156:            public static void checkPrintJobAccess() {
157:                final SecurityManager mgr = System.getSecurityManager();
158:
159:                if (mgr != null) {
160:                    mgr.checkPrintJobAccess();
161:                }
162:            }
163:
164:            public static native String getDefaultPrinterName()
165:                    throws PrintException;
166:
167:            public static native String[] getConnectedPrinterNames()
168:                    throws PrintException;
169:
170:            public static native long getPrinterHandle(final String printerName)
171:                    throws PrintException;
172:
173:            public static native void releasePrinterHandle(final long handle)
174:                    throws PrintException;
175:
176:            /**
177:             * Returns pointer to DEVMODEW structure
178:             */
179:            public static native long getPrinterProps(final String printerName,
180:                    final long handle) throws PrintException;
181:
182:            public static native long getPrinterDC(final String printerName,
183:                    final long pDevMode) throws PrintException;
184:
185:            public static native void releasePrinterDC(final long pdc)
186:                    throws PrintException;
187:
188:            public static native int startDoc(final long pdc,
189:                    final String docName, final String filePath)
190:                    throws PrintException;
191:
192:            public static native void endDoc(final long pdc)
193:                    throws PrintException;
194:
195:            public static native void startPage(final long pdc)
196:                    throws PrintException;
197:
198:            public static native void endPage(final long pdc)
199:                    throws PrintException;
200:
201:            public static native int getQueuedJobs(final long handle)
202:                    throws PrintException;
203:
204:            public static native int getPixelsPerInchX(final long pdc)
205:                    throws PrintException;
206:
207:            public static native int getPixelsPerInchY(final long pdc)
208:                    throws PrintException;
209:
210:            public static native int getPaperPhysicalWidth(final long pdc)
211:                    throws PrintException;
212:
213:            public static native int getPaperPhysicalHeight(final long pdc)
214:                    throws PrintException;
215:
216:            public static native long getPrinterStatus(final long handle)
217:                    throws PrintException;
218:
219:            public static native boolean isColorPrintingSupported(
220:                    final long handle) throws PrintException;
221:
222:            public static native boolean isCollatingSupported(final long handle)
223:                    throws PrintException;
224:
225:            public static native boolean isDuplexSupported(final long handle)
226:                    throws PrintException;
227:
228:            public static native int[] getSupportedPaperSizes(final long handle)
229:                    throws PrintException;
230:
231:            public static native int[] getSupportedResolutions(final long handle)
232:                    throws PrintException;
233:
234:            public static native int getLandscapeOrientationDegree(
235:                    final long handle) throws PrintException;
236:
237:            public static native int getMaxNumberOfCopies(final long handle)
238:                    throws PrintException;
239:
240:            public static native void cancelPrinterJob(final long handle,
241:                    final int jobId) throws PrintException;
242:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.