Sfoglia il codice sorgente

Add some basic actions framework

git-svn-id: http://svn.dmdirc.com/trunk@769 00569f92-eb28-0410-84fd-f71c24880f
tags/0.3
Chris Smith 17 anni fa
parent
commit
4387e084e4

+ 45
- 0
src/uk/org/ownage/dmdirc/actions/ActionManager.java Vedi File

@@ -0,0 +1,45 @@
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 uk.org.ownage.dmdirc.actions;
24
+
25
+/**
26
+ * Manages all actions for the client.
27
+ * @author chris
28
+ */
29
+public class ActionManager {
30
+    
31
+    /** Creates a new instance of ActionManager. */
32
+    private ActionManager() {
33
+        
34
+    }
35
+    
36
+    /**
37
+     * Processes an event of the specified type.
38
+     * @param type The type of the event to process
39
+     * @param arguments The arguments for the event
40
+     */
41
+    public static void processEvent(final ActionType type, final Object ... arguments) {
42
+        assert(type.getType().getArity() == arguments.length);
43
+    }
44
+    
45
+}

+ 57
- 0
src/uk/org/ownage/dmdirc/actions/ActionMetaType.java Vedi File

@@ -0,0 +1,57 @@
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 uk.org.ownage.dmdirc.actions;
24
+
25
+/**
26
+ * An enumeration of different types of actions (the type determines the
27
+ * parameters an action expects).
28
+ * @author chris
29
+ */
30
+public enum ActionMetaType {
31
+    
32
+    CHANNEL_EVENT(2),
33
+    CHANNEL_EVENT_WITH_ARG(3),
34
+    CHANNEL_EVENT_WITH_VICTIM(3);
35
+    
36
+    /** The arity of this type. */
37
+    private final int arity;
38
+    
39
+    /**
40
+     * Constructs an instance of an ActionMetaType.
41
+     * 
42
+     * @param arity The arity of the action type
43
+     */
44
+    ActionMetaType(int arity) {
45
+        this.arity = arity;
46
+    }
47
+    
48
+    /**
49
+     * Retrieves the arity of an ActionMetaType.
50
+     * 
51
+     * @return The arity of this action type
52
+     */
53
+    public int getArity() {
54
+        return arity;
55
+    }
56
+    
57
+}

+ 37
- 0
src/uk/org/ownage/dmdirc/actions/ActionType.java Vedi File

@@ -0,0 +1,37 @@
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 uk.org.ownage.dmdirc.actions;
24
+
25
+/**
26
+ * Encapsulates the methods that all actions are required to implement.
27
+ * @author chris
28
+ */
29
+public interface ActionType {
30
+    
31
+    /**
32
+     * Retrieves the type of this action.
33
+     * @return This action's type
34
+     */
35
+    ActionMetaType getType();
36
+    
37
+}

+ 54
- 0
src/uk/org/ownage/dmdirc/actions/CoreActionType.java Vedi File

@@ -0,0 +1,54 @@
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 uk.org.ownage.dmdirc.actions;
24
+
25
+/**
26
+ * An enumeration of actions that are raised by the core.
27
+ * @author chris
28
+ */
29
+public enum CoreActionType implements ActionType {
30
+    
31
+    CHANNEL_MESSAGE(ActionMetaType.CHANNEL_EVENT_WITH_ARG),
32
+    CHANNEL_ACTION(ActionMetaType.CHANNEL_EVENT_WITH_ARG),
33
+    CHANNEL_JOIN(ActionMetaType.CHANNEL_EVENT);
34
+    
35
+    /** The type of this action. */
36
+    private final ActionMetaType type;
37
+    
38
+    /**
39
+     * Constructs a new core action.
40
+     * @param type The type of this action
41
+     */
42
+    CoreActionType(ActionMetaType type) {
43
+        this.type = type;
44
+    }
45
+    
46
+    /**
47
+     * Retrieves the type of this action.
48
+     * @return This action's type
49
+     */
50
+    public ActionMetaType getType() {
51
+        return type;
52
+    }
53
+    
54
+}

Loading…
Annulla
Salva