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

📄 toolkit.java

📁 kaffe是一个java虚拟机的源代码。里面包含了一些java例程和标准的java包。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package java.awt;import java.awt.ImageNativeProducer;import java.awt.datatransfer.Clipboard;import java.awt.datatransfer.Transferable;import java.awt.event.InputEvent;import java.awt.image.ColorModel;import java.awt.image.ImageObserver;import java.awt.image.ImageProducer;import java.awt.peer.ComponentPeer;import java.awt.peer.LightweightPeer;import java.awt.peer.WindowPeer;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.PrintStream;import java.net.URL;import java.util.Properties;import kaffe.io.NullOutputStream;import kaffe.util.Ptr;import kaffe.util.log.LogClient;import kaffe.util.log.LogStream;/** * Toolkit - used to be an abstract factory for peers, but since we don't have * peers, it is just a simple anchor for central mechanisms (like System- * EventQueue etc.) and a wrapper for all native methods. Of course, it is a * singleton. * * Copyright (c) 1998 *      Transvirtual Technologies, Inc.  All rights reserved. * * See the file "license.terms" for information on usage and redistribution  * of this file.  * * @author P.C.Mehlitz */class FlushThread  extends Thread{	boolean stop;	int flushInterval;FlushThread ( int interval ) {	super( "AWT-Flusher");	flushInterval = interval;	setPriority( Thread.MIN_PRIORITY + 1);}public void run () {	while ( !stop ) {		Toolkit.tlkFlush();		try {			Thread.sleep( flushInterval);		}		catch ( Exception x ) {}	}}void stopFlushing () {	stop = true;}}class NativeCollector  extends Thread{NativeCollector () {	super( "AWT-native");}public void run () {        	// this does not return until the we shut down the system, since it	// consititutes the native dispatcher loop. Don't be confused about	// tlkInit being a sync method. It gives up the lock in the native	// layer before falling into its dispatcher loop	try {		if ( !Toolkit.tlkInit( System.getProperty( "awt.display")) ) {			throw new AWTError( "native layer init failed");		}	} catch ( Throwable x ) {		x.printStackTrace();	}}}public class Toolkit{	static Toolkit singleton;	static Dimension screenSize;	static int resolution;	static EventQueue eventQueue;	static EventDispatchThread eventThread;	static NativeClipboard clipboard;	static LightweightPeer lightweightPeer = new LightweightPeer() {};	static ComponentPeer componentPeer = new ComponentPeer() {};	static WindowPeer windowPeer = new WindowPeer() {};	static FlushThread flushThread;	static NativeCollector collectorThread;	static int flags;	final static int FAILED = -1;	final static int IS_BLOCKING = 1;	final static int IS_DISPATCH_EXCLUSIVE = 2;	final static int NEEDS_FLUSH = 4;	final static int NATIVE_DISPATCHER_LOOP = 8;	final static int EXTERNAL_DECO = 16;static {	System.loadLibrary( "awt");	flags = tlkProperties();		// hack to please swings default look and feel init	// ( no utsname support for System.c , so default is 'Unknown' )		Properties p = System.getProperties();	String osn = p.getProperty( "os.name");	if ( (osn == null) || !(osn.startsWith("Windows"))) {		p.put( "os.name", "Windows" );	}	if ( (flags & NATIVE_DISPATCHER_LOOP) == 0 ) {		if ( !tlkInit( System.getProperty( "awt.display")) ) {			throw new AWTError( "native layer initialization failed");		}		initToolkit();	}	else {		// Not much we can do here, we have to delegate the native init		// to a own thread since tlkInit() doesn't return. Wait for this		// thread to flag that initialization has been completed		collectorThread = new NativeCollector();		collectorThread.start();		try {			synchronized ( Toolkit.class ) {				while ( singleton == null ) {					Toolkit.class.wait();				}			}		}		catch ( Exception x ) {			x.printStackTrace();		}	}}Toolkit () {}public void beep () {	tlkBeep();}native static synchronized Ptr btnCreateCheckbox ( Ptr parent, String label );native static synchronized Ptr btnCreatePushbutton ( Ptr parent, String label );native static synchronized Ptr btnCreateRadiobutton ( Ptr parent, String label );native static synchronized boolean btnGetCheck ( Ptr data);native static synchronized void btnSetCheck ( Ptr data, boolean check );native static synchronized void btnSetGrouped ( Ptr data, boolean grouped);native static synchronized void btnSetLabel ( Ptr data, String label );native static synchronized void cbdFreeClipboard ( Ptr cbdData );native static synchronized Transferable cbdGetContents( Ptr cbdData);native static synchronized Ptr cbdInitClipboard ();native static synchronized boolean cbdSetOwner ( Ptr cbdData );public int checkImage(Image image, int width, int height, ImageObserver observer) {	return (image.checkImage( width, height, observer, false));}native static synchronized void choiceAppendItem( Ptr data, String item);native static synchronized Ptr choiceCreateChoice( Ptr parent);native static synchronized void choiceInsertItem( Ptr data, String item, int idx);native static synchronized void choiceRemoveAll( Ptr data);native static synchronized void choiceRemoveItem( Ptr data, int idx);native static synchronized void choiceSelectItem( Ptr data, int idx);native static synchronized long clrBright ( int rgbValue );native static synchronized long clrDark ( int rgbValue );native static synchronized int clrGetPixelValue ( int rgb );native static synchronized int clrSetSystemColors ( int[] sysClrs );native static synchronized void cmnDestroyWindow ( Ptr wndData );native static synchronized Dimension cmnGetPreferredSize ( Ptr data);native static synchronized void cmnInvalidate ( Ptr data, int x, int y, int w, int h );native static synchronized void cmnSetBackground ( Ptr data, int clr );native static synchronized void cmnSetBounds ( Ptr data, int x, int y, int w, int h);native static synchronized void cmnSetCursor ( Ptr data, int type);native static synchronized void cmnSetEnabled ( Ptr data, boolean en );native static synchronized void cmnSetFocus ( Ptr data);native static synchronized void cmnSetFont ( Ptr data, Ptr fntData );native static synchronized void cmnSetForeground ( Ptr data, int clr );native static synchronized void cmnSetVisible ( Ptr data, boolean vis );native static synchronized void cmnValidate ( Ptr data );public Image createImage ( ImageProducer producer ) {	return new Image( producer);}public Image createImage ( byte[] imageData ) {	return createImage( imageData, 0, imageData.length);}public Image createImage ( byte[] imagedata, int imageoffset, int imagelength ) {	return new Image( imagedata, imageoffset, imagelength);}ComponentPeer createLightweight ( Component c ) {	// WARNING! this is just a dummy to enable checks like	// "..getPeer() != null.. or ..peer instanceof LightweightPeer..	// see createWindow()	return lightweightPeer;}static void createNative ( Component c ) {	WMEvent e = null;	synchronized ( Toolkit.class ) {		// even if this could be done in a central location, we defer this		// as much as possible because it might involve polling (for non-threaded		// AWTs), slowing down the startup time		if ( eventThread == null ) {			startDispatch();		}	}	// do we need some kind of a context switch ?	if ( (flags & IS_DISPATCH_EXCLUSIVE) != 0 ){		if ( (flags & NATIVE_DISPATCHER_LOOP) != 0 ){			if ( Thread.currentThread() != collectorThread ){				// this is beyond our capabilities (there is no Java message entry we can call				// in the native collector), we have to revert to some native mechanism				e =  WMEvent.getEvent( c, WMEvent.WM_CREATE);				evtSendWMEvent( e);			}		}		else {			if ( Thread.currentThread() != eventThread ){				// we can force the context switch by ourselves, no need to go native				e =  WMEvent.getEvent( c, WMEvent.WM_CREATE);				eventQueue.postEvent( e);			}		}					// Ok, we have a request out there, wait for it to be served		if ( e != null ) {			// we should check for nativeData because the event might			// already be processed (depending on the thread system)			while ( c.getNativeData() == null ) {				synchronized ( e ) {					try { e.wait(); } 					catch ( InterruptedException x ) {}				} 			}							return;		}	}	else {		// no need to switch threads, go native right away		c.createNative();	}}protected WindowPeer createWindow ( Window w ) {	// WARNING! this is just a dummy to enable checks like	// "..getPeer() != null.. or ..peer instanceof LightweightPeer..	// it is NOT a real peer support. The peer field just exists to	// check if a Component already passed its addNotify()/removeNotify().	// This most probably will be removed once the "isLightweightComponent()"	// method gets official (1.2?)	return windowPeer;}static void destroyNative ( Component c ) {	WMEvent e = null;	// do we need some kind of a context switch ?	if ( (flags & IS_DISPATCH_EXCLUSIVE) != 0 ){		if ( (flags & NATIVE_DISPATCHER_LOOP) != 0 ){			if ( Thread.currentThread() != collectorThread ){				// this is beyond our capabilities (there is no Java message entry we can call				// in the native collector), we have to revert to some native mechanism				e =  WMEvent.getEvent( c, WMEvent.WM_DESTROY);				evtSendWMEvent( e);			}		}		else {			if ( Thread.currentThread() != eventThread ){				// we can force the context switch by ourselves, no need to go native				e =  WMEvent.getEvent( c, WMEvent.WM_DESTROY);				eventQueue.postEvent( e);			}		}					// Ok, we have a request out there, wait for it to be served		if ( e != null ) {			// we should check for nativeData because the event might			// already be processed (depending on the thread system)			while ( c.getNativeData() != null ) {				synchronized ( e ) {					try { e.wait(); } catch ( InterruptedException x ) {}				} 			}							return;		}	}	else {		// no need to switch threads, go native right away		c.destroyNative();	}}native static synchronized void editAppend( Ptr data, String txt);native static synchronized Ptr editCreateArea( Ptr parent, String txt, int style);native static synchronized Ptr editCreateField( Ptr parent, String txt);native static synchronized int editGetCaretPosition( Ptr data);native static synchronized String editGetSelectedText( Ptr data);native static synchronized int editGetSelectionEnd( Ptr data);native static synchronized int editGetSelectionStart( Ptr data);native static synchronized String editGetText( Ptr data);native static synchronized void editInsert( Ptr data, String txt, int idx);native static synchronized void editReplaceRange( Ptr data, String txt, int start, int end);native static synchronized void editSelect( Ptr data, int start, int end);native static synchronized void editSelectAll( Ptr data);native static synchronized void editSetCaretPosition( Ptr data, int idx);native static synchronized int editSetEchoChar( Ptr data, char c);native static synchronized void editSetEditable( Ptr data, boolean edit);native static synchronized void editSetSelectionEnd( Ptr data, int idx);native static synchronized void editSetSelectionStart( Ptr data, int idx);native static synchronized void editSetText( Ptr data, String txt);native static synchronized AWTEvent evtGetNextEvent ();native static synchronized Component[] evtInit ();native static synchronized AWTEvent evtPeekEvent ();native static synchronized AWTEvent evtPeekEventId ( int eventId );native static synchronized int evtRegisterSource ( Ptr wndData );native static synchronized void evtSendWMEvent ( WMEvent e );native static synchronized int evtUnregisterSource ( Ptr wndData );native static synchronized void evtWakeup ();native static synchronized String fdlgLoad ( Ptr owner, String title, String dir, String file, String filter );native static synchronized String fdlgSave ( Ptr owner, String title, String dir, String file, String filter );native static synchronized int fntBytesWidth ( Ptr fmData, byte[] data, int off, int len );native static synchronized int fntCharWidth ( Ptr fmData, char c );native static synchronized int fntCharsWidth ( Ptr fmData, char[] data, int off, int len );native static synchronized void fntFreeFont ( Ptr fontData );native static synchronized void fntFreeFontMetrics ( Ptr fmData );native static synchronized int fntGetAscent ( Ptr fmData);native static synchronized int fntGetDescent ( Ptr fmData);native static synchronized int fntGetFixedWidth ( Ptr fmData);native static synchronized int fntGetHeight ( Ptr fmData);

⌨️ 快捷键说明

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