1 7 8 package org.jdesktop.jdnc.markup.elem; 9 10 import java.awt.Component ; 11 12 import java.util.Hashtable ; 13 import java.util.Map ; 14 import java.util.Vector ; 15 16 import javax.swing.JComponent ; 17 import javax.swing.JTabbedPane ; 18 19 import net.openmarkup.AttributeHandler; 20 import net.openmarkup.ElementAssimilator; 21 import net.openmarkup.ElementHandler; 22 import net.openmarkup.ElementType; 23 import net.openmarkup.Realizable; 24 25 import org.w3c.dom.Element ; 26 27 import org.jdesktop.jdnc.markup.Attributes; 28 import org.jdesktop.jdnc.markup.ElementTypes; 29 import org.jdesktop.jdnc.markup.Namespace; 30 import org.jdesktop.jdnc.markup.attr.ComponentAttributes; 31 import org.jdesktop.jdnc.markup.attr.RootPaneAttributes; 32 33 37 public class TabbedPaneElement extends ComponentElement { 38 39 private static final Map attrMap = new Hashtable (); 40 private static final Map elementMap = new Hashtable (); 41 42 public TabbedPaneElement(Element element, ElementType elementType) { 43 super(element, elementType); 44 } 45 46 public ElementHandler getElementHandler(String namespaceURI, String elementName) { 47 Map handlerMap = getElementHandlerMap(); 48 return handlerMap == null ? null : (ElementHandler) handlerMap.get(namespaceURI + ":" + elementName); 49 } 50 51 public AttributeHandler getAttributeHandler(String namespaceURI, String attrName) { 52 Map handlerMap = getAttributeHandlerMap(); 53 return handlerMap == null ? null : (AttributeHandler) attrMap.get(namespaceURI + ":" + attrName); 54 } 55 56 protected Map getAttributeHandlerMap() { 57 return attrMap; 58 } 59 60 protected Map getElementHandlerMap() { 61 return elementMap; 62 } 63 64 70 71 protected Map registerAttributeHandlers() { 72 Map handlerMap = super.registerAttributeHandlers(); 73 if (handlerMap != null) { 74 75 } 76 return handlerMap; 77 } 78 79 protected Map registerElementHandlers() { 80 Map handlerMap = super.registerElementHandlers(); 81 if (handlerMap != null) { 82 handlerMap.put(Namespace.JDNC + ":" + 83 ElementTypes.EDITOR.getLocalName(), 84 editorElementHandler); 85 handlerMap.put(Namespace.JDNC + ":" + 86 ElementTypes.FORM.getLocalName(), 87 formElementHandler); 88 handlerMap.put(Namespace.JDNC + ":" + 89 ElementTypes.TABLE.getLocalName(), 90 tableElementHandler); 91 handlerMap.put(Namespace.JDNC + ":" + 92 ElementTypes.TREE_TABLE.getLocalName(), 93 treeTableElementHandler); 94 } 95 return handlerMap; 96 } 97 98 public static final ElementAssimilator componentAssimilator = new ElementAssimilator() { 99 public void assimilate(Realizable parent, Realizable child) { 100 JTabbedPane tabPane = (JTabbedPane )parent.getObject(); 101 Component component = (Component )child.getObject(); 102 String tabTitle = child.getAttributeNSOptional(Namespace.JDNC, Attributes.TITLE); 103 if (tabTitle.equals("")) { 104 tabTitle = component.getName(); 105 } 106 if (tabTitle.equals("")) { 107 tabTitle = "Tab " + tabPane.getTabCount(); 108 } 109 tabPane.addTab(tabTitle, component); 110 } 111 }; 112 113 115 protected static final ElementHandler editorElementHandler = 116 new ElementHandler(ElementTypes.EDITOR, 117 TabbedPaneElement.componentAssimilator); 118 119 protected static final ElementHandler formElementHandler = 120 new ElementHandler(ElementTypes.FORM, 121 TabbedPaneElement.componentAssimilator); 122 123 protected static final ElementHandler tableElementHandler = 124 new ElementHandler(ElementTypes.TABLE, 125 TabbedPaneElement.componentAssimilator); 126 127 protected static final ElementHandler treeTableElementHandler = 128 new ElementHandler(ElementTypes.TREE_TABLE, 129 TabbedPaneElement.componentAssimilator); 130 131 132 } 133 | Popular Tags |