SVTableCellRendererpublic class SVTableCellRenderer extends JLabel implements TableCellRenderer, SerializableSheet Viewer Table Cell Render -- not commented via javadoc as it
nearly completely consists of overridden methods. |
Fields Summary |
---|
protected static Border | noFocusBorder | protected SVBorder | cellBorder | private HSSFWorkbook | wb | private final CellFormatter | cellFormatter |
Constructors Summary |
---|
public SVTableCellRenderer(HSSFWorkbook wb)
super();
setOpaque(true);
setBorder(noFocusBorder);
this.wb = wb;
|
Methods Summary |
---|
protected void | firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
// Strings get interned...
if (propertyName=="text") {
super.firePropertyChange(propertyName, oldValue, newValue);
}
| public void | firePropertyChange(java.lang.String propertyName, boolean oldValue, boolean newValue)
| public java.awt.Component | getTableCellRendererComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, boolean hasFocus, int row, int column)
boolean isBorderSet = false;
//If the JTables default cell renderer has been setup correctly the
//value will be the HSSFCell that we are trying to render
HSSFCell c = (HSSFCell)value;
if (c != null) {
HSSFCellStyle s = c.getCellStyle();
HSSFFont f = wb.getFontAt(s.getFontIndex());
setFont(SVTableUtils.makeFont(f));
if (s.getFillPattern() == HSSFCellStyle.SOLID_FOREGROUND) {
setBackground(SVTableUtils.getAWTColor(s.getFillForegroundColor(), SVTableUtils.white));
} else setBackground(SVTableUtils.white);
setForeground(SVTableUtils.getAWTColor(f.getColor(), SVTableUtils.black));
cellBorder.setBorder(SVTableUtils.getAWTColor(s.getTopBorderColor(), SVTableUtils.black),
SVTableUtils.getAWTColor(s.getRightBorderColor(), SVTableUtils.black),
SVTableUtils.getAWTColor(s.getBottomBorderColor(), SVTableUtils.black),
SVTableUtils.getAWTColor(s.getLeftBorderColor(), SVTableUtils.black),
s.getBorderTop(), s.getBorderRight(),
s.getBorderBottom(), s.getBorderLeft(),
hasFocus);
setBorder(cellBorder);
isBorderSet=true;
//Set the value that is rendered for the cell
switch (c.getCellType()) {
case HSSFCell.CELL_TYPE_BLANK:
setValue("");
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
if (c.getBooleanCellValue()) {
setValue("true");
} else {
setValue("false");
}
break;
case HSSFCell.CELL_TYPE_NUMERIC:
short format = s.getDataFormat();
double numericValue = c.getNumericCellValue();
if (cellFormatter.useRedColor(format, numericValue))
setForeground(Color.red);
else setForeground(null);
setValue(cellFormatter.format(format, c.getNumericCellValue()));
break;
case HSSFCell.CELL_TYPE_STRING:
setValue(c.getRichStringCellValue().getString());
break;
case HSSFCell.CELL_TYPE_FORMULA:
default:
setValue("?");
}
//Set the text alignment of the cell
switch (s.getAlignment()) {
case HSSFCellStyle.ALIGN_LEFT:
case HSSFCellStyle.ALIGN_JUSTIFY:
case HSSFCellStyle.ALIGN_FILL:
setHorizontalAlignment(SwingConstants.LEFT);
break;
case HSSFCellStyle.ALIGN_CENTER:
case HSSFCellStyle.ALIGN_CENTER_SELECTION:
setHorizontalAlignment(SwingConstants.CENTER);
break;
case HSSFCellStyle.ALIGN_GENERAL:
case HSSFCellStyle.ALIGN_RIGHT:
setHorizontalAlignment(SwingConstants.RIGHT);
break;
default:
setHorizontalAlignment(SwingConstants.LEFT);
break;
}
} else {
setValue("");
setBackground(SVTableUtils.white);
}
if (hasFocus) {
if (!isBorderSet) {
//This is the border to paint when there is no border
//and the cell has focus
cellBorder.setBorder(SVTableUtils.black,
SVTableUtils.black,
SVTableUtils.black,
SVTableUtils.black,
HSSFCellStyle.BORDER_NONE,
HSSFCellStyle.BORDER_NONE,
HSSFCellStyle.BORDER_NONE,
HSSFCellStyle.BORDER_NONE,
isSelected);
setBorder(cellBorder);
}
if (table.isCellEditable(row, column)) {
setForeground( UIManager.getColor("Table.focusCellForeground") );
setBackground( UIManager.getColor("Table.focusCellBackground") );
}
} else if (!isBorderSet) {
setBorder(noFocusBorder);
}
// ---- 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;
| public void | repaint(long tm, int x, int y, int width, int height)
| public void | repaint(java.awt.Rectangle r)
| public void | revalidate()
| protected void | setValue(java.lang.Object value)Sets the string to either the value or "" if the value is null.
setText((value == null) ? "" : value.toString());
| public void | validate()
|
|