Method from jxl.biff.XFRecord Detail: |
public boolean equals(Object o) {
if (o == this)
{
return true;
}
if (!(o instanceof XFRecord))
{
return false;
}
XFRecord xfr = (XFRecord) o;
// Both records must be writable and have their format info initialized
if (!formatInfoInitialized)
{
initializeFormatInformation();
}
if (!xfr.formatInfoInitialized)
{
xfr.initializeFormatInformation();
}
if (xfFormatType != xfr.xfFormatType ||
parentFormat != xfr.parentFormat ||
locked != xfr.locked ||
hidden != xfr.hidden ||
usedAttributes != xfr.usedAttributes)
{
return false;
}
if (align != xfr.align ||
valign != xfr.valign ||
orientation != xfr.orientation ||
wrap != xfr.wrap ||
shrinkToFit != xfr.shrinkToFit ||
indentation != xfr.indentation)
{
return false;
}
if (leftBorder != xfr.leftBorder ||
rightBorder != xfr.rightBorder ||
topBorder != xfr.topBorder ||
bottomBorder != xfr.bottomBorder)
{
return false;
}
if (leftBorderColour != xfr.leftBorderColour ||
rightBorderColour != xfr.rightBorderColour ||
topBorderColour != xfr.topBorderColour ||
bottomBorderColour != xfr.bottomBorderColour)
{
return false;
}
if (backgroundColour != xfr.backgroundColour ||
pattern != xfr.pattern)
{
return false;
}
if (initialized && xfr.initialized)
{
// Both formats are initialized, so it is sufficient to just do
// shallow equals on font, format objects,
// since we are testing for the presence of clones anwyay
// Use indices rather than objects because of the rationalization
// process (which does not set the object on an XFRecord)
if (fontIndex != xfr.fontIndex ||
formatIndex != xfr.formatIndex)
{
return false;
}
}
else
{
// Perform a deep compare of fonts and formats
if (!font.equals(xfr.font) ||
!format.equals(xfr.format))
{
return false;
}
}
return true;
}
Equals method. This is called when comparing writable formats
in order to prevent duplicate formats being added to the workbook |
public Alignment getAlignment() {
if (!formatInfoInitialized)
{
initializeFormatInformation();
}
return align;
}
Gets the horizontal cell alignment |
public Colour getBackgroundColour() {
if (!formatInfoInitialized)
{
initializeFormatInformation();
}
return backgroundColour;
}
Gets the background colour used by this cell |
public BorderLineStyle getBorder(Border border) {
return getBorderLine(border);
}
Gets the line style for the given cell border
If a border type of ALL or NONE is specified, then a line style of
NONE is returned |
public Colour getBorderColour(Border border) {
// Don't bother with the short cut records
if (border == Border.NONE ||
border == Border.ALL)
{
return Colour.PALETTE_BLACK;
}
if (!formatInfoInitialized)
{
initializeFormatInformation();
}
if (border == Border.LEFT)
{
return leftBorderColour;
}
else if (border == Border.RIGHT)
{
return rightBorderColour;
}
else if (border == Border.TOP)
{
return topBorderColour;
}
else if (border == Border.BOTTOM)
{
return bottomBorderColour;
}
return Colour.BLACK;
}
Gets the line style for the given cell border
If a border type of ALL or NONE is specified, then a line style of
NONE is returned |
public BorderLineStyle getBorderLine(Border border) {
// Don't bother with the short cut records
if (border == Border.NONE ||
border == Border.ALL)
{
return BorderLineStyle.NONE;
}
if (!formatInfoInitialized)
{
initializeFormatInformation();
}
if (border == Border.LEFT)
{
return leftBorder;
}
else if (border == Border.RIGHT)
{
return rightBorder;
}
else if (border == Border.TOP)
{
return topBorder;
}
else if (border == Border.BOTTOM)
{
return bottomBorder;
}
return BorderLineStyle.NONE;
}
Gets the line style for the given cell border
If a border type of ALL or NONE is specified, then a line style of
NONE is returned |
public byte[] getData() {
// Format rationalization process means that we always want to
// regenerate the format info - even if the spreadsheet was
// read in
if (!formatInfoInitialized)
{
initializeFormatInformation();
}
byte[] data = new byte[20];
IntegerHelper.getTwoBytes(fontIndex, data, 0);
IntegerHelper.getTwoBytes(formatIndex, data, 2);
// Do the cell attributes
int cellAttributes = 0;
if (getLocked())
{
cellAttributes |= 0x01;
}
if (getHidden())
{
cellAttributes |= 0x02;
}
if (xfFormatType == style)
{
cellAttributes |= 0x04;
parentFormat = 0xffff;
}
cellAttributes |= (parentFormat < < 4);
IntegerHelper.getTwoBytes(cellAttributes, data, 4);
int alignMask = align.getValue();
if (wrap)
{
alignMask |= 0x08;
}
alignMask |= (valign.getValue() < < 4);
alignMask |= (orientation.getValue() < < 8);
IntegerHelper.getTwoBytes(alignMask, data, 6);
data[9] = (byte) 0x10;
// Set the borders
int borderMask = leftBorder.getValue();
borderMask |= (rightBorder.getValue() < < 4);
borderMask |= (topBorder.getValue() < < 8);
borderMask |= (bottomBorder.getValue() < < 12);
IntegerHelper.getTwoBytes(borderMask, data, 10);
// Set the border palette information if border mask is non zero
// Hard code the colours to be black
if (borderMask != 0)
{
byte lc = (byte)leftBorderColour.getValue();
byte rc = (byte)rightBorderColour.getValue();
byte tc = (byte)topBorderColour.getValue();
byte bc = (byte)bottomBorderColour.getValue();
int sideColourMask = (lc & 0x7f) | ((rc & 0x7f) < < 7);
int topColourMask = (tc & 0x7f) | ((bc & 0x7f) < < 7);
IntegerHelper.getTwoBytes(sideColourMask, data, 12);
IntegerHelper.getTwoBytes(topColourMask, data, 14);
}
// Set the background pattern
int patternVal = pattern.getValue() < < 10;
IntegerHelper.getTwoBytes(patternVal, data, 16);
// Set the colour palette
int colourPaletteMask = backgroundColour.getValue();
colourPaletteMask |= (0x40 < < 7);
IntegerHelper.getTwoBytes(colourPaletteMask, data, 18);
// Set the cell options
options |= indentation & 0x0f;
if (shrinkToFit)
{
options |= 0x10;
}
else
{
options &= 0xef;
}
data[8] = (byte) options;
if (biffType == biff8)
{
data[9] = (byte) usedAttributes;
}
return data;
}
Converts the various fields into binary data. If this object has
been read from an Excel file rather than being requested by a user (ie.
if the read flag is TRUE) then
no processing takes place and the raw data is simply returned. |
public DateFormat getDateFormat() {
return dateFormat;
}
Gets the java date format for this format record |
public Font getFont() {
if (!formatInfoInitialized)
{
initializeFormatInformation();
}
return font;
}
Gets the font used by this format |
public int getFontIndex() {
return fontIndex;
}
Accessor for the font index. Called by the FormattingRecords objects
during the rationalization process |
public Format getFormat() {
if (!formatInfoInitialized)
{
initializeFormatInformation();
}
return excelFormat;
}
Gets the format used by this format |
public int getFormatRecord() {
return formatIndex;
}
Gets the lookup number of the format record |
protected final boolean getHidden() {
return hidden;
}
Accessor for the hidden flag |
public int getIndentation() {
if (!formatInfoInitialized)
{
initializeFormatInformation();
}
return indentation;
}
|
protected final boolean getLocked() {
return locked;
}
Accessor for the locked flag |
public NumberFormat getNumberFormat() {
return numberFormat;
}
Gets the java number format for this format record |
public Orientation getOrientation() {
if (!formatInfoInitialized)
{
initializeFormatInformation();
}
return orientation;
}
|
public Pattern getPattern() {
if (!formatInfoInitialized)
{
initializeFormatInformation();
}
return pattern;
}
Gets the pattern used by this cell format |
public VerticalAlignment getVerticalAlignment() {
if (!formatInfoInitialized)
{
initializeFormatInformation();
}
return valign;
}
Gets the vertical cell alignment |
public boolean getWrap() {
if (!formatInfoInitialized)
{
initializeFormatInformation();
}
return wrap;
}
Gets whether or not the contents of this cell are wrapped |
public final int getXFIndex() {
return xfIndex;
}
Accessor for the XF index |
public final boolean hasBorders() {
if (!formatInfoInitialized)
{
initializeFormatInformation();
}
if (leftBorder == BorderLineStyle.NONE &&
rightBorder == BorderLineStyle.NONE &&
topBorder == BorderLineStyle.NONE &&
bottomBorder == BorderLineStyle.NONE)
{
return false;
}
return true;
}
Determines if this cell format has any borders at all. Used to
set the new borders when merging a group of cells |
public int hashCode() {
// Must have its formats info initialized in order to compute the hash code
if (!formatInfoInitialized)
{
initializeFormatInformation();
}
int hashValue = 17;
int oddPrimeNumber = 37;
// The boolean fields
hashValue = oddPrimeNumber*hashValue + (hidden ? 1:0);
hashValue = oddPrimeNumber*hashValue + (locked ? 1:0);
hashValue = oddPrimeNumber*hashValue + (wrap ? 1:0);
hashValue = oddPrimeNumber*hashValue + (shrinkToFit ? 1:0);
// The enumerations
if (xfFormatType == cell)
{
hashValue = oddPrimeNumber*hashValue + 1;
}
else if (xfFormatType == style)
{
hashValue = oddPrimeNumber*hashValue + 2;
}
hashValue = oddPrimeNumber*hashValue + (align.getValue() + 1);
hashValue = oddPrimeNumber*hashValue + (valign.getValue() + 1);
hashValue = oddPrimeNumber*hashValue + (orientation.getValue());
hashValue ^= leftBorder.getDescription().hashCode();
hashValue ^= rightBorder.getDescription().hashCode();
hashValue ^= topBorder.getDescription().hashCode();
hashValue ^= bottomBorder.getDescription().hashCode();
hashValue = oddPrimeNumber*hashValue + (leftBorderColour.getValue());
hashValue = oddPrimeNumber*hashValue + (rightBorderColour.getValue());
hashValue = oddPrimeNumber*hashValue + (topBorderColour.getValue());
hashValue = oddPrimeNumber*hashValue + (bottomBorderColour.getValue());
hashValue = oddPrimeNumber*hashValue + (backgroundColour.getValue());
hashValue = oddPrimeNumber*hashValue + (pattern.getValue() + 1);
// The integer fields
hashValue = oddPrimeNumber*hashValue + usedAttributes;
hashValue = oddPrimeNumber*hashValue + parentFormat;
hashValue = oddPrimeNumber*hashValue + fontIndex;
hashValue = oddPrimeNumber*hashValue + formatIndex;
hashValue = oddPrimeNumber*hashValue + indentation;
return hashValue;
}
Standard hash code implementation |
public final void initialize(int pos,
FormattingRecords fr,
Fonts fonts) throws NumFormatRecordsException {
xfIndex = pos;
formattingRecords = fr;
// If this file has been read in or copied,
// the font and format indexes will
// already be initialized, so just set the initialized flag and
// return
if (read || copied)
{
initialized = true;
return;
}
if (!font.isInitialized())
{
fonts.addFont(font);
}
if (!format.isInitialized())
{
fr.addFormat(format);
}
fontIndex = font.getFontIndex();
formatIndex = format.getFormatIndex();
initialized = true;
}
If this cell has not been read in from an existing Excel sheet,
then initializes this record with the XF index passed in. Calls
initialized on the font and format record |
public boolean isDate() {
return date;
}
Sees if this format is a date format |
public final boolean isInitialized() {
return initialized;
}
Accessor to see if this format is initialized |
public boolean isLocked() {
if (!formatInfoInitialized)
{
initializeFormatInformation();
}
return locked;
}
Accessor for whether a particular cell is locked |
public boolean isNumber() {
return number;
}
Sees if this format is a number format |
public final boolean isRead() {
return read;
}
Accessor to see if this format was read in. Used when checking merged
cells |
public boolean isShrinkToFit() {
if (!formatInfoInitialized)
{
initializeFormatInformation();
}
return shrinkToFit;
}
Gets the shrink to fit flag |
void rationalize(IndexMapping xfMapping) {
xfIndex = xfMapping.getNewIndex(xfIndex);
if (xfFormatType == cell)
{
parentFormat = xfMapping.getNewIndex(parentFormat);
}
}
Changes the appropriate indexes during the rationalization process |
public void setFont(FontRecord f) {
// This style cannot be initialized, otherwise it would mean it would
// have been initialized with shared font
// However, sometimes (when setting a row or column format) an initialized
// XFRecord may have its font overridden by the column/row
font = f;
}
Sets the font object with a workbook specific clone. Called from
the CellValue object when the font has been identified as a statically
shared font
Also called to superimpose a HyperlinkFont on an existing label cell |
void setFontIndex(int newindex) {
fontIndex = newindex;
}
Sets the font index. This is called during the rationalization process
when some of the duplicate fonts have been removed |
void setFormatIndex(int newindex) {
formatIndex = newindex;
}
Sets the format index. This is called during the rationalization process
when some of the duplicate number formats have been removed |
protected void setXFAlignment(Alignment a) {
Assert.verify(!initialized);
align = a;
usedAttributes |= USE_ALIGNMENT;
}
Sets the horizontal alignment for the data in this cell.
This method should only be called from its writable subclass
CellXFRecord |
protected void setXFBackground(Colour c,
Pattern p) {
Assert.verify(!initialized);
backgroundColour = c;
pattern = p;
usedAttributes |= USE_BACKGROUND;
}
Sets the horizontal alignment for the data in this cell.
This method should only be called from its writable subclass
CellXFRecord |
protected void setXFBorder(Border b,
BorderLineStyle ls,
Colour c) {
Assert.verify(!initialized);
if (c == Colour.BLACK || c == Colour.UNKNOWN)
{
c = Colour.PALETTE_BLACK;
}
if (b == Border.LEFT)
{
leftBorder = ls;
leftBorderColour = c;
}
else if (b == Border.RIGHT)
{
rightBorder = ls;
rightBorderColour = c;
}
else if (b == Border.TOP)
{
topBorder = ls;
topBorderColour = c;
}
else if (b == Border.BOTTOM)
{
bottomBorder = ls;
bottomBorderColour = c;
}
usedAttributes |= USE_BORDER;
return;
}
Sets the border for this cell
This method should only be called from its writable subclass
CellXFRecord |
protected final void setXFCellOptions(int opt) {
options |= opt;
}
|
protected void setXFDetails(XFType t,
int pf) {
xfFormatType = t;
parentFormat = pf;
}
Sets the format type and parent format from the writable subclass |
protected void setXFIndentation(int i) {
Assert.verify(!initialized);
indentation = i;
usedAttributes |= USE_ALIGNMENT;
}
|
final void setXFIndex(int xfi) {
xfIndex = xfi;
}
Sets the XF index. Called when rationalizing the XF records
immediately prior to writing |
protected final void setXFLocked(boolean l) {
locked = l;
usedAttributes |= USE_PROTECTION;
}
Sets whether or not this XF record locks the cell |
protected void setXFOrientation(Orientation o) {
Assert.verify(!initialized);
orientation = o;
usedAttributes |= USE_ALIGNMENT;
}
Sets the vertical alignment for the data in this cell
This method should only be called from its writable subclass
CellXFRecord |
protected void setXFShrinkToFit(boolean s) {
Assert.verify(!initialized);
shrinkToFit = s;
usedAttributes |= USE_ALIGNMENT;
}
Sets the shrink to fit flag |
protected void setXFVerticalAlignment(VerticalAlignment va) {
Assert.verify(!initialized);
valign = va;
usedAttributes |= USE_ALIGNMENT;
}
Sets the vertical alignment for the data in this cell
This method should only be called from its writable subclass
CellXFRecord |
protected void setXFWrap(boolean w) {
Assert.verify(!initialized);
wrap = w;
usedAttributes |= USE_ALIGNMENT;
}
Sets whether the data in this cell is wrapped
This method should only be called from its writable subclass
CellXFRecord |
public final void uninitialize() {
// As the default formats are cloned internally, the initialized
// flag should never be anything other than false
if (initialized == true)
{
logger.warn("A default format has been initialized");
}
initialized = false;
}
Resets the initialize flag. This is called by the constructor of
WritableWorkbookImpl to reset the statically declared fonts |