Java Code Examples for java.awt.event.WindowEvent#WINDOW_CLOSING

The following examples show how to use java.awt.event.WindowEvent#WINDOW_CLOSING . 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: serverMain.java    From fei_Q with GNU General Public License v2.0 6 votes vote down vote up
protected void processWindowEvent(WindowEvent e)
{
	if (e.getID() == WindowEvent.WINDOW_CLOSING)
	{
		String sql_update = "update mainInfo set status = 0;";
		dispose();
		try
		{
			con1.createStatement().execute(sql_update);
		}
		catch (SQLException e1)
		{
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		System.exit(0);
	}
	else
	{
		super.processWindowEvent(e);
	}
}
 
Example 2
Source File: JFrame.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Processes window events occurring on this component.
 * Hides the window or disposes of it, as specified by the setting
 * of the <code>defaultCloseOperation</code> property.
 *
 * @param  e  the window event
 * @see    #setDefaultCloseOperation
 * @see    java.awt.Window#processWindowEvent
 */
protected void processWindowEvent(final WindowEvent e) {
    super.processWindowEvent(e);

    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
        switch (defaultCloseOperation) {
            case HIDE_ON_CLOSE:
                setVisible(false);
                break;
            case DISPOSE_ON_CLOSE:
                dispose();
                break;
            case EXIT_ON_CLOSE:
                // This needs to match the checkExit call in
                // setDefaultCloseOperation
                System.exit(0);
                break;
            case DO_NOTHING_ON_CLOSE:
            default:
        }
    }
}
 
Example 3
Source File: JFrame.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Processes window events occurring on this component.
 * Hides the window or disposes of it, as specified by the setting
 * of the <code>defaultCloseOperation</code> property.
 *
 * @param  e  the window event
 * @see    #setDefaultCloseOperation
 * @see    java.awt.Window#processWindowEvent
 */
protected void processWindowEvent(final WindowEvent e) {
    super.processWindowEvent(e);

    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
        switch (defaultCloseOperation) {
            case HIDE_ON_CLOSE:
                setVisible(false);
                break;
            case DISPOSE_ON_CLOSE:
                dispose();
                break;
            case EXIT_ON_CLOSE:
                // This needs to match the checkExit call in
                // setDefaultCloseOperation
                System.exit(0);
                break;
            case DO_NOTHING_ON_CLOSE:
            default:
        }
    }
}
 
Example 4
Source File: JFrame.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Processes window events occurring on this component.
 * Hides the window or disposes of it, as specified by the setting
 * of the <code>defaultCloseOperation</code> property.
 *
 * @param  e  the window event
 * @see    #setDefaultCloseOperation
 * @see    java.awt.Window#processWindowEvent
 */
protected void processWindowEvent(final WindowEvent e) {
    super.processWindowEvent(e);

    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
        switch (defaultCloseOperation) {
            case HIDE_ON_CLOSE:
                setVisible(false);
                break;
            case DISPOSE_ON_CLOSE:
                dispose();
                break;
            case EXIT_ON_CLOSE:
                // This needs to match the checkExit call in
                // setDefaultCloseOperation
                System.exit(0);
                break;
            case DO_NOTHING_ON_CLOSE:
            default:
        }
    }
}
 
Example 5
Source File: SwingUtils.java    From IBC with GNU General Public License v3.0 6 votes vote down vote up
static String windowEventToString(int eventID) {
    switch (eventID) { 
        case WindowEvent.WINDOW_ACTIVATED:
            return "Activated";
        case WindowEvent.WINDOW_CLOSED:
            return "Closed";
        case WindowEvent.WINDOW_CLOSING:
            return "Closing";
        case WindowEvent.WINDOW_DEACTIVATED:
            return "Deactivated";
        case WindowEvent.WINDOW_DEICONIFIED:
            return "Deiconified";
        case WindowEvent.WINDOW_GAINED_FOCUS:
            return "Focused";
        case WindowEvent.WINDOW_ICONIFIED:
            return "Iconified";
        case WindowEvent.WINDOW_LOST_FOCUS:
            return "Lost focus";
        case WindowEvent.WINDOW_OPENED:
            return "Opened";
        case WindowEvent.WINDOW_STATE_CHANGED:
            return "State changed";
        default:
            return "???";
    }
}
 
