KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > Element


1 package jimm.datavision;
2 import jimm.util.XMLWriter;
3 import java.util.Observer JavaDoc;
4 import java.util.Observable JavaDoc;
5
6 /**
7  * <code>Element</code> is the abstract superclass of <code>Field</code>
8  * and <code>Line</code>. These are the visual elements of a report section.
9  *
10  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
11  */

12
13 public abstract class Element
14     extends Observable JavaDoc
15     implements Writeable, Observer JavaDoc
16 {
17
18 protected Report report;
19 protected Section section;
20 protected boolean visible;
21
22 /**
23  * Constructor. (Though a section knows about it's report, too, often we
24  * create elements with a <code>null</code> section and then add them to
25  * some section later on).
26  *
27  * @param report the report containing this element
28  * @param section the report section containing this element
29  */

30 public Element(Report report, Section section, boolean visible) {
31     this.report = report;
32     this.section = section;
33     this.visible = visible;
34 }
35
36 public void update(Observable JavaDoc o, Object JavaDoc arg) {
37     setChanged();
38     notifyObservers(arg);
39 }
40
41 /**
42  * Returns the section that containts this field.
43  *
44  * @return the section
45  */

46 public Section getSection() { return section; }
47
48 /**
49  * Returns the report that containts this field.
50  *
51  * @return the report
52  */

53 public Report getReport() { return report; }
54
55 /**
56  * Modifies the section to which this field belongs. Only called by
57  * section itself.
58  *
59  * @param s the section
60  */

61 public void setSection(Section s) {
62     if (s != section) {
63     section = s;
64     setChanged();
65     notifyObservers();
66     }
67 }
68
69 /**
70  * Returns the visible state of this element.
71  *
72  * @return the visible state
73  */

74 public boolean isVisible() { return visible; }
75
76 /**
77  * Sets the visibility of this element.
78  *
79  * @param newVisible the new visible state
80  */

81 public void setVisible(boolean newVisible) {
82     if (visible != newVisible) {
83     visible = newVisible;
84     setChanged();
85     notifyObservers();
86     }
87 }
88
89 /**
90  * Writes this element as an XML tag. This abstract method is overridden
91  * by the <code>Field</code> and <code>Line</code> subclasses.
92  *
93  * @param out a writer that knows how to write XML
94  */

95 public abstract void writeXML(XMLWriter out);
96
97 }
98
Popular Tags