Selaa lähdekoodia

Some more UI abstraction (server window)

git-svn-id: http://svn.dmdirc.com/trunk@1579 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5
Chris Smith 17 vuotta sitten
vanhempi
commit
73a8f92b6a

+ 30
- 26
src/com/dmdirc/Server.java Näytä tiedosto

@@ -62,6 +62,7 @@ import com.dmdirc.ui.interfaces.InputWindow;
62 62
 import com.dmdirc.ui.MainFrame;
63 63
 import com.dmdirc.ui.ServerFrame;
64 64
 import com.dmdirc.ui.input.TabCompleter;
65
+import com.dmdirc.ui.interfaces.ServerWindow;
65 66
 import com.dmdirc.ui.interfaces.Window;
66 67
 import com.dmdirc.ui.messages.Formatter;
67 68
 
@@ -109,8 +110,8 @@ public final class Server extends WritableFrameContainer implements
109 110
     private IRCParser parser;
110 111
     /** The raw frame used for this server instance. */
111 112
     private Raw raw;
112
-    /** The ServerFrame corresponding to this server. */
113
-    private ServerFrame frame;
113
+    /** The ServerWindow corresponding to this server. */
114
+    private ServerWindow window;
114 115
     
115 116
     /** The name of the server we're connecting to. */
116 117
     private String server;
@@ -163,13 +164,16 @@ public final class Server extends WritableFrameContainer implements
163 164
         
164 165
         configManager = new ConfigManager("", "", server);
165 166
         
166
-        frame = new ServerFrame(this);
167
-        frame.setTitle(server + ":" + port);
168
-        frame.getInputHandler().setTabCompleter(tabCompleter);
169
-        frame.addInternalFrameListener(this);
170
-        MainFrame.getMainFrame().addChild(frame);
167
+        window = new ServerFrame(this);
171 168
         
172
-        frame.open();
169
+        window.setTitle(server + ":" + port);
170
+        
171
+        window.getInputHandler().setTabCompleter(tabCompleter);
172
+        
173
+        ((ServerFrame) window).addInternalFrameListener(this);
174
+        MainFrame.getMainFrame().addChild(window);
175
+        
176
+        window.open();
173 177
         
174 178
         tabCompleter.addEntries(CommandManager.getServerCommandNames());
175 179
         tabCompleter.addEntries(CommandManager.getGlobalCommandNames());
@@ -223,9 +227,10 @@ public final class Server extends WritableFrameContainer implements
223 227
             imageURL = cldr.getResource("com/dmdirc/res/server.png");
224 228
         }
225 229
         imageIcon = new ImageIcon(imageURL);
226
-        frame.setFrameIcon(imageIcon);
227 230
         
228
-        frame.addLine("serverConnecting", server, port);
231
+        window.setFrameIcon(imageIcon);
232
+        
233
+        window.addLine("serverConnecting", server, port);
229 234
         
230 235
         final MyInfo myInfo = new MyInfo();
231 236
         myInfo.setNickname(profile.getOption("profile", "nickname"));
@@ -262,7 +267,7 @@ public final class Server extends WritableFrameContainer implements
262 267
         
263 268
         away = false;
264 269
         awayMessage = null;
265
-        frame.setAway(false);
270
+        ((ServerFrame) window).setAway(false);
266 271
         
267 272
         try {
268 273
             new Thread(parser).start();
@@ -472,7 +477,7 @@ public final class Server extends WritableFrameContainer implements
472 477
     
473 478
     /** {@inheritDoc} */
474 479
     public InputWindow getFrame() {
475
-        return frame;
480
+        return window;
476 481
     }
477 482
     
478 483
     /** {@inheritDoc} */
@@ -494,9 +499,9 @@ public final class Server extends WritableFrameContainer implements
494 499
             parser.getCallbackManager().delAllCallback(this);
495 500
         }
496 501
         
