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