method.setAccessible(true);
return method.invoke(currentObject, (Object [])null);
}
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
DefaultTableCellRenderer renderer = (DefaultTableCellRenderer)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
// Add whitespace to left and right of columns
renderer.setBorder(new EmptyBorder(insets.top, insets.left + (iconSupported ? 0 : 8), insets.bottom, insets.right + 8));
// Set the correct colours. CraigM 27/11/2007
// TF:05/05/2009:Corrected these dependent upon the hasRowHighlights property of a ListViewTable
boolean ignoreSelection = (table instanceof ListViewTable) && (!((ListViewTable)table).getHasRowHighlights());
if (isSelected && !ignoreSelection) {
if (table.hasFocus()) {
renderer.setBackground(table.getSelectionBackground());
renderer.setForeground(table.getSelectionForeground());
}
else {
renderer.setBackground(java.awt.Color.lightGray);
renderer.setForeground(java.awt.Color.black);
}
}
else {
renderer.setBackground(table.getBackground());
renderer.setForeground(table.getForeground());
}
// Display icon if defined for this column
if(value instanceof DisplayNode) {
try {
// Get the real value via reflection. This will either be the text of
// the object or an image data. The first case (text) will be when this
// is column 0 in the array and we need to use the icon image with the
// retrieved text, and the second case will be when there is an explicitly
// mapped image associated with this column.
//Object objValue = AlignedCellRenderer.expressionExecute(value, this.methodName, "().");
Object objValue = AlignedCellRenderer.expressionExecute(value, this.methodName, ".");
int iconHeight = 0;
if (objValue != null && objValue instanceof ImageData) {
// This is a column defined as an image, it can contain no text
ImageData id = (ImageData)objValue;
renderer.setIcon(id.asScaledIconImage(ICON_WIDTH, ICON_HEIGHT));
iconHeight = ICON_HEIGHT;
}
else {
// display icon
// TF:24/7/07: In Forte, if there was no selected icon, the small icon would display, even if selected.
Icon icon = null;
ImageData image = ((DisplayNode)value).getDVSmallIcon();
// COLET 20/01/2009 : Check if the selected image is valid by checking isNull(). If its empty, use the small icon. This is what Forte did.
ImageData selectedImage = ((DisplayNode)value).getDVSelectedIcon();
if (isSelected && selectedImage != null && !selectedImage.isNull()) {
image = selectedImage;
}
// We have an icon
if(image != null) {
icon = image.asScaledIconImage(ICON_WIDTH, ICON_HEIGHT);
iconHeight = ICON_HEIGHT;
}
// We don't have an icon and we are the left column, however, some other row does, so pad the space with an invisible image.
else if (column == 0 && this.hasIconInColumn1(table)) {
icon = invisibleIcon;
}
//COLET 20/01/2009 : Add some shading to the icon. Forte would have the icon painted like this.
// By default, Java wont paint the background colour over the icon. Lets mimic Forte.
if(icon != null && isSelected) {
icon = new AlphaBlendedIcon(icon, getBackground(), BLENDED_ICON_TRANSPARENCY);
}
renderer.setIcon(icon);
if(objValue != null) {
renderer.setText(objValue.toString());
// If we don't have an icon and we are the left most column, pad the space.
if (icon == null && column == 0) {
renderer.setText(" " + renderer.getText());
}
// The column sorts by comparing DVNodeText on the display node,
// so this should be set using the displayed text
// DisplayNode node = (DisplayNode)value;
// TextData td = node.getDVNodeText();
// if(td == null || td.toString() == null || td.toString().length() == 0
// || !objValue.toString().equals(td.toString())) {
// node.setDVNodeText(objValue.toString());
// }
}
}
// set row height sufficient for icon
int currentHeight = table.getRowHeight();
int newHeight = Math.max(iconHeight, currentHeight);
if(newHeight != currentHeight) {
table.setRowHeight(newHeight);
}
} catch (Exception e) {
e.printStackTrace();
}
}
else {
renderer.setIcon(null);
}
// Don't have a completely blank cell, as this will cause the row highlighting to not work. CraigM 14/09/2007.
if (renderer.getIcon() == null && renderer.getText().length() == 0) {
renderer.setText(" ");
}
return renderer;
}