497
-        if (frame != null) {
502
+        if (window != null) {
498 503
             // Unregister frame callbacks
499
-            frame.removeInternalFrameListener(this);
504
+            ((ServerFrame) window).removeInternalFrameListener(this);
500 505
         }
501 506
         
502 507
         // Disconnect from the server
@@ -512,13 +517,12 @@ public final class Server extends WritableFrameContainer implements
512 517
         // Unregister ourselves with the server manager
513 518
         ServerManager.getServerManager().unregisterServer(this);
514 519
         
515
-        if (frame != null) {
520
+        if (window != null) {
516 521
             SwingUtilities.invokeLater(new Runnable() {
517 522
                 public void run() {
518
-                    // Close our own window
519
-                    frame.setVisible(false);
520
-                    MainFrame.getMainFrame().delChild(frame);
521
-                    frame = null;
523
+                    window.setVisible(false);
524
+                    MainFrame.getMainFrame().delChild(window);
525
+                    window = null;
522 526
                 }
523 527
             });
524 528
         }
@@ -663,7 +667,7 @@ public final class Server extends WritableFrameContainer implements
663 667
     @Override
664 668
     public boolean ownsFrame(final Window target) {
665 669
         // Check if it's our server frame
666
-        if (frame != null && frame.equals(target)) { return true; }
670
+        if (window != null && window.equals(target)) { return true; }
667 671
         // Check if it's the raw frame
668 672
         if (raw != null && raw.ownsFrame(target)) { return true; }
669 673
         // Check if it's a channel frame
@@ -717,7 +721,7 @@ public final class Server extends WritableFrameContainer implements
717 721
             query.getFrame().addLine(messageType, args);
718 722
         }
719 723
         
720
-        frame.addLine(messageType, args);
724
+        window.addLine(messageType, args);
721 725
     }
722 726
     
723 727
     /**
@@ -859,17 +863,17 @@ public final class Server extends WritableFrameContainer implements
859 863
     
860 864
     /** {@inheritDoc} */
861 865
     public void onMOTDStart(final IRCParser tParser, final String sData) {
862
-        frame.addLine("motdStart", sData);
866
+        window.addLine("motdStart", sData);
863 867
     }
864 868
     
865 869
     /** {@inheritDoc} */
866 870
     public void onMOTDLine(final IRCParser tParser, final String sData) {
867
-        frame.addLine("motdLine", sData);
871
+        window.addLine("motdLine", sData);
868 872
     }
869 873
     
870 874
     /** {@inheritDoc} */
871 875
     public void onMOTDEnd(final IRCParser tParser, final boolean noMOTD) {
872
-        frame.addLine("motdEnd", "End of server's MOTD.");
876
+        window.addLine("motdEnd", "End of server's MOTD.");
873 877
     }
874 878
     
875 879
     /** {@inheritDoc} */
@@ -918,7 +922,7 @@ public final class Server extends WritableFrameContainer implements
918 922
         ActionManager.processEvent(CoreActionType.SERVER_USERMODES, format,
919 923
                 this, setter, sModes);
920 924
         
921
-        frame.addLine(format, setterParts[0], setterParts[1], setterParts[2],
925
+        window.addLine(format, setterParts[0], setterParts[1], setterParts[2],
922 926
                 sModes);
923 927
     }
924 928
     
@@ -937,7 +941,7 @@ public final class Server extends WritableFrameContainer implements
937 941
             ActionManager.processEvent(CoreActionType.SERVER_BACK, null, this);
938 942
         }
939 943
         
940
-        frame.setAway(away);
944
+        ((ServerFrame) window).setAway(away);
941 945
     }
942 946
     
943 947
     /** {@inheritDoc} */

+ 12
- 8
src/com/dmdirc/ui/MainFrame.java Näytä tiedosto

@@ -93,7 +93,7 @@ public final class MainFrame extends JFrame implements WindowListener,
93 93
      * structure is changed (or anything else that would prevent serialized
94 94
      * objects being unserialized with the new class).
95 95
      */
96
-    private static final long serialVersionUID = 5;
96
+    private static final long serialVersionUID = 6;
97 97
     
98 98
     /**
99 99
      * The number of pixels each new internal frame is offset by.
@@ -243,10 +243,13 @@ public final class MainFrame extends JFrame implements WindowListener,
243 243
     }
244 244
     
245 245
     /**
246
-     * Adds the specified InternalFrame as a child of the main frame.
247
-     * @param frame the frame to be added
246
+     * Adds the specified window as a child of the main frame.
247
+     * 
248
+     * @param window the window to be added
248 249
      */
