<commit_before>/*! ******************************************************************************
 *
 * Pentaho Data Integration
 *
 * Copyright (C) 2002-2013 by Pentaho : http://www.pentaho.com
 *
 *******************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************************/

package org.pentaho.di.ui.core.dialog;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.SwtUniversalImage;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.logging.LogChannel;
import org.pentaho.di.core.logging.LogChannelInterface;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.laf.BasePropertyHandler;
import org.pentaho.di.ui.spoon.Spoon;
import org.pentaho.di.ui.util.SwtSvgImageUtil;
import org.pentaho.di.version.BuildVersion;

/**
 * Displays the Kettle splash screen
 * 
 * @author Matt
 * @since 14-mrt-2005
 */
public class Splash {
  private Shell splash;

  private Image kettle_image;
  private Image kettle_icon;
  private Image exclamation_image;

  private Font verFont;
  private Font licFont;
  private Font devWarningFont;

  private Color versionWarningBackgroundColor;
  private Color versionWarningForegroundColor;

  private int licFontSize = 8;

  private static Class<?> PKG = Splash.class; // for i18n purposes, needed by Translator2!!

  private static LogChannelInterface log;

  public Splash( Display display ) throws KettleException {
    this( display, new Shell( display, SWT.APPLICATION_MODAL ) );
  }

  protected Splash( Display display, Shell splashShell ) throws KettleException {
    log = new LogChannel( Spoon.APP_NAME );

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

    // "kettle_splash.png"
    kettle_image = loadAsResource( display, BasePropertyHandler.getProperty( "splash_image" ) );
    // "spoon.ico"
    kettle_icon = loadAsResource( display, BasePropertyHandler.getProperty( "splash_icon" ) );
    // "exclamation.png"
    exclamation_image = loadAsResource( display, BasePropertyHandler.getProperty( "exclamation_image" ) );

    verFont = new Font( display, "Helvetica", 11, SWT.BOLD );
    licFont = new Font( display, "Helvetica", licFontSize, SWT.NORMAL );
    devWarningFont = new Font( display, "Helvetica", 10, SWT.NORMAL );

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

    splash = splashShell;
    splash.setImage( kettle_icon );

    splash.setText( BaseMessages.getString( PKG, "SplashDialog.Title" ) ); // "Pentaho Data Integration"

    splash.addPaintListener( new PaintListener() {
      public void paintControl( PaintEvent e ) {
        String fullVersionText =
            BaseMessages.getString( PKG, "SplashDialog.Version" ) + " " + BuildVersion.getInstance().getVersion();

        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" ) ) );

          while ( ( line = reader.readLine() ) != null ) {
            sb.append( line + System.getProperty( "line.separator" ) );
          }
        } catch ( Exception ex ) {
          sb.append( "" );
          log.logError( BaseMessages.getString( PKG, "SplashDialog.LicenseTextNotFound" ), ex );
        }
        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 ) ) {
          fullVersionText = BaseMessages.getString( PKG, "SplashDialog.DeveloperRelease" ) + " - " + fullVersionText;
          drawVersionWarning( e );
        } else if ( Const.RELEASE.equals( Const.ReleaseType.RELEASE_CANDIDATE ) ) {
          fullVersionText = BaseMessages.getString( PKG, "SplashDialog.ReleaseCandidate" ) + " - " + fullVersionText;
        } else if ( Const.RELEASE.equals( Const.ReleaseType.PREVIEW ) ) {
          fullVersionText = BaseMessages.getString( PKG, "SplashDialog.PreviewRelease" ) + " - " + fullVersionText;
        } else if ( Const.RELEASE.equals( Const.ReleaseType.GA ) ) {
          fullVersionText = BaseMessages.getString( PKG, "SplashDialog.GA" ) + " - " + fullVersionText;
        }

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

        String inputStringDate = BuildVersion.getInstance().getBuildDate();
        String outputStringDate = "";
        SimpleDateFormat inputFormat = null;
        SimpleDateFormat outputFormat = null;
    
        if ( inputStringDate.matches( "^\\d{4}/\\d{1,2}/\\d{1,2}\\s\\d{1,2}:\\d{2}:\\d{2}.\\d{3}$" ) ) {
          inputFormat = new SimpleDateFormat( "yyyy/MM/dd hh:mm:ss.SSS" );
        }
        if ( inputStringDate.matches( "^\\d{4}-\\d{1,2}-\\d{1,2}\\_\\d{1,2}-\\d{2}-\\d{2}$" ) ) {
          inputFormat = new SimpleDateFormat( "yyyy-MM-dd_hh-mm-ss" );
        }
        if ( inputStringDate.matches( "^\\d{4}-\\d{1,2}-\\d{1,2}\\s\\d{1,2}.\\d{2}.\\d{2}$" ) ) {
          inputFormat = new SimpleDateFormat( "yyyy-MM-dd hh.mm.ss" );
        }
        outputFormat = new SimpleDateFormat( "MMMM d, yyyy hh:mm:ss" );
        try {
          if ( inputFormat != null ) {
            Date date = inputFormat.parse( inputStringDate );
            outputStringDate = outputFormat.format( date );
          } else {
            // If date isn't correspond to formats above just show date in origin format
            outputStringDate = inputStringDate;
          }
        } catch ( ParseException pe ) {
          // Just show date in origin format
          outputStringDate = inputStringDate;
        }        
        
        // 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 );
          e.gc.setFont( licFont );
        }

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

