Mercurial > hg > Applications > tvnjviewer
annotate src/viewer_swing/java/com/glavsoft/viewer/Viewer.java @ 31:59cdd271f79c
change compressed DSM only pixel data
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 16 Nov 2015 23:02:29 +0900 |
parents | e2de671a155d |
children |
rev | line source |
---|---|
0 | 1 // Copyright (C) 2010, 2011, 2012, 2013 GlavSoft LLC. |
2 // All rights reserved. | |
3 // | |
4 //------------------------------------------------------------------------- | |
5 // This file is part of the TightVNC software. Please visit our Web site: | |
6 // | |
7 // http://www.tightvnc.com/ | |
8 // | |
9 // This program is free software; you can redistribute it and/or modify | |
10 // it under the terms of the GNU General Public License as published by | |
11 // the Free Software Foundation; either version 2 of the License, or | |
12 // (at your option) any later version. | |
13 // | |
14 // This program is distributed in the hope that it will be useful, | |
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 // GNU General Public License for more details. | |
18 // | |
19 // You should have received a copy of the GNU General Public License along | |
20 // with this program; if not, write to the Free Software Foundation, Inc., | |
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
22 //------------------------------------------------------------------------- | |
23 // | |
24 | |
25 package com.glavsoft.viewer; | |
26 | |
24 | 27 import alice.datasegment.DataSegment; |
28 import alice.datasegment.ReceiveData; | |
29 | |
0 | 30 import com.glavsoft.rfb.protocol.ProtocolSettings; |
31 import com.glavsoft.viewer.cli.Parser; | |
32 import com.glavsoft.viewer.mvp.View; | |
33 import com.glavsoft.viewer.swing.ConnectionParams; | |
34 import com.glavsoft.viewer.swing.ParametersHandler; | |
35 import com.glavsoft.viewer.swing.SwingConnectionWorkerFactory; | |
36 import com.glavsoft.viewer.swing.SwingViewerWindowFactory; | |
37 import com.glavsoft.viewer.swing.gui.ConnectionView; | |
38 | |
39 import javax.swing.*; | |
24 | 40 |
0 | 41 import java.awt.*; |
42 import java.awt.event.WindowEvent; | |
43 import java.awt.event.WindowListener; | |
44 import java.io.IOException; | |
45 import java.io.InputStream; | |
46 import java.util.jar.Attributes; | |
47 import java.util.jar.Manifest; | |
48 import java.util.logging.*; | |
49 | |
50 @SuppressWarnings("serial") | |
51 public class Viewer extends JApplet implements Runnable, WindowListener { | |
52 | |
53 private Logger logger; | |
54 private int paramsMask; | |
55 private boolean allowAppletInteractiveConnections; | |
56 | |
57 private final ConnectionParams connectionParams; | |
58 private String passwordFromParams; | |
59 boolean isSeparateFrame = true; | |
60 boolean isApplet = true; | |
61 private final ProtocolSettings settings; | |
62 private final UiSettings uiSettings; | |
63 private volatile boolean isAppletStopped = false; | |
64 private ConnectionPresenter connectionPresenter; | |
25 | 65 private boolean needReconnect = true; |
27 | 66 public boolean hideJFrame = false; |
0 | 67 |
68 public static void main(String[] args) { | |
69 Parser parser = new Parser(); | |
70 ParametersHandler.completeParserOptions(parser); | |
71 | |
72 parser.parse(args); | |
73 if (parser.isSet(ParametersHandler.ARG_HELP)) { | |
74 printUsage(parser.optionsUsage()); | |
75 System.exit(0); | |
76 } | |
77 Viewer viewer = new Viewer(parser); | |
78 SwingUtilities.invokeLater(viewer); | |
79 } | |
80 | |
81 public static void printUsage(String additional) { | |
82 System.out.println("Usage: java -jar (progfilename) [hostname [port_number]] [Options]\n" + | |
83 " or\n"+ | |
84 " java -jar (progfilename) [Options]\n" + | |
85 " or\n java -jar (progfilename) -help\n to view this help\n\n" + | |
86 "Where Options are:\n" + additional + | |
87 "\nOptions format: -optionName=optionValue. Ex. -host=localhost -port=5900 -viewonly=yes\n" + | |
88 "Both option name and option value are case insensitive."); | |
89 } | |
90 | |
91 public Viewer() { | |
92 logger = Logger.getLogger(getClass().getName()); | |
93 connectionParams = new ConnectionParams(); | |
94 settings = ProtocolSettings.getDefaultSettings(); | |
95 uiSettings = new UiSettings(); | |
96 } | |
97 | |
2
960c7717ad0d
add getUisetting method and change constructor type public
YU
parents:
0
diff
changeset
|
98 public Viewer(Parser parser) { |
0 | 99 this(); |
100 setLoggingLevel(parser.isSet(ParametersHandler.ARG_VERBOSE) ? Level.FINE : | |
101 parser.isSet(ParametersHandler.ARG_VERBOSE_MORE) ? Level.FINER : | |
102 Level.INFO); | |
24 | 103 |
0 | 104 paramsMask = ParametersHandler.completeSettingsFromCLI(parser, connectionParams, settings, uiSettings); |
105 passwordFromParams = parser.getValueFor(ParametersHandler.ARG_PASSWORD); | |
106 logger.info("TightVNC Viewer version " + ver()); | |
107 isApplet = false; | |
24 | 108 |
21
966878ff1227
not appear NEW TightVNC Connection window if first argument equal "localhost"
sugi
parents:
2
diff
changeset
|
109 if (parser.isSetPlainOptions()) { |
966878ff1227
not appear NEW TightVNC Connection window if first argument equal "localhost"
sugi
parents:
2
diff
changeset
|
110 if ("localhost".equals(parser.getPlainOptionAt(0))) { |
966878ff1227
not appear NEW TightVNC Connection window if first argument equal "localhost"
sugi
parents:
2
diff
changeset
|
111 connectionParams.hostName = "localhost"; |
966878ff1227
not appear NEW TightVNC Connection window if first argument equal "localhost"
sugi
parents:
2
diff
changeset
|
112 isApplet = true; |
31
59cdd271f79c
change compressed DSM only pixel data
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
28
diff
changeset
|
113 ReceiveData rData = new ReceiveData(this); |
59cdd271f79c
change compressed DSM only pixel data
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
28
diff
changeset
|
114 DataSegment.getLocal().put("viewer", rData, false); |
25 | 115 this.needReconnect = false; |
27 | 116 this.hideJFrame = true; |
21
966878ff1227
not appear NEW TightVNC Connection window if first argument equal "localhost"
sugi
parents:
2
diff
changeset
|
117 }; |
966878ff1227
not appear NEW TightVNC Connection window if first argument equal "localhost"
sugi
parents:
2
diff
changeset
|
118 } |
0 | 119 } |
120 | |
121 private void setLoggingLevel(Level levelToSet) { | |
122 final Logger appLogger = Logger.getLogger("com.glavsoft"); | |
123 appLogger.setLevel(levelToSet); | |
124 ConsoleHandler ch = null; | |
125 for (Handler h : appLogger.getHandlers()) { | |
126 if (h instanceof ConsoleHandler) { | |
127 ch = (ConsoleHandler) h; | |
128 break; | |
129 } | |
130 } | |
131 if (null == ch) { | |
132 ch = new ConsoleHandler(); | |
133 appLogger.addHandler(ch); | |
134 } | |
135 // ch.setFormatter(new SimpleFormatter()); | |
136 ch.setLevel(levelToSet); | |
137 } | |
138 | |
139 | |
140 @Override | |
141 public void windowClosing(WindowEvent e) { | |
142 if (e != null && e.getComponent() != null) { | |
143 final Window w = e.getWindow(); | |
144 if (w != null) { | |
145 w.setVisible(false); | |
146 w.dispose(); | |
147 } | |
148 } | |
149 closeApp(); | |
150 } | |
151 | |
152 /** | |
153 * Closes App(lication) or stops App(let). | |
154 */ | |
155 public void closeApp() { | |
156 if (connectionPresenter != null) { | |
157 connectionPresenter.cancelConnection(); | |
158 logger.info("Connections cancelled."); | |
159 } | |
160 if (isApplet) { | |
161 if ( ! isAppletStopped) { | |
162 logger.severe("Applet is stopped."); | |
163 isAppletStopped = true; | |
164 repaint(); | |
165 stop(); | |
166 } | |
167 } else { | |
168 System.exit(0); | |
169 } | |
170 } | |
171 | |
172 @Override | |
173 public void paint(Graphics g) { | |
174 if ( ! isAppletStopped) { | |
175 super.paint(g); | |
176 } else { | |
177 getContentPane().removeAll(); | |
178 g.clearRect(0, 0, getWidth(), getHeight()); | |
179 g.drawString("Disconnected", 10, 20); | |
180 } | |
181 } | |
182 | |
183 @Override | |
184 public void destroy() { | |
185 closeApp(); | |
186 super.destroy(); | |
187 } | |
188 | |
189 @Override | |
190 public void init() { | |
191 paramsMask = ParametersHandler.completeSettingsFromApplet(this, connectionParams, settings, uiSettings); | |
192 isSeparateFrame = ParametersHandler.isSeparateFrame; | |
193 passwordFromParams = getParameter(ParametersHandler.ARG_PASSWORD); | |
194 isApplet = true; | |
195 allowAppletInteractiveConnections = ParametersHandler.allowAppletInteractiveConnections; | |
196 repaint(); | |
197 | |
198 try { | |
199 SwingUtilities.invokeAndWait(this); | |
200 } catch (Exception e) { | |
201 logger.severe(e.getMessage()); | |
202 } | |
203 } | |
204 | |
205 @Override | |
206 public void start() { | |
207 super.start(); | |
208 } | |
209 | |
210 private boolean checkJsch() { | |
211 try { | |
212 Class.forName("com.jcraft.jsch.JSch"); | |
213 return true; | |
214 } catch (ClassNotFoundException e) { | |
215 return false; | |
216 } | |
217 } | |
218 | |
219 @Override | |
220 public void run() { | |
221 | |
222 final boolean hasJsch = checkJsch(); | |
223 final boolean allowInteractive = allowAppletInteractiveConnections || ! isApplet; | |
224 connectionPresenter = new ConnectionPresenter(hasJsch, allowInteractive); | |
225 connectionPresenter.addModel("ConnectionParamsModel", connectionParams); | |
226 final ConnectionView connectionView = new ConnectionView( | |
227 Viewer.this, // appWindowListener | |
228 connectionPresenter, hasJsch); | |
229 connectionPresenter.addView(ConnectionPresenter.CONNECTION_VIEW, connectionView); | |
230 if (isApplet) { | |
231 connectionPresenter.addView("AppletStatusStringView", new View() { | |
232 @Override | |
233 public void showView() { /*nop*/ } | |
234 @Override | |
235 public void closeView() { /*nop*/ } | |
236 }); | |
237 } | |
25 | 238 if (!needReconnect) { |
239 connectionPresenter.setNeedReconnection(false); | |
240 } | |
0 | 241 |
242 SwingViewerWindowFactory viewerWindowFactory = new SwingViewerWindowFactory(isSeparateFrame, isApplet, this); | |
243 connectionPresenter.setConnectionWorkerFactory( | |
244 new SwingConnectionWorkerFactory(connectionView.getFrame(), passwordFromParams, connectionPresenter, viewerWindowFactory)); | |
245 connectionPresenter.startConnection(settings, uiSettings, paramsMask); | |
246 } | |
247 | |
248 @Override | |
249 public void windowOpened(WindowEvent e) { /* nop */ } | |
250 @Override | |
251 public void windowClosed(WindowEvent e) { /* nop */ } | |
252 @Override | |
253 public void windowIconified(WindowEvent e) { /* nop */ } | |
254 @Override | |
255 public void windowDeiconified(WindowEvent e) { /* nop */ } | |
256 @Override | |
257 public void windowActivated(WindowEvent e) { /* nop */ } | |
258 @Override | |
259 public void windowDeactivated(WindowEvent e) { /* nop */ } | |
260 | |
261 public static String ver() { | |
262 final InputStream mfStream = Viewer.class.getClassLoader().getResourceAsStream( | |
263 "META-INF/MANIFEST.MF"); | |
264 if (null == mfStream) { | |
265 System.out.println("No Manifest file found."); | |
266 return "-1"; | |
267 } | |
268 try { | |
269 Manifest mf = new Manifest(); | |
270 mf.read(mfStream); | |
271 Attributes atts = mf.getMainAttributes(); | |
272 return atts.getValue(Attributes.Name.IMPLEMENTATION_VERSION); | |
273 } catch (IOException e) { | |
274 return "-2"; | |
275 } | |
276 } | |
277 | |
2
960c7717ad0d
add getUisetting method and change constructor type public
YU
parents:
0
diff
changeset
|
278 // add |
960c7717ad0d
add getUisetting method and change constructor type public
YU
parents:
0
diff
changeset
|
279 public UiSettings getUiSettings() { |
960c7717ad0d
add getUisetting method and change constructor type public
YU
parents:
0
diff
changeset
|
280 return uiSettings; |
960c7717ad0d
add getUisetting method and change constructor type public
YU
parents:
0
diff
changeset
|
281 } |
960c7717ad0d
add getUisetting method and change constructor type public
YU
parents:
0
diff
changeset
|
282 |
0 | 283 } |