1 7 8 package org.jdesktop.jdnc.markup.elem; 9 10 import java.awt.BorderLayout ; 11 import java.awt.Component ; 12 import java.awt.Dimension ; 13 14 import java.util.ArrayList ; 15 import java.util.Hashtable ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 import java.util.Map ; 19 import java.util.Vector ; 20 21 import javax.swing.Action ; 22 import javax.swing.JComponent ; 23 import javax.swing.JMenuBar ; 24 import javax.swing.JRootPane ; 25 import javax.swing.JSeparator ; 26 import javax.swing.JToolBar ; 27 28 import net.openmarkup.AttributeHandler; 29 import net.openmarkup.ElementAssimilator; 30 import net.openmarkup.ElementHandler; 31 import net.openmarkup.ElementType; 32 import net.openmarkup.Realizable; 33 34 import org.w3c.dom.Element ; 35 36 import org.jdesktop.jdnc.markup.Attributes; 37 import org.jdesktop.jdnc.markup.ElementTypes; 38 import org.jdesktop.jdnc.markup.Namespace; 39 import org.jdesktop.jdnc.markup.attr.ComponentAttributes; 40 import org.jdesktop.jdnc.markup.attr.RootPaneAttributes; 41 42 import org.jdesktop.swing.JXStatusBar; 43 import org.jdesktop.swing.JXRootPane; 44 45 import org.jdesktop.swing.Application; 46 import org.jdesktop.swing.actions.ActionContainerFactory; 47 import org.jdesktop.swing.actions.ActionManager; 48 49 53 public class RootPaneElement extends ComponentElement { 54 55 private static final Map attrMap = new Hashtable (); 56 private static final Map elementMap = new Hashtable (); 57 58 public RootPaneElement(Element element, ElementType elementType) { 59 super(element, elementType); 60 } 61 62 public ElementHandler getElementHandler(String namespaceURI, String elementName) { 63 Map handlerMap = getElementHandlerMap(); 64 return handlerMap == null ? null : (ElementHandler) handlerMap.get(namespaceURI + ":" + elementName); 65 } 66 67 public AttributeHandler getAttributeHandler(String namespaceURI, String attrName) { 68 Map handlerMap = getAttributeHandlerMap(); 69 return handlerMap == null ? null : (AttributeHandler) attrMap.get(namespaceURI + ":" + attrName); 70 } 71 72 protected Map getAttributeHandlerMap() { 73 return attrMap; 74 } 75 76 protected Map getElementHandlerMap() { 77 return elementMap; 78 } 79 80 protected void applyAttributesBefore() { 81 super.applyAttributesBefore(); 82 applyAttribute(Namespace.JDNC, Attributes.APP); 83 applyAttribute(Namespace.JDNC, Attributes.SIZE); } 85 86 protected Map registerAttributeHandlers() { 87 Map handlerMap = super.registerAttributeHandlers(); 88 if (handlerMap != null) { 89 handlerMap.put(Namespace.JDNC + ":" + Attributes.APP, 90 appHandler); 91 handlerMap.put(Namespace.JDNC + ":" + Attributes.SIZE, 92 sizeHandler); } 94 return handlerMap; 95 } 96 97 protected Map registerElementHandlers() { 98 Map handlerMap = super.registerElementHandlers(); 99 if (handlerMap != null) { 100 handlerMap.put(Namespace.JDNC + ":" + 101 ElementTypes.EDITOR.getLocalName(), 102 editorElementHandler); 103 handlerMap.put(Namespace.JDNC + ":" + 104 ElementTypes.FORM.getLocalName(), 105 formElementHandler); 106 handlerMap.put(Namespace.JDNC + ":" + 107 ElementTypes.SPLIT_PANE.getLocalName(), 108 splitPaneElementHandler); 109 handlerMap.put(Namespace.JDNC + ":" + 110 ElementTypes.TABBED_PANE.getLocalName(), 111 tabbedPaneElementHandler); 112 handlerMap.put(Namespace.JDNC + ":" + 113 ElementTypes.TABLE.getLocalName(), 114 tableElementHandler); 115 handlerMap.put(Namespace.JDNC + ":" + 116 ElementTypes.TREE_TABLE.getLocalName(), 117 treeTableElementHandler); 118 handlerMap.put(Namespace.JDNC + ":" + 119 ElementTypes.COMPONENT_TOOLBAR.getLocalName(), 120 toolBarElementHandler); 121 handlerMap.put(Namespace.JDNC + ":" + 122 ElementTypes.EDITOR.getLocalName(), 123 editorElementHandler); 124 handlerMap.put(Namespace.JDNC + ":" + 125 ElementTypes.MENUBAR.getLocalName(), 126 menuBarElementHandler); 127 handlerMap.put(Namespace.JDNC + ":" + 128 ElementTypes.STATUSBAR.getLocalName(), 129 statusBarElementHandler); 130 } 131 return handlerMap; 132 } 133 134 public static final ElementAssimilator contentComponentAssimilator = new ElementAssimilator() { 135 public void assimilate(Realizable parent, Realizable child) { 136 JXRootPane rootPane = (JXRootPane)parent.getObject(); 137 Component contentComponent = (Component )child.getObject(); 138 rootPane.addComponent(contentComponent); 139 } 140 }; 141 142 public static final ElementAssimilator menuBarAssimilator = new ElementAssimilator() { 143 public void assimilate(Realizable parent, Realizable child) { 144 JRootPane rootPane = (JRootPane )parent.getObject(); 145 JMenuBar menuBar = (JMenuBar )child.getObject(); 146 rootPane.setJMenuBar(menuBar); 147 } 148 }; 149 150 151 157 public static final ElementAssimilator toolBarAssimilator = new ElementAssimilator() { 158 public void assimilate(Realizable parent, Realizable child) { 159 JXRootPane rootPane = (JXRootPane)parent.getObject(); 160 161 Vector entries = (Vector )child.getObject(); 164 Iterator iter = entries.iterator(); 165 List actionlist = new ArrayList (); 166 while (iter.hasNext()) { 167 Object obj = iter.next(); 168 if (obj instanceof Action ) { 169 actionlist.add(((Action )obj).getValue(Action.ACTION_COMMAND_KEY)); 170 } else if (obj instanceof JSeparator ) { 171 actionlist.add(null); 172 } else if (obj instanceof Vector ) { 173 Vector group = (Vector )obj; 175 Iterator i2 = group.iterator(); 176 while (i2.hasNext()) { 177 Action action = (Action )i2.next(); 178 Object value = action.getValue(Action.ACTION_COMMAND_KEY); 179 actionlist.add(value); 180 } 181 } 182 } 183 184 ActionManager manager = Application.getInstance().getActionManager(); 185 ActionContainerFactory factory = manager.getFactory(); 186 187 JToolBar toolBar = factory.createToolBar(actionlist); 188 rootPane.setToolBar(toolBar); 189 } 190 }; 191 192 public static final ElementAssimilator statusBarAssimilator = new ElementAssimilator() { 193 public void assimilate(Realizable parent, Realizable child) { 194 JXRootPane rootPane = (JXRootPane)parent.getObject(); 195 JXStatusBar status = (JXStatusBar)child.getObject(); 196 rootPane.setStatusBar(status); 197 } 198 }; 199 200 201 203 protected static final AttributeHandler appHandler = 204 new AttributeHandler(Namespace.JDNC, Attributes.APP, 205 RootPaneAttributes.appApplier); 206 207 protected static final AttributeHandler sizeHandler = 208 new AttributeHandler(Namespace.JDNC, Attributes.SIZE, 209 ComponentAttributes.sizeApplier); 210 211 protected static final ElementHandler editorElementHandler = 212 new ElementHandler(ElementTypes.EDITOR, 213 RootPaneElement.contentComponentAssimilator); 214 215 protected static final ElementHandler formElementHandler = 216 new ElementHandler(ElementTypes.FORM, 217 RootPaneElement.contentComponentAssimilator); 218 219 protected static final ElementHandler splitPaneElementHandler = 220 new ElementHandler(ElementTypes.SPLIT_PANE, 221 RootPaneElement.contentComponentAssimilator); 222 223 protected static final ElementHandler tabbedPaneElementHandler = 224 new ElementHandler(ElementTypes.TABBED_PANE, 225 RootPaneElement.contentComponentAssimilator); 226 227 protected static final ElementHandler tableElementHandler = 228 new ElementHandler(ElementTypes.TABLE, 229 RootPaneElement.contentComponentAssimilator); 230 231 protected static final ElementHandler treeTableElementHandler = 232 new ElementHandler(ElementTypes.TREE_TABLE, 233 RootPaneElement.contentComponentAssimilator); 234 235 protected static final ElementHandler toolBarElementHandler = 236 new ElementHandler(ElementTypes.COMPONENT_TOOLBAR, 237 RootPaneElement.toolBarAssimilator); 238 239 protected static final ElementHandler statusBarElementHandler = 240 new ElementHandler(ElementTypes.STATUSBAR, 241 RootPaneElement.statusBarAssimilator); 242 243 protected static final ElementHandler menuBarElementHandler = 244 new ElementHandler(ElementTypes.MENUBAR, 245 RootPaneElement.menuBarAssimilator); 246 } 247 | Popular Tags |