Example #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();
      }
    }
  }
Example #2
0
  public static void zoomOut() {

    double newzoom = 1;

    if (!swtDisplay.isActive()) return;

    if (zoomFactor == 1) {
      zoomFactor = -2;
    } else {
      zoomFactor--;
    }

    if (zoomFactor >= 1) {
      newzoom = zoomFactor;
    } else {
      newzoom = ((double) 1) / -zoomFactor;
    }

    swtDisplay.setZoomFactor(newzoom);
    try {
      swtDisplay.updateRequest(false); // full request
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Example #3
0
  /** Performs the stop action into the VNC Component. */
  public static synchronized void stop() {

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

      if (swtDisplay.isActive()) {
        swtDisplay
            .getDisplay()
            .syncExec(
                new Runnable() {
                  public void run() {
                    swtDisplay.stop();
                    zoomFactor = 1;
                    swtDisplay.setZoomFactor(zoomFactor);
                    swtDisplay.getCanvas().setSize(0, 0);
                  }
                });
      }
    }
  }
Example #4
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();
        }
      }
    }
  }
Example #5
0
  public void dispose() {

    running = false;
    if (swtDisplay != null) swtDisplay.dispose();
    super.dispose();
  }
Example #6
0
 public void setFocus() {
   if (swtDisplay != null) {
     swtDisplay.setFocus();
   }
 }