|
1 | 1 | package net.sf.sockettest; |
2 | 2 |
|
3 | 3 | import java.awt.*; |
4 | | -import java.applet.*; |
5 | | -import java.awt.event.*; |
| 4 | +import java.util.HashMap; |
| 5 | +import java.util.Map; |
6 | 6 | import javax.swing.*; |
7 | | -import javax.swing.event.*; |
8 | | -import javax.swing.border.*; |
| 7 | + |
9 | 8 | import net.sf.sockettest.swing.About; |
10 | 9 | import net.sf.sockettest.swing.SocketTestClient; |
11 | 10 | import net.sf.sockettest.swing.SocketTestServer; |
12 | 11 | import net.sf.sockettest.swing.SocketTestUdp; |
13 | 12 | import net.sf.sockettest.swing.SplashScreen; |
14 | 13 |
|
15 | 14 | /** |
16 | | - * |
17 | 15 | * @author Akshathkumar Shetty |
18 | 16 | */ |
19 | 17 | public class SocketTest extends JFrame { |
| 18 | + private static final String CLIENT = "c"; |
| 19 | + private static final String SERVER = "s"; |
| 20 | + private static final String UDP = "u"; |
20 | 21 | private ClassLoader cl = getClass().getClassLoader(); |
21 | | - public ImageIcon logo = new ImageIcon( |
22 | | - cl.getResource("icons/logo.gif")); |
23 | | - public ImageIcon ball = new ImageIcon( |
24 | | - cl.getResource("icons/ball.gif")); |
| 22 | + public ImageIcon logo = new ImageIcon(cl.getResource("icons/logo.gif")); |
| 23 | + public ImageIcon ball = new ImageIcon(cl.getResource("icons/ball.gif")); |
25 | 24 | private JTabbedPane tabbedPane; |
26 | | - |
27 | | - /** Creates a new instance of SocketTest */ |
| 25 | + |
| 26 | + private static Map<String, NetService> services = new HashMap<>(); |
| 27 | + |
| 28 | + /** |
| 29 | + * Creates a new instance of SocketTest |
| 30 | + */ |
28 | 31 | public SocketTest() { |
29 | 32 | Container cp = getContentPane(); |
30 | | - |
| 33 | + |
31 | 34 | tabbedPane = new JTabbedPane(JTabbedPane.TOP); |
32 | 35 | SocketTestClient client = new SocketTestClient(this); |
33 | 36 | SocketTestServer server = new SocketTestServer(this); |
34 | 37 | SocketTestUdp udp = new SocketTestUdp(this); |
35 | 38 | About about = new About(); |
36 | | - |
37 | | - tabbedPane.addTab("Client", ball, (Component)client, "Test any server"); |
| 39 | + |
| 40 | + services.put(CLIENT, client); |
| 41 | + services.put(SERVER, server); |
| 42 | + services.put(UDP, udp); |
| 43 | + |
| 44 | + tabbedPane.addTab("Client", ball, (Component) client, "Test any server"); |
38 | 45 | tabbedPane.addTab("Server", ball, server, "Test any client"); |
39 | 46 | tabbedPane.addTab("Udp", ball, udp, "Test any UDP Client or Server"); |
40 | 47 | tabbedPane.addTab("About", ball, about, "About SocketTest"); |
41 | | - |
42 | | - tabbedPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); |
| 48 | + |
| 49 | + tabbedPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); |
43 | 50 | cp.add(tabbedPane); |
44 | 51 | } |
45 | | - |
| 52 | + |
46 | 53 | /** |
47 | 54 | * @param args the command line arguments |
48 | 55 | */ |
49 | 56 | public static void main(String[] args) { |
50 | 57 | try { |
51 | 58 | UIManager.setLookAndFeel("net.sourceforge.mlf.metouia.MetouiaLookAndFeel"); |
52 | | - } catch(Exception e) { |
| 59 | + } catch (Exception e) { |
53 | 60 | //e.printStackTrace(); |
54 | 61 | try { |
55 | 62 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
56 | | - } catch(Exception ee) { |
| 63 | + } catch (Exception ee) { |
57 | 64 | System.out.println("Error setting native LAF: " + ee); |
58 | 65 | } |
59 | 66 | } |
60 | | - |
61 | | - boolean toSplash = true; |
62 | | - if(args.length>0) { |
63 | | - if("nosplash".equals(args[0])) toSplash = false; |
64 | | - } |
65 | | - |
66 | | - SplashScreen splash = null; |
67 | | - if(toSplash) splash = new SplashScreen(); |
68 | | - |
| 67 | + |
| 68 | + boolean toSplash = true; |
| 69 | + if (args.length > 0) { |
| 70 | + if ("nosplash".equals(args[0])) toSplash = false; |
| 71 | + } |
| 72 | + |
| 73 | + SplashScreen splash = null; |
| 74 | + if (toSplash) splash = new SplashScreen(); |
| 75 | + |
69 | 76 | SocketTest st = new SocketTest(); |
70 | | - st.setTitle("SocketTest v 3.0.0"); |
71 | | - st.setSize(600,500); |
| 77 | + st.setTitle("SocketTest v 3.0.1"); |
| 78 | + st.setSize(600, 500); |
72 | 79 | Util.centerWindow(st); |
73 | 80 | st.setDefaultCloseOperation(EXIT_ON_CLOSE); |
74 | 81 | st.setIconImage(st.logo.getImage()); |
75 | | - if(toSplash) splash.kill(); |
| 82 | + |
| 83 | + setUpArgParams(args); |
| 84 | + |
| 85 | + if (toSplash) splash.kill(); |
76 | 86 | st.setVisible(true); |
77 | 87 | } |
78 | | - |
| 88 | + |
| 89 | + private static void setUpArgParams(String[] configuration) { |
| 90 | + if (configuration.length < 1) { |
| 91 | + return; |
| 92 | + } |
| 93 | + |
| 94 | + //c:ip:port |
| 95 | + //s:ip:port |
| 96 | + //u:ip:port |
| 97 | + for (String arg : configuration) { |
| 98 | + String[] params = arg.split(":"); |
| 99 | + if (params.length == 3) { |
| 100 | + String service = params[0]; |
| 101 | + String ip = params[1]; |
| 102 | + String port = params[2]; |
| 103 | + services.get(service).setUpConfiguration(ip, port); |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + |
79 | 108 | } |
| 109 | + |
| 110 | + |
0 commit comments