Sfoglia il codice sorgente

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 anni fa
parent
commit
880560a067

+ 0
- 1
src/com/dmdirc/Channel.java Vedi File

132
                 public void run() {
132
                 public void run() {
133
                     frame = new ChannelFrame(Channel.this);
133
                     frame = new ChannelFrame(Channel.this);
134
                     MainFrame.getMainFrame().addChild(frame);
134
                     MainFrame.getMainFrame().addChild(frame);
135
-                    frame.addInternalFrameListener(Channel.this);
136
                     frame.setFrameIcon(imageIcon);
135
                     frame.setFrameIcon(imageIcon);
137
                     frame.getInputHandler().setTabCompleter(tabCompleter);
136
                     frame.getInputHandler().setTabCompleter(tabCompleter);
138
                 }
137
                 }

+ 22
- 39
src/com/dmdirc/FrameContainer.java Vedi File

25
 import com.dmdirc.identities.ConfigManager;
25
 import com.dmdirc.identities.ConfigManager;
26
 import com.dmdirc.logger.ErrorLevel;
26
 import com.dmdirc.logger.ErrorLevel;
27
 import com.dmdirc.logger.Logger;
27
 import com.dmdirc.logger.Logger;
28
-import com.dmdirc.ui.interfaces.InputWindow;
29
 import com.dmdirc.ui.MainFrame;
28
 import com.dmdirc.ui.MainFrame;
30
 import com.dmdirc.ui.interfaces.Window;
29
 import com.dmdirc.ui.interfaces.Window;
31
 
30
 
33
 import java.beans.PropertyVetoException;
32
 import java.beans.PropertyVetoException;
34
 
33
 
35
 import javax.swing.ImageIcon;
34
 import javax.swing.ImageIcon;
36
-import javax.swing.event.InternalFrameEvent;
37
-import javax.swing.event.InternalFrameListener;
38
 
35
 
39
 /**
36
 /**
40
  * The frame container implements basic methods that should be present in
37
  * The frame container implements basic methods that should be present in
41
  * all objects that handle a frame.
38
  * all objects that handle a frame.
42
- * 
39
+ *
43
  * @author chris
40
  * @author chris
44
  */
41
  */
