Java Code Examples for org.eclipse.swt.widgets.Shell#addDisposeListener()

The following examples show how to use org.eclipse.swt.widgets.Shell#addDisposeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DiskWindow.java    From AppleCommander with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Setup the Disk window and display (open) it.
 */
public void open() {
	shell = new Shell(parentShell, SWT.SHELL_TRIM);
	shell.setLayout(new FillLayout());
	shell.setImage(imageManager.get(ImageManager.ICON_DISK));
	setStandardWindowTitle();
	shell.addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent event) {
				dispose(event);
			}
		});
		
	CTabFolder tabFolder = new CTabFolder(shell, SWT.BOTTOM);
	new DiskExplorerTab(tabFolder, disks, imageManager, this);
	diskMapTabs = new DiskMapTab[disks.length];
	for (int i=0; i<disks.length; i++) {
		if (disks[i].supportsDiskMap()) {
			diskMapTabs[i] = new DiskMapTab(tabFolder, disks[i]);
		}
	}
	diskInfoTab = new DiskInfoTab(tabFolder, disks);
	tabFolder.setSelection(tabFolder.getItems()[0]);
	
	
	shell.open();
}
 
Example 2
Source File: DrawableToolTip.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Creates a drawable tool tip instance.
 *
 * @param parent The parent composite.
 */
public DrawableToolTip(Composite parent) {
    fToolTipShell = new Shell(parent.getShell(), SWT.ON_TOP);
    fToolTipShell.setLayout(new RowLayout());
    fToolTipShell.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    fToolTipShell.addPaintListener(this);
    fToolTipShell.setSize(SHELL_WIDTH, SHELL_HEIGHT);
    fToolTipShell.addDisposeListener((e) -> {
        for (int i = 0; i < fColors.length; i++) {
            fColors[i].dispose();
        }
    });

    fColors = new Color[NUMBER_STEPS];
    int greenBlue = BASE_GREEN_BLUE_VALUE;
    final int step = COLOR_STEP;
    for (int i = 0; i < fColors.length; i++) {
        fColors[i] = new Color(Display.getDefault(), BASE_RED_VALUE, greenBlue, greenBlue);
        greenBlue -= step;
    }
}
 
Example 3
Source File: DualListSnippet.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private static Image createImage(final Shell shell, final String fileName) {
	final Image image = new Image(shell.getDisplay(), DualListSnippet.class.//
			getResourceAsStream("flags/" + fileName + ".png"));
	shell.addDisposeListener(e -> {
		image.dispose();
	});
	return image;
}
 
Example 4
Source File: SWTUtil.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Adds support to resizable dialogs for (re)storing the dialog size.
 *
 * @param dialog
 *          the dialog to add support to
 * @param settings
 *          the dialog settings to store the size in
 * @param dialogKey
 *          the unique key for the dialog
 */
public static void addResizeSupport(Dialog dialog, IDialogSettings settings, String dialogKey) {

  Shell shell = dialog.getShell();
  ShellResizeSupportListener shellSupport = new ShellResizeSupportListener(dialog, settings,
          dialogKey);

  shell.addControlListener(shellSupport);
  shell.addShellListener(shellSupport);
  shell.addDisposeListener(shellSupport);
}
 
Example 5
Source File: ShellFactory.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void open() {
	UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
	if (uiFunctions != null) {
		Boolean bringToFront = (Boolean)getData( "bringToFront" );
		if ( bringToFront == null || bringToFront ){
			Shell mainShell = uiFunctions.getMainShell();
			if (mainShell != null && mainShell.getMinimized()) {
				uiFunctions.bringToFront();
			}
		}
	}

	Shell firstShellWithStyle = Utils.findFirstShellWithStyle(SWT.APPLICATION_MODAL);
	if (firstShellWithStyle != null && firstShellWithStyle != this) {
		// ok, there's a window with application_modal set, which on OSX will mean
		// that if we open our window, it will be on top, but users won't be able
		// to interact with it.  So, wait until the modal window goes away..
		firstShellWithStyle.addDisposeListener(new DisposeListener() {
			@Override
			public void widgetDisposed(DisposeEvent e) {
				// wait for dispose to complete, then run open again to check for
				// any new application modal shells to wait for
				Utils.execSWTThreadLater(0, new AERunnable() {
					@Override
					public void runSupport() {
						AEShell.this.open();
					}
				});
			}
		});
		firstShellWithStyle.setVisible(true);
		firstShellWithStyle.forceActive();
	} else {
		if (!isDisposed()) {
			super.open();
		}
	}
}
 
