Browse Source

Window Manager work. Horribly broken at the minute, but my PC can't seem to cope with editing files.


git-svn-id: http://svn.dmdirc.com/trunk@2440 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5.5
Chris Smith 16 years ago
parent
commit
e0a444553c

+ 3
- 2
src/com/dmdirc/GlobalWindow.java View File

@@ -26,6 +26,7 @@ import com.dmdirc.commandparser.CommandManager;
26 26
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
27 27
 import com.dmdirc.config.ConfigManager;
28 28
 import com.dmdirc.config.IdentityManager;
29
+import com.dmdirc.ui.WindowManager;
29 30
 import com.dmdirc.ui.input.TabCompleter;
30 31
 import com.dmdirc.ui.interfaces.InputWindow;
31 32
 
@@ -54,7 +55,7 @@ public class GlobalWindow extends WritableFrameContainer {
54 55
         window.getInputHandler().setTabCompleter(tabCompleter);
55 56
         window.setFrameIcon(icon);        
56 57
         
57
-        Main.getUI().getMainWindow().getFrameManager().addWindow(this);
58
+        WindowManager.addWindow(window);
58 59
         
59 60
         window.open();
60 61
     }
@@ -69,7 +70,7 @@ public class GlobalWindow extends WritableFrameContainer {
69 70
 
70 71
     public void close() {
71 72
         window.setVisible(false);
72
-        Main.getUI().getMainWindow().getFrameManager().delWindow(this);
73
+        WindowManager.removeWindow(window);
73 74
     }
74 75
 
75 76
     public Server getServer() {

+ 6
- 5
src/com/dmdirc/Server.java View File

@@ -38,6 +38,7 @@ import com.dmdirc.parser.IRCParser;
38 38
 import com.dmdirc.parser.MyInfo;
39 39
 import com.dmdirc.parser.ParserError;
40 40
 import com.dmdirc.parser.ServerInfo;
41
+import com.dmdirc.ui.WindowManager;
41 42
 import com.dmdirc.ui.input.TabCompleter;
42 43
 import com.dmdirc.ui.interfaces.InputWindow;
43 44
 import com.dmdirc.ui.interfaces.ServerWindow;
@@ -660,7 +661,7 @@ public final class Server extends WritableFrameContainer implements Serializable
660 661
      * closed).
661 662
      */
662 663
     public void delRaw() {
663
-        Main.getUI().getMainWindow().getFrameManager().delWindow(this, raw);
664
+        WindowManager.removeWindow(raw.getFrame());
664 665
         raw = null; //NOPMD
665 666
     }
666 667
     
@@ -671,8 +672,8 @@ public final class Server extends WritableFrameContainer implements Serializable
671 672
      */
672 673
     public void delChannel(final String chan) {
673 674
         tabCompleter.removeEntry(chan);
674
-        Main.getUI().getMainWindow().getFrameManager().delWindow(
675
-                this, channels.get(parser.toLowerCase(chan)));
675
+        WindowManager.removeWindow(
676
+                channels.get(parser.toLowerCase(chan)).getFrame());
676 677
         channels.remove(parser.toLowerCase(chan));
677 678
     }
678 679
     
@@ -715,8 +716,8 @@ public final class Server extends WritableFrameContainer implements Serializable
715 716
      */
716 717
     public void delQuery(final String host) {
717 718
         tabCompleter.removeEntry(ClientInfo.parseHost(host));
718
-        Main.getUI().getMainWindow().getFrameManager().delWindow(this,
719
-                queries.get(parser.toLowerCase(ClientInfo.parseHost(host))));
719
+        WindowManager.removeWindow(
720
+                queries.get(parser.toLowerCase(ClientInfo.parseHost(host))).getFrame());
720 721
         queries.remove(parser.toLowerCase(ClientInfo.parseHost(host)));
721 722
     }
722 723
     

+ 3
- 1
src/com/dmdirc/ServerManager.java View File

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc;
24 24
 
25
+import com.dmdirc.ui.WindowManager;
25 26
 import com.dmdirc.ui.interfaces.Window;
26 27
 
27 28
 import java.util.ArrayList;
@@ -84,7 +85,8 @@ public final class ServerManager {
84 85
         if (!closing) {
85 86
             servers.remove(server);
86 87
         }
87
-        Main.getUI().getMainWindow().getFrameManager().delWindow(server);
88
+        
89
+        WindowManager.removeWindow(server.getFrame());
88 90
     }
89 91
     
90 92
     /**

+ 140
- 0
src/com/dmdirc/ui/WindowManager.java View File

@@ -0,0 +1,140 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
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.ui;
24
+
25
+import com.dmdirc.Main;
26
+import com.dmdirc.logger.Logger;
27
+import com.dmdirc.ui.interfaces.FrameManager;
28
+import com.dmdirc.ui.interfaces.Window;
29
+
30
+import java.util.ArrayList;
31
+import java.util.HashMap;
32
+import java.util.List;
33
+import java.util.Map;
34
+import java.util.Map.Entry;
35
+
36
+public class WindowManager {
37
+    
38
+    private final static List<Window> rootWindows = new ArrayList<Window>();
39
+    
40
+    private final static Map<Window, List<Window>> childWindows = new HashMap<Window, List<Window>>();
41
+    
42
+    private final static List<FrameManager> frameManagers = new ArrayList<FrameManager>();
43
+    
44
+    static {
45
+        frameManagers.add(Main.getUI().getMainWindow().getFrameManager());
46
+    }
47
+    
48
+    private WindowManager() {
49
+        // Shouldn't be instansiated
50
+    }
51
+    
52
+    public static void addFrameManager(final FrameManager frameManager) {
53
+        Logger.doAssertion(frameManager != null);
54
+        Logger.doAssertion(!frameManagers.contains(frameManager));
55
+        
56
+        frameManagers.add(frameManager);
57
+    }
58
+    
59
+    public static void removeFrameManager(final FrameManager frameManager) {
60
+        Logger.doAssertion(frameManager != null);
61
+        Logger.doAssertion(frameManagers.contains(frameManager));
62
+        
63
+        frameManagers.remove(frameManager);
64
+    }
65
+    
66
+    public static void addWindow(final Window window) {
67
+        Logger.doAssertion(window != null);
68
+        Logger.doAssertion(!rootWindows.contains(window));
69
+        
70
+        rootWindows.add(window);
71
+        childWindows.put(window, new ArrayList<Window>());
72
+        
73
+        fireAddWindow(window);
74
+    }
75
+    
76
+    public static void addWindow(final Window parent, final Window child) {
77
+        Logger.doAssertion(parent != null, child != null);
78
+        Logger.doAssertion(childWindows.containsKey(parent), !childWindows.containsKey(child));
79
+        
80
+        childWindows.get(parent).add(child);
81
+        childWindows.put(child, new ArrayList<Window>());
82
+        
83
+        fireAddWindow(parent, child);
84
+    }
85
+    
86
+    public static void removeWindow(final Window window) {
87
+        Logger.doAssertion(window != null);
88
+        Logger.doAssertion(childWindows.containsKey(window));
89
+        Logger.doAssertion(childWindows.get(window).isEmpty());
90
+        
91
+        childWindows.remove(window);
92
+        
93
+        if (rootWindows.contains(window)) {
94
+            rootWindows.remove(window);
95
+            
96
+            fireDeleteWindow(window);
97
+        } else {
98
+            final Window parent = getParent(window);
99
+            
100
+            childWindows.get(parent).remove(window);
101
+            
102
+            fireDeleteWindow(parent, window);
103
+        }
104
+    }
105
+    
106
+    private static Window getParent(final Window window) {
107
+        for (Entry<Window, List<Window>> entry : childWindows.entrySet()) {
108
+            if (entry.getValue().contains(window)) {
109
+                return entry.getKey();
110
+            }
111
+        }
112
+        
113
+        return null;
114
+    }
115
+    
116
+    private static void fireAddWindow(final Window window) {
117
+        for (FrameManager manager : frameManagers) {
118
+            manager.addWindow(window.getContainer());
119
+        }
120
+    }
121
+    
122
+    private static void fireAddWindow(final Window parent, final Window child) {
123
+        for (FrameManager manager : frameManagers) {
124
+            manager.addWindow(parent.getContainer(), child.getContainer());
125
+        }
126
+    }
127
+    
128
+    private static void fireDeleteWindow(final Window window) {
129
+        for (FrameManager manager : frameManagers) {
130
+            manager.delWindow(window.getContainer());
131
+        }
132
+    }
133
+    
134
+    private static void fireDeleteWindow(final Window parent, final Window child) {
135
+        for (FrameManager manager : frameManagers) {
136
+            manager.delWindow(parent.getContainer(), child.getContainer());
137
+        }
138
+    }
139
+    
140
+}

+ 1
- 0
src/com/dmdirc/ui/dummy/DummyMainWindow.java View File

@@ -72,6 +72,7 @@ public final class DummyMainWindow implements MainWindow {
72 72
     }
73 73
     
74 74
     /** {@inheritDoc} */
75
+    @Deprecated
75 76
     public FrameManager getFrameManager() {
76 77
         return new DummyFrameManager();
77 78
     }

+ 2
- 0
src/com/dmdirc/ui/interfaces/MainWindow.java View File

@@ -55,7 +55,9 @@ public interface MainWindow {
55 55
      * Retrieves the frame manager that's currently in use.
56 56
      *
57 57
      * @return The current frame manager
58
+     * @deprecated Frame Managers should interface via WindowManager.
58 59
      */
60
+    @Deprecated
59 61
     FrameManager getFrameManager();
60 62
     
61 63
     /**

+ 1
- 0
src/com/dmdirc/ui/swing/MainFrame.java View File

@@ -288,6 +288,7 @@ public final class MainFrame extends JFrame implements WindowListener,
288 288
 
289 289
     /** {@inheritDoc}. */
290 290
     @Override
291
+    @Deprecated
291 292
     public FrameManager getFrameManager() {
292 293
         return mainFrameManager;
293 294
     }

Loading…
Cancel
Save