1 17 18 package org.objectweb.jac.aspects.gui.swing; 19 20 import java.awt.Component ; 21 import javax.swing.JComponent ; 22 import javax.swing.JTable ; 23 import javax.swing.UIManager ; 24 import javax.swing.table.TableCellRenderer ; 25 import org.apache.log4j.Logger; 26 import org.objectweb.jac.aspects.gui.FieldUpdate; 27 import org.objectweb.jac.aspects.gui.Utils; 28 import org.objectweb.jac.core.rtti.FieldItem; 29 30 public abstract class AbstractFieldView extends AbstractView 31 implements FieldUpdate, TableCellRenderer 32 { 33 static Logger logger = Logger.getLogger("gui.table"); 34 35 Object substance; 38 FieldItem field; 39 40 boolean isCellViewer = false; 41 42 public AbstractFieldView(Object substance, FieldItem field) { 43 this.substance = substance; 44 this.field = field; 45 46 Utils.registerField(substance,field,this); 47 } 48 49 public AbstractFieldView() { 50 substance = null; 51 field = null; 52 } 53 54 57 protected void setTableFont() { 58 JComponent component = getComponent(); 59 if (component!=null) { 60 component.setFont(UIManager.getFont("Table.font")); 61 } 62 } 63 64 public abstract void setValue(Object value); 65 66 public void setSubstance(Object substance) { 67 Utils.unregisterField(this.substance,field,this); 68 this.substance = substance; 69 Utils.registerField(substance,field,this); 70 } 71 72 public Object getSubstance() { 73 return substance; 74 } 75 76 public void setField(FieldItem field) { 77 Utils.unregisterField(substance,this.field,this); 78 this.field = field; 79 Utils.registerField(substance,field,this); 80 } 81 82 public FieldItem getField() { 83 return field; 84 } 85 86 public void setAutoUpdate(boolean autoUpdate) { 87 } 89 90 public void close(boolean validate) { 91 Utils.unregisterField(substance,field,this); 92 } 93 94 public void fieldUpdated(Object substance, 96 FieldItem field, Object value, 97 Object param) { 98 setValue(value); 99 } 100 101 public Component getTableCellRendererComponent( 103 JTable table, Object value, 104 boolean isSelected, boolean hasFocus, 105 int row, int column) 106 { 107 logger.debug( 108 this+".getTableCellRendererComponent("+row+","+column+","+isSelected+")"); 109 JComponent component = getComponent(); 110 111 if (component!=null) { 112 component.setOpaque(true); } 114 setOpaque(true); 116 if (isSelected) { 117 if (component!=null) { 118 component.setForeground(table.getSelectionForeground()); 119 component.setBackground(table.getSelectionBackground()); 120 } 121 setForeground(table.getSelectionForeground()); 122 setBackground(table.getSelectionBackground()); 123 } else { 124 if (component!=null) { 125 component.setForeground(table.getForeground()); 126 component.setBackground(table.getBackground()); 127 } 128 setForeground(table.getForeground()); 129 setBackground(table.getBackground()); 130 } 131 setValue(value); 132 133 return this; 134 } 135 136 140 protected JComponent getComponent() { 141 return null; 142 } 143 } 144 | Popular Tags |