JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
AWTFocusAdapter.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.util;
30
31import java.awt.event.FocusEvent;
32import java.awt.event.FocusListener;
33
34public class AWTFocusAdapter implements FocusEventCountAdapter, FocusListener {
35
36 String prefix;
37 int focusCount;
38 boolean wasTemporary;
39 boolean verbose = true;
40
41 public AWTFocusAdapter(final String prefix) {
42 this.prefix = prefix;
43 reset();
44 }
45
46 public void setVerbose(final boolean v) { verbose = false; }
47
48 public boolean focusLost() {
49 return focusCount<0;
50 }
51
52 public boolean focusGained() {
53 return focusCount>0;
54 }
55
56 public void reset() {
57 focusCount = 0;
58 wasTemporary = false;
59 }
60
61 /** @return true, if the last change was temporary */
62 public boolean getWasTemporary() {
63 return wasTemporary;
64 }
65
66 /* @Override */
67 public void focusGained(final FocusEvent e) {
68 if(focusCount<0) { focusCount=0; }
69 focusCount++;
70 wasTemporary = e.isTemporary();
71 if( verbose ) {
72 System.err.println("FOCUS AWT GAINED "+(wasTemporary?"TEMP":"PERM")+" [fc "+focusCount+"]: "+prefix+", "+e);
73 }
74 }
75
76 /* @Override */
77 public void focusLost(final FocusEvent e) {
78 if(focusCount>0) { focusCount=0; }
79 focusCount--;
80 wasTemporary = e.isTemporary();
81 if( verbose ) {
82 System.err.println("FOCUS AWT LOST "+(wasTemporary?"TEMP":"PERM")+" [fc "+focusCount+"]: "+prefix+", "+e);
83 }
84 }
85
86 public String toString() { return prefix+"[focusCount "+focusCount +", temp "+wasTemporary+"]"; }
87}
void setVerbose(final boolean v)
Instance starts in verbose mode, call w/ false to disable verbosity.