249
-    public void addChild(final JInternalFrame frame) {
250
+    public void addChild(final Window window) {
251
+        final JInternalFrame frame = (JInternalFrame) window;
252
+        
250 253
         // Add the frame
251 254
         desktopPane.add(frame);
252 255
         
@@ -268,11 +271,12 @@ public final class MainFrame extends JFrame implements WindowListener,
268 271
     }
269 272
     
270 273
     /**
271
-     * Removes the specified InternalFrame from our desktop pane.
272
-     * @param frame The frame to be removed
274
+     * Removes the specified window from our desktop pane.
275
+     * 
276
+     * @param window The window to be removed
273 277
      */
274
-    public void delChild(final JInternalFrame frame) {
275
-        desktopPane.remove(frame);
278
+    public void delChild(final Window window) {
279
+        desktopPane.remove((JInternalFrame) window);
276 280
         if (desktopPane.getAllFrames().length == 0) {
277 281
             setTitle(getTitlePrefix());
278 282
         }

+ 2
- 1
src/com/dmdirc/ui/ServerFrame.java Näytä tiedosto

@@ -29,6 +29,7 @@ import com.dmdirc.commandparser.CommandParser;
29 29
 import com.dmdirc.commandparser.ServerCommandParser;
30 30
 import com.dmdirc.ui.input.InputHandler;
31 31
 import com.dmdirc.ui.components.InputFrame;
32
+import com.dmdirc.ui.interfaces.ServerWindow;
32 33
 
33 34
 import java.awt.GridBagConstraints;
34 35
 import java.awt.GridBagLayout;
@@ -37,7 +38,7 @@ import java.awt.Insets;
37 38
 /**
38 39
  * The ServerFrame is the MDI window that shows server messages to the user.
39 40
  */
40
-public final class ServerFrame extends InputFrame {
41
+public final class ServerFrame extends InputFrame implements ServerWindow {
41 42
     
42 43
     /**
43 44
      * A version number for this class. It should be changed whenever the class

+ 12
- 2
src/com/dmdirc/ui/interfaces/InputWindow.java Näytä tiedosto

@@ -23,18 +23,28 @@
23 23
 package com.dmdirc.ui.interfaces;
24 24
 
25 25
 import com.dmdirc.commandparser.CommandParser;
26
+import com.dmdirc.ui.input.InputHandler;
26 27
 
27 28
 /**
28 29
  * The Input Window interface specifies additional methods that windows should
29 30
  * implement if they have an input field.
31
+ * 
30 32
  * @author chris
31 33
  */
32 34
 public interface InputWindow extends Window {
33 35
     
34 36
     /**
35
-     * Retrieves the command Parser for this command window.
36
-     * @return This window's command Parser
37
+     * Retrieves the command Parser for this input window.
38
+     * 
39
+     * @return This window's command parser
37 40
      */
38 41
     CommandParser getCommandParser();
39 42
     
43
+    /**
44
+     * Retrieves the input handler for this input window.
45
+     * 
46
+     * @return This window's input handler
47
+     */
48
+    InputHandler getInputHandler();
49
+    
40 50
 }

+ 32
- 0
src/com/dmdirc/ui/interfaces/ServerWindow.java Näytä tiedosto

@@ -0,0 +1,32 @@
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.interfaces;
24
+
25
+/**
26
+ * Lists the standard methods that should be implemented by any server window.
27
+ * 
28
+ * @author chris
29
+ */
30
+public interface ServerWindow extends InputWindow {
31
+    
32
+}

+ 30
- 1
src/com/dmdirc/ui/interfaces/Window.java Näytä tiedosto

@@ -24,7 +24,9 @@ package com.dmdirc.ui.interfaces;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.identities.ConfigManager;
27
+
27 28
 import java.beans.PropertyVetoException;
29
+import javax.swing.Icon;
28 30
 
29 31
 /**
30 32
  * The Window interface specifies common methods that should be implemented
@@ -70,12 +72,19 @@ public interface Window {
70 72
     FrameContainer getContainer();
71 73
     
72 74
     /**
73
-     * Determines if the current frame is visible.
75
+     * Determines if the current window is visible.
74 76
      *
75 77
      * @return boolean visibility
76 78
      */
77 79
     boolean isVisible();
78 80
     
81
+    /**
82
+     * Sets the visibility of this window.
83
+     * 
84
+     * @param isVisible Whether the window should be visible or not
85
+     */
86
+    void setVisible(boolean isVisible);
87
+    
79 88
     /**
80 89
      * Retrives the current title of this window.
81 90
      * 
@@ -97,4 +106,24 @@ public interface Window {
97 106
      * @throws PropertyVetoException if the change is vetoed
98 107
      */
99 108
     void setMaximum(boolean b) throws PropertyVetoException;
109
+    
110
+    /**
111
+     * Sets the title of this window.
112
+     * 
113
+     * @param title The new title to be used.
114
+     */
115
+    void setTitle(String title);
116
+    
117
+    /**
118
+     * Opens this window.
119
+     */
120
+    void open();
121
+    
122
+    /**
123
+     * Sets the icon used by this window, if the GUI supports icons.
124
+     * 
125
+     * @param icon The icon to be used
126
+     */
127
+    void setFrameIcon(Icon icon);
128
+    
100 129
 }

Loading…
Peruuta
Tallenna