Преглед изворни кода

More updates to the command parser classes.

Command instances are no longer singletons per se, but the CommandManager handles creating and storing a single instance.
The server frame now uses a server command parser.

git-svn-id: http://svn.dmdirc.com/trunk@139 00569f92-eb28-0410-84fd-f71c24880f
tags/0.1
Chris Smith пре 17 година
родитељ
комит
4d4cbdc941

+ 5
- 0
src/uk/org/ownage/dmdirc/Server.java Прегледај датотеку

@@ -23,6 +23,7 @@
23 23
 package uk.org.ownage.dmdirc;
24 24
 
25 25
 import java.util.Hashtable;
26
+import uk.org.ownage.dmdirc.commandparser.ServerCommandParser;
26 27
 import uk.org.ownage.dmdirc.parser.ChannelInfo;
27 28
 import uk.org.ownage.dmdirc.parser.ServerInfo;
28 29
 import uk.org.ownage.dmdirc.ui.MainFrame;
@@ -104,6 +105,10 @@ public class Server {
104 105
     public IRCParser getParser() {
105 106
         return parser;
106 107
     }
108
+    
109
+    public void addLine(String line) {
110
+        frame.addLine(line);
111
+    }
107 112
 
108 113
     private void addChannel(ChannelInfo chan) {
109 114
         channels.put(chan.getName(), new Channel(this, chan));

+ 1
- 1
src/uk/org/ownage/dmdirc/commandparser/ChannelCommand.java Прегледај датотеку

@@ -36,5 +36,5 @@ public abstract class ChannelCommand extends Command {
36 36
         super();
37 37
     }
38 38
     
39
-    public abstract void Execute(Server server, Channel channel, String... args);    
39
+    public abstract void execute(Server server, Channel channel, String... args);    
40 40
 }

+ 1
- 1
src/uk/org/ownage/dmdirc/commandparser/ChannelCommandParser.java Прегледај датотеку

@@ -42,7 +42,7 @@ public class ChannelCommandParser extends CommandParser {
42 42
         this.channel = channel;
43 43
     }
44 44
 
45
-    protected void LoadCommands() {
45
+    protected void loadCommands() {
46 46
         throw new UnsupportedOperationException("Not implemented yet");
47 47
     }
48 48
 

+ 0
- 6
src/uk/org/ownage/dmdirc/commandparser/Command.java Прегледај датотеку

@@ -30,8 +30,6 @@ import uk.org.ownage.dmdirc.Server;
30 30
  */
31 31
 public abstract class Command {
32 32
     
33
-    protected static Command instance;
34
-    
35 33
     protected String name;
36 34
     protected int arity = 0;
37 35
     protected boolean polyadic;
@@ -58,8 +56,4 @@ public abstract class Command {
58 56
         return name+" "+arguments+" - "+description;
59 57
     }
60 58
     
61
-    public static Command getInstance() {
62
-        return instance;
63
-    }
64
-    
65 59
 }

+ 14
- 1
src/uk/org/ownage/dmdirc/commandparser/CommandManager.java Прегледај датотеку

@@ -22,18 +22,31 @@
22 22
 
23 23
 package uk.org.ownage.dmdirc.commandparser;
24 24
 
25
+import java.util.Vector;
26
+import uk.org.ownage.dmdirc.commandparser.commands.*;
27
+
25 28
 /**
26 29
  *
27 30
  * @author chris
28 31
  */
29 32
 public class CommandManager {
33
+    
34
+    private static Vector<Command> serverCommands;
30 35
            
31 36
     public static void loadChannelCommands(CommandParser parser) {
32 37
         throw new UnsupportedOperationException("Not implemented yet");        
33 38
     }
34 39
     
35 40
     public static void loadServerCommands(CommandParser parser) {
36
-        throw new UnsupportedOperationException("Not implemented yet");        
41
+        if (serverCommands == null) {
42
+            serverCommands = new Vector<Command>(0,1);
43
+
44
+            serverCommands.add(new Test());
45
+        }
46
+
47
+        for (Command com : serverCommands) {
48
+            parser.registerCommand(com);
49
+        }
37 50
     }    
38 51
     
39 52
 }

+ 3
- 2
src/uk/org/ownage/dmdirc/commandparser/CommandParser.java Прегледај датотеку

@@ -36,10 +36,11 @@ abstract public class CommandParser {
36 36
     /** Creates a new instance of CommandParser */
37 37
     public CommandParser() {
38 38
         commands = new Hashtable<String,Command>();
39
+        loadCommands();
39 40
     }
40 41
     
41 42
     /** Loads the relevant commands into the parser */
42
-    protected abstract void LoadCommands();
43
+    protected abstract void loadCommands();
43 44
     
44 45
     public void registerCommand(Command command) {
45 46
         commands.put(command.getSignature(), command);
@@ -52,7 +53,7 @@ abstract public class CommandParser {
52 53
             
53 54
             assert(args.length > 0);
54 55
             
55
-            String command = args[0];
56
+            String command = args[0].substring(1);
56 57
             
57 58
             String signature = command+"/"+(args.length-1);
58 59
             

+ 1
- 1
src/uk/org/ownage/dmdirc/commandparser/ServerCommand.java Прегледај датотеку

@@ -36,5 +36,5 @@ public abstract class ServerCommand extends Command {
36 36
         super();
37 37
     }
38 38
     
39
-    public abstract void Execute(Server server, String... args);
39
+    public abstract void execute(Server server, String... args);
40 40
 }

+ 5
- 5
src/uk/org/ownage/dmdirc/commandparser/ServerCommandParser.java Прегледај датотеку

@@ -39,20 +39,20 @@ public class ServerCommandParser extends CommandParser {
39 39
         this.server = server;
40 40
     }
41 41
 
42
-    protected void LoadCommands() {
43
-        throw new UnsupportedOperationException("Not implemented yet");
42
+    protected void loadCommands() {
43
+        CommandManager.loadServerCommands(this);
44 44
     }
45 45
 
46 46
     protected void executeCommand(Command command, String... args) {
47
-        throw new UnsupportedOperationException("Not implemented yet");
47
+        ((ServerCommand)command).execute(server, args);
48 48
     }
49 49
 
50 50
     protected void handleInvalidCommand(String command, String... args) {
51
-        throw new UnsupportedOperationException("Not implemented yet");
51
+        server.addLine("Unknown command: "+command+"/"+(args.length-1));
52 52
     }
53 53
 
54 54
     protected void handleNonCommand(String line) {
55
-        throw new UnsupportedOperationException("Not implemented yet");
55
+        server.getParser().sendLine(line);
56 56
     }
57 57
     
58 58
 }

+ 2
- 4
src/uk/org/ownage/dmdirc/commandparser/commands/Test.java Прегледај датотеку

@@ -32,8 +32,6 @@ import uk.org.ownage.dmdirc.commandparser.ServerCommand;
32 32
  */
33 33
 public class Test extends ServerCommand {
34 34
     
35
-    protected static Command instance = new Test();
36
-    
37 35
     /** Creates a new instance of Test */
38 36
     public Test() {
39 37
         description = "a test command";
@@ -44,8 +42,8 @@ public class Test extends ServerCommand {
44 42
         show = true;
45 43
     }
46 44
 
47
-    public void Execute(Server server, String... args) {
48
-        throw new UnsupportedOperationException("Not implemented yet");
45
+    public void execute(Server server, String... args) {
46
+        server.addLine(server.getParser().getSvnInfo());
49 47
     }
50 48
     
51 49
 }

+ 6
- 1
src/uk/org/ownage/dmdirc/ui/ServerFrame.java Прегледај датотеку

@@ -35,6 +35,7 @@ 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.ServerCommandParser;
38 39
 
39 40
 /**
40 41
  * The ServerFrame is the MDI window that shows server messages to the user
@@ -55,6 +56,8 @@ public class ServerFrame extends javax.swing.JInternalFrame {
55 56
      **/
56 57
     private Dimension titlebarSize;
57 58
     
59
+    private ServerCommandParser commandParser;
60
+    
58 61
     /**
59 62
      * Creates new form ServerFrame
60 63
      * @param parent The server instance that owns this frame
@@ -68,9 +71,11 @@ public class ServerFrame extends javax.swing.JInternalFrame {
68 71
         
69 72
         this.parent = parent;
70 73
         
74
+        commandParser = new ServerCommandParser(parent);
75
+        
71 76
         jTextField1.addActionListener(new ActionListener() {
72 77
             public void actionPerformed(ActionEvent actionEvent) {
73
-                ServerFrame.this.parent.getParser().sendLine(jTextField1.getText());
78
+                ServerFrame.this.commandParser.parseCommand(jTextField1.getText());
74 79
                 jTextField1.setText("");
75 80
             }
76 81
         });

Loading…
Откажи
Сачувај