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 
19 package org.openoffice.xmerge.converter.xml.sxc;
20 
21 import java.awt.Color;
22 
26 public 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;
60  private String category;
61  private String value;
63  private int decimalPlaces;
64 
66  private String fontName;
68  private int sizeInPoints;
69 
70  private Color foreground, background;
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();
108  formatSpecifier = fmt.getFormatSpecifier();
109  decimalPlaces = fmt.getDecimalPlaces();
110 
111  attributes = fmt.attributes;
112  mask = fmt.mask;
113 
114  fontName = fmt.getFontName();
115  align = fmt.getAlign();
116  vertAlign = fmt.getVertAlign();
117  foreground = fmt.getForeground();
118  background = fmt.getBackground();
119  sizeInPoints = fmt.sizeInPoints;
120  }
121 
125  public void clearFormatting() {
126  category = "";
127  value = "";
128  formatSpecifier = "";
129  decimalPlaces = 0;
130  attributes = 0;
131  mask = 0;
132  sizeInPoints = 10;
133  align = LEFT_ALIGN;
134  vertAlign = BOTTOM_ALIGN;
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) {
238  decimalPlaces = precision;
239  }
240 
246  private int getDecimalPlaces() {
247  return decimalPlaces;
248  }
249 
255  public void setFontName(String fontName) {
256  this.fontName = fontName;
257  }
258 
264  public String getFontName() {
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 
337  public Color getForeground() {
338  return foreground;
339  }
340 
346  public void setBackground(Color c) {
347  if(c!=null)
348  background = new Color(c.getRGB());
349  }
350 
356  public Color getBackground() {
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 }
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
final static int BOLD
Indicates bold text.
Definition: Format.java:39
Format(int attributes, int fontSize, String fontName)
Constructor that creates a new.
Definition: Format.java:92
void setCategory(String newCategory)
Set the formatting category of this object, ie number, date, currency.
Definition: Format.java:180
final static int SUPERSCRIPT
Indicates superscripted text.
Definition: Format.java:47
Format()
Constructor for creating a new.
Definition: Format.java:80
Color getBackground()
Get the Background.
Definition: Format.java:356
void setAttribute(int flags, boolean toggle)
Set one or more text attributes.
Definition: Format.java:146
void setFontName(String fontName)
Set the font used for this cell.
Definition: Format.java:255
int getAlign()
Get the alignment used for this cell.
Definition: Format.java:318
exports com.sun.star. java
final static int SUBSCRIPT
Indicates subscripted text.
Definition: Format.java:49
boolean isDefault()
Tests if the current.
Definition: Format.java:375
void setFormatSpecifier(String formatString)
Set the.
Definition: Format.java:219
This class specifies the format for a given spreadsheet cell.
Definition: Format.java:26
boolean getAttribute(int attribute)
Return.
Definition: Format.java:164
PyRef getClass(const OUString &name, const Runtime &runtime)
Format(Format fmt)
Constructor for creating a new.
Definition: Format.java:105
String getFontName()
Get the font used for this cell.
Definition: Format.java:264
void setBackground(Color c)
Set the Background.
Definition: Format.java:346
final static int TOP_ALIGN
Vertical Alignment Constants.
Definition: Format.java:34
void setVertAlign(int vertAlign)
Set the vertical alignment used for this cell.
Definition: Format.java:291
String getCategory()
Return the formatting category of the object.
Definition: Format.java:191
void setDecimalPlaces(int precision)
Set the precision of the number to be displayed.
Definition: Format.java:237
int getFontSize()
Get the font size (in points) used for this cell.
Definition: Format.java:282
void setFontSize(int fontSize)
Set the font size (in points) used for this cell.
Definition: Format.java:273
void setAlign(int align)
Set the alignment used for this cell.
Definition: Format.java:309
boolean isSubset(Format rhs)
Return true if passed.
Definition: Format.java:402
Color getForeground()
Get the Foreground.
Definition: Format.java:337
int getVertAlign()
Get the vertical alignment used for this cell.
Definition: Format.java:300
final static int UNDERLINE
Indicates underlined text.
Definition: Format.java:43
int getDecimalPlaces()
Get the number of decimal places displayed.
Definition: Format.java:246
void setForeground(Color c)
Set the Foreground.
Definition: Format.java:327
int mask
Bitwise mask of text attributes.
Definition: Format.java:75
String getValue()
In the case of Formula returns the value of the formula.
Definition: Format.java:200
final static int STRIKETHRU
Indicates strike-through in the text.
Definition: Format.java:45
final static int RIGHT_ALIGN
Horizontal Alignment Constants.
Definition: Format.java:29
int attributes
Values of text attributes.
Definition: Format.java:73
final static int ITALIC
Indicates italic text.
Definition: Format.java:41