KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > designer > elements > MultiLineBaseDE


1 /*
2  * (c) Rob Gordon 2005.
3  */

4 package org.oddjob.designer.elements;
5
6 import org.oddjob.designer.model.DesignDefinition;
7 import org.oddjob.designer.model.DesignElementAttribute;
8 import org.oddjob.designer.model.TextInput;
9
10
11 /**
12  * This is the base type for a text type that can contain multline text.
13  */

14 abstract public class MultiLineBaseDE extends DesignElementAttribute {
15     
16     private String JavaDoc cache;
17     
18     public boolean hasDetail() {
19         return true;
20     }
21     
22     public DesignDefinition detail() {
23         return new TextInput("Text") {
24             public String JavaDoc getText() {
25                 return cache;
26             }
27             public void setText(String JavaDoc text) {
28                 attribute(text);
29                 this.setChanged();
30                 this.notifyObservers();
31             }
32         };
33     }
34
35     public void attribute(String JavaDoc attr) {
36         cache = attr;
37     }
38     
39     /* (non-Javadoc)
40      * @see org.oddjob.designer.model.DesignElement#attribute()
41      */

42     public String JavaDoc attribute() {
43         if (cache == null) {
44             return cache;
45         }
46         if (cache.indexOf('\n') == -1) {
47             return cache;
48         }
49         return null;
50     }
51     
52     /**
53      * Add text. This method uses the attribute to store text. It will only
54      * be moved to the text field on reading.
55      *
56      * @param text
57      */

58     public void addText(String JavaDoc text) {
59         String JavaDoc sofar = "";
60         if (cache != null) {
61             sofar = attribute();
62         }
63         cache = sofar + text;
64     }
65
66     public String JavaDoc getValue() {
67         if (cache == null) {
68             return cache;
69         }
70         if (cache.indexOf('\n') == -1) {
71             return cache;
72         }
73         return null;
74     }
75     
76     public String JavaDoc text() {
77         if (cache == null) {
78             return null;
79         }
80         if (cache.indexOf('\n') != -1) {
81             return cache;
82         }
83         return null;
84     }
85     
86     public void setValue(String JavaDoc value) {
87         cache = value;
88     }
89     
90     public void clear() {
91         cache = null;
92         super.clear();
93     }
94
95 }
96
Popular Tags