]> _ Git - cubeextranet.git/blob
b3f4a4a5d95ab4d79763f353e658bde4173a47ca
[cubeextranet.git] /
1 /*\r
2  * Licensed to the Apache Software Foundation (ASF) under one or more\r
3  * contributor license agreements.  See the NOTICE file distributed with\r
4  * this work for additional information regarding copyright ownership.\r
5  * The ASF licenses this file to You under the Apache License, Version 2.0\r
6  * (the "License"); you may not use this file except in compliance with\r
7  * the License.  You may obtain a copy of the License at\r
8  *\r
9  *      http://www.apache.org/licenses/LICENSE-2.0\r
10  *\r
11  * Unless required by applicable law or agreed to in writing, software\r
12  * distributed under the License is distributed on an "AS IS" BASIS,\r
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14  * See the License for the specific language governing permissions and\r
15  * limitations under the License.\r
16  */\r
17 package org.apache.pdfbox.pdmodel.documentinterchange.taggedpdf;\r
18 \r
19 import org.apache.pdfbox.cos.COSArray;\r
20 import org.apache.pdfbox.cos.COSBase;\r
21 import org.apache.pdfbox.cos.COSNull;\r
22 import org.apache.pdfbox.pdmodel.common.COSObjectable;\r
23 import org.apache.pdfbox.pdmodel.graphics.color.PDGamma;\r
24 \r
25 /**\r
26  * An object for four colours.\r
27  *\r
28  * @author <a href="mailto:Johannes%20Koch%20%3Ckoch@apache.org%3E">Johannes Koch</a>\r
29  * @version $Revision: $\r
30  */\r
31 public class PDFourColours implements COSObjectable\r
32 {\r
33 \r
34     private COSArray array;\r
35 \r
36     public PDFourColours()\r
37     {\r
38         this.array = new COSArray();\r
39         this.array.add(COSNull.NULL);\r
40         this.array.add(COSNull.NULL);\r
41         this.array.add(COSNull.NULL);\r
42         this.array.add(COSNull.NULL);\r
43     }\r
44 \r
45     public PDFourColours(COSArray array)\r
46     {\r
47         this.array = array;\r
48         // ensure that array has 4 items\r
49         if (this.array.size() < 4)\r
50         {\r
51             for (int i = (this.array.size() - 1); i < 4; i++)\r
52             {\r
53                 this.array.add(COSNull.NULL);\r
54             }\r
55         }\r
56     }\r
57 \r
58 \r
59     /**\r
60      * Gets the colour for the before edge.\r
61      * \r
62      * @return the colour for the before edge\r
63      */\r
64     public PDGamma getBeforeColour()\r
65     {\r
66         return this.getColourByIndex(0);\r
67     }\r
68 \r
69     /**\r
70      * Sets the colour for the before edge.\r
71      * \r
72      * @param colour the colour for the before edge\r
73      */\r
74     public void setBeforeColour(PDGamma colour)\r
75     {\r
76         this.setColourByIndex(0, colour);\r
77     }\r
78 \r
79     /**\r
80      * Gets the colour for the after edge.\r
81      * \r
82      * @return the colour for the after edge\r
83      */\r
84     public PDGamma getAfterColour()\r
85     {\r
86         return this.getColourByIndex(1);\r
87     }\r
88 \r
89     /**\r
90      * Sets the colour for the after edge.\r
91      * \r
92      * @param colour the colour for the after edge\r
93      */\r
94     public void setAfterColour(PDGamma colour)\r
95     {\r
96         this.setColourByIndex(1, colour);\r
97     }\r
98 \r
99     /**\r
100      * Gets the colour for the start edge.\r
101      * \r
102      * @return the colour for the start edge\r
103      */\r
104     public PDGamma getStartColour()\r
105     {\r
106         return this.getColourByIndex(2);\r
107     }\r
108 \r
109     /**\r
110      * Sets the colour for the start edge.\r
111      * \r
112      * @param colour the colour for the start edge\r
113      */\r
114     public void setStartColour(PDGamma colour)\r
115     {\r
116         this.setColourByIndex(2, colour);\r
117     }\r
118 \r
119     /**\r
120      * Gets the colour for the end edge.\r
121      * \r
122      * @return the colour for the end edge\r
123      */\r
124     public PDGamma getEndColour()\r
125     {\r
126         return this.getColourByIndex(3);\r
127     }\r
128 \r
129     /**\r
130      * Sets the colour for the end edge.\r
131      * \r
132      * @param colour the colour for the end edge\r
133      */\r
134     public void setEndColour(PDGamma colour)\r
135     {\r
136         this.setColourByIndex(3, colour);\r
137     }\r
138 \r
139 \r
140     /**\r
141      * {@inheritDoc}\r
142      */\r
143     public COSBase getCOSObject()\r
144     {\r
145         return this.array;\r
146     }\r
147 \r
148 \r
149     /**\r
150      * Gets the colour by edge index.\r
151      * \r
152      * @param index edge index\r
153      * @return the colour\r
154      */\r
155     private PDGamma getColourByIndex(int index)\r
156     {\r
157         PDGamma retval = null;\r
158         COSBase item = this.array.getObject(index);\r
159         if (item instanceof COSArray)\r
160         {\r
161             retval = new PDGamma((COSArray) item);\r
162         }\r
163         return retval;\r
164     }\r
165 \r
166     /**\r
167      * Sets the colour by edge index.\r
168      * \r
169      * @param index the edge index\r
170      * @param colour the colour\r
171      */\r
172     private void setColourByIndex(int index, PDGamma colour)\r
173     {\r
174         COSBase base;\r
175         if (colour == null)\r
176         {\r
177             base = COSNull.NULL;\r
178         }\r
179         else\r
180         {\r
181             base = colour.getCOSArray();\r
182         }\r
183         this.array.set(index, base);\r
184     }\r
185 \r
186 }\r