Browse Source

Hide colour picker dialogs when focus is lost.

Fixes CLIENT-191

Change-Id: I1f4d9617215e699282a5b934b7d2ecd842d62ed5
Reviewed-on: http://gerrit.dmdirc.com/1818
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.7rc1
Greg Holmes 13 years ago
parent
commit
11204480cf

+ 14
- 1
src/com/dmdirc/addons/ui_swing/components/inputfields/SwingInputField.java View File

@@ -33,11 +33,14 @@ import com.dmdirc.util.ReturnableThread;
33 33
 
34 34
 import java.awt.Color;
35 35
 import java.awt.FontMetrics;
36
+import java.awt.KeyboardFocusManager;
36 37
 import java.awt.Window;
37 38
 import java.awt.event.ActionEvent;
38 39
 import java.awt.event.ActionListener;
39 40
 import java.awt.event.KeyEvent;
40 41
 import java.awt.event.KeyListener;
42
+import java.beans.PropertyChangeEvent;
43
+import java.beans.PropertyChangeListener;
41 44
 
42 45
 import javax.swing.JComponent;
43 46
 import javax.swing.JLabel;
@@ -49,7 +52,7 @@ import net.miginfocom.swing.MigLayout;
49 52
 
50 53
 /** Swing input field. */
51 54
 public class SwingInputField extends JComponent implements InputField,
52
-        KeyListener, InputValidationListener {
55
+        KeyListener, InputValidationListener, PropertyChangeListener {
53 56
 
54 57
     /**
55 58
      * A version number for this class. It should be changed whenever the class
@@ -108,6 +111,8 @@ public class SwingInputField extends JComponent implements InputField,
108 111
                 textField.getInputMap(SwingInputField.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT));
109 112
         setInputMap(SwingInputField.WHEN_IN_FOCUSED_WINDOW,
110 113
                 textField.getInputMap(SwingInputField.WHEN_IN_FOCUSED_WINDOW));
114
+        KeyboardFocusManager.getCurrentKeyboardFocusManager()
115
+                .addPropertyChangeListener(this);
111 116
     }
112 117
 
113 118
     /** {@inheritDoc} */
@@ -548,4 +553,12 @@ public class SwingInputField extends JComponent implements InputField,
548 553
             }
549 554
         });
550 555
     }
556
+
557
+    /** {@inheritDoc} */
558
+    @Override
559
+    public void propertyChange(final PropertyChangeEvent evt) {
560
+        if (!isFocusOwner()) {
561
+            hideColourPicker();
562
+        }
563
+    }
551 564
 }

+ 19
- 3
src/com/dmdirc/addons/ui_swing/components/inputfields/TextAreaInputField.java View File

@@ -19,23 +19,27 @@
19 19
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 20
  * SOFTWARE.
21 21
  */
22
+
22 23
 package com.dmdirc.addons.ui_swing.components.inputfields;
23 24
 
24 25
 import com.dmdirc.addons.ui_swing.components.colours.ColourPickerDialog;
25 26
 import com.dmdirc.config.IdentityManager;
26 27
 import com.dmdirc.ui.interfaces.InputField;
28
+import java.awt.KeyboardFocusManager;
27 29
 
28 30
 import java.awt.event.ActionEvent;
29 31
 import java.awt.event.ActionListener;
32
+import java.beans.PropertyChangeEvent;
33
+import java.beans.PropertyChangeListener;
30 34
 
31 35
 import javax.swing.JTextArea;
32 36
 import javax.swing.text.BadLocationException;
33 37
 
34 38
 /**
35
- *
36
- * @author chris
39
+ * JTextArea implementing InputField
37 40
  */
38
-public class TextAreaInputField extends JTextArea implements InputField {
41
+public class TextAreaInputField extends JTextArea implements InputField,
42
+        PropertyChangeListener {
39 43
     
40 44
     /**
41 45
      * A version number for this class. It should be changed whenever the class
@@ -55,6 +59,8 @@ public class TextAreaInputField extends JTextArea implements InputField {
55 59
      */
56 60
     public TextAreaInputField(final int rows, final int columns) {
57 61
         super(rows, columns);
62
+        KeyboardFocusManager.getCurrentKeyboardFocusManager()
63
+                .addPropertyChangeListener(this);
58 64
     }
59 65
 
60 66
     /**
@@ -64,6 +70,8 @@ public class TextAreaInputField extends JTextArea implements InputField {
64 70
      */
65 71
     public TextAreaInputField(final String text) {
66 72
         super(text);
73
+        KeyboardFocusManager.getCurrentKeyboardFocusManager()
74
+                .addPropertyChangeListener(this);
67 75
     }
68 76
     
69 77
     /** {@inheritDoc} */
@@ -114,4 +122,12 @@ public class TextAreaInputField extends JTextArea implements InputField {
114 122
         }
115 123
     }
116 124
 
125
+    /** {@inheritDoc} */
126
+    @Override
127
+    public void propertyChange(final PropertyChangeEvent evt) {
128
+        if (!isFocusOwner()) {
129
+            hideColourPicker();
130
+        }
131
+    }
132
+
117 133
 }

+ 28
- 6
src/com/dmdirc/addons/ui_swing/components/inputfields/TextFieldInputField.java View File

