1 7 8 package org.jdesktop.jdnc.markup.elem; 9 10 import javax.swing.table.TableCellRenderer ; 11 12 import org.jdesktop.swing.data.MetaData; 13 import org.jdesktop.swing.data.DefaultTableModelExt; 14 15 import org.jdesktop.swing.LabelProperties; 16 import org.jdesktop.swing.table.ColumnHeaderRenderer; 17 import org.jdesktop.swing.table.TableColumnExt; 18 19 import org.jdesktop.jdnc.JNTable; 20 21 import java.util.Hashtable ; 22 import java.util.Map ; 23 24 import net.openmarkup.AttributeHandler; 25 import net.openmarkup.ElementAssimilator; 26 import net.openmarkup.ElementHandler; 27 import net.openmarkup.ElementType; 28 import net.openmarkup.Realizable; 29 30 import org.w3c.dom.Element ; 31 import org.w3c.dom.Node ; 32 33 import org.jdesktop.jdnc.markup.Attributes; 34 import org.jdesktop.jdnc.markup.ElementTypes; 35 import org.jdesktop.jdnc.markup.Namespace; 36 import org.jdesktop.jdnc.markup.attr.TableColumnAttributes; 37 38 43 public class TableColumnElement extends ElementProxy { 44 private static final Map attrMap = new Hashtable (); 45 private static final Map elementMap = new Hashtable (); 46 47 public TableColumnElement(Element element, ElementType elementType) { 48 super(element, elementType); 49 } 50 51 protected Map getAttributeHandlerMap() { 52 return attrMap; 53 } 54 55 protected Map getElementHandlerMap() { 56 return elementMap; 57 } 58 59 protected void applyAttributesAfter() { 60 super.applyAttributesAfter(); 61 applyAttribute(Namespace.JDNC, Attributes.BINDING); 63 applyAttribute(Namespace.JDNC, Attributes.IS_READ_ONLY); 64 applyAttribute(Namespace.JDNC, Attributes.ENUM_VALUES); 65 applyAttribute(Namespace.JDNC, Attributes.PROTOTYPE_VALUE); 66 applyAttribute(Namespace.JDNC, Attributes.TITLE); 68 initializeHeaderTitle(); 69 70 applyAttribute(Namespace.JDNC, Attributes.BACKGROUND); 72 applyAttribute(Namespace.JDNC, Attributes.FOREGROUND); 73 applyAttribute(Namespace.JDNC, Attributes.HORIZONTAL_ALIGNMENT); 74 applyAttribute(Namespace.JDNC, Attributes.VERTICAL_ALIGNMENT); 75 applyAttribute(Namespace.JDNC, Attributes.PREFERRED_WIDTH); 76 77 } 78 79 protected Map registerAttributeHandlers() { 80 Map handlerMap = super.registerAttributeHandlers(); 81 if (handlerMap != null) { 82 handlerMap.put(Namespace.JDNC + ":" + Attributes.BINDING, 84 bindingHandler); 85 handlerMap.put(Namespace.JDNC + ":" + Attributes.IS_READ_ONLY, 86 isReadOnlyHandler); 87 handlerMap.put(Namespace.JDNC + ":" + Attributes.ENUM_VALUES, 88 enumValuesHandler); 89 handlerMap.put(Namespace.JDNC + ":" + Attributes.PROTOTYPE_VALUE, 90 prototypeValueHandler); 91 handlerMap.put(Namespace.JDNC + ":" + Attributes.TITLE, 94 titleHandler); 95 handlerMap.put(Namespace.JDNC + ":" + Attributes.BACKGROUND, 96 backgroundHandler); 97 handlerMap.put(Namespace.JDNC + ":" + Attributes.FOREGROUND, 98 foregroundHandler); 99 handlerMap.put(Namespace.JDNC + ":" + Attributes.HORIZONTAL_ALIGNMENT, 100 horizontalAlignmentHandler); 101 105 handlerMap.put(Namespace.JDNC + ":" + Attributes.PREFERRED_WIDTH, 106 preferredWidthHandler); 107 108 } 109 return handlerMap; 110 } 111 112 protected void initializeHeaderTitle() { 113 TableColumnExt column = (TableColumnExt)getObject(); 114 if (column.getHeaderValue() == null) { 116 Realizable tableTarget = ElementProxy.getRealizable((Element ) 117 getParentNode().getParentNode()); 118 JNTable table = (JNTable) tableTarget.getObject(); 119 DefaultTableModelExt data = (DefaultTableModelExt)table.getModel(); 120 int columnIndex = column.getModelIndex(); 121 String label = "Column" + columnIndex; 122 if (data != null) { 123 MetaData metaData = data.getColumnMetaData(columnIndex); 124 String columnLabel = metaData.getLabel(); 125 if (columnLabel != null) { 126 label = columnLabel; 127 } 128 } 129 column.setHeaderValue(label); 130 } 131 } 132 133 protected Map registerElementHandlers() { 134 Map handlerMap = super.registerElementHandlers(); 135 if (handlerMap != null) { 136 handlerMap.put(Namespace.JDNC + ":" + 137 ElementTypes.TABLE_COLUMN_HEADER.getLocalName(), 138 tableColumnHeaderElementHandler); 139 } 140 return handlerMap; 141 } 142 143 public static final ElementAssimilator tableColumnHeaderAssimilator = new 144 ElementAssimilator() { 145 public void assimilate(Realizable parent, Realizable child) { 146 TableColumnExt column = (TableColumnExt) parent.getObject(); 147 LabelProperties headerProperties = (LabelProperties) child.getObject(); 148 TableCellRenderer headerRenderer = new ColumnHeaderRenderer(); 149 headerProperties.applyPropertiesTo(headerRenderer); 150 column.setHeaderRenderer(headerRenderer); 151 } 152 }; 153 154 private static final ElementHandler tableColumnHeaderElementHandler = 155 new ElementHandler(ElementTypes.TABLE_COLUMN_HEADER, tableColumnHeaderAssimilator); 156 157 158 private static final AttributeHandler backgroundHandler = 159 new AttributeHandler(Namespace.JDNC, Attributes.BACKGROUND, 160 TableColumnAttributes.backgroundApplier); 161 162 private static final AttributeHandler bindingHandler = 163 new AttributeHandler(Namespace.JDNC, Attributes.BINDING, 164 TableColumnAttributes.bindingApplier); 165 166 private static final AttributeHandler foregroundHandler = 167 new AttributeHandler(Namespace.JDNC, Attributes.FOREGROUND, 168 TableColumnAttributes.foregroundApplier); 169 170 private static final AttributeHandler isReadOnlyHandler = 171 new AttributeHandler(Namespace.JDNC, Attributes.IS_READ_ONLY, 172 TableColumnAttributes.isReadOnlyApplier); 173 174 private static final AttributeHandler enumValuesHandler = 175 new AttributeHandler(Namespace.JDNC, Attributes.ENUM_VALUES, 176 TableColumnAttributes.enumValuesApplier); 177 178 private static final AttributeHandler horizontalAlignmentHandler = 179 new AttributeHandler(Namespace.JDNC, Attributes.HORIZONTAL_ALIGNMENT, 180 TableColumnAttributes.horizontalAlignmentApplier); 181 182 private static final AttributeHandler prototypeValueHandler = 183 new AttributeHandler(Namespace.JDNC, Attributes.PROTOTYPE_VALUE, 184 TableColumnAttributes.prototypeValueApplier); 185 190 private static final AttributeHandler titleHandler = 191 new AttributeHandler(Namespace.JDNC, Attributes.TITLE, 192 TableColumnAttributes.titleApplier); 193 198 199 private static final AttributeHandler preferredWidthHandler = 200 new AttributeHandler(Namespace.JDNC, Attributes.PREFERRED_WIDTH, 201 TableColumnAttributes.preferredWidthApplier); 202 203 204 } 205 | Popular Tags |