KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: ComponentElement.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.util.Hashtable JavaDoc;
11 import java.util.Map JavaDoc;
12
13 import org.w3c.dom.Element JavaDoc;
14
15 import net.openmarkup.AttributeHandler;
16 import net.openmarkup.ElementAssimilator;
17 import net.openmarkup.ElementHandler;
18 import net.openmarkup.ElementType;
19 import net.openmarkup.Realizable;
20
21 import org.jdesktop.jdnc.markup.Attributes;
22 import org.jdesktop.jdnc.markup.ElementTypes;
23 import org.jdesktop.jdnc.markup.Namespace;
24 import org.jdesktop.jdnc.markup.attr.ComponentAttributes;
25
26 import org.jdesktop.jdnc.JNComponent;
27
28 import javax.swing.JPopupMenu JavaDoc;
29
30 /**
31  *
32  * @author Ramesh Gupta
33  */

34 public class ComponentElement extends ElementProxy {
35     private static final Map JavaDoc attrMap = new Hashtable JavaDoc();
36     private static final Map JavaDoc elementMap = new Hashtable JavaDoc();
37
38     public ComponentElement(Element JavaDoc element, ElementType elementType) {
39         super(element, elementType);
40     }
41
42     protected Map JavaDoc getAttributeHandlerMap() {
43         return attrMap;
44     }
45
46     protected Map JavaDoc getElementHandlerMap() {
47     return elementMap;
48     }
49
50     protected void applyAttributesAfter() {
51         super.applyAttributesAfter();
52         applyAttribute(Namespace.JDNC, Attributes.BACKGROUND);
53         applyAttribute(Namespace.JDNC, Attributes.FOREGROUND);
54         applyAttribute(Namespace.JDNC, Attributes.FONT);
55         applyAttribute(Namespace.JDNC, Attributes.IS_ENABLED);
56         applyAttribute(Namespace.JDNC, Attributes.IS_VISIBLE);
57         applyAttribute(Namespace.JDNC, Attributes.NAME);
58     }
59
60     protected Map JavaDoc registerAttributeHandlers() {
61         Map JavaDoc handlerMap = super.registerAttributeHandlers();
62         if (handlerMap != null) {
63             handlerMap.put(Namespace.JDNC + ":" + Attributes.BACKGROUND, backgroundHandler);
64             handlerMap.put(Namespace.JDNC + ":" + Attributes.FOREGROUND, foregroundHandler);
65             handlerMap.put(Namespace.JDNC + ":" + Attributes.FONT, fontHandler);
66             handlerMap.put(Namespace.JDNC + ":" + Attributes.IS_ENABLED, isEnabledHandler);
67             handlerMap.put(Namespace.JDNC + ":" + Attributes.IS_VISIBLE, isVisibleHandler);
68             handlerMap.put(Namespace.JDNC + ":" + Attributes.NAME, nameHandler);
69         }
70         return handlerMap;
71     }
72
73     protected Map JavaDoc registerElementHandlers() {
74     Map JavaDoc handlerMap = super.registerElementHandlers();
75     if (handlerMap != null) {
76         handlerMap.put(Namespace.JDNC + ":" + ElementTypes.POPUPMENU.getLocalName(),
77                popupElementHandler);
78     }
79     return handlerMap;
80     }
81
82     public static final ElementAssimilator popupAssimilator = new ElementAssimilator() {
83         public void assimilate(Realizable parent, Realizable child) {
84         JNComponent comp = (JNComponent)parent.getObject();
85         JPopupMenu JavaDoc popup = (JPopupMenu JavaDoc)child.getObject();
86         comp.setPopupMenu(popup);
87         }
88     };
89
90     protected static final ElementHandler popupElementHandler =
91     new ElementHandler(ElementTypes.POPUPMENU, ComponentElement.popupAssimilator);
92
93
94     private static final AttributeHandler backgroundHandler =
95         new AttributeHandler(Namespace.JDNC, Attributes.BACKGROUND,
96                  ComponentAttributes.backgroundApplier);
97
98     private static final AttributeHandler foregroundHandler =
99         new AttributeHandler(Namespace.JDNC, Attributes.FOREGROUND,
100                  ComponentAttributes.foregroundApplier);
101
102     private static final AttributeHandler fontHandler =
103         new AttributeHandler(Namespace.JDNC, Attributes.FONT,
104                  ComponentAttributes.fontApplier);
105
106     private static final AttributeHandler isEnabledHandler =
107         new AttributeHandler(Namespace.JDNC, Attributes.IS_ENABLED,
108                  ComponentAttributes.isEnabledApplier);
109
110     private static final AttributeHandler isVisibleHandler =
111         new AttributeHandler(Namespace.JDNC, Attributes.IS_VISIBLE,
112                  ComponentAttributes.isVisibleApplier);
113
114     private static final AttributeHandler nameHandler =
115         new AttributeHandler(Namespace.JDNC, Attributes.NAME, ComponentAttributes.nameApplier);
116 }
117
Popular Tags