Browse Source

More web UI tidying

Change-Id: Ia71576bce010a76138b101a3451745dced1452a2
Reviewed-on: http://gerrit.dmdirc.com/2103
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.7rc1
Chris Smith 13 years ago
parent
commit
edff12bedb

+ 1
- 2
src/com/dmdirc/addons/ui_web/Client.java View File

@@ -22,7 +22,6 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_web;
24 24
 
25
-import com.dmdirc.addons.ui_web.uicomponents.WebWindow;
26 25
 import com.dmdirc.ui.interfaces.Window;
27 26
 
28 27
 import java.util.LinkedList;
@@ -61,7 +60,7 @@ public class Client {
61 60
 
62 61
         final List<Window> added = new LinkedList<Window>();
63 62
         final List<Window> queued
64
-                = new LinkedList<Window>(WebWindow.getWindows());
63
+                = new LinkedList<Window>(controller.getWindowManager().getWindows());
65 64
 
66 65
         while (!queued.isEmpty()) {
67 66
             final Window window = queued.remove(0);

+ 12
- 12
src/com/dmdirc/addons/ui_web/DynamicRequestHandler.java View File

@@ -201,7 +201,7 @@ public class DynamicRequestHandler extends AbstractHandler {
201 201
     }
202 202
 
203 203
     private void doInput(final HttpServletRequest request) throws IOException {
204
-        final WebWindow window = WebWindow.getWindow(
204
+        final WebWindow window = controller.getWindowManager().getWindow(
205 205
                 request.getParameter("window"));
206 206
 
207 207
         if (window instanceof WebInputWindow) {
@@ -213,7 +213,7 @@ public class DynamicRequestHandler extends AbstractHandler {
213 213
     }
214 214
 
215 215
     private void doKey(final HttpServletRequest request) throws IOException {
216
-        final WebWindow window = WebWindow.getWindow(
216
+        final WebWindow window = controller.getWindowManager().getWindow(
217 217
                 request.getParameter("window"));
218 218
 
219 219
         if (window instanceof WebInputWindow) {
@@ -237,8 +237,8 @@ public class DynamicRequestHandler extends AbstractHandler {
237 237
     }
238 238
 
239 239
     private void doTab(final HttpServletRequest request) throws IOException {
240
-        final WebWindow window = WebWindow.getWindow(request.getParameter(
241
-                "window"));
240
+        final WebWindow window = controller.getWindowManager().getWindow(
241
+                request.getParameter("window"));
242 242
 
243 243
         if (window instanceof WebInputWindow) {
244 244
             final WebInputWindow wiw = (WebInputWindow) window;
@@ -253,8 +253,8 @@ public class DynamicRequestHandler extends AbstractHandler {
253 253
 
254 254
     private void doKeyUpDown(final boolean up, final HttpServletRequest request)
255 255
             throws IOException {
256
-        final WebWindow window = WebWindow.getWindow(request.getParameter(
257
-                "window"));
256
+        final WebWindow window = controller.getWindowManager().getWindow(
257
+                request.getParameter("window"));
258 258
 
259 259
         if (window instanceof WebInputWindow) {
260 260
             final WebInputWindow wiw = (WebInputWindow) window;
@@ -294,8 +294,8 @@ public class DynamicRequestHandler extends AbstractHandler {
294 294
 
295 295
         nickEvents.add(new Event("clearnicklist", false));
296 296
 
297
-        for (ChannelClientInfo cci : ((Channel) (WebWindow.getWindow(
298
-                request.getParameter("window"))).getContainer())
297
+        for (ChannelClientInfo cci : ((Channel) (controller.getWindowManager()
298
+                .getWindow(request.getParameter("window"))).getContainer())
299 299
                 .getChannelInfo().getChannelClients()) {
300 300
             nickEvents.add(new Event("addnicklist",
301 301
                     cci.getClient().getNickname()));
@@ -328,8 +328,8 @@ public class DynamicRequestHandler extends AbstractHandler {
328 328
 
329 329
         final List<Event> windowEvents = new ArrayList<Event>();
330 330
 
331
-        final WebWindow window = WebWindow.getWindow(request.getParameter(
332
-                "window"));
331
+        final WebWindow window = controller.getWindowManager().getWindow(
332
+                request.getParameter("window"));
333 333
 
334 334
         windowEvents.add(new Event("clearwindow", window.getId()));
335 335
 
@@ -350,7 +350,7 @@ public class DynamicRequestHandler extends AbstractHandler {
350 350
     private void doJoinChannel(final HttpServletRequest request)
351 351
             throws IOException {
352 352
         final String windowID = request.getParameter("source");
353
-        final WebWindow window = WebWindow.getWindow(windowID);
353
+        final WebWindow window = controller.getWindowManager().getWindow(windowID);
354 354
         window.getContainer().getServer().join(new ChannelJoinRequest(request.
355 355
                 getParameter("channel")));
356 356
     }
@@ -358,7 +358,7 @@ public class DynamicRequestHandler extends AbstractHandler {
358 358
     private void doOpenQuery(final HttpServletRequest request)
359 359
             throws IOException {
360 360
         final String windowID = request.getParameter("source");
361
-        final WebWindow window = WebWindow.getWindow(windowID);
361
+        final WebWindow window = controller.getWindowManager().getWindow(windowID);
362 362
         window.getContainer().getServer().getQuery(request.getParameter(
363 363
                 "target"));
364 364
     }

+ 35
- 4
src/com/dmdirc/addons/ui_web/WebWindowManager.java View File

@@ -34,6 +34,7 @@ import com.dmdirc.ui.interfaces.Window;
34 34
 
35 35
 import java.util.Arrays;
36 36
 import java.util.Collection;
37
+import java.util.Collections;
37 38
 import java.util.HashMap;
38 39
 import java.util.HashSet;
39 40
 import java.util.Map;
@@ -71,9 +72,16 @@ public class WebWindowManager implements FrameListener {
71 72
     /** The controller that owns this manager. */
72 73
     private final WebInterfaceUI controller;
73 74
 
75
+    /** The ID of the next window to be created. */
76
+    private long nextId = 0l;
77
+
74 78
     /** Map of known windows. */
75
-    private final Map<FrameContainer, Window> windows
76
-            = new HashMap<FrameContainer, Window>();
79
+    private final Map<FrameContainer, WebWindow> windows
80
+            = new HashMap<FrameContainer, WebWindow>();
81
+
82
+    /** A map of window IDs to their windows. */
83
+    private final Map<String, WebWindow> windowsById
84
+            = new HashMap<String, WebWindow>();
77 85
 
78 86
     /**
79 87
      * Creates a new window manager for the specified controller.
@@ -93,10 +101,20 @@ public class WebWindowManager implements FrameListener {
93 101
      * @param container The container whose window should be retrieved
94 102
      * @return The corresponding web window, or null if there is none
95 103
      */
96
-    public Window getWindow(final FrameContainer container) {
104
+    public WebWindow getWindow(final FrameContainer container) {
97 105
         return windows.get(container);
98 106
     }
99 107
 
108
+    /**
109
+     * Retrieves the web window with the specified ID, if any.
110
+     *
111
+     * @param id The ID of the window to retrieve
112
+     * @return The corresponding web window, or null if there isn't one
113
+     */
114
+    public WebWindow getWindow(final String id) {
115
+        return windowsById.get(id);
116
+    }
117
+
100 118
     /** {@inheritDoc} */
101 119
     @Override
102 120
     public void addWindow(final FrameContainer window, final boolean focus) {
@@ -107,6 +125,7 @@ public class WebWindowManager implements FrameListener {
107 125
     @Override
108 126
     public void delWindow(final FrameContainer window) {
109 127
         if (windows.containsKey(window)) {
128
+            windowsById.remove(windows.get(window).getId());
110 129
             windows.remove(window);
111 130
         }
112 131
     }
@@ -128,6 +147,15 @@ public class WebWindowManager implements FrameListener {
128 147
         }
129 148
     }
130 149
 
150
+    /**
151
+     * Retrieves a collection of all known windows.
152
+     *
153
+     * @return The collection of all known windows
154
+     */
155
+    public Collection<WebWindow> getWindows() {
156
+        return Collections.unmodifiableCollection(windows.values());
157
+    }
158
+
131 159
     /**
132 160
      * Creates a new window for the specified container.
133 161
      *
@@ -147,9 +175,12 @@ public class WebWindowManager implements FrameListener {
147 175
         }
148 176
 
149 177
         try {
150
-            final Window frame = (Window) clazz.getConstructors()[0].newInstance(controller, window);
178
+            final String id = String.valueOf(nextId++);
179
+
180
+            final WebWindow frame = (WebWindow) clazz.getConstructors()[0].newInstance(controller, window, id);
151 181
 
152 182
             windows.put(window, frame);
183
+            windowsById.put(id, frame);
153 184
         } catch (Exception ex) {
154 185
             Logger.appError(ErrorLevel.MEDIUM, "Unable to create window of type "
155 186
                     + clazz.getCanonicalName() + " for web ui", ex);

+ 1
- 1
src/com/dmdirc/addons/ui_web/uicomponents/WebInputField.java View File

@@ -30,7 +30,7 @@ import java.awt.event.ActionListener;
30 30
 import java.awt.event.KeyListener;
31 31
 
32 32
 /**
33
- * An input field for a specific
33
+ * An input field for a specific client.
34 34
  */
35 35
 public class WebInputField implements InputField {
36 36
 

+ 2
- 2
src/com/dmdirc/addons/ui_web/uicomponents/WebInputWindow.java View File

@@ -47,8 +47,8 @@ public class WebInputWindow extends WebWindow implements InputWindow {
47 47
             = new HashMap<Client, WebInputHandler>();
48 48
 
49 49
     public WebInputWindow(final WebInterfaceUI controller,
50
-            final WritableFrameContainer parent) {
51
-        super(controller, parent);
50
+            final WritableFrameContainer parent, final String id) {
51
+        super(controller, parent, id);
52 52
         this.parent = parent;
53 53
         this.commandparser = parent.getCommandParser();
54 54
         this.inputhandler = new WebInputHandler(new WebInputField(),

+ 12
- 23
src/com/dmdirc/addons/ui_web/uicomponents/WebWindow.java View File

@@ -38,8 +38,6 @@ import java.awt.Color;
38 38
 import java.awt.font.TextAttribute;
39 39
 import java.text.AttributedCharacterIterator;
40 40
 import java.util.ArrayList;
41
-import java.util.Collection;
42
-import java.util.HashMap;
43 41
 import java.util.List;
44 42
 import java.util.Map;
45 43
 
@@ -51,27 +49,27 @@ import org.apache.commons.lang.StringEscapeUtils;
51 49
 public class WebWindow implements Window, IRCDocumentListener,
52 50
         FrameInfoListener, FrameCloseListener {
53 51
 
54
-    protected static int counter = 0;
55
-
56
-    protected static final Map<String, WebWindow> WINDOWS
57
-            = new HashMap<String, WebWindow>();
58
-
59
-    protected int myID = ++counter;
52
+    /** The unique ID of this window, used by clients to address the window. */
53
+    private final String id;
60 54
 
55
+    /** The container that this window corresponds to. */
61 56
     private final FrameContainer parent;
62 57
 
63 58
     /** The handler to pass global events to. */
64 59
     private final DynamicRequestHandler handler;
65 60
 
61
+    /** The controller that owns this window. */
62
+    private final WebInterfaceUI controller;
63
+
66 64
     public WebWindow(final WebInterfaceUI controller,
67
-            final FrameContainer parent) {
65
+            final FrameContainer parent, final String id) {
68 66
         super();
69 67
 
68
+        this.id = id;
70 69
         this.parent = parent;
70
+        this.controller = controller;
71 71
         this.handler = controller.getHandler();
72 72
 
73
-        WINDOWS.put(getId(), this);
74
-
75 73
         parent.getDocument().addIRCDocumentListener(this);
76 74
         parent.addFrameInfoListener(this);
77 75
 
@@ -84,14 +82,6 @@ public class WebWindow implements Window, IRCDocumentListener,
84 82
         }
85 83
     }
86 84
 
87
-    public static Collection<WebWindow> getWindows() {
88
-        return WINDOWS.values();
89
-    }
90
-
91
-    public static WebWindow getWindow(final String id) {
92
-        return WINDOWS.get(id);
93
-    }
94
-
95 85
     public List<String> getMessages() {
96 86
         final List<String> messages = new ArrayList<String>(getContainer()
97 87
                 .getDocument().getNumLines());
@@ -110,7 +100,7 @@ public class WebWindow implements Window, IRCDocumentListener,
110 100
     }
111 101
 
112 102
     public String getId() {
113
-        return String.valueOf(myID);
103
+        return id;
114 104
     }
115 105
 
116 106
     protected String style(final AttributedCharacterIterator aci) {
@@ -206,8 +196,7 @@ public class WebWindow implements Window, IRCDocumentListener,
206 196
     /** {@inheritDoc} */
207 197
     @Override
208 198
     public UIController getController() {
209
-        //TODO FIXME
210
-        return null;
199
+        return controller;
211 200
     }
212 201
 
213 202
     /** {@inheritDoc} */
@@ -258,7 +247,7 @@ public class WebWindow implements Window, IRCDocumentListener,
258 247
     /** {@inheritDoc} */
259 248
     @Override
260 249
     public void windowClosing(final FrameContainer window) {
261
-        handler.addEvent(new Event("closewindow", myID));
250
+        handler.addEvent(new Event("closewindow", id));
262 251
     }
263 252
 
264 253
     /**

Loading…
Cancel
Save