1 10 11 12 package org.enhydra.jawe.xml; 13 14 import org.enhydra.jawe.xml.panels.*; 15 16 70 public class XMLChoice extends XMLElement { 71 72 protected Object choosen; 73 74 protected Object [] choices; 75 76 85 public XMLChoice (String name,Object [] choices) { 86 this(name,choices,0); 87 } 88 89 99 public XMLChoice (String name,Object [] choices,int choosenIndex) { 100 super(name); 101 try { 102 this.choices=choices; 103 this.choosen=choices[choosenIndex]; 104 this.value=choosen; 105 } 106 catch (Exception e) { 107 this.value=""; 108 } 109 } 110 111 119 public void setReadOnly (boolean ro) { 120 super.setReadOnly(ro); 121 if (choices!=null) { 122 for (int i=0; i<choices.length; i++) { 123 if (choices[i] instanceof XMLElement) { 124 ((XMLElement)choices[i]).setReadOnly(ro); 125 } 126 } 127 } 128 } 129 130 136 public void setValue(Object v) { 137 super.setValue(v); 138 choosen=v; 139 } 140 141 147 public Object [] getChoices() { 148 return choices; 149 } 150 151 157 public Object getChoosen() { 158 return choosen; 159 } 160 161 169 public XMLPanel getPanel () { 170 return new XMLComboPanel(this); 171 } 172 173 181 public Object clone () { 182 XMLChoice d=(XMLChoice)super.clone(); 183 184 d.choosen=null; 185 d.choices=null; 186 187 if (this.choices!=null && this.choices.length>0) { 188 if (this.choices[0] instanceof String ) { 189 d.choices=this.choices; 190 d.choosen=this.choosen; 191 } 192 else { 193 d.choices=new Object [this.choices.length]; 194 for (int i=0; i<this.choices.length; i++) { 195 Object och=this.choices[i]; 196 if (och instanceof XMLElement) { 197 XMLElement ch=(XMLElement)this.choices[i]; 198 d.choices[i]=ch.clone(); 199 if (this.choosen==ch) { 200 d.choosen=d.choices[i]; 201 } 203 } else { 204 d.choices[i]=och; 205 if (this.choosen!=null && this.choosen.equals(och)) { 206 d.choosen=d.choices[i]; 207 } 208 } 209 } 210 } 211 } 212 return d; 213 } 214 215 public void refreshLabelName() { 216 super.refreshLabelName(); 217 if (choices!=null) { 218 for (int i=0; i<choices.length; i++) { 219 if (choices[i] instanceof XMLElement) { 220 ((XMLElement) choices[i]).refreshLabelName(); 221 } 222 } 223 } 224 } 225 } 226 227 228 | Popular Tags |