KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > adwt > editor > PropertiesEditor


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.adwt.editor;
8
9 import java.awt.Component JavaDoc;
10 import java.io.ByteArrayInputStream JavaDoc;
11 import java.io.ByteArrayOutputStream JavaDoc;
12 import java.io.IOException JavaDoc;
13 import java.util.Properties JavaDoc;
14
15 import javax.swing.JTextArea JavaDoc;
16
17 /**
18  * Description of the Class
19  *
20  * @author Laurent Etiemble
21  * @version $Revision: 1.5 $
22  * @todo Javadoc to complete
23  */

24 public class PropertiesEditor extends GenericEditor
25 {
26    /** Constructor for the PropertiesEditor object */
27    public PropertiesEditor()
28    {
29       this.value = new Properties JavaDoc();
30    }
31
32
33    /**
34     * Getter for the asText attribute
35     *
36     * @return The value of asText attribute
37     */

38    public String JavaDoc getAsText()
39    {
40       ByteArrayOutputStream JavaDoc bytearrayoutputstream = new ByteArrayOutputStream JavaDoc();
41       try
42       {
43          ((Properties JavaDoc) this.value).store(bytearrayoutputstream, "");
44       }
45       catch (IOException JavaDoc ioe)
46       {
47       }
48       return bytearrayoutputstream.toString();
49    }
50
51
52    /**
53     * Getter for the customEditor attribute
54     *
55     * @return The value of customEditor attribute
56     */

57    public Component JavaDoc getCustomEditor()
58    {
59       return new PropertiesView();
60    }
61
62
63    /**
64     * Setter for the asText attribute
65     *
66     * @param s The new value for asText attribute
67     */

68    public void setAsText(String JavaDoc s)
69    {
70       try
71       {
72          ((Properties JavaDoc) this.value).load(new ByteArrayInputStream JavaDoc(s.getBytes()));
73          this.firePropertyChange();
74       }
75       catch (IOException JavaDoc ioe)
76       {
77       }
78    }
79
80
81    /**
82     * Description of the Method
83     *
84     * @return Description of the Returned Value
85     */

86    public boolean supportsCustomEditor()
87    {
88       return true;
89    }
90
91
92    /**
93     * Description of the Class
94     *
95     * @author letiembl
96     * @version $Revision: 1.5 $
97     */

98    protected class PropertiesView extends JTextArea JavaDoc
99    {
100       /** Constructor for the PropertiesView object */
101       public PropertiesView()
102       {
103          super(10, 40);
104          this.setText(PropertiesEditor.this.getAsText());
105       }
106    }
107 }
108
Popular Tags