KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > data > config > ConfigData


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package org.jgap.data.config;
11
12 import java.util.*;
13
14 /**
15  * Class to encapsulate information given by the GUI to a ConfigWriter to
16  * persist.
17  *
18  * @author Siddhartha Azad
19  * @since 2.3
20  * */

21 public class ConfigData {
22   /** String containing the CVS revision. Read out via reflection!*/
23   private final static String JavaDoc CVS_REVISION = "$Revision: 1.5 $";
24
25   private List m_listData;
26
27   private List m_textData;
28
29   // The namespace for the properties file.
30
private String JavaDoc m_ns;
31
32   public ConfigData() {
33     m_listData = Collections.synchronizedList(new ArrayList());
34     m_textData = Collections.synchronizedList(new ArrayList());
35   }
36
37   public void addListData(final String JavaDoc a_name, final List a_values) {
38     ListData ld = new ListData(a_name, a_values);
39     m_listData.add(ld);
40   }
41
42   public void addTextData(final String JavaDoc a_name, final String JavaDoc a_value) {
43     TextData td = new TextData(a_name, a_value);
44     m_textData.add(td);
45   }
46
47   public int getNumLists() {
48     return m_listData.size();
49   }
50
51   public int getNumTexts() {
52     return m_textData.size();
53   }
54
55   /**
56    * Get the name of the list at the specified index.
57    * @param a_index index of the list
58    * @return name of the list at the specified index
59    * @throws IndexOutOfBoundsException when index < 0 or
60    * index >= listData.size()
61    *
62    * @author Siddhartha Azad
63    * @since 2.3
64    * */

65   public String JavaDoc getListNameAt(final int a_index) {
66     ListData ld = (ListData) m_listData.get(a_index);
67     return ld.getName();
68   }
69
70   /**
71    * Get the contents of the list at the specified index.
72    * @param a_index index of the list
73    * @return contents of the list at the specified index.
74    * @throws IndexOutOfBoundsException when index < 0 or
75    * index >= listData.size()
76    *
77    * @author Siddhartha Azad
78    * @since 2.3
79    * */

80   public List getListValuesAt(final int a_index) {
81     ListData ld = (ListData) m_listData.get(a_index);
82     return ld.getListData();
83   }
84
85   /**
86    * Get the name of the text at the specified index.
87    * @param a_index index of the text
88    * @return name of the text at the specified index.
89    * @throws IndexOutOfBoundsException when index < 0 or
90    * index >= textData.size()
91    *
92    * @author Siddhartha Azad
93    * @since 2.3
94    * */

95   public String JavaDoc getTextNameAt(final int a_index) {
96     TextData td = (TextData) m_textData.get(a_index);
97     return td.getName();
98   }
99
100   /**
101    * Get the value of the text at the specified index.
102    * @param a_index index of the text
103    * @return value of the text at the specified index
104    * @throws IndexOutOfBoundsException when index < 0 ||
105    * index >= textData.size()
106    *
107    * @author Siddhartha Azad
108    * @since 2.3
109    * */

110   public String JavaDoc getTextValueAt(final int a_index) {
111     TextData ld = (TextData) m_textData.get(a_index);
112     return ld.getValue();
113   }
114
115   /**
116    * Set the namespace of the Configurable for which this ConfigData is being
117    * used.
118    * @param a_ns namespace of the Configurable to be used while writing the
119    * config file
120    *
121    * @author Siddhartha Azad
122    * @since 2.3
123    * */

124   public void setNS(final String JavaDoc a_ns) {
125     m_ns = a_ns;
126   }
127
128   /**
129    * Get the namespace of the Configurable for which this ConfigData is being
130    * used.
131    * @return The namespace of the Configurable to be used while writing the
132    * config file.
133    *
134    * @author Siddhartha Azad
135    * @since 2.3
136    * */

137   public String JavaDoc getNS() {
138     return m_ns;
139   }
140
141   /**
142    * Data associated with the lists on the GUI.
143    *
144    * @author Siddhartha Azad
145    * @since 2.3
146    * */

147
148   class ListData {
149     // name of the object being configured
150
private String JavaDoc m_name;
151
152     // values selected for this object, to be written in the config file
153
private List m_data;
154
155     /**
156      * Constructor.
157      * @param a_name Name of the object being configured, to be used as the
158      * key in the config properties file.
159      * @param a_data Data associated with the List (Data selected by the user)
160      */

161     ListData(final String JavaDoc a_name, final List a_data) {
162       m_data = a_data;
163       m_name = a_name;
164     }
165
166     public List getListData() {
167       return m_data;
168     }
169
170     public String JavaDoc getName() {
171       return m_name;
172     }
173   }
174   /**
175    * Data associated with the TextFields, on the GUI.
176    *
177    * @author Siddhartha Azad
178    * @since 2.3
179    * */

180   class TextData {
181     // name of the object being configured
182
private String JavaDoc m_textname;
183
184     // value in the text field for this object
185
private String JavaDoc m_textvalue;
186
187     /**
188      * Constructor.
189      * @param a_name name of the object being configured. Will be used as the
190      * key in the config properties file
191      * @param a_value the value in the JTextField (value in the properties file)
192      * */

193     public TextData(final String JavaDoc a_name, final String JavaDoc a_value) {
194       m_textname = a_name;
195       m_textvalue = a_value;
196     }
197
198     public String JavaDoc getName() {
199       return m_textname;
200     }
201
202     public String JavaDoc getValue() {
203       return m_textvalue;
204     }
205   }
206 }
207
Popular Tags