Просмотр исходного кода

Groundwork for OSD Queueing

Change-Id: Id65cc8eba2320a89a93619c77ad044829f3e0ceb
Reviewed-on: http://gerrit.dmdirc.com/611
Automatic-Compile: Gregory Holmes <greg@dmdirc.com>
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
tags/0.6.3
Simon Mott 14 лет назад
Родитель
Сommit
c880a9113c

+ 8
- 6
src/com/dmdirc/addons/osd/OsdCommand.java Просмотреть файл

@@ -28,7 +28,6 @@ import com.dmdirc.commandparser.commands.GlobalCommand;
28 28
 import com.dmdirc.commandparser.commands.IntelligentCommand;
29 29
 import com.dmdirc.ui.input.AdditionalTabTargets;
30 30
 import com.dmdirc.ui.interfaces.InputWindow;
31
-import com.dmdirc.ui.messages.Styliser;
32 31
 
33 32
 import java.util.List;
34 33
 
@@ -40,20 +39,23 @@ public final class OsdCommand extends GlobalCommand implements IntelligentComman
40 39
 
41 40
     /** The plugin that owns this command. */
42 41
     private final OsdPlugin plugin;
42
+
43
+    /** The OSDManager that this command should use. */
44
+    private final OsdManager osdManager;
43 45
     
44 46
     /**
45 47
      * Creates a new instance of OsdCommand.
46 48
      *
47 49
      * @param plugin The plugin that owns this command
48 50
      */