        // use the same font/size as the license text
        String version = BaseMessages.getString( PKG, "SplashDialog.BuildVersion" ) + " " + 
            BuildVersion.getInstance().getVersion();
        String buildDate = BaseMessages.getString( PKG, "SplashDialog.BuildDate" ) + " " + outputStringDate;
        e.gc.drawText( version, 290, 235, true );
        e.gc.drawText( buildDate, 290, 250, true );<commit_msg>[PDI-14132] About screen - information of GA, build version is out of screen<commit_after>/*! ******************************************************************************
 *
 * Pentaho Data Integration
 *
 * Copyright (C) 2002-2013 by Pentaho : http://www.pentaho.com
 *
 *******************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************************/

package org.pentaho.di.ui.core.dialog;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.SwtUniversalImage;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.logging.LogChannel;
import org.pentaho.di.core.logging.LogChannelInterface;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.laf.BasePropertyHandler;
import org.pentaho.di.ui.spoon.Spoon;
import org.pentaho.di.ui.util.SwtSvgImageUtil;
import org.pentaho.di.version.BuildVersion;

/**
 * Displays the Kettle splash screen
 * 
 * @author Matt
 * @since 14-mrt-2005
 */
public class Splash {
  private Shell splash;

  private Image kettle_image;
  private Image kettle_icon;
  private Image exclamation_image;

  private Font verFont;
  private Font licFont;
  private Font devWarningFont;

  private Color versionWarningBackgroundColor;
  private Color versionWarningForegroundColor;

  private int licFontSize = 8;

  private static Class<?> PKG = Splash.class; // for i18n purposes, needed by Translator2!!

  private static LogChannelInterface log;

  public Splash( Display display ) throws KettleException {
    this( display, new Shell( display, SWT.APPLICATION_MODAL ) );
  }