45
-public abstract class FrameContainer implements InternalFrameListener {
42
+public abstract class FrameContainer {
46
     
43
     
47
     /** The colour of our frame's notifications. */
44
     /** The colour of our frame's notifications. */
48
     protected Color notification = Color.BLACK;
45
     protected Color notification = Color.BLACK;
52
     
49
     
53
     /**
50
     /**
54
      * Returns the internal frame associated with this object.
51
      * Returns the internal frame associated with this object.
55
-     * 
52
+     *
56
      * @return The internal frame associated with this object
53
      * @return The internal frame associated with this object
57
      */
54
      */
58
     public abstract Window getFrame();
55
     public abstract Window getFrame();
59
     
56
     
60
     /**
57
     /**
61
      * Returns a string identifier for this object/its frame.
58
      * Returns a string identifier for this object/its frame.
59
+     *
62
      * @return String identifier
60
      * @return String identifier
63
      */
61
      */
64
     public abstract String toString();
62
     public abstract String toString();
70
     
68
     
71
     /**
69
     /**
72
      * Returns the server instance associated with this container.
70
      * Returns the server instance associated with this container.
71
+     *
73
      * @return the associated server connection
72
      * @return the associated server connection
74
      */
73
      */
75
     public abstract Server getServer();
74
     public abstract Server getServer();
76
     
75
     
77
     /**
76
     /**
78
      * Retrieves the icon used by the query frame.
77
      * Retrieves the icon used by the query frame.
78
+     *
79
      * @return The query frame's icon
79
      * @return The query frame's icon
80
      */
80
      */
81
     public ImageIcon getIcon() {
81
     public ImageIcon getIcon() {
84
     
84
     
85
     /**
85
     /**
86
      * Returns the config manager for this container.
86
      * Returns the config manager for this container.
87
+     *
87
      * @return the associated config manager
88
      * @return the associated config manager
88
      */
89
      */
89
     public ConfigManager getConfigManager() {
90
     public ConfigManager getConfigManager() {
107
     
108
     
108
     /**
109
     /**
109
      * Sends a notification to the frame manager if this fame isn't active.
110
      * Sends a notification to the frame manager if this fame isn't active.
111
+     *
110
      * @param colour The colour to use for the notification
112
      * @param colour The colour to use for the notification
111
      */
113
      */
112
     public void sendNotification(final Color colour) {
114
     public void sendNotification(final Color colour) {
119
     
121
     
120
     /**
122
     /**
121
      * Retrieves the current notification colour of this channel.
123
      * Retrieves the current notification colour of this channel.
124
+     *
122
      * @return This channel's notification colour
125
      * @return This channel's notification colour
123
      */
126
      */
124
     public Color getNotification() {
127
     public Color getNotification() {
127
     
130
     
128
     /**
131
     /**
129
      * Determines if the specified frame is owned by this object.
132
      * Determines if the specified frame is owned by this object.
133
+     *
130
      * @param target Window to check ownership of
134
      * @param target Window to check ownership of
131
      * @return True iff frame is owned by this container, false otherwise
135
      * @return True iff frame is owned by this container, false otherwise
132
      */
136
      */
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
         final boolean pref = getServer().getConfigManager().getOptionBool("ui", "maximisewindows");
145
         final boolean pref = getServer().getConfigManager().getOptionBool("ui", "maximisewindows");
143
         if (pref || MainFrame.getMainFrame().getMaximised()) {
146
         if (pref || MainFrame.getMainFrame().getMaximised()) {
144
             try {
147
             try {
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
         close();
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
         if (MainFrame.getMainFrame().getMaximised()) {
173
         if (MainFrame.getMainFrame().getMaximised()) {
190
             try {
174
             try {
191
                 getFrame().setMaximum(true);
175
                 getFrame().setMaximum(true);
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 Vedi File

85
         ActionManager.processEvent(CoreActionType.QUERY_OPENED, null, this);
85
         ActionManager.processEvent(CoreActionType.QUERY_OPENED, null, this);
86
         
86
         
87
         MainFrame.getMainFrame().addChild(frame);
87
         MainFrame.getMainFrame().addChild(frame);
88
-        frame.addInternalFrameListener(this);
89
         frame.setFrameIcon(imageIcon);
88
         frame.setFrameIcon(imageIcon);
90
         
89
         
91
         if (!Config.getOptionBool("general", "hidequeries")) {
90
         if (!Config.getOptionBool("general", "hidequeries")) {

+ 0
- 1
src/com/dmdirc/Raw.java Vedi File

63
         
63
         
64
         frame = new ServerFrame(server);
64
         frame = new ServerFrame(server);
65
         frame.setTitle("(Raw log)");
65
         frame.setTitle("(Raw log)");
66
-        frame.addInternalFrameListener(this);
67
         MainFrame.getMainFrame().addChild(frame);
66
         MainFrame.getMainFrame().addChild(frame);
68
         frame.getInputHandler().setTabCompleter(server.getTabCompleter());
67
         frame.getInputHandler().setTabCompleter(server.getTabCompleter());
69
         frame.setFrameIcon(imageIcon);
68
         frame.setFrameIcon(imageIcon);

+ 2
- 8
src/com/dmdirc/Server.java Vedi File

170
         
170
         
171
         window.getInputHandler().setTabCompleter(tabCompleter);
171
         window.getInputHandler().setTabCompleter(tabCompleter);
172
         
172
         
173
-        ((ServerFrame) window).addInternalFrameListener(this);
174
         MainFrame.getMainFrame().addChild(window);
173
         MainFrame.getMainFrame().addChild(window);
175
         
174
         
176
         window.open();
175
         window.open();
267
         
266
         
268
         away = false;
267
         away = false;
269
         awayMessage = null;
268
         awayMessage = null;
270
-        ((ServerFrame) window).setAway(false);
269
+        window.setAwayIndicator(false);
271
         
270
         
272
         try {
271
         try {
273
             new Thread(parser).start();
272
             new Thread(parser).start();
499
             parser.getCallbackManager().delAllCallback(this);
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
         // Disconnect from the server
501
         // Disconnect from the server
508
         disconnect(reason);
502
         disconnect(reason);
509
         // Close all channel windows
503
         // Close all channel windows
941
             ActionManager.processEvent(CoreActionType.SERVER_BACK, null, this);
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
     /** {@inheritDoc} */
941
     /** {@inheritDoc} */

+ 25
- 13
src/com/dmdirc/ui/ServerFrame.java Vedi File

30
 import com.dmdirc.ui.input.InputHandler;
30
 import com.dmdirc.ui.input.InputHandler;
31
 import com.dmdirc.ui.components.InputFrame;
31
 import com.dmdirc.ui.components.InputFrame;
32
 import com.dmdirc.ui.interfaces.ServerWindow;
32
 import com.dmdirc.ui.interfaces.ServerWindow;
33
+import java.awt.BorderLayout;
33
 
34
 
34
 import java.awt.GridBagConstraints;
35
 import java.awt.GridBagConstraints;
35
 import java.awt.GridBagLayout;
36
 import java.awt.GridBagLayout;
79
     
80
     
80
     /**
81
     /**
81
      * Sets the away status for this and all associated frames.
82
      * Sets the away status for this and all associated frames.
83
+     *
82
      * @param newAwayState away state
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 Vedi File

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

+ 8
- 8
src/com/dmdirc/ui/components/InputFrame.java Vedi File

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

+ 8
- 0
src/com/dmdirc/ui/interfaces/InputWindow.java Vedi File

47
      */
47
      */
48
     InputHandler getInputHandler();
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
 }

Loading…
Annulla
Salva