01: package org.swingml;
02:
03: import java.awt.*;
04:
05: import org.swingml.component.*;
06: import org.w3c.dom.*;
07:
08: /**
09: * @author CrossLogic
10: */
11: public class SwingMLComponentUtilities {
12:
13: /**
14: * Locate and return the JFrameComponent in the given Container's parentage.
15: *
16: * @param aContainer
17: * @return The parent JFrameComponent, if found. Null otherwise.
18: */
19: public static JFrameComponent getJFrameComponent(
20: Container aContainer) {
21: JFrameComponent result = null;
22:
23: while (aContainer != null
24: && !(aContainer instanceof JFrameComponent)) {
25: aContainer = aContainer.getParent();
26: }
27: if (aContainer != null && aContainer instanceof JFrameComponent) {
28: result = (JFrameComponent) aContainer;
29: }
30:
31: return result;
32: }
33:
34: /**
35: * Returns true if the given Node contains a child with the given name.
36: *
37: * @param node
38: * @param name
39: * @return
40: */
41: public static boolean nodeContains(Node node, String name) {
42: boolean result = false;
43:
44: if (node != null && name != null && name.length() > 0) {
45: if (node.hasChildNodes()) {
46: NodeList children = node.getChildNodes();
47: Node child;
48: for (int x = 0; x < children.getLength(); x++) {
49: child = children.item(x);
50: if (child.getNodeName().equals(name)
51: || nodeIs(child, name)
52: || nodeContains(child, name)) {
53: result = true;
54: break;
55: }
56: }
57: }
58: }
59:
60: return result;
61: }
62:
63: public static boolean nodeIs(Node node, String name) {
64: boolean result = false;
65:
66: if (node != null && name != null
67: && node.getAttributes() != null) {
68: if (node.getAttributes().getNamedItem("NAME") != null) {
69: result = node.getAttributes().getNamedItem("NAME")
70: .getNodeValue().equals(name);
71: }
72: }
73:
74: return result;
75: }
76:
77: }
|