Mercurial > hg > Applications > TreeVNC
annotate src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java @ 512:16f9b37ef43b
fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 20 Feb 2019 15:49:28 +0900 |
parents | 4ea47640942a |
children | 887ebd993b3d |
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; |
512 | 46 private boolean useMulticast; |
65 | 47 |
240 | 48 public static void main(String[] args) { |
49 Parser parser = new Parser(); | |
50 ParametersHandler.completeParserOptions(parser); | |
65 | 51 |
240 | 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 } | |
65 | 60 |
240 | 61 public static void printUsage(String additional) { |
62 System.out | |
300 | 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."); | |
240 | 71 } |
65 | 72 |
240 | 73 public CuiViewer() { |
74 logger = Logger.getLogger(getClass().getName()); | |
75 connectionParams = new ConnectionParams(); | |
76 settings = ProtocolSettings.getDefaultSettings(); | |
77 uiSettings = new UiSettings(); | |
78 } | |
65 | 79 |
240 | 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 | |
300 | 84 : Level.INFO); |
65 | 85 |
240 | 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 } | |
65 | 92 |
240 | 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 } | |
65 | 110 |
240 | 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 } | |
65 | 122 |
240 | 123 /** |
124 * Closes App(lication) or stops App(let). | |
125 */ | |
126 public void closeApp() { | |
127 /* nop */ | |
128 } | |
65 | 129 |
240 | 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 } | |
65 | 138 |
240 | 139 @Override |
140 public void run() { | |
141 final boolean hasJsch = checkJsch(); | |
142 final boolean allowInteractive = allowAppletInteractiveConnections | |
143 || !isApplet; | |
363 | 144 ConnectionPresenter connectionPresenter = new ConnectionPresenter(hasJsch, allowInteractive); |
240 | 145 connectionPresenter.addModel("ConnectionParamsModel", connectionParams); |
65 | 146 connectionPresenter.setConnectionWorkerFactory( |
147 new SwingConnectionWorkerFactory(null, passwordFromParams, connectionPresenter, null, myRfb)); | |
240 | 148 connectionPresenter.setCuiVersion(true); |
512 | 149 connectionPresenter.setMulticast(useMulticast); |
395
704ac9e79e25
Call startVNCConnectionWithSocket for directedServerChangeReqeust
innparusu
parents:
383
diff
changeset
|
150 connectionPresenter.startConnection(settings, uiSettings, paramsMask, false, null, null); |
240 | 151 } |
65 | 152 |
240 | 153 @Override |
370 | 154 public ConnectionPresenter getConnectionPresenter() { |
155 return connectionPresenter; | |
363 | 156 } |
157 | |
158 @Override | |
370 | 159 public void setConnectionPresenter(ConnectionPresenter connectionPresenter) { |
160 this.connectionPresenter = connectionPresenter; | |
369 | 161 } |
162 | |
163 @Override | |
428
f6a828dd37b0
Change timing for setting share screen info
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
427
diff
changeset
|
164 public void changeToDirectConnectedServer(String hostName, Reader is, Writer os, int x, int y, int width, int height, int scale) { |
383 | 165 |
166 } | |
167 | |
168 @Override | |
512 | 169 public void setUseMulticast(boolean useMulticast) { |
170 this.useMulticast = useMulticast; | |
171 } | |
172 | |
173 @Override | |
174 public boolean getUseMulticast() { | |
175 return useMulticast; | |
176 } | |
177 | |
178 @Override | |
240 | 179 public void windowOpened(WindowEvent e) { /* nop */ |
180 } | |
65 | 181 |
240 | 182 @Override |
183 public void windowClosed(WindowEvent e) { /* nop */ | |
184 } | |
65 | 185 |
240 | 186 @Override |
187 public void windowIconified(WindowEvent e) { /* nop */ | |
188 } | |
65 | 189 |
240 | 190 @Override |
191 public void windowDeiconified(WindowEvent e) { /* nop */ | |
192 } | |
65 | 193 |
240 | 194 @Override |
195 public void windowActivated(WindowEvent e) { /* nop */ | |
196 } | |
65 | 197 |
240 | 198 @Override |
199 public void windowDeactivated(WindowEvent e) { /* nop */ | |
200 } | |
65 | 201 |
240 | 202 public static String ver() { |
203 final InputStream mfStream = Viewer.class.getClassLoader() | |
204 .getResourceAsStream("META-INF/MANIFEST.MF"); | |
205 if (null == mfStream) { | |
206 System.out.println("No Manifest file found."); | |
207 return "-1"; | |
208 } | |
209 try { | |
210 Manifest mf = new Manifest(); | |
211 mf.read(mfStream); | |
212 Attributes atts = mf.getMainAttributes(); | |
213 return atts.getValue(Attributes.Name.IMPLEMENTATION_VERSION); | |
214 } catch (IOException e) { | |
215 return "-2"; | |
216 } | |
217 } | |
65 | 218 |
240 | 219 public void setSocket(Socket soc) { |
220 connectionParams.setConnectionParam(soc.getInetAddress().getHostAddress(), soc.getPort()); | |
221 } | |
65 | 222 |
240 | 223 public void setOpenPort(int parseInt) { |
224 } | |
65 | 225 |
328
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
327
diff
changeset
|
226 public void setTerminationType(boolean b) { |
240 | 227 myRfb.setTerminationType(b); |
228 } | |
65 | 229 |
379 | 230 public void startTreeViewer(String hostName, boolean cui, boolean addSerialNum) { |
240 | 231 CuiViewer viewer = new CuiViewer(); |
232 viewer.cuiVersion = cui; | |
327
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
317
diff
changeset
|
233 TreeRFBProto rfb = new TreeRFBProto(false, this); |
240 | 234 CreateConnectionParam cp = new CreateConnectionParam(rfb); |
300 | 235 if (hostName==null) { |
327
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
317
diff
changeset
|
236 cp.findTreeVncRoot(); |
240 | 237 } else { |
238 cp.setHostName(hostName); | |
239 } | |
240 rfb.createConnectionAndStart(this); | |
241 cp.sendWhereToConnect(viewer); | |
242 rfb.setCuiVersion(cui); | |
243 viewer.myRfb = rfb; | |
244 SwingUtilities.invokeLater(viewer); | |
245 } | |
65 | 246 |
240 | 247 public void setIsTreeVNC(boolean flag) { |
248 } | |
65 | 249 |
240 | 250 public TreeRFBProto getRfb() { |
251 return myRfb; | |
252 } | |
65 | 253 |
240 | 254 public boolean getCuiVersion() { |
255 return cuiVersion; | |
256 } | |
257 | |
258 public void setCuiVersion(boolean flag) { | |
259 // nop | |
260 } | |
130 | 261 |
262 @Override | |
174 | 263 public void connectToParenet(int port, String hostname) throws IOException { |
328
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
327
diff
changeset
|
264 setTerminationType(false); |
174 | 265 closeApp(); |
179 | 266 connectionParams.setConnectionParam(hostname, port); |
174 | 267 run(); |
268 } | |
269 | |
270 @Override | |
428
f6a828dd37b0
Change timing for setting share screen info
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
427
diff
changeset
|
271 public void inhelitClients(String hostName, short newVNCServerId, int x, int y, int width, int height, int scale) { |
240 | 272 |
174 | 273 } |
274 | |
275 @Override | |
455
6f3d3da40940
fix cui and hasViewer flag
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
448
diff
changeset
|
276 public void proxyStart(String[] args, String hostName, int width, int height, boolean showTree, boolean checkDelay, boolean addSerialNum, boolean fixingSize, boolean filterSingleDisplay, boolean hasViewer) { |
240 | 277 |
174 | 278 } |
279 | |
176 | 280 @Override |
281 public void setNoConnection(boolean noConnection) { | |
240 | 282 |
176 | 283 } |
284 | |
240 | 285 @Override |
286 public void setVisible(boolean b) { | |
287 } | |
192 | 288 |
240 | 289 @Override |
290 public Socket getVNCSocket() { | |
291 return connectionPresenter.getSocket(); | |
292 } | |
202 | 293 |
204
d9d234715853
TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
202
diff
changeset
|
294 @Override |
d9d234715853
TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
202
diff
changeset
|
295 public boolean getShowTree() { |
d9d234715853
TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
202
diff
changeset
|
296 return showTree; |
d9d234715853
TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
202
diff
changeset
|
297 } |
d9d234715853
TreeManager for each interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
202
diff
changeset
|
298 |
225 | 299 @Override |
300 public void setWidth(int w) { | |
240 | 301 width = w; |
225 | 302 } |
303 | |
304 @Override | |
305 public void setHeight(int h) { | |
300 | 306 height = h; |
257 | 307 } |
308 | |
309 @Override | |
310 public void setFixingSize(int width, int height) { | |
311 } | |
301 | 312 |
313 @Override | |
458 | 314 public java.util.ArrayList<FbRectangle> getScreenRectangles() { |
301 | 315 return null; |
316 } | |
317 | 317 |
318 @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
|
319 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
|
320 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
|
321 } |
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
|
322 |
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
|
323 @Override |
456
34277b436cac
Using retina scale to share screnn if minus postion
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
455
diff
changeset
|
324 public int retinaScale(int shareScreenNumber) { |
34277b436cac
Using retina scale to share screnn if minus postion
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
455
diff
changeset
|
325 return 1; |
34277b436cac
Using retina scale to share screnn if minus postion
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
455
diff
changeset
|
326 } |
34277b436cac
Using retina scale to share screnn if minus postion
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
455
diff
changeset
|
327 |
34277b436cac
Using retina scale to share screnn if minus postion
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
455
diff
changeset
|
328 @Override |
317 | 329 public void setFitScreen() { |
330 } | |
65 | 331 } |