1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.uruma.annotation;
17  
18  import java.text.SimpleDateFormat;
19  import java.util.Date;
20  
21  import org.eclipse.swt.events.SelectionEvent;
22  import org.eclipse.swt.widgets.Event;
23  import org.eclipse.swt.widgets.Text;
24  import org.seasar.uruma.core.UrumaConstants;
25  import org.seasar.uruma.renderer.impl.AbstractGUITest;
26  
27  /**
28   * {@link EventListener} のためのテストクラスです。<br />
29   * 
30   * @author bskuroneko
31   */
32  public class EventListenerGUITest extends AbstractGUITest {
33  
34      private SimpleDateFormat format = new SimpleDateFormat("mm:ss.SSS");
35  
36      public Text eventLog;
37  
38      // Button
39      @EventListener(id = "button", type = EventListenerType.SELECTION)
40      public void onButtonSelection() {
41          logEvent("buttonSelection NONE ARGUMENTS");
42      }
43  
44      @EventListener(id = "button", type = EventListenerType.SELECTION)
45      public void onButtonSelection(final Event event) {
46          logEvent("buttonSelection EVENT", event);
47      }
48  
49      @EventListener(id = "button", type = EventListenerType.SELECTION)
50      public void onButtonSelection(final SelectionEvent selectionEvent) {
51          logEvent("buttonSelection SELECTION EVENT", selectionEvent);
52      }
53  
54      @EventListener(id = "button", type = EventListenerType.ACTIVATE)
55      public void onButtonActivate(final Event event) {
56          logEvent("buttonActivate", event);
57      }
58  
59      @EventListener(id = "button", type = EventListenerType.DEACTIVATE)
60      public void onButtonDeactivate(final Event event) {
61          logEvent("buttonDeactivate", event);
62      }
63  
64      @EventListener(id = "button", type = EventListenerType.DISPOSE)
65      public void onButtonDispose(final Event event) {
66          logEvent("buttonDispose", event);
67      }
68  
69      @EventListener(id = "button", type = EventListenerType.HELP)
70      public void onButtonHelp(final Event event) {
71          logEvent("buttonHelp", event);
72      }
73  
74      @EventListener(id = "button", type = EventListenerType.FOCUS_IN)
75      public void onButtonFocusIn(final Event event) {
76          logEvent("buttonFocusIn", event);
77      }
78  
79      @EventListener(id = "button", type = EventListenerType.FOCUS_OUT)
80      public void onButtonFocusOut(final Event event) {
81          logEvent("buttonFocusOut", event);
82      }
83  
84      @EventListener(id = "button", type = EventListenerType.TRAVERSE)
85      public void onButtonTraverse(final Event event) {
86          logEvent("buttonTraverse", event);
87      }
88  
89      @EventListener(id = "button", type = EventListenerType.MOUSE_DOWN)
90      public void onButtonMouseDown(final Event event) {
91          logEvent("buttonMouseDown", event);
92      }
93  
94      @EventListener(id = "button", type = EventListenerType.MOUSE_UP)
95      public void onButtonMouseUp(final Event event) {
96          logEvent("buttonMouseUp", event);
97      }
98  
99      @EventListener(id = "button", type = EventListenerType.MOUSE_DOUBLE_CLICK)
100     public void onButtonMouseDoubleClick(final Event event) {
101         logEvent("buttonMouseDoubleClick", event);
102     }
103 
104     // Shell
105     @EventListener(id = UrumaConstants.SHELL_CID, type = EventListenerType.SHOW)
106     public void onShellShow(final Event event) {
107         logEvent("shellShow", event);
108     }
109 
110     @EventListener(id = UrumaConstants.SHELL_CID, type = EventListenerType.CLOSE)
111     public void onShellClose(final Event event) {
112         logEvent("shellClose", event);
113     }
114 
115     @EventListener(id = UrumaConstants.SHELL_CID, type = EventListenerType.ACTIVATE)
116     public void onShellActivate(final Event event) {
117         logEvent("shellActivate", event);
118     }
119 
120     @EventListener(id = UrumaConstants.SHELL_CID, type = EventListenerType.DEACTIVATE)
121     public void onShellDeactivate(final Event event) {
122         logEvent("shellDeactivate", event);
123     }
124 
125     @EventListener(id = UrumaConstants.SHELL_CID, type = EventListenerType.ICONIFY)
126     public void onShellIconify(final Event event) {
127         logEvent("shellIconify", event);
128     }
129 
130     @EventListener(id = UrumaConstants.SHELL_CID, type = EventListenerType.DEICONIFY)
131     public void onShellDeiconify(final Event event) {
132         logEvent("shellDeiconify", event);
133     }
134 
135     @EventListener(id = UrumaConstants.SHELL_CID, type = EventListenerType.DISPOSE)
136     public void onShellDispose(final Event event) {
137         logEvent("shellDispose", event);
138     }
139 
140     @EventListener(id = UrumaConstants.SHELL_CID, type = EventListenerType.MOVE)
141     public void onShellMove(final Event event) {
142         logEvent("shellMove", event);
143     }
144 
145     @EventListener(id = UrumaConstants.SHELL_CID, type = EventListenerType.RESIZE)
146     public void onShellResize(final Event event) {
147         logEvent("shellResize", event);
148     }
149 
150     @EventListener(id = UrumaConstants.SHELL_CID, type = EventListenerType.HELP)
151     public void onShellHelp(final Event event) {
152         logEvent("shellHelp", event);
153     }
154 
155     @EventListener(id = UrumaConstants.SHELL_CID, type = EventListenerType.FOCUS_IN)
156     public void onShellFocusIn(final Event event) {
157         logEvent("shellFocusIn", event);
158     }
159 
160     @EventListener(id = UrumaConstants.SHELL_CID, type = EventListenerType.FOCUS_OUT)
161     public void onShellFocusOut(final Event event) {
162         logEvent("shellFocusOut", event);
163     }
164 
165     // Mouse
166     @EventListener(id = "mouseLabel", type = EventListenerType.MOUSE_ENTER)
167     public void onLabelMouseEnter(final Event event) {
168         logEvent("labelMouseEnter", event);
169     }
170 
171     @EventListener(id = "mouseLabel", type = EventListenerType.MOUSE_EXIT)
172     public void onLabelMouseExit(final Event event) {
173         logEvent("labelMouseExit", event);
174     }
175 
176     @EventListener(id = "mouseLabel", type = EventListenerType.MOUSE_DOWN)
177     public void onLabelMouseDown(final Event event) {
178         logEvent("labelMouseDown", event);
179     }
180 
181     @EventListener(id = "mouseLabel", type = EventListenerType.MOUSE_UP)
182     public void onLabelMouseUp(final Event event) {
183         logEvent("labelMouseUp", event);
184     }
185 
186     @EventListener(id = "mouseLabel", type = EventListenerType.MOUSE_HOVER)
187     public void onLabelMouseHover(final Event event) {
188         logEvent("labelMouseHover", event);
189     }
190 
191     @EventListener(id = "mouseLabel", type = EventListenerType.MOUSE_DOUBLE_CLICK)
192     public void onLabelMouseDoubleClick(final Event event) {
193         logEvent("labelMouseDoubleClick", event);
194     }
195 
196     @EventListener(id = "mouseLabel", type = EventListenerType.MOUSE_MOVE)
197     public void onLabelMouseMove(final Event event) {
198         logEvent("labelMouseMove", event);
199     }
200 
201     // text
202     @EventListener(id = "text", type = EventListenerType.KEY_DOWN)
203     public void onTextKeyDown(final Event event) {
204         logEvent("textKeyDown", event);
205     }
206 
207     @EventListener(id = "text", type = EventListenerType.KEY_UP)
208     public void onTextKeyUp(final Event event) {
209         logEvent("textKeyUp", event);
210     }
211 
212     @EventListener(id = "text", type = EventListenerType.MODIFY)
213     public void onTextModify(final Event event) {
214         logEvent("textModify", event);
215     }
216 
217     @EventListener(id = "text", type = EventListenerType.VERIFY)
218     public void onTextVerify(final Event event) {
219         logEvent("textVerify", event);
220     }
221 
222     @EventListener(id = "text", type = EventListenerType.MOUSE_WHEEL)
223     public void onTextMouseWheel(final Event event) {
224         logEvent("textMouseWheel", event);
225     }
226 
227     // logger
228     private void logEvent(final String message, final Object event) {
229         logEvent(message + " : " + event.toString());
230     }
231 
232     private void logEvent(final String message) {
233         String dateString = format.format(new Date());
234         StringBuilder log = new StringBuilder(dateString);
235         log.append(" ");
236         log.append(message);
237 
238         if (!eventLog.isDisposed()) {
239             eventLog.append(log.toString());
240             eventLog.append(Text.DELIMITER);
241         }
242         System.out.println(log.toString());
243     }
244 }