KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > pdmodel > interactive > annotation > PDBorderStyleDictionary


1 /**
2  * Copyright (c) 2003-2005, 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.interactive.annotation;
32
33 import org.pdfbox.cos.COSBase;
34 import org.pdfbox.cos.COSDictionary;
35 import org.pdfbox.cos.COSArray;
36 import org.pdfbox.cos.COSInteger;
37
38 import org.pdfbox.pdmodel.common.COSObjectable;
39 import org.pdfbox.pdmodel.graphics.PDLineDashPattern;
40
41 /**
42  * This class represents a PDF /BS entry the border style dictionary.
43  *
44  * @author Paul King
45  * @version $Revision: 1.1 $
46  */

47 public class PDBorderStyleDictionary implements COSObjectable
48 {
49
50     /*
51      * The various values of the style for the border as defined in the PDF 1.6
52      * reference Table 8.13
53      */

54
55     /**
56      * Constant for the name of a solid style.
57      */

58     public static final String JavaDoc STYLE_SOLID = "S";
59
60     /**
61      * Constant for the name of a dashed style.
62      */

63     public static final String JavaDoc STYLE_DASHED = "D";
64
65     /**
66      * Constant for the name of a beveled style.
67      */

68     public static final String JavaDoc STYLE_BEVELED = "B";
69
70     /**
71      * Constant for the name of a inset style.
72      */

73     public static final String JavaDoc STYLE_INSET = "I";
74
75     /**
76      * Constant for the name of a underline style.
77      */

78     public static final String JavaDoc STYLE_UNDERLINE = "U";
79
80     private COSDictionary dictionary;
81
82     /**
83      * Constructor.
84      */

85     public PDBorderStyleDictionary()
86     {
87         dictionary = new COSDictionary();
88     }
89
90     /**
91      * Constructor.
92      *
93      * @param dict
94      * a border style dictionary.
95      */

96     public PDBorderStyleDictionary( COSDictionary dict )
97     {
98         dictionary = dict;
99     }
100
101     /**
102      * returns the dictionary.
103      *
104      * @return the dictionary
105      */

106     public COSDictionary getDictionary()
107     {
108         return dictionary;
109     }
110
111     /**
112      * returns the dictionary.
113      *
114      * @return the dictionary
115      */

116     public COSBase getCOSObject()
117     {
118         return dictionary;
119     }
120
121     /**
122      * This will set the border width in points, 0 = no border.
123      *
124      * @param w
125      * float the width in points
126      */

127     public void setWidth( float w )
128     {
129         getDictionary().setFloat( "W", w );
130     }
131
132     /**
133      * This will retrieve the border width in points, 0 = no border.
134      *
135      * @return flaot the width of the border in points
136      */

137     public float getWidth()
138     {
139         return getDictionary().getFloat( "W", 1 );
140     }
141
142     /**
143      * This will set the border style, see the STYLE_* constants for valid values.
144      *
145      * @param s
146      * the border style to use
147      */

148     public void setStyle( String JavaDoc s )
149     {
150         getDictionary().setName( "S", s );
151     }
152
153     /**
154      * This will retrieve the border style, see the STYLE_* constants for valid
155      * values.
156      *
157      * @return the style of the border
158      */

159     public String JavaDoc getStyle()
160     {
161         return getDictionary().getNameAsString( "S", STYLE_SOLID );
162     }
163
164     /**
165      * This will set the dash style used for drawing the border.
166      *
167      * @param d
168      * the dash style to use
169      */

170     public void setDashStyle( PDLineDashPattern d )
171     {
172         COSArray array = null;
173         if( d != null )
174         {
175             array = d.getCOSDashPattern();
176         }
177         getDictionary().setItem( "D", array );
178     }
179
180     /**
181      * This will retrieve the dash style used for drawing the border.
182      *
183      * @return the dash style of the border
184      */

185     public PDLineDashPattern getDashStyle()
186     {
187         COSArray d = (COSArray) getDictionary().getDictionaryObject( "D" );
188         if (d == null)
189         {
190             d = new COSArray();
191             d.add( new COSInteger( 3 ) );
192             getDictionary().setItem( "D", d );
193         }
194         return new PDLineDashPattern( d, 0 );
195     }
196
197 }
Popular Tags