Ejemplo n.º 1
0
  public void createPartControl(Composite parent) {

    final ScrolledComposite scomposite =
        new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);

    swtDisplay = (SWTRemoteDisplay) RemoteDisplayFactory.getDisplay(SWTDISPLAY, scomposite);
    running = true;

    scomposite.setContent(swtDisplay);
    scomposite.setExpandHorizontal(true);
    scomposite.setExpandVertical(true);

    swtDisplay
        .getCanvas()
        .addControlListener(
            new ControlListener() {
              public void controlMoved(ControlEvent e) {}

              public void controlResized(ControlEvent e) {
                Point size = swtDisplay.getCanvas().getSize();
                scomposite.setMinSize(swtDisplay.getParent().computeSize(size.x, size.y));
              }
            });

    swtDisplay.getCanvas().setSize(0, 0);

    if (VNCViewerView.protocolHandle != null) {
      try {
        swtDisplay.start(protocolHandle);
      } catch (Exception e) {
        // TODO handle properly
        e.printStackTrace();
      }
    }
  }
Ejemplo n.º 2
0
  /** Performs the start action into the VNC Component. */
  public static synchronized void start(
      String host, int port, String protoVersion, String password, boolean bypassProxy) {

    if ((running) && (swtDisplay != null)) {

      if (swtDisplay.isActive()) {
        swtDisplay.stop();
      }

      try {

        HashMap<String, Object> parameters = new HashMap<String, Object>();
        String protocolId = ProtocolIdTranslator.getProtocolId(protoVersion);

        parameters.put("password", password); // $NON-NLS-1$
        parameters.put(
            "connectionRetries",
            swtDisplay //$NON-NLS-1$
                .getConnectionRetries());

        parameters.put("bypassProxy", new Boolean(bypassProxy)); // $NON-NLS-1$

        VNCViewerView.protocolHandle =
            PluginProtocolActionDelegate.requestStartProtocolAsClient(
                protocolId, new VNCProtocolExceptionHandler(), host, port, parameters);

        while (!PluginProtocolActionDelegate.isProtocolRunning(VNCViewerView.protocolHandle)) {
          Thread.sleep(500);
        }

        swtDisplay.start(protocolHandle);
        currentHost = host;
        currentPort = Integer.toString(port);

      } catch (Exception e) {

        log(VNCViewerView.class).error(VIEWER_COULD_NOT_BE_STARTED + e.getMessage());

        Canvas canvas = swtDisplay.getCanvas();
        if ((canvas != null) && (!canvas.isDisposed())) {
          GC gc = new GC(swtDisplay.getCanvas());
          gc.fillRectangle(0, 0, swtDisplay.getScreenWidth(), swtDisplay.getScreenHeight());
          gc.dispose();
        }
      }
    }
  }