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
     }
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
      * @param selectionEnd End index
460
      * @param selectionEnd End index
461
      */
461
      */

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

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

Loading…
Cancel
Save