File Source: SwingInputHandler.java
/*
P/P * Method: com.dmdirc.addons.ui_swing.components.SwingInputHandler__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.dmdirc.addons.ui_swing.components;
24
25 import com.dmdirc.commandparser.parsers.CommandParser;
26 import com.dmdirc.ui.input.InputHandler;
27 import com.dmdirc.ui.interfaces.InputField;
28 import com.dmdirc.ui.interfaces.InputWindow;
29 import com.dmdirc.addons.ui_swing.Apple;
30 import com.dmdirc.addons.ui_swing.UIUtilities;
31
32 import java.awt.event.ActionEvent;
33 import java.awt.event.KeyEvent;
34 import java.awt.event.KeyListener;
35
36 import javax.swing.AbstractAction;
37 import javax.swing.JComponent;
38 import javax.swing.KeyStroke;
39 import javax.swing.SwingUtilities;
40 import javax.swing.text.JTextComponent;
41
42 /**
43 * Swing input handler.
44 */
/*
P/P * Method: void access$500(SwingInputHandler, String, int, bool, bool)
*
* Preconditions:
* x0 != null
*/
45 public class SwingInputHandler extends InputHandler implements KeyListener {
46
47 /**
48 * Creates a new instance of InputHandler. Adds listeners to the target
49 * that we need to operate.
50 *
51 * @param target The text field this input handler is dealing with.
52 * @param commandParser The command parser to use for this text field.
53 * @param parentWindow The window that owns this input handler
54 */
55 public SwingInputHandler(final InputField target,
56 final CommandParser commandParser, final InputWindow parentWindow) {
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.SwingInputHandler(InputField, CommandParser, InputWindow)
*/
57 super(target, commandParser, parentWindow);
58 }
59
60 /** {@inheritDoc} */
61 @Override
62 protected void addUpHandler() {
/*
P/P * Method: void addUpHandler()
*
* Preconditions:
* init'ed(this.target)
*
* Presumptions:
* com.dmdirc.util.ReturnableThread:getObject(...)@203 != null
* javax.swing.text.JTextComponent:getActionMap(...)@70 != null
* javax.swing.text.JTextComponent:getInputMap(...)@86 != null
* javax.swing.text.JTextComponent:getInputMap(...)@89 != null
*/
63 JTextComponent localTarget = null;
64 if (target instanceof JTextComponent) {
65 localTarget = (JTextComponent) target;
66 } else if (target instanceof SwingInputField) {
67 localTarget = ((SwingInputField) target).getTextField();
68 }
69
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.SwingInputHandler$1(SwingInputHandler)
*/
70 localTarget.getActionMap().put("upArrow", new AbstractAction() {
71
72 /**
73 * A version number for this class. It should be changed whenever the class
74 * structure is changed (or anything else that would prevent serialized
75 * objects being unserialized with the new class).
76 */
77 private static final long serialVersionUID = 1;
78
79 /** {@inheritDoc} */
80 @Override
81 public void actionPerformed(ActionEvent e) {
/*
P/P * Method: void actionPerformed(ActionEvent)
*/
82 doBufferUp();
83 }
84 });
85 if (Apple.isAppleUI()) {
86 localTarget.getInputMap(JComponent.WHEN_FOCUSED).
87 put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "upArrow");
88 } else {
89 localTarget.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).
90 put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "upArrow");
91 }
92 }
93
94 /** {@inheritDoc} */
95 @Override
96 protected void addDownHandler() {
/*
P/P * Method: void addDownHandler()
*
* Preconditions:
* init'ed(this.target)
*
* Presumptions:
* com.dmdirc.util.ReturnableThread:getObject(...)@203 != null
* javax.swing.text.JTextComponent:getActionMap(...)@103 != null
* javax.swing.text.JTextComponent:getInputMap(...)@119 != null
* javax.swing.text.JTextComponent:getInputMap(...)@122 != null
*/
97 JTextComponent localTarget = null;
98 if (target instanceof JTextComponent) {
99 localTarget = (JTextComponent) target;
100 } else if (target instanceof SwingInputField) {
101 localTarget = ((SwingInputField) target).getTextField();
102 }
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.SwingInputHandler$2(SwingInputHandler)
*/
103 localTarget.getActionMap().put("downArrow", new AbstractAction() {
104
105 /**
106 * A version number for this class. It should be changed whenever the class
107 * structure is changed (or anything else that would prevent serialized
108 * objects being unserialized with the new class).
109 */
110 private static final long serialVersionUID = 1;
111
112 /** {@inheritDoc} */
113 @Override
114 public void actionPerformed(ActionEvent e) {
/*
P/P * Method: void actionPerformed(ActionEvent)
*/
115 doBufferDown();
116 }
117 });
118 if (Apple.isAppleUI()) {
119 localTarget.getInputMap(JComponent.WHEN_FOCUSED).
120 put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "downArrow");
121 } else {
122 localTarget.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).
123 put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "downArrow");
124 }
125 }
126
127 /** {@inheritDoc} */
128 @Override
129 protected void addTabHandler() {
/*
P/P * Method: void addTabHandler()
*
* Preconditions:
* init'ed(this.target)
*
* Presumptions:
* com.dmdirc.util.ReturnableThread:getObject(...)@203 != null
* javax.swing.text.JTextComponent:getActionMap(...)@136 != null
* javax.swing.text.JTextComponent:getInputMap(...)@159 != null
*/
130 JTextComponent localTarget = null;
131 if (target instanceof JTextComponent) {
132 localTarget = (JTextComponent) target;
133 } else if (target instanceof SwingInputField) {
134 localTarget = ((SwingInputField) target).getTextField();
135 }
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.SwingInputHandler$3(SwingInputHandler)
*/
136 localTarget.getActionMap().put("tabPressed", new AbstractAction() {
137
138 /**
139 * A version number for this class. It should be changed whenever the class
140 * structure is changed (or anything else that would prevent serialized
141 * objects being unserialized with the new class).
142 */
143 private static final long serialVersionUID = 1;
144
145 /** {@inheritDoc} */
146 @Override
147 public void actionPerformed(ActionEvent e) {
/*
P/P * Method: void actionPerformed(ActionEvent)
*/
148 new LoggingSwingWorker() {
149
150 /** {@inheritDoc} */
151 @Override
152 protected Object doInBackground() throws Exception {
/*
P/P * Method: Object doInBackground()
*
* Postconditions:
* return_value == null
*/
153 doTabCompletion();
154 return null;
155 }
156 }.execute();
157 }
158 });
159 localTarget.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).
160 put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "tabPressed");
161 }
162
163 /** {@inheritDoc} */
164 @Override
165 protected void addEnterHandler() {
/*
P/P * Method: void addEnterHandler()
*
* Preconditions:
* init'ed(this.target)
*
* Presumptions:
* com.dmdirc.util.ReturnableThread:getObject(...)@203 != null
* javax.swing.text.JTextComponent:getActionMap(...)@172 != null
* javax.swing.text.JTextComponent:getInputMap(...)@197 != null
*/
166 JTextComponent localTarget = null;
167 if (target instanceof JTextComponent) {
168 localTarget = (JTextComponent) target;
169 } else if (target instanceof SwingInputField) {
170 localTarget = ((SwingInputField) target).getTextField();
171 }
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.SwingInputHandler$4(SwingInputHandler)
*/
172 localTarget.getActionMap().put("enterButton", new AbstractAction() {
173
174 /**
175 * A version number for this class. It should be changed whenever the class
176 * structure is changed (or anything else that would prevent serialized
177 * objects being unserialized with the new class).
178 */
179 private static final long serialVersionUID = 1;
180
181 /** {@inheritDoc} */
182 @Override
183 public void actionPerformed(final ActionEvent e) {
/*
P/P * Method: void actionPerformed(ActionEvent)
*
* Preconditions:
* this.target != null
*/
184 final String line = target.getText();
185 target.setText("");
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.SwingInputHandler$4$1(SwingInputHandler$4, String)
*
* Postconditions:
* this.val$line == Param_2
* init'ed(this.val$line)
*/
186 new LoggingSwingWorker() {
187
188 /** {@inheritDoc} */
189 @Override
190 protected Object doInBackground() throws Exception {
/*
P/P * Method: Object doInBackground()
*
* Postconditions:
* return_value == null
*/
191 enterPressed(line);
192 return null;
193 }
194 }.execute();
195 }
196 });
197 localTarget.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).
198 put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enterButton");
199 }
200
201 /** {@inheritDoc} */
202 @Override
203 protected void addKeyHandler() {
/*
P/P * Method: void addKeyHandler()
*
* Preconditions:
* this.target != null
*/
204 target.addKeyListener(this);
205 }
206
207 /**
208 * {@inheritDoc}
209 *
210 * @param e Key event
211 */
212 @Override
213 public void keyTyped(final KeyEvent e) {
214 //Ignore
/*
P/P * Method: void keyTyped(KeyEvent)
*/
215 }
216
217 /**
218 * {@inheritDoc}
219 *
220 * @param e Key event
221 */
222 @Override
223 public void keyPressed(final KeyEvent e) {
/*
P/P * Method: void keyPressed(KeyEvent)
*
* Preconditions:
* e != null
* (soft) init'ed(this.flags)
* (soft) this.target != null
*
* Test Vectors:
* this.flags & 8: {0..7}, {8}
* java.awt.event.KeyEvent:getKeyCode(...)@224: {9}, {-231..8, 10..232-1}
* java.awt.event.KeyEvent:getKeyCode(...)@224: {38}, {-231..37, 39..232-1}
* java.awt.event.KeyEvent:getKeyCode(...)@224: {40}, {-231..39, 41..232-1}
* java.awt.event.KeyEvent:getKeyCode(...)@227: {-231..9, 11..232-1}, {10}
*/
224 if (e.getKeyCode() != KeyEvent.VK_TAB && e.getKeyCode() !=
225 KeyEvent.VK_UP && e.getKeyCode() != KeyEvent.VK_DOWN) {
226 final String line = target.getText();
227 if (UIUtilities.isCtrlDown(e) && e.getKeyCode() == KeyEvent.VK_ENTER
228 && (flags & HANDLE_RETURN) == HANDLE_RETURN) {
229 target.setText("");
230 }
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.SwingInputHandler$5(SwingInputHandler, String, KeyEvent)
*
* Postconditions:
* this.val$e == Param_3
* init'ed(this.val$e)
* this.val$line == Param_2
* init'ed(this.val$line)
*/
231 SwingUtilities.invokeLater(new Runnable() {
232
233 /** {@inheritDoc} */
234 @Override
235 public void run() {
/*
P/P * Method: void run()
*
* Preconditions:
* this.val$e != null
*/
236 handleKeyPressed(line, e.getKeyCode(), e.isShiftDown(),
237 UIUtilities.isCtrlDown(e));
238 }
239 });
240 }
241 }
242
243 /**
244 * {@inheritDoc}
245 *
246 * @param e Key event
247 */
248 @Override
249 public void keyReleased(final KeyEvent e) {
250 //Ignore
/*
P/P * Method: void keyReleased(KeyEvent)
*/
251 }
252 }
SofCheck Inspector Build Version : 2.17854
| SwingInputHandler.java |
2009-Jun-25 01:54:24 |
| SwingInputHandler.class |
2009-Sep-02 17:04:15 |
| SwingInputHandler$1.class |
2009-Sep-02 17:04:15 |
| SwingInputHandler$2.class |
2009-Sep-02 17:04:15 |
| SwingInputHandler$3.class |
2009-Sep-02 17:04:15 |
| SwingInputHandler$3$1.class |
2009-Sep-02 17:04:15 |
| SwingInputHandler$4.class |
2009-Sep-02 17:04:15 |
| SwingInputHandler$4$1.class |
2009-Sep-02 17:04:15 |
| SwingInputHandler$5.class |
2009-Sep-02 17:04:15 |