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.JSplitPane ; 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.SplitPaneAttributes; 31 32 36 public class SplitPaneElement extends ComponentElement { 37 38 private static final Map attrMap = new Hashtable (); 39 private static final Map elementMap = new Hashtable (); 40 41 public SplitPaneElement(Element element, ElementType elementType) { 42 super(element, elementType); 43 } 44 45 public ElementHandler getElementHandler(String namespaceURI, String elementName) { 46 Map handlerMap = getElementHandlerMap(); 47 return handlerMap == null ? null : (ElementHandler) handlerMap.get(namespaceURI + ":" + elementName); 48 } 49 50 public AttributeHandler getAttributeHandler(String namespaceURI, String attrName) { 51 Map handlerMap = getAttributeHandlerMap(); 52 return handlerMap == null ? null : (AttributeHandler) attrMap.get(namespaceURI + ":" + attrName); 53 } 54 55 protected Map getAttributeHandlerMap() { 56 return attrMap; 57 } 58 59 protected Map getElementHandlerMap() { 60 return elementMap; 61 } 62 63 protected void applyAttributesAfter() { 64 super.applyAttributesAfter(); 65 applyAttribute(Namespace.JDNC, Attributes.ORIENTATION); 66 } 67 68 protected Map registerAttributeHandlers() { 69 Map handlerMap = super.registerAttributeHandlers(); 70 if (handlerMap != null) { 71 handlerMap.put(Namespace.JDNC + ":" + Attributes.ORIENTATION, 72 orientationHandler); 73 } 74 return handlerMap; 75 } 76 77 protected Map registerElementHandlers() { 78 Map handlerMap = super.registerElementHandlers(); 79 if (handlerMap != null) { 80 handlerMap.put(Namespace.JDNC + ":" + 81 ElementTypes.EDITOR.getLocalName(), 82 editorElementHandler); 83 handlerMap.put(Namespace.JDNC + ":" + 84 ElementTypes.FORM.getLocalName(), 85 formElementHandler); 86 handlerMap.put(Namespace.JDNC + ":" + 87 ElementTypes.TABLE.getLocalName(), 88 tableElementHandler); 89 handlerMap.put(Namespace.JDNC + ":" + 90 ElementTypes.TREE_TABLE.getLocalName(), 91 treeTableElementHandler); 92 } 93 return handlerMap; 94 } 95 96 public static final ElementAssimilator componentAssimilator = new ElementAssimilator() { 97 public void assimilate(Realizable parent, Realizable child) { 98 JSplitPane splitPane = (JSplitPane )parent.getObject(); 99 Component component = (Component )child.getObject(); 100 int orientation = splitPane.getOrientation(); 101 if (orientation == JSplitPane.VERTICAL_SPLIT) { 102 if (splitPane.getClientProperty("first") == null) { 105 splitPane.setTopComponent(component); 106 splitPane.putClientProperty("first", "true"); 107 } else { 108 if (splitPane.getClientProperty("second") == null) { 109 splitPane.setBottomComponent(component); 110 splitPane.putClientProperty("second", "true"); 111 } else { 112 113 System.out.println("splitpane can only have two children"); 114 } 115 } 116 } else { 117 if (splitPane.getClientProperty("first") == null) { 118 splitPane.setLeftComponent(component); 119 splitPane.putClientProperty("first", "true"); 120 } else { 121 if (splitPane.getClientProperty("second") == null) { 122 splitPane.setRightComponent(component); 123 splitPane.putClientProperty("second", "true"); 124 } else { 125 126 System.out.println("splitpane can only have two children"); 127 } 128 } 129 } 130 } 131 }; 132 133 135 protected static final AttributeHandler orientationHandler = 136 new AttributeHandler(Namespace.JDNC, Attributes.ORIENTATION, SplitPaneAttributes.orientationApplier); 137 138 protected static final ElementHandler editorElementHandler = 139 new ElementHandler(ElementTypes.EDITOR, 140 SplitPaneElement.componentAssimilator); 141 142 protected static final ElementHandler formElementHandler = 143 new ElementHandler(ElementTypes.FORM, 144 SplitPaneElement.componentAssimilator); 145 146 protected static final ElementHandler tableElementHandler = 147 new ElementHandler(ElementTypes.TABLE, 148 SplitPaneElement.componentAssimilator); 149 150 protected static final ElementHandler treeTableElementHandler = 151 new ElementHandler(ElementTypes.TREE_TABLE, 152 SplitPaneElement.componentAssimilator); 153 154 155 } 156 | Popular Tags |