KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > xml > XMLComplexChoice


1 /* XMLComplexChoice.java
2  *
3  * Authors:
4  * Stefanovic Nenad chupo@iis.ns.ac.yu
5  * Bojanic Sasa sasaboy@neobee.net
6  * Puskas Vladimir vpuskas@eunet.yu
7  * Pilipovic Goran zboniek@uns.ac.yu
8  *
9  */

10
11
12 package org.enhydra.jawe.xml;
13
14 import org.enhydra.jawe.xml.panels.*;
15
16 import org.w3c.dom.*;
17
18 /**
19 * Represents complex type choice of some XML XML.
20 */

21 public class XMLComplexChoice extends XMLChoice {
22    /** Attribute for visual presentation of an object within the panel. */
23    private boolean isComboPanel;
24    /** Attribute for visual presentation of an object within the panel. */
25    private boolean isVertical;
26    /** Attribute for visual presentation of an object within the panel. */
27    private boolean isChoiceVertical;
28    /** Attribute for visual presentation of an object within the panel. */
29    private boolean hasBorder;
30    /** Attribute for visual presentation of an object within the panel. */
31    private boolean hasTitle;
32
33    /**
34    * Creates a new instance of element with the specified name,
35    * specified choices for the element, and with <b>chooseIndex</b>'th
36    * element choosen. All visual attributes are default, and the
37    * 'shortcut' to the dialog for defining the new choice does not exist.
38    *
39    * @param name The name of the 'choice' XML element
40    * that this class represents.
41    * @param choices The possible choices for this element.
42    * @param choosenIndex The index of element to be choosen right after
43    * creation.
44    */

45    public XMLComplexChoice (String JavaDoc name,XMLElement[] choices,int choosenIndex) {
46       this(name,choices,choosenIndex,true);
47    }
48
49    /**
50    * Creates a new instance of element with the specified name,
51    * specified choices for the element, and with <b>chooseIndex</b>'th
52    * element choosen, and with specified panel type (combo or radio).
53    * All other visual attributes are default, and the 'shortcut'
54    * to the dialog for defining the new choice does not exist.
55    *
56    * @param name The name of the 'choice' XML element
57    * that this class represents.
58    * @param choices The possible choices for this element.
59    * @param choosenIndex The index of element to be choosen right after
60    * creation.
61    * @param isComboPanel Indicates if the choices are displayed within the
62    * combo panel, or the radio panel.
63    */

64    public XMLComplexChoice (String JavaDoc name,XMLElement[] choices,int choosenIndex,
65       boolean isComboPanel) {
66
67       this(name,choices,choosenIndex,isComboPanel,true,false,true,true);
68    }
69
70    /**
71    * Creates a new instance of element with the specified name,
72    * specified choices for the element, and with <b>chooseIndex</b>'th
73    * element choosen, and with specified all visual attributes. The
74    * 'shortcut' to the dialog for defining the new choice might exist.
75    *
76    * @param name The name of the 'choice' XML element
77    * that this class represents.
78    * @param choices The possible choices for this element.
79    * @param choosenIndex The index of element to be choosen right after
80    * creation.
81    * @param isComboPanel Indicates if the choices are displayed within the
82    * combo panel, or the radio panel.
83    * @param isVertical Indicates if label will stand left to the combo
84    * panel, or above it.
85    * @param isChoiceVertical Indicates if the panel of choosen element will
86    * be vertical or not.
87    * @param hasBorder Indicates if the panel will have the border
88    * around it's area.
89    * @param hasTitle Indicates if the panel will have the title
90    * for it's area.
91    */

92    public XMLComplexChoice (String JavaDoc name,XMLElement[] choices,int choosenIndex,
93       boolean isComboPanel,boolean isVertical, boolean isChoiceVertical,
94       boolean hasBorder,boolean hasTitle) {
95
96       super(name,choices,choosenIndex);
97       this.isComboPanel=isComboPanel;
98       this.isVertical=isVertical;
99       this.isChoiceVertical=isChoiceVertical;
100       this.hasBorder=hasBorder;
101       this.hasTitle=hasTitle;
102    }
103
104    /**
105    * Indicates if element is empty.
106    *
107    * @return <tt>true</tt> if user haven't defined the element
108    * value within dialog, <tt>false</tt> otherwise.
109    */

110    public boolean isEmpty () {
111       if (choices==null) {
112          return true;
113       } else {
114          if (choosen!=null) {
115             return false;
116          } else {
117             return true;
118          }
119       }
120    }
121
122    public void toXML(Node parent) throws DOMException {
123       //System.out.println("Choosen="+choosen);
124
// Calls the toXML of the choosen element
125
if (choosen!=null) {
126          ((XMLElement)choosen).toXML(parent);
127       }
128    }
129
130    public void fromXML(String JavaDoc choosenName,Node node) {
131 //System.out.println("Processing cmplx choice "+getClass()+" for choosen name="+choosenName);
132
if (choices!=null) {
133          // Search for the element wich name is choosen,
134
// and calls it's fromXML with the 'tagContent'
135
for (int i=0; i<choices.length; i++) {
136             if (((XMLElement)choices[i]).name.equals(choosenName)) {
137                setValue(choices[i]);
138                ((XMLElement)choices[i]).fromXML(node);
139                break;
140             }
141          }
142       }
143    }
144
145    public XMLPanel getPanel () {
146       if (isComboPanel) {
147          return new XMLComboChoicePanel(this,(hasTitle) ? toLabel():"",
148             XMLPanel.BOX_LAYOUT,isVertical,isChoiceVertical,hasBorder);
149       }
150       else {
151          return new XMLRadioChoicePanel(this,(hasTitle) ? toLabel():"",
152             XMLPanel.BOX_LAYOUT,isVertical,isChoiceVertical,hasBorder);
153       }
154    }
155
156    public Object JavaDoc clone () {
157       XMLComplexChoice d=(XMLComplexChoice)super.clone();
158       d.isComboPanel=this.isComboPanel;
159       d.isVertical=this.isVertical;
160       d.isChoiceVertical=this.isChoiceVertical;
161       d.hasBorder=this.hasBorder;
162       d.hasTitle=this.hasTitle;
163       return d;
164    }
165
166 }
167 /* End of XMLComplexChoice.java */
168
Popular Tags