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