FileDocCategorySizeDatePackage
ModalEventFilter.javaAPI DocJava SE 6 API6651Tue Jun 10 00:25:18 BST 2008java.awt

ModalEventFilter

public abstract class ModalEventFilter extends Object implements EventFilter

Fields Summary
protected Dialog
modalDialog
protected boolean
disabled
Constructors Summary
protected ModalEventFilter(Dialog modalDialog)

        this.modalDialog = modalDialog;
        disabled = false;
    
Methods Summary
public FilterActionacceptEvent(java.awt.AWTEvent event)

        if (disabled || !modalDialog.isVisible()) {
            return FilterAction.ACCEPT;
        }
        int eventID = event.getID();
        if ((eventID >= MouseEvent.MOUSE_FIRST &&
             eventID <= MouseEvent.MOUSE_LAST) ||
            (eventID >= ActionEvent.ACTION_FIRST &&
             eventID <= ActionEvent.ACTION_LAST) ||
            eventID == WindowEvent.WINDOW_CLOSING)
        {
            Object o = event.getSource();
            if (o instanceof sun.awt.ModalExclude) {
                // Exclude this object from modality and
                // continue to pump it's events.
            } else if (o instanceof Component) {
                Component c = (Component)o;
                while ((c != null) && !(c instanceof Window)) {
                    c = c.getParent_NoClientCode();
                }
                if (c != null) {
                    return acceptWindow((Window)c);
                }
            }
        }
        return FilterAction.ACCEPT;
    
protected abstract FilterActionacceptWindow(java.awt.Window w)

intcompareTo(java.awt.ModalEventFilter another)

        Dialog anotherDialog = another.getModalDialog();
        // check if modalDialog is from anotherDialog's hierarchy
        //   or vice versa
        Component c = modalDialog;
        while (c != null) {
            if (c == anotherDialog) {
                return 1;
            }
            c = c.getParent_NoClientCode();
        }
        c = anotherDialog;
        while (c != null) {
            if (c == modalDialog) {
                return -1;
            }
            c = c.getParent_NoClientCode();
        }
        // check if one dialog blocks (directly or indirectly) another
        Dialog blocker = modalDialog.getModalBlocker();
        while (blocker != null) {
            if (blocker == anotherDialog) {
                return -1;
            }
            blocker = blocker.getModalBlocker();
        }
        blocker = anotherDialog.getModalBlocker();
        while (blocker != null) {
            if (blocker == modalDialog) {
                return 1;
            }
            blocker = blocker.getModalBlocker();
        }
        // compare modality types
        return modalDialog.getModalityType().compareTo(anotherDialog.getModalityType());
    
static java.awt.ModalEventFiltercreateFilterForDialog(java.awt.Dialog modalDialog)

        switch (modalDialog.getModalityType()) {
            case DOCUMENT_MODAL: return new DocumentModalEventFilter(modalDialog);
            case APPLICATION_MODAL: return new ApplicationModalEventFilter(modalDialog);
            case TOOLKIT_MODAL: return new ToolkitModalEventFilter(modalDialog);
        }
        return null;
    
voiddisable()

        disabled = true;
    
java.awt.DialoggetModalDialog()

        return modalDialog;