Example 6
Source File: DualListTextSnippet.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private static List<DLItem> createItems(final Shell shell) {
	final List<DLItem> list = new ArrayList<DLItem>();

	String defaultFontName = null;
	int defaultHeight = -1;
	for (final FontData fontData : shell.getFont().getFontData()) {
		if (defaultFontName == null) {
			defaultFontName = fontData.getName();
		}
		if (defaultHeight == -1) {
			defaultHeight = fontData.getHeight();
		}
	}

	final Font font = new Font(shell.getDisplay(), defaultFontName, defaultHeight, SWT.BOLD);

	list.add(new DLItem("Austria"));
	list.add(new DLItem("Belgium"));
	list.add(new DLItem("Bulgaria"));
	list.add(new DLItem("Cyprus"));
	list.add(new DLItem("Czech Republic"));
	list.add(new DLItem("Denmark"));
	list.add(new DLItem("Estonia"));
	list.add(new DLItem("Finland"));
	list.add(new DLItem("France"));
	list.add(new DLItem("Germany"));
	list.add(new DLItem("Greece"));
	list.add(new DLItem("Hungary"));
	list.add(new DLItem("Ireland"));
	list.add(new DLItem("Italy"));
	list.add(new DLItem("Latvia"));
	list.add(new DLItem("Lithuania"));
	list.add(new DLItem("Luxembourg"));
	list.add(new DLItem("Malta"));
	list.add(new DLItem("Netherlands"));
	list.add(new DLItem("Poland"));
	list.add(new DLItem("Portugal"));
	list.add(new DLItem("Romania"));
	list.add(new DLItem("Slovakia"));
	list.add(new DLItem("Slovenia"));
	list.add(new DLItem("Spain"));
	list.add(new DLItem("Sweden"));
	list.add(new DLItem("United Kingdom"));

	shell.addDisposeListener(e -> {
		font.dispose();
	});

	return list;
}
 
Example 7
Source File: DualListSnippet.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private static List<DLItem> createItems(final Shell shell) {
	final List<DLItem> list = new ArrayList<>();

	String defaultFontName = null;
	int defaultHeight = -1;
	for (final FontData fontData : shell.getFont().getFontData()) {
		if (defaultFontName == null) {
			defaultFontName = fontData.getName();
		}
		if (defaultHeight == -1) {
			defaultHeight = fontData.getHeight();
		}
	}

	final Font font = new Font(shell.getDisplay(), defaultFontName, defaultHeight, SWT.BOLD);

	list.add(new DLItem("Austria", createImage(shell, "austria")));
	list.add(new DLItem("Belgium", createImage(shell, "belgium")));
	list.add(new DLItem("Bulgaria", createImage(shell, "bulgaria")));
	list.add(new DLItem("Cyprus", createImage(shell, "cyprus")));
	list.add(new DLItem("Czech Republic", createImage(shell, "czech")));
	list.add(new DLItem("Denmark", createImage(shell, "denmark")));
	list.add(new DLItem("Estonia", createImage(shell, "estonia")));
	list.add(new DLItem("Finland", createImage(shell, "finland")));
	list.add(new DLItem("France", createImage(shell, "france"), font));
	list.add(new DLItem("Germany", createImage(shell, "germany")));
	list.add(new DLItem("Greece", createImage(shell, "greece")));
	list.add(new DLItem("Hungary", createImage(shell, "hungary")));
	list.add(new DLItem("Ireland", createImage(shell, "ireland")));
	list.add(new DLItem("Italy", createImage(shell, "italy")));
	list.add(new DLItem("Latvia", createImage(shell, "latvia")));
	list.add(new DLItem("Lithuania", createImage(shell, "lithuania")));
	list.add(new DLItem("Luxembourg", createImage(shell, "luxembourg")));
	list.add(new DLItem("Malta", createImage(shell, "malta")));
	list.add(new DLItem("Netherlands", createImage(shell, "netherlands")));
	list.add(new DLItem("Poland", createImage(shell, "poland"), shell.getDisplay().getSystemColor(SWT.COLOR_WHITE), shell.getDisplay().getSystemColor(SWT.COLOR_RED)));
	list.add(new DLItem("Portugal", createImage(shell, "portugal")));
	list.add(new DLItem("Romania", createImage(shell, "romania")));
	list.add(new DLItem("Slovakia", createImage(shell, "slovakia")));
	list.add(new DLItem("Slovenia", createImage(shell, "slovenia")));
	list.add(new DLItem("Spain", createImage(shell, "spain")));
	list.add(new DLItem("Sweden", createImage(shell, "sweden")));
	list.add(new DLItem("United Kingdom", createImage(shell, "unitedkingdom")));

	shell.addDisposeListener(e -> {
		font.dispose();
	});

	return list;
}
 
