KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > buchuki > ensmer > input > InputEventConverter


1 /*
2  * Copyright 2004 Dusty Phillips
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, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.buchuki.ensmer.input;
17
18 import java.awt.*;
19 import java.awt.event.*;
20 import com.buchuki.ensmer.input.event.*;
21
22 /**
23  * Class to listen to AWT and Swing input events and convert them to
24  * EnsmerInputEvent references to be passed to the InputManager.
25  *
26  * @author Dusty Phillips [dusty@buchuki.com]
27  */

28 public class InputEventConverter implements MouseListener, MouseMotionListener, MouseWheelListener, KeyListener {
29
30     /**
31      * Construct the InputEventConvert with a reference to the InputProcessor that
32      * events should be forwarded to and the Component that is issuing the events
33      *
34      * @param processor the InputProcessor that should receive the converted
35      * EnsmerInputEvents
36      * @param comp the Component that is issuing AWT and Swing input events
37      */

38     public InputEventConverter(InputProcessor processor, Component comp) {
39         this.processor = processor;
40         comp.addMouseListener(this);
41         comp.addMouseMotionListener(this);
42         comp.addMouseWheelListener(this);
43         comp.addKeyListener(this);
44     }
45
46     /**
47      * Ignore MouseClicked events.
48      *
49      * @param e the MouseEvent generated
50      */

51     public void mouseClicked(MouseEvent e) { }
52
53     /**
54      * Ignore MouseEntered events.
55      *
56      * @param e the MouseEvent generated
57      */

58     public void mouseEntered(MouseEvent e) { }
59
60     /**
61      * Ignore mouseExited events.
62      *
63      * @param e the MouseEvent generated
64      */

65     public void mouseExited(MouseEvent e) { }
66
67     /**
68      * Forward mousePressed events to the processor
69      *
70      * @param e the MouseEvent generated
71      */

72     public void mousePressed(MouseEvent e) {
73         processor.processInput(new MousePressEvent(e));
74     }
75
76     /**
77      * Forward mouseReleased events to the processor
78      *
79      * @param e the MouseEvent generated
80      */

81     public void mouseReleased(MouseEvent e) {
82         processor.processInput(new MouseReleaseEvent(e));
83     }
84
85     /**
86      * Convert a drag to a movement and forward to the processor. It is up to the
87      * processor to determine if a mouse button was pressed
88      *
89      * @param e the MouseEvent generated
90      */

91     public void mouseDragged(MouseEvent e) {
92         processor.processInput(new MouseMoveEvent(e));
93     }
94
95     /**
96      * Forward mouseMoved events to the processor
97      *
98      * @param e the MouseEvent generated
99      */

100     public void mouseMoved(MouseEvent e) {
101         processor.processInput(new MouseMoveEvent(e));
102     }
103
104     /**
105      * Forward mouseWheelMoved events tot he processor
106      *
107      * @param e the MouseWheelEvent generated
108      */

109     public void mouseWheelMoved(java.awt.event.MouseWheelEvent JavaDoc e) {
110         processor.processInput(new com.buchuki.ensmer.input.event.MouseWheelEvent(e));
111     }
112
113     /**
114      * Ignore keytyped events.
115      *
116      * @param e the KeyEvent generated
117      */

118     public void keyTyped(KeyEvent e) { }
119
120     /**
121      * Forward keyPressed events to the processor
122      *
123      * @param e the KeyEvent generated
124      */

125     public void keyPressed(KeyEvent e) {
126         processor.processInput(new KeyPressEvent(e));
127     }
128
129     /**
130      * Forward keyReleased events to the processor
131      *
132      * @param e the KeyEvent generated
133      */

134     public void keyReleased(KeyEvent e) {
135         processor.processInput(new KeyReleaseEvent(e));
136     }
137
138     /**
139      * The InputProcessor to forward EnsmerInputEvents to
140      */

141     private InputProcessor processor;
142 }
143
144
Popular Tags