KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* XMLComboButtonPanel.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 package org.enhydra.jawe.xml.panels;
12
13 import org.enhydra.jawe.xml.*;
14
15 import java.util.*;
16 import javax.swing.*;
17 import java.awt.*;
18 import java.awt.event.*;
19
20 /**
21  * Creates panel with JLabel, JComboBox and shortcut button.
22  */

23 public class XMLComboButtonPanel extends XMLComboPanel {
24
25    protected XMLCollection refCollection=null;
26
27    public XMLComboButtonPanel (XMLElement myOwner,XMLCollection c) {
28       this(myOwner,null,c,XMLPanel.BOX_LAYOUT,false,false);
29    }
30
31    public XMLComboButtonPanel (XMLElement myOwner,Object JavaDoc[] choices,XMLCollection c) {
32       this(myOwner,choices,c,XMLPanel.BOX_LAYOUT,false,false);
33    }
34
35    public XMLComboButtonPanel (XMLElement myOwner,Object JavaDoc[] choices,XMLCollection c,boolean isEditable) {
36       this(myOwner,choices,c,XMLPanel.BOX_LAYOUT,false,isEditable);
37    }
38
39    public XMLComboButtonPanel (XMLElement myOwner,Object JavaDoc[] choices,
40                                XMLCollection c1,int layout,boolean isVertical,boolean isEditable) {
41
42       super(myOwner,choices,layout,isVertical,isEditable);
43
44       final JComboBox jcb=getComboBox();
45
46       refCollection=c1;
47
48       String JavaDoc s=XMLUtil.getLanguageDependentString("DefineKey");
49       double w=0;
50       try {
51          w=getFontMetrics(getFont()).stringWidth(s);
52       } catch(Exception JavaDoc ex) {}
53       double h=getFontMetrics(getFont()).getHeight();
54       w+=25;
55       if (w<30) w=30;
56       Dimension dim=new Dimension((int)w,(int)h);
57
58       XMLButton buttonDefine=new XMLButton(s,"Define",dim);
59       buttonDefine.setAlignmentX(Component.LEFT_ALIGNMENT);
60       buttonDefine.setAlignmentY(Component.BOTTOM_ALIGNMENT);
61       buttonDefine.setEnabled(!myOwner.isReadOnly());
62
63       // action listener for defining new element
64
buttonDefine.addActionListener(new ActionListener(){
65                public void actionPerformed(ActionEvent ae){
66                   Object JavaDoc selected=jcb.getSelectedItem();
67                   XMLElementDialog de=new XMLElementDialog(getDialog(),refCollection.toLabel()+
68                                                               " - "+XMLUtil.getLanguageDependentString("DefiningKey"));
69                   // First, we must call getPanel(), and then getControlledPanel()
70
XMLPanel panelToEdit=refCollection.getPanel();
71                   XMLPanel cp=refCollection.getControlledPanel();
72                   if (cp instanceof XMLTablePanel) {
73                      ((XMLTablePanel)cp).setSelectedElement(selected);
74                   }
75
76                   de.editXMLElement(panelToEdit,false,false);
77                   if (!de.isCanceled()) {
78                      // refresh
79
DefaultComboBoxModel dcbm=new
80                         DefaultComboBoxModel(refCollection.getChoosable().toArray());
81                      jcb.setModel(dcbm);
82                      if (selected!=null) {
83                         try {
84                            jcb.setSelectedItem(selected);
85                         } catch (Exception JavaDoc ex) {}
86                      }
87                   }
88                }
89             });
90
91       add(Box.createRigidArea(new Dimension(10,0)));
92       add(buttonDefine);
93
94    }
95
96 }
97
98
Popular Tags