KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > pdmodel > graphics > color > PDDeviceN


1 /**
2  * Copyright (c) 2004, www.pdfbox.org
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. Neither the name of pdfbox; nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * http://www.pdfbox.org
29  *
30  */

31 package org.pdfbox.pdmodel.graphics.color;
32
33 import java.awt.color.ColorSpace JavaDoc;
34 import java.awt.image.ColorModel JavaDoc;
35
36 import java.io.IOException JavaDoc;
37
38 import java.util.List JavaDoc;
39
40 import org.pdfbox.cos.COSArray;
41 import org.pdfbox.cos.COSBase;
42 import org.pdfbox.cos.COSName;
43 import org.pdfbox.cos.COSNull;
44
45 import org.pdfbox.pdmodel.common.COSArrayList;
46
47 /**
48  * This class represents a DeviceN color space.
49  *
50  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
51  * @version $Revision: 1.3 $
52  */

53 public class PDDeviceN extends PDColorSpace
54 {
55     /**
56      * The name of this color space.
57      */

58     public static final String JavaDoc NAME = "DeviceN";
59
60     private COSArray array;
61
62     /**
63      * Constructor.
64      */

65     public PDDeviceN()
66     {
67         array = new COSArray();
68         array.add( COSName.getPDFName( NAME ) );
69         array.add( COSName.getPDFName( "" ) );
70     }
71
72     /**
73      * Constructor.
74      *
75      * @param separation The array containing all separation information.
76      */

77     public PDDeviceN( COSArray separation )
78     {
79         array = separation;
80     }
81
82     /**
83      * This will return the name of the color space. For a PDSeparation object
84      * this will always return "Separation"
85      *
86      * @return The name of the color space.
87      */

88     public String JavaDoc getName()
89     {
90         return NAME;
91     }
92
93     /**
94      * This will get the number of components that this color space is made up of.
95      *
96      * @return The number of components in this color space.
97      *
98      * @throws IOException If there is an error getting the number of color components.
99      */

100     public int getNumberOfComponents() throws IOException JavaDoc
101     {
102         return getColorantNames().size();
103     }
104
105     /**
106      * Create a Java colorspace for this colorspace.
107      *
108      * @return A color space that can be used for Java AWT operations.
109      *
110      * @throws IOException If there is an error creating the color space.
111      */

112     public ColorSpace JavaDoc createColorSpace() throws IOException JavaDoc
113     {
114         throw new IOException JavaDoc( "Not implemented" );
115     }
116     
117     /**
118      * Create a Java color model for this colorspace.
119      *
120      * @param bpc The number of bits per component.
121      *
122      * @return A color model that can be used for Java AWT operations.
123      *
124      * @throws IOException If there is an error creating the color model.
125      */

126     public ColorModel JavaDoc createColorModel( int bpc ) throws IOException JavaDoc
127     {
128         throw new IOException JavaDoc( "Not implemented" );
129     }
130
131     /**
132      * This will get the colorant names. A list of string objects.
133      *
134      * @return A list of colorants
135      */

136     public List JavaDoc getColorantNames()
137     {
138         COSArray names = (COSArray)array.getObject( 1 );
139         return COSArrayList.convertCOSNameCOSArrayToList( names );
140     }
141
142     /**
143      * This will set the list of colorants.
144      *
145      * @param names The list of colorant names.
146      */

147     public void setColorantNames( List JavaDoc names )
148     {
149         COSArray namesArray = COSArrayList.convertStringListToCOSNameCOSArray( names );
150         array.set( 1, namesArray );
151     }
152
153     /**
154      * This will get the alternate color space for this separation.
155      *
156      * @return The alternate color space.
157      *
158      * @throws IOException If there is an error getting the alternate color space.
159      */

160     public PDColorSpace getAlternateColorSpace() throws IOException JavaDoc
161     {
162         COSBase alternate = array.getObject( 2 );
163         return PDColorSpaceFactory.createColorSpace( alternate );
164     }
165
166     /**
167      * This will set the alternate color space.
168      *
169      * @param cs The alternate color space.
170      */

171     public void setAlternateColorSpace( PDColorSpace cs )
172     {
173         COSBase space = null;
174         if( cs != null )
175         {
176             space = cs.getCOSObject();
177         }
178         array.set( 2, space );
179     }
180
181     /**
182      * This will get the tint transform function. At this time the PDModel
183      * does not support functions so we will just return the COSBase object. This
184      * method will change in the future to be a PDModel object.
185      *
186      * @return The tint transform function.
187      */

188     public COSBase getTintTransform()
189     {
190         return array.get( 3 );
191     }
192
193     /**
194      * This will set the tint transform function. At this time the PDModel
195      * does not support functions so we will just return the COSBase object. This
196      * method will change in the future to be a PDModel object.
197      *
198      * @param tint The tint transform function.
199      */

200     public void setTintTransform( COSBase tint )
201     {
202         array.set( 3, tint );
203     }
204
205     /**
206      * This will get the attributes that are associated with the deviceN
207      * color space.
208      *
209      * @return The DeviceN attributes.
210      */

211     public PDDeviceNAttributes getAttributes()
212     {
213         PDDeviceNAttributes retval = null;
214         if( array.size() <5)
215         {
216             retval = new PDDeviceNAttributes();
217             setAttributes( retval );
218         }
219         return retval;
220     }
221
222     /**
223      * This will set the color space attributes. If null is passed in then
224      * all attribute will be removed.
225      *
226      * @param attributes The color space attributes.
227      */

228     public void setAttributes( PDDeviceNAttributes attributes )
229     {
230         if( attributes == null )
231         {
232             array.remove( 4 );
233         }
234         else
235         {
236             //make sure array is large enough
237
while( array.size() < 5 )
238             {
239                 array.add( COSNull.NULL );
240             }
241             array.set( 4, attributes.getCOSDictionary() );
242         }
243     }
244 }
Popular Tags