1 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 25 public class XMLRadioChoicePanel extends XMLPanel { 26 27 XMLPanel prevPanel=null; 28 29 public XMLRadioChoicePanel (XMLChoice myOwner) { 30 this(myOwner,""); 31 } 32 33 public XMLRadioChoicePanel (XMLChoice myOwner,String title) { 34 this(myOwner,title,XMLPanel.BOX_LAYOUT); 35 } 36 37 public XMLRadioChoicePanel (XMLChoice myOwner,String title, 38 int layout) { 39 this(myOwner,title,layout,true); 40 } 41 42 public XMLRadioChoicePanel (XMLChoice myOwner,String title, 43 int layout,boolean isVertical) { 44 this(myOwner,title,layout,isVertical,true); 45 } 46 47 public XMLRadioChoicePanel (XMLChoice myOwner,String title, 48 int layout,boolean isVertical,boolean isChoiceVertical) { 49 this(myOwner,title,layout,isVertical,isChoiceVertical,true); 50 } 51 52 public XMLRadioChoicePanel (XMLChoice myOwner,String title,int layout, 53 boolean isVertical,boolean isChoiceVertical,boolean hasBorder) { 54 55 super(myOwner,(myOwner instanceof XMLAttribute) ? 2:3,title,layout,isVertical,hasBorder); 56 57 int noOfPanels=2; 58 if (myOwner instanceof XMLAttribute) { 59 noOfPanels=1; 60 } 61 62 XMLRadioPanel pRadio=new XMLRadioPanel(myOwner,"",XMLPanel.BOX_LAYOUT,isChoiceVertical,false); 63 add(pRadio); 64 65 if (noOfPanels==2) { 66 final JScrollPane jsp=new JScrollPane(); 67 jsp.setPreferredSize(new Dimension(600,400)); 68 jsp.setAlignmentX(Component.LEFT_ALIGNMENT); 69 jsp.setAlignmentY(Component.TOP_ALIGNMENT); 70 add(jsp); 71 ButtonGroup bg = pRadio.getButtonGroup(); 72 Enumeration e=bg.getElements(); 73 int i=0; 74 Object [] choices=myOwner.getChoices(); 75 while (e.hasMoreElements()) { 76 final Object choosen=choices[i++]; 77 JRadioButton jr=(JRadioButton)e.nextElement(); 78 jr.addActionListener(new ActionListener() { 79 public void actionPerformed(ActionEvent ae) { 80 if (prevPanel!=null) { 81 prevPanel.setElements(); 82 } 84 if (choosen!=null) { 85 prevPanel=((XMLElement)choosen).getPanel(); 86 jsp.setViewportView(prevPanel); 87 } 88 } 89 }); 90 if (choosen==myOwner.getChoosen()) { 91 jsp.setViewportView(((XMLElement)choosen).getPanel()); 92 jr.setSelected(true); 93 } 94 } 95 } 96 97 if (layout==XMLPanel.BOX_LAYOUT) { 98 if (isVertical) { 99 add(Box.createVerticalGlue()); 100 } 101 else { 102 add(Box.createHorizontalGlue()); 103 } 104 } 105 106 } 107 108 public boolean checkRequired () { 109 boolean isOK=((XMLPanel)getComponent(0)).checkRequired(); 111 if (!(getOwner() instanceof XMLAttribute)) { 113 JScrollPane jsp=(JScrollPane)getComponent(1); 114 JViewport jvp=(JViewport)jsp.getComponent(0); 115 isOK=isOK && ((XMLPanel)jvp.getComponent(0)).checkRequired(); 116 } 117 return isOK; 118 } 119 120 public void setElements () { 121 ((XMLPanel)getComponent(0)).setElements(); 123 if (!(getOwner() instanceof XMLAttribute)) { 125 JScrollPane jsp=(JScrollPane)getComponent(1); 126 JViewport jvp=(JViewport)jsp.getComponent(0); 127 ((XMLPanel)jvp.getComponent(0)).setElements(); 128 } 129 130 } 131 132 } 133 134 135 | Popular Tags |