49
-    public OsdCommand(final OsdPlugin plugin) {
51
+    public OsdCommand(final OsdPlugin plugin, final OsdManager osdManager) {
50 52
         super();
51 53
 
54
+        this.osdManager = osdManager;
52 55
         this.plugin = plugin;
53 56
         
54 57
         CommandManager.registerCommand(this);
55 58
     }
56
-    
57 59
 
58 60
     /**
59 61
      * Used to show a notification using this plugin.
@@ -63,8 +65,8 @@ public final class OsdCommand extends GlobalCommand implements IntelligentComman
63 65
      * @return True if the notification was shown.
64 66
      */
65 67
     public boolean showOSD(final String title, final String message) {
66
-        new OsdWindow(Styliser.stipControlCodes(message), false, plugin);
67
-        return true;
68
+        osdManager.createOSDWindow(title, message);
69
+        return true;		
68 70
     }
69 71
 
70 72
     /** {@inheritDoc} */
@@ -73,7 +75,7 @@ public final class OsdCommand extends GlobalCommand implements IntelligentComman
73 75
             final CommandArguments args) {
74 76
         if (args.getArguments().length > 0
75 77
                 && "--close".equalsIgnoreCase(args.getArguments()[0])) {
76
-            OsdWindow.closeAll();
78
+            osdManager.destroyAllOSDWindows();
77 79
         } else {
78 80
             showOSD("", args.getArgumentsAsString());
79 81
         }

+ 134
- 0
src/com/dmdirc/addons/osd/OsdManager.java Просмотреть файл

@@ -0,0 +1,134 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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.addons.osd;
24
+
25
+import com.dmdirc.config.IdentityManager;
26
+import java.util.ArrayList;
27
+import java.util.List;
28
+
29
+/**
30
+ * Class to manage OSD Windows.
31
+ *
32
+ * @author Simon
33
+ */
34
+public class OsdManager {
35
+
36
+    /** The Plugin that owns this OSD Manager. */
37
+    private final OsdPlugin plugin;
38
+
39
+    /** List of OSD Windows. */
40
+    private List<OsdWindow> windowList = new ArrayList<OsdWindow>();
41
+
42
+    /** The spacing between the windows. */
43
+    private static final int WINDOW_GAP = 5;
44
+
45
+    /**
46
+     * Create a new OSD Manager.
47
+     *
48
+     * @param plugin The plugin that owns this OSD Manager
49
+     */
50
+    public OsdManager(final OsdPlugin plugin) {
51
+        //Constructor
52
+        this.plugin = plugin;
53
+    }
54
+
55
+    public void createOSDWindow(final String title, final String message) {
56
+        //Check some form of queue.
57
+        OsdWindow currentWindow = new OsdWindow(message, false,
58
+                IdentityManager.getGlobalConfig().getOptionInt(plugin.getDomain(),
59
+                "locationX"), getYPosition(), plugin, this);
60
+
61
+        windowList.add(currentWindow);
62
+    }
63
+
64
+    /**
65
+    * Destroy the given OSD Window.
66
+    *
67
+    * @param window The window that we are destroying.
68
+    */
69
+    public void destroyOSDWindow(OsdWindow window) {
70
+        windowList.remove(window);
71
+        window.dispose();
72
+    }
73
+
74
+    /**
75
+     * Destropy all OSD Windows
76
+     */
77
+    public void destroyAllOSDWindows() {
78
+        for (OsdWindow window : new ArrayList<OsdWindow>(windowList)) {
79
+            window.setVisible(false);
80
+            destroyOSDWindow(window);
81
+        }
82
+    }
83
+
84
+    /**
85
+    * Get the list of current OSDWindows.
86
+    *
87
+    * @return a List of all currently open OSDWindows
88
+    */
89
+    public List<OsdWindow> getWindowList() {
90
+        return new ArrayList<OsdWindow>(windowList);
91
+    }
92
+
93
+    /**
94
+    * Get the count of open windows.
95
+    *
96
+    * @return Current number of OSD Windows open.
97
+    */
98
+    public int getWindowCount() {
99
+        return windowList.size();
100
+    }
101
+
102
+    /**
103
+    * Get the Y position for the next window.
104
+    *
105
+    * @return the Y position for the next window.
106
+    */
107
+    public int getYPosition() {
108
+        final String policy = IdentityManager.getGlobalConfig()
109
+                .getOption(plugin.getDomain(), "newbehaviour");
110
+        int y = IdentityManager.getGlobalConfig().getOptionInt(plugin.getDomain(),
111
+                "locationY");
112
+
113
+        if ("down".equals(policy)) {
114
+            // Place our new window below old windows
115
+            for (OsdWindow window : new ArrayList<OsdWindow>(getWindowList())) {
116
+                if (window.isVisible()) {
117
+                    y = Math.max(y, window.getY() + window.getHeight() + WINDOW_GAP);
118
+                }
119
+            }
120
+        } else if ("up".equals(policy)) {
121
+            // Place our new window above old windows
122
+            for (OsdWindow window : new ArrayList<OsdWindow>(getWindowList())) {
123
+                if (window.isVisible()) {
124
+                    y = Math.min(y, window.getY() - window.getHeight() - WINDOW_GAP);
125
+                }
126
+            }
127
+        } else if ("close".equals(policy)) {
128
+            // Close existing windows and use their place
129
+            destroyAllOSDWindows();
130
+        }
131
+
132
+        return y;
133
+    }
134
+}

+ 23
- 8
src/com/dmdirc/addons/osd/OsdPlugin.java Просмотреть файл

@@ -48,6 +48,9 @@ public final class OsdPlugin extends Plugin implements CategoryChangeListener,
48 48
     
49 49
     /** OSD Command. */
50 50
     private OsdCommand command;
51
+
52
+    /** The OSD Manager that this plugin is using. */
53
+    private OsdManager osdManager;
51 54
     
52 55
     /** X-axis position of OSD. */
53 56
     private int x;
@@ -55,9 +58,15 @@ public final class OsdPlugin extends Plugin implements CategoryChangeListener,
55 58
     /** Y-axis potion of OSD. */
56 59
     private int y;
57 60
     
58
-    /** Setting objects with registered change listeners. */
59
-    private PreferencesSetting fontSizeSetting, backgroundSetting, 
60
-            foregroundSetting, widthSetting;
61
+    /** Setting objects with registered change listeners.*/
62
+    /**
63
+     * Setting objects with registered change listeners.
64
+     * maxWindowSetting not used at present so comment out
65
+     */
66
+    //private PreferencesSetting fontSizeSetting, backgroundSetting,
67
+    //        foregroundSetting, widthSetting, timeoutSetting, maxWindowsSetting;
68
+    private PreferencesSetting fontSizeSetting, backgroundSetting,
69
+            foregroundSetting, widthSetting, timeoutSetting;
61 70
     
62 71
     /**
63 72
      * Creates a new instance of OsdPlugin.
@@ -69,7 +78,8 @@ public final class OsdPlugin extends Plugin implements CategoryChangeListener,
69 78
     /** {@inheritDoc} */
70 79
     @Override
71 80
     public void onLoad() {
72
-        command = new OsdCommand(this);
81
+        osdManager = new OsdManager(this);
82
+        command = new OsdCommand(this, osdManager);
73 83
     }
74 84
     
75 85
     /** {@inheritDoc} */
@@ -100,14 +110,19 @@ public final class OsdPlugin extends Plugin implements CategoryChangeListener,
100 110
         widthSetting = new PreferencesSetting(PreferencesType.INTEGER,
101 111
                 getDomain(), "width", "OSD Width", "Width of the OSD Window").
102 112
                 registerChangeListener(this);
113
+        timeoutSetting = new PreferencesSetting(PreferencesType.INTEGER,
114
+                getDomain(), "timeout", "Timeout", "Length of time in " +
115
+                "seconds before the OSD window closes");
116
+        //maxWindowsSetting = new PreferencesSetting(PreferencesType.OPTIONALINTEGER,
117
+        //        getDomain(), "maxWindows", "Max display at once", "Maximum number of OSD " +
118
+        //        "windows that will be displayed at any given time");
103 119
                 
104 120
         category.addSetting(fontSizeSetting);
105 121
         category.addSetting(backgroundSetting);
106 122
         category.addSetting(foregroundSetting);
107 123
         category.addSetting(widthSetting);
108
-        category.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
109
-                getDomain(), "timeout", "Timeout", "Length of time in " +
110
-                "seconds before the OSD window closes"));
124
+        category.addSetting(timeoutSetting);
125
+        //category.addSetting(maxWindowsSetting);
111 126
         
