Exemple #1
0
 /**
  * Returns the monitor on which the application was launched.
  *
  * @param display
  * @return
  */
 private static Monitor getMonitor(Display display) {
   Point mouse = display.getCursorLocation();
   for (Monitor monitor : display.getMonitors()) {
     if (monitor.getBounds().contains(mouse)) {
       return monitor;
     }
   }
   return display.getPrimaryMonitor();
 }
  public Splash(Display display) throws KettleException {
    log = new LogChannel(Spoon.APP_NAME);

    Rectangle displayBounds = display.getPrimaryMonitor().getBounds();

    kettle_image =
        ImageUtil.getImageAsResource(
            display,
            BasePropertyHandler.getProperty("splash_image")); // "kettle_splash.png" //$NON-NLS-1$
    kettle_icon =
        ImageUtil.getImageAsResource(
            display, BasePropertyHandler.getProperty("splash_icon")); // "spoon.ico" //$NON-NLS-1$
    exclamation_image =
        ImageUtil.getImageAsResource(
            display,
            BasePropertyHandler.getProperty(
                "exclamation_image")); // "exclamation.png" //$NON-NLS-1$

    verFont = new Font(display, "Helvetica", 11, SWT.BOLD); // $NON-NLS-1$
    licFont = new Font(display, "Helvetica", licFontSize, SWT.NORMAL); // $NON-NLS-1$
    devWarningFont = new Font(display, "Helvetica", 10, SWT.NORMAL); // $NON-NLS-1$

    versionWarningBackgroundColor = new Color(display, 255, 253, 213);
    versionWarningForegroundColor = new Color(display, 220, 177, 20);

    splash = new Shell(display, SWT.APPLICATION_MODAL);
    splash.setImage(kettle_icon);

    splash.setText(
        BaseMessages.getString(
            PKG, "SplashDialog.Title")); // "Pentaho Data Integration" //$NON-NLS-1$

    FormLayout splashLayout = new FormLayout();
    splash.setLayout(splashLayout);

    Canvas canvas = new Canvas(splash, SWT.NO_BACKGROUND);

    FormData fdCanvas = new FormData();
    fdCanvas.left = new FormAttachment(0, 0);
    fdCanvas.top = new FormAttachment(0, 0);
    fdCanvas.right = new FormAttachment(100, 0);
    fdCanvas.bottom = new FormAttachment(100, 0);
    canvas.setLayoutData(fdCanvas);

    canvas.addPaintListener(
        new PaintListener() {
          public void paintControl(PaintEvent e) {
            String versionText =
                BaseMessages.getString(PKG, "SplashDialog.Version")
                    + " "
                    + Const.VERSION; // $NON-NLS-1$ //$NON-NLS-2$

            StringBuilder sb = new StringBuilder();
            String line = null;

            try {
              BufferedReader reader =
                  new BufferedReader(
                      new InputStreamReader(
                          Splash.class
                              .getClassLoader()
                              .getResourceAsStream(
                                  "org/pentaho/di/ui/core/dialog/license/license.txt"))); //$NON-NLS-1$

              while ((line = reader.readLine()) != null) {
                sb.append(line + System.getProperty("line.separator")); // $NON-NLS-1$
              }
            } catch (Exception ex) {
              sb.append(""); // $NON-NLS-1$
              log.logError(
                  BaseMessages.getString(PKG, "SplashDialog.LicenseTextNotFound"),
                  ex); //$NON-NLS-1$
            }
            Calendar cal = Calendar.getInstance();
            String licenseText = String.format(sb.toString(), cal);
            e.gc.drawImage(kettle_image, 0, 0);

            // If this is a Milestone or RC release, warn the user
            if (Const.RELEASE.equals(Const.ReleaseType.MILESTONE)) {
              versionText =
                  BaseMessages.getString(PKG, "SplashDialog.DeveloperRelease")
                      + " - "
                      + versionText; //$NON-NLS-1$ //$NON-NLS-2$
              drawVersionWarning(e);
            } else if (Const.RELEASE.equals(Const.ReleaseType.RELEASE_CANDIDATE)) {
              versionText =
                  BaseMessages.getString(PKG, "SplashDialog.ReleaseCandidate")
                      + " - "
                      + versionText; //$NON-NLS-1$//$NON-NLS-2$
            } else if (Const.RELEASE.equals(Const.ReleaseType.PREVIEW)) {
              versionText =
                  BaseMessages.getString(PKG, "SplashDialog.PreviewRelease")
                      + " - "
                      + versionText; //$NON-NLS-1$//$NON-NLS-2$
            } else if (Const.RELEASE.equals(Const.ReleaseType.GA)) {
              versionText =
                  BaseMessages.getString(PKG, "SplashDialog.GA")
                      + " - "
                      + versionText; //$NON-NLS-1$//$NON-NLS-2$
            }

            e.gc.setFont(verFont);
            e.gc.drawText(versionText, 290, 205, true);

            // try using the desired font size for the license text
            e.gc.setFont(licFont);

            // if the text will not fit the allowed space
            while (!willLicenseTextFit(licenseText, e.gc)) {
              licFontSize--;
              if (licFont != null) {
                licFont.dispose();
              }
              licFont = new Font(e.display, "Helvetica", licFontSize, SWT.NORMAL); // $NON-NLS-1$
              e.gc.setFont(licFont);
            }

            e.gc.drawText(licenseText, 290, 290, true);
          }
        });

    splash.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent arg0) {
            kettle_image.dispose();
            kettle_icon.dispose();
            exclamation_image.dispose();
            verFont.dispose();
            licFont.dispose();
            devWarningFont.dispose();
            versionWarningForegroundColor.dispose();
            versionWarningBackgroundColor.dispose();
          }
        });
    Rectangle bounds = kettle_image.getBounds();
    int x = (displayBounds.width - bounds.width) / 2;
    int y = (displayBounds.height - bounds.height) / 2;

    splash.setSize(bounds.width, bounds.height);
    splash.setLocation(x, y);

    splash.open();
  }
