Java Code Examples for java.awt.SplashScreen#createGraphics()

The following examples show how to use java.awt.SplashScreen#createGraphics() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiResolutionSplashTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
Example 2
Source File: UnixMultiResolutionSplashTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();
    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }
    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();
    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;
    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
Example 3
Source File: MultiResolutionSplashTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
Example 4
Source File: KSE.java    From keystore-explorer with GNU General Public License v3.0 6 votes vote down vote up
private static void updateSplashMessage(SplashScreen splash, String message) {
	// Splash screen may not be present
	if (splash != null) {
		Font font = new Font(Font.SANS_SERIF, Font.PLAIN, 10);
		Graphics2D g = splash.createGraphics();
		g.setFont(font);
		g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

		// Wipe out any previous text
		g.setColor(new Color(238, 238, 238)); // #EEEEEE
		g.setPaintMode();
		g.fillRect(12, 70, 250, 30); // (x,y) is top left corner of area

		// Draw next text
		g.setColor(new Color(96, 96, 96)); // #606060
		g.setPaintMode();
		g.drawString(message, 17, 86); // (x,y) is baseline of text

		splash.update();
	}
}
 
Example 5
Source File: MultiResolutionSplashTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
Example 6
Source File: MultiResolutionSplashTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
Example 7
Source File: Main.java    From gsn with GNU General Public License v3.0 6 votes vote down vote up
private static void updateSplashIfNeeded(String message[]) {
	boolean headless_check = isHeadless();

	if (!headless_check) {
		SplashScreen splash = SplashScreen.getSplashScreen();
		if (splash == null)
			return;
		if (splash.isVisible()) {
			//Get a graphics overlay for the splash screen
			Graphics2D g = splash.createGraphics();
			//Do some drawing on the graphics object
			//Now update to the splash screen

			g.setComposite(AlphaComposite.Clear);
			g.fillRect(0,0,400,70);
			g.setPaintMode();
			g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
			g.setColor(Color.BLACK);
			g.setFont(new Font("Arial",Font.BOLD,11));
			for (int i=0;i<message.length;i++)
				g.drawString(message[i], 13, 16*i+10);
			splash.update();
		}
	}
}
 
Example 8
Source File: MultiResolutionSplashTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    if(splashBounds.width != IMAGE_WIDTH){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong width");
    }
    if(splashBounds.height != IMAGE_HEIGHT){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong height");
    }

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
Example 9
Source File: MultiResolutionSplashTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    if(splashBounds.width != IMAGE_WIDTH){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong width");
    }
    if(splashBounds.height != IMAGE_HEIGHT){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong height");
    }

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
Example 10
Source File: Opt4J.java    From opt4j with MIT License 5 votes vote down vote up
/**
 * Decorate the splash screen with the version and date.
 * 
 * @param splash
 *            the splash screen
 */
protected static void decorateVersionDate(SplashScreen splash) {
	if (splash != null) {
		Graphics2D g = splash.createGraphics();
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g.setColor(new Color(242, 130, 38));
		g.setFont(new Font("SansSerif", Font.BOLD, 11));
		g.drawString("version " + getVersion(), 170, 76);
		g.drawString(getDateISO(), 170, 91);
		splash.update();
	}
}
 
Example 11
Source File: MultiResolutionSplashTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    if(splashBounds.width != IMAGE_WIDTH){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong width");
    }
    if(splashBounds.height != IMAGE_HEIGHT){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong height");
    }

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
Example 12
Source File: MultiResolutionSplashTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    if(splashBounds.width != IMAGE_WIDTH){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong width");
    }
    if(splashBounds.height != IMAGE_HEIGHT){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong height");
    }

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
Example 13
Source File: MultiResolutionSplashTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();
    if (splashBounds.width != IMAGE_WIDTH) {
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong width");
    }
    if (splashBounds.height != IMAGE_HEIGHT) {
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong height");
    }

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);
    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
Example 14
Source File: MultiResolutionSplashTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    if(splashBounds.width != IMAGE_WIDTH){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong width");
    }
    if(splashBounds.height != IMAGE_HEIGHT){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong height");
    }

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
Example 15
Source File: MultiResolutionSplashTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    if(splashBounds.width != IMAGE_WIDTH){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong width");
    }
    if(splashBounds.height != IMAGE_HEIGHT){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong height");
    }

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
Example 16
Source File: DBrowser.java    From Rel with Apache License 2.0 4 votes vote down vote up
private static void launch(String[] args) {
	Display.setAppName(Version.getAppName());
	Display.setAppVersion(Version.getVersion());
	final Display display = new Display();
	
	OpenDocumentEventProcessor openDocProcessor = new OpenDocumentEventProcessor();
	display.addListener(SWT.OpenDocument, openDocProcessor);
	
	openDocProcessor.addFilesToOpen(args);		

	if (Util.isMac())
		executeSplashInteractor(() -> {
			try {
				Thread.sleep(300);
			} catch (InterruptedException e1) {
			}
		});

	try {
		Class.forName("org.reldb.rel.Rel");
		localRel = true;
	} catch (ClassNotFoundException cnfe) {
		localRel = false;
	}
	
	OSSpecific.launch(Version.getAppName(),
		event -> quit(),
		event -> new AboutDialog(shell).open(),
		event -> new Preferences(shell).show()
	);

	if (!Util.isMac()) {
		SplashScreen splash = SplashScreen.getSplashScreen();
		if (splash != null && localRel && !Preferences.getPreferenceBoolean(PreferencePageGeneral.SKIP_DEFAULT_DB_LOAD)) {
			Graphics2D gc = splash.createGraphics();
			Rectangle rect = splash.getBounds();
			int barWidth = rect.width - 20;
			int barHeight = 10;
			Rectangle progressBarRect = new Rectangle(10, rect.height - 20, barWidth, barHeight);
			gc.draw3DRect(progressBarRect.x, progressBarRect.y, progressBarRect.width, progressBarRect.height, false);
			gc.setColor(Color.green);
			(new Thread(() -> {
				while (SplashScreen.getSplashScreen() != null) {
					int percent = Loading.getPercentageOfExpectedMessages();
					int drawExtent = Math.min(barWidth * percent / 100, barWidth);
					gc.fillRect(progressBarRect.x, progressBarRect.y, drawExtent, barHeight);
					splash.update();					
					try {
						Thread.sleep(250);
					} catch (InterruptedException e) {
					}
				}							
			})).start();
		}			
	}
	
	shell = createShell();
	shell.setImage(IconLoader.loadIcon("RelIcon"));
	shell.setImages(loadIcons(display));
	shell.setText(Version.getAppID());
	shell.addListener(SWT.Close, e -> {
		shell.dispose();
	});
	shell.addDisposeListener(e -> quit());
	shell.layout();

	Loading.start();
	
	Core.launch(openDocProcessor, shell);
	
	if (!Util.isMac())
		closeSplash();
	
	shell.open();		
	
	while (!display.isDisposed()) {
		try {
			if (!display.readAndDispatch())
				display.sleep();
		} catch (Throwable t) {
			System.out.println("DBrowser: Exception: " + t);
			t.printStackTrace();
		}
	}
}