1 package com.ca.directory.jxplorer.viewer.tableviewer; 2 3 import java.awt.Component ; 4 import javax.swing.JTable ; 5 import javax.swing.table.*; 6 import java.awt.*; 7 8 import com.ca.commons.cbutil.CBIntText; 9 10 15 16 public class AttributeValueCellRenderer extends DefaultTableCellRenderer 17 18 { 19 Font normalFont; 20 Font boldFont; 21 Font boldBlueFont; 22 23 27 28 public AttributeValueCellRenderer() 29 { 30 super(); 31 normalFont = this.getFont(); 32 boldFont = normalFont.deriveFont(java.awt.Font.BOLD); 33 boldBlueFont = normalFont.deriveFont(java.awt.Font.BOLD); 34 } 35 36 40 41 protected void setValue(Object value) { 43 if (value instanceof AttributeValue) 44 { 45 if (((AttributeValue)value).isBinary() && (((AttributeValue)value).isEmpty()==false)) 46 value = CBIntText.get("(non string data)"); 47 else 48 { 49 String stringVal = value.toString(); 51 if (stringVal.length() > 100) 52 value = truncateLongString(stringVal); 53 54 if (stringVal.substring(0,6).toLowerCase().startsWith("<html>")) 55 value = " " + stringVal; 56 } 57 } 58 super.setValue(value); 59 } 60 61 public String truncateLongString(String truncateMe) 62 { 63 return truncateMe.substring(0, 100) + "..."; 64 } 65 66 70 71 public Component getTableCellRendererComponent(JTable table, Object value, 72 boolean isSelected, boolean hasFocus, int row, int column) 73 { 74 if (value instanceof AttributeValue) 75 { 76 77 AttributeValue attVal = (AttributeValue)value; 78 String attString = attVal.toString(); 79 if (attString.length() > 100) 80 attString = truncateLongString(attString); 81 82 Component c = super.getTableCellRendererComponent(table, attString, isSelected, hasFocus, row, column); 83 84 if (attVal.isNaming()) 85 { 86 c.setForeground(((isSelected)?Color.white:Color.blue)); 87 c.setFont(boldFont); 88 } 89 else 90 { 91 c.setForeground(((isSelected)?Color.white:Color.black)); 92 c.setFont(normalFont); 93 } 94 return c; 95 96 } 97 else 98 return super.getTableCellRendererComponent(table, new String ("error"), isSelected, hasFocus, row, column); 99 } 100 } | Popular Tags |