KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hwpf > usermodel > HWPFList


1 /* ====================================================================
2    Copyright 2002-2004 Apache Software Foundation
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 ==================================================================== */

16
17 package org.apache.poi.hwpf.usermodel;
18
19 import org.apache.poi.hwpf.HWPFDocument;
20 import org.apache.poi.hwpf.model.ListTables;
21 import org.apache.poi.hwpf.model.ListLevel;
22 import org.apache.poi.hwpf.model.ListData;
23 import org.apache.poi.hwpf.model.ListFormatOverride;
24 import org.apache.poi.hwpf.model.StyleSheet;
25
26 import org.apache.poi.hwpf.sprm.CharacterSprmCompressor;
27 import org.apache.poi.hwpf.sprm.ParagraphSprmCompressor;
28
29 /**
30  * This class is used to create a list in a Word document. It is used in
31  * conjunction with {@link
32  * org.apache.poi.hwpf.HWPFDocument#registerList(HWPFList) registerList} in
33  * {@link org.apache.poi.hwpf.HWPFDocument HWPFDocument}.
34  *
35  * In Word, lists are not ranged entities, meaning you can't actually add one
36  * to the document. Lists only act as properties for list entries. Once you
37  * register a list, you can add list entries to a document that are a part of
38  * the list.
39  *
40  * The only benefit of this that I see, is that you can add a list entry
41  * anywhere in the document and continue numbering from the previous list.
42  *
43  * @author Ryan Ackley
44  */

45 public class HWPFList
46 {
47   private ListData _listData;
48   private ListFormatOverride _override;
49   private boolean _registered;
50   private StyleSheet _styleSheet;
51
52   /**
53    *
54    * @param numbered true if the list should be numbered; false if it should be
55    * bulleted.
56    * @param styleSheet The document's stylesheet.
57    */

58   public HWPFList(boolean numbered, StyleSheet styleSheet)
59   {
60     _listData = new ListData((int)(Math.random() * (double)System.currentTimeMillis()), numbered);
61     _override = new ListFormatOverride(_listData.getLsid());
62     _styleSheet = styleSheet;
63   }
64
65   /**
66    * Sets the character properties of the list numbers.
67    *
68    * @param level the level number that the properties should apply to.
69    * @param chp The character properties.
70    */

71   public void setLevelNumberProperties(int level, CharacterProperties chp)
72   {
73     ListLevel listLevel = _listData.getLevel(level);
74     int styleIndex = _listData.getLevelStyle(level);
75     CharacterProperties base = _styleSheet.getCharacterStyle(styleIndex);
76
77     byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(chp, base);
78     listLevel.setNumberProperties(grpprl);
79   }
80
81   /**
82    * Sets the paragraph properties for a particular level of the list.
83    *
84    * @param level The level number.
85    * @param pap The paragraph properties
86    */

87   public void setLevelParagraphProperties(int level, ParagraphProperties pap)
88   {
89     ListLevel listLevel = _listData.getLevel(level);
90     int styleIndex = _listData.getLevelStyle(level);
91     ParagraphProperties base = _styleSheet.getParagraphStyle(styleIndex);
92
93     byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(pap, base);
94     listLevel.setLevelProperties(grpprl);
95   }
96
97   public void setLevelStyle(int level, int styleIndex)
98   {
99     _listData.setLevelStyle(level, styleIndex);
100   }
101
102   public ListData getListData()
103   {
104     return _listData;
105   }
106
107   public ListFormatOverride getOverride()
108   {
109     return _override;
110   }
111
112 }
113
Popular Tags