KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > jpdf > PDFBorder


1 /*
2  * $Id: PDFBorder.java,v 1.2 2001/11/16 15:26:04 ezb Exp $
3  *
4  * $Date: 2001/11/16 15:26:04 $
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */

20 package gnu.jpdf;
21
22 import java.awt.*;
23 import java.io.*;
24 import java.util.*;
25
26 /**
27  * <p>A border around an annotation </p>
28  *
29  *
30  * @author Peter T Mount, http://www.retep.org.uk/pdf/
31  * @author Eric Z. Beard, ericzbeard@hotmail.com
32  * @author $Author: ezb $
33  * @version $Revision: 1.2 $
34  */

35 public class PDFBorder extends PDFObject
36 {
37     /*
38      * NOTE: The original class is the work of Peter T. Mount, who released it
39      * in the uk.org.retep.pdf package. It was modified by Eric Z. Beard as
40      * follows: the package name was changed to gnu.pdf. It is still
41      * licensed under the LGPL.
42    */

43
44     /**
45      * The style of the border
46      */

47     private short style;
48     
49     /**
50      * The width of the border
51      */

52     private double width;
53     
54     /**
55      * This array allows the definition of a dotted line for the border
56      */

57     private double dash[];
58     
59     /**
60      * Creates a border using the predefined styles in PDFAnnot.
61      * <p>Note: Do not use PDFAnnot.DASHED with this method.
62      * Use the other constructor.
63      *
64      * @param style The style of the border
65      * @param width The width of the border
66      * @see PDFAnnot
67      */

68     public PDFBorder(short style,double width) {
69         super("/Border");
70         this.style = style;
71         this.width = width;
72     }
73     
74     /**
75      * Creates a border of style PDFAnnot.DASHED
76      *
77      * @param width The width of the border
78      * @param dash The line pattern definition
79      */

80     public PDFBorder(double width,double dash[]) {
81         super("/Border");
82         this.style = PDFAnnot.DASHED;
83         this.width = width;
84         this.dash = dash;
85     }
86     
87     /**
88      * @param os OutputStream to send the object to
89      * @exception IOException on error
90      */

91     public void write(OutputStream os) throws IOException {
92         //writeStart(os);
93
os.write(Integer.toString(objser).getBytes());
94         os.write(" 0 obj\n".getBytes());
95       
96         os.write("[/S /".getBytes());
97         os.write("SDBIU".substring(style,style+1).getBytes());
98         os.write(" /W ".getBytes());
99         os.write(Double.toString(width).getBytes());
100         if(dash!=null) {
101             os.write(" /D [".getBytes());
102             os.write(Double.toString(dash[0]).getBytes());
103             for(int i=1;i<dash.length;i++) {
104                 os.write(" ".getBytes());
105                 os.write(Double.toString(dash[i]).getBytes());
106             }
107             os.write("] ".getBytes());
108         }
109         os.write("]\n".getBytes());
110       
111         //writeEnd(os);
112
os.write("endobj\n".getBytes());
113     }
114 } // end class PDFBorder
115
Popular Tags