1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package uk.ac.rdg.resc.jstyx.client.browser;
30
31 import javax.swing.*;
32 import java.awt.event.WindowAdapter;
33 import java.awt.event.WindowEvent;
34
35 import uk.ac.rdg.resc.jstyx.client.StyxConnection;
36 import uk.ac.rdg.resc.jstyx.StyxUtils;
37
38 /***
39 * Main class for a graphical StyxBrowser; simply puts a JTreeTable in a JFrame
40 * @todo Make into an applet?
41 *
42 * @author Jon Blower
43 * $Revision: 604 $
44 * $Date: 2006-03-21 14:58:42 +0000 (Tue, 21 Mar 2006) $
45 * $Log$
46 * Revision 1.11 2006/03/21 14:58:42 jonblower
47 * Implemented clear-text password-based authentication and did some simple tests
48 *
49 * Revision 1.10 2006/03/21 09:06:14 jonblower
50 * Still implementing authentication
51 *
52 * Revision 1.9 2005/03/18 13:55:59 jonblower
53 * Improved freeing of ByteBuffers, and bug fixes
54 *
55 * Revision 1.8 2005/03/15 15:51:41 jonblower
56 * Removed hard limit on maximum message size
57 *
58 * Revision 1.6 2005/03/11 15:06:21 jonblower
59 * Replaced deprecated frame.show() with frame.setVisible(true)
60 *
61 * Revision 1.5 2005/03/11 13:58:54 jonblower
62 * Merged MINA-Test_20059309 into main line of development
63 *
64 * Revision 1.4.2.1 2005/03/10 11:47:36 jonblower
65 * Changed to create the StyxConnection in the StyxBrowser class so it can be closed cleanly
66 *
67 * Revision 1.4 2005/02/28 16:16:26 jonblower
68 * Specified anonymous user when logging on without a user name
69 *
70 * Revision 1.3 2005/02/26 09:59:34 jonblower
71 * Now reads connection details from command line
72 *
73 * Revision 1.1 2005/02/18 17:52:40 jonblower
74 * Added client.browser package
75 *
76 */
77
78 public class StyxBrowser
79 {
80 public static void main(String[] args) throws Throwable
81 {
82 if (args.length < 2 || args.length > 4)
83 {
84 System.err.println("Usage: java StyxBrowser <hostname> <port> [user] [password]");
85 return;
86 }
87 int port;
88 try
89 {
90 port = Integer.parseInt(args[1]);
91 }
92 catch(NumberFormatException nfe)
93 {
94 System.err.println("Invalid port number");
95 return;
96 }
97 if (port < 0 || port > StyxUtils.MAXUSHORT)
98 {
99 System.err.println("Invalid port number (must be between 0 and " +
100 StyxUtils.MAXUSHORT + ")");
101 return;
102 }
103 String user = args.length > 2 ? args[2] : "";
104 String password = args.length > 3 ? args[3] : "";
105
106 new StyxBrowser(args[0], port, user, password);
107 }
108
109 public StyxBrowser(String host, int port, String user, String password)
110 throws Throwable
111 {
112 String s = user.trim().equals("") ? StyxUtils.ANONYMOUS_USER : user;
113 JFrame frame = new JFrame(s + "@" + host + ":" + port);
114 final StyxConnection conn = new StyxConnection(host, port, user, password);
115 conn.connect();
116 JTreeTable treeTable = new JTreeTable(new StyxFileSystemModel(conn));
117
118 frame.addWindowListener(new WindowAdapter()
119 {
120 public void windowClosing(WindowEvent we)
121 {
122 conn.close();
123 System.exit(0);
124 }
125 });
126
127 frame.getContentPane().add(new JScrollPane(treeTable));
128 frame.pack();
129 frame.setVisible(true);
130 }
131 }
132