Browse Source

* Added Raw class

* Remove default ServerFrame window
* Added AddLine method to ServerFrame
* Automatically create a new server window (quakenet)
* Server instances now create an IRC Parser and Raw instance
* Added PortInputVerifier class to NewServerDialog

git-svn-id: http://svn.dmdirc.com/trunk@21 00569f92-eb28-0410-84fd-f71c24880f
tags/0.1
Chris Smith 17 years ago
parent
commit
319b35ecd6

+ 2
- 0
src/dmdirc/Main.java View File

@@ -58,6 +58,8 @@ public class Main {
58 58
         
59 59
         MainFrame frame = MainFrame.getMainFrame();
60 60
         
61
+        Server serv = new Server("irc.quakenet.org", 6667);
62
+        
61 63
     }
62 64
     
63 65
 }

+ 59
- 0
src/dmdirc/Raw.java View File

@@ -0,0 +1,59 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
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 dmdirc;
24
+
25
+import dmdirc.parser.IRCParser;
26
+import dmdirc.ui.MainFrame;
27
+import dmdirc.ui.ServerFrame;
28
+
29
+/**
30
+ *
31
+ * @author chris
32
+ */
33
+public class Raw {
34
+    
35
+    private Server server;
36
+    private ServerFrame frame;
37
+    
38
+    /** Creates a new instance of Raw */
39
+    public Raw(Server server) {
40
+        this.server = server;
41
+        
42
+        frame = new ServerFrame();
43
+        
44
+        MainFrame.getMainFrame().addChild(frame);
45
+        
46
+        server.AddDataIn(new IRCParser.IDataIn() {
47
+            public void onDataIn(IRCParser tParser, String sData) {
48
+                Raw.this.frame.addLine("<<< "+sData);
49
+            }
50
+        });
51
+        
52
+        server.AddDataOut(new IRCParser.IDataOut() {
53
+            public void onDataOut(IRCParser tparser, String sData) {
54
+                Raw.this.frame.addLine(">>> "+sData);
55
+            }
56
+        });
57
+    }
58
+    
59
+}

+ 16
- 1
src/dmdirc/Server.java View File

@@ -51,7 +51,7 @@ public class Server {
51 51
     private IRCParser parser;
52 52
     
53 53
     /** Creates a new instance of Server */
54
-    public Server() {
54
+    public Server(String server, int port) {
55 55
         
56 56
         channels = new Vector(0,1);
57 57
         
@@ -60,6 +60,17 @@ public class Server {
60 60
         frame = new ServerFrame();
61 61
         
62 62
         MainFrame.getMainFrame().addChild(frame);
63
+        
64
+        parser = new IRCParser();
65
+        
66
+        Raw raw = new Raw(this);
67
+        
68
+        try {
69
+            parser.connect(server, port);
70
+            parser.run();
71
+        } catch (Exception ex) {
72
+            frame.addLine("ERROR: "+ex.getMessage());
73
+        }
63 74
     }
64 75
     
65 76
     /**
@@ -69,4 +80,8 @@ public class Server {
69 80
         ServerManager.getServerManager().unregisterServer(this);
70 81
     }
71 82
     
83
+    public void AddDataIn (Object eMethod) { parser.AddDataIn(eMethod); }
84
+    public void AddDataOut (Object eMethod) { parser.AddDataOut(eMethod); }
85
+    public void AddMOTDEnd (Object eMethod) { parser.AddMOTDEnd(eMethod); }
86
+    
72 87
 }

+ 1
- 3
src/dmdirc/ui/MainFrame.java View File

@@ -36,7 +36,7 @@ public class MainFrame extends javax.swing.JFrame {
36 36
     /**
37 37
      * Singleton instance of MainFrame
38 38
      */
39
-    private static MainFrame me = null;
39
+    private static MainFrame me;
40 40
     
41 41
     /**
42 42
      * Returns the singleton instance of MainFrame
@@ -53,8 +53,6 @@ public class MainFrame extends javax.swing.JFrame {
53 53
     public MainFrame() {
54 54
         initComponents();
55 55
         setVisible(true);
56
-        ServerFrame test = new ServerFrame();
57
-        desktopPane.add(test);
58 56
         
59 57
         miAddServer.addActionListener(new ActionListener() {
60 58
             public void actionPerformed(ActionEvent actionEvent) {

+ 19
- 0
src/dmdirc/ui/NewServerDialog.java View File

@@ -27,6 +27,9 @@ import java.awt.event.ActionEvent;
27 27
 import java.awt.event.ActionListener;
28 28
 import java.awt.event.WindowEvent;
29 29
 import java.awt.event.WindowListener;
30
+import javax.swing.InputVerifier;
31
+import javax.swing.JComponent;
32
+import javax.swing.JTextField;
30 33
 
31 34
 /**
32 35
  *
@@ -46,6 +49,8 @@ public class NewServerDialog extends javax.swing.JDialog {
46 49
             jCheckBox1.setEnabled(false);
47 50
         }
48 51
         
52
+        jTextField2.setInputVerifier(new PortVerifier());
53
+        
49 54
         addCallbacks();
50 55
         
51 56
         setVisible(true);
@@ -200,3 +205,17 @@ public class NewServerDialog extends javax.swing.JDialog {
200 205
     // End of variables declaration//GEN-END:variables
201 206
     
202 207
 }
208
+
209
+class PortVerifier extends InputVerifier {
210
+    
211
+    public boolean verify(JComponent jComponent) {
212
+        JTextField tf = (JTextField)jComponent;
213
+        try {
214
+            Integer port = Integer.parseInt(tf.getText());
215
+            return (port > 0 && port <= 65535);
216
+        } catch (Exception e) {
217
+            return false;
218
+        }
219
+    }
220
+    
221
+}

+ 3
- 0
src/dmdirc/ui/ServerFrame.form View File

@@ -1,6 +1,9 @@
1 1
 <?xml version="1.0" encoding="UTF-8" ?>
2 2
 
3 3
 <Form version="1.3" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
4
+  <Properties>
5
+    <Property name="title" type="java.lang.String" value="Server Frame"/>
6
+  </Properties>
4 7
   <SyntheticProperties>
5 8
     <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
6 9
   </SyntheticProperties>

+ 5
- 0
src/dmdirc/ui/ServerFrame.java View File

@@ -36,6 +36,10 @@ public class ServerFrame extends javax.swing.JInternalFrame {
36 36
         setVisible(true);
37 37
     }
38 38
     
39
+    public void addLine(String line) {
40
+        jTextArea1.append(line+"\n");
41
+    }
42
+    
39 43
     /** This method is called from within the constructor to
40 44
      * initialize the form.
41 45
      * WARNING: Do NOT modify this code. The content of this method is
@@ -47,6 +51,7 @@ public class ServerFrame extends javax.swing.JInternalFrame {
47 51
         jTextArea1 = new javax.swing.JTextArea();
48 52
         jTextField1 = new javax.swing.JTextField();
49 53
 
54
+        setTitle("Server Frame");
50 55
         jTextArea1.setColumns(20);
51 56
         jTextArea1.setRows(5);
52 57
         jScrollPane1.setViewportView(jTextArea1);

Loading…
Cancel
Save