Browse Source

Abstracted JTextField mainly for InputHandler

git-svn-id: http://svn.dmdirc.com/trunk@2897 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Gregory Holmes 16 years ago
parent
commit
7ddb09df31

+ 1
- 2
src/com/dmdirc/ui/dummy/DummyChannelWindow.java View File

@@ -38,7 +38,6 @@ import java.util.Arrays;
38 38
 import java.util.List;
39 39
 
40 40
 import javax.swing.Icon;
41
-import javax.swing.JTextField;
42 41
 
43 42
 /**
44 43
  * Dummy channel window, used for testing.
@@ -89,7 +88,7 @@ public final class DummyChannelWindow implements ChannelWindow {
89 88
 
90 89
     /** {@inheritDoc} */
91 90
     public InputHandler getInputHandler() {
92
-        return new InputHandler(new JTextField(), getCommandParser(), this);
91
+        return new InputHandler(new DummyInputField(), getCommandParser(), this);
93 92
     }
94 93
 
95 94
     /** {@inheritDoc} */

+ 113
- 0
src/com/dmdirc/ui/dummy/DummyInputField.java View File

@@ -0,0 +1,113 @@
1
+/*
2
+ * Copyright (c) 2006-2007 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.ui.dummy;
24
+
25
+import com.dmdirc.ui.interfaces.InputField;
26
+
27
+import java.awt.Color;
28
+import java.awt.event.ActionListener;
29
+import java.awt.event.KeyListener;
30
+
31
+/**
32
+ * Dummy input field.
33
+ */
34
+public class DummyInputField implements InputField {
35
+
36
+    /** {@inheritDoc} */
37
+    @Override
38
+    public void addActionListener(ActionListener listener) {
39
+        throw new UnsupportedOperationException("Not supported yet.");
40
+    }
41
+
42
+    /** {@inheritDoc} */
43
+    @Override
44
+    public void addKeyListener(KeyListener listener) {
45
+        throw new UnsupportedOperationException("Not supported yet.");
46
+    }
47
+
48
+    /** {@inheritDoc} */
49
+    @Override
50
+    public void removeActionListener(ActionListener listener) {
51
+        throw new UnsupportedOperationException("Not supported yet.");
52
+    }
53
+
54
+    /** {@inheritDoc} */
55
+    @Override
56
+    public void removeKeyListener(KeyListener listener) {
57
+        throw new UnsupportedOperationException("Not supported yet.");
58
+    }
59
+
60
+    /** {@inheritDoc} */
61
+    @Override
62
+    public String getSelectedText() {
63
+        throw new UnsupportedOperationException("Not supported yet.");
64
+    }
65
+
66
+    /** {@inheritDoc} */
67
+    @Override
68
+    public int getSelectionEnd() {
69
+        throw new UnsupportedOperationException("Not supported yet.");
70
+    }
71
+
72
+    /** {@inheritDoc} */
73
+    @Override
74
+    public int getSelectionStart() {
75
+        throw new UnsupportedOperationException("Not supported yet.");
76
+    }
77
+
78
+    /** {@inheritDoc} */
79
+    @Override
80
+    public String getText() {
81
+        throw new UnsupportedOperationException("Not supported yet.");
82
+    }
83
+
84
+    /** {@inheritDoc} */
85
+    @Override
86
+    public void setText(String text) {
87
+        throw new UnsupportedOperationException("Not supported yet.");
88
+    }
89
+
90
+    /** {@inheritDoc} */
91
+    @Override
92
+    public int getCaretPosition() {
93
+        throw new UnsupportedOperationException("Not supported yet.");
94
+    }
95
+
96
+    /** {@inheritDoc} */
97
+    @Override
98
+    public void setCaretPosition(int position) {
99
+        throw new UnsupportedOperationException("Not supported yet.");
100
+    }
101
+
102
+    /** {@inheritDoc} */
103
+    @Override
104
+    public void showColourPicker(boolean irc, boolean hex) {
105
+        throw new UnsupportedOperationException("Not supported yet.");
106
+    }
107
+
108
+    /** {@inheritDoc} */
109
+    @Override
110
+    public void hideColourPicker() {
111
+        throw new UnsupportedOperationException("Not supported yet.");
112
+    }
113
+}

+ 1
- 2
src/com/dmdirc/ui/dummy/DummyInputWindow.java View File

@@ -36,7 +36,6 @@ import java.nio.charset.Charset;
36 36
 import java.util.Arrays;
37 37
 
38 38
 import javax.swing.Icon;
39
-import javax.swing.JTextField;
40 39
 
41 40
 /**
42 41
  * Dummy input window, used for testing.
@@ -70,7 +69,7 @@ public final class DummyInputWindow implements InputWindow {
70 69
     
71 70
     /** {@inheritDoc} */
72 71
     public InputHandler getInputHandler() {
73
-        return new InputHandler(new JTextField(), null, this);
72
+        return new InputHandler(new DummyInputField(), null, this);
74 73
     }
75 74
     
76 75
     /** {@inheritDoc} */

+ 1
- 2
src/com/dmdirc/ui/dummy/DummyServerWindow.java View File

@@ -36,7 +36,6 @@ import java.nio.charset.Charset;
36 36
 import java.util.Arrays;
37 37
 
38 38
 import javax.swing.Icon;
39
-import javax.swing.JTextField;
40 39
 
41 40
 /**
42 41
  * Dummy server window, used for testing.
@@ -71,7 +70,7 @@ public final class DummyServerWindow implements ServerWindow {
71 70
     
72 71
     /** {@inheritDoc} */
73 72
     public InputHandler getInputHandler() {
74
-        return new InputHandler(new JTextField(), null, this);
73
+        return new InputHandler(new DummyInputField(), null, this);
75 74
     }
76 75
     
77 76
     /** {@inheritDoc} */

+ 6
- 38
src/com/dmdirc/ui/input/InputHandler.java View File

@@ -29,14 +29,13 @@ import com.dmdirc.commandparser.CommandManager;
29 29
 import com.dmdirc.commandparser.parsers.CommandParser;
30 30
 import com.dmdirc.commandparser.commands.IntelligentCommand;
31 31
 import com.dmdirc.interfaces.ConfigChangeListener;
32
-import com.dmdirc.config.IdentityManager;
33 32
 import com.dmdirc.ui.input.tabstyles.BashStyle;
34 33
 import com.dmdirc.ui.input.tabstyles.MircStyle;
35 34
 import com.dmdirc.ui.input.tabstyles.TabCompletionResult;
36 35
 import com.dmdirc.ui.input.tabstyles.TabCompletionStyle;
36
+import com.dmdirc.ui.interfaces.InputField;
37 37
 import com.dmdirc.ui.interfaces.InputWindow;
38 38
 import com.dmdirc.ui.messages.Styliser;
39
-import com.dmdirc.ui.swing.components.ColourPickerDialog;
40 39
 import com.dmdirc.util.RollingList;
41 40
 
42 41
 import java.awt.Toolkit;
@@ -47,8 +46,6 @@ import java.awt.event.KeyEvent;
47 46
 import java.util.ArrayList;
48 47
 import java.util.List;
49 48
 
50
-import javax.swing.JTextField;
51
-
52 49
 /**
53 50
  * Handles events generated by a user typing into a textfield. Allows the user
54 51
  * to use shortcut keys for control characters (ctrl+b, etc), to tab complete
@@ -76,7 +73,7 @@ public final class InputHandler extends KeyAdapter implements ActionListener,
76 73
     private RollingList<String> buffer;
77 74
     
78 75
     /** The textfield that we're handling input for. */
79
-    private final JTextField target;
76
+    private final InputField target;
80 77
     
81 78
     /** The TabCompleter to use for tab completion. */
82 79
     private TabCompleter tabCompleter;
@@ -87,9 +84,6 @@ public final class InputHandler extends KeyAdapter implements ActionListener,
87 84
     /** The frame that we belong to. */
88 85
     private final InputWindow parentWindow;
89 86
     
90
-    /** Colour picker dialog. */
91
-    private ColourPickerDialog colourPicker;
92
-    
93 87
     /** The tab completion style. */
94 88
     private TabCompletionStyle style;
95 89
     
@@ -101,7 +95,7 @@ public final class InputHandler extends KeyAdapter implements ActionListener,
101 95
      * @param thisCommandParser The command parser to use for this text field.
102 96
      * @param thisParentWindow The window that owns this input handler
103 97
      */
104
-    public InputHandler(final JTextField thisTarget,
98
+    public InputHandler(final InputField thisTarget,
105 99
             final CommandParser thisCommandParser,
106 100
             final InputWindow thisParentWindow) {
107 101
         
@@ -117,7 +111,6 @@ public final class InputHandler extends KeyAdapter implements ActionListener,
117 111
         
118 112
         target.addKeyListener(this);
119 113
         target.addActionListener(this);
120
-        target.setFocusTraversalKeysEnabled(false);
121 114
         
122 115
         parentWindow.getConfigManager().addChangeListener("tabcompletion", "style", this);
123 116
     }
@@ -153,10 +146,7 @@ public final class InputHandler extends KeyAdapter implements ActionListener,
153 146
      */
154 147
     @Override
155 148
     public void keyPressed(final KeyEvent keyEvent) {
156
-        if (colourPicker != null) {
157
-            colourPicker.dispose();
158
-            colourPicker = null;
159
-        }
149
+        target.hideColourPicker();
160 150
         
161 151
         // Formatting codes
162 152
         if ((keyEvent.getModifiers() & KeyEvent.CTRL_MASK) != 0) {
@@ -210,10 +200,10 @@ public final class InputHandler extends KeyAdapter implements ActionListener,
210 200
         case KeyEvent.VK_K:
211 201
             if ((keyEvent.getModifiers() & KeyEvent.SHIFT_MASK) == 0) {
212 202
                 addControlCode(Styliser.CODE_COLOUR, POSITION_START);
213
-                showColourPicker(true, false);
203
+                target.showColourPicker(true, false);
214 204
             } else {
215 205
                 addControlCode(Styliser.CODE_HEXCOLOUR, POSITION_START);
216
-                showColourPicker(false, true);
206
+                target.showColourPicker(false, true);
217 207
             }
218 208
             break;
219 209
             
@@ -420,28 +410,6 @@ public final class InputHandler extends KeyAdapter implements ActionListener,
420 410
         target.setText("");
421 411
     }
422 412
     
423
-    /**
424
-     * Displays a colour picker for the target.
425
-     *
426
-     * @param irc show irc colours in the colour picker
427
-     * @param hex show hex colours in the colour picker
428
-     */
429
-    private void showColourPicker(final boolean irc, final boolean hex) {
430
-        if (IdentityManager.getGlobalConfig().getOptionBool("general", "showcolourdialog", false)) {
431
-            colourPicker = new ColourPickerDialog(irc, hex);
432
-            colourPicker.addActionListener(new ActionListener() {
433
-                @Override
434
-                public void actionPerformed(final ActionEvent actionEvent) {
435
-                    target.setText(target.getText() + actionEvent.getActionCommand());
436
-                    colourPicker.dispose();
437
-                    colourPicker = null;
438
-                } });
439
-                colourPicker.setLocation((int) target.getLocationOnScreen().getX(),
440
-                        (int) target.getLocationOnScreen().getY() - colourPicker.getHeight());
441
-                colourPicker.setVisible(true);
442
-        }
443
-    }
444
-    
445 413
     /** {@inheritDoc} */
446 414
     @Override
447 415
     public void configChanged(final String domain, final String key) {

+ 122
- 0
src/com/dmdirc/ui/interfaces/InputField.java View File

@@ -0,0 +1,122 @@
1
+/*
2
+ * Copyright (c) 2006-2007 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.ui.interfaces;
24
+
25
+import java.awt.event.ActionListener;
26
+import java.awt.event.KeyListener;
27
+
28
+/**
29
+ * Input field interface.
30
+ */
31
+public interface InputField {
32
+
33
+    /**
34
+     * Adds an action listener to this input field.
35
+     * 
36
+     * @param listener ActionListener to add
37
+     */
38
+    public void addActionListener(final ActionListener listener);
39
+
40
+    /**
41
+     * Adds a keylistener to this input field.
42
+     * 
43
+     * @param listener KeyListener to add
44
+     */
45
+    public void addKeyListener(final KeyListener listener);
46
+    
47
+    /**
48
+     * Removes an action listener to this input field.
49
+     * 
50
+     * @param listener ActionListener to remove
51
+     */
52
+    public void removeActionListener(final ActionListener listener);
53
+
54
+    /**
55
+     * Removes a keylistener to this input field.
56
+     * 
57
+     * @param listener KeyListener to remove
58
+     */
59
+    public void removeKeyListener(final KeyListener listener);
60
+
61
+    /**
62
+     * Returns the selected text in the input field.
63
+     * 
64
+     * @return Selected text
65
+     */
66
+    public String getSelectedText();
67
+
68
+    /**
69
+     * Returns the end of the selection.
70
+     * 
71
+     * @return Selection end
72
+     */
73
+    public int getSelectionEnd();
74
+
75
+    /**
76
+     * Returns the start of the selection.
77
+     * 
78
+     * @return Selection start
79
+     */
80
+    public int getSelectionStart();
81
+
82
+    /**
83
+     * Returns the text in the input field.
84
+     * 
85
+     * @return Input field text
86
+     */
87
+    public String getText();
88
+
89
+    /**
90
+     * Sets the text in the input field to the specified text.
91
+     * 
92
+     * @param text New text for the input field
93
+     */
94
+    public void setText(final String text);
95
+
96
+    /**
97
+     * Returns the caret position.
98
+     * 
99
+     * @return Caret position
100
+     */
101
+    public int getCaretPosition();
102
+
103
+    /**
104
+     * Sets the caret position.
105
+     * 
106
+     * @param position Caret position
107
+     */
108
+    public void setCaretPosition(final int position);
109
+
110
+    /**
111
+     * Shows a colour picker for this input field.
112
+     * 
113
+     * @param irc Show irc colours?
114
+     * @param hex Show hex colours?
115
+     */
116
+    public void showColourPicker(final boolean irc, final boolean hex);
117
+
118
+    /**
119
+     * Hides the colour picker for this input field.
120
+     */
121
+    public void hideColourPicker();
122
+}

+ 23
- 6
src/com/dmdirc/ui/swing/components/InputTextFrame.java View File

@@ -62,7 +62,6 @@ import javax.swing.JLabel;
62 62
 import javax.swing.JMenuItem;
63 63
 import javax.swing.JPanel;
64 64
 import javax.swing.JPopupMenu;
65
-import javax.swing.JTextField;
66 65
 import javax.swing.KeyStroke;
67 66
 import javax.swing.event.InternalFrameEvent;
68 67
 import javax.swing.event.InternalFrameListener;
@@ -94,7 +93,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
94 93
     private InputHandler inputHandler;
95 94
     
96 95
     /** Frame input field. */
97
-    private JTextField inputField;
96
+    private SwingInputField inputField;
98 97
     
99 98
     /** Popupmenu for this frame. */
100 99
     private JPopupMenu inputFieldPopup;
@@ -140,6 +139,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
140 139
     }
141 140
     
142 141
     /** {@inheritDoc} */
142
+    @Override
143 143
     public void open() {
144 144
         if (getConfigManager().getOptionBool("ui", "awayindicator", false)
145 145
                 && getContainer().getServer() != null) {
@@ -154,7 +154,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
154 154
      * Initialises the components for this frame.
155 155
      */
156 156
     private void initComponents() {
157
-        setInputField(new JTextField());
157
+        setInputField(new SwingInputField());
158 158
         getInputField().setBorder(
159 159
                 BorderFactory.createCompoundBorder(
160 160
                 getInputField().getBorder(),
@@ -216,6 +216,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
216 216
      *
217 217
      * @return Input handlers for this frame
218 218
      */
219
+    @Override
219 220
     public final InputHandler getInputHandler() {
220 221
         return inputHandler;
221 222
     }
@@ -232,9 +233,9 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
232 233
     /**
233 234
      * Returns the input field for this frame.
234 235
      *
235
-     * @return JTextField input field for the frame.
236
+     * @return SwingInputField input field for the frame.
236 237
      */
237
-    public final JTextField getInputField() {
238
+    public final SwingInputField getInputField() {
238 239
         return inputField;
239 240
     }
240 241
     
@@ -243,7 +244,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
243 244
      *
244 245
      * @param newInputField new input field to use
245 246
      */
246
-    protected final void setInputField(final JTextField newInputField) {
247
+    protected final void setInputField(final SwingInputField newInputField) {
247 248
         this.inputField = newInputField;
248 249
     }
249 250
     
@@ -279,6 +280,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
279 280
     /**
280 281
      * Not needed for this class. {@inheritDoc}
281 282
      */
283
+    @Override
282 284
     public void internalFrameOpened(final InternalFrameEvent event) {
283 285
         super.internalFrameOpened(event);
284 286
     }
@@ -286,6 +288,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
286 288
     /**
287 289
      * Not needed for this class. {@inheritDoc}
288 290
      */
291
+    @Override
289 292
     public void internalFrameClosing(final InternalFrameEvent event) {
290 293
         super.internalFrameClosing(event);
291 294
     }
@@ -293,6 +296,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
293 296
     /**
294 297
      * Not needed for this class. {@inheritDoc}
295 298
      */
299
+    @Override
296 300
     public void internalFrameClosed(final InternalFrameEvent event) {
297 301
         super.internalFrameClosed(event);
298 302
     }
@@ -300,6 +304,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
300 304
     /**
301 305
      * Makes the internal frame invisible. {@inheritDoc}
302 306
      */
307
+    @Override
303 308
     public void internalFrameIconified(final InternalFrameEvent event) {
304 309
         super.internalFrameIconified(event);
305 310
     }
@@ -307,6 +312,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
307 312
     /**
308 313
      * Not needed for this class. {@inheritDoc}
309 314
      */
315
+    @Override
310 316
     public void internalFrameDeiconified(final InternalFrameEvent event) {
311 317
         super.internalFrameDeiconified(event);
312 318
     }
@@ -314,6 +320,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
314 320
     /**
315 321
      * Activates the input field on frame focus. {@inheritDoc}
316 322
      */
323
+    @Override
317 324
     public void internalFrameActivated(final InternalFrameEvent event) {
318 325
         super.internalFrameActivated(event);
319 326
     }
@@ -321,17 +328,20 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
321 328
     /**
322 329
      * Not needed for this class. {@inheritDoc}
323 330
      */
331
+    @Override
324 332
     public void internalFrameDeactivated(final InternalFrameEvent event) {
325 333
         super.internalFrameDeactivated(event);
326 334
     }
327 335
     
328 336
     /** {@inheritDoc} */
337
+    @Override
329 338
     public void keyTyped(final KeyEvent event) {
330 339
         //Ignore.
331 340
         super.keyTyped(event);
332 341
     }
333 342
     
334 343
     /** {@inheritDoc} */
344
+    @Override
335 345
     public void keyPressed(final KeyEvent event) {
336 346
         if (event.getSource() == getTextPane()
337 347
         && (getConfigManager().getOptionBool("ui", "quickCopy", false)
@@ -349,6 +359,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
349 359
     }
350 360
     
351 361
     /** {@inheritDoc} */
362
+    @Override
352 363
     public void keyReleased(final KeyEvent event) {
353 364
         //Ignore.
354 365
         super.keyReleased(event);
@@ -357,6 +368,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
357 368
     /**
358 369
      * Checks for url's, channels and nicknames. {@inheritDoc}
359 370
      */
371
+    @Override
360 372
     public void mouseClicked(final MouseEvent mouseEvent) {
361 373
         if (mouseEvent.getSource() == getTextPane()) {
362 374
             processMouseEvent(mouseEvent);
@@ -367,6 +379,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
367 379
     /**
368 380
      * Not needed for this class. {@inheritDoc}
369 381
      */
382
+    @Override
370 383
     public void mousePressed(final MouseEvent mouseEvent) {
371 384
         processMouseEvent(mouseEvent);
372 385
         super.mousePressed(mouseEvent);
@@ -375,6 +388,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
375 388
     /**
376 389
      * Not needed for this class. {@inheritDoc}
377 390
      */
391
+    @Override
378 392
     public void mouseReleased(final MouseEvent mouseEvent) {
379 393
         processMouseEvent(mouseEvent);
380 394
         super.mouseReleased(mouseEvent);
@@ -383,6 +397,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
383 397
     /**
384 398
      * Not needed for this class. {@inheritDoc}
385 399
      */
400
+    @Override
386 401
     public void mouseEntered(final MouseEvent mouseEvent) {
387 402
         //Ignore.
388 403
     }
@@ -390,6 +405,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
390 405
     /**
391 406
      * Not needed for this class. {@inheritDoc}
392 407
      */
408
+    @Override
393 409
     public void mouseExited(final MouseEvent mouseEvent) {
394 410
         //Ignore.
395 411
     }
@@ -489,6 +505,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
489 505
     }
490 506
     
491 507
     /** {@inheritDoc} */
508
+    @Override
492 509
     public void nickNameClicked(final String nickname, final MouseEvent e) {
493 510
         if (e.isPopupTrigger()) {
494 511
             final Point point = getMousePosition();

+ 82
- 0
src/com/dmdirc/ui/swing/components/SwingInputField.java View File

@@ -0,0 +1,82 @@
1
+/*
2
+ * Copyright (c) 2006-2007 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.ui.swing.components;
24
+
25
+import com.dmdirc.config.IdentityManager;
26
+import com.dmdirc.ui.interfaces.InputField;
27
+
28
+import java.awt.event.ActionEvent;
29
+import java.awt.event.ActionListener;
30
+
31
+import javax.swing.JTextField;
32
+
33
+/** Swing input field. */
34
+public class SwingInputField extends JTextField implements InputField {
35
+
36
+    /**
37
+     * A version number for this class. It should be changed whenever the class
38
+     * structure is changed (or anything else that would prevent serialized
39
+     * objects being unserialized with the new class).
40
+     */
41
+    private static final long serialVersionUID = 1;
42
+    /** Colour picker. */
43
+    private ColourPickerDialog colourPicker;
44
+
45
+    /**
46
+     * Instantiates a new swing input field.
47
+     */
48
+    public SwingInputField() {
49
+        setFocusTraversalKeysEnabled(false);
50
+    }
51
+
52
+    /** {@inheritDoc} */
53
+    @Override
54
+    public void showColourPicker(boolean irc, boolean hex) {
55
+        if (IdentityManager.getGlobalConfig().getOptionBool("general",
56
+                "showcolourdialog", false)) {
57
+            colourPicker = new ColourPickerDialog(irc, hex);
58
+            colourPicker.addActionListener(new ActionListener() {
59
+
60
+                @Override
61
+                public void actionPerformed(final ActionEvent actionEvent) {
62
+                    setText(getText() + actionEvent.getActionCommand());
63
+                    colourPicker.dispose();
64
+                    colourPicker = null;
65
+                }
66
+            });
67
+            colourPicker.setLocation((int) getLocationOnScreen().getX(),
68
+                    (int) getLocationOnScreen().getY() -
69
+                    colourPicker.getHeight());
70
+            colourPicker.setVisible(true);
71
+        }
72
+    }
73
+
74
+    /** {@inheritDoc} */
75
+    @Override
76
+    public void hideColourPicker() {
77
+        if (colourPicker != null) {
78
+            colourPicker.dispose();
79
+            colourPicker = null;
80
+        }
81
+    }
82
+}

Loading…
Cancel
Save