package com.impart.kurs.swt;

import java.net.URL;

import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class Main extends ApplicationWindow {
	
	// um jface zu benutzen, muessen die folgenden libraries eingebunden sein
	// org.eclipse.jface_3.1.1.jar
	// org.eclipse.swt.win32.x86_3.1.2.jar
	// org.eclipse.core.runtime_3.1.2.jar

	Shell shell = null;
	ImageRegistry imageRegistry=null;
	
	public Main() {
		super(null);
	}
	
	protected Control createContents(Composite parent) {
		
		final Text txtName=new Text(shell,SWT.SINGLE);
		txtName.setBounds(100,60,100,20);
		txtName.setTextLimit(10);
		
		return parent;
	}
	
	protected void configureShell(Shell shell) {
		
		this.shell = shell;
		imageRegistry=new ImageRegistry();
//		fontRegistry = new FontRegistry();
		
		Image appImg = null;
		URL imgUrl = this.getClass().getResource("myapp.gif");
		appImg = new Image(shell.getDisplay(), imgUrl.getPath());
		imageRegistry.put("myapp",appImg);
		
		shell.setText("Uebung 100");
        shell.setImage(appImg);
        shell.setSize(400,300);
        
//        shell.getDisplay().syncExec(new Thread());
//        shell.getDisplay().asyncExec(new Thread());
	}
	
	public boolean close() {
		imageRegistry.dispose();
		return super.close();
	}

	public static void main(String[] args) {
		Main window=new Main();
		window.setBlockOnOpen(true);
		window.open();
	}
}