1 7 8 package org.jdesktop.jdnc; 9 10 import java.awt.Color ; 11 import java.awt.Component ; 12 import java.awt.Font ; 13 14 import java.util.HashMap ; 15 16 import org.jdesktop.swing.decorator.AlternateRowHighlighter; 17 import org.jdesktop.swing.decorator.ComponentAdapter; 18 19 24 class ColumnPropertyHighlighter extends AlternateRowHighlighter { 25 26 private HashMap columnProperties = new HashMap (); 27 28 public ColumnPropertyHighlighter() { 29 super(null, null, null); 30 } 31 32 public void setColumnBackground(String columnName, Color background) { 33 if (background != null) { 34 columnProperties.put(columnName + ".background", background); 35 } 36 else { 37 columnProperties.remove(columnName + ".background"); 38 } 39 } 40 41 public Color getColumnBackground(String columnName) { 42 return (Color ) columnProperties.get(columnName + ".background"); 43 } 44 45 public void setColumnForeground(String columnName, Color foreground) { 46 if (foreground != null) { 47 columnProperties.put(columnName + ".foreground", foreground); 48 } 49 else { 50 columnProperties.remove(columnName + ".foreground"); 51 } 52 } 53 54 public Color getColumnForeground(String columnName) { 55 return (Color ) columnProperties.get(columnName + ".foreground"); 56 } 57 58 public void setColumnFont(String columnName, Font font) { 59 if (font != null) { 60 columnProperties.put(columnName + ".font", font); 61 } 62 else { 63 columnProperties.remove(columnName + ".font"); 64 } 65 } 66 67 public Font getColumnFont(String columnName) { 68 return (Font ) columnProperties.get(columnName + ".font"); 69 } 70 71 protected void applyFont(Component renderer, ComponentAdapter adapter) { 72 Font font = getColumnFont(adapter.getColumnName(adapter.column)); 73 if (font != null) { 74 renderer.setFont(font); 75 } 76 } 77 78 protected Color computeBackground(Component renderer, 79 ComponentAdapter adapter) { 80 Color seed = getColumnBackground(adapter.getColumnName(adapter.column)); 81 if (seed == null) { 82 seed = (adapter.row % 2) == 0 ? 83 getOddRowBackground() : getEvenRowBackground(); 84 } 85 if (seed == null) { 86 seed = getBackground() == null ? adapter.getComponent().getBackground() : 87 getBackground(); 88 } 89 return adapter.isSelected() ? computeSelectedBackground(seed) : seed; 90 } 91 92 protected Color computeForeground(Component renderer, 93 ComponentAdapter adapter) { 94 Color seed = getColumnForeground(adapter.getColumnName(adapter.column)); 95 if (seed == null) { 96 seed = getForeground() == null ? adapter.getComponent().getForeground() : 97 getForeground(); 98 } 99 return adapter.isSelected() ? computeSelectedForeground(seed) : seed; 100 101 } 102 } 103 | Popular Tags |