⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vncviewer.java

📁 JAVA版vpn客户端,是在web上实现远程访问的最佳方式.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      } else if (kbitsPerSecond < 1000 &&                 encodingsSaved[0] != RfbProto.EncodingTight) {        // Switch to Tight/ZRLE if the connection speed is below 1Mbps.        System.out.println("Throughput " + kbitsPerSecond +                           " kbit/s - changing to Tight/ZRLE encodings");        preferredEncoding = RfbProto.EncodingTight;      } else {        // Don't change the encoder.        if (autoSelectOnly)          return;        preferredEncoding = encodingsSaved[0];      }    } else {      // Auto encoder selection is not enabled.      if (autoSelectOnly)        return;    }    int[] encodings = new int[20];    int nEncodings = 0;    encodings[nEncodings++] = preferredEncoding;    if (options.useCopyRect) {      encodings[nEncodings++] = RfbProto.EncodingCopyRect;    }    if (preferredEncoding != RfbProto.EncodingTight) {      encodings[nEncodings++] = RfbProto.EncodingTight;    }    if (preferredEncoding != RfbProto.EncodingZRLE) {      encodings[nEncodings++] = RfbProto.EncodingZRLE;    }    if (preferredEncoding != RfbProto.EncodingHextile) {      encodings[nEncodings++] = RfbProto.EncodingHextile;    }    if (preferredEncoding != RfbProto.EncodingZlib) {      encodings[nEncodings++] = RfbProto.EncodingZlib;    }    if (preferredEncoding != RfbProto.EncodingCoRRE) {      encodings[nEncodings++] = RfbProto.EncodingCoRRE;    }    if (preferredEncoding != RfbProto.EncodingRRE) {      encodings[nEncodings++] = RfbProto.EncodingRRE;    }    if (options.compressLevel >= 0 && options.compressLevel <= 9) {      encodings[nEncodings++] =        RfbProto.EncodingCompressLevel0 + options.compressLevel;    }    if (options.jpegQuality >= 0 && options.jpegQuality <= 9) {      encodings[nEncodings++] =        RfbProto.EncodingQualityLevel0 + options.jpegQuality;    }    if (options.requestCursorUpdates) {      encodings[nEncodings++] = RfbProto.EncodingXCursor;      encodings[nEncodings++] = RfbProto.EncodingRichCursor;      if (!options.ignoreCursorUpdates)	encodings[nEncodings++] = RfbProto.EncodingPointerPos;    }    encodings[nEncodings++] = RfbProto.EncodingLastRect;    encodings[nEncodings++] = RfbProto.EncodingNewFBSize;    boolean encodingsWereChanged = false;    if (nEncodings != nEncodingsSaved) {      encodingsWereChanged = true;    } else {      for (int i = 0; i < nEncodings; i++) {        if (encodings[i] != encodingsSaved[i]) {          encodingsWereChanged = true;          break;        }      }    }    if (encodingsWereChanged) {      try {        rfb.writeSetEncodings(encodings, nEncodings);        if (vc != null) {          vc.softCursorFree();        }      } catch (Exception e) {        e.printStackTrace();      }      encodingsSaved = encodings;      nEncodingsSaved = nEncodings;    }  }  //  // setCutText() - send the given cut text to the RFB server.  //  void setCutText(String text) {    try {      if (rfb != null && rfb.inNormalProtocol) {	rfb.writeClientCutText(text);      }    } catch (Exception e) {      e.printStackTrace();    }  }  //  // Order change in session recording status. To stop recording, pass  // null in place of the fname argument.  //  void setRecordingStatus(String fname) {    synchronized(recordingSync) {      sessionFileName = fname;      recordingStatusChanged = true;    }  }  //  // Start or stop session recording. Returns true if this method call  // causes recording of a new session.  //  boolean checkRecordingStatus() throws IOException {    synchronized(recordingSync) {      if (recordingStatusChanged) {	recordingStatusChanged = false;	if (sessionFileName != null) {	  startRecording();	  return true;	} else {	  stopRecording();	}      }    }    return false;  }  //  // Start session recording.  //  protected void startRecording() throws IOException {    synchronized(recordingSync) {      if (!recordingActive) {	// Save settings to restore them after recording the session.	cursorUpdatesDef =	  options.choices[options.cursorUpdatesIndex].getSelectedItem();	eightBitColorsDef =	  options.choices[options.eightBitColorsIndex].getSelectedItem();	// Set options to values suitable for recording.	options.choices[options.cursorUpdatesIndex].select("Disable");	options.choices[options.cursorUpdatesIndex].setEnabled(false);	options.setEncodings();	options.choices[options.eightBitColorsIndex].select("No");	options.choices[options.eightBitColorsIndex].setEnabled(false);	options.setColorFormat();      } else {	rfb.closeSession();      }      System.out.println("Recording the session in " + sessionFileName);      rfb.startSession(sessionFileName);      recordingActive = true;    }  }  //  // Stop session recording.  //  protected void stopRecording() throws IOException {    synchronized(recordingSync) {      if (recordingActive) {	// Restore options.	options.choices[options.cursorUpdatesIndex].select(cursorUpdatesDef);	options.choices[options.cursorUpdatesIndex].setEnabled(true);	options.setEncodings();	options.choices[options.eightBitColorsIndex].select(eightBitColorsDef);	options.choices[options.eightBitColorsIndex].setEnabled(true);	options.setColorFormat();	rfb.closeSession();	System.out.println("Session recording stopped.");      }      sessionFileName = null;      recordingActive = false;    }  }  //  // readParameters() - read parameters from the html source or from the  // command line.  On the command line, the arguments are just a sequence of  // param_name/param_value pairs where the names and values correspond to  // those expected in the html applet tag source.  //  void readParameters() {    host = readParameter("HOST", !inAnApplet);    if (host == null) {      host = getCodeBase().getHost();      if (host.equals("")) {	fatalError("HOST parameter not specified");      }    }    String str = readParameter("PORT", true);    port = Integer.parseInt(str);    // Read "ENCPASSWORD" or "PASSWORD" parameter if specified.    readPasswordParameters();    if (inAnApplet) {      str = readParameter("Open New Window", false);      if (str != null && str.equalsIgnoreCase("Yes"))	inSeparateFrame = true;    }    // "Show Controls" set to "No" disables button panel.    showControls = true;    str = readParameter("Show Controls", false);    if (str != null && str.equalsIgnoreCase("No"))      showControls = false;    // "Offer Relogin" set to "No" disables "Login again" and "Close    // window" buttons under error messages in applet mode.    offerRelogin = true;    str = readParameter("Offer Relogin", false);    if (str != null && str.equalsIgnoreCase("No"))      offerRelogin = false;    // Do we continue showing desktop on remote disconnect?    showOfflineDesktop = false;    str = readParameter("Show Offline Desktop", false);    if (str != null && str.equalsIgnoreCase("Yes"))      showOfflineDesktop = true;    // Fine tuning options.    deferScreenUpdates = readIntParameter("Defer screen updates", 20);    deferCursorUpdates = readIntParameter("Defer cursor updates", 10);    deferUpdateRequests = readIntParameter("Defer update requests", 50);    // SocketFactory.    socketFactory = readParameter("SocketFactory", false);  }  //  // Read password parameters. If an "ENCPASSWORD" parameter is set,  // then decrypt the password into the passwordParam string. Otherwise,  // try to read the "PASSWORD" parameter directly to passwordParam.  //  private void readPasswordParameters() {    String encPasswordParam = readParameter("ENCPASSWORD", false);    if (encPasswordParam == null) {      passwordParam = readParameter("PASSWORD", false);    } else {      // ENCPASSWORD is hexascii-encoded. Decode.      byte[] pw = {0, 0, 0, 0, 0, 0, 0, 0};      int len = encPasswordParam.length() / 2;      if (len > 8)        len = 8;      for (int i = 0; i < len; i++) {        String hex = encPasswordParam.substring(i*2, i*2+2);        Integer x = new Integer(Integer.parseInt(hex, 16));        pw[i] = x.byteValue();      }      // Decrypt the password.      byte[] key = {23, 82, 107, 6, 35, 78, 88, 7};      DesCipher des = new DesCipher(key);      des.decrypt(pw, 0, pw, 0);      passwordParam = new String(pw);    }  }  public String readParameter(String name, boolean required) {    if (inAnApplet) {      String s = getParameter(name);      if ((s == null) && required) {	fatalError(name + " parameter not specified");      }      return s;    }    for (int i = 0; i < mainArgs.length; i += 2) {      if (mainArgs[i].equalsIgnoreCase(name)) {	try {	  return mainArgs[i+1];	} catch (Exception e) {	  if (required) {	    fatalError(name + " parameter not specified");	  }	  return null;	}      }    }    if (required) {      fatalError(name + " parameter not specified");    }    return null;  }  int readIntParameter(String name, int defaultValue) {    String str = readParameter(name, false);    int result = defaultValue;    if (str != null) {      try {	result = Integer.parseInt(str);      } catch (NumberFormatException e) { }    }    return result;  }  //  // moveFocusToDesktop() - move keyboard focus either to VncCanvas.  //  void moveFocusToDesktop() {    if (vncContainer != null) {      if (vc != null && vncContainer.isAncestorOf(vc))	vc.requestFocus();    }  }  //  // disconnect() - close connection to server.  //  synchronized public void disconnect() {    System.out.println("Disconnect");    if (rfb != null && !rfb.closed())      rfb.close();    options.dispose();    clipboard.dispose();    if (rec != null)      rec.dispose();    if (inAnApplet) {      showMessage("Disconnected");    } else {      System.exit(0);    }  }  //  // fatalError() - print out a fatal error message.  // FIXME: Do we really need two versions of the fatalError() method?  //  synchronized public void fatalError(String str) {    System.out.println(str);    if (inAnApplet) {      // vncContainer null, applet not inited,      // can not present the error to the user.      Thread.currentThread().stop();    } else {      System.exit(1);    }  }  synchronized public void fatalError(String str, Exception e) {     if (rfb != null && rfb.closed()) {      // Not necessary to show error message if the error was caused      // by I/O problems after the rfb.close() method call.      System.out.println("RFB thread finished");      return;    }    System.out.println(str);    e.printStackTrace();    if (rfb != null)      rfb.close();    if (inAnApplet) {      showMessage(str);    } else {      System.exit(1);    }  }  //  // Show message text and optionally "Relogin" and "Close" buttons.  //  void showMessage(String msg) {    vncContainer.removeAll();    Label errLabel = new Label(msg, Label.CENTER);    errLabel.setFont(new Font("Helvetica", Font.PLAIN, 12));    if (offerRelogin) {      Panel gridPanel = new Panel(new GridLayout(0, 1));      Panel outerPanel = new Panel(new FlowLayout(FlowLayout.LEFT));      outerPanel.add(gridPanel);      vncContainer.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 16));      vncContainer.add(outerPanel);      Panel textPanel = new Panel(new FlowLayout(FlowLayout.CENTER));      textPanel.add(errLabel);      gridPanel.add(textPanel);      gridPanel.add(new ReloginPanel(this));    } else {      vncContainer.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 30));      vncContainer.add(errLabel);    }    if (inSeparateFrame) {      vncFrame.pack();    } else {      validate();    }  }  //  // Stop the applet.  // Main applet thread will terminate on first exception  // after seeing that rfbThread has been set to null.  //  public void stop() {    System.out.println("Stopping applet");    rfbThread = null;  }  //  // This method is called before the applet is destroyed.  //  public void destroy() {    System.out.println("Destroying applet");    vncContainer.removeAll();    options.dispose();    clipboard.dispose();    if (rec != null)      rec.dispose();    if (rfb != null && !rfb.closed())      rfb.close();    if (inSeparateFrame)      vncFrame.dispose();  }  //  // Start/stop receiving mouse events.  //  public void enableInput(boolean enable) {    vc.enableInput(enable);  }  //  // Close application properly on window close event.  //  public void windowClosing(WindowEvent evt) {    System.out.println("Closing window");    if (rfb != null)      disconnect();    vncContainer.hide();    if (!inAnApplet) {      System.exit(0);    }  }  //  // Ignore window events we're not interested in.  //  public void windowActivated(WindowEvent evt) {}  public void windowDeactivated (WindowEvent evt) {}  public void windowOpened(WindowEvent evt) {}  public void windowClosed(WindowEvent evt) {}  public void windowIconified(WindowEvent evt) {}  public void windowDeiconified(WindowEvent evt) {}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -