Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* 
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at
  
  http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */
 
 package org.odftoolkit.simple.table;
 
 
This class provides functions to handle the style of a cell.

This class provides functions to handle the border settings, font settings, text alignment settings and so on.

Since:
0.3
 
 public class CellStyleHandler extends DefaultStyleHandler {
 
 
 
 	CellStyleHandler(Cell aCell) {
 		super(aCell.getOdfElement());
 		 = aCell;
 	}
 
 	private boolean isShared = false;

Return the used style name of this cell.

If there is no style name defined for cell, the attribute "table:default-cell-style-name" in table row and table column would be returned.

 
 	public String getUsedStyleName() {
 		String styleName = .getStyleName();
 		if (styleName == null || (styleName.equals(""))) { // search in row
 			Row aRow = .getTableRow();
 			 = true;
 		}
 		if (styleName == null || (styleName.equals(""))) { // search in column
 			Column aColumn = .getTableColumn();
 			 = true;
 		}
 		return styleName;
 	}

Return the style element for this cell, for read and write functions.

An empty style definition will be created if there is no style definition.

Returns:
the style element
		if ( != null)
		 = // note here: mOdfElement in
									// DefaultStyleHandler must be updated at
									// the same time
		String styleName = getUsedStyleName();
	}
	}
	}
	private OdfStyleBase getParentStyle(OdfStyle aStyle) {
		String parentName = aStyle.getStyleParentStyleNameAttribute();
		if (parentName == null || parentName.length() == 0)
			return null;
		if (parentName.equals("Default"))
		else
			return getStyleByName(parentName);
	}
	private OdfStyle getStyleByName(String name) {
		OdfStyle styleElement = null;
		styleElement = styles.getStyle(name.);
		if (styleElement == null) {
		}
		return styleElement;
	}
		if ( != null)
		else
	}

Return the country information for a specific script type

The country information in its parent style and default style will be taken into considered.

Null will be returned if there is no country information for this script type.

