JIDE 3.5.15

com.jidesoft.grid
Class CellStyle

java.lang.Object
  extended by com.jidesoft.grid.CellStyle
All Implemented Interfaces:
Prioritized, Cloneable, SwingConstants
Direct Known Subclasses:
FlashCellStyle

public class CellStyle
extends Object
implements SwingConstants, Prioritized, Cloneable

CellStyle defines the styles of a table cell. Those styles include the background (include the selection background), the foreground (include the selection foreground), the font, the horizontal alignment, the vertical alignment, the text, the toolTipText, the icon and the border. CellStyleTable and its subclasses will use the styles defined in CellStyle and set to cell renderer component. Obviously, not all styles apply to all types of cell renderer components.

CellStyle works with StyleModel which can be used as an interface for TableModel. You can refer to StyleModel to see how to use it.

In additional to all the styles that you can set to CellStyle, you can assign a priority to it. This is useful where there are multiple cell styles for the same cell. Please read javadoc of getPriority() for more information.


Field Summary
static Border EMPTY_BORDER
           
static CellPainter EMPTY_CELL_PAINTER
           
static Color EMPTY_COLOR
           
static Font EMPTY_FONT
           
static Icon EMPTY_ICON
          An empty icon instance.
static String EMPTY_STRING
           
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Constructor Summary
CellStyle()
           
CellStyle(CellStyle style)
          Create a copy of the CellStyle;
 
Method Summary
 CellStyle clone()
           
 boolean equals(Object obj)
           
 boolean equalsForExporting(Object obj)
          Checks if this CellStyle instance equals to the obj in terms of exporting to excel.
 Color getBackground()
           
 Border getBorder()
           
 Font getFont()
           
 int getFontStyle()
           
 Color getForeground()
           
 int getHorizontalAlignment()
           
 int getHorizontalTextPosition()
           
 Icon getIcon()
           
 Border getOverlayBorder()
           
 CellPainter getOverlayCellPainter()
          Gets the overlay CellPainter which is used to paint after the cell content is painted.
 int getPriority()
          Gets the priority of the cell style.
 Color getSelectionBackground()
           
 Color getSelectionForeground()
           
 String getText()
           
 String getToolTipText()
           
 CellPainter getUnderlayCellPainter()
          Gets the underlay CellPainter which is used to paint before the cell content is painted.
 int getVerticalAlignment()
           
 int getVerticalTextPosition()
           
 boolean isShowIconOnly()
          Deprecated. replaced by getText(). If it returns an empty string, that means only icon will be shown.
static void mergeCellStyle(CellStyle mergedCellStyle, CellStyle anotherCellStyle)
          Merges the styles from the originalCellStyle to mergedCellStyle only if the mergedCellStyle doesn't have the particular style set before.
 void setBackground(Color background)
          Sets the background.
 void setBorder(Border border)
          Sets the border style.
 void setFont(Font font)
          Sets the font.
 void setFontStyle(int fontStyle)
          Sets the font style which could be Font.PLAIN, Font.BOLD or Font.ITALIC.
 void setForeground(Color foreground)
          Sets the foreground color.
 void setHorizontalAlignment(int horizontalAlignment)
          Sets the horizontal alignment.
 void setHorizontalTextPosition(int horizontalTextPosition)
          Sets the horizontal text position.
 void setIcon(Icon icon)
          Sets the icon.
 void setOverlayBorder(Border overlayBorder)
          Sets the overlay border cell style.
 void setOverlayCellPainter(CellPainter overlayCellPainter)
          Sets the overlay CellPainter.
 void setPriority(int priority)
          Sets the priority of the cell style.
 void setSelectionBackground(Color selectionBackground)
          Sets the selection background.
 void setSelectionForeground(Color selectionForeground)
          Sets the selection foreground.
 void setShowIconOnly(boolean showIconOnly)
          Deprecated. replaced by setText(String)
 void setText(String text)
          Sets the text style.
 void setToolTipText(String toolTipText)
          Sets the tooltip text style.
 void setUnderlayCellPainter(CellPainter underlayCellPainter)
          Sets the underlay CellPainter.
 void setVerticalAlignment(int verticalAlignment)
          Sets the vertical alignment.
 void setVerticalTextPosition(int verticalTextPosition)
          Sets the vertical text position.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ICON

public static final Icon EMPTY_ICON
An empty icon instance. If you ever setIcon on a cell style, you should set this EMPTY_ICON to those cell styles that don't have an icon.


EMPTY_COLOR

