1 10 11 12 package org.enhydra.jawe.xml; 13 14 import org.enhydra.jawe.xml.panels.*; 15 16 import java.util.*; 17 import javax.swing.*; 18 import java.awt.*; 19 20 import java.io.*; 21 import org.w3c.dom.*; 22 23 33 public class XMLAttribute extends XMLChoice { 34 38 private int XMLTextPanelType=0; 39 40 private String [] choiceNames=null; 41 42 private boolean isComboPanel=true; 43 47 private boolean isVertical=false; 48 49 56 public XMLAttribute (String name) { 57 super(name,null); 58 } 59 60 69 public XMLAttribute (String name,int tpType) { 70 super(name,null); 71 this.XMLTextPanelType=tpType; 72 } 73 74 89 public XMLAttribute (String name,String [] choices,int choosenIndex) { 90 this(name,choices,choosenIndex,true,false); 91 } 92 93 113 public XMLAttribute (String name,String [] choices,int choosenIndex, 114 boolean isComboPanel,boolean isVertical) { 115 116 super(name,(Object [])choices,choosenIndex); 117 this.choiceNames=new String [choices.length]; 118 String nm; 119 for (int i=0; i<choices.length; i++) { 120 nm=XMLUtil.getLanguageDependentString(choices[i]+"Key"); 121 if (nm!=null) { 122 this.choiceNames[i]=nm; 123 } else { 124 this.choiceNames[i]=choices[i]; 125 } 126 } 127 nm=XMLUtil.getLanguageDependentString(choices[choosenIndex]+"Key"); 128 if (nm!=null) { 129 this.choosen=nm; 130 } else { 131 choosen=choices[choosenIndex]; 132 } 133 this.isComboPanel=isComboPanel; 134 this.isVertical=isVertical; 135 } 136 137 146 public Object [] getChoices () { 147 return choiceNames; 148 } 149 150 158 public Object getChoosen() { 159 return choosen; 160 } 161 162 168 public boolean isEmpty () { 169 if (choices==null) { 170 return super.isEmpty(); 171 } else { 172 if (choosen==null || ((choosen instanceof String ) && ((String )choosen).length()==0)) { 173 return true; 174 } else { 175 return false; 176 } 177 } 178 } 179 180 187 public String toString () { 188 if (choices==null) { 189 return super.toString(); 190 } else { 191 if (choosen!=null) { 192 return choosen.toString(); 193 } else { 194 return super.toString(); 195 } 196 } 197 } 198 199 203 public void toXML(Node parent) throws DOMException { 204 if (!isEmpty() || isRequired()) { 206 if (parent!=null) { 207 Attr node = (parent.getOwnerDocument()).createAttribute(name); 208 node.setValue(value.toString().trim()); 209 ((Element) parent).setAttributeNode(node); 210 } 211 } 212 } 213 214 218 public void fromXML(Node node) { 219 super.fromXML(node); 220 if (choices!=null) { 221 for (int i=0; i<choices.length; i++) { 222 if (choices[i].equals(value)) { 223 choosen=choiceNames[i]; 224 break; 225 } 226 } 227 } 228 } 229 230 231 245 public XMLPanel getPanel () { 246 if (choices==null) { 247 if (XMLTextPanelType==1) { 248 return new XMLLocationPanel(this); 249 } else if (XMLTextPanelType==2) { 250 return new XMLTextPanel(this,XMLPanel.BOX_LAYOUT,false,true); 251 } else { 252 return new XMLTextPanel(this,XMLPanel.BOX_LAYOUT, 253 isVertical,false); 254 } 255 } 256 else { 257 if (isComboPanel) { 258 return new XMLComboPanel(this,XMLPanel.BOX_LAYOUT,isVertical); 259 } 260 else { 261 return new XMLRadioPanel(this,toLabel(), 262 XMLPanel.BOX_LAYOUT,isVertical); 263 } 264 } 265 } 266 267 276 public void setValue(Object v) { 277 if (choices==null) { 278 super.setValue(v); 279 } 280 else { 281 if (v!=null) { 282 choosen=v.toString(); 283 boolean choiceFound=false; 284 for (int i=0; i<choiceNames.length; i++) { 285 if (choiceNames[i].equals(choosen.toString())) { 286 value=choices[i]; 287 choiceFound=true; 288 break; 289 } 290 } 291 if (!choiceFound) { 292 value=v; 293 } 294 } else { 295 if (choices!=null && choices.length>0) { 296 value=choices[0]; 297 } 298 } 299 } 300 } 301 302 309 public Object clone () { 310 XMLAttribute d=(XMLAttribute)super.clone(); 311 d.XMLTextPanelType=this.XMLTextPanelType; 312 d.choiceNames=this.choiceNames; 313 d.isComboPanel=this.isComboPanel; 314 return d; 315 } 316 317 public void refreshLabelName () { 318 super.refreshLabelName(); 319 if (choices!=null) { 320 String nm, oldnm; 321 for (int i=0; i<choices.length; i++) { 322 nm=XMLUtil.getLanguageDependentString(choices[i]+"Key"); 323 oldnm=choiceNames[i]; 324 if (nm!=null) { 325 choiceNames[i]=nm; 326 } else { 327 choiceNames[i]=(String )choices[i]; 328 } 329 if (choosen!=null && choosen.toString().equals(oldnm)) { 330 choosen=choiceNames[i]; 331 } 332 } 333 } 334 } 335 336 } 337 338 | Popular Tags |