KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.pdfbox.cos.COSArray;
39 import org.pdfbox.cos.COSBase;
40 import org.pdfbox.cos.COSName;
41 import org.pdfbox.pdmodel.common.function.PDFunction;
42
43 /**
44  * This class represents a Separation color space.
45  *
46  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
47  * @version $Revision: 1.4 $
48  */

49 public class PDSeparation extends PDColorSpace
50 {
51     /**
52      * The name of this color space.
53      */

54     public static final String JavaDoc NAME = "Separation";
55
56     private COSArray array;
57
58     /**
59      * Constructor.
60      */

61     public PDSeparation()
62     {
63         array = new COSArray();
64         array.add( COSName.getPDFName( NAME ) );
65         array.add( COSName.getPDFName( "" ) );
66     }
67
68     /**
69      * Constructor.
70      *
71      * @param separation The array containing all separation information.
72      */

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

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

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

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

122     public ColorModel JavaDoc createColorModel( int bpc ) throws IOException JavaDoc
123     {
124         throw new IOException JavaDoc( "Not implemented" );
125     }
126
127     /**
128      * This will get the separation name.
129      *
130      * @return The name in the separation.
131      */

132     public String JavaDoc getColorantName()
133     {
134         COSName name = (COSName)array.getObject( 1 );
135         return name.getName();
136     }
137
138     /**
139      * This will set the separation name.
140      *
141      * @param name The separation name.
142      */

143     public void setColorantName( String JavaDoc name )
144     {
145         array.set( 1, COSName.getPDFName( name ) );
146     }
147
148     /**
149      * This will get the alternate color space for this separation.
150      *
151      * @return The alternate color space.
152      *
153      * @throws IOException If there is an error getting the alternate color space.
154      */

155     public PDColorSpace getAlternateColorSpace() throws IOException JavaDoc
156     {
157         COSBase alternate = array.getObject( 2 );
158         return PDColorSpaceFactory.createColorSpace( alternate );
159     }
160
161     /**
162      * This will set the alternate color space.
163      *
164      * @param cs The alternate color space.
165      */

166     public void setAlternateColorSpace( PDColorSpace cs )
167     {
168         COSBase space = null;
169         if( cs != null )
170         {
171             space = cs.getCOSObject();
172         }
173         array.set( 2, space );
174     }
175
176     /**
177      * This will get the tint transform function.
178      *
179      * @return The tint transform function.
180      *
181      * @throws IOException If there is an error creating the PDFunction
182      */

183     public PDFunction getTintTransform() throws IOException JavaDoc
184     {
185         return PDFunction.create( array.get( 3 ) );
186     }
187
188     /**
189      * This will set the tint transform function.
190      *
191      * @param tint The tint transform function.
192      */

193     public void setTintTransform( PDFunction tint )
194     {
195         array.set( 3, tint );
196     }
197 }
Popular Tags