JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
NEWTMouseAdapter.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.util.ArrayList;
32import java.util.EventObject;
33import java.util.List;
34
35import com.jogamp.newt.event.MouseAdapter;
36import com.jogamp.newt.event.MouseEvent;
37
38public class NEWTMouseAdapter extends MouseAdapter implements InputEventCountAdapter {
39
40 String prefix;
41 volatile int mouseClicked;
42 volatile int consumed;
43 volatile boolean pressed;
44 List<EventObject> queue = new ArrayList<EventObject>();
45 boolean verbose = true;
46
47 public NEWTMouseAdapter(final String prefix) {
48 this.prefix = prefix;
49 reset();
50 }
51
52 @Override
53 public synchronized void setVerbose(final boolean v) { verbose = v; }
54
55 @Override
56 public synchronized boolean isPressed() {
57 return pressed;
58 }
59
60 @Override
61 public synchronized int getCount() {
62 return mouseClicked;
63 }
64
65 @Override
66 public synchronized int getConsumedCount() {
67 return consumed;
68 }
69
70 @Override
71 public synchronized List<EventObject> copyQueue() {
72 return new ArrayList<EventObject>(queue);
73 }
74
75 @Override
76 public synchronized int getQueueSize() {
77 return queue.size();
78 }
79
80 @Override
81 public synchronized void reset() {
82 mouseClicked = 0;
83 consumed = 0;
84 pressed = false;
85 queue.clear();
86 }
87
88 @Override
89 public synchronized void mousePressed(final MouseEvent e) {
90 pressed = true;
91 queue.add(e);
92 if( verbose ) {
93 System.err.println("MOUSE NEWT PRESSED ["+pressed+"]: "+prefix+", "+e);
94 }
95 }
96
97 @Override
98 public synchronized void mouseReleased(final MouseEvent e) {
99 pressed = false;
100 queue.add(e);
101 if( verbose ) {
102 System.err.println("MOUSE NEWT RELEASED ["+pressed+"]: "+prefix+", "+e);
103 }
104 }
105
106 @Override
107 public synchronized void mouseClicked(final MouseEvent e) {
108 mouseClicked+=e.getClickCount();
109 if(e.isConsumed()) {
110 consumed++;
111 }
112 queue.add(e);
113 if( verbose ) {
114 System.err.println("MOUSE NEWT CLICKED ["+mouseClicked+"]: "+prefix+", "+e);
115 }
116 }
117
118 @Override
119 public String toString() { return prefix+"[pressed "+pressed+", clicked "+mouseClicked+", consumed "+consumed+"]"; }
120}
121
Pointer event of type PointerType.
Definition: MouseEvent.java:74
final boolean isConsumed()
Returns true if this events has been consumed, otherwise false.
Definition: NEWTEvent.java:105
synchronized List< EventObject > copyQueue()
synchronized void mousePressed(final MouseEvent e)
synchronized void setVerbose(final boolean v)
Instance starts in verbose mode, call w/ false to disable verbosity.
synchronized void mouseClicked(final MouseEvent e)
synchronized void mouseReleased(final MouseEvent e)