1 package jp.ac.aiit.xdf.component.swing.event;
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
5 import java.awt.event.FocusEvent;
6 import java.awt.event.FocusListener;
7 import java.awt.event.KeyEvent;
8 import java.awt.event.KeyListener;
9 import java.awt.event.MouseEvent;
10 import java.awt.event.MouseListener;
12 import javax.swing.AbstractButton;
13 import javax.swing.event.ChangeEvent;
14 import javax.swing.event.ChangeListener;
16 import jp.ac.aiit.xdf.core.action.Action;
17 import jp.ac.aiit.xdf.core.model.ObjectModel;
21 * 実コンポーネントにユーザ定義アクションをListenerにてバンディングする
24 public class UIEventListener implements ActionListener, MouseListener, KeyListener, ChangeListener, FocusListener {
25 private ObjectModel model;
26 //private Map<String, Action> actions;
27 private SwingEventType event;
28 private Action action;
36 public UIEventListener(ObjectModel model, SwingEventType event, Action action) {
38 //this.actions = model.getActions();
44 * 発生したイベントに対応づけられたアクションを実行する
45 * @param e 発生したイベントの種類
47 public void invokeAction(SwingEventType e) {
49 * TODO ここで発生したイベントに関する情報をアクションにセットする必要がある。(まずは仕様を決める)
50 * 例としてはKeyEventの場合にどのキーが押されたかや修飾キーが押されていたかどうかなど
52 //Action action = actions.get(event);
53 SwingEvent event = new SwingEvent(e, this.model, param);
55 if( this.action != null ) {
56 this.action.execute(event);
61 public void actionPerformed(ActionEvent e) {
62 if (model.tagname().equals("checkbox")||model.tagname().equals("radio")){
63 AbstractButton checkbox = (AbstractButton)e.getSource();
64 // チェックボックスチェックされた際に、"check"イベントを発生する
65 if (checkbox.isSelected() && event.equals(SwingEventType.CHECK)){
66 this.action.execute(new SwingEvent(SwingEventType.CHECK, this.model, null));
68 // チェックボックスチェック外された際に、"uncheck"イベントを発生する
69 if ((!checkbox.isSelected()) && event.equals(SwingEventType.UNCHECK)){
70 this.action.execute(new SwingEvent(SwingEventType.UNCHECK, this.model, null));
73 this.action.execute(new SwingEvent(SwingEventType.ACTIONED, this.model, null));
78 public void mouseClicked(MouseEvent e) {
79 if (e.getClickCount() == 1){
80 if (event.equals(SwingEventType.CLICK))
81 invokeAction(SwingEventType.CLICK);
82 } else if (e.getClickCount() == 2) {
83 if (event.equals(SwingEventType.DOUBLECLICK))
84 invokeAction(SwingEventType.DOUBLECLICK);
89 public void mouseEntered(MouseEvent e) { }
92 public void mouseExited(MouseEvent e) { }
95 public void mousePressed(MouseEvent e) { }
98 public void mouseReleased(MouseEvent e) { }
101 public void keyTyped(KeyEvent e) {
102 if (model.tagname().equals("textfield")) {
105 if (e.getKeyCode() == KeyEvent.VK_ENTER ){
106 // System.out.println("Key press: enter");
115 } else if (model.tagname().equals("textarea")){
126 public void keyPressed(KeyEvent e) { }
129 public void keyReleased(KeyEvent e) { }
132 public void stateChanged(ChangeEvent e) {
133 invokeAction(SwingEventType.TAB_CHANGE);
137 public void focusGained(FocusEvent e) {
138 if (event.equals(SwingEventType.FOCUS)) {
139 invokeAction(SwingEventType.FOCUS);
144 public void focusLost(FocusEvent e) {
145 if (event.equals(SwingEventType.FOCUSLOSE)) {
146 invokeAction(SwingEventType.FOCUSLOSE);