Browse Source

Add some source checking to enterPressed action in inputfield.

Fixes issue 4306

Change-Id: Icf1baca52dbf18a53ffdc37a305c3badbcbb5cac
Reviewed-on: http://gerrit.dmdirc.com/1426
Automatic-Compile: Gregory Holmes <greg@dmdirc.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.4
Greg Holmes 14 years ago
parent
commit
7a5ad49789

+ 1
- 1
src/com/dmdirc/addons/ui_swing/components/SwingInputField.java View File

@@ -455,7 +455,7 @@ public class SwingInputField extends JComponent implements InputField,
455 455
     }
456 456
 
457 457
     /**
458
-     * Sets the end index of the selection for this component
458
+     * Sets the end index of the selection for this component.
459 459
      *
460 460
      * @param selectionEnd End index
461 461
      */

+ 23
- 10
src/com/dmdirc/addons/ui_swing/components/SwingInputHandler.java View File

@@ -1,16 +1,16 @@
1 1
 /*
2 2
  * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
- * 
3
+ *
4 4
  * Permission is hereby granted, free of charge, to any person obtaining a copy
5 5
  * of this software and associated documentation files (the "Software"), to deal
6 6
  * in the Software without restriction, including without limitation the rights
7 7
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 8
  * copies of the Software, and to permit persons to whom the Software is
9 9
  * furnished to do so, subject to the following conditions:
10
- * 
10
+ *
11 11
  * The above copyright notice and this permission notice shall be included in
12 12
  * all copies or substantial portions of the Software.
13
- * 
13
+ *
14 14
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 15
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 16
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -25,6 +25,8 @@ package com.dmdirc.addons.ui_swing.components;
25 25
 import com.dmdirc.addons.ui_swing.Apple;
26 26
 import com.dmdirc.addons.ui_swing.UIUtilities;
27 27
 import com.dmdirc.commandparser.parsers.CommandParser;
28
+import com.dmdirc.logger.ErrorLevel;
29
+import com.dmdirc.logger.Logger;
28 30
 import com.dmdirc.ui.input.InputHandler;
29 31
 import com.dmdirc.ui.interfaces.InputField;
30 32
 import com.dmdirc.ui.interfaces.InputWindow;
@@ -233,7 +235,18 @@ public class SwingInputHandler extends InputHandler implements KeyListener {
233 235
                     /** {@inheritDoc} */
234 236
                     @Override
235 237
                     public void run() {
236
-                        if (((JTextField) e.getSource()).isEditable()) {
238
+                        final JTextField source;
239
+                        if (e.getSource() instanceof SwingInputField) {
240
+                            source = ((SwingInputField) e.getSource()).getTextField();
241
+                        } else if (e.getSource() instanceof JTextField) {
242
+                            source = (JTextField) e.getSource();
243
+                        } else {
244
+                            Logger.appError(ErrorLevel.HIGH, "Unable to send "
245
+                                    + "line", new IllegalArgumentException(
246
+                                    "Event is not from known source."));
247
+                            return;
248
+                        }
249
+                        if (source.isEditable()) {
237 250
                             new LoggingSwingWorker() {
238 251
 
239 252
                                 /** {@inheritDoc} */
@@ -259,9 +272,9 @@ public class SwingInputHandler extends InputHandler implements KeyListener {
259 272
         target.addKeyListener(this);
260 273
     }
261 274
 
262
-    /** 
275
+    /**
263 276
      * {@inheritDoc}
264
-     * 
277
+     *
265 278
      * @param e Key event
266 279
      */
267 280
     @Override
@@ -269,9 +282,9 @@ public class SwingInputHandler extends InputHandler implements KeyListener {
269 282
         //Ignore
270 283
     }
271 284
 
272
-    /** 
285
+    /**
273 286
      * {@inheritDoc}
274
-     * 
287
+     *
275 288
      * @param e Key event
276 289
      */
277 290
     @Override
@@ -295,9 +308,9 @@ public class SwingInputHandler extends InputHandler implements KeyListener {
295 308
         }
296 309
     }
297 310
 
298
-    /** 
311
+    /**
299 312
      * {@inheritDoc}
300
-     * 
313
+     *
301 314
      * @param e Key event
302 315
      */
303 316
     @Override

Loading…
Cancel
Save