|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MouseButton | Line # 28 | 5 | 0% | 3 | 0 | 100% |
1.0
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| No Tests | |||
| 1 | /* | |
| 2 | * Created on Sep 21, 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.core; | |
| 17 | ||
| 18 | import static java.awt.event.InputEvent.*; | |
| 19 | import static org.fest.util.Strings.concat; | |
| 20 | ||
| 21 | import java.awt.event.InputEvent; | |
| 22 | ||
| 23 | /** | |
| 24 | * Understands mouse buttons. | |
| 25 | * | |
| 26 | * @author Alex Ruiz | |
| 27 | */ | |
| 28 | public enum MouseButton { | |
| 29 | ||
| 30 | LEFT_BUTTON(BUTTON1_MASK), MIDDLE_BUTTON(BUTTON2_MASK), RIGHT_BUTTON(BUTTON3_MASK); | |
| 31 | ||
| 32 | /** | |
| 33 | * The mouse button modifier. | |
| 34 | * @see InputEvent | |
| 35 | */ | |
| 36 | public final int mask; | |
| 37 | ||
| 38 | 4062 |
private MouseButton(int mask) { |
| 39 | 4062 | this.mask = mask; |
| 40 | } | |
| 41 | ||
| 42 | /** | |
| 43 | * Returns the mouse button whose mask matches the given mask. Valid values are | |
| 44 | * <code>{@link InputEvent#BUTTON1_MASK}</code>, <code>{@link InputEvent#BUTTON2_MASK}</code>, and | |
| 45 | * <code>{@link InputEvent#BUTTON3_MASK}</code> | |
| 46 | * @param mask the mask of the button we are looking for. | |
| 47 | * @return the found button. | |
| 48 | * @throws IllegalArgumentException if the given mask is not a valid one. | |
| 49 | */ | |
| 50 | 4 |
public static MouseButton lookup(int mask) { |
| 51 | 4 | for (MouseButton button : values()) |
| 52 | 3 | if (button.mask == mask) return button; |
| 53 | 1 | throw new IllegalArgumentException(concat(String.valueOf(mask), " is not a valid button mask")); |
| 54 | } | |
| 55 | } | |
|
||||||||||||