Browse Source

Create queueing for OSD windows.

Fixes issue 882

Change-Id: Ib1376b6b35072256a008b34ee93a1ff5f523be9a
Reviewed-on: http://gerrit.dmdirc.com/624
Automatic-Compile: Chris Smith <chris@dmdirc.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.3
Simon Mott 14 years ago
parent
commit
cfb1c90aa6

+ 4
- 4
src/com/dmdirc/addons/osd/OsdCommand.java View File

@@ -65,8 +65,8 @@ public final class OsdCommand extends GlobalCommand implements IntelligentComman
65 65
      * @return True if the notification was shown.
66 66
      */
67 67
     public boolean showOSD(final String title, final String message) {
68
-        osdManager.createOSDWindow(title, message);
69
-        return true;		
68
+        osdManager.showWindow(message);
69
+        return true;
70 70
     }
71 71
 
72 72
     /** {@inheritDoc} */
@@ -75,9 +75,9 @@ public final class OsdCommand extends GlobalCommand implements IntelligentComman
75 75
             final CommandArguments args) {
76 76
         if (args.getArguments().length > 0
77 77
                 && "--close".equalsIgnoreCase(args.getArguments()[0])) {
78
-            osdManager.destroyAllOSDWindows();
78
+            osdManager.closeAll();
79 79
         } else {
80
-            showOSD("", args.getArgumentsAsString());
80
+            showOSD(null, args.getArgumentsAsString());
81 81
         }
82 82
     }
83 83
     

+ 51
- 14
src/com/dmdirc/addons/osd/OsdManager.java View File

@@ -24,12 +24,15 @@ package com.dmdirc.addons.osd;
24 24
 
25 25
 import com.dmdirc.config.IdentityManager;
26 26
 import java.util.ArrayList;
27
+import java.util.LinkedList;
27 28
 import java.util.List;
29
+import java.util.Queue;
28 30
 
29 31
 /**
30 32
  * Class to manage OSD Windows.
31 33
  *
32 34
  * @author Simon
35
+ * @since 0.6.3
33 36
  */