Example 6
Source File: JFrame.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Processes window events occurring on this component.
 * Hides the window or disposes of it, as specified by the setting
 * of the <code>defaultCloseOperation</code> property.
 *
 * @param  e  the window event
 * @see    #setDefaultCloseOperation
 * @see    java.awt.Window#processWindowEvent
 */
protected void processWindowEvent(final WindowEvent e) {
    super.processWindowEvent(e);

    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
        switch (defaultCloseOperation) {
            case HIDE_ON_CLOSE:
                setVisible(false);
                break;
            case DISPOSE_ON_CLOSE:
                dispose();
                break;
            case EXIT_ON_CLOSE:
                // This needs to match the checkExit call in
                // setDefaultCloseOperation
                System.exit(0);
                break;
            case DO_NOTHING_ON_CLOSE:
            default:
        }
    }
}
 
Example 7
Source File: JFrame.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Processes window events occurring on this component.
 * Hides the window or disposes of it, as specified by the setting
 * of the <code>defaultCloseOperation</code> property.
 *
 * @param  e  the window event
 * @see    #setDefaultCloseOperation
 * @see    java.awt.Window#processWindowEvent
 */
protected void processWindowEvent(final WindowEvent e) {
    super.processWindowEvent(e);

    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
        switch (defaultCloseOperation) {
            case HIDE_ON_CLOSE:
                setVisible(false);
                break;
            case DISPOSE_ON_CLOSE:
                dispose();
                break;
            case EXIT_ON_CLOSE:
                // This needs to match the checkExit call in
                // setDefaultCloseOperation
                System.exit(0);
                break;
            case DO_NOTHING_ON_CLOSE:
            default:
        }
    }
}
 
Example 8
Source File: JTSTestBuilder_AboutBox.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
        cancel();
    }
    super.processWindowEvent(e);
}
 
Example 9
Source File: Utilities.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
/**
 * Closes the application specified.
 * @param frame the application to close.
 */
public static void closeApplication(Frame frame) {
    if (null != frame) {
        WindowEvent wev = new WindowEvent(frame, WindowEvent.WINDOW_CLOSING);
        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);
    }
}
 
