1 23 24 package org.gjt.sp.jedit; 25 26 import java.util.*; 27 28 38 public class OptionGroup 39 { 40 41 protected final String name; 43 protected final String label; 44 protected final Vector members; 45 private boolean sort; 46 48 56 public OptionGroup(String name) 57 { 58 this.name = name; 59 label = jEdit.getProperty("options." + name + ".label"); 60 members = new Vector(); 61 } 63 70 public OptionGroup(String name, String label, String options) 71 { 72 this.name = name; 73 this.label = label; 74 members = new Vector(); 75 76 StringTokenizer st = new StringTokenizer(options); 77 while(st.hasMoreTokens()) 78 { 79 String pane = st.nextToken(); 80 addOptionPane(pane); 81 } 82 } 84 public String getName() 86 { 87 return name; 88 } 90 95 public String getLabel() 96 { 97 return label; 98 } 100 public void addOptionGroup(OptionGroup group) 102 { 103 insertionSort(group.getLabel(),group); 104 } 106 public void addOptionPane(OptionPane pane) 108 { 109 String label = jEdit.getProperty("options." 110 + pane.getName() + ".label","NO LABEL PROPERTY: " 111 + pane.getName()); 112 113 insertionSort(label,pane); 114 } 116 public void addOptionPane(String pane) 118 { 119 String label = jEdit.getProperty("options." 120 + pane + ".label","NO LABEL PROPERTY: " 121 + pane); 122 123 insertionSort(label,pane); 124 } 126 public Enumeration getMembers() 128 { 129 return members.elements(); 130 } 132 public Object getMember(int index) 134 { 135 return (index >= 0 && index < members.size()) 136 ? members.elementAt(index) : null; 137 } 139 public int getMemberIndex(Object member) 141 { 142 return members.indexOf(member); 143 } 145 public int getMemberCount() 147 { 148 return members.size(); 149 } 151 156 public void setSort(boolean sort) 157 { 158 this.sort = sort; 159 } 161 163 164 private void insertionSort(String newLabel, Object newObj) 166 { 167 if(sort) 168 { 169 for(int i = 0; i < members.size(); i++) 170 { 171 Object obj = members.elementAt(i); 172 String label; 173 if(obj instanceof OptionPane) 174 { 175 String name = ((OptionPane)obj).getName(); 176 label = jEdit.getProperty("options." 177 + name + ".label","NO LABEL PROPERTY: " 178 + name); 179 } 180 else if(obj instanceof String ) 181 { 182 label = jEdit.getProperty("options." 183 + obj + ".label","NO LABEL PROPERTY: " 184 + obj); 185 } 186 else if(obj instanceof OptionGroup) 187 label = ((OptionGroup)obj).getLabel(); 188 else 189 throw new InternalError (); 190 191 if(newLabel.compareToIgnoreCase(label) < 0) 192 { 193 members.insertElementAt(newObj,i); 194 return; 195 } 196 } 197 } 198 199 members.addElement(newObj); 200 } 202 } 204 | Popular Tags |