|
@@ -22,23 +22,24 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.ui.swing.components;
|
24
|
24
|
|
|
25
|
+import com.dmdirc.IconManager;
|
25
|
26
|
import com.dmdirc.config.IdentityManager;
|
26
|
27
|
import com.dmdirc.ui.interfaces.InputField;
|
27
|
28
|
|
28
|
|
-import java.awt.BorderLayout;
|
29
|
29
|
import java.awt.Color;
|
30
|
30
|
import java.awt.event.ActionEvent;
|
31
|
31
|
import java.awt.event.ActionListener;
|
32
|
32
|
import java.awt.event.KeyListener;
|
33
|
33
|
|
34
|
|
-import java.util.logging.Level;
|
35
|
|
-import java.util.logging.Logger;
|
36
|
34
|
import javax.swing.JComponent;
|
37
|
35
|
import javax.swing.JTextField;
|
|
36
|
+import javax.swing.event.DocumentEvent;
|
|
37
|
+import javax.swing.event.DocumentListener;
|
38
|
38
|
import javax.swing.text.BadLocationException;
|
|
39
|
+import net.miginfocom.swing.MigLayout;
|
39
|
40
|
|
40
|
41
|
/** Swing input field. */
|
41
|
|
-public class SwingInputField extends JComponent implements InputField {
|
|
42
|
+public class SwingInputField extends JComponent implements InputField, DocumentListener {
|
42
|
43
|
|
43
|
44
|
/**
|
44
|
45
|
* A version number for this class. It should be changed whenever the class
|
|
@@ -50,6 +51,8 @@ public class SwingInputField extends JComponent implements InputField {
|
50
|
51
|
private ColourPickerDialog colourPicker;
|
51
|
52
|
/** Input field text field. */
|
52
|
53
|
private JTextField textField;
|
|
54
|
+ /** Line wrap indicator. */
|
|
55
|
+ private ImageButton wrapIndicator;
|
53
|
56
|
|
54
|
57
|
/**
|
55
|
58
|
* Instantiates a new swing input field.
|
|
@@ -57,10 +60,14 @@ public class SwingInputField extends JComponent implements InputField {
|
57
|
60
|
public SwingInputField() {
|
58
|
61
|
textField = new JTextField();
|
59
|
62
|
textField.setFocusTraversalKeysEnabled(false);
|
|
63
|
+ wrapIndicator = new ImageButton("", IconManager.getIconManager().getIcon("dmdirc"));
|
|
64
|
+ textField.getDocument().addDocumentListener(this);
|
|
65
|
+ checkLength(0);
|
60
|
66
|
|
61
|
|
- setLayout(new BorderLayout());
|
|
67
|
+ setLayout(new MigLayout("ins 0, hidemode 3"));
|
62
|
68
|
|
63
|
|
- add(textField, BorderLayout.CENTER);
|
|
69
|
+ add(textField, "growx, pushx");
|
|
70
|
+ add(wrapIndicator, "");
|
64
|
71
|
}
|
65
|
72
|
|
66
|
73
|
/** {@inheritDoc} */
|
|
@@ -204,6 +211,7 @@ public class SwingInputField extends JComponent implements InputField {
|
204
|
211
|
*
|
205
|
212
|
* @param optionColour Colour for the caret
|
206
|
213
|
*/
|
|
214
|
+ @Override
|
207
|
215
|
public void setForeground(Color optionColour) {
|
208
|
216
|
textField.setForeground(optionColour);
|
209
|
217
|
}
|
|
@@ -213,7 +221,35 @@ public class SwingInputField extends JComponent implements InputField {
|
213
|
221
|
*
|
214
|
222
|
* @param optionColour Colour for the caret
|
215
|
223
|
*/
|
|
224
|
+ @Override
|
216
|
225
|
public void setBackground(Color optionColour) {
|
217
|
226
|
textField.setBackground(optionColour);
|
218
|
227
|
}
|
|
228
|
+
|
|
229
|
+ /** {@inheritDoc} */
|
|
230
|
+ @Override
|
|
231
|
+ public void insertUpdate(final DocumentEvent e) {
|
|
232
|
+ checkLength(e.getDocument().getLength());
|
|
233
|
+ }
|
|
234
|
+
|
|
235
|
+ /** {@inheritDoc} */
|
|
236
|
+ @Override
|
|
237
|
+ public void removeUpdate(final DocumentEvent e) {
|
|
238
|
+ checkLength(e.getDocument().getLength());
|
|
239
|
+ }
|
|
240
|
+
|
|
241
|
+ /** {@inheritDoc} */
|
|
242
|
+ @Override
|
|
243
|
+ public void changedUpdate(final DocumentEvent e) {
|
|
244
|
+ //Ignore
|
|
245
|
+ }
|
|
246
|
+
|
|
247
|
+ /**
|
|
248
|
+ * Checks the length of the input and shows wrap indicator if required.
|
|
249
|
+ *
|
|
250
|
+ * @param newLength New length of input
|
|
251
|
+ */
|
|
252
|
+ private void checkLength(final int newLength) {
|
|
253
|
+ //Check length and set visible if needed
|
|
254
|
+ }
|
219
|
255
|
}
|