OSDN Git Service

initial commit
[xdf/git-repos.git] / xdf-swing / src / main / java / jp / ac / aiit / xdf / component / swing / mappers / JFrameMapper.java
1 package jp.ac.aiit.xdf.component.swing.mappers;
2
3 import java.awt.event.WindowAdapter;
4 import java.awt.event.WindowEvent;
5 import java.util.Map;
6
7 import javax.swing.JFrame;
8 import javax.swing.JMenuBar;
9
10 import jp.ac.aiit.xdf.application.Application;
11 import jp.ac.aiit.xdf.component.swing.attribute.AttributeProcessingUnit;
12 import jp.ac.aiit.xdf.component.swing.attribute.CommonAttributeStore;
13 import jp.ac.aiit.xdf.component.swing.attribute.GetterAttributeProcessor;
14 import jp.ac.aiit.xdf.component.swing.attribute.SetterAttributeProcessor;
15 import jp.ac.aiit.xdf.core.action.EventHandler;
16 import jp.ac.aiit.xdf.core.typeconvert.StringConverter;
17
18 /**
19  * frameタグをSwingのJFrameにマッピングする
20  * 
21  * @author Shunichi Takagi
22  */
23 public class JFrameMapper extends SwingLayoutingComponentMapperTemplate {
24
25         @Override
26         protected Map<String, AttributeProcessingUnit> initProcessingUnits() {
27                 Map<String, AttributeProcessingUnit> result = CommonAttributeStore.commonAttributes(model);
28                 result.put("title", new AttributeProcessingUnit(new SetterAttributeProcessor("setTitle", false), new GetterAttributeProcessor("getTitle"), new StringConverter()));
29                 
30                 return result;
31         }
32
33         @Override
34         protected Object newComponent() {
35                 JFrame frame = new JFrame();
36                 frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
37                 
38                 frame.addWindowListener(new WindowAdapter() {
39                         @Override public void windowClosing(WindowEvent e) {
40                                 Application.getInstance().close( (String) model.rootModel().attr("windowName") );
41                         }
42                 });
43                 
44                 // メニューバーの追加
45                 if (model.hasAttr("menubar")){
46                         JMenuBar menubar = (JMenuBar)model.attr("menubar");
47                         frame.setJMenuBar(menubar);
48                 }
49                 
50                 return frame;
51         }
52
53         @Override
54         protected Map<String, EventHandler> intiProcessingAction() {
55                 // TODO Auto-generated method stub
56                 return null;
57         }
58
59 }