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