Bläddra i källkod

More abstraction (core no longer deals with internal frame listener stuff)

This breaks the raw window quite impressively, will be fixed when it's made into a custom window.

git-svn-id: http://svn.dmdirc.com/trunk@1580 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5
Chris Smith 17 år sedan
förälder
incheckning
880560a067

+ 0
- 1
src/com/dmdirc/Channel.java Visa fil

@@ -132,7 +132,6 @@ public final class Channel extends WritableFrameContainer implements
132 132
                 public void run() {
133 133
                     frame = new ChannelFrame(Channel.this);
134 134
                     MainFrame.getMainFrame().addChild(frame);
135
-                    frame.addInternalFrameListener(Channel.this);
136 135
                     frame.setFrameIcon(imageIcon);
137 136
                     frame.getInputHandler().setTabCompleter(tabCompleter);
138 137
                 }

+ 22
- 39
src/com/dmdirc/FrameContainer.java Visa fil

@@ -25,7 +25,6 @@ package com.dmdirc;
25 25
 import com.dmdirc.identities.ConfigManager;
26 26
 import com.dmdirc.logger.ErrorLevel;
27 27
 import com.dmdirc.logger.Logger;
28
-import com.dmdirc.ui.interfaces.InputWindow;
29 28
 import com.dmdirc.ui.MainFrame;
30 29
 import com.dmdirc.ui.interfaces.Window;
31 30
 
@@ -33,16 +32,14 @@ import java.awt.Color;
33 32
 import java.beans.PropertyVetoException;
34 33
 
35 34
 import javax.swing.ImageIcon;
36
-import javax.swing.event.InternalFrameEvent;
37
-import javax.swing.event.InternalFrameListener;
38 35
 
39 36
 /**
40 37
  * The frame container implements basic methods that should be present in
41 38
  * all objects that handle a frame.
42
- * 
39
+ *
43 40
  * @author chris
44 41
  */