@@ -1,17 +1,17 @@
1 1
 /*
2
- * 
2
+ *
3 3
  * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
4
- * 
4
+ *
5 5
  * Permission is hereby granted, free of charge, to any person obtaining a copy
6 6
  * of this software and associated documentation files (the "Software"), to deal
7 7
  * in the Software without restriction, including without limitation the rights
8 8
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 9
  * copies of the Software, and to permit persons to whom the Software is
10 10
  * furnished to do so, subject to the following conditions:
11
- * 
11
+ *
12 12
  * The above copyright notice and this permission notice shall be included in
13 13
  * all copies or substantial portions of the Software.
14
- * 
14
+ *
15 15
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 16
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 17
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -26,17 +26,21 @@ package com.dmdirc.addons.ui_swing.components.inputfields;
26 26
 import com.dmdirc.addons.ui_swing.components.colours.ColourPickerDialog;
27 27
 import com.dmdirc.config.IdentityManager;
28 28
 import com.dmdirc.ui.interfaces.InputField;
29
+import java.awt.KeyboardFocusManager;
29 30
 
30 31
 import java.awt.event.ActionEvent;
31 32
 import java.awt.event.ActionListener;
33
+import java.beans.PropertyChangeEvent;
34
+import java.beans.PropertyChangeListener;
32 35
 
33 36
 import javax.swing.JTextField;
34 37
 import javax.swing.text.BadLocationException;
35 38
 
36 39
 /**
37
- *
40
+ * JTextField implementing InputField.
38 41
  */
39
-public class TextFieldInputField extends JTextField implements InputField {
42
+public class TextFieldInputField extends JTextField implements InputField,
43
+        PropertyChangeListener {
40 44
 
41 45
     /**
42 46
      * A version number for this class. It should be changed whenever the class
@@ -47,6 +51,16 @@ public class TextFieldInputField extends JTextField implements InputField {
47 51
     /** Colour picker. */
48 52
     protected ColourPickerDialog colourPicker;
49 53
 
54
+    /**
55
+     * Creates a new text field input field.
56
+     */
57
+    public TextFieldInputField() {
58
+        super();
59
+
60
+        KeyboardFocusManager.getCurrentKeyboardFocusManager()
61
+                .addPropertyChangeListener(this);
62
+    }
63
+
50 64
     /** {@inheritDoc} */
51 65
     @Override
52 66
     public void showColourPicker(final boolean irc, final boolean hex) {
@@ -82,4 +96,12 @@ public class TextFieldInputField extends JTextField implements InputField {
82 96
             colourPicker = null;
83 97
         }
84 98
     }
99
+
100
+    /** {@inheritDoc} */
101
+    @Override
102
+    public void propertyChange(final PropertyChangeEvent evt) {
103
+        if (!isFocusOwner()) {
104
+            hideColourPicker();
105
+        }
106
+    }
85 107
 }

+ 26
- 5
src/com/dmdirc/addons/ui_swing/components/inputfields/TextPaneInputField.java View File

@@ -1,17 +1,16 @@
1 1
 /*
2
- * 
3 2
  * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
4
- * 
3
+ *
5 4
  * Permission is hereby granted, free of charge, to any person obtaining a copy
6 5
  * of this software and associated documentation files (the "Software"), to deal
7 6
  * in the Software without restriction, including without limitation the rights
8 7
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 8
  * copies of the Software, and to permit persons to whom the Software is
10 9
  * furnished to do so, subject to the following conditions:
11
- * 
10
+ *
12 11
  * The above copyright notice and this permission notice shall be included in
13 12
  * all copies or substantial portions of the Software.
14
- * 
13
+ *
15 14
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 15
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 16
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -26,9 +25,12 @@ package com.dmdirc.addons.ui_swing.components.inputfields;
26 25
 import com.dmdirc.addons.ui_swing.components.colours.ColourPickerDialog;
27 26
 import com.dmdirc.config.IdentityManager;
28 27
 import com.dmdirc.ui.interfaces.InputField;
28
+import java.awt.KeyboardFocusManager;
29 29
 
30 30
 import java.awt.event.ActionEvent;
31 31
 import java.awt.event.ActionListener;
32
+import java.beans.PropertyChangeEvent;
33
+import java.beans.PropertyChangeListener;
32 34
 
33 35
 import javax.swing.BorderFactory;
34 36
 import javax.swing.JEditorPane;
@@ -39,7 +41,8 @@ import javax.swing.text.BadLocationException;
39 41
 /**
40 42
  * JTextPane implementing InputField.
41 43
  */
42
-public class TextPaneInputField extends JEditorPane implements InputField {
44
+public class TextPaneInputField extends JEditorPane implements InputField,
45
+        PropertyChangeListener {
43 46
 
44 47
     /**
45 48
      * A version number for this class. It should be changed whenever the class
@@ -50,6 +53,16 @@ public class TextPaneInputField extends JEditorPane implements InputField {
50 53
     /** Colour picker. */
51 54
     protected ColourPickerDialog colourPicker;
52 55
 
56
+    /**
57
+     * Creates a new text pane input field.
58
+     */
59
+    public TextPaneInputField() {
60
+        super();
61
+
62
+        KeyboardFocusManager.getCurrentKeyboardFocusManager()
63
+                .addPropertyChangeListener(this);
64
+    }
65
+
53 66
     /** {@inheritDoc} */
54 67
     @Override
55 68
     public void showColourPicker(final boolean irc, final boolean hex) {
@@ -111,4 +124,12 @@ public class TextPaneInputField extends JEditorPane implements InputField {
111 124
         super.setUI(new BasicEditorPaneUI());
112 125
         super.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
113 126
     }
127
+
128
+    /** {@inheritDoc} */
129
+    @Override
130
+    public void propertyChange(final PropertyChangeEvent evt) {
131
+        if (!isFocusOwner()) {
132
+            hideColourPicker();
133
+        }
134
+    }
114 135
 }

Loading…
Cancel
Save