public static final Color EMPTY_COLOR

EMPTY_FONT

public static final Font EMPTY_FONT

EMPTY_BORDER

public static final Border EMPTY_BORDER

EMPTY_STRING

public static final String EMPTY_STRING
See Also:
Constant Field Values

EMPTY_CELL_PAINTER

public static final CellPainter EMPTY_CELL_PAINTER
Constructor Detail

CellStyle

public CellStyle()

CellStyle

public CellStyle(CellStyle style)
Create a copy of the CellStyle;

Parameters:
style - the existing cell style.
Method Detail

getBorder

public Border getBorder()

setBorder

public void setBorder(Border border)
Sets the border style. The border is used to set the border to the cell renderer component. Setting the border will make the cell content smaller. You can also use the overlay border if you prefer the border to be painted over the cell content instead of setting the border to the component.

Parameters:
border - the border.

getBackground

public Color getBackground()

setBackground

public void setBackground(Color background)
Sets the background.

Parameters:
background - the background color.

getForeground

public Color getForeground()

setForeground

public void setForeground(Color foreground)
Sets the foreground color.

Parameters:
foreground - the foreground color.

getSelectionBackground

public Color getSelectionBackground()

setSelectionBackground

public void setSelectionBackground(Color selectionBackground)
Sets the selection background.

Parameters:
selectionBackground - the selection background.

getSelectionForeground

public Color getSelectionForeground()

setSelectionForeground

public void setSelectionForeground(Color selectionForeground)
Sets the selection foreground.

Parameters:
selectionForeground - the selection foreground.

getFont

public Font getFont()

setFont

public void setFont(Font font)
Sets the font. If you set the font, we will ignore the value in setFontStyle.

Parameters:
font - the font in the CellStyle.

getFontStyle

public int getFontStyle()

setFontStyle

public void setFontStyle(int fontStyle)
Sets the font style which could be Font.PLAIN, Font.BOLD or Font.ITALIC. If you set the font, we will ignore the value in setFontStyle.

Parameters:
fontStyle - the font style in the CellStyle.

getIcon

public Icon getIcon()

setIcon

public void setIcon(Icon icon)
Sets the icon. The icon will be used if the cell renderer component is a JLabel or an AbstractButton.

Parameters:
icon - the icon.

getVerticalAlignment

public int getVerticalAlignment()

setVerticalAlignment

public void setVerticalAlignment(int verticalAlignment)
Sets the vertical alignment. It will be applicable for the renderer component that supports the vertical alignment, such as JLabel, JButton etc.

Parameters:
verticalAlignment - One of the following constants defined in SwingConstants: TOP, CENTER (the default), or BOTTOM.

getHorizontalAlignment

public int getHorizontalAlignment()

setHorizontalAlignment

public void setHorizontalAlignment(int horizontalAlignment)
Sets the horizontal alignment. It will be applicable for the renderer component that supports the vertical alignment, such as JLabel, JButton etc.

Parameters:
horizontalAlignment - One of the following constants defined in SwingConstants: LEFT, CENTER (the default for image-only labels), RIGHT, LEADING (the default for text-only labels) or TRAILING.

getVerticalTextPosition

public int getVerticalTextPosition()

setVerticalTextPosition

public void setVerticalTextPosition(int verticalTextPosition)
Sets the vertical text position. It will be applicable for the renderer component that supports the vertical text position, such as JLabel, JButton etc.

Parameters:
verticalTextPosition - One of the following constants defined in SwingConstants: TOP, CENTER (the default), or BOTTOM.

getHorizontalTextPosition

public int getHorizontalTextPosition()

setHorizontalTextPosition

public void setHorizontalTextPosition(int horizontalTextPosition)
Sets the horizontal text position. It will be applicable for the renderer component that supports the horizontal text position, such as JLabel, JButton etc.

Parameters:
horizontalTextPosition - One of the following constants defined in SwingConstants: LEFT, CENTER (the default for image-only labels), RIGHT, LEADING (the default for text-only labels) or TRAILING.

getText

public String getText()

setText

public void setText(String text)
Sets the text style. This style can be used when you don't want the value to be visible. By using this text style, the text will be displayed instead of the actual cell value.

Parameters:
text - the text.

getToolTipText

public String getToolTipText()

setToolTipText

public void setToolTipText(String toolTipText)
Sets the tooltip text style. If you want a cell to have a tooltip, you can use this cell style.

Parameters:
toolTipText - the tooltip text.

getOverlayBorder

public Border getOverlayBorder()

