KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.pdfbox.cos.COSArray;
34 import org.pdfbox.cos.COSBase;
35 import org.pdfbox.cos.COSFloat;
36 import org.pdfbox.cos.COSNumber;
37
38 import org.pdfbox.pdmodel.common.COSObjectable;
39
40 /**
41  * A tristimulus, or collection of three floating point parameters used for
42  * color operations.
43  *
44  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
45  * @version $Revision: 1.2 $
46  */

47 public class PDTristimulus implements COSObjectable
48 {
49     private COSArray values = null;
50
51     /**
52      * Constructor. Defaults all values to 0, 0, 0.
53      */

54     public PDTristimulus()
55     {
56         values = new COSArray();
57         values.add( new COSFloat( 0.0f ) );
58         values.add( new COSFloat( 0.0f ) );
59         values.add( new COSFloat( 0.0f ) );
60     }
61
62     /**
63      * Constructor from COS object.
64      *
65      * @param array The array containing the XYZ values.
66      */

67     public PDTristimulus( COSArray array )
68     {
69         values = array;
70     }
71
72     /**
73      * Constructor from COS object.
74      *
75      * @param array The array containing the XYZ values.
76      */

77     public PDTristimulus( float[] array )
78     {
79         values = new COSArray();
80         for( int i=0; i<array.length && i<3; i++ )
81         {
82             values.add( new COSFloat( array[i] ) );
83         }
84     }
85
86     /**
87      * Convert this standard java object to a COS object.
88      *
89      * @return The cos object that matches this Java object.
90      */

91     public COSBase getCOSObject()
92     {
93         return values;
94     }
95
96     /**
97      * This will get the x value of the tristimulus.
98      *
99      * @return The X value.
100      */

101     public float getX()
102     {
103         return ((COSNumber)values.get( 0 )).floatValue();
104     }
105
106     /**
107      * This will set the x value of the tristimulus.
108      *
109      * @param x The x value for the tristimulus.
110      */

111     public void setX( float x )
112     {
113         values.set( 0, new COSFloat( x ) );
114     }
115
116     /**
117      * This will get the y value of the tristimulus.
118      *
119      * @return The Y value.
120      */

121     public float getY()
122     {
123         return ((COSNumber)values.get( 1 )).floatValue();
124     }
125
126     /**
127      * This will set the y value of the tristimulus.
128      *
129      * @param y The y value for the tristimulus.
130      */

131     public void setY( float y )
132     {
133         values.set( 1, new COSFloat( y ) );
134     }
135
136     /**
137      * This will get the z value of the tristimulus.
138      *
139      * @return The Z value.
140      */

141     public float getZ()
142     {
143         return ((COSNumber)values.get( 2 )).floatValue();
144     }
145
146     /**
147      * This will set the z value of the tristimulus.
148      *
149      * @param z The z value for the tristimulus.
150      */

151     public void setZ( float z )
152     {
153         values.set( 2, new COSFloat( z ) );
154     }
155 }
Popular Tags