Mercurial > hg > Applications > TightVNC_orginal
annotate src/main/java/ac/ryukyu/treevnc/client/MyVncClient.java @ 2:dca3bd61b830
before change MyVncClient.java
author | Yu Taninari <you@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 09 Jul 2012 18:47:33 +0900 |
parents | 75b54fd9e73a |
children | e7ce2b2ffed8 |
rev | line source |
---|---|
1 | 1 package ac.ryukyu.treevnc.client; |
2 | |
3 import java.awt.Image; | |
4 import java.awt.Insets; | |
5 import java.awt.event.WindowEvent; | |
6 import java.awt.event.WindowListener; | |
7 import java.io.IOException; | |
8 import java.net.Socket; | |
9 import java.util.logging.Logger; | |
10 | |
11 import javax.swing.SwingUtilities; | |
12 | |
13 import com.glavsoft.exceptions.AuthenticationFailedException; | |
14 import com.glavsoft.exceptions.FatalException; | |
15 import com.glavsoft.exceptions.TransportException; | |
16 import com.glavsoft.exceptions.UnsupportedProtocolVersionException; | |
17 import com.glavsoft.exceptions.UnsupportedSecurityTypeException; | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
18 import com.glavsoft.rfb.IChangeSettingsListener; |
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
19 import com.glavsoft.rfb.IRfbSessionListener; |
1 | 20 import com.glavsoft.rfb.protocol.Protocol; |
21 import com.glavsoft.rfb.protocol.ProtocolSettings; | |
22 import com.glavsoft.transport.Reader; | |
23 import com.glavsoft.transport.Writer; | |
24 import com.glavsoft.viewer.ConnectionManager; | |
25 import com.glavsoft.viewer.Viewer; | |
26 import com.glavsoft.viewer.Viewer.PasswordChooser; | |
27 import com.glavsoft.viewer.cli.Parser; | |
28 import com.glavsoft.viewer.swing.ClipboardControllerImpl; | |
29 import com.glavsoft.viewer.swing.ParametersHandler; | |
30 import com.glavsoft.viewer.swing.Surface; | |
31 import com.glavsoft.viewer.swing.UiSettings; | |
32 import com.glavsoft.viewer.swing.ParametersHandler.ConnectionParams; | |
33 | |
34 import ac.ryukyu.treevnc.InterfaceForViewer; | |
35 | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
36 public class MyVncClient extends Viewer implements Runnable, |
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
37 IRfbSessionListener, WindowListener, IChangeSettingsListener { |
1 | 38 |
39 /** | |
40 * | |
41 */ | |
42 private static final long serialVersionUID = 1L; | |
43 private boolean inAnApplet = true; | |
44 private boolean inSeparateFrame = false; | |
45 private Socket clientSocket = null; | |
46 private String parent, treenum; | |
47 private String leaderflag; | |
48 // private boolean runflag = false; | |
49 private boolean first = true; | |
50 | |
51 private EchoClient echoValue; | |
52 private int echoPort; | |
53 private String pHost; | |
54 private TextBoxClient getHost; | |
55 private GetDataClient getBcast; | |
56 private Thread runBcast; | |
57 private GetHostClient bCast; | |
58 boolean isClient = false; | |
59 public static final int DEFAULT_PORT = 5900; | |
60 public static Logger logger = Logger.getLogger("com.glavsoft"); | |
61 private static final Insets BUTTONS_MARGIN = new Insets(2, 2, 2, 2); | |
62 private boolean isZoomToFitSelected; | |
63 private boolean forceReconnection; | |
64 private String reconnectionReason; | |
65 private ConnectionParams connectionParams; | |
66 private final ProtocolSettings settings; | |
67 private final UiSettings uiSettings; | |
68 | |
69 | |
70 public MyVncClient() { | |
71 connectionParams = new ParametersHandler.ConnectionParams(); | |
72 settings = ProtocolSettings.getDefaultSettings(); | |
73 uiSettings = new UiSettings(); | |
74 } | |
75 | |
76 public MyVncClient(Parser parser) { | |
77 this(); | |
78 ParametersHandler.completeSettingsFromCLI(parser, connectionParams, settings, uiSettings); | |
79 showControls = ParametersHandler.showControls; | |
80 passwordFromParams = parser.getValueFor(ParametersHandler.ARG_PASSWORD); | |
81 logger.info("TightVNC Viewer version " + ver()); | |
82 isApplet = false; | |
83 } | |
84 | |
85 public void treeVncClient(String[] argv) { | |
86 MyVncClient v = new MyVncClient(); | |
87 //v.runClient(argv); | |
88 } | |
89 | |
90 // private void runClient(String[] argv) { | |
91 public static void main(String[] argv) { | |
92 String[] mainArgs = argv; | |
93 System.out.println(mainArgs.length); | |
94 // input into arguments Decision | |
95 if (mainArgs.length != 0) { | |
96 for (int i = 0; i < argv.length; i++) { | |
97 if ("-c".equals(argv[i])) { | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
98 // write later |
1 | 99 } |
100 } | |
101 } else { | |
102 //getHostData(); | |
103 } | |
104 Parser parser = new Parser(); | |
105 ParametersHandler.completeParserOptions(parser); | |
106 | |
107 parser.parse(argv); | |
108 if (parser.isSet(ParametersHandler.ARG_HELP)) { | |
109 printUsage(parser.optionsUsage()); | |
110 System.exit(0); | |
111 } | |
112 MyVncClient myClient = new MyVncClient(parser); | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
113 //SwingUtilities.invokeLater(myClient); |
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
114 Thread th = new Thread(myClient); |
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
115 th.start(); |
1 | 116 } |
117 | |
118 private void getHostData() { | |
119 bCast = new GetHostClient("who"); | |
120 bCast.createSocket(); | |
121 bCast.sendData(); | |
122 getBcast = new GetDataClient(); | |
123 runBcast = new Thread(getBcast); | |
124 runBcast.start(); | |
125 getBcast.setStopFlag(true); | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
126 connectionParams.hostName = getBcast.textAddress(); |
1 | 127 if("notFound".equals(pHost)) { |
128 getHost = new TextBoxClient(); | |
129 getHost.ipRegister(); | |
130 connectionParams.hostName = getHost.getAddressOption(); | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
131 //connectionParams.portNumber = Integer.parseInt(getHost.getPortOption()); |
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
132 connectionParams.portNumber = 5900; |
1 | 133 } else { |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
134 //connectionParams.portNumber = Integer.parseInt(getBcast.textPort()); |
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
135 connectionParams.portNumber = 5900; |
1 | 136 } |
137 } | |
138 | |
139 @Override | |
140 public void run() { | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
141 // getHostData(); |
1 | 142 ConnectionManager connectionManager = new ConnectionManager(this, isApplet); |
143 if (forceReconnection) { | |
144 connectionManager.showReconnectDialog("Connection lost", reconnectionReason); | |
145 forceReconnection = false; | |
146 } | |
147 tryAgain = true; | |
148 while (tryAgain) { | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
149 // workingSocket = connectionManager.connectToTreeHost(connectionParams, settings); |
1 | 150 workingSocket = connectionManager.connectToHost(connectionParams, settings); |
151 if (null == workingSocket) { | |
152 closeApp(); | |
153 break; | |
154 } | |
155 logger.info("Connected"); | |
156 | |
157 try { | |
158 workingSocket.setTcpNoDelay(true); // disable Nagle algorithm | |
159 Reader reader = new Reader(workingSocket.getInputStream()); | |
160 Writer writer = new Writer(workingSocket.getOutputStream()); | |
161 | |
162 workingProtocol = new Protocol(reader, writer, | |
163 new PasswordChooser(passwordFromParams, connectionParams, containerFrame, this), | |
164 settings); | |
165 workingProtocol.handshake(); | |
166 | |
167 ClipboardControllerImpl clipboardController = | |
168 new ClipboardControllerImpl(workingProtocol, settings.getRemoteCharsetName()); | |
169 clipboardController.setEnabled(settings.isAllowClipboardTransfer()); | |
170 settings.addListener(clipboardController); | |
171 | |
172 surface = new Surface(workingProtocol, this, uiSettings.getScaleFactor()); | |
173 settings.addListener(this); | |
174 uiSettings.addListener(surface); | |
175 containerFrame = createContainer(); | |
176 connectionManager.setContainerFrame(containerFrame); | |
177 updateFrameTitle(); | |
178 | |
179 workingProtocol.startNormalHandling(this, surface, clipboardController); | |
180 tryAgain = false; | |
181 } catch (UnsupportedProtocolVersionException e) { | |
182 connectionManager.showReconnectDialog("Unsupported Protocol Version", e.getMessage()); | |
183 logger.severe(e.getMessage()); | |
184 } catch (UnsupportedSecurityTypeException e) { | |
185 connectionManager.showReconnectDialog("Unsupported Security Type", e.getMessage()); | |
186 logger.severe(e.getMessage()); | |
187 } catch (AuthenticationFailedException e) { | |
188 passwordFromParams = null; | |
189 connectionManager.showReconnectDialog("Authentication Failed", e.getMessage()); | |
190 logger.severe(e.getMessage()); | |
191 } catch (TransportException e) { | |
192 connectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage()); | |
193 logger.severe(e.getMessage()); | |
194 } catch (IOException e) { | |
195 connectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage()); | |
196 logger.severe(e.getMessage()); | |
197 } catch (FatalException e) { | |
198 connectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage()); | |
199 logger.severe(e.getMessage()); | |
200 } | |
201 } | |
202 | |
203 } | |
204 | |
205 | |
206 | |
207 | |
208 | |
209 @Override | |
210 public void destroy() { | |
211 // TODO Auto-generated method stub | |
212 | |
213 } | |
214 | |
215 @Override | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
216 public void windowClosing(WindowEvent e) { |
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
217 if (e != null && e.getComponent() != null) { |
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
218 e.getWindow().setVisible(false); |
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
219 } |
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
220 closeApp(); |
1 | 221 } |
222 | |
223 @Override | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
224 public void windowActivated(WindowEvent e) { /*nop*/ } |
1 | 225 |
226 @Override | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
227 public void windowClosed(WindowEvent e) { /*nop*/ } |
1 | 228 |
229 @Override | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
230 public void windowDeactivated(WindowEvent e) { /*nop*/ } |
1 | 231 |
232 @Override | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
233 public void windowDeiconified(WindowEvent e) { /*nop*/ } |
1 | 234 |
235 @Override | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
236 public void windowIconified(WindowEvent e) { /*nop*/ } |
1 | 237 |
238 @Override | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
239 public void windowOpened(WindowEvent e) { /*nop*/ } |
1 | 240 |
241 } |