Parcourir la source

PopupManager

git-svn-id: http://svn.dmdirc.com/trunk@2388 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5.5
Chris Smith il y a 16 ans
Parent
révision
42355bb272

+ 66
- 0
src/com/dmdirc/commandparser/PopupManager.java Voir le fichier

@@ -0,0 +1,66 @@
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.commandparser;
24
+
25
+import com.dmdirc.config.ConfigManager;
26
+import java.util.HashMap;
27
+import java.util.Map;
28
+
29
+/**
30
+ * The popup manager manages which commands should be present in popup menus.
31
+ *
32
+ * @author Chris
33
+ */
34
+public class PopupManager {
35
+    
36
+    /**
37
+     * Creates a new instance of PopupManager.
38
+     */
39
+    private PopupManager() {
40
+        // Shouldn't be instansiated.
41
+    }
42
+    
43
+    /**
44
+     * Retrieves a map of the menu items that should be in a certain menu type.
45
+     *
46
+     * @param menuType The type of menu that is being built
47
+     * @param configManager The config manager for the current context
48
+     * @return A map of "friendly names" to commands (without command characters)
49
+     */
50
+    public static Map<String, String> getMenuItems(final PopupType menuType,
51
+            final ConfigManager configManager) {
52
+        final Map<String, String> res = new HashMap<String, String>();
53
+        
54
+        for (String domain : menuType.getDomains()) {
55
+            for (String option : configManager.getOptions(domain)) {
56
+                final String command = configManager.getOption(domain, option);
57
+                if (!command.isEmpty()) {
58
+                    res.put(option, command);
59
+                }
60
+            }
61
+        }
62
+        
63
+        return res;
64
+    }
65
+    
66
+}

+ 62
- 0
src/com/dmdirc/commandparser/PopupType.java Voir le fichier

@@ -0,0 +1,62 @@
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.commandparser;
24
+
25
+/**
26
+ * An enumeration of the types of popup menu which are supported by the
27
+ * PopupManager.
28
+ * 
29
+ * @author chris
30
+ */
31
+public enum PopupType {
32
+    
33
+    /** The menu that appears when right clicking in a channel's nicklist. */
34
+    CHAN_NICKLIST("chan-nick-list", "chan-nick", "nick"),
35
+    /** The menu that appears when right clicking on a nickname in normal channel text. */
36
+    CHAN_NICKTEXT("chan-nick-text", "chan-nick", "nick", "chan"),
37
+    /** The menu that appears when right clicking in a channel window. */
38
+    CHAN_CHAN("chan"),
39
+    /** The menu that appears when right clicking in a query window. */
40
+    QUERY_QUERY("query", "nick");
41
+    
42
+    private final String[] domains;
43
+    
44
+    /**
45
+     * Instansiates one of the PopupTypes.
46
+     * 
47
+     * @param domains The configuration domains used for the type
48
+     */
49
+    PopupType(final String ... domains) {
50
+        this.domains = domains;
51
+    }
52
+    
53
+    /**
54
+     * Retrieve a list of the domains that should be used by this type.
55
+     * 
56
+     * @return This type's domains
57
+     */
58
+    public String[] getDomains() {
59
+        return domains.clone();
60
+    }
61
+    
62
+}

Chargement…
Annuler
Enregistrer