KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: TabbedPaneElement.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
12 import java.util.Hashtable JavaDoc;
13 import java.util.Map JavaDoc;
14 import java.util.Vector JavaDoc;
15
16 import javax.swing.JComponent JavaDoc;
17 import javax.swing.JTabbedPane 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 TabbedPaneElement 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 TabbedPaneElement(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 /*
65     protected void applyAttributesAfter() {
66         super.applyAttributesAfter();
67         //applyAttribute(Namespace.JDNC, Attributes.ENABLED);
68     }
69 */

70
71     protected Map JavaDoc registerAttributeHandlers() {
72          Map JavaDoc handlerMap = super.registerAttributeHandlers();
73          if (handlerMap != null) {
74
75          }
76          return handlerMap;
77     }
78
79     protected Map JavaDoc registerElementHandlers() {
80         Map JavaDoc 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 JavaDoc tabPane = (JTabbedPane JavaDoc)parent.getObject();
101             Component JavaDoc component = (Component JavaDoc)child.getObject();
102             String JavaDoc 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     // For typecasting entries in a Vector when converted to an array
114

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