1 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 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 [] choices,XMLCollection c) { 32 this(myOwner,choices,c,XMLPanel.BOX_LAYOUT,false,false); 33 } 34 35 public XMLComboButtonPanel (XMLElement myOwner,Object [] choices,XMLCollection c,boolean isEditable) { 36 this(myOwner,choices,c,XMLPanel.BOX_LAYOUT,false,isEditable); 37 } 38 39 public XMLComboButtonPanel (XMLElement myOwner,Object [] 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 s=XMLUtil.getLanguageDependentString("DefineKey"); 49 double w=0; 50 try { 51 w=getFontMetrics(getFont()).stringWidth(s); 52 } catch(Exception 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 buttonDefine.addActionListener(new ActionListener(){ 65 public void actionPerformed(ActionEvent ae){ 66 Object selected=jcb.getSelectedItem(); 67 XMLElementDialog de=new XMLElementDialog(getDialog(),refCollection.toLabel()+ 68 " - "+XMLUtil.getLanguageDependentString("DefiningKey")); 69 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 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 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 |