OSDN Git Service

initial commit
[xdf/git-repos.git] / xdf-swing / src / main / java / jp / ac / aiit / xdf / component / swing / mappers / JListMapper.java
1 package jp.ac.aiit.xdf.component.swing.mappers;
2
3 import java.awt.Component;
4 import java.util.Map;
5
6 import javax.swing.JList;
7 import javax.swing.border.Border;
8
9 import jp.ac.aiit.xdf.component.swing.attribute.AttributeProcessingUnit;
10 import jp.ac.aiit.xdf.component.swing.attribute.CommonAttributeStore;
11 import jp.ac.aiit.xdf.component.swing.attribute.GetterAttributeProcessor;
12 import jp.ac.aiit.xdf.component.swing.attribute.SelectedIndexProcessor;
13 import jp.ac.aiit.xdf.component.swing.attribute.SetterAttributeProcessor;
14 import jp.ac.aiit.xdf.component.swing.event.ActionEventHandler;
15 import jp.ac.aiit.xdf.component.swing.event.SwingEventHandler;
16 import jp.ac.aiit.xdf.component.swing.event.SwingEventType;
17 import jp.ac.aiit.xdf.component.swing.typeconvert.BorderConverter;
18 import jp.ac.aiit.xdf.core.action.EventHandler;
19 import jp.ac.aiit.xdf.core.typeconvert.IntegerConverter;
20 import jp.ac.aiit.xdf.core.typeconvert.StringValuesConverter;
21
22 /**
23  * listタグをSwingのJListにマッピングする
24  * 
25  * @author kodama
26  */
27 public class JListMapper extends SwingComponentMapperTemplate {
28
29         @Override
30         protected Map<String, AttributeProcessingUnit> initProcessingUnits() {
31                 Map<String, AttributeProcessingUnit> result = CommonAttributeStore.commonAttributes(model);
32                 result.put("values", new AttributeProcessingUnit(new SetterAttributeProcessor("setListData", false), new GetValuesProcessor(), new StringValuesConverter()));
33                 result.put("border", new AttributeProcessingUnit(new SetterAttributeProcessor("setBorder", Border.class), new GetterAttributeProcessor("getBorder"), new BorderConverter()));
34                 result.put("selected", new AttributeProcessingUnit(new SelectedIndexProcessor(), new GetterAttributeProcessor("getSelectedIndex"), new IntegerConverter()));
35
36                 return result;
37         }
38         
39         @Override
40         protected Object newComponent() {
41                 return new JList();
42         }
43
44         @Override
45         protected void processingChildComponents() { }
46
47         private class GetValuesProcessor extends GetterAttributeProcessor{
48                 public GetValuesProcessor(){
49                         super(null);
50                 }
51                 @Override
52                 public Object invokeGet(Object target, String name) {
53                         JList list = (JList)getComponent();
54                         Component[] components = list.getComponents();
55                         String[] values = new String[components.length];
56                         System.arraycopy(components, 0, values, 0, components.length);
57                         return values;
58                 }
59         }
60
61         @Override
62         protected Map<String, EventHandler> intiProcessingAction() {
63                 Map<String, EventHandler> action = SwingEventHandler.commonEvent();
64                 action.put("change", new ActionEventHandler(SwingEventType.CHANGE));
65                 return action;
66         }
67 }