1 package jp.ac.aiit.xdf.component.swing.mappers;
3 import java.util.HashMap;
6 import javax.swing.ButtonGroup;
7 import javax.swing.JRadioButton;
9 import jp.ac.aiit.xdf.component.swing.attribute.AttributeProcessingUnit;
10 import jp.ac.aiit.xdf.component.swing.attribute.AttributeSetProcessor;
11 import jp.ac.aiit.xdf.component.swing.attribute.CommonAttributeStore;
12 import jp.ac.aiit.xdf.component.swing.attribute.DoNothingAttributeProcessor;
13 import jp.ac.aiit.xdf.component.swing.attribute.GetterAttributeProcessor;
14 import jp.ac.aiit.xdf.component.swing.attribute.ObjectModelAttributeGetProcessor;
15 import jp.ac.aiit.xdf.component.swing.attribute.SetterAttributeProcessor;
16 import jp.ac.aiit.xdf.component.swing.event.ActionEventHandler;
17 import jp.ac.aiit.xdf.component.swing.event.SwingEventHandler;
18 import jp.ac.aiit.xdf.component.swing.event.SwingEventType;
19 import jp.ac.aiit.xdf.core.action.EventHandler;
20 import jp.ac.aiit.xdf.core.typeconvert.BooleanConverter;
21 import jp.ac.aiit.xdf.core.typeconvert.StringConverter;
24 * radioタグをSwingのJRadioButtonにマッピングする
28 public class JRadioButtonMapper extends SwingComponentMapperTemplate {
31 * name属性の値からButtonGroupへの対応。
34 private static Map<String, ButtonGroup> buttonGroups
35 = new HashMap<String, ButtonGroup>();
38 protected Map<String, AttributeProcessingUnit> initProcessingUnits() {
39 Map<String, AttributeProcessingUnit> result = CommonAttributeStore.commonAttributes(model);
40 result.put("name", new AttributeProcessingUnit(new ChangeGroupProcessor(), new ObjectModelAttributeGetProcessor(model), new StringConverter()));
41 result.put("value", new AttributeProcessingUnit(new DoNothingAttributeProcessor(), new ObjectModelAttributeGetProcessor(model), new StringConverter()));
42 result.put("text", new AttributeProcessingUnit(new SetterAttributeProcessor("setText", false), new GetterAttributeProcessor("getText"), new StringConverter()));
43 result.put("checked", new AttributeProcessingUnit(new SetterAttributeProcessor("setSelected", true), new GetterAttributeProcessor("isSelected"), new BooleanConverter()));
50 protected Object newComponent() {
51 return new JRadioButton();
55 protected void processingChildComponents() { }
58 * radioタグのname属性の為のAttributeProcessor。
60 private class ChangeGroupProcessor implements AttributeSetProcessor {
62 public void invokeSet(Object target, String name, Object value) {
63 JRadioButton radio = (JRadioButton)getComponent();
64 //旧所属ButtonGroupからの引揚げ
65 for(ButtonGroup group : buttonGroups.values()){
67 //ButtonGroupがすべてのラジオボタンを失っても、それを残しておく。
70 ButtonGroup group = buttonGroups.get(value);
71 if(group == null) buttonGroups.put((String)value, group = new ButtonGroup());
77 protected Map<String, EventHandler> intiProcessingAction() {
78 Map<String, EventHandler> action = SwingEventHandler.commonEvent();
79 action.put("check", new ActionEventHandler(SwingEventType.CHECK));
80 action.put("uncheck", new ActionEventHandler(SwingEventType.UNCHECK));