Java Code Examples for org.eclipse.swt.widgets.Display#addListener()

The following examples show how to use org.eclipse.swt.widgets.Display#addListener() . These examples are extracted from open source projects. 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 Project: arx   File: Resources.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Loads an image. Adds a dispose listener that disposes the image when the display is disposed
 * @param display
 * @param resource
 * @return
 */
private static final Image getImage(Display display, String resource) {
    InputStream stream = Resources.class.getResourceAsStream(resource);
    try {
        final Image image = new Image(display, stream);
        display.addListener(SWT.Dispose, new Listener() {
            public void handleEvent(Event arg0) {
                if (image != null && !image.isDisposed()) {
                    image.dispose();
                }
            }
        });
        return image;
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
                // Ignore silently
            }
        }
    }
}
 
Example 2
Source Project: nebula   File: SWTGraphicUtil.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Create a color that is disposed automatically
 *
 * @param r red component
 * @param g green component
 * @param b blue component
 * @return the color
 */
public static Color getColorSafely(final int r, final int g, final int b) {
	final Display display = Display.getCurrent();
	final Color color = new Color(display, r, g, b);
	display.addListener(SWT.Dispose, e -> {
		if (!color.isDisposed()) {
			color.dispose();
		}
	});
	return color;
}
 
Example 3
public Object start(IApplicationContext context) throws Exception {
	OpenDocumentEventProcessor openDocProcessor = new OpenDocumentEventProcessor();

	Display display = PlatformUI.createDisplay();
	display.addListener(SWT.OpenDocument, openDocProcessor);

	try {
		IProduct product = Platform.getProduct();
		String id = product.getId();
		String hsVersion = "";
		if (id.equals("net.heartsome.cat.te.tmx_editor_product")) {
			hsVersion = "F";
		}
		System.getProperties().put("TSVersion", "88");
		System.getProperties().put("TSEdition", hsVersion);

		String versionDate = System.getProperty("date", "");
		String version = System.getProperty("version", "");
		System.getProperties().put("TSVersionDate", version + "." + versionDate);
		checkCleanValue();

		int returnCode = PlatformUI.createAndRunWorkbench(display,
				new ApplicationWorkbenchAdvisor(openDocProcessor));
		if (returnCode == PlatformUI.RETURN_RESTART)
			return IApplication.EXIT_RESTART;
		else
			return IApplication.EXIT_OK;
	} finally {
		display.dispose();
	}

}
 
Example 4
Source Project: goclipse   File: HTMLPrinter.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private static void installColorUpdater(final Display display) {
	display.addListener(SWT.Settings, new Listener() {
		@Override
		public void handleEvent(Event event) {
			cacheColors(display);
		}
	});
}