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: /**
018: * @author Aleksei V. Ivaschenko
019: * @version $Revision: 1.2 $
020: */package org.apache.harmony.x.print;
021:
022: import java.io.OutputStream;
023: import javax.print.DocFlavor;
024: import javax.print.DocPrintJob;
025: import javax.print.ServiceUIFactory;
026: import javax.print.StreamPrintService;
027: import javax.print.StreamPrintServiceFactory;
028: import javax.print.attribute.Attribute;
029: import javax.print.attribute.AttributeSet;
030: import javax.print.attribute.PrintServiceAttribute;
031: import javax.print.attribute.PrintServiceAttributeSet;
032: import javax.print.attribute.standard.ColorSupported;
033: import javax.print.attribute.standard.Copies;
034: import javax.print.attribute.standard.JobName;
035: import javax.print.attribute.standard.Media;
036: import javax.print.attribute.standard.MediaPrintableArea;
037: import javax.print.attribute.standard.MediaSizeName;
038: import javax.print.attribute.standard.Sides;
039: import javax.print.event.PrintServiceAttributeListener;
040:
041: /*
042: * Image2PSStreamPrintService
043: */
044: public class All2PSStreamPrintService extends StreamPrintService {
045:
046: private static final String outputFormat = "application/postscript";
047: private static final MediaSizeName mediaSizes[] = {
048: MediaSizeName.ISO_A3, MediaSizeName.ISO_A4,
049: MediaSizeName.ISO_A5 };
050:
051: private static final Class supportedAttributeCategories[] = {
052: ColorSupported.class, Copies.class, JobName.class,
053: Media.class, MediaPrintableArea.class, Sides.class };
054:
055: private static final DocFlavor supportedDocFlavors[] = {
056: DocFlavor.SERVICE_FORMATTED.PRINTABLE,
057: DocFlavor.SERVICE_FORMATTED.PAGEABLE,
058: DocFlavor.BYTE_ARRAY.GIF, DocFlavor.INPUT_STREAM.GIF,
059: DocFlavor.URL.GIF, DocFlavor.BYTE_ARRAY.JPEG,
060: DocFlavor.INPUT_STREAM.JPEG, DocFlavor.URL.JPEG,
061: DocFlavor.BYTE_ARRAY.PNG, DocFlavor.INPUT_STREAM.PNG,
062: DocFlavor.URL.PNG };
063:
064: public All2PSStreamPrintService(OutputStream outputstream,
065: StreamPrintServiceFactory factory) {
066: super (outputstream);
067: if (factory == null) {
068: throw new NullPointerException("factory is null");
069: }
070: }
071:
072: public String getOutputFormat() {
073: return outputFormat;
074: }
075:
076: public Class[] getSupportedAttributeCategories() {
077: Class copy_supportedAttrCats[] = new Class[supportedAttributeCategories.length];
078: for (int i = 0; i < supportedAttributeCategories.length; i++) {
079: copy_supportedAttrCats[i] = supportedAttributeCategories[i];
080: }
081: return copy_supportedAttrCats;
082: }
083:
084: public boolean isAttributeCategorySupported(Class category) {
085: if (category == null) {
086: throw new NullPointerException("Argument category is null");
087: }
088: if (!(javax.print.attribute.Attribute.class)
089: .isAssignableFrom(category)) {
090: throw new IllegalArgumentException(category.toString()
091: + " is not an Attribute");
092: }
093:
094: for (int i = 0; i < supportedAttributeCategories.length; i++) {
095: if (category.equals(supportedAttributeCategories[i]))
096: return true;
097: }
098: return false;
099: }
100:
101: public String getName() {
102: return "Convert source to Postscript language";
103: }
104:
105: public DocFlavor[] getSupportedDocFlavors() {
106: DocFlavor copy_supportedDocFlavors[] = new DocFlavor[supportedDocFlavors.length];
107: for (int i = 0; i < supportedDocFlavors.length; i++) {
108: copy_supportedDocFlavors[i] = supportedDocFlavors[i];
109: }
110: return copy_supportedDocFlavors;
111: }
112:
113: public boolean isDocFlavorSupported(DocFlavor flavor) {
114: if (flavor == null) {
115: throw new NullPointerException("Argument flavor is null");
116: }
117:
118: for (int i = 0; i < supportedDocFlavors.length; i++) {
119: if (flavor.equals(supportedDocFlavors[i]))
120: return true;
121: }
122: return false;
123: }
124:
125: public DocPrintJob createPrintJob() {
126: return new All2PSDocPrintJob(this );
127: }
128:
129: public int hashCode() {
130: return getName().hashCode();
131: }
132:
133: public boolean equals(Object obj) {
134: return obj == this
135: || (obj instanceof All2PSStreamPrintService)
136: && ((All2PSStreamPrintService) obj).getName().equals(
137: getName());
138: }
139:
140: public ServiceUIFactory getServiceUIFactory() {
141: return null;
142: }
143:
144: /* methods below this line must be completed */
145:
146: public PrintServiceAttributeSet getAttributes() {
147: return null;
148: }
149:
150: public void addPrintServiceAttributeListener(
151: PrintServiceAttributeListener arg0) {
152: }
153:
154: public void removePrintServiceAttributeListener(
155: PrintServiceAttributeListener arg0) {
156: }
157:
158: public Object getDefaultAttributeValue(Class arg0) {
159: return null;
160: }
161:
162: public PrintServiceAttribute getAttribute(Class arg0) {
163: return null;
164: }
165:
166: public boolean isAttributeValueSupported(Attribute arg0,
167: DocFlavor arg1, AttributeSet arg2) {
168: return false;
169: }
170:
171: public AttributeSet getUnsupportedAttributes(DocFlavor arg0,
172: AttributeSet arg1) {
173: return arg1;
174: }
175:
176: public Object getSupportedAttributeValues(Class arg0,
177: DocFlavor arg1, AttributeSet arg2) {
178: return null;
179: }
180:
181: }
|