1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| package org.ericmignot.modeler.gui; |
19 |
| |
20 |
| import java.awt.BorderLayout; |
21 |
| import java.awt.Dimension; |
22 |
| import java.awt.event.WindowAdapter; |
23 |
| import java.awt.event.WindowEvent; |
24 |
| |
25 |
| import javax.swing.JFrame; |
26 |
| |
27 |
| import org.ericmignot.modeler.Interoperable; |
28 |
| import org.ericmignot.modeler.data.BusinessObject; |
29 |
| import org.ericmignot.modeler.util.action.NotifyableAction; |
30 |
| |
31 |
| public class ModelerFrame extends JFrame implements Interoperable |
32 |
| { |
33 |
| private Controller controller; |
34 |
| |
35 |
1
| public ModelerFrame()
|
36 |
| { |
37 |
1
| this.setTitle(this.getApplicationTitle());
|
38 |
1
| getContentPane().setLayout(new BorderLayout());
|
39 |
1
| addWindowListener(new WindowAdapter()
|
40 |
| { |
41 |
0
| public void windowClosing(WindowEvent e)
|
42 |
| { |
43 |
0
| System.exit(0);
|
44 |
| } |
45 |
| }); |
46 |
1
| this.controller = this.buildController();
|
47 |
1
| this.controller.setInteroperable(this);
|
48 |
1
| this.initController(this.controller);
|
49 |
| |
50 |
1
| this.getContentPane().removeAll();
|
51 |
1
| this.getContentPane().add(controller.createMainPanel(), BorderLayout.CENTER);
|
52 |
| } |
53 |
| |
54 |
1
| public String getApplicationTitle()
|
55 |
| { |
56 |
1
| return "Abstract modeler";
|
57 |
| } |
58 |
1
| public Controller buildController()
|
59 |
| { |
60 |
1
| return new Controller();
|
61 |
| } |
62 |
| |
63 |
1
| public void initController(Controller controller)
|
64 |
| { |
65 |
| |
66 |
| } |
67 |
| |
68 |
1
| public Controller getController()
|
69 |
| { |
70 |
1
| return controller;
|
71 |
| } |
72 |
| |
73 |
0
| public void setData(String xml) throws IllegalArgumentException
|
74 |
| { |
75 |
0
| this.controller.setData(xml);
|
76 |
| } |
77 |
| |
78 |
0
| public String getData()
|
79 |
| { |
80 |
0
| return this.controller.getModel().getXML();
|
81 |
| } |
82 |
| |
83 |
0
| public void fireEvent(String event)
|
84 |
| { |
85 |
0
| if (event != null)
|
86 |
| { |
87 |
0
| System.out.println(event);
|
88 |
| } |
89 |
| } |
90 |
0
| public void fireDoEvent(NotifyableAction action, BusinessObject target)
|
91 |
| { |
92 |
0
| if (action != null)
|
93 |
| { |
94 |
0
| String javascriptCall = action.getDoEvent();
|
95 |
0
| if (javascriptCall != null)
|
96 |
| { |
97 |
0
| if (javascriptCall.indexOf("xml") != -1)
|
98 |
| { |
99 |
0
| javascriptCall = javascriptCall.replaceAll("xml", "\"" + target.getXML() + "\"");
|
100 |
| } |
101 |
0
| fireEvent(javascriptCall);
|
102 |
| } |
103 |
| } |
104 |
| } |
105 |
0
| public void fireUndoEvent(NotifyableAction action, BusinessObject target)
|
106 |
| { |
107 |
0
| if (action != null)
|
108 |
| { |
109 |
0
| String javascriptCall = action.getUndoEvent();
|
110 |
0
| if (javascriptCall != null)
|
111 |
| { |
112 |
0
| if (javascriptCall.indexOf("xml") != -1)
|
113 |
| { |
114 |
0
| javascriptCall = javascriptCall.replaceAll("xml", "\"" + target.getXML() + "\"");
|
115 |
| } |
116 |
0
| fireEvent(javascriptCall);
|
117 |
| } |
118 |
| } |
119 |
| } |
120 |
| |
121 |
| |
122 |
0
| public static void main(String[] arg)
|
123 |
| { |
124 |
0
| ModelerFrame frame = new ModelerFrame();
|
125 |
0
| frame.setSize(new Dimension(558, 386));
|
126 |
0
| frame.setLocation(100, 100);
|
127 |
0
| frame.setVisible(true);
|
128 |
| } |
129 |
| |
130 |
| } |