001: /*
002: * ====================================================================
003: * The JRefactory License, Version 1.0
004: *
005: * Copyright (c) 2001 JRefactory. All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The end-user documentation included with the redistribution,
020: * if any, must include the following acknowledgment:
021: * "This product includes software developed by the
022: * JRefactory (http://www.sourceforge.org/projects/jrefactory)."
023: * Alternately, this acknowledgment may appear in the software itself,
024: * if and wherever such third-party acknowledgments normally appear.
025: *
026: * 4. The names "JRefactory" must not be used to endorse or promote
027: * products derived from this software without prior written
028: * permission. For written permission, please contact seguin@acm.org.
029: *
030: * 5. Products derived from this software may not be called "JRefactory",
031: * nor may "JRefactory" appear in their name, without prior written
032: * permission of Chris Seguin.
033: *
034: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
036: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
037: * DISCLAIMED. IN NO EVENT SHALL THE CHRIS SEGUIN OR
038: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
039: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
040: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
041: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
042: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
043: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
044: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
045: * SUCH DAMAGE.
046: * ====================================================================
047: *
048: * This software consists of voluntary contributions made by many
049: * individuals on behalf of JRefactory. For more information on
050: * JRefactory, please see
051: * <http://www.sourceforge.org/projects/jrefactory>.
052: */
053: package org.acm.seguin.tools.install;
054:
055: import java.awt.Font;
056: import java.awt.GridLayout;
057: import java.io.PrintWriter;
058: import java.util.Iterator;
059: import java.util.List;
060: import java.util.ArrayList;
061: import javax.swing.JLabel;
062: import javax.swing.JPanel;
063: import org.acm.seguin.util.FileSettings;
064: import org.acm.seguin.util.MissingSettingsException;
065:
066: /**
067: * Generic base class containing the setting panel
068: *
069: *@author Chris Seguin
070: *@created September 12, 2001
071: */
072: public abstract class SettingPanel extends JPanel {
073: private List descriptions;
074: private GridLayout gridLayout;
075: private int items;
076: /**
077: * The file settings
078: */
079: protected static FileSettings bundle = null;
080: /**
081: * Description of the Field
082: */
083: protected static Font teletype = null;
084:
085: /**
086: * Constructor for the SettingPanel object
087: */
088: public SettingPanel() {
089: descriptions = new ArrayList();
090: gridLayout = new GridLayout(1, 1);
091: setLayout(gridLayout);
092: items = 0;
093: }
094:
095: /**
096: * Gets the Key attribute of the SettingPanel object
097: *
098: *@return The Key value
099: */
100: public abstract String getKey();
101:
102: /**
103: * Gets the Value attribute of the SettingPanel object
104: *
105: *@return The Value value
106: */
107: public String getValue() {
108: return getDefaultValue();
109: }
110:
111: /**
112: * Gets the DefaultValue attribute of the SettingPanel object
113: *
114: *@return The DefaultValue value
115: */
116: public String getDefaultValue() {
117: if (SettingPanel.bundle == null) {
118: SettingPanel.init();
119: }
120: try {
121: return SettingPanel.bundle.getString(getKey());
122: } catch (MissingSettingsException mse) {
123: return getInitialValue();
124: }
125: }
126:
127: /**
128: * Adds a feature to the Description attribute of the SettingPanel object
129: *
130: *@param value The feature to be added to the Description attribute
131: */
132: public void addDescription(String value) {
133: addDescription(value, true);
134: }
135:
136: /**
137: * Adds a feature to the Description attribute of the SettingPanel object
138: *
139: *@param value The feature to be added to the Description attribute
140: */
141: public void addCodeDescription(String value) {
142: addCodeDescription(value, true);
143: }
144:
145: /**
146: * Generate the settings file for this particular setting
147: *
148: *@param output the output stream
149: */
150: public void generateSetting(PrintWriter output) {
151: printDescription(output);
152: output.println(getKey() + "=" + getValue());
153: output.println("");
154: }
155:
156: /**
157: * Gets the initial value if it is not defined
158: *
159: *@return The InitialValue value
160: */
161: protected abstract String getInitialValue();
162:
163: /**
164: * Adds a feature to the Description attribute of the SettingPanel object
165: *
166: *@param value The feature to be added to the Description attribute
167: *@param show true if this should be displayed
168: */
169: protected void addDescription(String value, boolean show) {
170: descriptions.add(value);
171: if (show) {
172: addLabel(value);
173: }
174: }
175:
176: /**
177: * Adds a feature to the Description attribute of the SettingPanel object
178: *
179: *@param value The feature to be added to the Description attribute
180: *@param show true if this should be displayed
181: */
182: protected void addCodeDescription(String value, boolean show) {
183: descriptions.add(value);
184: if (show) {
185: addCodeLabel(value);
186: }
187: }
188:
189: /**
190: * Increment the number of items in the grid
191: */
192: protected void incrItems() {
193: items++;
194: gridLayout.setRows(items);
195: }
196:
197: /**
198: * Description of the Method
199: *
200: *@param output Description of Parameter
201: */
202: protected void printDescription(PrintWriter output) {
203: Iterator iter = descriptions.iterator();
204: while (iter.hasNext()) {
205: output.println("# " + iter.next());
206: }
207: }
208:
209: /**
210: * Adds a feature to the Label attribute of the SettingPanel object
211: *
212: *@param value The feature to be added to the Label attribute
213: */
214: protected void addLabel(String value) {
215: items++;
216: gridLayout.setColumns(items);
217: add(new JLabel(value));
218: }
219:
220: /**
221: * Adds a feature to the Label attribute of the SettingPanel object
222: *
223: *@param value The feature to be added to the Label attribute
224: */
225: protected void addCodeLabel(String value) {
226: items++;
227: gridLayout.setColumns(items);
228: JLabel temp = new JLabel(value);
229: temp.setFont(teletype);
230: add(temp);
231: }
232:
233: /**
234: * Initialize the file setting singleton
235: */
236: private static synchronized void init() {
237: if (bundle == null) {
238: bundle = FileSettings.getRefactoryPrettySettings();
239: teletype = new Font("monospaced", Font.PLAIN, 12);
240: }
241: }
242:
243: /**
244: * Reload the value from the pretty.settings file
245: */
246: public abstract void reload();
247: }
248: // This is the end of the file
|