  protected Splash( Display display, Shell splashShell ) throws KettleException {
    log = new LogChannel( Spoon.APP_NAME );

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

    // "kettle_splash.png"
    kettle_image = loadAsResource( display, BasePropertyHandler.getProperty( "splash_image" ) );
    // "spoon.ico"
    kettle_icon = loadAsResource( display, BasePropertyHandler.getProperty( "splash_icon" ) );
    // "exclamation.png"
    exclamation_image = loadAsResource( display, BasePropertyHandler.getProperty( "exclamation_image" ) );

    verFont = new Font( display, "Helvetica", 11, SWT.BOLD );
    licFont = new Font( display, "Helvetica", licFontSize, SWT.NORMAL );
    devWarningFont = new Font( display, "Helvetica", 10, SWT.NORMAL );

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

    splash = splashShell;
    splash.setImage( kettle_icon );

    splash.setText( BaseMessages.getString( PKG, "SplashDialog.Title" ) ); // "Pentaho Data Integration"

    splash.addPaintListener( new PaintListener() {
      public void paintControl( PaintEvent e ) {
        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" ) ) );

          while ( ( line = reader.readLine() ) != null ) {
            sb.append( line + System.getProperty( "line.separator" ) );
          }
        } catch ( Exception ex ) {
          sb.append( "" );
          log.logError( BaseMessages.getString( PKG, "SplashDialog.LicenseTextNotFound" ), ex );
        }
        Calendar cal = Calendar.getInstance();
        String licenseText = String.format( sb.toString(), cal );
        e.gc.drawImage( kettle_image, 0, 0 );
        
        String fullVersionText =  BaseMessages.getString( PKG, "SplashDialog.Version" );
        String buildVersion = BuildVersion.getInstance().getVersion();
        if ( buildVersion.indexOf( "-" ) > -1 ) {
          fullVersionText =  fullVersionText + " "  + buildVersion.substring( 0, buildVersion.indexOf( "-" ) );
        } else {
          fullVersionText =  fullVersionText + " "  + buildVersion;
        }
        e.gc.setFont( verFont );
        e.gc.drawText( fullVersionText, 290, 205, true );

        String inputStringDate = BuildVersion.getInstance().getBuildDate();
        String outputStringDate = "";
        SimpleDateFormat inputFormat = null;
        SimpleDateFormat outputFormat = null;
    
        if ( inputStringDate.matches( "^\\d{4}/\\d{1,2}/\\d{1,2}\\s\\d{1,2}:\\d{2}:\\d{2}.\\d{3}$" ) ) {
          inputFormat = new SimpleDateFormat( "yyyy/MM/dd hh:mm:ss.SSS" );
        }
        if ( inputStringDate.matches( "^\\d{4}-\\d{1,2}-\\d{1,2}\\_\\d{1,2}-\\d{2}-\\d{2}$" ) ) {
          inputFormat = new SimpleDateFormat( "yyyy-MM-dd_hh-mm-ss" );
        }
        if ( inputStringDate.matches( "^\\d{4}-\\d{1,2}-\\d{1,2}\\s\\d{1,2}.\\d{2}.\\d{2}$" ) ) {
          inputFormat = new SimpleDateFormat( "yyyy-MM-dd hh.mm.ss" );
        }
        outputFormat = new SimpleDateFormat( "MMMM d, yyyy hh:mm:ss" );
        try {
          if ( inputFormat != null ) {
            Date date = inputFormat.parse( inputStringDate );
            outputStringDate = outputFormat.format( date );
          } else {
            // If date isn't correspond to formats above just show date in origin format
            outputStringDate = inputStringDate;
          }
        } catch ( ParseException pe ) {
          // Just show date in origin format
          outputStringDate = inputStringDate;
        }        
        
        // 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 );
          e.gc.setFont( licFont );
        }

        e.gc.drawText( licenseText, 290, 275, true );
        
        String version =  buildVersion;
        // If this is a Milestone or RC release, warn the user
        if ( Const.RELEASE.equals( Const.ReleaseType.MILESTONE ) ) {
          version = BaseMessages.getString( PKG, "SplashDialog.DeveloperRelease" ) + " - " + version;
          drawVersionWarning( e );
        } else if ( Const.RELEASE.equals( Const.ReleaseType.RELEASE_CANDIDATE ) ) {
          version = BaseMessages.getString( PKG, "SplashDialog.ReleaseCandidate" ) + " - " + version;
        } else if ( Const.RELEASE.equals( Const.ReleaseType.PREVIEW ) ) {
          version = BaseMessages.getString( PKG, "SplashDialog.PreviewRelease" ) + " - " + version;
        } else if ( Const.RELEASE.equals( Const.ReleaseType.GA ) ) {
          version = BaseMessages.getString( PKG, "SplashDialog.GA" ) + " - " + version;
        }
        String buildDate = BaseMessages.getString( PKG, "SplashDialog.BuildDate" ) + " " + outputStringDate;
        // use the same font/size as the license text
        e.gc.drawText( version, 290, 235, true );
        e.gc.drawText( buildDate, 290, 250, true );
{'fraction_non_alphanumeric': 0.14456534736338633, 'fraction_numerical': 0.01333253617123042, 'mean_word_length': 3.0083872513779055, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5444218', 'n_tokens_mistral': 5146, 'n_tokens_neox': 4834, 'n_words': 1170}