01: package net.xoetrope.awt;
02:
03: import java.awt.Graphics;
04: import java.awt.Rectangle;
05: import java.awt.Color;
06: import net.xoetrope.xui.XAttributedComponent;
07: import java.util.Vector;
08: import java.awt.SystemColor;
09:
10: /**
11: * A dummy component type, used if no other component can be found
12: * <p> Copyright (c) Xoetrope Ltd., 2002-2003</p>
13: * <p> $Revision: 1.5 $</p>
14: * <p> License: see License.txt</p>
15: */
16: public class XUnknown extends XLabel implements XAttributedComponent {
17: private Vector attributes;
18: private Vector attributeNames;
19:
20: public XUnknown() {
21: attributes = new Vector();
22: attributeNames = new Vector();
23: attributes.addElement("Unknown");
24: attributeNames.addElement("type");
25:
26: attributeNames.addElement("name");
27: attributes.addElement("");
28:
29: attributeNames.addElement("x");
30: attributes.addElement("0");
31:
32: attributeNames.addElement("y");
33: attributes.addElement("0");
34:
35: attributeNames.addElement("w");
36: attributes.addElement("100");
37:
38: attributeNames.addElement("h");
39: attributes.addElement("20");
40:
41: attributeNames.addElement("style");
42: attributes.addElement("");
43: }
44:
45: public String getTypeName() {
46: return (String) attributes.elementAt(0);
47: }
48:
49: public void paint(Graphics g) {
50: super .paint(g);
51:
52: Rectangle rect = getBounds();
53: g.setColor(SystemColor.control);
54: g.drawRect(0, 0, rect.width - 1, rect.height - 1);
55: }
56:
57: /**
58: * Set one or more attributes of the component.
59: * @param attribName the attribute name
60: * @param attribValue the attribute value
61: */
62: public void setAttribute(String attribName, String attribValue) {
63: String attribNameLwr = attribName.toLowerCase();
64: int numAttribute = attributeNames.size();
65: for (int i = 0; i < numAttribute; i++) {
66: if (((String) attributeNames.elementAt(i))
67: .equals(attribNameLwr)) {
68: attributes.setElementAt(attribValue, i);
69: return;
70: }
71: }
72: attributes.addElement(attribValue);
73: attributeNames.addElement(attribNameLwr);
74: }
75:
76: public String getAttribute(int idx) {
77: return (String) attributes.elementAt(idx);
78: }
79:
80: public String getAttributeName(int idx) {
81: return (String) attributeNames.elementAt(idx);
82: }
83:
84: public int getNumAttributes() {
85: return attributes.size();
86: }
87: }
|