KickJava   Java API By Example, From Geeks To Geeks.

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


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
18
19 package org.apache.poi.hwpf.usermodel;
20
21 import org.apache.poi.hwpf.model.CHPX;
22 import org.apache.poi.hwpf.model.StyleSheet;
23 import org.apache.poi.hwpf.sprm.SprmBuffer;
24
25 /**
26  * This class represents a run of text that share common properties.
27  *
28  * @author Ryan Ackley
29  */

30 public class CharacterRun
31   extends Range
32   implements Cloneable JavaDoc
33 {
34   public final static short SPRM_FRMARKDEL = (short)0x0800;
35   public final static short SPRM_FRMARK = 0x0801;
36   public final static short SPRM_FFLDVANISH = 0x0802;
37   public final static short SPRM_PICLOCATION = 0x6A03;
38   public final static short SPRM_IBSTRMARK = 0x4804;
39   public final static short SPRM_DTTMRMARK = 0x6805;
40   public final static short SPRM_FDATA = 0x0806;
41   public final static short SPRM_SYMBOL = 0x6A09;
42   public final static short SPRM_FOLE2 = 0x080A;
43   public final static short SPRM_HIGHLIGHT = 0x2A0C;
44   public final static short SPRM_OBJLOCATION = 0x680E;
45   public final static short SPRM_ISTD = 0x4A30;
46   public final static short SPRM_FBOLD = 0x0835;
47   public final static short SPRM_FITALIC = 0x0836;
48   public final static short SPRM_FSTRIKE = 0x0837;
49   public final static short SPRM_FOUTLINE = 0x0838;
50   public final static short SPRM_FSHADOW = 0x0839;
51   public final static short SPRM_FSMALLCAPS = 0x083A;
52   public final static short SPRM_FCAPS = 0x083B;
53   public final static short SPRM_FVANISH = 0x083C;
54   public final static short SPRM_KUL = 0x2A3E;
55   public final static short SPRM_DXASPACE = (short)0x8840;
56   public final static short SPRM_LID = 0x4A41;
57   public final static short SPRM_ICO = 0x2A42;
58   public final static short SPRM_HPS = 0x4A43;
59   public final static short SPRM_HPSPOS = 0x4845;
60   public final static short SPRM_ISS = 0x2A48;
61   public final static short SPRM_HPSKERN = 0x484B;
62   public final static short SPRM_YSRI = 0x484E;
63   public final static short SPRM_RGFTCASCII = 0x4A4F;
64   public final static short SPRM_RGFTCFAREAST = 0x4A50;
65   public final static short SPRM_RGFTCNOTFAREAST = 0x4A51;
66   public final static short SPRM_CHARSCALE = 0x4852;
67   public final static short SPRM_FDSTRIKE = 0x2A53;
68   public final static short SPRM_FIMPRINT = 0x0854;
69   public final static short SPRM_FSPEC = 0x0855;
70   public final static short SPRM_FOBJ = 0x0856;
71   public final static short SPRM_PROPRMARK = (short)0xCA57;
72   public final static short SPRM_FEMBOSS = 0x0858;
73   public final static short SPRM_SFXTEXT = 0x2859;
74   public final static short SPRM_DISPFLDRMARK = (short)0xCA62;
75   public final static short SPRM_IBSTRMARKDEL = 0x4863;
76   public final static short SPRM_DTTMRMARKDEL = 0x6864;
77   public final static short SPRM_BRC = 0x6865;
78   public final static short SPRM_SHD = 0x4866;
79   public final static short SPRM_IDSIRMARKDEL = 0x4867;
80   public final static short SPRM_CPG = 0x486B;
81   public final static short SPRM_NONFELID = 0x486D;
82   public final static short SPRM_FELID = 0x486E;
83   public final static short SPRM_IDCTHINT = 0x286F;
84
85   SprmBuffer _chpx;
86   CharacterProperties _props;
87
88   /**
89    *
90    * @param chpx The chpx this object is based on.
91    * @param ss The stylesheet for the document this run belongs to.
92    * @param istd The style index if this run's base style.
93    * @param parent The parent range of this character run (usually a paragraph).
94    */

95   CharacterRun(CHPX chpx, StyleSheet ss, short istd, Range parent)
96   {
97     super(Math.max(parent._start, chpx.getStart()), Math.min(parent._end, chpx.getEnd()), parent);
98     _props = chpx.getCharacterProperties(ss, istd);
99     _chpx = chpx.getSprmBuf();
100   }
101
102   /**
103    * Here for runtime type determination using a switch statement convenient.
104    *
105    * @return TYPE_CHARACTER
106    */

107   public int type()
108   {
109     return TYPE_CHARACTER;
110   }
111
112   public boolean isMarkedDeleted()
113   {
114     return _props.isFRMarkDel();
115   }
116
117   public void markDeleted(boolean mark)
118   {
119     _props.setFRMarkDel(mark);
120
121     byte newVal = (byte)(mark ? 1 : 0);
122     _chpx.updateSprm(SPRM_FRMARKDEL, newVal);
123
124   }
125
126   public boolean isBold()
127   {
128     return _props.isFBold();
129   }
130
131   public void setBold(boolean bold)
132   {
133     _props.setFBold(bold);
134
135     byte newVal = (byte)(bold ? 1 : 0);
136     _chpx.updateSprm(SPRM_FBOLD, newVal);
137
138   }
139
140   public boolean isItalic()
141   {
142     return _props.isFItalic();
143   }
144
145   public void setItalic(boolean italic)
146   {
147     _props.setFItalic(italic);
148
149     byte newVal = (byte)(italic ? 1 : 0);
150     _chpx.updateSprm(SPRM_FITALIC, newVal);
151
152   }
153
154   public boolean isOutlined()
155   {
156     return _props.isFOutline();
157   }
158
159   public void setOutline(boolean outlined)
160   {
161     _props.setFOutline(outlined);
162
163     byte newVal = (byte)(outlined ? 1 : 0);
164     _chpx.updateSprm(SPRM_FOUTLINE, newVal);
165
166   }
167
168   public boolean isFldVanished()
169   {
170     return _props.isFFldVanish();
171   }
172
173   public void setFldVanish(boolean fldVanish)
174   {
175     _props.setFFldVanish(fldVanish);
176
177     byte newVal = (byte)(fldVanish ? 1 : 0);
178     _chpx.updateSprm(SPRM_FFLDVANISH, newVal);
179
180   }
181
182   public boolean isSmallCaps()
183   {
184     return _props.isFSmallCaps();
185   }
186
187   public void setSmallCaps(boolean smallCaps)
188   {
189     _props.setFSmallCaps(smallCaps);
190
191     byte newVal = (byte)(smallCaps ? 1 : 0);
192     _chpx.updateSprm(SPRM_FSMALLCAPS, newVal);
193
194   }
195
196   public boolean isCapitalized()
197   {
198     return _props.isFCaps();
199   }
200
201   public void setCapitalized(boolean caps)
202   {
203     _props.setFCaps(caps);
204
205     byte newVal = (byte)(caps ? 1 : 0);
206     _chpx.updateSprm(SPRM_FCAPS, newVal);
207
208   }
209
210   public boolean isVanished()
211   {
212     return _props.isFVanish();
213   }
214
215   public void setVanished(boolean vanish)
216   {
217     _props.setFVanish(vanish);
218
219     byte newVal = (byte)(vanish ? 1 : 0);
220     _chpx.updateSprm(SPRM_FVANISH, newVal);
221
222   }
223
224   public boolean isMarkedInserted()
225   {
226     return _props.isFRMark();
227   }
228
229   public void markInserted(boolean mark)
230   {
231     _props.setFRMark(mark);
232
233     byte newVal = (byte)(mark ? 1 : 0);
234     _chpx.updateSprm(SPRM_FRMARK, newVal);
235
236   }
237
238   public boolean isStrikeThrough()
239   {
240     return _props.isFStrike();
241   }
242
243   public void strikeThrough(boolean strike)
244   {
245     _props.setFStrike(strike);
246
247     byte newVal = (byte)(strike ? 1 : 0);
248     _chpx.updateSprm(SPRM_FSTRIKE, newVal);
249
250   }
251
252   public boolean isShadowed()
253   {
254     return _props.isFShadow();
255   }
256
257   public void setShadow(boolean shadow)
258   {
259     _props.setFShadow(shadow);
260
261     byte newVal = (byte)(shadow ? 1 : 0);
262     _chpx.updateSprm(SPRM_FSHADOW, newVal);
263
264   }
265
266   public boolean isEmbossed()
267   {
268     return _props.isFEmboss();
269   }
270
271   public void setEmbossed(boolean emboss)
272   {
273     _props.setFEmboss(emboss);
274
275     byte newVal = (byte)(emboss ? 1 : 0);
276     _chpx.updateSprm(SPRM_FEMBOSS, newVal);
277
278   }
279
280   public boolean isImprinted()
281   {
282     return _props.isFImprint();
283   }
284
285   public void setImprinted(boolean imprint)
286   {
287     _props.setFImprint(imprint);
288
289     byte newVal = (byte)(imprint ? 1 : 0);
290     _chpx.updateSprm(SPRM_FIMPRINT, newVal);
291
292   }
293
294   public boolean isDoubleStrikeThrough()
295   {
296     return _props.isFDStrike();
297   }
298
299   public void setDoubleStrikethrough(boolean dstrike)
300   {
301     _props.setFDStrike(dstrike);
302
303     byte newVal = (byte)(dstrike ? 1 : 0);
304     _chpx.updateSprm(SPRM_FDSTRIKE, newVal);
305
306   }
307
308   public void setFtcAscii(int ftcAscii)
309   {
310     _props.setFtcAscii(ftcAscii);
311
312     _chpx.updateSprm(SPRM_RGFTCASCII, (short)ftcAscii);
313
314   }
315
316   public void setFtcFE(int ftcFE)
317   {
318     _props.setFtcFE(ftcFE);
319
320     _chpx.updateSprm(SPRM_RGFTCFAREAST, (short)ftcFE);
321
322   }
323
324   public void setFtcOther(int ftcOther)
325   {
326     _props.setFtcOther(ftcOther);
327
328     _chpx.updateSprm(SPRM_RGFTCNOTFAREAST, (short)ftcOther);
329
330   }
331
332   public int getFontSize()
333   {
334     return _props.getHps();
335   }
336
337   public void setFontSize(int halfPoints)
338   {
339     _props.setHps(halfPoints);
340
341     _chpx.updateSprm(SPRM_HPS, (short)halfPoints);
342
343   }
344
345   public int getCharacterSpacing()
346   {
347     return _props.getDxaSpace();
348   }
349
350   public void setCharacterSpacing(int twips)
351   {
352     _props.setDxaSpace(twips);
353
354     _chpx.updateSprm(SPRM_DXASPACE, twips);
355
356   }
357
358   public short getSubSuperScriptIndex()
359   {
360     return _props.getIss();
361   }
362
363   public void setSubSuperScriptIndex(short iss)
364   {
365     _props.setDxaSpace(iss);
366
367     _chpx.updateSprm(SPRM_DXASPACE, iss);
368
369   }
370
371   public int getUnderlineCode()
372   {
373     return _props.getKul();
374   }
375
376   public void setUnderlineCode(int kul)
377   {
378     _props.setKul((byte)kul);
379     _chpx.updateSprm(SPRM_KUL, (byte)kul);
380   }
381
382   public int getColor()
383   {
384     return _props.getIco();
385   }
386
387   public void setColor(int color)
388   {
389     _props.setIco((byte)color);
390     _chpx.updateSprm(SPRM_ICO, (byte)color);
391   }
392
393   public int getVerticalOffset()
394   {
395     return _props.getHpsPos();
396   }
397
398   public void setVerticalOffset(int hpsPos)
399   {
400     _props.setHpsPos(hpsPos);
401     _chpx.updateSprm(SPRM_HPSPOS, (byte)hpsPos);
402   }
403
404   public int getKerning()
405   {
406     return _props.getHpsKern();
407   }
408
409   public void setKerning(int kern)
410   {
411     _props.setHpsKern(kern);
412     _chpx.updateSprm(SPRM_HPSKERN, (short)kern);
413   }
414
415   public boolean isHighlighted()
416   {
417     return _props.isFHighlight();
418   }
419
420   public void setHighlighted(byte color)
421   {
422     _props.setFHighlight(true);
423     _props.setIcoHighlight(color);
424     _chpx.updateSprm(SPRM_HIGHLIGHT, color);
425   }
426
427   public String JavaDoc getFontName()
428   {
429     return _doc.getFontTable().getMainFont(_props.getFtcAscii());
430   }
431
432   public boolean isSpecialCharacter()
433   {
434     return _props.isFSpec();
435   }
436
437   public void setSpecialCharacter(boolean spec)
438   {
439     _props.setFSpec(spec);
440
441     byte newVal = (byte)(spec ? 1 : 0);
442     _chpx.updateSprm(SPRM_FSPEC, newVal);
443   }
444
445   public boolean isObj()
446   {
447     return _props.isFObj();
448   }
449
450   public void setObj(boolean obj)
451   {
452     _props.setFObj(obj);
453
454     byte newVal = (byte)(obj ? 1 : 0);
455     _chpx.updateSprm(SPRM_FOBJ, newVal);
456   }
457
458   public int getPicOffset()
459   {
460     return _props.getFcPic();
461   }
462
463   public void setPicOffset(int offset)
464   {
465     _props.setFcPic(offset);
466     _chpx.updateSprm(SPRM_PICLOCATION, offset);
467   }
468
469
470   public boolean isData()
471   {
472     return _props.isFData();
473   }
474
475   public void setData(boolean data)
476   {
477     _props.setFData(data);
478
479     byte newVal = (byte)(data ? 1 : 0);
480     _chpx.updateSprm(SPRM_FOBJ, newVal);
481   }
482
483   public boolean isOle2()
484   {
485     return _props.isFOle2();
486   }
487
488   public void setOle2(boolean ole)
489   {
490     _props.setFOle2(ole);
491
492     byte newVal = (byte)(ole ? 1 : 0);
493     _chpx.updateSprm(SPRM_FOBJ, newVal);
494   }
495
496   public int getObjOffset()
497   {
498     return _props.getFcObj();
499   }
500
501   public void setObjOffset(int obj)
502   {
503     _props.setFcObj(obj);
504     _chpx.updateSprm(SPRM_OBJLOCATION, obj);
505   }
506
507   /**
508   * Get the ico24 field for the CHP record.
509   */

510   public int getIco24()
511   {
512     return _props.getIco24();
513   }
514
515   /**
516    * Set the ico24 field for the CHP record.
517    */

518   public void setIco24(int colour24)
519   {
520     _props.setIco24(colour24);
521   }
522
523   /**
524    * Used to create a deep copy of this object.
525    *
526    * @return A deep copy.
527    * @throws CloneNotSupportedException never
528    */

529   public Object JavaDoc clone()
530     throws CloneNotSupportedException JavaDoc
531   {
532     CharacterRun cp = (CharacterRun)super.clone();
533     cp._props.setDttmRMark((DateAndTime)_props.getDttmRMark().clone());
534     cp._props.setDttmRMarkDel((DateAndTime)_props.getDttmRMarkDel().clone());
535     cp._props.setDttmPropRMark((DateAndTime)_props.getDttmPropRMark().clone());
536     cp._props.setDttmDispFldRMark((DateAndTime)_props.getDttmDispFldRMark().
537                                   clone());
538     cp._props.setXstDispFldRMark((byte[])_props.getXstDispFldRMark().clone());
539     cp._props.setShd((ShadingDescriptor)_props.getShd().clone());
540
541     return cp;
542   }
543
544 }
545
Popular Tags