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;
29 private String optionName;
33 private String category;
37 private String description;
39 private int currentValueIndex;
41 private int defaultValueIndex;
43 private String[] possibleValues;
45 // special value for <possibleValues> indicating that
46 // the <currentValueIndex> is the actual value
47 public final static String[] NoDiscreteValue = {};
52 * Initialize an instance of this class according to a specific locale
57 public ConfigurableOption(String componentName, String optionName,
58 Locale loc, int currentValueIndex) {
60 this.componentName = componentName;
61 this.optionName = optionName;
62 this.currentValueIndex = currentValueIndex;
64 ResourceBundle resource = null;
66 String location = componentName.substring(0, componentName
68 resource = ResourceBundle.getBundle(location + ".Options", loc); //$NON-NLS-1$
69 } catch (MissingResourceException e) {
70 category = "Missing ressources entries for" + componentName + " options"; //$NON-NLS-1$ //$NON-NLS-2$
71 name = "Missing ressources entries for" + componentName + " options"; //$NON-NLS-1$ //$NON-NLS-2$
72 description = "Missing ressources entries for" + componentName + " options"; //$NON-NLS-1$ //$NON-NLS-2$
73 possibleValues = new String[0];
79 id = Integer.parseInt(resource.getString(optionName + ".number")); //$NON-NLS-1$
80 } catch (MissingResourceException e) {
82 } catch (NumberFormatException e) {
86 category = resource.getString(optionName + ".category"); //$NON-NLS-1$
87 } catch (MissingResourceException e) {
88 category = "Missing ressources entries for" + componentName + " options"; //$NON-NLS-1$ //$NON-NLS-2$
91 name = resource.getString(optionName + ".name"); //$NON-NLS-1$
92 } catch (MissingResourceException e) {
93 name = "Missing ressources entries for" + componentName + " options"; //$NON-NLS-1$ //$NON-NLS-2$
96 StringTokenizer tokenizer = new StringTokenizer(resource
97 .getString(optionName + ".possibleValues"), "|"); //$NON-NLS-1$ //$NON-NLS-2$
98 int numberOfValues = Integer.parseInt(tokenizer.nextToken());
99 if (numberOfValues == -1) {
100 possibleValues = NoDiscreteValue;
102 possibleValues = new String[numberOfValues];
104 while (tokenizer.hasMoreTokens()) {
105 possibleValues[index] = tokenizer.nextToken();
109 } catch (MissingResourceException e) {
110 possibleValues = new String[0];
111 } catch (NoSuchElementException e) {
112 possibleValues = new String[0];
113 } catch (NumberFormatException e) {
114 possibleValues = new String[0];
117 description = resource.getString(optionName + ".description"); //$NON-NLS-1$
118 } catch (MissingResourceException e) {
119 description = "Missing ressources entries for" + componentName + " options"; //$NON-NLS-1$ //$NON-NLS-2$
124 * Return a String that represents the localized category of the receiver.
126 * @return java.lang.String
128 public String getCategory() {
133 * Return a String that identifies the component owner (typically the
134 * qualified type name of the class which it corresponds to).
136 * e.g. "org.phpeclipse.phpdt.internal.compiler.api.Compiler"
138 * @return java.lang.String
140 public String getComponentName() {
141 return componentName;
145 * Answer the index (in possibleValues array) of the current setting for
146 * this particular option.
148 * In case the set of possibleValues is NoDiscreteValue, then this index is
149 * the actual value (e.g. max line lenght set to 80).
153 public int getCurrentValueIndex() {
154 return currentValueIndex;
158 * Answer the index (in possibleValues array) of the default setting for
159 * this particular option.
161 * In case the set of possibleValues is NoDiscreteValue, then this index is
162 * the actual value (e.g. max line lenght set to 80).
166 public int getDefaultValueIndex() {
167 return defaultValueIndex;
171 * Return an String that represents the localized description of the
174 * @return java.lang.String
176 public String getDescription() {
181 * Internal ID which allows the configurable component to identify this
191 * Return a String that represents the localized name of the receiver.
193 * @return java.lang.String
195 public String getName() {
200 * Return an array of String that represents the localized possible values
203 * @return java.lang.String[]
205 public String[] getPossibleValues() {
206 return possibleValues;
210 * Change the index (in possibleValues array) of the current setting for
211 * this particular option.
213 * In case the set of possibleValues is NoDiscreteValue, then this index is
214 * the actual value (e.g. max line lenght set to 80).
218 public void setValueIndex(int newIndex) {
219 currentValueIndex = newIndex;
222 public String toString() {
223 StringBuffer buffer = new StringBuffer();
224 buffer.append("Configurable option for "); //$NON-NLS-1$
225 buffer.append(this.componentName).append("\n"); //$NON-NLS-1$
226 buffer.append("- category: ").append(this.category).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$
227 buffer.append("- name: ").append(this.name).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$
228 /* display current value */
229 buffer.append("- current value: "); //$NON-NLS-1$
230 if (possibleValues == NoDiscreteValue) {
231 buffer.append(this.currentValueIndex);
233 buffer.append(this.possibleValues[this.currentValueIndex]);
235 buffer.append("\n"); //$NON-NLS-1$
237 /* display possible values */
238 if (possibleValues != NoDiscreteValue) {
239 buffer.append("- possible values: ["); //$NON-NLS-1$
240 for (int i = 0, max = possibleValues.length; i < max; i++) {
242 buffer.append(", "); //$NON-NLS-1$
243 buffer.append(possibleValues[i]);
245 buffer.append("]\n"); //$NON-NLS-1$
247 .append("- curr. val. index: ").append(currentValueIndex).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$
249 buffer.append("- description: ").append(description).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$
250 return buffer.toString();
254 * Gets the optionName.
256 * @return Returns a String
258 public String getOptionName() {