001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hwpf.usermodel;
019:
020: import org.apache.poi.hwpf.HWPFDocument;
021: import org.apache.poi.hwpf.model.ListTables;
022: import org.apache.poi.hwpf.model.ListLevel;
023: import org.apache.poi.hwpf.model.ListData;
024: import org.apache.poi.hwpf.model.ListFormatOverride;
025: import org.apache.poi.hwpf.model.StyleSheet;
026:
027: import org.apache.poi.hwpf.sprm.CharacterSprmCompressor;
028: import org.apache.poi.hwpf.sprm.ParagraphSprmCompressor;
029:
030: /**
031: * This class is used to create a list in a Word document. It is used in
032: * conjunction with {@link
033: * org.apache.poi.hwpf.HWPFDocument#registerList(HWPFList) registerList} in
034: * {@link org.apache.poi.hwpf.HWPFDocument HWPFDocument}.
035: *
036: * In Word, lists are not ranged entities, meaning you can't actually add one
037: * to the document. Lists only act as properties for list entries. Once you
038: * register a list, you can add list entries to a document that are a part of
039: * the list.
040: *
041: * The only benefit of this that I see, is that you can add a list entry
042: * anywhere in the document and continue numbering from the previous list.
043: *
044: * @author Ryan Ackley
045: */
046: public class HWPFList {
047: private ListData _listData;
048: private ListFormatOverride _override;
049: private boolean _registered;
050: private StyleSheet _styleSheet;
051:
052: /**
053: *
054: * @param numbered true if the list should be numbered; false if it should be
055: * bulleted.
056: * @param styleSheet The document's stylesheet.
057: */
058: public HWPFList(boolean numbered, StyleSheet styleSheet) {
059: _listData = new ListData((int) (Math.random() * (double) System
060: .currentTimeMillis()), numbered);
061: _override = new ListFormatOverride(_listData.getLsid());
062: _styleSheet = styleSheet;
063: }
064:
065: /**
066: * Sets the character properties of the list numbers.
067: *
068: * @param level the level number that the properties should apply to.
069: * @param chp The character properties.
070: */
071: public void setLevelNumberProperties(int level,
072: CharacterProperties chp) {
073: ListLevel listLevel = _listData.getLevel(level);
074: int styleIndex = _listData.getLevelStyle(level);
075: CharacterProperties base = _styleSheet
076: .getCharacterStyle(styleIndex);
077:
078: byte[] grpprl = CharacterSprmCompressor
079: .compressCharacterProperty(chp, base);
080: listLevel.setNumberProperties(grpprl);
081: }
082:
083: /**
084: * Sets the paragraph properties for a particular level of the list.
085: *
086: * @param level The level number.
087: * @param pap The paragraph properties
088: */
089: public void setLevelParagraphProperties(int level,
090: ParagraphProperties pap) {
091: ListLevel listLevel = _listData.getLevel(level);
092: int styleIndex = _listData.getLevelStyle(level);
093: ParagraphProperties base = _styleSheet
094: .getParagraphStyle(styleIndex);
095:
096: byte[] grpprl = ParagraphSprmCompressor
097: .compressParagraphProperty(pap, base);
098: listLevel.setLevelProperties(grpprl);
099: }
100:
101: public void setLevelStyle(int level, int styleIndex) {
102: _listData.setLevelStyle(level, styleIndex);
103: }
104:
105: public ListData getListData() {
106: return _listData;
107: }
108:
109: public ListFormatOverride getOverride() {
110: return _override;
111: }
112:
113: }
|