KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > biff > drawing > ClientAnchor


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

19
20 package jxl.biff.drawing;
21
22 import jxl.biff.IntegerHelper;
23
24 class ClientAnchor extends EscherAtom
25 {
26   private byte[] data;
27
28   private double x1;
29   private double y1;
30   private double x2;
31   private double y2;
32
33   public ClientAnchor(EscherRecordData erd)
34   {
35     super(erd);
36     byte[] bytes = getBytes();
37
38     // The x1 cell
39
int x1Cell = IntegerHelper.getInt(bytes[2], bytes[3]);
40     int x1Fraction = IntegerHelper.getInt(bytes[4], bytes[5]);
41
42     x1 = x1Cell + (double) x1Fraction / (double) 1024;
43     
44     // The y1 cell
45
int y1Cell = IntegerHelper.getInt(bytes[6], bytes[7]);
46     int y1Fraction = IntegerHelper.getInt(bytes[8], bytes[9]);
47
48     y1 = y1Cell + (double) y1Fraction / (double) 256;
49
50     // The x2 cell
51
int x2Cell = IntegerHelper.getInt(bytes[10], bytes[11]);
52     int x2Fraction = IntegerHelper.getInt(bytes[12], bytes[13]);
53
54     x2 = x2Cell + (double) x2Fraction / (double) 1024;
55     
56     // The y1 cell
57
int y2Cell = IntegerHelper.getInt(bytes[14], bytes[15]);
58     int y2Fraction = IntegerHelper.getInt(bytes[16], bytes[17]);
59
60     y2 = y2Cell + (double) y2Fraction / (double) 256;
61   }
62
63   public ClientAnchor(double x1, double y1, double x2, double y2)
64   {
65     super(EscherRecordType.CLIENT_ANCHOR);
66     this.x1 = x1;
67     this.y1 = y1;
68     this.x2 = x2;
69     this.y2 = y2;
70   }
71
72   byte[] getData()
73   {
74     data = new byte[18];
75     IntegerHelper.getTwoBytes(0x2, data, 0);
76
77     // The x1 cell
78
IntegerHelper.getTwoBytes((int) x1, data, 2);
79
80     // The x1 fraction into the cell 0-1024
81
int x1fraction = (int) ((x1 - (int) x1) * 1024);
82     IntegerHelper.getTwoBytes(x1fraction, data, 4);
83     
84     // The y1 cell
85
IntegerHelper.getTwoBytes((int) y1, data, 6);
86
87     // The y1 fraction into the cell 0-256
88
int y1fraction = (int) ((y1 - (int) y1) * 256);
89     IntegerHelper.getTwoBytes(y1fraction, data, 8);
90
91     // The x2 cell
92
IntegerHelper.getTwoBytes((int) x2, data, 10);
93
94     // The x2 fraction into the cell 0-1024
95
int x2fraction = (int) ((x2 - (int) x2) * 1024);
96     IntegerHelper.getTwoBytes(x2fraction, data, 12);
97     
98     // The y2 cell
99
IntegerHelper.getTwoBytes((int) y2, data, 14);
100
101     // The y2 fraction into the cell 0-256
102
int y2fraction = (int) ((y2 - (int) y2) * 256);
103     IntegerHelper.getTwoBytes(y2fraction, data, 16);
104
105     return setHeaderData(data);
106   }
107
108   double getX1()
109   {
110     return x1;
111   }
112
113   double getY1()
114   {
115     return y1;
116   }
117
118   double getX2()
119   {
120     return x2;
121   }
122
123   double getY2()
124   {
125     return y2;
126   }
127 }
128
Popular Tags