|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AWTEvents | Line # 30 | 4 | 11.1% | 4 | 0 | 100% |
1.0
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| No Tests | |||
| 1 | /* | |
| 2 | * Created on Nov 11, 2007 | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 5 | * in compliance with the License. You may obtain a copy of the License at | |
| 6 | * | |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 | * | |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 11 | * or implied. See the License for the specific language governing permissions and limitations under | |
| 12 | * the License. | |
| 13 | * | |
| 14 | * Copyright @2007-2010 the original author or authors. | |
| 15 | */ | |
| 16 | package org.fest.swing.util; | |
| 17 | ||
| 18 | import static java.awt.event.ComponentEvent.COMPONENT_SHOWN; | |
| 19 | import static java.awt.event.WindowEvent.WINDOW_CLOSED; | |
| 20 | import static java.awt.event.WindowEvent.WINDOW_OPENED; | |
| 21 | ||
| 22 | import java.awt.AWTEvent; | |
| 23 | import java.awt.Window; | |
| 24 | ||
| 25 | /** | |
| 26 | * Understands utility methods related to AWT events. | |
| 27 | * | |
| 28 | * @author Alex Ruiz | |
| 29 | */ | |
| 30 | public final class AWTEvents { | |
| 31 | ||
| 32 | /** | |
| 33 | * Returns <code>true</code> if the id of the given event is equal to | |
| 34 | * <code>{@link java.awt.event.WindowEvent#WINDOW_OPENED WINDOW_OPENED}</code> | |
| 35 | * @param e the given event. | |
| 36 | * @return <code>true</code> if the id of the given event is equal to <code>WINDOW_OPENED</code>; <code>false</code> | |
| 37 | * otherwise. | |
| 38 | */ | |
| 39 | 121378 |
public static boolean windowOpened(AWTEvent e) { |
| 40 | 121378 | return idEquals(e, WINDOW_OPENED); |
| 41 | } | |
| 42 | ||
| 43 | /** | |
| 44 | * Returns <code>true</code> if the id of the given event is equal to | |
| 45 | * <code>{@link java.awt.event.WindowEvent#COMPONENT_SHOWN COMPONENT_SHOWN}</code> and the source of the event is a | |
| 46 | * <code>{@link Window}</code>. | |
| 47 | * @param e the given event. | |
| 48 | * @return <code>true</code> if the id of the given event is equal to <code>COMPONENT_SHOWN</code> and the source of | |
| 49 | * the event is a window; <code>false</code> otherwise. | |
| 50 | */ | |
| 51 | 117378 |
public static boolean windowShown(AWTEvent e) { |
| 52 | 117378 | return idEquals(e, COMPONENT_SHOWN) && e.getSource() instanceof Window; |
| 53 | } | |
| 54 | ||
| 55 | /** | |
| 56 | * Returns <code>true</code> if the id of the given event is equal to | |
| 57 | * <code>{@link java.awt.event.WindowEvent#WINDOW_CLOSED WINDOW_CLOSED}</code> | |
| 58 | * @param e the given event. | |
| 59 | * @return <code>true</code> if the id of the given event is equal to <code>WINDOW_CLOSED</code>; <code>false</code> | |
| 60 | * otherwise. | |
| 61 | */ | |
| 62 | 113363 |
public static boolean windowClosed(AWTEvent e) { |
| 63 | 113363 | return idEquals(e, WINDOW_CLOSED); |
| 64 | } | |
| 65 | ||
| 66 | 352119 |
private static boolean idEquals(AWTEvent e, int expectedId) { |
| 67 | 352119 | return e.getID() == expectedId; |
| 68 | } | |
| 69 | ||
| 70 |
private AWTEvents() {} |
|
| 71 | } | |
|
||||||||||||