Exemple #1
0
  private void showPic(String path) {
    FileInputStream fin;
    try {
      fin = new FileInputStream(path);
      Image image = new Image(Display.getCurrent(), fin);

      label.setText("test");
      label.setImage(image);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (SWTException e) {
      e.printStackTrace();
      label.setText("Unable to load Image");
    }
  }
 /**
  * Create this dialog's drop-down list component.
  *
  * @param parent the parent composite
  * @return the drop-down list component
  */
 protected void createDropDownText(Composite parent) {
   // create the list
   text = new Text(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
   // print the stacktrace in the text field
   try {
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     PrintStream ps = new PrintStream(baos);
     detail.printStackTrace(ps);
     if ((detail instanceof SWTError) && (((SWTError) detail).throwable != null)) {
       ps.println("\n*** Stack trace of contained exception ***"); // $NON-NLS-1$
       ((SWTError) detail).throwable.printStackTrace(ps);
     } else if ((detail instanceof SWTException) && (((SWTException) detail).throwable != null)) {
       ps.println("\n*** Stack trace of contained exception ***"); // $NON-NLS-1$
       ((SWTException) detail).throwable.printStackTrace(ps);
     }
     ps.flush();
     baos.flush();
     text.setText(baos.toString());
   } catch (IOException e) {
   }
   GridData data =
       new GridData(
           GridData.HORIZONTAL_ALIGN_FILL
               | GridData.GRAB_HORIZONTAL
               | GridData.VERTICAL_ALIGN_FILL
               | GridData.GRAB_VERTICAL);
   data.heightHint = text.getLineHeight() * TEXT_LINE_COUNT;
   text.setLayoutData(data);
 }
 /**
  * Executes the given <code><var>task</var></code> in the given display's thread.
  *
  * <p>Note: <code>Throwable</code>s thrown by <code><var>task</var></code> will not be displayed.
  * If you want them to be displayed, use a try/catch block with <code>printStackTrace()</code>
  * inside <code><var>task</var></code> yourself.
  *
  * @throws SWTException
  *     <ul>
  *       <li>ERROR_DEVICE_DISPOSED - if the display has been disposed
  *     </ul>
  */
 public void asyncExec(Display display, final Runnable task) {
   final Runnable final_task;
   if (isReportingAsyncExecExceptions()) {
     final_task =
         new Runnable() {
           public void run() {
             try {
               task.run();
             } catch (RuntimeException e) {
               e.printStackTrace();
               throw e;
             } catch (Error e) {
               e.printStackTrace();
               throw e;
             }
           }
         };
   } else {
     final_task = task;
   }
   try {
     display.asyncExec(final_task);
   } catch (NullPointerException e) {
     // Workaround for wrong order of actions inside Display.dispose().
     // https://bugs.eclipse.org/bugs/show_bug.cgi?id=216346
     // http://dev.eclipse.org/newslists/news.eclipse.platform.swt/msg30856.html
     StackTraceElement[] stack = e.getStackTrace();
     if (stack.length > 0
         && "org.eclipse.swt.widgets.Display".equals(stack[0].getClassName())
         && "asyncExec".equals(stack[0].getMethodName())) {
       SWTException swte = new SWTException(SWT.ERROR_DEVICE_DISPOSED);
       swte.throwable = e;
       throw swte;
     } else throw e;
   }
 }
  BARControl(String[] args) {
    try {
      // load settings
      Settings.load();

      // parse arguments
      parseArguments(args);

      // init display
      display = new Display();

      // connect to server
      LoginData loginData = new LoginData(serverName, serverPort, serverTLSPort);
      boolean connectOkFlag = false;
      if ((loginData.serverName != null)
          && !loginData.serverName.equals("")
          && (loginData.password != null)
          && !loginData.password.equals("")
          && !loginDialogFlag) {
        // connect to server with preset data
        try {
          BARServer.connect(
              loginData.serverName,
              loginData.port,
              loginData.tlsPort,
              loginData.password,
              serverKeyFileName);
          connectOkFlag = true;
        } catch (ConnectionError error) {
        }
      }
      while (!connectOkFlag) {
        // get login data
        if (!getLoginData(loginData)) {
          System.exit(0);
        }
        if ((loginData.port == 0) && (loginData.tlsPort == 0)) {
          throw new Error("Cannot connect to server. No server ports specified!");
        }
        /// ??? host name scheck

        // connect to server
        try {
          BARServer.connect(
              loginData.serverName,
              loginData.port,
              loginData.tlsPort,
              loginData.password,
              serverKeyFileName);
          connectOkFlag = true;
        } catch (ConnectionError error) {
          if (!Dialogs.confirmError(
              new Shell(),
              "Connection fail",
              "Error: " + error.getMessage(),
              "Try again",
              "Cancel")) {
            System.exit(1);
          }
        }
      }

      // open main window
      createWindow();
      createTabs();
      createMenu();

      // run
      run();

      // disconnect
      BARServer.disconnect();

      // save settings
      Settings.save();
    } catch (org.eclipse.swt.SWTException exception) {
      System.err.println("ERROR graphics: " + exception.getCause());
      if (debug) {
        for (StackTraceElement stackTraceElement : exception.getStackTrace()) {
          System.err.println("  " + stackTraceElement);
        }
      }
    } catch (CommunicationError communicationError) {
      System.err.println("ERROR communication: " + communicationError.getMessage());
    } catch (AssertionError assertionError) {
      System.err.println("INTERNAL ERROR: " + assertionError.toString());
      for (StackTraceElement stackTraceElement : assertionError.getStackTrace()) {
        System.err.println("  " + stackTraceElement);
      }
      System.err.println("");
      System.err.println("Please report this assertion error to [email protected].");
    } catch (InternalError error) {
      System.err.println("INTERNAL ERROR: " + error.getMessage());
    } catch (Error error) {
      System.err.println("ERROR: " + error.getMessage());
      if (debug) {
        for (StackTraceElement stackTraceElement : error.getStackTrace()) {
          System.err.println("  " + stackTraceElement);
        }
      }
    }
  }