⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 splash.java

📁 开源的关于SWT开发的图形应用库
💻 JAVA
字号:
package com.swtplus.gallery;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Region;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;

public class Splash {
	
	Shell shell;
	Shell parent;
	private int height;
	private int width;
	
	private Image title = GalleryImageRegistry.getImage(this.getClass(),"title.png");
	private Image signature = GalleryImageRegistry.getImage(this.getClass(),"signature.png");
	private ControlListener controlListener;
	
	public Splash(Shell parent){
		
		this.parent = parent;
		
		try {
			go(parent);
		} catch (InterruptedException e) {
		}		
	}

	private void go(final Shell parent) throws InterruptedException{
		shell = new Shell(parent,SWT.NO_TRIM);
		
		//shell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));

//		shell.addFocusListener(new FocusListener() {
//			public void focusLost(FocusEvent e) {
//			}		
//			public void focusGained(FocusEvent e) {
//				shell.getDisplay().asyncExec(new Runnable() {
//					public void run() {
//						parent.setFocus();
//						try {
//							close();
//						} catch (InterruptedException e1) {
//						}
//					}				
//				});
//			}		
//		});
		
		shell.addMouseListener(new MouseListener() {
			public void mouseUp(MouseEvent arg0) {
			}
			public void mouseDown(MouseEvent arg0) {
				shell.getDisplay().asyncExec(new Runnable() {
					public void run() {
						parent.setFocus();
						try {
							close();
						} catch (InterruptedException e1) {
						}
					}				
				});
			}
			public void mouseDoubleClick(MouseEvent arg0) {
			}		
		});
		
		resize();
		
		shell.setVisible(true);
		
		parent.getDisplay().readAndDispatch();
		
		controlListener = new ControlListener() {
			public void controlResized(ControlEvent e) {
				resize();
			}		
			public void controlMoved(ControlEvent e) {
				resize();
			}		
		};
		
		parent.addControlListener(controlListener);
		
		createContents();
		
		parent.getDisplay().asyncExec(new Runnable(){
			public void run() {
				resize();
			}		
		});
		
	}
	
	private void createContents(){
		
		final String text = "The SWTPlus Demo is a showcase of the available SWTPlus widgets.\r\n\r\nMost widgets are designed with specific strategies determining appearance, much \r\nlike Swing's UI delegates.  This demo is designed to showcase each individual \r\nstrategy available for each widget.";
		
		shell.setLayout(new FillLayout());
		final Composite c = new Composite(shell,SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED);
		c.setEnabled(false);
		c.addPaintListener(new PaintListener() {
			public void paintControl(PaintEvent e) { 
				e.gc.setForeground(c.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
				e.gc.setBackground(c.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
				e.gc.fillGradientRectangle(0,0,c.getSize().x,c.getSize().y,true);

				e.gc.drawImage(title,50,50);
				
				e.gc.drawImage(signature,55,85);
				
				e.gc.setForeground(c.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
				e.gc.drawText(text,70,165,true);
				
				e.gc.setForeground(c.getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
				e.gc.drawString("Copyright 2005 Near Corner Software",681,536,true);
				
				e.gc.setForeground(c.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
				e.gc.drawString("Copyright 2005 Near Corner Software",680,535,true);

				e.gc.setForeground(c.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
				e.gc.drawString("Click Anywhere to Continue",70,280,true);
			}		
		});
		
		final Color color1 = shell.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
		final Color color2 = shell.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND);

		Runnable run = new Runnable() {
			int i = 0;
			public void run() {
				if (shell.isDisposed())
					return;
				GC gc = new GC(c);
				i ++;
				if (i %2 == 0){
					gc.setForeground(color1);					
				} else {
					gc.setForeground(color2);
				}
				gc.drawString("Click Anywhere to Continue",70,280,true);
				gc.dispose();
				if (i %2 == 0){
					shell.getDisplay().timerExec(500,this);					
				} else {
					shell.getDisplay().timerExec(3000,this);
				}
			}		
		};
		run.run();

		shell.layout();		

	}
		
	private void close() throws InterruptedException{
		Thread.sleep(10);
		
		int x = 0;
		int y = 0;
		
		do {
			Region old = shell.getRegion();
			Region r = new Region();
			if (height - 10 < 5){
				y -= height - 5/2;
				height = 5;
			} else {
				height -= 10;
				y += 5;
			}
			r.add(x,y,width,height);
			shell.setRegion(r);
			if (old != null)
				old.dispose();
			
			parent.redraw();
			parent.getDisplay().update();
			Thread.sleep(1);
			
		} while (height > 5);
		
		do {
			Region old = shell.getRegion();
			Region r = new Region();
			width -= 8;
			x += 4;
			r.add(x,y,width,height);
			shell.setRegion(r);
			if (old != null)
				old.dispose();
			
			parent.redraw();
			parent.getDisplay().update();
			Thread.sleep(1);
		} while (width > 10);
		

		if (shell.getRegion() != null)
			shell.getRegion().dispose();		
		shell.dispose();
		
		parent.removeControlListener(controlListener);
	}



	protected void resize() {
		if (shell.isDisposed())
			return;
		if (parent.isDisposed())
			return;
		
		Point p = parent.getDisplay().map(parent,null,0,0);
		
		height = parent.getClientArea().height;
		width = parent.getClientArea().width;
		
		shell.setBounds(p.x,p.y,width,height);	
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -