01: package net.xoetrope.swing;
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., 1998-2004<br>
13: * License: see license.txt
14: * $Revision: 1.4 $
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.add("Unknown");
24: attributeNames.add("type");
25:
26: attributeNames.add("name");
27: attributes.add("");
28:
29: attributeNames.add("x");
30: attributes.add("0");
31:
32: attributeNames.add("y");
33: attributes.add("0");
34:
35: attributeNames.add("w");
36: attributes.add("100");
37:
38: attributeNames.add("h");
39: attributes.add("20");
40:
41: attributeNames.add("style");
42: attributes.add("");
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 int getNumAttributes() {
77: return attributes.size();
78: }
79:
80: public String getAttribute(int idx) {
81: if (idx >= attributes.size())
82: return null;
83: return (String) attributes.elementAt(idx);
84: }
85:
86: public String getAttributeName(int idx) {
87: if (idx >= attributes.size())
88: return null;
89: return (String) attributeNames.elementAt(idx);
90: }
91: }
|