LibreOffice Module xmerge (master) 1
Format.java
Go to the documentation of this file.
1/*
2 * This file is part of the LibreOffice project.
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 */
18
19package org.openoffice.xmerge.converter.xml.sxc;
20
21import java.awt.Color;
22
26public class Format {
27
29 final public static int RIGHT_ALIGN = 0x01;
30 final public static int CENTER_ALIGN = 0x02;
31 final public static int LEFT_ALIGN = 0x03;
32
34 final public static int TOP_ALIGN = 0x01;
35 final public static int MIDDLE_ALIGN = 0x02;
36 final public static int BOTTOM_ALIGN = 0x03;
37
39 final public static int BOLD = 0x01;
41 final public static int ITALIC = 0x02;
43 final public static int UNDERLINE = 0x04;
45 final public static int STRIKETHRU = 0x08;
47 final public static int SUPERSCRIPT = 0x10;
49 final public static int SUBSCRIPT = 0x20;
50
51 final public static int LEFT_BORDER = 0x40;
52 final public static int RIGHT_BORDER = 0x80;
53 final public static int TOP_BORDER = 0x100;
54 final public static int BOTTOM_BORDER = 0x200;
55
56 final public static int WORD_WRAP = 0x400;
57
58 private int align;
59 private int vertAlign;
61 private String value;
63 private int decimalPlaces;
64
68 private int sizeInPoints;
69
71
73 private int attributes = 0;
75 private int mask = 0;
76
80 public Format() {
82 }
83
92 public Format(int attributes, int fontSize, String fontName) {
93
94 this.attributes = attributes;
95 sizeInPoints = fontSize;
96 this.fontName = fontName;
97 }
98
105 public Format(Format fmt) {
106 category = fmt.getCategory();
107 value = fmt.getValue();
110
112 mask = fmt.mask;
113
114 fontName = fmt.getFontName();
115 align = fmt.getAlign();
116 vertAlign = fmt.getVertAlign();
120 }
121
125 public void clearFormatting() {
126 category = "";
127 value = "";
128 formatSpecifier = "";
129 decimalPlaces = 0;
130 attributes = 0;
131 mask = 0;
132 sizeInPoints = 10;
135 fontName = "";
136 foreground = null;
137 background = null;
138 }
139
146 public void setAttribute(int flags, boolean toggle) {
147 mask |= flags;
148 if(toggle) {
149 attributes |= flags;
150 } else {
151 attributes &= ~flags;
152 }
153 }
154
164 public boolean getAttribute(int attribute) {
165 if ((mask & attribute) == 0)
166 return false;
167 return ((attributes & attribute) != 0);
168 }
169
180 public void setCategory(String newCategory) {
181 category = newCategory;
182 }
183
191 private String getCategory() {
192 return category;
193 }
194
200 private String getValue() {
201 return value;
202 }
203
210 public void setValue(String newValue) {
211 value = newValue;
212 }
213
219 public void setFormatSpecifier(String formatString) {
220 formatSpecifier = formatString;
221 }
222
229 return formatSpecifier;
230 }
231
237 public void setDecimalPlaces(int precision) {
239 }
240
246 private int getDecimalPlaces() {
247 return decimalPlaces;
248 }
249
255 public void setFontName(String fontName) {
256 this.fontName = fontName;
257 }
258
265 return fontName;
266 }
267
273 public void setFontSize(int fontSize) {
274 sizeInPoints = fontSize;
275 }
276
282 public int getFontSize() {
283 return sizeInPoints;
284 }
285
291 public void setVertAlign(int vertAlign) {
292 this.vertAlign = vertAlign;
293 }
294
300 public int getVertAlign() {
301 return vertAlign;
302 }
303
309 public void setAlign(int align) {
310 this.align = align;
311 }
312
318 public int getAlign() {
319 return align;
320 }
321
327 public void setForeground(Color c) {
328 if(c!=null)
329 foreground = new Color(c.getRGB());
330 }
331
338 return foreground;
339 }
340
346 public void setBackground(Color c) {
347 if(c!=null)
348 background = new Color(c.getRGB());
349 }
350
357 return background;
358 }
359
365 @Override
366 public String toString() {
367 return "Value : " + getValue() + " Category : " + getCategory();
368 }
369
375 public boolean isDefault() {
376
377 Format rhs = new Format();
378
379 if (rhs.attributes!= attributes)
380 return false;
381
382 if (foreground!=rhs.foreground)
383 return false;
384
385 if (background!=rhs.background)
386 return false;
387
388 if (rhs.align!= align)
389 return false;
390
391 return rhs.vertAlign == vertAlign;
392 }
393
402 public boolean isSubset(Format rhs) {
403 if (rhs.getClass() != this.getClass())
404 return false;
405
406 if (rhs.attributes!= attributes)
407 return false;
408
409 if (rhs.sizeInPoints != 0 && sizeInPoints != rhs.sizeInPoints)
410 return false;
411
412 if (fontName == null ? rhs.fontName != null : !fontName.equals(rhs.fontName))
413 return false;
414
415 if (foreground!=rhs.foreground)
416 return false;
417
418 if (background!=rhs.background)
419 return false;
420
421 if (rhs.align!= align)
422 return false;
423
424 return rhs.vertAlign == vertAlign;
425 }
426}
This class specifies the format for a given spreadsheet cell.
Definition: Format.java:26
int getFontSize()
Get the font size (in points) used for this cell.
Definition: Format.java:282
void setVertAlign(int vertAlign)
Set the vertical alignment used for this cell.
Definition: Format.java:291
int getVertAlign()
Get the vertical alignment used for this cell.
Definition: Format.java:300
String toString()
Get a String representation of this Format.
Definition: Format.java:366
final static int RIGHT_ALIGN
Horizontal Alignment Constants.
Definition: Format.java:29
void setAlign(int align)
Set the alignment used for this cell.
Definition: Format.java:309
int mask
Bitwise mask of text attributes.
Definition: Format.java:75
void setFontName(String fontName)
Set the font used for this cell.
Definition: Format.java:255
void setValue(String newValue)
In the case of formula the contents are set as the formula string and the value of the formula is a f...
Definition: Format.java:210
String getValue()
In the case of Formula returns the value of the formula.
Definition: Format.java:200
boolean isSubset(Format rhs)
Return true if passed Format specifies as much or less than this Format, and nothing it specifies con...
Definition: Format.java:402
final static int BOLD
Indicates bold text.
Definition: Format.java:39
Color getForeground()
Get the Foreground Color for this cell.
Definition: Format.java:337
boolean isDefault()
Tests if the current Format object has default attribute values.
Definition: Format.java:375
void setFontSize(int fontSize)
Set the font size (in points) used for this cell.
Definition: Format.java:273
void setCategory(String newCategory)
Set the formatting category of this object, ie number, date, currency.
Definition: Format.java:180
void setBackground(Color c)
Set the Background Color for this cell.
Definition: Format.java:346
String getFontName()
Get the font used for this cell.
Definition: Format.java:264
Format(Format fmt)
Constructor for creating a new Format object based on an existing one.
Definition: Format.java:105
int attributes
Values of text attributes.
Definition: Format.java:73
final static int STRIKETHRU
Indicates strike-through in the text.
Definition: Format.java:45
Format(int attributes, int fontSize, String fontName)
Constructor that creates a new Format object by setting all the format attributes.
Definition: Format.java:92
String getFormatSpecifier()
Get the Format specifier for this category.
Definition: Format.java:228
Format()
Constructor for creating a new Format.
Definition: Format.java:80
int getDecimalPlaces()
Get the number of decimal places displayed.
Definition: Format.java:246
final static int SUPERSCRIPT
Indicates superscripted text.
Definition: Format.java:47
void setAttribute(int flags, boolean toggle)
Set one or more text attributes.
Definition: Format.java:146
final static int SUBSCRIPT
Indicates subscripted text.
Definition: Format.java:49
final static int ITALIC
Indicates italic text.
Definition: Format.java:41
void clearFormatting()
Reset this Format description.
Definition: Format.java:125
String getCategory()
Return the formatting category of the object.
Definition: Format.java:191
void setFormatSpecifier(String formatString)
Set the Format specifier for this category.
Definition: Format.java:219
void setDecimalPlaces(int precision)
Set the precision of the number to be displayed.
Definition: Format.java:237
boolean getAttribute(int attribute)
Return true if the attribute is set to on.
Definition: Format.java:164
final static int TOP_ALIGN
Vertical Alignment Constants.
Definition: Format.java:34
int getAlign()
Get the alignment used for this cell.
Definition: Format.java:318
final static int UNDERLINE
Indicates underlined text.
Definition: Format.java:43
void setForeground(Color c)
Set the Foreground Color for this cell.
Definition: Format.java:327
Color getBackground()
Get the Background Color for this cell.
Definition: Format.java:356
sal_Int32 precision
sal_Int32 attribute