Mercurial > hg > Members > riono > TreeVNC_ja_comment
annotate src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java @ 455:6f3d3da40940
fix cui and hasViewer flag
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 22 Jun 2016 12:29:57 +0900 |
parents | 344a35b7c47f |
children | 34277b436cac |
rev | line source |
---|---|
65 | 1 package com.glavsoft.viewer; |
2 | |
3 import com.glavsoft.rfb.protocol.ProtocolSettings; | |
383 | 4 import com.glavsoft.transport.Reader; |
5 import com.glavsoft.transport.Writer; | |
65 | 6 import com.glavsoft.viewer.cli.Parser; |
7 import com.glavsoft.viewer.swing.ConnectionParams; | |
8 import com.glavsoft.viewer.swing.ParametersHandler; | |
9 import com.glavsoft.viewer.swing.SwingConnectionWorkerFactory; | |
448
344a35b7c47f
send both frame buffer size and selected screen size in Disktop size change (INIT_DATA)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
428
diff
changeset
|
10 import jp.ac.u_ryukyu.treevnc.CreateConnectionParam; |
344a35b7c47f
send both frame buffer size and selected screen size in Disktop size change (INIT_DATA)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
428
diff
changeset
|
11 import jp.ac.u_ryukyu.treevnc.TreeRFBProto; |
130 | 12 |
65 | 13 import javax.swing.*; |
14 import java.awt.*; | |
15 import java.awt.event.WindowEvent; | |
16 import java.awt.event.WindowListener; | |
17 import java.io.IOException; | |
18 import java.io.InputStream; | |
19 import java.net.Socket; | |
448
344a35b7c47f
send both frame buffer size and selected screen size in Disktop size change (INIT_DATA)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
428
diff
changeset
|
20 import java.util.ArrayList; |
65 | 21 import java.util.jar.Attributes; |
22 import java.util.jar.Manifest; | |
448
344a35b7c47f
send both frame buffer size and selected screen size in Disktop size change (INIT_DATA)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
428
diff
changeset
|
23 import java.util.logging.ConsoleHandler; |
344a35b7c47f
send both frame buffer size and selected screen size in Disktop size change (INIT_DATA)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
428
diff
changeset
|
24 import java.util.logging.Handler; |
344a35b7c47f
send both frame buffer size and selected screen size in Disktop size change (INIT_DATA)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
428
diff
changeset
|
25 import java.util.logging.Level; |
344a35b7c47f
send both frame buffer size and selected screen size in Disktop size change (INIT_DATA)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
428
diff
changeset
|
26 import java.util.logging.Logger; |
65 | 27 |
153 | 28 public class CuiViewer implements Runnable, WindowListener, ViewerInterface { |
65 | 29 |
240 | 30 private Logger logger; |
31 private int paramsMask; | |
32 private boolean allowAppletInteractiveConnections; | |
65 | 33 |
240 | 34 public final ConnectionParams connectionParams; |
35 protected String passwordFromParams; | |
36 boolean isSeparateFrame = true; | |
37 protected boolean isApplet = true; | |
38 private final ProtocolSettings settings; | |
39 protected UiSettings uiSettings; | |
40 private ConnectionPresenter connectionPresenter; | |
41 protected TreeRFBProto myRfb; | |
42 private boolean cuiVersion; | |
204
d9d234715853
TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
202
diff
changeset
|
43 private boolean showTree = false; |
225 | 44 public int width; |
240 | 45 public int height; |
65 | 46 |
240 | 47 public static void main(String[] args) { |
48 Parser parser = new Parser(); | |
49 ParametersHandler.completeParserOptions(parser); | |
65 | 50 |
240 | 51 parser.parse(args); |
52 if (parser.isSet(ParametersHandler.ARG_HELP)) { | |
53 printUsage(parser.optionsUsage()); | |
54 System.exit(0); | |
55 } | |
56 CuiViewer viewer = new CuiViewer(parser); | |
57 SwingUtilities.invokeLater(viewer); | |
58 } | |
65 | 59 |
240 | 60 public static void printUsage(String additional) { |
61 System.out | |
300 | 62 .println("Usage: java -jar (progfilename) [hostname [port_number]] [Options]?n" |
63 + " or?n" | |
64 + " java -jar (progfilename) [Options]?n" | |
65 + " or?n java -jar (progfilename) -help?n to view this help?n?n" | |
66 + "Where Options are:?n" | |
67 + additional | |
68 + "?nOptions format: -optionName=optionValue. Ex. -host=localhost -port=5900 -viewonly=yes?n" | |
69 + "Both option name and option value are case insensitive."); | |
240 | 70 } |
65 | 71 |
240 | 72 public CuiViewer() { |
73 logger = Logger.getLogger(getClass().getName()); | |
74 connectionParams = new ConnectionParams(); | |
75 settings = ProtocolSettings.getDefaultSettings(); | |
76 uiSettings = new UiSettings(); | |
77 } | |
65 | 78 |
240 | 79 private CuiViewer(Parser parser) { |
80 this(); | |
81 setLoggingLevel(parser.isSet(ParametersHandler.ARG_VERBOSE) ? Level.FINE | |
82 : parser.isSet(ParametersHandler.ARG_VERBOSE_MORE) ? Level.FINER | |
300 | 83 : Level.INFO); |
65 | 84 |
240 | 85 paramsMask = ParametersHandler.completeSettingsFromCLI(parser, |
86 connectionParams, settings, uiSettings); | |
87 passwordFromParams = parser.getValueFor(ParametersHandler.ARG_PASSWORD); | |
88 logger.info("TightVNC Viewer version " + ver()); | |
89 isApplet = false; | |
90 } | |
65 | 91 |
240 | 92 private void setLoggingLevel(Level levelToSet) { |
93 final Logger appLogger = Logger.getLogger("com.glavsoft"); | |
94 appLogger.setLevel(levelToSet); | |
95 ConsoleHandler ch = null; | |
96 for (Handler h : appLogger.getHandlers()) { | |
97 if (h instanceof ConsoleHandler) { | |
98 ch = (ConsoleHandler) h; | |
99 break; | |
100 } | |
101 } | |
102 if (null == ch) { | |
103 ch = new ConsoleHandler(); | |
104 appLogger.addHandler(ch); | |
105 } | |
106 // ch.setFormatter(new SimpleFormatter()); | |
107 ch.setLevel(levelToSet); | |
108 } | |
65 | 109 |
240 | 110 @Override |
111 public void windowClosing(WindowEvent e) { | |
112 if (e != null && e.getComponent() != null) { | |
113 final Window w = e.getWindow(); | |
114 if (w != null) { | |
115 w.setVisible(false); | |
116 w.dispose(); | |
117 } | |
118 } | |
119 closeApp(); | |
120 } | |
65 | 121 |
240 | 122 /** |
123 * Closes App(lication) or stops App(let). | |
124 */ | |
125 public void closeApp() { | |
126 /* nop */ | |
127 } | |
65 | 128 |
240 | 129 private boolean checkJsch() { |
130 try { | |
131 Class.forName("com.jcraft.jsch.JSch"); | |
132 return true; | |
133 } catch (ClassNotFoundException e) { | |
134 return false; | |
135 } | |
136 } | |
65 | 137 |
240 | 138 @Override |
139 public void run() { | |
140 final boolean hasJsch = checkJsch(); | |
141 final boolean allowInteractive = allowAppletInteractiveConnections | |
142 || !isApplet; | |
363 | 143 ConnectionPresenter connectionPresenter = new ConnectionPresenter(hasJsch, allowInteractive); |
240 | 144 connectionPresenter.addModel("ConnectionParamsModel", connectionParams); |
65 | 145 connectionPresenter.setConnectionWorkerFactory( |
146 new SwingConnectionWorkerFactory(null, passwordFromParams, connectionPresenter, null, myRfb)); | |
240 | 147 connectionPresenter.setCuiVersion(true); |
395
704ac9e79e25
Call startVNCConnectionWithSocket for directedServerChangeReqeust
innparusu
parents:
383
diff
changeset
|
148 connectionPresenter.startConnection(settings, uiSettings, paramsMask, false, null, null); |
240 | 149 } |
65 | 150 |
240 | 151 @Override |
370 | 152 public ConnectionPresenter getConnectionPresenter() { |
153 return connectionPresenter; | |
363 | 154 } |
155 | |
156 @Override | |
370 | 157 public void setConnectionPresenter(ConnectionPresenter connectionPresenter) { |
158 this.connectionPresenter = connectionPresenter; | |
369 | 159 } |
160 | |
161 @Override | |
428
f6a828dd37b0
Change timing for setting share screen info
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
427
diff
changeset
|
162 public void changeToDirectConnectedServer(String hostName, Reader is, Writer os, int x, int y, int width, int height, int scale) { |
383 | 163 |
164 } | |
165 | |
166 @Override | |
240 | 167 public void windowOpened(WindowEvent e) { /* nop */ |
168 } | |
65 | 169 |
240 | 170 @Override |
171 public void windowClosed(WindowEvent e) { /* nop */ | |
172 } | |
65 | 173 |
240 | 174 @Override |
175 public void windowIconified(WindowEvent e) { /* nop */ | |
176 } | |
65 | 177 |
240 | 178 @Override |
179 public void windowDeiconified(WindowEvent e) { /* nop */ | |
180 } | |
65 | 181 |
240 | 182 @Override |
183 public void windowActivated(WindowEvent e) { /* nop */ | |
184 } | |
65 | 185 |
240 | 186 @Override |
187 public void windowDeactivated(WindowEvent e) { /* nop */ | |
188 } | |
65 | 189 |
240 | 190 public static String ver() { |
191 final InputStream mfStream = Viewer.class.getClassLoader() | |
192 .getResourceAsStream("META-INF/MANIFEST.MF"); | |
193 if (null == mfStream) { | |
194 System.out.println("No Manifest file found."); | |
195 return "-1"; | |
196 } | |
197 try { | |
198 Manifest mf = new Manifest(); | |
199 mf.read(mfStream); | |
200 Attributes atts = mf.getMainAttributes(); | |
201 return atts.getValue(Attributes.Name.IMPLEMENTATION_VERSION); | |
202 } catch (IOException e) { | |
203 return "-2"; | |
204 } | |
205 } | |
65 | 206 |
240 | 207 public void setSocket(Socket soc) { |
208 connectionParams.setConnectionParam(soc.getInetAddress().getHostAddress(), soc.getPort()); | |
209 } | |
65 | 210 |
240 | 211 public void setOpenPort(int parseInt) { |
212 } | |
65 | 213 |
328
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
327
diff
changeset
|
214 public void setTerminationType(boolean b) { |
240 | 215 myRfb.setTerminationType(b); |
216 } | |
65 | 217 |
379 | 218 public void startTreeViewer(String hostName, boolean cui, boolean addSerialNum) { |
240 | 219 CuiViewer viewer = new CuiViewer(); |
220 viewer.cuiVersion = cui; | |
327
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
317
diff
changeset
|
221 TreeRFBProto rfb = new TreeRFBProto(false, this); |
240 | 222 CreateConnectionParam cp = new CreateConnectionParam(rfb); |
300 | 223 if (hostName==null) { |
327
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
317
diff
changeset
|
224 cp.findTreeVncRoot(); |
240 | 225 } else { |
226 cp.setHostName(hostName); | |
227 } | |
228 rfb.createConnectionAndStart(this); | |
229 cp.sendWhereToConnect(viewer); | |
230 rfb.setCuiVersion(cui); | |
231 viewer.myRfb = rfb; | |
232 SwingUtilities.invokeLater(viewer); | |
233 } | |
65 | 234 |
240 | 235 public void setIsTreeVNC(boolean flag) { |
236 } | |
65 | 237 |
240 | 238 public TreeRFBProto getRfb() { |
239 return myRfb; | |
240 } | |
65 | 241 |
240 | 242 public boolean getCuiVersion() { |
243 return cuiVersion; | |
244 } | |
245 | |
246 public void setCuiVersion(boolean flag) { | |
247 // nop | |
248 } | |
130 | 249 |
250 @Override | |
174 | 251 public void connectToParenet(int port, String hostname) throws IOException { |
328
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
327
diff
changeset
|
252 setTerminationType(false); |
174 | 253 closeApp(); |
179 | 254 connectionParams.setConnectionParam(hostname, port); |
174 | 255 run(); |
256 } | |
257 | |
258 @Override | |
428
f6a828dd37b0
Change timing for setting share screen info
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
427
diff
changeset
|
259 public void inhelitClients(String hostName, short newVNCServerId, int x, int y, int width, int height, int scale) { |
240 | 260 |
174 | 261 } |
262 | |
263 @Override | |
455
6f3d3da40940
fix cui and hasViewer flag
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
448
diff
changeset
|
264 public void proxyStart(String[] args, String hostName, int width, int height, boolean showTree, boolean checkDelay, boolean addSerialNum, boolean fixingSize, boolean filterSingleDisplay, boolean hasViewer) { |
240 | 265 |
174 | 266 } |
267 | |
176 | 268 @Override |
269 public void setNoConnection(boolean noConnection) { | |
240 | 270 |
176 | 271 } |
272 | |
240 | 273 @Override |
274 public void setVisible(boolean b) { | |
275 } | |
192 | 276 |
240 | 277 @Override |
278 public Socket getVNCSocket() { | |
279 return connectionPresenter.getSocket(); | |
280 } | |
202 | 281 |
204
d9d234715853
TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
202
diff
changeset
|
282 @Override |
d9d234715853
TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
202
diff
changeset
|
283 public boolean getShowTree() { |
d9d234715853
TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
202
diff
changeset
|
284 return showTree; |
d9d234715853
TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
202
diff
changeset
|
285 } |
d9d234715853
TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
202
diff
changeset
|
286 |
225 | 287 @Override |
288 public void setWidth(int w) { | |
240 | 289 width = w; |
225 | 290 } |
291 | |
292 @Override | |
293 public void setHeight(int h) { | |
300 | 294 height = h; |
257 | 295 } |
296 | |
297 @Override | |
298 public void setFixingSize(int width, int height) { | |
299 } | |
301 | 300 |
301 @Override | |
302 public java.util.ArrayList<Rectangle> getScreenRectangles() { | |
303 return null; | |
304 } | |
317 | 305 |
306 @Override | |
448
344a35b7c47f
send both frame buffer size and selected screen size in Disktop size change (INIT_DATA)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
428
diff
changeset
|
307 public Point getScreenOffset(ArrayList<Rectangle> rectangles) { |
344a35b7c47f
send both frame buffer size and selected screen size in Disktop size change (INIT_DATA)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
428
diff
changeset
|
308 return null; |
344a35b7c47f
send both frame buffer size and selected screen size in Disktop size change (INIT_DATA)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
428
diff
changeset
|
309 } |
344a35b7c47f
send both frame buffer size and selected screen size in Disktop size change (INIT_DATA)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
428
diff
changeset
|
310 |
344a35b7c47f
send both frame buffer size and selected screen size in Disktop size change (INIT_DATA)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
428
diff
changeset
|
311 @Override |
317 | 312 public void setFitScreen() { |
313 } | |
65 | 314 } |