Mercurial > hg > Applications > TreeVNC
comparison src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java @ 65:ffd7537cebfc
cuiversion
author | Taninari YU <you@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 27 Jan 2014 16:35:20 +0900 |
parents | |
children | e6550afe663b |
comparison
equal
deleted
inserted
replaced
64:e73e2c30c9a6 | 65:ffd7537cebfc |
---|---|
1 package com.glavsoft.viewer; | |
2 | |
3 import com.glavsoft.rfb.protocol.ProtocolSettings; | |
4 import com.glavsoft.viewer.cli.Parser; | |
5 import com.glavsoft.viewer.mvp.View; | |
6 import com.glavsoft.viewer.swing.ConnectionParams; | |
7 import com.glavsoft.viewer.swing.ParametersHandler; | |
8 import com.glavsoft.viewer.swing.SwingConnectionWorkerFactory; | |
9 import com.glavsoft.viewer.swing.SwingViewerWindowFactory; | |
10 import com.glavsoft.viewer.swing.gui.ConnectionView; | |
11 | |
12 import javax.swing.*; | |
13 import java.awt.*; | |
14 import java.awt.event.WindowEvent; | |
15 import java.awt.event.WindowListener; | |
16 import java.io.IOException; | |
17 import java.io.InputStream; | |
18 import java.net.Socket; | |
19 import java.util.jar.Attributes; | |
20 import java.util.jar.Manifest; | |
21 import java.util.logging.*; | |
22 | |
23 import jp.ac.u_ryukyu.treevnc.AcceptThread; | |
24 import jp.ac.u_ryukyu.treevnc.CreateConnectionParam; | |
25 import jp.ac.u_ryukyu.treevnc.MyRfbProto; | |
26 import jp.ac.u_ryukyu.treevnc.client.GetDataClient; | |
27 import jp.ac.u_ryukyu.treevnc.client.GetHostClient; | |
28 import jp.ac.u_ryukyu.treevnc.client.MyRfbProtoClient; | |
29 | |
30 public class CuiViewer implements Runnable, WindowListener, ViewerImpl { | |
31 | |
32 private Logger logger; | |
33 private int paramsMask; | |
34 private boolean allowAppletInteractiveConnections; | |
35 | |
36 public final ConnectionParams connectionParams; | |
37 protected String passwordFromParams; | |
38 boolean isSeparateFrame = true; | |
39 protected boolean isApplet = true; | |
40 private final ProtocolSettings settings; | |
41 protected UiSettings uiSettings; | |
42 private volatile boolean isAppletStopped = false; | |
43 private ConnectionPresenter connectionPresenter; | |
44 private boolean isTreeVNC = false; | |
45 protected MyRfbProto myRfb; | |
46 private boolean cuiVersion; | |
47 | |
48 public static void main(String[] args) { | |
49 Parser parser = new Parser(); | |
50 ParametersHandler.completeParserOptions(parser); | |
51 | |
52 parser.parse(args); | |
53 if (parser.isSet(ParametersHandler.ARG_HELP)) { | |
54 printUsage(parser.optionsUsage()); | |
55 System.exit(0); | |
56 } | |
57 CuiViewer viewer = new CuiViewer(parser); | |
58 SwingUtilities.invokeLater(viewer); | |
59 } | |
60 | |
61 public static void printUsage(String additional) { | |
62 System.out | |
63 .println("Usage: java -jar (progfilename) [hostname [port_number]] [Options]?n" | |
64 + " or?n" | |
65 + " java -jar (progfilename) [Options]?n" | |
66 + " or?n java -jar (progfilename) -help?n to view this help?n?n" | |
67 + "Where Options are:?n" | |
68 + additional | |
69 + "?nOptions format: -optionName=optionValue. Ex. -host=localhost -port=5900 -viewonly=yes?n" | |
70 + "Both option name and option value are case insensitive."); | |
71 } | |
72 | |
73 public CuiViewer() { | |
74 logger = Logger.getLogger(getClass().getName()); | |
75 connectionParams = new ConnectionParams(); | |
76 settings = ProtocolSettings.getDefaultSettings(); | |
77 uiSettings = new UiSettings(); | |
78 } | |
79 | |
80 private CuiViewer(Parser parser) { | |
81 this(); | |
82 setLoggingLevel(parser.isSet(ParametersHandler.ARG_VERBOSE) ? Level.FINE | |
83 : parser.isSet(ParametersHandler.ARG_VERBOSE_MORE) ? Level.FINER | |
84 : Level.INFO); | |
85 | |
86 paramsMask = ParametersHandler.completeSettingsFromCLI(parser, | |
87 connectionParams, settings, uiSettings); | |
88 passwordFromParams = parser.getValueFor(ParametersHandler.ARG_PASSWORD); | |
89 logger.info("TightVNC Viewer version " + ver()); | |
90 isApplet = false; | |
91 } | |
92 | |
93 private void setLoggingLevel(Level levelToSet) { | |
94 final Logger appLogger = Logger.getLogger("com.glavsoft"); | |
95 appLogger.setLevel(levelToSet); | |
96 ConsoleHandler ch = null; | |
97 for (Handler h : appLogger.getHandlers()) { | |
98 if (h instanceof ConsoleHandler) { | |
99 ch = (ConsoleHandler) h; | |
100 break; | |
101 } | |
102 } | |
103 if (null == ch) { | |
104 ch = new ConsoleHandler(); | |
105 appLogger.addHandler(ch); | |
106 } | |
107 // ch.setFormatter(new SimpleFormatter()); | |
108 ch.setLevel(levelToSet); | |
109 } | |
110 | |
111 @Override | |
112 public void windowClosing(WindowEvent e) { | |
113 if (e != null && e.getComponent() != null) { | |
114 final Window w = e.getWindow(); | |
115 if (w != null) { | |
116 w.setVisible(false); | |
117 w.dispose(); | |
118 } | |
119 } | |
120 closeApp(); | |
121 } | |
122 | |
123 /** | |
124 * Closes App(lication) or stops App(let). | |
125 */ | |
126 public void closeApp() { | |
127 /* nop */ | |
128 } | |
129 | |
130 private boolean checkJsch() { | |
131 try { | |
132 Class.forName("com.jcraft.jsch.JSch"); | |
133 return true; | |
134 } catch (ClassNotFoundException e) { | |
135 return false; | |
136 } | |
137 } | |
138 | |
139 @Override | |
140 public void run() { | |
141 final boolean hasJsch = checkJsch(); | |
142 final boolean allowInteractive = allowAppletInteractiveConnections | |
143 || !isApplet; | |
144 connectionPresenter = new ConnectionPresenter(hasJsch, allowInteractive); | |
145 connectionPresenter.addModel("ConnectionParamsModel", connectionParams); | |
146 | |
147 | |
148 /* | |
149 * SwingViewerWindowFactory viewerWindowFactory = new | |
150 * SwingViewerWindowFactory( isSeparateFrame, isApplet, this); | |
151 * | |
152 * connectionPresenter.setConnectionWorkerFactory(new | |
153 * SwingConnectionWorkerFactory( connectionView.getFrame(), | |
154 * passwordFromParams, connectionPresenter, viewerWindowFactory, | |
155 * myRfb)); | |
156 */ | |
157 | |
158 | |
159 connectionPresenter.setConnectionWorkerFactory( | |
160 new SwingConnectionWorkerFactory(null, passwordFromParams, connectionPresenter, null, myRfb)); | |
161 connectionPresenter.setCuiVersion(true); | |
162 connectionPresenter.startConnection(settings, uiSettings, paramsMask); | |
163 } | |
164 | |
165 @Override | |
166 public void windowOpened(WindowEvent e) { /* nop */ | |
167 } | |
168 | |
169 @Override | |
170 public void windowClosed(WindowEvent e) { /* nop */ | |
171 } | |
172 | |
173 @Override | |
174 public void windowIconified(WindowEvent e) { /* nop */ | |
175 } | |
176 | |
177 @Override | |
178 public void windowDeiconified(WindowEvent e) { /* nop */ | |
179 } | |
180 | |
181 @Override | |
182 public void windowActivated(WindowEvent e) { /* nop */ | |
183 } | |
184 | |
185 @Override | |
186 public void windowDeactivated(WindowEvent e) { /* nop */ | |
187 } | |
188 | |
189 public static String ver() { | |
190 final InputStream mfStream = Viewer.class.getClassLoader() | |
191 .getResourceAsStream("META-INF/MANIFEST.MF"); | |
192 if (null == mfStream) { | |
193 System.out.println("No Manifest file found."); | |
194 return "-1"; | |
195 } | |
196 try { | |
197 Manifest mf = new Manifest(); | |
198 mf.read(mfStream); | |
199 Attributes atts = mf.getMainAttributes(); | |
200 return atts.getValue(Attributes.Name.IMPLEMENTATION_VERSION); | |
201 } catch (IOException e) { | |
202 return "-2"; | |
203 } | |
204 } | |
205 | |
206 public void setType(TreeConnectionManager treeConnectionManager, | |
207 MyRfbProtoClient myRfbProtoClient) { | |
208 // must write | |
209 } | |
210 | |
211 public void setSocket(Socket soc) { | |
212 setConnectionParam(soc.getInetAddress().getHostAddress(), soc.getPort()); | |
213 // Thread accThread = new Thread(new AcceptThread(myRfb, | |
214 // soc.getPort())); | |
215 // accThread.start(); | |
216 } | |
217 | |
218 public void setOpenPort(int parseInt) { | |
219 // TODO Auto-generated method stub | |
220 | |
221 } | |
222 | |
223 public void setTeminationType(boolean b) { | |
224 myRfb.setTerminationType(b); | |
225 } | |
226 | |
227 public void startViewer() { | |
228 CuiViewer viewer = new CuiViewer(); | |
229 MyRfbProtoClient rfb = new MyRfbProtoClient(); | |
230 CreateConnectionParam cp = new CreateConnectionParam(rfb); | |
231 cp.communicationToProxy(); | |
232 cp.createConnectionParam(viewer); | |
233 viewer.isTreeVNC = true; | |
234 rfb.setViewer(viewer); | |
235 viewer.myRfb = rfb; | |
236 SwingUtilities.invokeLater(viewer); | |
237 } | |
238 | |
239 public void startViewer(String hostName, boolean cui) { | |
240 CuiViewer viewer = new CuiViewer(); | |
241 viewer.cuiVersion = cui; | |
242 MyRfbProtoClient rfb = new MyRfbProtoClient(); | |
243 CreateConnectionParam cp = new CreateConnectionParam(rfb); | |
244 cp.setHostName(hostName); | |
245 cp.createConnectionParam(viewer); | |
246 viewer.isTreeVNC = true; | |
247 rfb.setViewer(viewer); | |
248 rfb.setCuiVersion(true); | |
249 viewer.myRfb = rfb; | |
250 SwingUtilities.invokeLater(viewer); | |
251 } | |
252 | |
253 public void setConnectionParam(String hostName, int port) { | |
254 connectionParams.setHostName(hostName); | |
255 connectionParams.setPortNumber(port); | |
256 } | |
257 | |
258 public void setIsTreeVNC(boolean flag) { | |
259 isTreeVNC = flag; | |
260 } | |
261 | |
262 public MyRfbProto getRfb() { | |
263 return myRfb; | |
264 } | |
265 | |
266 public boolean getCuiVersion() { | |
267 return cuiVersion; | |
268 } | |
269 } |