Browse Source

Add UI support for typing labels

Change-Id: Ib3a6830eccc07b8f84aaf65ef12ca9b9eeb0c651
Fixes-Issue: CLIENT-291
Reviewed-on: http://gerrit.dmdirc.com/2131
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.7rc1
Chris Smith 13 years ago
parent
commit
2a09854080

+ 133
- 0
src/com/dmdirc/addons/ui_swing/components/TypingLabel.java View File

@@ -0,0 +1,133 @@
1
+/*
2
+ * Copyright (c) 2006-2011 DMDirc Developers
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.addons.ui_swing.components;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.ui_swing.UIUtilities;
27
+import com.dmdirc.interfaces.ConfigChangeListener;
28
+import com.dmdirc.interfaces.FrameCloseListener;
29
+import com.dmdirc.interfaces.FrameComponentChangeListener;
30
+import com.dmdirc.ui.core.components.WindowComponent;
31
+
32
+import javax.swing.JLabel;
33
+
34
+/**
35
+ * Simple panel to show when a user is typing.
36
+ */
37
+public class TypingLabel extends JLabel implements ConfigChangeListener,
38
+        FrameComponentChangeListener, FrameCloseListener {
39
+
40
+    /**
41
+     * A version number for this class. It should be changed whenever the class
42
+     * structure is changed (or anything else that would prevent serialized
43
+     * objects being unserialized with the new class).
44
+     */
45
+    private static final long serialVersionUID = 2;
46
+    /** typingindicator string for compiler optimisation. */
47
+    private static final String CONFIG_KEY = "typingindicator";
48
+    /** Whether or not to show the typing indicator. */
49
+    private boolean useTypingIndicator;
50
+    /** Parent frame container. */
51
+    private final FrameContainer container;
52
+
53
+    /**
54
+     * Creates a new typing label for the specified container.
55
+     *
56
+     * @param container Parent frame container
57
+     */
58
+    public TypingLabel(final FrameContainer container) {
59
+        super("[Typing...]");
60
+
61
+        this.container = container;
62
+
63
+        container.getConfigManager().addChangeListener("ui", CONFIG_KEY,
64
+                this);
65
+        setVisible(false);
66
+        useTypingIndicator = container.getConfigManager().getOptionBool("ui",
67
+                CONFIG_KEY);
68
+
69
+        if (container.getComponents().contains(WindowComponent.TYPING_INDICATOR.getIdentifier())) {
70
+            setVisible(true);
71
+        }
72
+
73
+        container.addComponentListener(this);
74
+        container.addCloseListener(this);
75
+    }
76
+
77
+    /** {@inheritDoc} */
78
+    @Override
79
+    public void configChanged(final String domain, final String key) {
80
+        useTypingIndicator = container.getConfigManager()
81
+                .getOptionBool("ui", CONFIG_KEY);
82
+        if (!useTypingIndicator) {
83
+            UIUtilities.invokeLater(new Runnable() {
84
+
85
+                /** {@inheritDoc} */
86
+                @Override
87
+                public void run() {
88
+                    setVisible(false);
89
+                }
90
+            });
91
+        }
92
+    }
93
+
94
+    /** {@inheritDoc} */
95
+    @Override
96
+    public void windowClosing(final FrameContainer window) {
97
+        if (container != null) {
98
+            container.removeComponentListener(this);
99
+        }
100
+    }
101
+
102
+    @Override
103
+    public void componentAdded(final FrameContainer container, final String component) {
104
+        if (WindowComponent.TYPING_INDICATOR.getIdentifier().equals(component)) {
105
+            UIUtilities.invokeLater(new Runnable() {
106
+
107
+                    /** {@inheritDoc} */
108
+                    @Override
109
+                    public void run() {
110
+                        if (useTypingIndicator) {
111
+                            setVisible(true);
112
+                        }
113
+                    }
114
+            });
115
+        }
116
+    }
117
+
118
+    @Override
119
+    public void componentRemoved(final FrameContainer container, final String component) {
120
+        if (WindowComponent.TYPING_INDICATOR.getIdentifier().equals(component)) {
121
+            UIUtilities.invokeLater(new Runnable() {
122
+
123
+                    /** {@inheritDoc} */
124
+                    @Override
125
+                    public void run() {
126
+                        if (useTypingIndicator) {
127
+                            setVisible(false);
128
+                        }
129
+                    }
130
+            });
131
+        }
132
+    }
133
+}

+ 6
- 0
src/com/dmdirc/addons/ui_swing/components/frames/InputTextFrame.java View File

@@ -30,6 +30,7 @@ import com.dmdirc.addons.ui_swing.actions.CutAction;
30 30
 import com.dmdirc.addons.ui_swing.actions.InputFieldCopyAction;
31 31
 import com.dmdirc.addons.ui_swing.actions.InputTextFramePasteAction;
32 32
 import com.dmdirc.addons.ui_swing.components.AwayLabel;
33
+import com.dmdirc.addons.ui_swing.components.TypingLabel;
33 34
 import com.dmdirc.addons.ui_swing.components.inputfields.SwingInputField;
34 35
 import com.dmdirc.addons.ui_swing.components.inputfields.SwingInputHandler;
35 36
 import com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog;
@@ -79,6 +80,8 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
79 80
     protected JPopupMenu nickPopup;
80 81
     /** Away label. */
81 82
     private AwayLabel awayLabel;
83
+    /** Typing indicator label. */
84
+    private TypingLabel typingLabel;
82 85
 
83 86
     /**
84 87
      * Creates a new instance of InputFrame.
@@ -139,8 +142,10 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
139 142
         inputPanel = new JPanel(new BorderLayout(
140 143
                 (int) PlatformDefaults.getUnitValueX("related").getValue(),
141 144
                 (int) PlatformDefaults.getUnitValueX("related").getValue()));
145
+
142 146
         inputPanel.add(awayLabel, BorderLayout.LINE_START);
143 147
         inputPanel.add(inputField, BorderLayout.CENTER);
148
+        inputPanel.add(typingLabel, BorderLayout.LINE_END);
144 149
 
145 150
         initInputField();
146 151
     }
@@ -156,6 +161,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
156 161
         inputFieldPopup.setLightWeightPopupEnabled(true);
157 162
 
158 163
         awayLabel = new AwayLabel(getContainer());
164
+        typingLabel = new TypingLabel(getContainer());
159 165
     }
160 166
 
161 167
     /**

Loading…
Cancel
Save