setOverlayBorder

public void setOverlayBorder(Border overlayBorder)
Sets the overlay border cell style. The overlay border is painted over the cell content (not set as the border to the cell renderer component). This style serves the same purpose as the overlay CellPainter. You can use the overlay border if it is easy to make a border to paint the way you prefer. Otherwise you can always the CellPainter which is more flexible to paint.

Please note, if the CellStyle is used in a HeaderStyleModel, the overlay border feature is not supported.

Parameters:
overlayBorder - the overlay border.

getOverlayCellPainter

public CellPainter getOverlayCellPainter()
Gets the overlay CellPainter which is used to paint after the cell content is painted.

Returns:
the overlay CellPainter
Since:
3.3.4

setOverlayCellPainter

public void setOverlayCellPainter(CellPainter overlayCellPainter)
Sets the overlay CellPainter. This painter is called after the cell content is painted so it is painted over the cell content. This style serves the same purpose as the overlay border. You can use the overlay border if it is easy to make a border to paint the way you prefer. Otherwise you can always the CellPainter which is more flexible to paint.

Please note, if the CellStyle is used in a HeaderStyleModel, the overlay CellPainter feature is not supported.

Parameters:
overlayCellPainter - the overlay CellPainter.
Since:
3.3.4

getUnderlayCellPainter

public CellPainter getUnderlayCellPainter()
Gets the underlay CellPainter which is used to paint before the cell content is painted.

Returns:
the underlay CellPainter
Since:
3.3.4

setUnderlayCellPainter

public void setUnderlayCellPainter(CellPainter underlayCellPainter)
Sets the underlay CellPainter. This painter is called before the cell content is painted.

Please note, if the CellStyle is used in a HeaderStyleModel, the underlay CellPainter feature is not supported.

Parameters:
underlayCellPainter - the underlay CellPainter.
Since:
3.3.4

getPriority

public int getPriority()
Gets the priority of the cell style. This has nothing to do with the styles for a cell but the priority of this particular cell style when there are multiple cell styles for the same cells.

In JIDE Grids, we used TableModelWrapper which can wrap another table model. So you can end up with a pipe of TableModelWrappers. Any of the table models can implement StyleModel and each one can return a different cell style. CellStyleTable will look at those CellStyles and sort them by the priority. The cell style that has the higher priority will win over any cell styles that have a lower priority when there are style conflicts (meaning the same style is used in different cell styles).

For example, you have one cell style that implements the row stripes and another cell style that implements cell update indication. Both use cell background style. Obviously you want the cell update indication has a higher priority than row stripes. So you just set a higher priority in cell update indication cell style.

If the cell styles have the same priority, the one from inner style table model has a higher priority.

Specified by:
getPriority in interface Prioritized
Returns:
the priority.

setPriority

public void setPriority(int priority)
Sets the priority of the cell style.

Parameters:
priority - the new priority

equalsForExporting

public boolean equalsForExporting(Object obj)
Checks if this CellStyle instance equals to the obj in terms of exporting to excel.

Only getBackground(), getForeground(), getFont(), getFontStyle(), getHorizontalAlignment() and getVerticalAlignment() are compared in this method.

Parameters:
obj - the target object
Returns:
true if it will equal after exporting to excel.
Since:
3.4.8

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

isShowIconOnly

@Deprecated
public boolean isShowIconOnly()
Deprecated. replaced by getText(). If it returns an empty string, that means only icon will be shown.

Gets the flag indicating if the cell shows the icon only if getIcon() is a non-null value.

Returns:
true if the cell shows the icon only without text. Otherwise false.
Since:
3.2.0

setShowIconOnly

@Deprecated
public void setShowIconOnly(boolean showIconOnly)
Deprecated. replaced by setText(String)

Sets the flag indicating if the cell shows the icon only if getIcon() is a non-null value.

Parameters:
showIconOnly - the flag
Since:
3.2.0

clone

public CellStyle clone()
                throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException

mergeCellStyle

public static void mergeCellStyle(CellStyle mergedCellStyle,
                                  CellStyle anotherCellStyle)
Merges the styles from the originalCellStyle to mergedCellStyle only if the mergedCellStyle doesn't have the particular style set before.

After merge, the priority of the merged cell style would be the higher one of those two CellStyles. If you have more than two CellStyles to merge, please sort those CellStyles with priority first.

Parameters:
mergedCellStyle - the cell style to merge to
anotherCellStyle - the cell style to merge from
Since:
3.3.5

JIDE 3.5.15