SWT Dialog

31 December 2007

Dialog class is the abstract superclass of the classes that represent the built in platform dialogs. A Dialog typically contains other widgets that are not accessible. A Dialog is not a Widget.

This class can also be used as the abstract superclass for user-designed dialogs. Such dialogs usually consist of a Shell with child widgets. The basic template for a user-defined dialog typically looks something like this:

 import org.eclipse.swt.*;
 import org.eclipse.swt.widgets.*;
 import org.eclipse.swt.layout.*;
 
 public class SWTDialog extends Dialog {
	Object result;
 
	public SWTDialog (Shell parent, int style) {
		super (parent, style);
	}
	public SWTDialog (Shell parent) {
		this (parent, 0); // your default style bits go here (not the Shell's style bits)
	}
	public Object open () {
		Shell parent = getParent();
		Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
		shell.setText(getText());
		// Your code goes here (widget creation, set result, etc).
		shell.open();
		Display display = parent.getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		return result;
	}
 }

Please note that the modality styles supported by this class must be treated as HINTs, because not all are supported by every subclass on every platform. If a modality style is not supported, it is “upgraded” to a more restrictive modality style that is supported. For example, if PRIMARY_MODAL is not supported by a particular dialog, it would be upgraded to APPLICATION_MODAL. In addition, as is the case for shells, the window manager for the desktop on which the instance is visible has ultimate control over the appearance and behavior of the instance, including its modality.

The styles supported by Dialog are: APPLICATION_MODAL, PRIMARY_MODAL, SYSTEM_MODAL. Please note that only one of the styles APPLICATION_MODAL, PRIMARY_MODAL, and SYSTEM_MODAL may be specified.

The following are the important constructors of Dialog class.

Dialog(Shell parent)
Constructs a new instance of this class given only its parent.

Dialog(Shell parent, int style)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

The following are the important methods of Dialog class.

protected void checkSubclass()
Checks that this class can be subclassed.

Shell getParent()
Returns the receiver’s parent, which must be a Shell or null.

int getStyle()
Returns the receiver’s style information.

String getText()
Returns the receiver’s text, which is the string that the window manager will typically display as the receiver’s title.

void setText(String string)
Sets the receiver’s text, which is the string that the window manager will typically display as the receiver’s title, to the argument, which must not be null.

del.icio.us:SWT Dialog  digg:SWT Dialog  spurl:SWT Dialog  wists:SWT Dialog  simpy:SWT Dialog  newsvine:SWT Dialog  blinklist:SWT Dialog  furl:SWT Dialog  reddit:SWT Dialog  fark:SWT Dialog  blogmarks:SWT Dialog  Y!:SWT Dialog  smarking:SWT Dialog  magnolia:SWT Dialog  segnalo:SWT Dialog  gifttagging:SWT Dialog

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: SWT Dialog

Leave a Reply