選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

VncViewer.java 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. //
  19. // VncViewer - the VNC viewer applet. It can also be run from the
  20. // command-line, when it behaves as much as possibly like the windows and unix
  21. // viewers.
  22. //
  23. // Unfortunately, because of the way Java classes are loaded on demand, only
  24. // configuration parameters defined in this file can be set from the command
  25. // line or in applet parameters.
  26. package com.tigervnc.vncviewer;
  27. import java.awt.*;
  28. import java.awt.Color;
  29. import java.awt.Graphics;
  30. import java.awt.Image;
  31. import java.awt.image.*;
  32. import java.awt.Label;
  33. import java.io.InputStream;
  34. import java.util.jar.Attributes;
  35. import java.util.jar.Manifest;
  36. import javax.swing.*;
  37. import java.net.URL;
  38. import com.tigervnc.rdr.*;
  39. import com.tigervnc.rfb.*;
  40. import com.tigervnc.rfb.Exception;
  41. public class VncViewer extends java.applet.Applet implements Runnable
  42. {
  43. public static final String about1 = "TigerVNC Viewer for Java";
  44. public static final String about2 = "Copyright (C) 1998-2011 "+
  45. "TigerVNC Team and many others (see README)";
  46. public static final String about3 = "Visit http://www.tigervnc.org "+
  47. "for information on TigerVNC.";
  48. public static String version = null;
  49. public static String build = null;
  50. public static void main(String[] argv) {
  51. try {
  52. String os = System.getProperty("os.name");
  53. if (os.startsWith("Windows")) {
  54. String laf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
  55. UIManager.setLookAndFeel(laf);
  56. } else {
  57. UIManager.put("swing.boldMetal", Boolean.FALSE);
  58. javax.swing.plaf.FontUIResource f = new
  59. javax.swing.plaf.FontUIResource("SansSerif", Font.PLAIN, 11);
  60. java.util.Enumeration keys = UIManager.getDefaults().keys();
  61. while (keys.hasMoreElements()) {
  62. Object key = keys.nextElement();
  63. Object value = UIManager.get (key);
  64. if (value instanceof javax.swing.plaf.FontUIResource)
  65. UIManager.put(key, f);
  66. }
  67. }
  68. UIManager.put("TitledBorder.titleColor",Color.blue);
  69. } catch (java.lang.Exception exc) { }
  70. VncViewer viewer = new VncViewer(argv);
  71. viewer.start();
  72. }
  73. public VncViewer(String[] argv) {
  74. applet = false;
  75. // Override defaults with command-line options
  76. for (int i = 0; i < argv.length; i++) {
  77. if (argv[i].equalsIgnoreCase("-log")) {
  78. if (++i >= argv.length) usage();
  79. System.err.println("Log setting: "+argv[i]);
  80. LogWriter.setLogParams(argv[i]);
  81. continue;
  82. }
  83. if (Configuration.setParam(argv[i]))
  84. continue;
  85. if (argv[i].charAt(0) == '-') {
  86. if (i+1 < argv.length) {
  87. if (Configuration.setParam(argv[i].substring(1), argv[i+1])) {
  88. i++;
  89. continue;
  90. }
  91. }
  92. usage();
  93. }
  94. if (vncServerName.getValue() != null)
  95. usage();
  96. vncServerName.setParam(argv[i]);
  97. }
  98. }
  99. public static void usage() {
  100. String usage = ("\nusage: vncviewer [options/parameters] "+
  101. "[host:displayNum] [options/parameters]\n"+
  102. //" vncviewer [options/parameters] -listen [port] "+
  103. //"[options/parameters]\n"+
  104. "\n"+
  105. "Options:\n"+
  106. " -log <level> configure logging level\n"+
  107. "\n"+
  108. "Parameters can be turned on with -<param> or off with "+
  109. "-<param>=0\n"+
  110. "Parameters which take a value can be specified as "+
  111. "-<param> <value>\n"+
  112. "Other valid forms are <param>=<value> -<param>=<value> "+
  113. "--<param>=<value>\n"+
  114. "Parameter names are case-insensitive. The parameters "+
  115. "are:\n\n"+
  116. Configuration.listParams());
  117. System.err.print(usage);
  118. System.exit(1);
  119. }
  120. public VncViewer() {
  121. applet = true;
  122. firstApplet = true;
  123. }
  124. public static void newViewer(VncViewer oldViewer) {
  125. VncViewer viewer = new VncViewer();
  126. viewer.applet = oldViewer.applet;
  127. viewer.firstApplet = false;
  128. viewer.start();
  129. }
  130. public void init() {
  131. vlog.debug("init called");
  132. setBackground(Color.white);
  133. ClassLoader cl = this.getClass().getClassLoader();
  134. ImageIcon icon = new ImageIcon(cl.getResource("com/tigervnc/vncviewer/tigervnc.png"));
  135. logo = icon.getImage();
  136. }
  137. public void start() {
  138. vlog.debug("start called");
  139. if (version == null || build == null) {
  140. ClassLoader cl = this.getClass().getClassLoader();
  141. InputStream stream = cl.getResourceAsStream("com/tigervnc/vncviewer/timestamp");
  142. try {
  143. Manifest manifest = new Manifest(stream);
  144. Attributes attributes = manifest.getMainAttributes();
  145. version = attributes.getValue("Version");
  146. build = attributes.getValue("Build");
  147. } catch (java.io.IOException e) { }
  148. }
  149. nViewers++;
  150. if (firstApplet) {
  151. alwaysShowServerDialog.setParam(true);
  152. Configuration.readAppletParams(this);
  153. String host = getCodeBase().getHost();
  154. if (vncServerName.getValue() == null && vncServerPort.getValue() != 0) {
  155. int port = vncServerPort.getValue();
  156. vncServerName.setParam(host + ((port >= 5900 && port <= 5999)
  157. ? (":"+(port-5900))
  158. : ("::"+port)));
  159. }
  160. }
  161. thread = new Thread(this);
  162. thread.start();
  163. }
  164. public void paint(Graphics g) {
  165. g.drawImage(logo, 0, 0, this);
  166. int h = logo.getHeight(this)+20;
  167. g.drawString(about1+" v"+version+" ("+build+")", 0, h);
  168. h += g.getFontMetrics().getHeight();
  169. g.drawString(about2, 0, h);
  170. h += g.getFontMetrics().getHeight();
  171. g.drawString(about3, 0, h);
  172. }
  173. public void run() {
  174. CConn cc = null;
  175. try {
  176. cc = new CConn(this, null, vncServerName.getValue(), false);
  177. while (true)
  178. cc.processMsg();
  179. } catch (EndOfStream e) {
  180. vlog.info(e.toString());
  181. } catch (java.lang.Exception e) {
  182. if (cc != null) cc.deleteWindow();
  183. if (cc == null || !cc.shuttingDown) {
  184. e.printStackTrace();
  185. JOptionPane.showMessageDialog(null,
  186. e.toString(),
  187. "VNC Viewer : Error",
  188. JOptionPane.ERROR_MESSAGE);
  189. }
  190. }
  191. if (cc != null) cc.deleteWindow();
  192. nViewers--;
  193. if (!applet && nViewers == 0) {
  194. System.exit(0);
  195. }
  196. }
  197. BoolParameter fastCopyRect
  198. = new BoolParameter("FastCopyRect",
  199. "Use fast CopyRect - turn this off if you get "+
  200. "screen corruption when copying from off-screen",
  201. true);
  202. BoolParameter useLocalCursor
  203. = new BoolParameter("UseLocalCursor",
  204. "Render the mouse cursor locally", true);
  205. BoolParameter sendLocalUsername
  206. = new BoolParameter("SendLocalUsername",
  207. "Send the local username for SecurityTypes "+
  208. "such as Plain rather than prompting", true);
  209. BoolParameter autoSelect
  210. = new BoolParameter("AutoSelect",
  211. "Auto select pixel format and encoding", true);
  212. BoolParameter fullColour
  213. = new BoolParameter("FullColour",
  214. "Use full colour - otherwise 6-bit colour is used "+
  215. "until AutoSelect decides the link is fast enough",
  216. true);
  217. AliasParameter fullColor
  218. = new AliasParameter("FullColor", "Alias for FullColour", fullColour);
  219. StringParameter preferredEncoding
  220. = new StringParameter("PreferredEncoding",
  221. "Preferred encoding to use (Tight, ZRLE, hextile or"+
  222. " raw) - implies AutoSelect=0", "Tight");
  223. BoolParameter viewOnly
  224. = new BoolParameter("ViewOnly", "Don't send any mouse or keyboard "+
  225. "events to the server", false);
  226. BoolParameter shared
  227. = new BoolParameter("Shared", "Don't disconnect other viewers upon "+
  228. "connection - share the desktop instead", false);
  229. BoolParameter fullScreen
  230. = new BoolParameter("FullScreen", "Full Screen Mode", false);
  231. BoolParameter acceptClipboard
  232. = new BoolParameter("AcceptClipboard",
  233. "Accept clipboard changes from the server", true);
  234. BoolParameter sendClipboard
  235. = new BoolParameter("SendClipboard",
  236. "Send clipboard changes to the server", true);
  237. StringParameter desktopSize
  238. = new StringParameter("DesktopSize",
  239. "Reconfigure desktop size on the server on "+
  240. "connect (if possible)", "");
  241. StringParameter scalingFactor
  242. = new StringParameter("ScalingFactor",
  243. "Reduce or enlarge the remote desktop image. "+
  244. "The value is interpreted as a scaling factor "+
  245. "in percent. If the parameter is set to "+
  246. "\"Auto\", then automatic scaling is "+
  247. "performed. Auto-scaling tries to choose a "+
  248. "scaling factor in such a way that the whole "+
  249. "remote desktop will fit on the local screen. "+
  250. "If the parameter is set to \"FixedRatio\", "+
  251. "then automatic scaling is performed, but the "+
  252. "original aspect ratio is preserved.", "100");
  253. BoolParameter alwaysShowServerDialog
  254. = new BoolParameter("AlwaysShowServerDialog",
  255. "Always show the server dialog even if a server "+
  256. "has been specified in an applet parameter or on "+
  257. "the command line", false);
  258. StringParameter vncServerName
  259. = new StringParameter("Server",
  260. "The VNC server <host>[:<dpyNum>] or "+
  261. "<host>::<port>", null);
  262. IntParameter vncServerPort
  263. = new IntParameter("Port",
  264. "The VNC server's port number, assuming it is on "+
  265. "the host from which the applet was downloaded", 0);
  266. BoolParameter acceptBell
  267. = new BoolParameter("AcceptBell",
  268. "Produce a system beep when requested to by the server.",
  269. true);
  270. BoolParameter customCompressLevel
  271. = new BoolParameter("CustomCompressLevel",
  272. "Use custom compression level. "+
  273. "Default if CompressLevel is specified.", false);
  274. IntParameter compressLevel
  275. = new IntParameter("CompressLevel",
  276. "Use specified compression level "+
  277. "0 = Low, 6 = High",
  278. 1);
  279. BoolParameter noJpeg
  280. = new BoolParameter("NoJPEG",
  281. "Disable lossy JPEG compression in Tight encoding.", false);
  282. IntParameter qualityLevel
  283. = new IntParameter("QualityLevel",
  284. "JPEG quality level. "+
  285. "0 = Low, 9 = High",
  286. 8);
  287. Thread thread;
  288. boolean applet, firstApplet;
  289. Image logo;
  290. static int nViewers;
  291. static LogWriter vlog = new LogWriter("main");
  292. }