1 11 package org.eclipse.jdt.internal.compiler; 12 13 19 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 ; 25 26 import org.eclipse.jdt.core.compiler.CharOperation; 27 28 public class ConfigurableOption { 29 private String componentName; 30 private String optionName; 31 private int id; 32 33 private String category; 34 private String name; 35 private String description; 36 private int currentValueIndex; 37 private String [] possibleValues; 38 39 public final static String [] NoDiscreteValue = {}; 42 49 public ConfigurableOption( 50 String componentName, 51 String optionName, 52 Locale loc, 53 int currentValueIndex) { 54 55 this.componentName = componentName; 56 this.optionName = optionName; 57 this.currentValueIndex = currentValueIndex; 58 59 ResourceBundle resource = null; 60 try { 61 String location = componentName.substring(0, componentName.lastIndexOf('.')); 62 resource = ResourceBundle.getBundle(location + ".options", loc); } catch (MissingResourceException e) { 64 category = "Missing ressources entries for" + componentName + " options"; name = "Missing ressources entries for"+ componentName + " options"; description = "Missing ressources entries for" + componentName + " options"; possibleValues = CharOperation.NO_STRINGS; 68 id = -1; 69 } 70 if (resource == null) return; 71 try { 72 id = Integer.parseInt(resource.getString(optionName + ".number")); } catch (MissingResourceException e) { 74 id = -1; 75 } catch (NumberFormatException e) { 76 id = -1; 77 } 78 try { 79 category = resource.getString(optionName + ".category"); } catch (MissingResourceException e) { 81 category = "Missing ressources entries for" + componentName + " options"; } 83 try { 84 name = resource.getString(optionName + ".name"); } catch (MissingResourceException e) { 86 name = "Missing ressources entries for"+ componentName + " options"; } 88 try { 89 StringTokenizer tokenizer = new StringTokenizer (resource.getString(optionName + ".possibleValues"), "|"); int numberOfValues = Integer.parseInt(tokenizer.nextToken()); 91 if(numberOfValues == -1){ 92 possibleValues = NoDiscreteValue; 93 } else { 94 possibleValues = new String [numberOfValues]; 95 int index = 0; 96 while (tokenizer.hasMoreTokens()) { 97 possibleValues[index] = tokenizer.nextToken(); 98 index++; 99 } 100 } 101 } catch (MissingResourceException e) { 102 possibleValues = CharOperation.NO_STRINGS; 103 } catch (NoSuchElementException e) { 104 possibleValues = CharOperation.NO_STRINGS; 105 } catch (NumberFormatException e) { 106 possibleValues = CharOperation.NO_STRINGS; 107 } 108 try { 109 description = resource.getString(optionName + ".description"); } catch (MissingResourceException e) { 111 description = "Missing ressources entries for"+ componentName + " options"; } 113 } 114 118 public String getCategory() { 119 return category; 120 } 121 129 public String getComponentName() { 130 return componentName; 131 } 132 141 public int getCurrentValueIndex() { 142 return currentValueIndex; 143 } 144 149 public String getDescription() { 150 return description; 151 } 152 157 public int getID() { 158 return id; 159 } 160 164 public String getName() { 165 return name; 166 } 167 171 public String [] getPossibleValues() { 172 return possibleValues; 173 } 174 181 public void setValueIndex(int newIndex) { 182 currentValueIndex = newIndex; 183 } 184 public String toString() { 185 StringBuffer buffer = new StringBuffer (); 186 buffer.append("Configurable option for "); buffer.append(this.componentName).append("\n"); buffer.append("- category: ").append(this.category).append("\n"); buffer.append("- name: ").append(this.name).append("\n"); 191 buffer.append("- current value: "); if (possibleValues == NoDiscreteValue){ 193 buffer.append(this.currentValueIndex); 194 } else { 195 buffer.append(this.possibleValues[this.currentValueIndex]); 196 } 197 buffer.append("\n"); 199 200 if (possibleValues != NoDiscreteValue){ 201 buffer.append("- possible values: ["); for (int i = 0, max = possibleValues.length; i < max; i++) { 203 if (i != 0) 204 buffer.append(", "); buffer.append(possibleValues[i]); 206 } 207 buffer.append("]\n"); buffer.append("- curr. val. index: ").append(currentValueIndex).append("\n"); } 210 buffer.append("- description: ").append(description).append("\n"); return buffer.toString(); 212 } 213 217 public String getOptionName() { 218 return optionName; 219 } 220 } 221 | Popular Tags |