1 /*******************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v0.5
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v05.html
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler;
14 * Generic option description, which can be modified independently from the
15 * component it belongs to.
17 * @deprecated backport 1.0 internal functionality
22 public class ConfigurableOption {
23 private String componentName;
24 private String optionName;
27 private String category;
29 private String description;
30 private int currentValueIndex;
31 private int defaultValueIndex;
32 private String[] possibleValues;
34 // special value for <possibleValues> indicating that
35 // the <currentValueIndex> is the actual value
36 public final static String[] NoDiscreteValue = {};
40 * Initialize an instance of this class according to a specific locale
42 * @param loc java.util.Locale
44 public ConfigurableOption(
48 int currentValueIndex) {
50 this.componentName = componentName;
51 this.optionName = optionName;
52 this.currentValueIndex = currentValueIndex;
54 ResourceBundle resource = null;
56 String location = componentName.substring(0, componentName.lastIndexOf('.'));
57 resource = ResourceBundle.getBundle(location + ".Options", loc); //$NON-NLS-1$
58 } catch (MissingResourceException e) {
59 category = "Missing ressources entries for" + componentName + " options"; //$NON-NLS-1$ //$NON-NLS-2$
60 name = "Missing ressources entries for"+ componentName + " options"; //$NON-NLS-1$ //$NON-NLS-2$
61 description = "Missing ressources entries for" + componentName + " options"; //$NON-NLS-1$ //$NON-NLS-2$
62 possibleValues = new String[0];
65 if (resource == null) return;
67 id = Integer.parseInt(resource.getString(optionName + ".number")); //$NON-NLS-1$
68 } catch (MissingResourceException e) {
70 } catch (NumberFormatException e) {
74 category = resource.getString(optionName + ".category"); //$NON-NLS-1$
75 } catch (MissingResourceException e) {
76 category = "Missing ressources entries for" + componentName + " options"; //$NON-NLS-1$ //$NON-NLS-2$
79 name = resource.getString(optionName + ".name"); //$NON-NLS-1$
80 } catch (MissingResourceException e) {
81 name = "Missing ressources entries for"+ componentName + " options"; //$NON-NLS-1$ //$NON-NLS-2$
84 StringTokenizer tokenizer = new StringTokenizer(resource.getString(optionName + ".possibleValues"), "|"); //$NON-NLS-1$ //$NON-NLS-2$
85 int numberOfValues = Integer.parseInt(tokenizer.nextToken());
86 if(numberOfValues == -1){
87 possibleValues = NoDiscreteValue;
89 possibleValues = new String[numberOfValues];
91 while (tokenizer.hasMoreTokens()) {
92 possibleValues[index] = tokenizer.nextToken();
96 } catch (MissingResourceException e) {
97 possibleValues = new String[0];
98 } catch (NoSuchElementException e) {
99 possibleValues = new String[0];
100 } catch (NumberFormatException e) {
101 possibleValues = new String[0];
104 description = resource.getString(optionName + ".description"); //$NON-NLS-1$
105 } catch (MissingResourceException e) {
106 description = "Missing ressources entries for"+ componentName + " options"; //$NON-NLS-1$ //$NON-NLS-2$
110 * Return a String that represents the localized category of the receiver.
111 * @return java.lang.String
113 public String getCategory() {
117 * Return a String that identifies the component owner (typically the qualified
118 * type name of the class which it corresponds to).
120 * e.g. "org.eclipse.jdt.internal.compiler.api.Compiler"
122 * @return java.lang.String
124 public String getComponentName() {
125 return componentName;
128 * Answer the index (in possibleValues array) of the current setting for this
131 * In case the set of possibleValues is NoDiscreteValue, then this index is the
132 * actual value (e.g. max line lenght set to 80).
136 public int getCurrentValueIndex() {
137 return currentValueIndex;
140 * Answer the index (in possibleValues array) of the default setting for this
143 * In case the set of possibleValues is NoDiscreteValue, then this index is the
144 * actual value (e.g. max line lenght set to 80).
148 public int getDefaultValueIndex() {
149 return defaultValueIndex;
152 * Return an String that represents the localized description of the receiver.
154 * @return java.lang.String
156 public String getDescription() {
160 * Internal ID which allows the configurable component to identify this particular option.
168 * Return a String that represents the localized name of the receiver.
169 * @return java.lang.String
171 public String getName() {
175 * Return an array of String that represents the localized possible values of the receiver.
176 * @return java.lang.String[]
178 public String[] getPossibleValues() {
179 return possibleValues;
182 * Change the index (in possibleValues array) of the current setting for this
185 * In case the set of possibleValues is NoDiscreteValue, then this index is the
186 * actual value (e.g. max line lenght set to 80).
190 public void setValueIndex(int newIndex) {
191 currentValueIndex = newIndex;
193 public String toString() {
194 StringBuffer buffer = new StringBuffer();
195 buffer.append("Configurable option for "); //$NON-NLS-1$
196 buffer.append(this.componentName).append("\n"); //$NON-NLS-1$
197 buffer.append("- category: ").append(this.category).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$
198 buffer.append("- name: ").append(this.name).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$
199 /* display current value */
200 buffer.append("- current value: "); //$NON-NLS-1$
201 if (possibleValues == NoDiscreteValue){
202 buffer.append(this.currentValueIndex);
204 buffer.append(this.possibleValues[this.currentValueIndex]);
206 buffer.append("\n"); //$NON-NLS-1$
208 /* display possible values */
209 if (possibleValues != NoDiscreteValue){
210 buffer.append("- possible values: ["); //$NON-NLS-1$
211 for (int i = 0, max = possibleValues.length; i < max; i++) {
213 buffer.append(", "); //$NON-NLS-1$
214 buffer.append(possibleValues[i]);
216 buffer.append("]\n"); //$NON-NLS-1$
217 buffer.append("- curr. val. index: ").append(currentValueIndex).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$
219 buffer.append("- description: ").append(description).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$
220 return buffer.toString();
223 * Gets the optionName.
224 * @return Returns a String
226 public String getOptionName() {