KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > xml > panels > XMLComboChoicePanel


1 /* XMLComboChoicePanel.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.panels;
13
14 import org.enhydra.jawe.xml.*;
15
16 import java.util.*;
17 import javax.swing.*;
18 import java.awt.*;
19 import java.awt.event.*;
20
21 /**
22 * Creates a combo panel and a panel which type is determined by the
23 * choosen element from combo panel.
24 */

25 public class XMLComboChoicePanel extends XMLPanel{
26
27    protected XMLPanel prevPanel=null;
28    protected XMLComboPanel pCombo;
29    protected JScrollPane jsp;
30
31    public XMLComboChoicePanel (XMLChoice myOwner) {
32       this(myOwner,"");
33    }
34
35    public XMLComboChoicePanel (XMLChoice myOwner,String JavaDoc title) {
36       this(myOwner,title,XMLPanel.BOX_LAYOUT);
37    }
38
39    public XMLComboChoicePanel (XMLChoice myOwner,String JavaDoc title,
40       int layout) {
41       this(myOwner,title,layout,true);
42    }
43
44    public XMLComboChoicePanel (XMLChoice myOwner,String JavaDoc title,
45       int layout,boolean isVertical) {
46       this(myOwner,title,layout,isVertical,false);
47    }
48
49    public XMLComboChoicePanel (XMLChoice myOwner,String JavaDoc title,
50       int layout,boolean isVertical,boolean isChoiceVertical) {
51       this(myOwner,title,layout,isVertical,isChoiceVertical,true);
52    }
53
54    public XMLComboChoicePanel (XMLChoice myOwner,String JavaDoc title,int layout,
55       boolean isVertical,boolean isChoiceVertical,boolean hasBorder) {
56
57       super(myOwner,(myOwner instanceof XMLAttribute) ? 2:3,title,layout,isVertical,hasBorder);
58
59
60       int noOfPanels=2;
61       if (myOwner instanceof XMLAttribute) {
62          noOfPanels=1;
63       }
64
65       pCombo=new XMLComboPanel(myOwner,XMLPanel.BOX_LAYOUT,
66          isChoiceVertical);
67       add(pCombo);
68
69       if (noOfPanels==2) {
70          jsp=new JScrollPane();
71          jsp.setAlignmentX(Component.LEFT_ALIGNMENT);
72          jsp.setAlignmentY(Component.TOP_ALIGNMENT);
73          //jsp.setMinimumSize(new Dimension(250,200));
74
add(jsp);
75
76          final JComboBox jcb=pCombo.getComboBox();
77          jcb.addActionListener(new ActionListener() {
78             public void actionPerformed(ActionEvent ae) {
79                if (prevPanel!=null) {
80                   prevPanel.setElements();
81                   //((XMLElementDialog)prevPanel.getDialog()).notifyListeners(prevPanel.getOwner());
82
}
83                XMLElement choosen;
84                choosen=(XMLElement)jcb.getSelectedItem();
85                if (choosen!=null) {
86                   prevPanel=choosen.getPanel();
87                   jsp.setViewportView(prevPanel);
88                }
89             }
90          });
91          jcb.setSelectedItem(myOwner.getChoosen());
92       }
93
94       if (layout==XMLPanel.BOX_LAYOUT) {
95          if (isVertical) {
96             add(Box.createVerticalGlue());
97          }
98          else {
99             add(Box.createHorizontalGlue());
100          }
101       }
102
103    }
104
105    public boolean checkRequired () {
106       // checking Combo panel
107
boolean isOK=((XMLPanel)getComponent(0)).checkRequired();
108       // checking implementation panel
109
if (!(getOwner() instanceof XMLAttribute)) {
110          JScrollPane jsp=(JScrollPane)getComponent(1);
111          JViewport jvp=(JViewport)jsp.getComponent(0);
112          if (jvp.getComponentCount()>0) {
113             XMLPanel p=(XMLPanel)jvp.getComponent(0);
114             isOK=isOK && p.checkRequired();
115          }
116       }
117       return isOK;
118    }
119
120
121    public void setElements () {
122       // setting Combo panel
123
((XMLPanel)getComponent(0)).setElements();
124       // setting implementation panel
125
if (!(getOwner() instanceof XMLAttribute)) {
126          JScrollPane jsp=(JScrollPane)getComponent(1);
127          JViewport jvp=jsp.getViewport();
128          if (jvp.getComponentCount()>0) {
129             XMLPanel p=(XMLPanel)jvp.getComponent(0);
130             p.setElements();
131          }
132       }
133    }
134
135 }
136
Popular Tags