KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdnc > markup > elem > ContainerElement


1 /*
2  * $Id: ContainerElement.java,v 1.1.1.1 2004/06/16 01:43:40 davidson1 Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.jdnc.markup.elem;
9
10 import java.awt.Component JavaDoc;
11 import java.awt.Container JavaDoc;
12
13 import java.util.Hashtable JavaDoc;
14 import java.util.Map JavaDoc;
15 import java.util.Vector JavaDoc;
16
17 import javax.swing.JComponent JavaDoc;
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 JavaDoc;
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 /**
34  *
35  * @author Amy Fowler
36  */

37 public class ContainerElement extends ComponentElement {
38
39     private static final Map JavaDoc attrMap = new Hashtable JavaDoc();
40     private static final Map JavaDoc elementMap = new Hashtable JavaDoc();
41
42     public ContainerElement(Element JavaDoc element, ElementType elementType) {
43         super(element, elementType);
44     }
45
46     public ElementHandler getElementHandler(String JavaDoc namespaceURI, String JavaDoc elementName) {
47         Map JavaDoc handlerMap = getElementHandlerMap();
48         return handlerMap == null ? null : (ElementHandler) handlerMap.get(namespaceURI + ":" + elementName);
49     }
50
51     public AttributeHandler getAttributeHandler(String JavaDoc namespaceURI, String JavaDoc attrName) {
52         Map JavaDoc handlerMap = getAttributeHandlerMap();
53         return handlerMap == null ? null : (AttributeHandler) attrMap.get(namespaceURI + ":" + attrName);
54     }
55
56     protected Map JavaDoc getAttributeHandlerMap() {
57         return attrMap;
58     }
59
60     protected Map JavaDoc getElementHandlerMap() {
61         return elementMap;
62     }
63 /*
64     protected void applyAttributesAfter() {
65         super.applyAttributesAfter();
66         //applyAttribute(Namespace.JDNC, Attributes.ENABLED);
67     }
68 */

69     protected Map JavaDoc registerAttributeHandlers() {
70          Map JavaDoc handlerMap = super.registerAttributeHandlers();
71          if (handlerMap != null) {
72             //handlerMap.put(Namespace.JDNC + ":" + Attributes.COLUMN_DELIMITER, columnDelimiterHandler);
73
}
74          return handlerMap;
75     }
76
77     protected Map JavaDoc registerElementHandlers() {
78         Map JavaDoc 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             Container JavaDoc container = (Container JavaDoc)parent.getObject();
99             Component JavaDoc component = (Component JavaDoc)child.getObject();
100             container.add(component);
101         }
102     };
103
104     // For typecasting entries in a Vector when converted to an array
105

106     protected static final ElementHandler editorElementHandler =
107         new ElementHandler(ElementTypes.EDITOR,
108                            ContainerElement.componentAssimilator);
109
110     protected static final ElementHandler formElementHandler =
111         new ElementHandler(ElementTypes.TABLE,
112                            ContainerElement.componentAssimilator);
113
114     protected static final ElementHandler tableElementHandler =
115         new ElementHandler(ElementTypes.TABLE,
116                            ContainerElement.componentAssimilator);
117
118     protected static final ElementHandler treeTableElementHandler =
119         new ElementHandler(ElementTypes.TREE_TABLE,
120                            ContainerElement.componentAssimilator);
121
122
123 }
124
Popular Tags