OSDN Git Service

initial commit
[xdf/git-repos.git] / xdf-swing / src / main / java / jp / ac / aiit / xdf / component / swing / mappers / JMenuItemMapper.java
1 package jp.ac.aiit.xdf.component.swing.mappers;
2
3 import java.util.Map;
4
5 import javax.swing.ImageIcon;
6 import javax.swing.JMenuItem;
7
8 import jp.ac.aiit.xdf.component.swing.attribute.AttributeProcessingUnit;
9 import jp.ac.aiit.xdf.component.swing.attribute.CommonAttributeStore;
10 import jp.ac.aiit.xdf.component.swing.event.KeyEventHandler;
11 import jp.ac.aiit.xdf.component.swing.event.SwingEventHandler;
12 import jp.ac.aiit.xdf.component.swing.event.SwingEventType;
13 import jp.ac.aiit.xdf.core.action.EventHandler;
14
15 /**
16  * menuitemタグをSwingのJMenuItemにマッピングする
17  * 
18  * @author pin.Yuan
19  */
20 public class JMenuItemMapper extends SwingComponentMapperTemplate {
21
22         @Override
23         protected Map<String, AttributeProcessingUnit> initProcessingUnits() {
24                 Map<String, AttributeProcessingUnit> result = CommonAttributeStore.commonAttributes(model);
25                 //result.put("access", new AttributeProcessingUnit(new ReplaceAllProcessor(), new GetValuesProcessor(), new StringValuesConverter()));
26                 
27                 return result;
28         }
29
30         @Override
31         protected Object newComponent() {
32                 JMenuItem menuitem = null;
33                 if (model.hasAttr("image")){
34                         menuitem = new JMenuItem(model.hasAttr("text")? (String)model.attr("text") : " ",
35                                         new ImageIcon(ClassLoader.getSystemResource((String)model.attr("image"))));
36                 } else {
37                         menuitem = new JMenuItem(model.hasAttr("text")? (String)model.attr("text") : " ");
38                 }
39
40                 return menuitem;
41         }
42
43         @Override
44         protected void processingChildComponents() { }
45
46         @Override
47         protected Map<String, EventHandler> intiProcessingAction() {
48                 Map<String, EventHandler> action = SwingEventHandler.commonEvent();
49                 action.put("change", new KeyEventHandler(SwingEventType.ACTIONED));
50                 return action;
51         }
52
53 }