KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > write > biff > SortRecord


1 /*********************************************************************
2  *
3  * Copyright (C) 200r Andrew Khan, Al Mantei
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.write.biff;
21
22 import jxl.biff.Type;
23 import jxl.biff.StringHelper;
24 import jxl.biff.WritableRecordData;
25
26 /**
27  * Record which specifies sort dialog box values
28  */

29 class SortRecord extends WritableRecordData
30 {
31     private String JavaDoc column1Name;
32     private String JavaDoc column2Name;
33     private String JavaDoc column3Name;
34     private boolean sortColumns;
35     private boolean sortKey1Desc;
36     private boolean sortKey2Desc;
37     private boolean sortKey3Desc;
38     private boolean sortCaseSensitive;
39
40     /**
41      * Constructor
42      *
43      * @param a Sort Column 1 Name
44      * @param b Sort Column 2 Name
45      * @param c Sort Column 3 Name
46      * @param sc Sort Columns
47      * @param sk1d Sort Key 1 Descending
48      * @param sk2d Sort Key 2 Descending
49      * @param sk3d Sort Key 3 Descending
50      * @param scs Sort Case Sensitive
51      */

52     public SortRecord(String JavaDoc a, String JavaDoc b, String JavaDoc c,
53                     boolean sc, boolean sk1d,
54                     boolean sk2d, boolean sk3d, boolean scs)
55   {
56         super(Type.SORT);
57
58         column1Name = a;
59         column2Name = b;
60         column3Name = c;
61         sortColumns = sc;
62         sortKey1Desc = sk1d;
63         sortKey2Desc = sk2d;
64         sortKey3Desc = sk3d;
65         sortCaseSensitive = scs;
66     }
67     
68 /**
69      * Gets the binary data for output to file
70      *
71      * @return the binary data
72      */

73     public byte[] getData()
74   {
75         int byteCount = 5 + (column1Name.length() * 2) + 1;
76         if (column2Name.length() > 0)
77             byteCount += (column2Name.length() * 2) + 1;
78         if (column3Name.length() > 0)
79             byteCount += (column3Name.length() * 2) + 1;
80         byte[] data = new byte[byteCount + 1];
81            // there is supposed to be an extra "unused" byte at the end
82
int optionFlag = 0;
83         if (sortColumns)
84             optionFlag = optionFlag | 0x01;
85         if (sortKey1Desc)
86             optionFlag = optionFlag | 0x02;
87         if (sortKey2Desc)
88             optionFlag = optionFlag | 0x04;
89         if (sortKey3Desc)
90             optionFlag = optionFlag | 0x08;
91         if (sortCaseSensitive)
92             optionFlag = optionFlag | 0x10;
93
94         data[0] = (byte) optionFlag;
95         // data[1] is an index for sorting by a list - not implemented
96
data[2] = (byte) column1Name.length();
97         data[3] = (byte) column2Name.length();
98         data[4] = (byte) column3Name.length();
99         // always write the headings in unicode
100
data[5] = 0x01;
101         StringHelper.getUnicodeBytes(column1Name, data, 6);
102         int curPos = 6 + (column1Name.length() * 2);
103         if (column2Name.length() > 0)
104     {
105             data[curPos++] = 0x01;
106             StringHelper.getUnicodeBytes(column2Name, data, curPos);
107             curPos += column2Name.length() * 2;
108         }
109         if (column3Name.length() > 0)
110     {
111             data[curPos++] = 0x01;
112             StringHelper.getUnicodeBytes(column3Name, data, curPos);
113             curPos += column3Name.length() * 2;
114         }
115
116         return data;
117     }
118 }
119
Popular Tags