|
Packit |
5e46da |
/*
|
|
Packit |
5e46da |
* This file is part of libbluray
|
|
Packit |
5e46da |
* Copyright (C) 2012 Libbluray
|
|
Packit |
5e46da |
* Copyright (C) 2013 Petri Hintukainen <phintuka@users.sourceforge.net>
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
* This library is free software; you can redistribute it and/or
|
|
Packit |
5e46da |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
5e46da |
* License as published by the Free Software Foundation; either
|
|
Packit |
5e46da |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
5e46da |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
5e46da |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
5e46da |
* Lesser General Public License for more details.
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
5e46da |
* License along with this library. If not, see
|
|
Packit |
5e46da |
* <http://www.gnu.org/licenses/>.
|
|
Packit |
5e46da |
*/
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
package java.awt;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
import java.awt.event.InvocationEvent;
|
|
Packit |
5e46da |
import java.awt.event.KeyEvent;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public class BDJHelper {
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public static EventDispatchThread getEventDispatchThread(EventQueue eq) {
|
|
Packit |
5e46da |
if (eq != null) {
|
|
Packit |
5e46da |
return eq.getDispatchThread();
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
return null;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public static void stopEventQueue(EventQueue eq) {
|
|
Packit |
5e46da |
EventDispatchThread t = eq.getDispatchThread();
|
|
Packit |
5e46da |
if (t != null && t.isAlive()) {
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
final long DISPOSAL_TIMEOUT = 5000;
|
|
Packit |
5e46da |
final Object notificationLock = new Object();
|
|
Packit |
5e46da |
Runnable runnable = new Runnable() { public void run() {
|
|
Packit |
5e46da |
synchronized(notificationLock) {
|
|
Packit |
5e46da |
notificationLock.notifyAll();
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
} };
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
synchronized (notificationLock) {
|
|
Packit |
5e46da |
eq.postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(), runnable));
|
|
Packit |
5e46da |
try {
|
|
Packit |
5e46da |
notificationLock.wait(DISPOSAL_TIMEOUT);
|
|
Packit |
5e46da |
} catch (InterruptedException e) {
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
t.stopDispatching();
|
|
Packit |
5e46da |
if (t.isAlive()) {
|
|
Packit |
5e46da |
t.interrupt();
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
try {
|
|
Packit |
5e46da |
t.join(1000);
|
|
Packit |
5e46da |
} catch (InterruptedException e) {
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
if (t.isAlive()) {
|
|
Packit |
5e46da |
org.videolan.Logger.getLogger("BDRootWindow").error("stopEventQueue() failed for " + t);
|
|
Packit |
5e46da |
org.videolan.PortingHelper.stopThread(t);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public static boolean postMouseEvent(int x, int y) {
|
|
Packit |
5e46da |
return false;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public static boolean postMouseEvent(int button) {
|
|
Packit |
5e46da |
return false;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public static boolean postKeyEvent(int id, int modifiers, int keyCode) {
|
|
Packit |
5e46da |
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getGlobalFocusOwner();
|
|
Packit |
5e46da |
if (focusOwner != null) {
|
|
Packit |
5e46da |
long when = System.currentTimeMillis();
|
|
Packit |
5e46da |
KeyEvent event;
|
|
Packit |
5e46da |
try {
|
|
Packit |
5e46da |
if (id == KeyEvent.KEY_TYPED)
|
|
Packit |
5e46da |
event = new KeyEvent(focusOwner, id, when, modifiers, KeyEvent.VK_UNDEFINED, (char)keyCode);
|
|
Packit |
5e46da |
else
|
|
Packit |
5e46da |
event = new KeyEvent(focusOwner, id, when, modifiers, keyCode, KeyEvent.CHAR_UNDEFINED);
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
EventQueue eq = BDToolkit.getEventQueue(focusOwner);
|
|
Packit |
5e46da |
if (eq != null) {
|
|
Packit |
5e46da |
eq.postEvent(event);
|
|
Packit |
5e46da |
return true;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
} catch (Exception e) {
|
|
Packit |
5e46da |
org.videolan.Logger.getLogger("BDJHelper").error("postKeyEvent failed: " + e);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
} else {
|
|
Packit |
5e46da |
org.videolan.Logger.getLogger("BDJHelper").error("*** KEY event dropped ***");
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
return false;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
}
|