JIDE 3.3.1

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 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)
           
 Color getBackground()
           
 Border getBorder()
           
 Font getFont()
           
 int getFontStyle()
           
 Color getForeground()
           
 int getHorizontalAlignment()
           
 int getHorizontalTextPosition()
           
 Icon getIcon()
           
 Border getOverlayBorder()
           
 int getPriority()
          Gets the priority of the cell style.
 Color getSelectionBackground()
           
 Color getSelectionForeground()
           
 String getText()
           
 String getToolTipText()
           
 int getVerticalAlignment()
           
 int getVerticalTextPosition()
           
 boolean isShowIconOnly()
          Deprecated. replaced by getText(). If it returns an empty string, that means only icon will be shown.
 void setBackground(Color background)
           
 void setBorder(Border border)
           
 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)
           
 void setHorizontalAlignment(int horizontalAlignment)
           
 void setHorizontalTextPosition(int horizontalTextPosition)
           
 void setIcon(Icon icon)
           
 void setOverlayBorder(Border overlayBorder)
           
 void setPriority(int priority)
          Sets the priority of the cell style.
 void setSelectionBackground(Color selectionBackground)
           
 void setSelectionForeground(Color selectionForeground)
           
 void setShowIconOnly(boolean showIconOnly)
          Deprecated. replaced by setText(String)
 void setText(String text)
           
 void setToolTipText(String toolTipText)
           
 void setVerticalAlignment(int verticalAlignment)
           
 void setVerticalTextPosition(int verticalTextPosition)
           
 
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
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)

getBackground

public Color getBackground()

setBackground

public void setBackground(Color background)

getForeground

public Color getForeground()

setForeground

public void setForeground(Color foreground)

getSelectionBackground

public Color getSelectionBackground()

setSelectionBackground

public void setSelectionBackground(Color selectionBackground)

getSelectionForeground

public Color getSelectionForeground()

setSelectionForeground

public void setSelectionForeground(Color selectionForeground)

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)

getVerticalAlignment

public int getVerticalAlignment()

setVerticalAlignment

public void setVerticalAlignment(int verticalAlignment)

getHorizontalAlignment

public int getHorizontalAlignment()

setHorizontalAlignment

public void setHorizontalAlignment(int horizontalAlignment)

getVerticalTextPosition

public int getVerticalTextPosition()

setVerticalTextPosition

public void setVerticalTextPosition(int verticalTextPosition)

getHorizontalTextPosition

public int getHorizontalTextPosition()

setHorizontalTextPosition

public void setHorizontalTextPosition(int horizontalTextPosition)

getText

public String getText()

setText

public void setText(String text)

getToolTipText

public String getToolTipText()

setToolTipText

public void setToolTipText(String toolTipText)

getOverlayBorder

public Border getOverlayBorder()

setOverlayBorder

public void setOverlayBorder(Border overlayBorder)

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

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

JIDE 3.3.1