001 /*
002 * Created on Nov 11, 2007
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License
010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011 * or implied. See the License for the specific language governing permissions and limitations under
012 * the License.
013 *
014 * Copyright @2007-2010 the original author or authors.
015 */
016 package org.fest.swing.util;
017
018 import static java.awt.event.ComponentEvent.COMPONENT_SHOWN;
019 import static java.awt.event.WindowEvent.WINDOW_CLOSED;
020 import static java.awt.event.WindowEvent.WINDOW_OPENED;
021
022 import java.awt.AWTEvent;
023 import java.awt.Window;
024
025 /**
026 * Understands utility methods related to AWT events.
027 *
028 * @author Alex Ruiz
029 */
030 public final class AWTEvents {
031
032 /**
033 * Returns <code>true</code> if the id of the given event is equal to
034 * <code>{@link java.awt.event.WindowEvent#WINDOW_OPENED WINDOW_OPENED}</code>
035 * @param e the given event.
036 * @return <code>true</code> if the id of the given event is equal to <code>WINDOW_OPENED</code>; <code>false</code>
037 * otherwise.
038 */
039 public static boolean windowOpened(AWTEvent e) {
040 return idEquals(e, WINDOW_OPENED);
041 }
042
043 /**
044 * Returns <code>true</code> if the id of the given event is equal to
045 * <code>{@link java.awt.event.WindowEvent#COMPONENT_SHOWN COMPONENT_SHOWN}</code> and the source of the event is a
046 * <code>{@link Window}</code>.
047 * @param e the given event.
048 * @return <code>true</code> if the id of the given event is equal to <code>COMPONENT_SHOWN</code> and the source of
049 * the event is a window; <code>false</code> otherwise.
050 */
051 public static boolean windowShown(AWTEvent e) {
052 return idEquals(e, COMPONENT_SHOWN) && e.getSource() instanceof Window;
053 }
054
055 /**
056 * Returns <code>true</code> if the id of the given event is equal to
057 * <code>{@link java.awt.event.WindowEvent#WINDOW_CLOSED WINDOW_CLOSED}</code>
058 * @param e the given event.
059 * @return <code>true</code> if the id of the given event is equal to <code>WINDOW_CLOSED</code>; <code>false</code>
060 * otherwise.
061 */
062 public static boolean windowClosed(AWTEvent e) {
063 return idEquals(e, WINDOW_CLOSED);
064 }
065
066 private static boolean idEquals(AWTEvent e, int expectedId) {
067 return e.getID() == expectedId;
068 }
069
070 private AWTEvents() {}
071 }