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
20 import java.util.Locale;
21 import java.util.MissingResourceException;
22 import java.util.NoSuchElementException;
23 import java.util.ResourceBundle;
24 import java.util.StringTokenizer;
26 public class ConfigurableOption {
27 private String componentName;
28 private String optionName;
31 private String category;
33 private String description;
34 private int currentValueIndex;
35 private int defaultValueIndex;
36 private String[] possibleValues;
38 // special value for <possibleValues> indicating that
39 // the <currentValueIndex> is the actual value
40 public final static String[] NoDiscreteValue = {};
44 * Initialize an instance of this class according to a specific locale
46 * @param loc java.util.Locale
48 public ConfigurableOption(
52 int currentValueIndex) {
54 this.componentName = componentName;
55 this.optionName = optionName;
56 this.currentValueIndex = currentValueIndex;
58 ResourceBundle resource = null;
60 String location = componentName.substring(0, componentName.lastIndexOf('.'));
61 resource = ResourceBundle.getBundle(location + ".Options", loc); //$NON-NLS-1$
62 } catch (MissingResourceException e) {
63 category = "Missing ressources entries for" + componentName + " options"; //$NON-NLS-1$ //$NON-NLS-2$
64 name = "Missing ressources entries for"+ componentName + " options"; //$NON-NLS-1$ //$NON-NLS-2$
65 description = "Missing ressources entries for" + componentName + " options"; //$NON-NLS-1$ //$NON-NLS-2$
66 possibleValues = new String[0];
69 if (resource == null) return;
71 id = Integer.parseInt(resource.getString(optionName + ".number")); //$NON-NLS-1$
72 } catch (MissingResourceException e) {
74 } catch (NumberFormatException e) {
78 category = resource.getString(optionName + ".category"); //$NON-NLS-1$
79 } catch (MissingResourceException e) {
80 category = "Missing ressources entries for" + componentName + " options"; //$NON-NLS-1$ //$NON-NLS-2$
83 name = resource.getString(optionName + ".name"); //$NON-NLS-1$
84 } catch (MissingResourceException e) {
85 name = "Missing ressources entries for"+ componentName + " options"; //$NON-NLS-1$ //$NON-NLS-2$
88 StringTokenizer tokenizer = new StringTokenizer(resource.getString(optionName + ".possibleValues"), "|"); //$NON-NLS-1$ //$NON-NLS-2$
89 int numberOfValues = Integer.parseInt(tokenizer.nextToken());
90 if(numberOfValues == -1){
91 possibleValues = NoDiscreteValue;
93 possibleValues = new String[numberOfValues];
95 while (tokenizer.hasMoreTokens()) {
96 possibleValues[index] = tokenizer.nextToken();
100 } catch (MissingResourceException e) {
101 possibleValues = new String[0];
102 } catch (NoSuchElementException e) {
103 possibleValues = new String[0];
104 } catch (NumberFormatException e) {
105 possibleValues = new String[0];
108 description = resource.getString(optionName + ".description"); //$NON-NLS-1$
109 } catch (MissingResourceException e) {
110 description = "Missing ressources entries for"+ componentName + " options"; //$NON-NLS-1$ //$NON-NLS-2$
114 * Return a String that represents the localized category of the receiver.
115 * @return java.lang.String
117 public String getCategory() {
121 * Return a String that identifies the component owner (typically the qualified
122 * type name of the class which it corresponds to).
124 * e.g. "org.phpeclipse.phpdt.internal.compiler.api.Compiler"
126 * @return java.lang.String
128 public String getComponentName() {
129 return componentName;
132 * Answer the index (in possibleValues array) of the current setting for this
135 * In case the set of possibleValues is NoDiscreteValue, then this index is the
136 * actual value (e.g. max line lenght set to 80).
140 public int getCurrentValueIndex() {
141 return currentValueIndex;
144 * Answer the index (in possibleValues array) of the default setting for this
147 * In case the set of possibleValues is NoDiscreteValue, then this index is the
148 * actual value (e.g. max line lenght set to 80).
152 public int getDefaultValueIndex() {
153 return defaultValueIndex;
156 * Return an String that represents the localized description of the receiver.
158 * @return java.lang.String
160 public String getDescription() {
164 * Internal ID which allows the configurable component to identify this particular option.
172 * Return a String that represents the localized name of the receiver.
173 * @return java.lang.String
175 public String getName() {
179 * Return an array of String that represents the localized possible values of the receiver.
180 * @return java.lang.String[]
182 public String[] getPossibleValues() {
183 return possibleValues;
186 * Change the index (in possibleValues array) of the current setting for this
189 * In case the set of possibleValues is NoDiscreteValue, then this index is the
190 * actual value (e.g. max line lenght set to 80).
194 public void setValueIndex(int newIndex) {
195 currentValueIndex = newIndex;
197 public String toString() {
198 StringBuffer buffer = new StringBuffer();
199 buffer.append("Configurable option for "); //$NON-NLS-1$
200 buffer.append(this.componentName).append("\n"); //$NON-NLS-1$
201 buffer.append("- category: ").append(this.category).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$
202 buffer.append("- name: ").append(this.name).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$
203 /* display current value */
204 buffer.append("- current value: "); //$NON-NLS-1$
205 if (possibleValues == NoDiscreteValue){
206 buffer.append(this.currentValueIndex);
208 buffer.append(this.possibleValues[this.currentValueIndex]);
210 buffer.append("\n"); //$NON-NLS-1$
212 /* display possible values */
213 if (possibleValues != NoDiscreteValue){
214 buffer.append("- possible values: ["); //$NON-NLS-1$
215 for (int i = 0, max = possibleValues.length; i < max; i++) {
217 buffer.append(", "); //$NON-NLS-1$
218 buffer.append(possibleValues[i]);
220 buffer.append("]\n"); //$NON-NLS-1$
221 buffer.append("- curr. val. index: ").append(currentValueIndex).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$
223 buffer.append("- description: ").append(description).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$
224 return buffer.toString();
227 * Gets the optionName.
228 * @return Returns a String
230 public String getOptionName() {