112 127
         final Map<String, String> posOptions = new HashMap<String, String>();
113 128
         posOptions.put("down", "Place new windows below old ones");
@@ -127,7 +142,7 @@ public final class OsdPlugin extends Plugin implements CategoryChangeListener,
127 142
     /** {@inheritDoc} */
128 143
     @Override
129 144
     public void categorySelected(final PreferencesCategory category) {
130
-        osdWindow = new OsdWindow("Please drag this OSD to position", true, x, y, this);
145
+        osdWindow = new OsdWindow("Please drag this OSD to position", true, x, y, this, osdManager);
131 146
         osdWindow.setBackgroundColour(backgroundSetting.getValue());
132 147
         osdWindow.setForegroundColour(foregroundSetting.getValue());
133 148
         osdWindow.setFontSize(Integer.parseInt(fontSizeSetting.getValue()));

+ 9
- 80
src/com/dmdirc/addons/osd/OsdWindow.java Просмотреть файл

@@ -33,7 +33,6 @@ import java.awt.event.MouseEvent;
33 33
 import java.awt.event.MouseListener;
34 34
 import java.awt.event.MouseMotionListener;
35 35
 import java.util.ArrayList;
36
-import java.util.List;
37 36
 import java.util.Timer;
38 37
 import java.util.TimerTask;
39 38
 
@@ -61,14 +60,8 @@ public final class OsdWindow extends JDialog implements MouseListener,
61 60
      */
62 61
     private static final long serialVersionUID = 2;
63 62
     
64
-    /** Gap between vertically stacked windows. */
65
-    private static final int WINDOW_GAP = 5;
66
-    
67
-    /** A list of open OSD windows. */
68
-    private static List<OsdWindow> windows = new ArrayList<OsdWindow>();
69
-
70
-    /** Plugin this window belongs to. */
71
-    private final OsdPlugin plugin;
63
+    /** The OSD Manager that owns this window. */
64
+    private final OsdManager osdManager;
72 65
     
73 66
     /** OSD Label. */
74 67
     private final JLabel label;
@@ -82,19 +75,6 @@ public final class OsdWindow extends JDialog implements MouseListener,
82 75
     /** Is this a config instance? */
83 76
     private final boolean config;
84 77
 
85
-    /**
86
-     * Creates a new instance of OsdWindow.
87
-     * 
88
-     * @param text The text to be displayed in the OSD window
89
-     * @param config Is the window being configured (should it timeout and
90
-     * allow itself to be moved)
91
-     * @param plugin The plugin that owns this window
92
-     */    
93
-    public OsdWindow(final String text, final boolean config, final OsdPlugin plugin) {
94
-        this(text, config, IdentityManager.getGlobalConfig()
95
-                .getOptionInt(plugin.getDomain(), "locationX"), getYPosition(plugin), plugin);
96
-    }
97
-
98 78
     /**
99 79
      * Creates a new instance of OsdWindow.
100 80
      *
@@ -104,13 +84,14 @@ public final class OsdWindow extends JDialog implements MouseListener,
104 84
      * @param x The x-axis position for the OSD Window
105 85
      * @param y The y-axis position for the OSD window
106 86
      * @param plugin Parent OSD Plugin
87
+     * @param osdMAnager The manager that owns this OSD Window
107 88
      */
108 89
     public OsdWindow(final String text, final boolean config, final int x,
109
-            final int y, final OsdPlugin plugin) {
90
+            final int y, final OsdPlugin plugin, final OsdManager osdManager) {
110 91
         super((MainFrame) Main.getUI().getMainWindow(), false);
111
-
112
-        this.plugin = plugin;
92
+        
113 93
         this.config = config;
94
+        this.osdManager = osdManager;
114 95
 
115 96
         setFocusableWindowState(false);
116 97
         setAlwaysOnTop(true);
@@ -154,57 +135,14 @@ public final class OsdWindow extends JDialog implements MouseListener,
154 135
                 @Override
155 136
                 public void run() {
156 137
                     setVisible(false);
157
-                    dispose();
138
+                    osdManager.destroyOSDWindow(OsdWindow.this);
158 139
                 }
159 140
             }, IdentityManager.getGlobalConfig().getOptionInt(plugin.getDomain(),
160 141
                     "timeout") * 1000);
