KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > discRack > presentation > delements > DComplexElement


1 package discRack.presentation.delements;
2
3 import discRack.presentation.dpanels.*;
4
5 import java.util.*;
6
7 /**
8  * Represents a complex element - element made of simple elements and other
9  * complex elements and gives a panel for editing it's context.
10  *
11  * @author Sasa Bojanic
12  * @version 1.0
13  */

14 public class DComplexElement extends DSimpleElement {
15
16    protected java.util.List JavaDoc complexStructure=new ArrayList();
17
18    public DComplexElement (String JavaDoc name) {
19       super(name);
20    }
21
22    /**
23    * Returns the collection of elements this element is made of.
24    */

25    public Collection toComplexType() {
26       return complexStructure;
27    }
28
29    /**
30    * Returns the collection of strings that represents elements
31    * that this element is made of.
32    */

33    public Collection toComplexTypeValues () {
34       java.util.List JavaDoc l=new ArrayList();
35       Iterator it=complexStructure.iterator();
36       while (it.hasNext()) {
37          DSimpleElement el=(DSimpleElement)it.next();
38          l.add(el.toValue());
39       }
40       return l;
41    }
42
43    /**
44    * Sets the element and all element it is made of to be
45    * read only or not.
46    */

47    public void setReadOnly (boolean ro) {
48       super.setReadOnly(ro);
49       Iterator it=complexStructure.iterator();
50       while (it.hasNext()) {
51          DSimpleElement el=(DSimpleElement)it.next();
52          el.setReadOnly(ro);
53       }
54    }
55
56    public boolean isEmpty () {
57       boolean isEmpty=true;
58       Iterator it=complexStructure.iterator();
59       while (it.hasNext()) {
60          DSimpleElement el=(DSimpleElement)it.next();
61          isEmpty=isEmpty && el.isEmpty();
62       }
63       return isEmpty;
64    }
65
66    public boolean isValid () {
67       boolean isValid=true;
68       Iterator it=complexStructure.iterator();
69       while (it.hasNext()) {
70          DSimpleElement el=(DSimpleElement)it.next();
71          isValid=isValid && el.isValid();
72       }
73       return isValid;
74    }
75
76    public DPanel getPanel () {
77       DSimpleElement[] c=new DSimpleElement[complexStructure.size()];
78       complexStructure.toArray(c);
79       return new DGroupPanel(this,c,toName(),true,true);
80    }
81
82    /** Gets the element that is placed at specified no. within structure. */
83    public DSimpleElement get (int no) {
84       try {
85          return (DSimpleElement)complexStructure.get(no);
86       } catch (Exception JavaDoc ex) {
87          return null;
88       }
89    }
90
91    /**
92    * Sets the element that is placed at specified no. within structure
93    * to the specified value.
94    */

95    public void set (int no,Object JavaDoc value) {
96       DSimpleElement el;
97       try {
98          el=get(no);
99       } catch (Exception JavaDoc ex) {
100          el=null;
101       }
102       if (el != null) {
103          el.setValue(value);
104       }
105    }
106
107
108    /** Gets the element with specified name from stucture. */
109    public DSimpleElement get (String JavaDoc name) {
110       Iterator it=complexStructure.iterator();
111       while (it.hasNext()) {
112          DSimpleElement el=(DSimpleElement)it.next();
113          if (el.name.equals(name)) {
114             return el;
115          }
116       }
117       return null;
118    }
119
120    /**
121    * Sets the element with specified name from stucture to
122    * the specified value.
123    */

124    public void set (String JavaDoc name,Object JavaDoc value) {
125       DSimpleElement el=get(name);
126       if (el != null) {
127          el.setValue(value);
128       }
129    }
130
131    public String JavaDoc toString () {
132       return name;
133    }
134
135    protected void fillStructure () {
136       return;
137    }
138
139 }
Popular Tags