45
-public abstract class FrameContainer implements InternalFrameListener {
42
+public abstract class FrameContainer {
46 43
     
47 44
     /** The colour of our frame's notifications. */
48 45
     protected Color notification = Color.BLACK;
@@ -52,13 +49,14 @@ public abstract class FrameContainer implements InternalFrameListener {
52 49
     
53 50
     /**
54 51
      * Returns the internal frame associated with this object.
55
-     * 
52
+     *
56 53
      * @return The internal frame associated with this object
57 54
      */
58 55
     public abstract Window getFrame();
59 56
     
60 57
     /**
61 58
      * Returns a string identifier for this object/its frame.
59
+     *
62 60
      * @return String identifier
63 61
      */
64 62
     public abstract String toString();
@@ -70,12 +68,14 @@ public abstract class FrameContainer implements InternalFrameListener {
70 68
     
71 69
     /**
72 70
      * Returns the server instance associated with this container.
71
+     *
73 72
      * @return the associated server connection
74 73
      */
75 74
     public abstract Server getServer();
76 75
     
77 76
     /**
78 77
      * Retrieves the icon used by the query frame.
78
+     *
79 79
      * @return The query frame's icon
80 80
      */
81 81
     public ImageIcon getIcon() {
@@ -84,6 +84,7 @@ public abstract class FrameContainer implements InternalFrameListener {
84 84
     
85 85
     /**
86 86
      * Returns the config manager for this container.
87
+     *
87 88
      * @return the associated config manager
88 89
      */
89 90
     public ConfigManager getConfigManager() {
@@ -107,6 +108,7 @@ public abstract class FrameContainer implements InternalFrameListener {
107 108
     
108 109
     /**
109 110
      * Sends a notification to the frame manager if this fame isn't active.
111
+     *
110 112
      * @param colour The colour to use for the notification
111 113
      */
112 114
     public void sendNotification(final Color colour) {
@@ -119,6 +121,7 @@ public abstract class FrameContainer implements InternalFrameListener {
119 121
     
120 122
     /**
121 123
      * Retrieves the current notification colour of this channel.
124
+     *
122 125
      * @return This channel's notification colour
123 126
      */
124 127
     public Color getNotification() {
@@ -127,6 +130,7 @@ public abstract class FrameContainer implements InternalFrameListener {
127 130
     
128 131
     /**
129 132
      * Determines if the specified frame is owned by this object.
133
+     *
130 134
      * @param target Window to check ownership of
131 135
      * @return True iff frame is owned by this container, false otherwise
132 136
      */
@@ -135,10 +139,9 @@ public abstract class FrameContainer implements InternalFrameListener {
135 139
     }
136 140
     
137 141
     /**
138
-     * Invoked when a internal frame has been opened.
139
-     * @param internalFrameEvent frame opened event
142
+     * Invoked when our window has been opened.
140 143
      */
141
-    public void internalFrameOpened(final InternalFrameEvent internalFrameEvent) {
144
+    public void windowOpened() {
142 145
         final boolean pref = getServer().getConfigManager().getOptionBool("ui", "maximisewindows");
143 146
         if (pref || MainFrame.getMainFrame().getMaximised()) {
144 147
             try {
@@ -150,42 +153,23 @@ public abstract class FrameContainer implements InternalFrameListener {
150 153
     }
151 154
     
152 155
     /**
153
-     * Invoked when an internal frame is in the process of being closed.
154
-     * @param internalFrameEvent frame closing event
156
+     * Invoked when our window is closing.
155 157
      */
156
-    public void internalFrameClosing(final InternalFrameEvent internalFrameEvent) {
158
+    public void windowClosing() {
157 159
         close();
158 160
     }
159 161
     
160 162
     /**
161
-     * Invoked when an internal frame has been closed.
162
-     * @param internalFrameEvent frame closed event
163
-     */
164
-    public void internalFrameClosed(final InternalFrameEvent internalFrameEvent) {
165
-        //Ignore.
166
-    }
167
-    
168
-    /**
169
-     * Invoked when an internal frame is iconified.
170
-     * @param internalFrameEvent frame iconified event
171
-     */
172
-    public void internalFrameIconified(final InternalFrameEvent internalFrameEvent) {
173
-        //Ignore.
174
-    }
175
-    
176
-    /**
177
-     * Invoked when an internal frame is de-iconified.
178
-     * @param internalFrameEvent frame deiconified event
163
+     * Invoked when our window has been closed.
179 164
      */
180
-    public void internalFrameDeiconified(final InternalFrameEvent internalFrameEvent) {
181
-        //Ignore.
165
+    public void windowClosed() {
166
+        // Ignore.
182 167
     }
183 168
     
184 169
     /**
185
-     * Invoked when an internal frame is activated.
186
-     * @param internalFrameEvent frame activation event
170
+     * Invoked when our window is activated.
187 171
      */
188
-    public void internalFrameActivated(final InternalFrameEvent internalFrameEvent) {
172
+    public void windowActivated() {
189 173
         if (MainFrame.getMainFrame().getMaximised()) {
190 174
             try {
191 175
                 getFrame().setMaximum(true);
@@ -199,11 +183,10 @@ public abstract class FrameContainer implements InternalFrameListener {
199 183
     }
200 184
     
201 185
     /**
202
-     * Invoked when an internal frame is de-activated.
203
-     * @param internalFrameEvent frame deactivation event
186
+     * Invoked when our window is deactivated.
204 187
      */
205
-    public void internalFrameDeactivated(final InternalFrameEvent internalFrameEvent) {
206
-        //Ignore.
188
+    public void windowDeactivated() {
189
+        // Do nothing.
207 190
     }
208 191
     
209 192
 }

+ 0
- 1
src/com/dmdirc/Query.java Visa fil

@@ -85,7 +85,6 @@ public final class Query extends WritableFrameContainer implements
85 85
         ActionManager.processEvent(CoreActionType.QUERY_OPENED, null, this);
86 86
         
87 87
         MainFrame.getMainFrame().addChild(frame);
88
-        frame.addInternalFrameListener(this);
89 88
         frame.setFrameIcon(imageIcon);
90 89
         
91 90
         if (!Config.getOptionBool("general", "hidequeries")) {

+ 0
- 1
src/com/dmdirc/Raw.java Visa fil

@@ -63,7 +63,6 @@ public final class Raw extends FrameContainer implements IDataIn, IDataOut {
63 63
         
64 64
         frame = new ServerFrame(server);
65 65
         frame.setTitle("(Raw log)");
66
-        frame.addInternalFrameListener(this);
67 66
         MainFrame.getMainFrame().addChild(frame);
68 67
         frame.getInputHandler().setTabCompleter(server.getTabCompleter());
69 68
         frame.setFrameIcon(imageIcon);

+ 2
- 8
src/com/dmdirc/Server.java Visa fil

@@ -170,7 +170,6 @@ public final class Server extends WritableFrameContainer implements
170 170
         
171 171
         window.getInputHandler().setTabCompleter(tabCompleter);
172 172
         
173
-        ((ServerFrame) window).addInternalFrameListener(this);
174 173
         MainFrame.getMainFrame().addChild(window);
175 174
         
176 175
         window.open();
@@ -267,7 +266,7 @@ public final class Server extends WritableFrameContainer implements
267 266
         
268 267
         away = false;
269 268
         awayMessage = null;
270
-        ((ServerFrame) window).setAway(false);
269
+        window.setAwayIndicator(false);
271 270
         
272 271
         try {
273 272
             new Thread(parser).start();
@@ -499,11 +498,6 @@ public final class Server extends WritableFrameContainer implements
499 498
             parser.getCallbackManager().delAllCallback(this);
500 499
         }
501 500
         
502
-        if (window != null) {
503
-            // Unregister frame callbacks
504
-            ((ServerFrame) window).removeInternalFrameListener(this);
505
-        }
506
-        
507 501
         // Disconnect from the server
508 502
         disconnect(reason);
509 503
         // Close all channel windows
@@ -941,7 +935,7 @@ public final class Server extends WritableFrameContainer implements
941 935
             ActionManager.processEvent(CoreActionType.SERVER_BACK, null, this);
942 936
         }
943 937
         
944
-        ((ServerFrame) window).setAway(away);
938
+        window.setAwayIndicator(away);
945 939
     }
946 940
     
947 941
     /** {@inheritDoc} */

+ 25
- 13
src/com/dmdirc/ui/ServerFrame.java Visa fil

@@ -30,6 +30,7 @@ import com.dmdirc.commandparser.ServerCommandParser;
30 30
 import com.dmdirc.ui.input.InputHandler;
31 31
 import com.dmdirc.ui.components.InputFrame;
32 32
 import com.dmdirc.ui.interfaces.ServerWindow;
33
+import java.awt.BorderLayout;
33 34
 
34 35
 import java.awt.GridBagConstraints;
35 36
 import java.awt.GridBagLayout;
@@ -79,23 +80,34 @@ public final class ServerFrame extends InputFrame implements ServerWindow {
79 80
     
80 81
     /**
81 82
      * Sets the away status for this and all associated frames.
83
+     *
82 84
      * @param newAwayState away state
83 85
      */
84
-    public void setAway(final boolean newAwayState) {
85
-        if (Config.hasOption("ui", "awayindicator")
86
-                && Config.getOptionBool("ui", "awayindicator")) {
87
-            setAwayIndicator(newAwayState);
88
-            
89
-            if (getContainer().getServer().getRaw() != null) {
90
-                ((InputFrame) getContainer().getServer().getRaw().getFrame()).setAwayIndicator(newAwayState);
91
-            }
92
-            
93
-            for (String channel : getContainer().getServer().getChannels()) {
94
-                ((InputFrame) getContainer().getServer().getChannel(channel).getFrame()).setAwayIndicator(newAwayState);
86
+    @Override
87
+    public void setAwayIndicator(final boolean newAwayState) {
88
+        if (Config.getOptionBool("ui", "awayindicator")) {
89
+            if (newAwayState) {
90
+                inputPanel.add(awayLabel, BorderLayout.LINE_START);
91
+                awayLabel.setVisible(true);
92
+            } else {
93
+                awayLabel.setVisible(false);
95 94
             }
96 95
             
97
-            for (String query : getContainer().getServer().getQueries()) {
98
-                ((InputFrame) getContainer().getServer().getQuery(query).getFrame()).setAwayIndicator(newAwayState);
96
+            // Hack++. To be removed when raw window is no longer a server frame
97
+            if (!getContainer().getServer().getRaw().getFrame().equals(this)) {
98
+                
99
+                if (getContainer().getServer().getRaw() != null) {
100
+                    getContainer().getServer().getRaw().getFrame().setAwayIndicator(newAwayState);
101
+                }
102
+                
103
+                for (String channel : getContainer().getServer().getChannels()) {
104
+                    getContainer().getServer().getChannel(channel).getFrame().setAwayIndicator(newAwayState);
105
+                }
106
+                
107
+                for (String query : getContainer().getServer().getQueries()) {
108
+                    getContainer().getServer().getQuery(query).getFrame().setAwayIndicator(newAwayState);
109
+                }
110
+                
99 111
             }
100 112
         }
101 113
     }

+ 5
- 5
src/com/dmdirc/ui/components/Frame.java Visa fil

@@ -279,21 +279,21 @@ public abstract class Frame extends JInternalFrame implements InputWindow,
279 279
      * Not needed for this class. {@inheritDoc}
280 280
      */
281 281
     public void internalFrameOpened(final InternalFrameEvent event) {
282
-        //Ignore.
282
+        parent.windowOpened();
283 283
     }
284 284
     
285 285
     /**
286 286
      * Not needed for this class. {@inheritDoc}
287 287
      */
288 288
     public void internalFrameClosing(final InternalFrameEvent event) {
289
-        //Ignore.
289
+        parent.windowClosing();
290 290
     }
291 291
     
292 292
     /**
293 293
      * Not needed for this class. {@inheritDoc}
294 294
      */
295 295
     public void internalFrameClosed(final InternalFrameEvent event) {
296
-        //Ignore.
296
+        parent.windowClosed();
297 297
     }
298 298
     
299 299
     /**
@@ -314,14 +314,14 @@ public abstract class Frame extends JInternalFrame implements InputWindow,
314 314
      * Activates the input field on frame focus. {@inheritDoc}
315 315
      */
316 316
     public void internalFrameActivated(final InternalFrameEvent event) {
317
-        //Ignore.
317
+        parent.windowActivated();
318 318
     }
319 319
     
320 320
     /**
321 321
      * Not needed for this class. {@inheritDoc}
322 322
      */
323 323
     public void internalFrameDeactivated(final InternalFrameEvent event) {
324
-        //Ignore.
324
+        parent.windowDeactivated();
325 325
     }
326 326
     
327 327
     /** {@inheritDoc} */

+ 8
- 8
src/com/dmdirc/ui/components/InputFrame.java Visa fil

@@ -52,7 +52,6 @@ import javax.swing.AbstractAction;
52 52
 import javax.swing.BorderFactory;
53 53
 import javax.swing.JLabel;
54 54
 import javax.swing.JMenuItem;
55
-import javax.swing.JOptionPane;
56 55
 import javax.swing.JPanel;
57 56
 import javax.swing.JPopupMenu;
58 57
 import javax.swing.JTextField;
@@ -107,7 +106,7 @@ public abstract class InputFrame extends Frame implements
107 106
     private Robot robot;
108 107
     
109 108
     /** Away label. */
110
-    private JLabel awayLabel;
109
+    protected JLabel awayLabel;
111 110
     
112 111
     /**
113 112
      * Creates a new instance of InputFrame.
@@ -313,35 +312,35 @@ public abstract class InputFrame extends Frame implements
313 312
      * Not needed for this class. {@inheritDoc}
314 313
      */
315 314
     public void internalFrameOpened(final InternalFrameEvent event) {
316
-        //Ignore.
315
+        super.internalFrameOpened(event);
317 316
     }
318 317
     
319 318
     /**
320 319
      * Not needed for this class. {@inheritDoc}
321 320
      */
322 321
     public void internalFrameClosing(final InternalFrameEvent event) {
323
-        //Ignore.
322
+        super.internalFrameClosing(event);
324 323
     }
325 324
     
326 325
     /**
327 326
      * Not needed for this class. {@inheritDoc}
328 327
      */
329 328
     public void internalFrameClosed(final InternalFrameEvent event) {
330
-        //Ignore.
329
+        super.internalFrameClosed(event);
331 330
     }
332 331
     
333 332
     /**
334 333
      * Makes the internal frame invisible. {@inheritDoc}
335 334
      */
336 335
     public void internalFrameIconified(final InternalFrameEvent event) {
337
-        //Ignore.
336
+        super.internalFrameIconified(event);
338 337
     }
339 338
     
340 339
     /**
341 340
      * Not needed for this class. {@inheritDoc}
342 341
      */
343 342
     public void internalFrameDeiconified(final InternalFrameEvent event) {
344
-        //Ignore.
343
+        super.internalFrameDeiconified(event);
345 344
     }
346 345
     
347 346
     /**
@@ -349,6 +348,7 @@ public abstract class InputFrame extends Frame implements
349 348
      */
350 349
     public void internalFrameActivated(final InternalFrameEvent event) {
351 350
         getInputField().requestFocus();
351
+        
352 352
         super.internalFrameActivated(event);
353 353
     }
354 354
     
@@ -356,7 +356,7 @@ public abstract class InputFrame extends Frame implements
356 356
      * Not needed for this class. {@inheritDoc}
357 357
      */
358 358
     public void internalFrameDeactivated(final InternalFrameEvent event) {
359
-        //Ignore.
359
+        super.internalFrameDeactivated(event);
360 360
     }
361 361
     
362 362
     /** {@inheritDoc} */

+ 8
- 0
src/com/dmdirc/ui/interfaces/InputWindow.java Visa fil

@@ -47,4 +47,12 @@ public interface InputWindow extends Window {
47 47
      */
48 48
     InputHandler getInputHandler();
49 49
     
50
+    /**
51
+     * Toggles the away-status indicator for this input window, if the UI
52
+     * supports it.
53
+     * 
54
+     * @param isAway Whether the away indicator should be displayed or not
55
+     */
56
+    void setAwayIndicator(boolean isAway);
57
+    
50 58
 }

Laddar…
Avbryt
Spara