KickJava   Java API By Example, From Geeks To Geeks.

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


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

17
18
19 package org.apache.poi.hwpf.usermodel;
20
21 import org.apache.poi.hwpf.model.PAPX;
22 import org.apache.poi.hwpf.sprm.SprmBuffer;
23 import org.apache.poi.hwpf.sprm.TableSprmCompressor;
24
25 public class Paragraph
26   extends Range
27     implements Cloneable JavaDoc
28 {
29   public final static short SPRM_JC = 0x2403;
30   public final static short SPRM_FSIDEBYSIDE = 0x2404;
31   public final static short SPRM_FKEEP = 0x2405;
32   public final static short SPRM_FKEEPFOLLOW = 0x2406;
33   public final static short SPRM_FPAGEBREAKBEFORE = 0x2407;
34   public final static short SPRM_BRCL = 0x2408;
35   public final static short SPRM_BRCP = 0x2409;
36   public final static short SPRM_ILVL = 0x260A;
37   public final static short SPRM_ILFO = 0x460B;
38   public final static short SPRM_FNOLINENUMB = 0x240C;
39   public final static short SPRM_CHGTABSPAPX = (short)0xC60D;
40   public final static short SPRM_DXARIGHT = (short)0x840E;
41   public final static short SPRM_DXALEFT = (short)0x840F;
42   public final static short SPRM_DXALEFT1 = (short)0x8411;
43   public final static short SPRM_DYALINE = 0x6412;
44   public final static short SPRM_DYABEFORE = (short)0xA413;
45   public final static short SPRM_DYAAFTER = (short)0xA414;
46   public final static short SPRM_CHGTABS = (short)0xC615;
47   public final static short SPRM_FINTABLE = 0x2416;
48   public final static short SPRM_FTTP = 0x2417;
49   public final static short SPRM_DXAABS = (short)0x8418;
50   public final static short SPRM_DYAABS = (short)0x8419;
51   public final static short SPRM_DXAWIDTH = (short)0x841A;
52   public final static short SPRM_PC = 0x261B;
53   public final static short SPRM_WR = 0x2423;
54   public final static short SPRM_BRCTOP = 0x6424;
55   public final static short SPRM_BRCLEFT = 0x6425;
56   public final static short SPRM_BRCBOTTOM = 0x6426;
57   public final static short SPRM_BRCRIGHT = 0x6427;
58   public final static short SPRM_BRCBAR = 0x6629;
59   public final static short SPRM_FNOAUTOHYPH = 0x242A;
60   public final static short SPRM_WHEIGHTABS = 0x442B;
61   public final static short SPRM_DCS = 0x442C;
62   public final static short SPRM_SHD = 0x442D;
63   public final static short SPRM_DYAFROMTEXT = (short)0x842E;
64   public final static short SPRM_DXAFROMTEXT = (short)0x842F;
65   public final static short SPRM_FLOCKED = 0x2430;
66   public final static short SPRM_FWIDOWCONTROL = 0x2431;
67   public final static short SPRM_RULER = (short)0xC632;
68   public final static short SPRM_FKINSOKU = 0x2433;
69   public final static short SPRM_FWORDWRAP = 0x2434;
70   public final static short SPRM_FOVERFLOWPUNCT = 0x2435;
71   public final static short SPRM_FTOPLINEPUNCT = 0x2436;
72   public final static short SPRM_AUTOSPACEDE = 0x2437;
73   public final static short SPRM_AUTOSPACEDN = 0x2438;
74   public final static short SPRM_WALIGNFONT = 0x4439;
75   public final static short SPRM_FRAMETEXTFLOW = 0x443A;
76   public final static short SPRM_ANLD = (short)0xC63E;
77   public final static short SPRM_PROPRMARK = (short)0xC63F;
78   public final static short SPRM_OUTLVL = 0x2640;
79   public final static short SPRM_FBIDI = 0x2441;
80   public final static short SPRM_FNUMRMLNS = 0x2443;
81   public final static short SPRM_CRLF = 0x2444;
82   public final static short SPRM_NUMRM = (short)0xC645;
83   public final static short SPRM_USEPGSUSETTINGS = 0x2447;
84   public final static short SPRM_FADJUSTRIGHT = 0x2448;
85
86
87   protected short _istd;
88   protected ParagraphProperties _props;
89   protected SprmBuffer _papx;
90
91   protected Paragraph(int startIdx, int endIdx, Table parent)
92   {
93     super(startIdx, endIdx, Range.TYPE_PARAGRAPH, parent);
94     PAPX papx = (PAPX)_paragraphs.get(_parEnd - 1);
95     _props = papx.getParagraphProperties(_doc.getStyleSheet());
96     _papx = papx.getSprmBuf();
97     _istd = papx.getIstd();
98   }
99
100   protected Paragraph(PAPX papx, Range parent)
101   {
102     super(Math.max(parent._start, papx.getStart()), Math.min(parent._end, papx.getEnd()), parent);
103     _props = papx.getParagraphProperties(_doc.getStyleSheet());
104     _papx = papx.getSprmBuf();
105     _istd = papx.getIstd();
106   }
107
108   public short getStyleIndex()
109   {
110     return _istd;
111   }
112
113   public int type()
114   {
115     return TYPE_PARAGRAPH;
116   }
117
118   public boolean isInTable()
119   {
120     return _props.getFInTable() != 0;
121   }
122
123   public boolean isTableRowEnd()
124   {
125     return _props.getFTtp() != 0 || _props.getFTtpEmbedded() != 0;
126   }
127
128   public int getTableLevel()
129   {
130     return _props.getTableLevel();
131   }
132
133   public boolean isEmbeddedCellMark()
134   {
135     return _props.getEmbeddedCellMark() != 0;
136   }
137
138   public int getJustification()
139   {
140     return _props.getJc();
141   }
142
143   public void setJustification(byte jc)
144   {
145     _props.setJc(jc);
146     _papx.updateSprm(SPRM_JC, jc);
147   }
148
149   public boolean keepOnPage()
150   {
151     return _props.getFKeep() != 0;
152   }
153
154   public void setKeepOnPage(boolean fKeep)
155   {
156     byte keep = (byte)(fKeep ? 1 : 0);
157     _props.setFKeep(keep);
158     _papx.updateSprm(SPRM_FKEEP, keep);
159   }
160
161   public boolean keepWithNext()
162   {
163     return _props.getFKeepFollow() != 0;
164   }
165
166   public void setKeepWithNext(boolean fKeepFollow)
167   {
168     byte keepFollow = (byte)(fKeepFollow ? 1 : 0);
169     _props.setFKeepFollow(keepFollow);
170     _papx.updateSprm(SPRM_FKEEPFOLLOW, keepFollow);
171   }
172
173   public boolean pageBreakBefore()
174   {
175     return _props.getFPageBreakBefore() != 0;
176   }
177
178   public void setPageBreakBefore(boolean fPageBreak)
179   {
180     byte pageBreak = (byte)(fPageBreak ? 1 : 0);
181     _props.setFPageBreakBefore(pageBreak);
182     _papx.updateSprm(SPRM_FPAGEBREAKBEFORE, pageBreak);
183   }
184
185   public boolean isLineNotNumbered()
186   {
187     return _props.getFNoLnn() != 0;
188   }
189
190   public void setLineNotNumbered(boolean fNoLnn)
191   {
192     byte noLnn = (byte)(fNoLnn ? 1 : 0);
193     _props.setFNoLnn(noLnn);
194     _papx.updateSprm(SPRM_FNOLINENUMB, noLnn);
195   }
196
197   public boolean isSideBySide()
198   {
199     return _props.getFSideBySide() != 0;
200   }
201
202   public void setSideBySide(boolean fSideBySide)
203   {
204     byte sideBySide = (byte)(fSideBySide ? 1 : 0);
205     _props.setFSideBySide(sideBySide);
206     _papx.updateSprm(SPRM_FSIDEBYSIDE, sideBySide);
207   }
208
209   public boolean isAutoHyphenated()
210   {
211     return _props.getFNoAutoHyph() == 0;
212   }
213
214   public void setAutoHyphenated(boolean autoHyph)
215   {
216     byte auto = (byte)(!autoHyph ? 1 : 0);
217     _props.setFNoAutoHyph(auto);
218     _papx.updateSprm(SPRM_FNOAUTOHYPH, auto);
219   }
220
221   public boolean isWidowControlled()
222   {
223     return _props.getFWidowControl() != 0;
224   }
225
226   public void setWidowControl(boolean widowControl)
227   {
228     byte widow = (byte)(widowControl ? 1 : 0);
229     _props.setFWidowControl(widow);
230     _papx.updateSprm(SPRM_FWIDOWCONTROL, widow);
231   }
232
233   public int getIndentFromRight()
234   {
235     return _props.getDxaRight();
236   }
237
238   public void setIndentFromRight(int dxaRight)
239   {
240     _props.setDxaRight(dxaRight);
241     _papx.updateSprm(SPRM_DXARIGHT, (short)dxaRight);
242   }
243
244   public int getIndentFromLeft()
245   {
246     return _props.getDxaLeft();
247   }
248
249   public void setIndentFromLeft(int dxaLeft)
250   {
251     _props.setDxaLeft(dxaLeft);
252     _papx.updateSprm(SPRM_DXALEFT, (short)dxaLeft);
253   }
254
255   public int getFirstLineIndent()
256   {
257     return _props.getDxaLeft1();
258   }
259
260   public void setFirstLineIndent(int first)
261   {
262     _props.setDxaLeft1(first);
263     _papx.updateSprm(SPRM_DXALEFT1, (short)first);
264   }
265
266   public LineSpacingDescriptor getLineSpacing()
267   {
268     return _props.getLspd();
269   }
270
271   public void setLineSpacing(LineSpacingDescriptor lspd)
272   {
273     _props.setLspd(lspd);
274     _papx.updateSprm(SPRM_DYALINE, lspd.toInt());
275   }
276
277   public int getSpacingBefore()
278   {
279     return _props.getDyaBefore();
280   }
281
282   public void setSpacingBefore(int before)
283   {
284     _props.setDyaBefore(before);
285     _papx.updateSprm(SPRM_DYABEFORE, (short)before);
286   }
287
288   public int getSpacingAfter()
289   {
290     return _props.getDyaAfter();
291   }
292
293   public void setSpacingAfter(int after)
294   {
295     _props.setDyaAfter(after);
296     _papx.updateSprm(SPRM_DYAAFTER, (short)after);
297   }
298
299   public boolean isKinsoku()
300   {
301     return _props.getFKinsoku() != 0;
302   }
303
304   public void setKinsoku(boolean kinsoku)
305   {
306     byte kin = (byte)(kinsoku ? 1 : 0);
307     _props.setFKinsoku(kin);
308     _papx.updateSprm(SPRM_FKINSOKU, kin);
309   }
310
311   public boolean isWordWrapped()
312   {
313     return _props.getFWordWrap() != 0;
314   }
315
316   public void setWordWrapped(boolean wrap)
317   {
318     byte wordWrap = (byte)(wrap ? 1 : 0);
319     _props.setFWordWrap(wordWrap);
320     _papx.updateSprm(SPRM_FWORDWRAP, wordWrap);
321   }
322
323   public int getFontAlignment()
324   {
325     return _props.getWAlignFont();
326   }
327
328   public void setFontAlignment(int align)
329   {
330     _props.setWAlignFont(align);
331     _papx.updateSprm(SPRM_WALIGNFONT, (short)align);
332   }
333
334   public boolean isVertical()
335   {
336     return _props.isFVertical();
337   }
338
339   public void setVertical(boolean vertical)
340   {
341     _props.setFVertical(vertical);
342     _papx.updateSprm(SPRM_FRAMETEXTFLOW, getFrameTextFlow());
343   }
344
345   public boolean isBackward()
346   {
347     return _props.isFBackward();
348   }
349
350   public void setBackward(boolean bward)
351   {
352     _props.setFBackward(bward);
353     _papx.updateSprm(SPRM_FRAMETEXTFLOW, getFrameTextFlow());
354   }
355
356   public BorderCode getTopBorder()
357   {
358     return _props.getBrcTop();
359   }
360
361   public void setTopBorder(BorderCode top)
362   {
363     _props.setBrcTop(top);
364     _papx.updateSprm(SPRM_BRCTOP, top.toInt());
365   }
366
367   public BorderCode getLeftBorder()
368   {
369     return _props.getBrcLeft();
370   }
371
372   public void setLeftBorder(BorderCode left)
373   {
374     _props.setBrcLeft(left);
375     _papx.updateSprm(SPRM_BRCLEFT, left.toInt());
376   }
377
378   public BorderCode getBottomBorder()
379   {
380     return _props.getBrcBottom();
381   }
382
383   public void setBottomBorder(BorderCode bottom)
384   {
385     _props.setBrcBottom(bottom);
386     _papx.updateSprm(SPRM_BRCBOTTOM, bottom.toInt());
387   }
388
389   public BorderCode getRightBorder()
390   {
391     return _props.getBrcRight();
392   }
393
394   public void setRightBorder(BorderCode right)
395   {
396     _props.setBrcRight(right);
397     _papx.updateSprm(SPRM_BRCRIGHT, right.toInt());
398   }
399
400   public BorderCode getBarBorder()
401   {
402     return _props.getBrcBar();
403   }
404
405   public void setBarBorder(BorderCode bar)
406   {
407     _props.setBrcBar(bar);
408     _papx.updateSprm(SPRM_BRCBAR, bar.toInt());
409   }
410
411   public ShadingDescriptor getShading()
412   {
413     return _props.getShd();
414   }
415
416   public void setShading(ShadingDescriptor shd)
417   {
418     _props.setShd(shd);
419     _papx.updateSprm(SPRM_SHD, shd.toShort());
420   }
421
422   public DropCapSpecifier getDropCap()
423   {
424     return _props.getDcs();
425   }
426
427   public void setDropCap(DropCapSpecifier dcs)
428   {
429     _props.setDcs(dcs);
430     _papx.updateSprm(SPRM_DCS, dcs.toShort());
431   }
432
433   public int getIlfo()
434    {
435      return _props.getIlfo();
436    }
437
438    public int getIlvl()
439    {
440      return _props.getIlvl();
441    }
442
443   void setTableRowEnd(TableProperties props)
444   {
445     setTableRowEnd((byte)1);
446     byte[] grpprl = TableSprmCompressor.compressTableProperty(props);
447     _papx.append(grpprl);
448   }
449
450   private void setTableRowEnd(byte val)
451   {
452     _props.setFTtp(val);
453     _papx.updateSprm(SPRM_FTTP, val);
454   }
455
456   public Object JavaDoc clone()
457     throws CloneNotSupportedException JavaDoc
458   {
459     Paragraph p = (Paragraph)super.clone();
460     p._props = (ParagraphProperties)_props.clone();
461     //p._baseStyle = _baseStyle;
462
p._papx = new SprmBuffer();
463     return p;
464   }
465
466   private short getFrameTextFlow()
467   {
468     short retVal = 0;
469     if (_props.isFVertical())
470     {
471       retVal |= 1;
472     }
473     if (_props.isFBackward())
474     {
475       retVal |= 2;
476     }
477     if (_props.isFRotateFont())
478     {
479       retVal |= 4;
480     }
481     return retVal;
482   }
483
484 }
485
Popular Tags