Example 8
Source File: ExporterDialog.java    From Rel with Apache License 2.0 4 votes vote down vote up
/**
 * Create contents of the dialog.
 */
private void createContents() {
	shlExportToFile = new Shell(getParent(), getStyle());
	shlExportToFile.addDisposeListener(new DisposeListener() {
		public void widgetDisposed(DisposeEvent e) {
			lastPath = exportDialog.getFileName();
		}
	});
	shlExportToFile.setSize(600, 200);
	shlExportToFile.setText("Export to File");
	shlExportToFile.setLayout(new FormLayout());
	
	Group group = new Group(shlExportToFile, SWT.NONE);
	FormData fd_group = new FormData();
	fd_group.top = new FormAttachment(0, 10);
	fd_group.right = new FormAttachment(100, -10);
	group.setLayoutData(fd_group);
	
	btnRadioButtonCSV = new Button(group, SWT.RADIO);
	btnRadioButtonCSV.addListener(SWT.Selection, e -> setupExportToCSV());
	btnRadioButtonCSV.setBounds(10, 10, 484, 18);
	btnRadioButtonCSV.setText("CSV text file");
	btnRadioButtonCSV.setSelection(true);
	
	btnRadioButtonXLS = new Button(group, SWT.RADIO);
	btnRadioButtonXLS.addListener(SWT.Selection, e -> setupExportToXLS());
	btnRadioButtonXLS.setBounds(10, 34, 484, 18);
	btnRadioButtonXLS.setText("Excel spreadsheet file (.XLS)");
	
	btnRadioButtonXLSX = new Button(group, SWT.RADIO);
	btnRadioButtonXLSX.addListener(SWT.Selection, e -> setupExportToXLSX());
	btnRadioButtonXLSX.setBounds(10, 58, 484, 18);
	btnRadioButtonXLSX.setText("Excel spreadsheet file (.XLSX)");
	
	Label lblExportTo = new Label(shlExportToFile, SWT.NONE);
	fd_group.left = new FormAttachment(lblExportTo, 6);
	FormData fd_lblExportTo = new FormData();
	fd_lblExportTo.top = new FormAttachment(0, 10);
	fd_lblExportTo.left = new FormAttachment(0, 10);
	lblExportTo.setLayoutData(fd_lblExportTo);
	lblExportTo.setText("Export to:");
	
	Button btnExport = new Button(shlExportToFile, SWT.NONE);
	btnExport.addListener(SWT.Selection, e -> doExport());
	FormData fd_btnExport = new FormData();
	fd_btnExport.top = new FormAttachment(group, 6);
	fd_btnExport.right = new FormAttachment(100, -10);
	btnExport.setLayoutData(fd_btnExport);
	btnExport.setText("Export");
	
	Button btnCancel = new Button(shlExportToFile, SWT.NONE);
	btnCancel.addListener(SWT.Selection, e -> close());
	btnCancel.setSelection(true);
	FormData fd_btnNewButton = new FormData();
	fd_btnNewButton.top = new FormAttachment(group, 6);
	fd_btnNewButton.right = new FormAttachment(btnExport, -10);
	btnCancel.setLayoutData(fd_btnNewButton);
	btnCancel.setText("Cancel");
	
	shlExportToFile.pack();
}