FileDocCategorySizeDatePackage
ShellManager.javaAPI DocAzureus 3.0.3.47449Mon Jul 24 04:13:20 BST 2006org.gudy.azureus2.ui.swt.components.shell

ShellManager

public class ShellManager extends Object
ShellManager provides a logical grouping for a set of shells

Note: This class must be used from the SWT display thread

version
1.0
author
James Yeh
see
org.eclipse.jface.window.WindowManager

Fields Summary
private static ShellManager
instance
private final Collection
shells
private final List
addHandlers
private final List
removeHandlers
Constructors Summary
Methods Summary
public final voidaddWindow(org.eclipse.swt.widgets.Shell shell)
Adds a shell to the shell manager. If the shell is already managed, it is not added again.

Note: This method must be invoked by the SWT display thread

param
shell A SWT Shell

        //Debug.out("Invoked by thread " + Thread.currentThread().getName());
        if(shells.contains(shell)) {return;}

        shells.add(shell);
        notifyAddListeners(shell);
        shell.addDisposeListener(new DisposeListener()
        {
            public void widgetDisposed(DisposeEvent event)
            {
            	try {
                removeWindow(shell);
            	} catch (Exception e) {
            		Logger.log(new LogEvent(LogIDs.GUI, "removeWindow", e));
            	}
            }
        });
        shell.addListener(SWT.Show, new Listener() {
        	public void handleEvent(Event event) {
        		Utils.verifyShellRect(shell, false);
        	}
        });
    
public final voidaddWindowAddedListener(org.eclipse.swt.widgets.Listener listener)

Adds a listener that will be invoked when a shell has been added to the ShellManager

The listener and the shell will automatically be removed when the shell is disposed

param
listener A SWT Listener

        addHandlers.add(listener);
    
public final voidaddWindowRemovedListener(org.eclipse.swt.widgets.Listener listener)
Adds a listener that will be invoked when a shell has been removed from the ShellManager

param
listener A SWT Listener

        removeHandlers.add(listener);
    
protected final java.util.CollectiongetManagedShellSet()
Gets the set of managed shells

return
The set

        return shells;
    
protected org.eclipse.swt.widgets.EventgetSWTEvent(org.eclipse.swt.widgets.Shell shell)

Gets a generated SWT Event based on the shell

The widget field of the event should be set to the shell

param
shell A SWT Shell
return
The event

        Event e = new Event();
        e.widget = shell;
        e.item = shell;
        return e;
    
public final intgetSize()
Gets the number of shells the ShellManager manages

return
The number

        return shells.size();
    
public final java.util.IteratorgetWindows()

Gets the shells managed by the manager as an Iterator

The order in which the shells were added are retained.

Note: This method must be invoked by the SWT display thread

return
The iterator

        return shells.iterator();
    
public final booleanisEmpty()
Gets whether the ShellManager manages no shells

return
True if ShellManager is empty

        return shells.isEmpty();
    
protected final voidnotifyAddListeners(org.eclipse.swt.widgets.Shell sender)
Notifies the WindowAddedListener handlers

param
sender A SWT shell that "sends" the events

        Iterator iter = addHandlers.iterator();
        for(int i = 0; i < addHandlers.size(); i++)
        {
            ((Listener)iter.next()).handleEvent(getSWTEvent(sender));
        }
    
protected final voidnotifyRemoveListeners(org.eclipse.swt.widgets.Shell sender)
Notifies the WindowRemovedListener handlers

param
sender A SWT shell that "sends" the events

        Iterator iter = removeHandlers.iterator();
        for(int i = 0; i < removeHandlers.size(); i++)
        {
            ((Listener)iter.next()).handleEvent(getSWTEvent(sender));
        }
    
public final voidperformForShells(org.eclipse.swt.widgets.Listener command)

Invokes the handleEvent method specified by the SWT listener for each managed shell

The event's widget is set to the reference of the shell invoking it

param
command A command implemented as a SWT Listener

        Iterator iter = shells.iterator();
        for(int i = 0; i < shells.size(); i++)
        {
            Shell aShell = (Shell)iter.next();
            Event evt = new Event();
            evt.widget = aShell;
            evt.data = this;
            command.handleEvent(evt);
        }
    
public final voidremoveWindow(org.eclipse.swt.widgets.Shell shell)
Removes a shell from the shell manager

Note: This method must be invoked by the SWT display thread

param
shell A SWT Shell

        shells.remove(shell);
        notifyRemoveListeners(shell);
    
public final voidremoveWindowAddedListener(org.eclipse.swt.widgets.Listener listener)
Removes a listener that will be invoked when a shell has been added to the ShellManager

param
listener A SWT Listener

        addHandlers.remove(listener);
    
public final voidremoveWindowRemovedListener(org.eclipse.swt.widgets.Listener listener)
Removes a listener that will be invoked when a shell has been removed from the ShellManager

param
listener A SWT Listener

        removeHandlers.remove(listener);
    
public static final org.gudy.azureus2.ui.swt.components.shell.ShellManagersharedManager()

Gets the application's shared shell manager

This ShellManager has no bearing on other ShellManager instances

Note: This method must be invoked by the SWT display thread

return


    
    
        instance = new ShellManager();
    
        return instance;