Bläddra i källkod

work on issue 454: Line wrap indicator

git-svn-id: http://svn.dmdirc.com/trunk@3481 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Gregory Holmes 16 år sedan
förälder
incheckning
8f9e13ef57
1 ändrade filer med 42 tillägg och 6 borttagningar
  1. 42
    6
      src/com/dmdirc/ui/swing/components/SwingInputField.java

+ 42
- 6
src/com/dmdirc/ui/swing/components/SwingInputField.java Visa fil

22
 
22
 
23
 package com.dmdirc.ui.swing.components;
23
 package com.dmdirc.ui.swing.components;
24
 
24
 
25
+import com.dmdirc.IconManager;
25
 import com.dmdirc.config.IdentityManager;
26
 import com.dmdirc.config.IdentityManager;
26
 import com.dmdirc.ui.interfaces.InputField;
27
 import com.dmdirc.ui.interfaces.InputField;
27
 
28
 
28
-import java.awt.BorderLayout;
29
 import java.awt.Color;
29
 import java.awt.Color;
30
 import java.awt.event.ActionEvent;
30
 import java.awt.event.ActionEvent;
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 java.util.logging.Level;
35
-import java.util.logging.Logger;
36
 import javax.swing.JComponent;
34
 import javax.swing.JComponent;
37
 import javax.swing.JTextField;
35
 import javax.swing.JTextField;
36
+import javax.swing.event.DocumentEvent;
37
+import javax.swing.event.DocumentListener;
38
 import javax.swing.text.BadLocationException;
38
 import javax.swing.text.BadLocationException;
39
+import net.miginfocom.swing.MigLayout;
39
 
40
 
40
 /** Swing input field. */
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
      * A version number for this class. It should be changed whenever the class
45
      * A version number for this class. It should be changed whenever the class
50
     private ColourPickerDialog colourPicker;
51
     private ColourPickerDialog colourPicker;
51
     /** Input field text field. */
52
     /** Input field text field. */
52
     private JTextField textField;
53
     private JTextField textField;
54
+    /** Line wrap indicator. */
55
+    private ImageButton wrapIndicator;
53
 
56
 
54
     /**
57
     /**
55
      * Instantiates a new swing input field.
58
      * Instantiates a new swing input field.
57
     public SwingInputField() {
60
     public SwingInputField() {
58
         textField = new JTextField();
61
         textField = new JTextField();
59
         textField.setFocusTraversalKeysEnabled(false);
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
     /** {@inheritDoc} */
73
     /** {@inheritDoc} */
204
      * 
211
      * 
205
      * @param optionColour Colour for the caret
212
      * @param optionColour Colour for the caret
206
      */
213
      */
214
+    @Override
207
     public void setForeground(Color optionColour) {
215
     public void setForeground(Color optionColour) {
208
         textField.setForeground(optionColour);
216
         textField.setForeground(optionColour);
209
     }
217
     }
213
      * 
221
      * 
214
      * @param optionColour Colour for the caret
222
      * @param optionColour Colour for the caret
215
      */
223
      */
224
+    @Override
216
     public void setBackground(Color optionColour) {
225
     public void setBackground(Color optionColour) {
217
         textField.setBackground(optionColour);
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
 }

Laddar…
Avbryt
Spara