|
@@ -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
|
+}
|