// Widget argument: Image cache will be cleared when the given widget is disposed public FileIconCache(@NotNull Widget disposeWidget) { this.disposeWidget = disposeWidget; disposeWidget.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { for (Image image : fileIconMap.values()) image.dispose(); fileIconMap.clear(); } }); }
/** * Dispose of the resource manager when the widget is disposed * * @param widget * @param resources */ public static void hookDisposal(Widget widget, final ResourceManager resources) { if (widget == null || resources == null) return; widget.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { resources.dispose(); } }); }
/** * This method should be called by *all* Widgets which use resources provided by this * SWTResourceManager. When widgets are disposed, they are removed from the "users" Vector, and * when no more registered Widgets are left, all resources are disposed. * * <p>If this method is not called for all Widgets then it should not be called at all, and the * "dispose" method should be explicitly called after all resources are no longer being used. */ public static void registerResourceUser(Widget widget) { if (users.contains(widget)) return; users.add(widget); widget.addDisposeListener(disposeListener); }