Back to index

wims  3.65+svn20090927
Public Member Functions | Protected Member Functions
SharpTools.SharpCellRenderer Class Reference

The class for rendering (displaying) individual Cell objects in a JTable. More...

Inheritance diagram for SharpTools.SharpCellRenderer:
Inheritance graph
[legend]
Collaboration diagram for SharpTools.SharpCellRenderer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SharpCellRenderer ()
 Creates a SharpCellRenderer.
Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
 Returns the default table cell renderer.

Protected Member Functions

void setValue (Object value, boolean hasFocus, boolean isSelected, int row, int column)
 Sets the string for the cell being rendered to value.
boolean isHeaderCell (int row, int column)
 Header cells are special.

Detailed Description

The class for rendering (displaying) individual Cell objects in a JTable.

Because the DefaultTableCellRender is optimized for rendering objects in JTable, this renderer extends that class. Since the zeroth row and column of the table are used as labels, SharpCellRender renders them differently by have a gray background etc. SharpCellRenderer can be changed to toggle between displaying the text and value of a formula cell. This was done in a previous version but is not removed.

Author:
Ricky Chin
Version:
Revision:
1.9

Definition at line 29 of file SharpCellRenderer.java.


Constructor & Destructor Documentation

Creates a SharpCellRenderer.

Definition at line 34 of file SharpCellRenderer.java.

                               {
       super();
    }

Member Function Documentation

Component SharpTools.SharpCellRenderer.getTableCellRendererComponent ( JTable  table,
Object  value,
boolean  isSelected,
boolean  hasFocus,
int  row,
int  column 
) [inline]

Returns the default table cell renderer.

Parameters:
tablethe JTable
valuethe value to assign to the cell at [row, column]
isSelectedtrue if cell is selected
hasFocustrue if cell has focus
rowthe row of the cell to render
columnthe column of the cell to render
Returns:
the default table cell renderer

Definition at line 50 of file SharpCellRenderer.java.

                                                                              {

        /* the following is the similar to DefaultTableCellRenderer */
       if (isSelected && !(isHeaderCell(row, column))) {
          super.setForeground(table.getSelectionForeground());
          super.setBackground(table.getSelectionBackground());
       }else {
           /* set header cells background to grey and rest to default */
           if (isHeaderCell(row, column)) {
              super.setBackground(Color.lightGray);
              super.setForeground(table.getForeground());
           }else {
              super.setForeground(table.getForeground());
              super.setBackground(table.getBackground());
           }
       }
       
       setFont(table.getFont());

       if (hasFocus) {
           setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
           if (table.isCellEditable(row, column)) {
               super.setForeground( UIManager.getColor(
                                       "Table.focusCellForeground") );
               super.setBackground( UIManager.getColor(
                                        "Table.focusCellBackground") );
           }
       } else {
           setBorder(noFocusBorder);
       }

        /* this method has been changed for formula feature */
        setValue(value, isSelected, hasFocus, row, column); 

        //DefaulTableCellRenderer code
       // begin optimization to avoid painting background
       Color back = getBackground();
       boolean colorMatch = (back != null) && 
                    ( back.equals(table.getBackground()) ) && table.isOpaque();
        setOpaque(!colorMatch);
       // end optimization to aviod painting background

       return this;
    }

Here is the call graph for this function:

boolean SharpTools.SharpCellRenderer.isHeaderCell ( int  row,
int  column 
) [inline, protected]

Header cells are special.

Parameters:
rowthe int value of the row
columnthe int value of the column
Returns:
true if row = column = 0.

Definition at line 141 of file SharpCellRenderer.java.

                                                        {
       return (/*row == 0 || */column == SharpTools.baseCol-1);
    }

Here is the caller graph for this function:

void SharpTools.SharpCellRenderer.setValue ( Object  value,
boolean  hasFocus,
boolean  isSelected,
int  row,
int  column 
) [inline, protected]

Sets the string for the cell being rendered to value.

Parameters:
valuethe string value for this cell; if value is null it sets the text value to an empty string
hasFocuswhether cell has focus or not
isSelectedwhether cell is selected
rowcell row
columncell column

Definition at line 105 of file SharpCellRenderer.java.

                                                                              {
        if (value instanceof Cell) {
            //we only care about the value, not the formula string
            Cell temp = (Cell)value;
           Object data = temp.getValue();
            
           if (isHeaderCell(row, column)) {
                //label cells are center aligned
              setHorizontalAlignment(JTextField.CENTER);
           }else {
                if (data instanceof Number) {
                    //numbers are right justified
                  setHorizontalAlignment(JTextField.RIGHT);
                }else {
                    //everything else is left justified
                  setHorizontalAlignment(JTextField.LEFT);
               }
            }
            
            //value to display in table
           setText((data == null) ? "" : data.toString());
        }
        else {
            //not cell object so render with toString of that object
            setText((value == null) ? "" : value.toString());
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: