Browse Source

fixed the console errors being generated by the swinginputfield

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

+ 2
- 4
src/com/dmdirc/ui/swing/components/SwingInputField.java View File

31
 import java.awt.event.ActionListener;
31
 import java.awt.event.ActionListener;
32
 import java.awt.event.KeyListener;
32
 import java.awt.event.KeyListener;
33
 
33
 
34
+import javax.swing.JComponent;
34
 import javax.swing.JLabel;
35
 import javax.swing.JLabel;
35
 import javax.swing.JTextField;
36
 import javax.swing.JTextField;
36
 import javax.swing.event.DocumentEvent;
37
 import javax.swing.event.DocumentEvent;
37
 import javax.swing.event.DocumentListener;
38
 import javax.swing.event.DocumentListener;
38
 import javax.swing.text.BadLocationException;
39
 import javax.swing.text.BadLocationException;
39
-import javax.swing.text.JTextComponent;
40
 import net.miginfocom.swing.MigLayout;
40
 import net.miginfocom.swing.MigLayout;
41
 
41
 
42
 /** Swing input field. */
42
 /** Swing input field. */
43
-public class SwingInputField extends JTextComponent implements InputField,
43
+public class SwingInputField extends JComponent implements InputField,
44
         DocumentListener {
44
         DocumentListener {
45
 
45
 
46
     /**
46
     /**
204
      * 
204
      * 
205
      * @param clipboard Text to replace selection with
205
      * @param clipboard Text to replace selection with
206
      */
206
      */
207
-    @Override
208
     public void replaceSelection(String clipboard) {
207
     public void replaceSelection(String clipboard) {
209
         textField.replaceSelection(clipboard);
208
         textField.replaceSelection(clipboard);
210
     }
209
     }
214
      * 
213
      * 
215
      * @param optionColour Colour for the caret
214
      * @param optionColour Colour for the caret
216
      */
215
      */
217
-    @Override
218
     public void setCaretColor(Color optionColour) {
216
     public void setCaretColor(Color optionColour) {
219
         textField.setCaretColor(optionColour);
217
         textField.setCaretColor(optionColour);
220
     }
218
     }

+ 40
- 8
src/com/dmdirc/ui/swing/components/SwingInputHandler.java View File

57
     /** {@inheritDoc} */
57
     /** {@inheritDoc} */
58
     @Override
58
     @Override
59
     protected void addUpHandler() {
59
     protected void addUpHandler() {
60
-        ((JTextComponent) target).getActionMap().put("upArrow", new AbstractAction() {
60
+        final JTextComponent localTarget;
61
+        if (target instanceof JTextComponent) {
62
+            localTarget = (JTextComponent) target;
63
+        } else if (target instanceof SwingInputField) {
64
+            localTarget = ((SwingInputField) target).getTextField();
65
+        } else {
66
+            throw new RuntimeException("Unsupported component: " + target.getClass());
67
+        }
68
+        localTarget.getActionMap().put("upArrow", new AbstractAction() {
61
 
69
 
62
             /**
70
             /**
63
              * A version number for this class. It should be changed whenever the class
71
              * A version number for this class. It should be changed whenever the class
72
                 doBufferUp();
80
                 doBufferUp();
73
             }
81
             }
74
         });
82
         });
75
-        ((JTextComponent) target).getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).
83
+        localTarget.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).
76
                 put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "upArrow");
84
                 put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "upArrow");
77
     }
85
     }
78
 
86
 
79
     /** {@inheritDoc} */
87
     /** {@inheritDoc} */
80
     @Override
88
     @Override
81
     protected void addDownHandler() {
89
     protected void addDownHandler() {
82
-        ((JTextComponent) target).getActionMap().put("downArrow", new AbstractAction() {
90
+        final JTextComponent localTarget;
91
+        if (target instanceof JTextComponent) {
92
+            localTarget = (JTextComponent) target;
93
+        } else if (target instanceof SwingInputField) {
94
+            localTarget = ((SwingInputField) target).getTextField();
95
+        } else {
96
+            throw new RuntimeException("Unsupported component: " + target.getClass());
97
+        }
98
+        localTarget.getActionMap().put("downArrow", new AbstractAction() {
83
 
99
 
84
             /**
100
             /**
85
              * A version number for this class. It should be changed whenever the class
101
              * A version number for this class. It should be changed whenever the class
94
                 doBufferDown();
110
                 doBufferDown();
95
             }
111
             }
96
         });
112
         });
97
-        ((JTextComponent) target).getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).
113
+        localTarget.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).
98
                 put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "downArrow");
114
                 put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "downArrow");
99
     }
115
     }
100
 
116
 
101
     /** {@inheritDoc} */
117
     /** {@inheritDoc} */
102
     @Override
118
     @Override
103
     protected void addTabHandler() {
119
     protected void addTabHandler() {
104
-        ((JTextComponent) target).getActionMap().put("tabPressed", new AbstractAction() {
120
+        final JTextComponent localTarget;
121
+        if (target instanceof JTextComponent) {
122
+            localTarget = (JTextComponent) target;
123
+        } else if (target instanceof SwingInputField) {
124
+            localTarget = ((SwingInputField) target).getTextField();
125
+        } else {
126
+            throw new RuntimeException("Unsupported component: " + target.getClass());
127
+        }
128
+        localTarget.getActionMap().put("tabPressed", new AbstractAction() {
105
 
129
 
106
             /**
130
             /**
107
              * A version number for this class. It should be changed whenever the class
131
              * A version number for this class. It should be changed whenever the class
116
                 doTabCompletion();
140
                 doTabCompletion();
117
             }
141
             }
118
         });
142
         });
119
-        ((JTextComponent) target).getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).
143
+        localTarget.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).
120
                 put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "tabPressed");
144
                 put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "tabPressed");
121
     }
145
     }
122
 
146
 
123
     /** {@inheritDoc} */
147
     /** {@inheritDoc} */
124
     @Override
148
     @Override
125
     protected void addEnterHandler() {
149
     protected void addEnterHandler() {
126
-        ((JTextComponent) target).getActionMap().put("enterButton", new AbstractAction() {
150
+        final JTextComponent localTarget;
151
+        if (target instanceof JTextComponent) {
152
+            localTarget = (JTextComponent) target;
153
+        } else if (target instanceof SwingInputField) {
154
+            localTarget = ((SwingInputField) target).getTextField();
155
+        } else {
156
+            throw new RuntimeException("Unsupported component: " + target.getClass());
157
+        }
158
+        localTarget.getActionMap().put("enterButton", new AbstractAction() {
127
 
159
 
128
             /**
160
             /**
129
              * A version number for this class. It should be changed whenever the class
161
              * A version number for this class. It should be changed whenever the class
138
                 enterPressed(target.getText());
170
                 enterPressed(target.getText());
139
             }
171
             }
140
         });
172
         });
141
-        ((JTextComponent) target).getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).
173
+        localTarget.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).
142
                 put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enterButton");
174
                 put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enterButton");
143
     }
175
     }
144
 
176
 

Loading…
Cancel
Save