34 37
 public class OsdManager {
35 38
 
@@ -37,7 +40,10 @@ public class OsdManager {
37 40
     private final OsdPlugin plugin;
38 41
 
39 42
     /** List of OSD Windows. */
40
-    private List<OsdWindow> windowList = new ArrayList<OsdWindow>();
43
+    private final List<OsdWindow> windowList = new ArrayList<OsdWindow>();
44
+
45
+    /** List of messages to be queued. */
46
+    private final Queue<String> windowQueue = new LinkedList<String>();
41 47
 
42 48
     /** The spacing between the windows. */
43 49
     private static final int WINDOW_GAP = 5;
@@ -45,15 +51,43 @@ public class OsdManager {
45 51
     /**
46 52
      * Create a new OSD Manager.
47 53
      *
48
-     * @param plugin The plugin that owns this OSD Manager
54
+     * @param plugin The plugin that owns this OSD Manager.
49 55
      */
50 56
     public OsdManager(final OsdPlugin plugin) {
51
-        //Constructor
52 57
         this.plugin = plugin;
53 58
     }
54 59
 
55
-    public void createOSDWindow(final String title, final String message) {
56
-        //Check some form of queue.
60
+    /**
61
+     * Add messages to the queue and call displayWindows.
62
+     *
63
+     * @param message Message to be displayed.
64
+     */
65
+    public void showWindow(final String message) {
66
+        windowQueue.add(message);
67
+        displayWindows();
68
+    }
69
+
70
+    /**
71
+     * Displays as many windows as appropriate.
72
+     */
73
+    private synchronized void displayWindows() {
74
+        final Integer maxWindows = IdentityManager.getGlobalConfig().getOptionInt(
75
+                plugin.getDomain(), "maxWindows");
76
+
77
+        String nextItem;
78
+
79
+        while ((maxWindows == null || getWindowCount() < maxWindows)
80
+                && (nextItem = windowQueue.poll()) != null) {
81
+            displayWindow(nextItem);
82
+        }
83
+    }
84
+
85
+    /**
86
+     * Create a new OSD window with "message".
87
+     *
88
+     * @param message Text to display in the OSD window.
89
+     */
90
+    private void displayWindow(final String message) {
57 91
         OsdWindow currentWindow = new OsdWindow(message, false,
58 92
                 IdentityManager.getGlobalConfig().getOptionInt(plugin.getDomain(),
59 93
                 "locationX"), getYPosition(), plugin, this);
@@ -62,29 +96,32 @@ public class OsdManager {
62 96
     }
63 97
 
64 98
     /**
65
-    * Destroy the given OSD Window.
99
+    * Destroy the given OSD Window and check if the Queue has items, if so
100
+    * Display them.
66 101
     *
67 102
     * @param window The window that we are destroying.
68 103
     */
69
-    public void destroyOSDWindow(OsdWindow window) {
104
+    public void closeWindow(final OsdWindow window) {
70 105
         windowList.remove(window);
71 106
         window.dispose();
107
+
108
+        displayWindows();
72 109
     }
73 110
 
74 111
     /**
75
-     * Destropy all OSD Windows
112
+     * Destroy all OSD Windows.
76 113
      */
77
-    public void destroyAllOSDWindows() {
114
+    public void closeAll() {
78 115
         for (OsdWindow window : new ArrayList<OsdWindow>(windowList)) {
79 116
             window.setVisible(false);
80
-            destroyOSDWindow(window);
117
+            closeWindow(window);
81 118
         }
82 119
     }
83 120
 
84 121
     /**
85 122
     * Get the list of current OSDWindows.
86 123
     *
87
-    * @return a List of all currently open OSDWindows
124
+    * @return a List of all currently open OSDWindows.
88 125
     */
89 126
     public List<OsdWindow> getWindowList() {
90 127
         return new ArrayList<OsdWindow>(windowList);
@@ -105,8 +142,8 @@ public class OsdManager {
105 142
     * @return the Y position for the next window.
106 143
     */
107 144
     public int getYPosition() {
108
-        final String policy = IdentityManager.getGlobalConfig()
109
-                .getOption(plugin.getDomain(), "newbehaviour");
145
+        final String policy = IdentityManager.getGlobalConfig().getOption(
146
+                plugin.getDomain(), "newbehaviour");
110 147
         int y = IdentityManager.getGlobalConfig().getOptionInt(plugin.getDomain(),
111 148
                 "locationY");
112 149
 
@@ -126,7 +163,7 @@ public class OsdManager {
126 163
             }
127 164
         } else if ("close".equals(policy)) {
128 165
             // Close existing windows and use their place
129
-            destroyAllOSDWindows();
166
+            closeAll();
130 167
         }
131 168
 
132 169
         return y;

+ 9
- 8
src/com/dmdirc/addons/osd/OsdPlugin.java View File

@@ -32,6 +32,8 @@ import com.dmdirc.config.prefs.PreferencesManager;
32 32
 import com.dmdirc.config.prefs.PreferencesSetting;
33 33
 import com.dmdirc.config.prefs.PreferencesType;
34 34
 import com.dmdirc.config.prefs.SettingChangeListener;
35
+import com.dmdirc.config.prefs.validator.NumericalValidator;
36
+import com.dmdirc.config.prefs.validator.OptionalValidator;
35 37
 import com.dmdirc.plugins.Plugin;
36 38
 import java.util.HashMap;
37 39
 import java.util.Map;
@@ -63,11 +65,9 @@ public final class OsdPlugin extends Plugin implements CategoryChangeListener,
63 65
      * Setting objects with registered change listeners.
64 66
      * maxWindowSetting not used at present so comment out
65 67
      */
66
-    //private PreferencesSetting fontSizeSetting, backgroundSetting,
67
-    //        foregroundSetting, widthSetting, timeoutSetting, maxWindowsSetting;
68 68
     private PreferencesSetting fontSizeSetting, backgroundSetting,
69
-            foregroundSetting, widthSetting, timeoutSetting;
70
-    
69
+            foregroundSetting, widthSetting, timeoutSetting, maxWindowsSetting;
70
+
71 71
     /**
72 72
      * Creates a new instance of OsdPlugin.
73 73
      */
@@ -113,16 +113,17 @@ public final class OsdPlugin extends Plugin implements CategoryChangeListener,
113 113
         timeoutSetting = new PreferencesSetting(PreferencesType.INTEGER,
114 114
                 getDomain(), "timeout", "Timeout", "Length of time in " +
115 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");
116
+        maxWindowsSetting = new PreferencesSetting(PreferencesType.OPTIONALINTEGER,
117
+                new OptionalValidator(new NumericalValidator(1 ,Integer.MAX_VALUE)),
118
+                getDomain(), "maxWindows", "Maximum open windows", "Maximum number of OSD " +
119
+                "windows that will be displayed at any given time");
119 120
                 
120 121
         category.addSetting(fontSizeSetting);
121 122
         category.addSetting(backgroundSetting);
122 123
         category.addSetting(foregroundSetting);
123 124
         category.addSetting(widthSetting);
124 125
         category.addSetting(timeoutSetting);
125
-        //category.addSetting(maxWindowsSetting);
126
+        category.addSetting(maxWindowsSetting);
126 127
         
127 128
         final Map<String, String> posOptions = new HashMap<String, String>();
128 129
         posOptions.put("down", "Place new windows below old ones");

+ 2
- 2
src/com/dmdirc/addons/osd/OsdWindow.java View File

@@ -134,7 +134,7 @@ public final class OsdWindow extends JDialog implements MouseListener,
134 134
                 @Override
135 135
                 public void run() {
136 136
                     setVisible(false);
137
-                    osdManager.destroyOSDWindow(OsdWindow.this);
137
+                    osdManager.closeWindow(OsdWindow.this);
138 138
                 }
139 139
             }, IdentityManager.getGlobalConfig().getOptionInt(plugin.getDomain(),
140 140
                     "timeout") * 1000);
@@ -151,7 +151,7 @@ public final class OsdWindow extends JDialog implements MouseListener,
151 151
     public void mouseClicked(final MouseEvent e) {
152 152
         if (!config) {
153 153
             setVisible(false);
154
-            osdManager.destroyOSDWindow(this);
154
+            osdManager.closeWindow(this);
155 155
         }
156 156
     }
157 157
     

Loading…
Cancel
Save