161 142
         }
162 143
     }
163 144
     
164
-    /**
165
-     * Retrieves the y-axis position for a new OSD window, based on the user's
166
-     * configured policy.
167
-     * 
168
-     * @return The y-axis position for a new OSD window.
169
-     */
170
-    private static int getYPosition(final OsdPlugin plugin) {
171
-        final String policy = IdentityManager.getGlobalConfig()
172
-                .getOption(plugin.getDomain(), "newbehaviour");
173
-        int y = IdentityManager.getGlobalConfig().getOptionInt(plugin.getDomain(),
174
-                "locationY");
175
-        
176
-        if ("down".equals(policy)) {
177
-            // Place our new window below old windows
178
-            for (OsdWindow window : new ArrayList<OsdWindow>(windows)) {
179
-                if (window.isVisible()) {
180
-                    y = Math.max(y, window.getY() + window.getHeight() + WINDOW_GAP);
181
-                }
182
-            }
183
-        } else if ("up".equals(policy)) {
184
-            // Place our new window above old windows
185
-            for (OsdWindow window : new ArrayList<OsdWindow>(windows)) {
186
-                if (window.isVisible()) {
187
-                    y = Math.min(y, window.getY() - window.getHeight() - WINDOW_GAP);
188
-                }
189
-            }            
190
-        } else if ("close".equals(policy)) {
191
-            // Close existing windows and use their place
192
-            closeAll();
193
-        }        
194
-        
195
-        return y;
196
-    }
197
-    
198
-    /**
199
-     * Closes all open OSD windows.
200
-     */
201
-    protected static void closeAll() {
202
-        for (OsdWindow window : new ArrayList<OsdWindow>(windows)) {
203
-            window.setVisible(false);
204
-            window.dispose();
205
-        }        
206
-    }
207
-    
145
+   
208 146
     /** 
209 147
      * {@inheritDoc}
210 148
      * 
@@ -214,7 +152,7 @@ public final class OsdWindow extends JDialog implements MouseListener,
214 152
     public void mouseClicked(final MouseEvent e) {
215 153
         if (!config) {
216 154
             setVisible(false);
217
-            dispose();
155
+            osdManager.destroyOSDWindow(this);
218 156
         }
219 157
     }
220 158
     
@@ -316,16 +254,7 @@ public final class OsdWindow extends JDialog implements MouseListener,
316 254
         super.setVisible(b);
317 255
         
318 256
         if (b) {
319
-            windows.add(this);
320 257
             transferFocusBackward();
321 258
         }
322 259
     }
323
-
324
-    /** {@inheritDoc} */
325
-    @Override
326
-    public void dispose() {
327
-        super.dispose();
328
-        
329
-        windows.remove(this);
330
-    }
331 260
 }

+ 1
- 0
src/com/dmdirc/addons/osd/plugin.config Просмотреть файл

@@ -42,6 +42,7 @@ defaults:
42 42
   fontSize=20
43 43
   timeout=15
44 44
   width=500
45
+  maxWindows=false:5
45 46
 
46 47
 exports:
47 48
   showOSD in com.dmdirc.addons.osd.OsdCommand as showNotification

Загрузка…
Отмена
Сохранить