📄 xmlradiopanel.java
字号:
package org.enhydra.jawe.base.panel.panels;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Enumeration;import java.util.List;import javax.swing.Box;import javax.swing.ButtonGroup;import javax.swing.JRadioButton;import org.enhydra.jawe.base.panel.PanelContainer;import org.enhydra.shark.xpdl.XMLAttribute;import org.enhydra.shark.xpdl.XMLComplexChoice;import org.enhydra.shark.xpdl.XMLComplexElement;import org.enhydra.shark.xpdl.XMLElement;/*** Creates a panel with radio buttons.* @author Sasa Bojanic* @author Zoran Milakovic*/public class XMLRadioPanel extends XMLBasicPanel { protected ButtonGroup rGroup; public XMLRadioPanel ( PanelContainer pc, XMLElement myOwner, String title, boolean isVertical, boolean hasBorder, boolean hasEmptyBorder, boolean isEnabled) { super(pc,myOwner,title,false,hasBorder,hasEmptyBorder); boolean rightAllignment = false; if (pc!=null) { rightAllignment=pc.getSettings().getSettingBoolean("XMLBasicPanel.RightAllignment"); } List choices=null; Object moChoosen=null; if (myOwner instanceof XMLAttribute) { choices=PanelUtilities.toXMLElementViewList(pc,((XMLAttribute)myOwner).getChoices(),true); moChoosen=new XMLElementView(pc,myOwner.toValue(),true); } else { choices=PanelUtilities.toXMLElementViewList(pc,((XMLComplexChoice)myOwner).getChoices(),true); XMLElement choosen=((XMLComplexChoice)myOwner).getChoosen(); if (choosen instanceof XMLComplexElement) { moChoosen=new XMLElementView(pc,choosen, XMLElementView.TONAME ); } else { moChoosen=new XMLElementView(pc,choosen, XMLElementView.TOVALUE ); } } XMLPanel bgPanel=new XMLBasicPanel(pc,myOwner,"",isVertical,false,false); int noOfElements=choices.size(); if (noOfElements>2) { int half=noOfElements/2; if (half!=noOfElements/2) half++; if (half>1) { bgPanel.setLayout(new GridLayout(half,half)); } else { int m,n; if (isVertical) { m=2*half; n=1; } else { m=1; n=2*half; } bgPanel.setLayout(new GridLayout(m,n)); } } rGroup = new ButtonGroup(); final XMLPanel p=this; for (int i=0; i<choices.size(); i++) { JRadioButton jr=new JRadioButton(choices.get(i).toString()); if (choices.get(i).equals(moChoosen)) { jr.setSelected(true); } jr.setEnabled( isEnabled ); jr.addActionListener(new ActionListener () { public void actionPerformed(ActionEvent evt){ if (getPanelContainer()==null) return; getPanelContainer().panelChanged(p, evt); } }); // Group the radio buttons. rGroup.add(jr); bgPanel.add(jr); } if (rightAllignment) { add(Box.createHorizontalGlue()); } add(bgPanel); if (!rightAllignment) { add(Box.createHorizontalGlue()); } } public void setElements () { if (!getOwner().isReadOnly()) { if (myOwner instanceof XMLAttribute) { myOwner.setValue(getSelectedItem().toString()); } else { ((XMLComplexChoice)getOwner()).setChoosen((XMLElement)getSelectedItem()); } } } public Object getSelectedItem() { Enumeration e=rGroup.getElements(); int i=0; List choices=null; if (getOwner() instanceof XMLAttribute) { choices=((XMLAttribute)getOwner()).getChoices(); } else { choices=((XMLComplexChoice)getOwner()).getChoices(); } while (e.hasMoreElements()) { JRadioButton jr=(JRadioButton)e.nextElement(); if (jr.isSelected()) { return choices.get(i); } i++; } return null; } public ButtonGroup getButtonGroup () { return rGroup; } public Object getValue () { return getSelectedItem(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -