01: /* $Id: ChoiceConfigParameter.java,v 1.1.1.1 2002/10/02 18:41:44 wastl Exp $ */
02: package net.wastl.webmail.config;
03:
04: import java.util.*;
05:
06: /*
07: * ChoiceConfigParameter.java
08: *
09: * Created: Sep 1999
10: *
11: * Copyright (C) 1999-2000 Sebastian Schaffert
12: *
13: * This program is free software; you can redistribute it and/or
14: * modify it under the terms of the GNU General Public License
15: * as published by the Free Software Foundation; either version 2
16: * of the License, or (at your option) any later version.
17: *
18: * This program is distributed in the hope that it will be useful,
19: * but WITHOUT ANY WARRANTY; without even the implied warranty of
20: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21: * GNU General Public License for more details.
22: *
23: * You should have received a copy of the GNU General Public License
24: * along with this program; if not, write to the Free Software
25: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26: */
27: /**
28: * Scheme of a parameter that can take one of several choices as value
29: */
30: public class ChoiceConfigParameter extends ConfigParameter {
31:
32: Hashtable possible_values;
33:
34: public ChoiceConfigParameter(String name, String desc) {
35: super (name, null, desc);
36: possible_values = new Hashtable();
37: }
38:
39: public void addChoice(Object choice, String desc) {
40: /* First is default */
41: if (possible_values.isEmpty()) {
42: def_value = choice;
43: }
44: possible_values.put(choice, desc);
45: }
46:
47: public void removeChoice(Object choice) {
48: possible_values.remove(choice);
49: }
50:
51: public Enumeration choices() {
52: return possible_values.keys();
53: }
54:
55: public String getDescription(String choice) {
56: return (String) possible_values.get(choice);
57: }
58:
59: public boolean isPossibleValue(Object value) {
60: Enumeration e = possible_values.keys();
61: boolean flag = false;
62: while (e.hasMoreElements()) {
63: Object o = e.nextElement();
64: if (value.equals(o)) {
65: flag = true;
66: break;
67: }
68: //System.err.println((String)value + " <> " + (String)o);
69: }
70: return flag;
71: }
72:
73: public String getType() {
74: return "choice";
75: }
76: }
|