Parameters:
type - script type
Returns:
the country information for a specific script type
	public String getCountry(ScriptType type) {
		String country = null;
		if (textProperties != null)
			country = textProperties.getCountry(type);
		if (country != null && country.length() > 0)
			return country;
		boolean isDefault = ;
		OdfStyleBase parentStyle = null;
		if (!isDefault)
		while ((!isDefault) && (parentStyle != null)) {
			TextProperties parentStyleSetting = TextProperties.getTextProperties(parentStyle);
			country = parentStyleSetting.getCountry(type);
			if (country != null && country.length() > 0)
				return country;
			if (parentStyle instanceof OdfDefaultStyle)
				isDefault = true;
			else
				parentStyle = getParentStyle((OdfStyleparentStyle);
		}
		if (!isDefault) {
			TextProperties defaultStyleSetting = TextProperties.getTextProperties(defaultStyle);
			country = defaultStyleSetting.getCountry(type);
		}
		return country;
	}
	private void mergeFont(Font targetFont source) {
		// merge font
		if (target.getFamilyName() == null && source.getFamilyName() != null)
			target.setFamilyName(source.getFamilyName());
		if (target.getColor() == null && source.getColor() != null)
			target.setColor(source.getColor());
		if (target.getSize() == 0 && source.getSize() > 0)
			target.setSize(source.getSize());
		if (target.getFontStyle() == null && source.getFontStyle() != null)
			target.setFontStyle(source.getFontStyle());
		if (target.getTextLinePosition() == null && source.getTextLinePosition() != null)
	}

Return the font definition for a specific script type.

The font definition in its parent style and default style will be taken into considered.

A default font definition will be returned if there is no font definition for this script type at all.

Parameters:
type - script type
Returns:
the font definition for a specific script type
	public Font getFont(ScriptType type) {
		// A font includes font family name, font style, font color, font size
		Font font = null;
		if (textProperties != null)
			font = textProperties.getFont(type);
		else
			font = new Font(nullnull, 0, (StyleTypeDefinitions.TextLinePositionnull);
		if (font != null && font.getFamilyName() != null && font.getColor() != null && font.getSize() != 0
				&& font.getFontStyle() != null && font.getTextLinePosition() != null)
			return font;
		boolean isDefault = ;
		OdfStyleBase parentStyle = null;
		if (!isDefault)
		while ((!isDefault) && (parentStyle != null)) {
			TextProperties parentStyleSetting = TextProperties.getTextProperties(parentStyle);
			Font tempFont = parentStyleSetting.getFont(type);
			mergeFont(fonttempFont);
			if (font.getFamilyName() != null && font.getColor() != null && font.getSize() > 0
					&& font.getFontStyle() != null && font.getTextLinePosition() != null) {
				return font;
			}
			// continue to get parent properties
			if (parentStyle instanceof OdfDefaultStyle)
				isDefault = true;
			else
				parentStyle = getParentStyle((OdfStyleparentStyle);
		}
		if (!isDefault) {
			// For text document, there is no default table cell style.
			// So use default font style in default paragraph style.
			if (defaultStyle == null) {
				defaultStyle = getParagraphDefaultStyle();
			}
			if (defaultStyle != null) {
				TextProperties defaultStyleSetting = TextProperties.getTextProperties(defaultStyle);
				Font tempFont = defaultStyleSetting.getFont(type);
				mergeFont(fonttempFont);
			}
		}
		if (font.getColor() == null)
		if (font.getFontStyle() == null)
		if (font.getTextLinePosition() == null)
		return font;
	}

Return the language information for a specific script type

The language definition in its parent style and default style will be taken into considered.

Null will be returned if there is no language information for this script type at all.

Parameters:
type - script type
Returns:
the language information for a specific script type
	public String getLanguage(ScriptType type) {
		String language = null;
		if (textProperties != null)
			language = textProperties.getLanguage(type);
		if (language != null && language.length() > 0)
			return language;
		boolean isDefault = ;
		OdfStyleBase parentStyle = null;
		if (!isDefault)
		while ((!isDefault) && (parentStyle != null)) {
			TextProperties parentStyleSetting = TextProperties.getTextProperties(parentStyle);
			language = parentStyleSetting.getLanguage(type);
			if (language != null && language.length() > 0)
				return language;
			if (parentStyle instanceof OdfDefaultStyle)
				isDefault = true;
			else
				parentStyle = getParentStyle((OdfStyleparentStyle);
		}
		if (!isDefault) {
			TextProperties defaultStyleSetting = TextProperties.getTextProperties(defaultStyle);
			language = defaultStyleSetting.getLanguage(type);
		}
		return language;
	}

Set the country information for a specific script type

The consistency between country and script type is not verified.

If the parameter country is null, the country information for this script type will be removed.

	public void setCountry(String countryScriptType type) {
	}

Set the font definition. The locale information in font definition will be used to justify the script type.

If the parameter font is null, nothing will be happened.

Parameters:
font - font definition
	public void setFont(Font font) {
	}

Set the font definition. The locale information in font definition will be used to justify the script type.

If the parameter font is null, nothing will be happened.

Parameters:
font - font definition
	public void setFont(Font fontLocale language) {
	}

Set the language information for a specific script type

If the parameter language is null, the language information for this script type will be removed.

Parameters:
language - the language information
type - script type
	public void setLanguage(String languageScriptType type) {
	}

Return the background color.

The background color in its parent style and default style will be taken into considered.

Color WHITE will be returned if there is no the background color definition or the background color definition is not valid.

Returns:
the background color
		Color tempColor = null;
		if (properties != null)
			tempColor = properties.getBackgroundColor();
		if (tempColor != null)
			return tempColor;
		boolean isDefault = ;
		// find in parent style definition
		OdfStyleBase parentStyle = null;
		if (!isDefault)
		while ((!isDefault) && (parentStyle != null)) {
			TableCellProperties parentStyleSetting = TableCellProperties.getTableCellProperties(parentStyle);
			tempColor = parentStyleSetting.getBackgroundColor();
			if (tempColor != null)
				return tempColor;
			if (parentStyle instanceof OdfDefaultStyle)
				isDefault = true;
			else
				parentStyle = getParentStyle((OdfStyleparentStyle);
		}
		// find in default style definition
		if (!isDefault) {
			TableCellProperties defaultStyleSetting = TableCellProperties.getTableCellProperties(defaultStyle);
			tempColor = defaultStyleSetting.getBackgroundColor();
		}
		// use default
		if (tempColor == null)
			return .;
		return tempColor;
	}
		switch (type) {
		case :
			return properties.getLeftBorder();
		case :
			return properties.getRightBorder();
		case :
			return properties.getTopBorder();
		case :
			return properties.getBottomBorder();
			return properties.getDiagonalBlTr();
			return properties.getDiagonalTlBr();
		default:
			throw new IllegalArgumentException("Only border type with a single border is accepted.");
		}
	}

Return the border setting for a specific border.

The accepted parameter can be TOP,BOTTOM,LEFT,RIGHT,DIAGONALBLTR and DIAGONALTLBR.

The border type with a collection of borders, e.g. ALL_FOUR, LEFT_RIGHT, are not legal arguments

The border definition in its parent style and default style will be taken into considered.

Border.NONE will be returned if there is no the border definition for a specific border.

Parameters:
type - the border type which describes a single border
Returns:
the border setting
	public Border getBorder(CellBordersType type) {
		Border tempBorder = null;
		if (properties != null) {
			tempBorder = getNullableBorder(propertiestype);
		}
		if (tempBorder != null)
			return tempBorder;
		boolean isDefault = ;
		// find in parent style definition
		OdfStyleBase parentStyle = null;
		if (!isDefault)
		while ((!isDefault) && (parentStyle != null)) {
			TableCellProperties parentStyleSetting = TableCellProperties.getTableCellProperties(parentStyle);
			tempBorder = getNullableBorder(parentStyleSettingtype);
			;
			if (tempBorder != null)
				return tempBorder;
			if (parentStyle instanceof OdfDefaultStyle)
				isDefault = true;
			else
				parentStyle = getParentStyle((OdfStyleparentStyle);
		}
		// find in default style definition
		if (!isDefault) {
			TableCellProperties defaultStyleSetting = TableCellProperties.getTableCellProperties(defaultStyle);
			tempBorder = getNullableBorder(defaultStyleSettingtype);
		}
		// use default
		if (tempBorder == null) {
			return .;
		}
		return tempBorder;
	}

Return the vertical alignment.

If there is no vertical alignment definition, DEFAULT will be returned.

The vertical alignment definition in its parent style and default style will be taken into considered.

Returns:
the vertical alignment
		VerticalAlignmentType tempAlign = null;
		if (properties != null) {
			tempAlign = properties.getVerticalAlignment();
		}
		if (tempAlign != null)
			return tempAlign;
		boolean isDefault = ;
		// find in parent style definition
		OdfStyleBase parentStyle = null;
		if (!isDefault)
		while ((!isDefault) && (parentStyle != null)) {
			TableCellProperties parentStyleSetting = TableCellProperties.getTableCellProperties(parentStyle);
			tempAlign = parentStyleSetting.getVerticalAlignment();
			if (tempAlign != null)
				return tempAlign;
			if (parentStyle instanceof OdfDefaultStyle)
				isDefault = true;
			else
				parentStyle = getParentStyle((OdfStyleparentStyle);
		}
		// find in default style definition
		if (!isDefault) {
			TableCellProperties defaultStyleSetting = TableCellProperties.getTableCellProperties(defaultStyle);
			tempAlign = defaultStyleSetting.getVerticalAlignment();
		}
		// use default
		if (tempAlign == null) {
		}
		return tempAlign;
	}

Return the wrap option of this cell.

The wrap option definition in its parent style and default style will be taken into considered.

Returns:
true if the cell content can be wrapped;

false if the cell content cannot be wrapped.

	public boolean isTextWrapped() {
		Boolean tempBool = null;
		if (properties != null)
			tempBool = properties.isWrapped();
		if (tempBool != null)
			return tempBool.booleanValue();
		boolean isDefault = ;
		// find in parent style definition
		OdfStyleBase parentStyle = null;
		if (!isDefault)
		while ((!isDefault) && (parentStyle != null)) {
			TableCellProperties parentStyleSetting = TableCellProperties.getTableCellProperties(parentStyle);
			tempBool = parentStyleSetting.isWrapped();
			if (tempBool != null)
				return tempBool;
			if (parentStyle instanceof OdfDefaultStyle)
				isDefault = true;
			else
				parentStyle = getParentStyle((OdfStyleparentStyle);
		}
		// find in default style definition
		if (!isDefault) {
			TableCellProperties defaultStyleSetting = TableCellProperties.getTableCellProperties(defaultStyle);
			tempBool = defaultStyleSetting.isWrapped();
		}
		// use default
		if (tempBool == null)
			return false;
		return tempBool.booleanValue();
	}

Set the background color of this cell.

Parameters:
color - the background color that need to set. If color is null, background color setting will be removed.
	public void setBackgroundColor(Color color) {
	}

Set the border style of this cell. You can set the border style for a single border or a border collection.

The second parameter bordersType describes which borders you want to apply the style to, e.g. up border, bottom border, left border, right border, diagonal lines or four borders.

Parameters:
border - the border style description
bordersType - the type of the borders
	public void setBorders(Border borderCellBordersType bordersType) {
	}

Set the vertical alignment setting of this cell.

If the alignment is set as Default or null, the explicit vertical alignment setting is removed.

Parameters:
alignType - the vertical alignment setting.
	public void setVerticalAlignment(VerticalAlignmentType alignType) {
	}

Set the wrap option of this cell.

Parameters:
isWrapped - whether the cell content can be wrapped or not
	public void setTextWrapped(boolean isWrapped) {
	}

Set the horizontal alignment.

If the parameter alignType is null, the horizontal alignment setting will be removed.

Parameters:
alignType - the horizontal alignment
	}

Return the horizontal alignment.

The horizontal alignment in its parent style and default style will be taken into considered.

DEFAULT will be returned if there is no horizontal alignment setting.

Returns:
- the horizontal alignment; null if there is no horizontal alignment setting.
		HorizontalAlignmentType tempAlign = null;
		if (properties != null)
			tempAlign = properties.getHorizontalAlignment();
		if (tempAlign != null)
			return tempAlign;
		boolean isDefault = ;
		// find in parent style definition
		OdfStyleBase parentStyle = null;
		if (!isDefault)
		while ((!isDefault) && (parentStyle != null)) {
			ParagraphProperties parentStyleSetting = ParagraphProperties.getParagraphProperties(parentStyle);
			tempAlign = parentStyleSetting.getHorizontalAlignment();
			if (tempAlign != null)
				return tempAlign;
			if (parentStyle instanceof OdfDefaultStyle)
				isDefault = true;
			else
				parentStyle = getParentStyle((OdfStyleparentStyle);
		}
		// find in default style definition
		if (!isDefault) {
			ParagraphProperties defaultStyleSetting = ParagraphProperties.getParagraphProperties(defaultStyle);
			tempAlign = defaultStyleSetting.getHorizontalAlignment();
		}
		// use default
		if (tempAlign == null)
		return tempAlign;
	}
New to GrepCode? Check out our FAQ X