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