Package net.mzalewski.goblin.gui

Source Code of net.mzalewski.goblin.gui.SplashScreen

package net.mzalewski.goblin.gui;

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class SplashScreen {

  private final static String logoFileName = "logo.jpg";
 
  public static void show(String appName, String appVersion) {
    final Display display = new Display();
    final Image image = new Image(display, logoFileName);
   
    GC gc = new GC(image);
    gc.setFont(new Font(display, new FontData("Times", 16, 0)));
    gc.drawText(appName, 100, 290, true);
    gc.dispose();
   
    final Shell splash = new Shell(SWT.ON_TOP);
    Label label = new Label(splash, SWT.NONE);
    label.setImage(image);
   
    FormLayout layout = new FormLayout();
    splash.setLayout(layout);
    FormData labelData = new FormData ();
    labelData.right = new FormAttachment (100, 0);
    labelData.bottom = new FormAttachment (100, 0);
    label.setLayoutData(labelData);
    splash.pack();
   
    Rectangle splashRect = splash.getBounds();
    Rectangle displayRect = display.getBounds();
    int x = (displayRect.width - splashRect.width) / 2;
    int y = (displayRect.height - splashRect.height) / 2;
    splash.setLocation(x, y);
    splash.open();
   
    try { Thread.sleep(2000); } catch (Throwable e) {}
   
    display.dispose();
  }
}
TOP

Related Classes of net.mzalewski.goblin.gui.SplashScreen

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.