Example 10
Source File: Window.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
boolean eventEnabled(AWTEvent e) {
    switch(e.id) {
      case WindowEvent.WINDOW_OPENED:
      case WindowEvent.WINDOW_CLOSING:
      case WindowEvent.WINDOW_CLOSED:
      case WindowEvent.WINDOW_ICONIFIED:
      case WindowEvent.WINDOW_DEICONIFIED:
      case WindowEvent.WINDOW_ACTIVATED:
      case WindowEvent.WINDOW_DEACTIVATED:
        if ((eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0 ||
            windowListener != null) {
            return true;
        }
        return false;
      case WindowEvent.WINDOW_GAINED_FOCUS:
      case WindowEvent.WINDOW_LOST_FOCUS:
        if ((eventMask & AWTEvent.WINDOW_FOCUS_EVENT_MASK) != 0 ||
            windowFocusListener != null) {
            return true;
        }
        return false;
      case WindowEvent.WINDOW_STATE_CHANGED:
        if ((eventMask & AWTEvent.WINDOW_STATE_EVENT_MASK) != 0 ||
            windowStateListener != null) {
            return true;
        }
        return false;
      default:
        break;
    }
    return super.eventEnabled(e);
}
 
Example 11
Source File: EventDispatchThread.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public FilterAction acceptEvent(AWTEvent event) {
    if (modalComponent != null) {
        int eventID = event.getID();
        boolean mouseEvent = (eventID >= MouseEvent.MOUSE_FIRST) &&
                             (eventID <= MouseEvent.MOUSE_LAST);
        boolean actionEvent = (eventID >= ActionEvent.ACTION_FIRST) &&
                              (eventID <= ActionEvent.ACTION_LAST);
        boolean windowClosingEvent = (eventID == WindowEvent.WINDOW_CLOSING);
        /*
         * filter out MouseEvent and ActionEvent that's outside
         * the modalComponent hierarchy.
         * KeyEvent is handled by using enqueueKeyEvent
         * in Dialog.show
         */
        if (Component.isInstanceOf(modalComponent, "javax.swing.JInternalFrame")) {
            /*
             * Modal internal frames are handled separately. If event is
             * for some component from another heavyweight than modalComp,
             * it is accepted. If heavyweight is the same - we still accept
             * event and perform further filtering in LightweightDispatcher
             */
            return windowClosingEvent ? FilterAction.REJECT : FilterAction.ACCEPT;
        }
        if (mouseEvent || actionEvent || windowClosingEvent) {
            Object o = event.getSource();
            if (o instanceof sun.awt.ModalExclude) {
                // Exclude this object from modality and
                // continue to pump it's events.
                return FilterAction.ACCEPT;
            } else if (o instanceof Component) {
                Component c = (Component) o;
                // 5.0u3 modal exclusion
                boolean modalExcluded = false;
                if (modalComponent instanceof Container) {
                    while (c != modalComponent && c != null) {
                        if ((c instanceof Window) &&
                            (sun.awt.SunToolkit.isModalExcluded((Window)c))) {
                            // Exclude this window and all its children from
                            //  modality and continue to pump it's events.
                            modalExcluded = true;
                            break;
                        }
                        c = c.getParent();
                    }
                }
                if (!modalExcluded && (c != modalComponent)) {
                    return FilterAction.REJECT;
                }
            }
        }
    }
    return FilterAction.ACCEPT;
}
 
Example 12
Source File: EventDispatchThread.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
public FilterAction acceptEvent(AWTEvent event) {
    if (modalComponent != null) {
        int eventID = event.getID();
        boolean mouseEvent = (eventID >= MouseEvent.MOUSE_FIRST) &&
                             (eventID <= MouseEvent.MOUSE_LAST);
        boolean actionEvent = (eventID >= ActionEvent.ACTION_FIRST) &&
                              (eventID <= ActionEvent.ACTION_LAST);
        boolean windowClosingEvent = (eventID == WindowEvent.WINDOW_CLOSING);
        /*
         * filter out MouseEvent and ActionEvent that's outside
         * the modalComponent hierarchy.
         * KeyEvent is handled by using enqueueKeyEvent
         * in Dialog.show
         */
        if (Component.isInstanceOf(modalComponent, "javax.swing.JInternalFrame")) {
            /*
             * Modal internal frames are handled separately. If event is
             * for some component from another heavyweight than modalComp,
             * it is accepted. If heavyweight is the same - we still accept
             * event and perform further filtering in LightweightDispatcher
             */
            return windowClosingEvent ? FilterAction.REJECT : FilterAction.ACCEPT;
        }
        if (mouseEvent || actionEvent || windowClosingEvent) {
            Object o = event.getSource();
            if (o instanceof sun.awt.ModalExclude) {
                // Exclude this object from modality and
                // continue to pump it's events.
                return FilterAction.ACCEPT;
            } else if (o instanceof Component) {
                Component c = (Component) o;
                // 5.0u3 modal exclusion
                boolean modalExcluded = false;
                if (modalComponent instanceof Container) {
                    while (c != modalComponent && c != null) {
                        if ((c instanceof Window) &&
                            (sun.awt.SunToolkit.isModalExcluded((Window)c))) {
                            // Exclude this window and all its children from
                            //  modality and continue to pump it's events.
                            modalExcluded = true;
                            break;
                        }
                        c = c.getParent();
                    }
                }
                if (!modalExcluded && (c != modalComponent)) {
                    return FilterAction.REJECT;
                }
            }
        }
    }
    return FilterAction.ACCEPT;
}
 
Example 13
Source File: EventDispatchThread.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public FilterAction acceptEvent(AWTEvent event) {
    if (modalComponent != null) {
        int eventID = event.getID();
        boolean mouseEvent = (eventID >= MouseEvent.MOUSE_FIRST) &&
                             (eventID <= MouseEvent.MOUSE_LAST);
        boolean actionEvent = (eventID >= ActionEvent.ACTION_FIRST) &&
                              (eventID <= ActionEvent.ACTION_LAST);
        boolean windowClosingEvent = (eventID == WindowEvent.WINDOW_CLOSING);
        /*
         * filter out MouseEvent and ActionEvent that's outside
         * the modalComponent hierarchy.
         * KeyEvent is handled by using enqueueKeyEvent
         * in Dialog.show
         */
        if (Component.isInstanceOf(modalComponent, "javax.swing.JInternalFrame")) {
            /*
             * Modal internal frames are handled separately. If event is
             * for some component from another heavyweight than modalComp,
             * it is accepted. If heavyweight is the same - we still accept
             * event and perform further filtering in LightweightDispatcher
             */
            return windowClosingEvent ? FilterAction.REJECT : FilterAction.ACCEPT;
        }
        if (mouseEvent || actionEvent || windowClosingEvent) {
            Object o = event.getSource();
            if (o instanceof sun.awt.ModalExclude) {
                // Exclude this object from modality and
                // continue to pump it's events.
                return FilterAction.ACCEPT;
            } else if (o instanceof Component) {
                Component c = (Component) o;
                // 5.0u3 modal exclusion
                boolean modalExcluded = false;
                if (modalComponent instanceof Container) {
                    while (c != modalComponent && c != null) {
                        if ((c instanceof Window) &&
                            (sun.awt.SunToolkit.isModalExcluded((Window)c))) {
                            // Exclude this window and all its children from
                            //  modality and continue to pump it's events.
                            modalExcluded = true;
                            break;
                        }
                        c = c.getParent();
                    }
                }
                if (!modalExcluded && (c != modalComponent)) {
                    return FilterAction.REJECT;
                }
            }
        }
    }
    return FilterAction.ACCEPT;
}
 
Example 14
Source File: TradesFrameHandler.java    From IBC with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void handleWindow(final Window window, int eventID) {
    if (!firstTradesWindowOpened) {
        showAllTrades = Settings.settings().getBoolean("ShowAllTrades", false);
    }
    if (!showAllTrades) {
        firstTradesWindowOpened = true;
        return;
    }
    if (eventID == WindowEvent.WINDOW_OPENED) {
        if (findCheckBox(window, "Sun") != null) {
            Utils.logToConsole("Setting trades log to show all trades");
            // TWS versions before 955
            SwingUtils.setCheckBoxSelected(window, "Sun", true);
            SwingUtils.setCheckBoxSelected(window, "Mon", true);
            SwingUtils.setCheckBoxSelected(window, "Tue", true);
            SwingUtils.setCheckBoxSelected(window, "Wed", true);
            SwingUtils.setCheckBoxSelected(window, "Thu", true);
            SwingUtils.setCheckBoxSelected(window, "Fri", true);
            SwingUtils.setCheckBoxSelected(window, "Sat", true);
            SwingUtils.setCheckBoxSelected(window, "All", true);

            monitorAllTradesCheckbox(window, "All");

            if (! firstTradesWindowOpened) {
                if (Settings.settings().getBoolean("MinimizeMainWindow", false)) {
                    ((JFrame) window).setExtendedState(java.awt.Frame.ICONIFIED);
                }
            }
        } else {
            Utils.logToConsole("Can't set trades log to show all trades with this TWS version: user must do this");
            /*
             * For TWS 955 onwards, IB have replaced the row of daily 
             * checkboxes with what appears visually to be a combo box:
             * it is indeed derived from a JComboBox, but setting the
             * selected item to 'Last 7 Days' doesn't have the desired
             * effect.
             * 
             * At present I don't see a way of getting round this, but 
             * the setting chosen by the user can now be persisted
             * between sessions, so there is really no longer a need for
             * 'ShowAllTrades'.
             * 
             */
            
            showAllTrades = false;
            ((JFrame) window).dispose();
        }

        firstTradesWindowOpened = true;

    } else if (eventID == WindowEvent.WINDOW_CLOSING) {
        Utils.logToConsole("User closing trades log");
    } else if (eventID == WindowEvent.WINDOW_CLOSED) {
        if (showAllTrades) {
            Utils.logToConsole("Trades log closed by user - recreating");
            Utils.showTradesLogWindow();
        }
    }

}
 
Example 15
Source File: NativeJVMHalt.java    From Launcher with GNU General Public License v3.0 4 votes vote down vote up
public WindowShutdown() {
    super();
    super.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    super.processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
}
 
Example 16
Source File: EventDispatchThread.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public FilterAction acceptEvent(AWTEvent event) {
    if (modalComponent != null) {
        int eventID = event.getID();
        boolean mouseEvent = (eventID >= MouseEvent.MOUSE_FIRST) &&
                             (eventID <= MouseEvent.MOUSE_LAST);
        boolean actionEvent = (eventID >= ActionEvent.ACTION_FIRST) &&
                              (eventID <= ActionEvent.ACTION_LAST);
        boolean windowClosingEvent = (eventID == WindowEvent.WINDOW_CLOSING);
        /*
         * filter out MouseEvent and ActionEvent that's outside
         * the modalComponent hierarchy.
         * KeyEvent is handled by using enqueueKeyEvent
         * in Dialog.show
         */
        if (Component.isInstanceOf(modalComponent, "javax.swing.JInternalFrame")) {
            /*
             * Modal internal frames are handled separately. If event is
             * for some component from another heavyweight than modalComp,
             * it is accepted. If heavyweight is the same - we still accept
             * event and perform further filtering in LightweightDispatcher
             */
            return windowClosingEvent ? FilterAction.REJECT : FilterAction.ACCEPT;
        }
        if (mouseEvent || actionEvent || windowClosingEvent) {
            Object o = event.getSource();
            if (o instanceof sun.awt.ModalExclude) {
                // Exclude this object from modality and
                // continue to pump it's events.
                return FilterAction.ACCEPT;
            } else if (o instanceof Component) {
                Component c = (Component) o;
                // 5.0u3 modal exclusion
                boolean modalExcluded = false;
                if (modalComponent instanceof Container) {
                    while (c != modalComponent && c != null) {
                        if ((c instanceof Window) &&
                            (sun.awt.SunToolkit.isModalExcluded((Window)c))) {
                            // Exclude this window and all its children from
                            //  modality and continue to pump it's events.
                            modalExcluded = true;
                            break;
                        }
                        c = c.getParent();
                    }
                }
                if (!modalExcluded && (c != modalComponent)) {
                    return FilterAction.REJECT;
                }
            }
        }
    }
    return FilterAction.ACCEPT;
}
 
Example 17
Source File: EventDispatchThread.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
public FilterAction acceptEvent(AWTEvent event) {
    if (modalComponent != null) {
        int eventID = event.getID();
        boolean mouseEvent = (eventID >= MouseEvent.MOUSE_FIRST) &&
                             (eventID <= MouseEvent.MOUSE_LAST);
        boolean actionEvent = (eventID >= ActionEvent.ACTION_FIRST) &&
                              (eventID <= ActionEvent.ACTION_LAST);
        boolean windowClosingEvent = (eventID == WindowEvent.WINDOW_CLOSING);
        /*
         * filter out MouseEvent and ActionEvent that's outside
         * the modalComponent hierarchy.
         * KeyEvent is handled by using enqueueKeyEvent
         * in Dialog.show
         */
        if (Component.isInstanceOf(modalComponent, "javax.swing.JInternalFrame")) {
            /*
             * Modal internal frames are handled separately. If event is
             * for some component from another heavyweight than modalComp,
             * it is accepted. If heavyweight is the same - we still accept
             * event and perform further filtering in LightweightDispatcher
             */
            return windowClosingEvent ? FilterAction.REJECT : FilterAction.ACCEPT;
        }
        if (mouseEvent || actionEvent || windowClosingEvent) {
            Object o = event.getSource();
            if (o instanceof sun.awt.ModalExclude) {
                // Exclude this object from modality and
                // continue to pump it's events.
                return FilterAction.ACCEPT;
            } else if (o instanceof Component) {
                Component c = (Component) o;
                // 5.0u3 modal exclusion
                boolean modalExcluded = false;
                if (modalComponent instanceof Container) {
                    while (c != modalComponent && c != null) {
                        if ((c instanceof Window) &&
                            (sun.awt.SunToolkit.isModalExcluded((Window)c))) {
                            // Exclude this window and all its children from
                            //  modality and continue to pump it's events.
                            modalExcluded = true;
                            break;
                        }
                        c = c.getParent();
                    }
                }
                if (!modalExcluded && (c != modalComponent)) {
                    return FilterAction.REJECT;
                }
            }
        }
    }
    return FilterAction.ACCEPT;
}
 
Example 18
Source File: EventDispatchThread.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public FilterAction acceptEvent(AWTEvent event) {
    if (modalComponent != null) {
        int eventID = event.getID();
        boolean mouseEvent = (eventID >= MouseEvent.MOUSE_FIRST) &&
                             (eventID <= MouseEvent.MOUSE_LAST);
        boolean actionEvent = (eventID >= ActionEvent.ACTION_FIRST) &&
                              (eventID <= ActionEvent.ACTION_LAST);
        boolean windowClosingEvent = (eventID == WindowEvent.WINDOW_CLOSING);
        /*
         * filter out MouseEvent and ActionEvent that's outside
         * the modalComponent hierarchy.
         * KeyEvent is handled by using enqueueKeyEvent
         * in Dialog.show
         */
        if (Component.isInstanceOf(modalComponent, "javax.swing.JInternalFrame")) {
            /*
             * Modal internal frames are handled separately. If event is
             * for some component from another heavyweight than modalComp,
             * it is accepted. If heavyweight is the same - we still accept
             * event and perform further filtering in LightweightDispatcher
             */
            return windowClosingEvent ? FilterAction.REJECT : FilterAction.ACCEPT;
        }
        if (mouseEvent || actionEvent || windowClosingEvent) {
            Object o = event.getSource();
            if (o instanceof sun.awt.ModalExclude) {
                // Exclude this object from modality and
                // continue to pump it's events.
                return FilterAction.ACCEPT;
            } else if (o instanceof Component) {
                Component c = (Component) o;
                // 5.0u3 modal exclusion
                boolean modalExcluded = false;
                if (modalComponent instanceof Container) {
                    while (c != modalComponent && c != null) {
                        if ((c instanceof Window) &&
                            (sun.awt.SunToolkit.isModalExcluded((Window)c))) {
                            // Exclude this window and all its children from
                            //  modality and continue to pump it's events.
                            modalExcluded = true;
                            break;
                        }
                        c = c.getParent();
                    }
                }
                if (!modalExcluded && (c != modalComponent)) {
                    return FilterAction.REJECT;
                }
            }
        }
    }
    return FilterAction.ACCEPT;
}
 
Example 19
Source File: EventDispatchThread.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public FilterAction acceptEvent(AWTEvent event) {
    if (modalComponent != null) {
        int eventID = event.getID();
        boolean mouseEvent = (eventID >= MouseEvent.MOUSE_FIRST) &&
                             (eventID <= MouseEvent.MOUSE_LAST);
        boolean actionEvent = (eventID >= ActionEvent.ACTION_FIRST) &&
                              (eventID <= ActionEvent.ACTION_LAST);
        boolean windowClosingEvent = (eventID == WindowEvent.WINDOW_CLOSING);
        /*
         * filter out MouseEvent and ActionEvent that's outside
         * the modalComponent hierarchy.
         * KeyEvent is handled by using enqueueKeyEvent
         * in Dialog.show
         */
        if (Component.isInstanceOf(modalComponent, "javax.swing.JInternalFrame")) {
            /*
             * Modal internal frames are handled separately. If event is
             * for some component from another heavyweight than modalComp,
             * it is accepted. If heavyweight is the same - we still accept
             * event and perform further filtering in LightweightDispatcher
             */
            return windowClosingEvent ? FilterAction.REJECT : FilterAction.ACCEPT;
        }
        if (mouseEvent || actionEvent || windowClosingEvent) {
            Object o = event.getSource();
            if (o instanceof sun.awt.ModalExclude) {
                // Exclude this object from modality and
                // continue to pump it's events.
                return FilterAction.ACCEPT;
            } else if (o instanceof Component) {
                Component c = (Component) o;
                // 5.0u3 modal exclusion
                boolean modalExcluded = false;
                if (modalComponent instanceof Container) {
                    while (c != modalComponent && c != null) {
                        if ((c instanceof Window) &&
                            (sun.awt.SunToolkit.isModalExcluded((Window)c))) {
                            // Exclude this window and all its children from
                            //  modality and continue to pump it's events.
                            modalExcluded = true;
                            break;
                        }
                        c = c.getParent();
                    }
                }
                if (!modalExcluded && (c != modalComponent)) {
                    return FilterAction.REJECT;
                }
            }
        }
    }
    return FilterAction.ACCEPT;
}
 
Example 20
Source File: EventDispatchThread.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public FilterAction acceptEvent(AWTEvent event) {
    if (modalComponent != null) {
        int eventID = event.getID();
        boolean mouseEvent = (eventID >= MouseEvent.MOUSE_FIRST) &&
                             (eventID <= MouseEvent.MOUSE_LAST);
        boolean actionEvent = (eventID >= ActionEvent.ACTION_FIRST) &&
                              (eventID <= ActionEvent.ACTION_LAST);
        boolean windowClosingEvent = (eventID == WindowEvent.WINDOW_CLOSING);
        /*
         * filter out MouseEvent and ActionEvent that's outside
         * the modalComponent hierarchy.
         * KeyEvent is handled by using enqueueKeyEvent
         * in Dialog.show
         */
        if (Component.isInstanceOf(modalComponent, "javax.swing.JInternalFrame")) {
            /*
             * Modal internal frames are handled separately. If event is
             * for some component from another heavyweight than modalComp,
             * it is accepted. If heavyweight is the same - we still accept
             * event and perform further filtering in LightweightDispatcher
             */
            return windowClosingEvent ? FilterAction.REJECT : FilterAction.ACCEPT;
        }
        if (mouseEvent || actionEvent || windowClosingEvent) {
            Object o = event.getSource();
            if (o instanceof sun.awt.ModalExclude) {
                // Exclude this object from modality and
                // continue to pump it's events.
                return FilterAction.ACCEPT;
            } else if (o instanceof Component) {
                Component c = (Component) o;
                // 5.0u3 modal exclusion
                boolean modalExcluded = false;
                if (modalComponent instanceof Container) {
                    while (c != modalComponent && c != null) {
                        if ((c instanceof Window) &&
                            (sun.awt.SunToolkit.isModalExcluded((Window)c))) {
                            // Exclude this window and all its children from
                            //  modality and continue to pump it's events.
                            modalExcluded = true;
                            break;
                        }
                        c = c.getParent();
                    }
                }
                if (!modalExcluded && (c != modalComponent)) {
                    return FilterAction.REJECT;
                }
            }
        }
    }
    return FilterAction.ACCEPT;
}