Exemple #3
0
  public GUI(String Profile, NetworkInterface NetObj) {

    MainDisplay = new Display();
    MainShell = new Shell(MainDisplay);
    Updater = new GUIUpdaterThread(NetObj, this);
    Updater.setDaemon(true);

    // restartOpt=false;
    if (Profile.equals("SERVER") == true) {
      // FIX THIS ASAP
      UserProfile = "SERVER";
      MainServer = (JTServer) NetObj;
      MainServer.test();
      System.out.println(
          "GUI invoked with " + MainServer.getLocalUserIP() + ":" + MainServer.getLocalUserPort());
      MainClient = null;
    } else if (Profile.equals("CLIENT") == true) {
      // FIX THIS ASAP
      UserProfile = "CLIENT";
      MainClient = (JTClient) NetObj;
      MainClient.test();
      MainServer = null;
      System.out.println(
          "GUI invoked with target " + MainClient.getTargetIP() + ":" + MainClient.getTargetPort());
      System.out.println(
          "and client "
              + MainClient.getLocalUserName()
              + "@"
              + MainClient.getLocalUserIP()
              + ":"
              + MainClient.getLocalUserPort());
    } else {
      confirmWin(
          MainShell,
          "Internal Error! No extension of JTNetworkInterface active!",
          jeremeTalk.JTC.OK);
      destroy();
    }

    Calibri = new Font(MainDisplay, "Calibri", 12, SWT.NORMAL);

    Red = new Color(MainDisplay, 0x80, 0, 0);
    Green = new Color(MainDisplay, 0, 0x80, 0);
    Blue = new Color(MainDisplay, 0, 0, 0x80);
    White = new Color(MainDisplay, 0xFF, 0xFF, 0xFF);
    Black = new Color(MainDisplay, 0, 0, 0);
    Gray = new Color(MainDisplay, 0xCC, 0xCC, 0xCC);

    GridLayout GlobalWinGL = new GridLayout();
    GlobalWinGL.numColumns = 3;
    GlobalWinGL.marginHeight = 10;
    GlobalWinGL.marginWidth = 10;
    GlobalWinGL.verticalSpacing = 5;
    GlobalWinGL.horizontalSpacing = 5;

    MainShell.setLayout(GlobalWinGL);

    initWidgets();

    addWidgetListeners();

    MainShell.setMenuBar(GlobalMainMenu);
    MainShell.pack();

    MainShell.setLocation(centralize(MainDisplay.getPrimaryMonitor().getBounds(), MainShell));

    MainShell.setText(
        "JeremeTalk v1.0 : Welcome " + NetObj.getLocalUserName() + " | You are " + UserProfile);

    MainShell.open();
    Updater.start();
    while (!MainShell.isDisposed()) {
      if (!MainDisplay.readAndDispatch()) MainDisplay.sleep();
    }
    if (MainServer == null) MainClient.freePort();
    else MainServer.freePort();
    Updater.kill();
    System.out.println("GUI Destroyed!");
  }