use of org.eclipse.swt.graphics.Resource in project eclipse.platform.swt by eclipse.
the class GradientDialog method open.
/**
* Sets up the dialog and opens it.
*/
public int open() {
final Shell dialog = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.RESIZE | getStyle());
// $NON-NLS-1$
dialog.setText(GraphicsExample.getResourceString("Gradient"));
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
gridLayout.marginHeight = 10;
gridLayout.marginWidth = 10;
dialog.setLayout(gridLayout);
// create the controls in the dialog
createDialogControls(dialog);
dialog.addListener(SWT.Close, event -> {
for (int i = 0; i < resources.size(); i++) {
Object obj = resources.get(i);
if (obj != null && obj instanceof Resource) {
((Resource) obj).dispose();
}
}
dialog.dispose();
});
dialog.setDefaultButton(okButton);
dialog.pack();
Rectangle rect = getParent().getMonitor().getBounds();
Rectangle bounds = dialog.getBounds();
dialog.setLocation(rect.x + (rect.width - bounds.width) / 2, rect.y + (rect.height - bounds.height) / 2);
dialog.setMinimumSize(bounds.width, bounds.height);
dialog.open();
Display display = getParent().getDisplay();
while (!dialog.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
if (menu1 != null) {
menu1.dispose();
menu1 = null;
}
if (menu2 != null) {
menu2.dispose();
menu2 = null;
}
return returnVal;
}