Parcourir la source

* Added CommandWindow interface, for frames that allow the user to issue commands

* Updated command parser to take a CommandWindow reference when executing

git-svn-id: http://svn.dmdirc.com/trunk@166 00569f92-eb28-0410-84fd-f71c24880f
tags/0.1
Chris Smith il y a 17 ans
Parent
révision
8230ab0352

+ 6
- 3
src/uk/org/ownage/dmdirc/commandparser/ChannelCommandParser.java Voir le fichier

@@ -60,10 +60,11 @@ public class ChannelCommandParser extends CommandParser {
60 60
     
61 61
     /**
62 62
      * Executes the specified command with the given arguments.
63
+     * @param origin The window in which the command was typed
63 64
      * @param command The command to be executed
64 65
      * @param args The arguments to the command
65 66
      */    
66
-    protected void executeCommand(Command command, String... args) {
67
+    protected void executeCommand(CommandWindow origin, Command command, String... args) {
67 68
         throw new UnsupportedOperationException("Not implemented yet");
68 69
     }
69 70
     
@@ -71,19 +72,21 @@ public class ChannelCommandParser extends CommandParser {
71 72
      * Called when the user attempted to issue a command (i.e., used the command
72 73
      * character) that wasn't found. It could be that the command has a different
73 74
      * arity, or that it plain doesn't exist.
75
+     * @param origin The window in which the command was typed
74 76
      * @param command The command the user tried to execute
75 77
      * @param args The arguments passed to the command
76 78
      */    
77
-    protected void handleInvalidCommand(String command, String... args) {
79
+    protected void handleInvalidCommand(CommandWindow origin, String command, String... args) {
78 80
         throw new UnsupportedOperationException("Not implemented yet");
79 81
     }
80 82
     
81 83
     /**
82 84
      * Called when the input was a line of text that was not a command. This normally
83 85
      * means it is sent to the server/channel/user as-is, with no further processing.
86
+     * @param origin The window in which the command was typed
84 87
      * @param line The line input by the user
85 88
      */    
86
-    protected void handleNonCommand(String line) {
89
+    protected void handleNonCommand(CommandWindow origin, String line) {
87 90
         throw new UnsupportedOperationException("Not implemented yet");
88 91
     }
89 92
     

+ 12
- 8
src/uk/org/ownage/dmdirc/commandparser/CommandParser.java Voir le fichier

@@ -57,9 +57,10 @@ abstract public class CommandParser {
57 57
     
58 58
     /**
59 59
      * Parses the specified string as a command
60
+     * @param origin The window in which the command was typed
60 61
      * @param line The line to be parsed
61 62
      */
62
-    public void parseCommand(String line) {
63
+    public void parseCommand(CommandWindow origin, String line) {
63 64
         if (line.charAt(0) == Config.getOption("general","commandchar").charAt(0)) {
64 65
             String[] args = line.split(" ");
65 66
             
@@ -73,37 +74,40 @@ abstract public class CommandParser {
73 74
             // have error handlers if there are too few arguments (e.g., msg/0 and
74 75
             // msg/1 would return errors, so msg only gets called with 2+ args).
75 76
             if (commands.containsKey(signature)) {
76
-                executeCommand(commands.get(signature), args);
77
+                executeCommand(origin, commands.get(signature), args);
77 78
             } else if (commands.containsKey(command)) {
78
-                executeCommand(commands.get(command), args);
79
+                executeCommand(origin, commands.get(command), args);
79 80
             } else {
80
-                handleInvalidCommand(command, args);
81
+                handleInvalidCommand(origin, command, args);
81 82
             }
82 83
         } else {
83
-            handleNonCommand(line);
84
+            handleNonCommand(origin, line);
84 85
         }
85 86
     }
86 87
     
87 88
     /**
88 89
      * Executes the specified command with the given arguments.
90
+     * @param origin The window in which the command was typed
89 91
      * @param command The command to be executed
90 92
      * @param args The arguments to the command
91 93
      */
92
-    abstract protected void executeCommand(Command command, String... args);
94
+    abstract protected void executeCommand(CommandWindow origin, Command command, String... args);
93 95
     
94 96
     /**
95 97
      * Called when the user attempted to issue a command (i.e., used the command
96 98
      * character) that wasn't found. It could be that the command has a different
97 99
      * arity, or that it plain doesn't exist.
100
+     * @param origin The window in which the command was typed
98 101
      * @param command The command the user tried to execute
99 102
      * @param args The arguments passed to the command
100 103
      */
101
-    abstract protected void handleInvalidCommand(String command, String... args);
104
+    abstract protected void handleInvalidCommand(CommandWindow origin, String command, String... args);
102 105
 
103 106
     /**
104 107
      * Called when the input was a line of text that was not a command. This normally
105 108
      * means it is sent to the server/channel/user as-is, with no further processing.
109
+     * @param origin The window in which the command was typed
106 110
      * @param line The line input by the user
107 111
      */
108
-    abstract protected void handleNonCommand(String line);
112
+    abstract protected void handleNonCommand(CommandWindow origin, String line);
109 113
 }

+ 33
- 0
src/uk/org/ownage/dmdirc/commandparser/CommandWindow.java Voir le fichier

@@ -0,0 +1,33 @@
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.commandparser;
24
+
25
+/**
26
+ *
27
+ * @author chris
28
+ */
29
+public interface CommandWindow {
30
+    
31
+    public void addLine(String line);
32
+    
33
+}

+ 7
- 4
src/uk/org/ownage/dmdirc/commandparser/ServerCommandParser.java Voir le fichier

@@ -52,10 +52,11 @@ public class ServerCommandParser extends CommandParser {
52 52
     
53 53
     /**
54 54
      * Executes the specified command with the given arguments.
55
+     * @param origin The window in which the command was typed
55 56
      * @param command The command to be executed
56 57
      * @param args The arguments to the command
57 58
      */
58
-    protected void executeCommand(Command command, String... args) {
59
+    protected void executeCommand(CommandWindow origin, Command command, String... args) {
59 60
         ((ServerCommand)command).execute(server, args);
60 61
     }
61 62
     
@@ -63,19 +64,21 @@ public class ServerCommandParser extends CommandParser {
63 64
      * Called when the user attempted to issue a command (i.e., used the command
64 65
      * character) that wasn't found. It could be that the command has a different
65 66
      * arity, or that it plain doesn't exist.
67
+     * @param origin The window in which the command was typed
66 68
      * @param command The command the user tried to execute
67 69
      * @param args The arguments passed to the command
68 70
      */
69
-    protected void handleInvalidCommand(String command, String... args) {
70
-        server.addLine("Unknown command: "+command+"/"+(args.length-1));
71
+    protected void handleInvalidCommand(CommandWindow origin, String command, String... args) {
72
+        origin.addLine("Unknown command: "+command+"/"+(args.length-1));
71 73
     }
72 74
     
73 75
     /**
74 76
      * Called when the input was a line of text that was not a command. This normally
75 77
      * means it is sent to the server/channel/user as-is, with no further processing.
78
+     * @param origin The window in which the command was typed
76 79
      * @param line The line input by the user
77 80
      */
78
-    protected void handleNonCommand(String line) {
81
+    protected void handleNonCommand(CommandWindow origin, String line) {
79 82
         server.getParser().sendLine(line);
80 83
     }
81 84
     

+ 3
- 3
src/uk/org/ownage/dmdirc/ui/ChannelFrame.java Voir le fichier

@@ -36,13 +36,14 @@ import javax.swing.plaf.basic.BasicInternalFrameUI;
36 36
 import javax.swing.text.BadLocationException;
37 37
 import javax.swing.text.StyledDocument;
38 38
 import uk.org.ownage.dmdirc.Channel;
39
+import uk.org.ownage.dmdirc.commandparser.CommandWindow;
39 40
 import uk.org.ownage.dmdirc.parser.ChannelClientInfo;
40 41
 
41 42
 /**
42 43
  *
43 44
  * @author  chris
44 45
  */
45
-public class ChannelFrame extends javax.swing.JInternalFrame {
46
+public class ChannelFrame extends javax.swing.JInternalFrame implements CommandWindow {
46 47
     
47 48
     private Channel parent;
48 49
     private NicklistListModel nicklistModel;
@@ -173,8 +174,7 @@ public class ChannelFrame extends javax.swing.JInternalFrame {
173 174
         );
174 175
         pack();
175 176
     }// </editor-fold>//GEN-END:initComponents
176
-    
177
-    
177
+      
178 178
     // Variables declaration - do not modify//GEN-BEGIN:variables
179 179
     private javax.swing.JList jList1;
180 180
     private javax.swing.JScrollPane jScrollPane1;

+ 3
- 2
src/uk/org/ownage/dmdirc/ui/ServerFrame.java Voir le fichier

@@ -35,13 +35,14 @@ import javax.swing.JComponent;
35 35
 import javax.swing.border.Border;
36 36
 import javax.swing.border.EmptyBorder;
37 37
 import javax.swing.plaf.basic.BasicInternalFrameUI;
38
+import uk.org.ownage.dmdirc.commandparser.CommandWindow;
38 39
 import uk.org.ownage.dmdirc.commandparser.ServerCommandParser;
39 40
 
40 41
 /**
41 42
  * The ServerFrame is the MDI window that shows server messages to the user
42 43
  * @author chris
43 44
  */
44
-public class ServerFrame extends javax.swing.JInternalFrame {
45
+public class ServerFrame extends javax.swing.JInternalFrame implements CommandWindow {
45 46
     
46 47
     /**
47 48
      * The Server object that owns this frame
@@ -84,7 +85,7 @@ public class ServerFrame extends javax.swing.JInternalFrame {
84 85
         
85 86
         jTextField1.addActionListener(new ActionListener() {
86 87
             public void actionPerformed(ActionEvent actionEvent) {
87
-                ServerFrame.this.commandParser.parseCommand(jTextField1.getText());
88
+                ServerFrame.this.commandParser.parseCommand(ServerFrame.this, jTextField1.getText());
88 89
                 jTextField1.setText("");
89 90
             }
90 91
         });

Chargement…
Annuler
Enregistrer