[libbluray-devel] Splitted unrelated functions from BDRootWindow
hpi1
git at videolan.org
Tue Apr 9 22:15:19 CEST 2013
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Tue Apr 9 12:09:58 2013 +0300| [dfbcca6804570bef8b3440ac9eac5776de122d72] | committer: hpi1
Splitted unrelated functions from BDRootWindow
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=dfbcca6804570bef8b3440ac9eac5776de122d72
---
.../bdj/java-j2me/java/awt/BDToolkit.java | 2 +-
.../bdj/java-j2se/java/awt/BDToolkit.java | 2 +-
src/libbluray/bdj/java/java/awt/BDJHelper.java | 90 ++++++++++++++++++++
src/libbluray/bdj/java/java/awt/BDRootWindow.java | 58 -------------
.../bdj/java/org/dvb/event/EventManager.java | 5 +-
.../bdj/java/org/videolan/BDJXletContext.java | 2 +-
6 files changed, 96 insertions(+), 63 deletions(-)
diff --git a/src/libbluray/bdj/java-j2me/java/awt/BDToolkit.java b/src/libbluray/bdj/java-j2me/java/awt/BDToolkit.java
index 6102bce..b5698c4 100644
--- a/src/libbluray/bdj/java-j2me/java/awt/BDToolkit.java
+++ b/src/libbluray/bdj/java-j2me/java/awt/BDToolkit.java
@@ -59,7 +59,7 @@ public class BDToolkit extends Toolkit {
public void dispose() {
if (eventQueue != null) {
- BDRootWindow.stopEventQueue(eventQueue);
+ BDJHelper.stopEventQueue(eventQueue);
eventQueue = null;
}
cachedImages = null;
diff --git a/src/libbluray/bdj/java-j2se/java/awt/BDToolkit.java b/src/libbluray/bdj/java-j2se/java/awt/BDToolkit.java
index 4455fc2..27fb0f3 100644
--- a/src/libbluray/bdj/java-j2se/java/awt/BDToolkit.java
+++ b/src/libbluray/bdj/java-j2se/java/awt/BDToolkit.java
@@ -61,7 +61,7 @@ public class BDToolkit extends Toolkit implements KeyboardFocusManagerPeerProvid
public void dispose() {
if (eventQueue != null) {
- BDRootWindow.stopEventQueue(eventQueue);
+ BDJHelper.stopEventQueue(eventQueue);
eventQueue = null;
}
BDKeyboardFocusManagerPeer.shutdown();
diff --git a/src/libbluray/bdj/java/java/awt/BDJHelper.java b/src/libbluray/bdj/java/java/awt/BDJHelper.java
new file mode 100644
index 0000000..1b194a9
--- /dev/null
+++ b/src/libbluray/bdj/java/java/awt/BDJHelper.java
@@ -0,0 +1,90 @@
+ /*
+ * This file is part of libbluray
+ * Copyright (C) 2012 Libbluray
+ * Copyright (C) 2013 Petri Hintukainen <phintuka at users.sourceforge.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+package java.awt;
+
+import java.awt.event.InvocationEvent;
+import java.awt.event.KeyEvent;
+
+public class BDJHelper {
+
+ public static EventDispatchThread getEventDispatchThread(EventQueue eq) {
+ if (eq != null) {
+ return eq.getDispatchThread();
+ }
+ return null;
+ }
+
+ public static void stopEventQueue(EventQueue eq) {
+ EventDispatchThread t = eq.getDispatchThread();
+ if (t != null && t.isAlive()) {
+
+ final long DISPOSAL_TIMEOUT = 5000;
+ final Object notificationLock = new Object();
+ Runnable runnable = new Runnable() { public void run() {
+ synchronized(notificationLock) {
+ notificationLock.notifyAll();
+ }
+ } };
+
+ synchronized (notificationLock) {
+ eq.postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(), runnable));
+ try {
+ notificationLock.wait(DISPOSAL_TIMEOUT);
+ } catch (InterruptedException e) {
+ }
+ }
+
+ t.stopDispatching();
+ if (t.isAlive()) {
+ t.interrupt();
+ }
+
+ try {
+ t.join(1000);
+ } catch (InterruptedException e) {
+ }
+ if (t.isAlive()) {
+ org.videolan.Logger.getLogger("BDRootWindow").error("stopEventQueue() failed for " + t);
+ org.videolan.PortingHelper.stopThread(t);
+ }
+ }
+ }
+
+ public static void postKeyEvent(int id, int modifiers, int keyCode) {
+ Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getGlobalFocusOwner();
+ if (focusOwner != null) {
+ long when = System.currentTimeMillis();
+ KeyEvent event;
+ try {
+ if (id == KeyEvent.KEY_TYPED)
+ event = new KeyEvent(focusOwner, id, when, modifiers, KeyEvent.VK_UNDEFINED, (char)keyCode);
+ else
+ event = new KeyEvent(focusOwner, id, when, modifiers, keyCode, KeyEvent.CHAR_UNDEFINED);
+ BDToolkit.getEventQueue(focusOwner).postEvent(event);
+ return;
+ } catch (Throwable e) {
+ org.videolan.Logger.getLogger("BDJHelper").error("postKeyEvent failed: " + e);
+ }
+ } else {
+ org.videolan.Logger.getLogger("BDJHelper").error("*** KEY event dropped ***");
+ }
+ }
+}
diff --git a/src/libbluray/bdj/java/java/awt/BDRootWindow.java b/src/libbluray/bdj/java/java/awt/BDRootWindow.java
index 4ceb78f..78b1441 100644
--- a/src/libbluray/bdj/java/java/awt/BDRootWindow.java
+++ b/src/libbluray/bdj/java/java/awt/BDRootWindow.java
@@ -19,8 +19,6 @@
package java.awt;
-import java.awt.event.InvocationEvent;
-import java.awt.event.KeyEvent;
import java.util.Arrays;
import java.util.Timer;
import java.util.TimerTask;
@@ -67,62 +65,6 @@ public class BDRootWindow extends Frame {
return null;
}
- public static void stopEventQueue(EventQueue eq) {
- EventDispatchThread t = eq.getDispatchThread();
- if (t != null && t.isAlive()) {
-
- final long DISPOSAL_TIMEOUT = 5000;
- final Object notificationLock = new Object();
- Runnable runnable = new Runnable() { public void run() {
- synchronized(notificationLock) {
- notificationLock.notifyAll();
- }
- } };
-
- synchronized (notificationLock) {
- eq.postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(), runnable));
- try {
- notificationLock.wait(DISPOSAL_TIMEOUT);
- } catch (InterruptedException e) {
- }
- }
-
- t.stopDispatching();
- if (t.isAlive()) {
- t.interrupt();
- }
-
- try {
- t.join(1000);
- } catch (InterruptedException e) {
- }
- if (t.isAlive()) {
- org.videolan.Logger.getLogger("BDRootWindow").error("stopEventQueue() failed for " + t);
- org.videolan.PortingHelper.stopThread(t);
- }
- }
- }
-
- public void postKeyEvent(int id, int modifiers, int keyCode) {
- Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getGlobalFocusOwner();
- if (focusOwner != null) {
- long when = System.currentTimeMillis();
- KeyEvent event;
- try {
- if (id == KeyEvent.KEY_TYPED)
- event = new KeyEvent(focusOwner, id, when, modifiers, KeyEvent.VK_UNDEFINED, (char)keyCode);
- else
- event = new KeyEvent(focusOwner, id, when, modifiers, keyCode, KeyEvent.CHAR_UNDEFINED);
- BDToolkit.getEventQueue(focusOwner).postEvent(event);
- return;
- } catch (Throwable e) {
- System.err.println(" *** " + e + "");
- }
- } else {
- org.videolan.Logger.getLogger("BDRootWindow").error("*** KEY event dropped ***");
- }
- }
-
public void notifyChanged() {
if (!isVisible()) {
org.videolan.Logger.getLogger("BDRootWindow").error("sync(): not visible");
diff --git a/src/libbluray/bdj/java/org/dvb/event/EventManager.java b/src/libbluray/bdj/java/org/dvb/event/EventManager.java
index 5390eb2..a1312b2 100644
--- a/src/libbluray/bdj/java/org/dvb/event/EventManager.java
+++ b/src/libbluray/bdj/java/org/dvb/event/EventManager.java
@@ -19,6 +19,7 @@
package org.dvb.event;
+import java.awt.BDJHelper;
import java.util.Iterator;
import java.util.LinkedList;
@@ -140,7 +141,7 @@ public class EventManager implements ResourceServer {
(evt.getCode() == keyCode) &&
(evt.getType() == type)) {
- GUIManager.getInstance().postKeyEvent(type, modifiers, keyCode);
+ BDJHelper.postKeyEvent(type, modifiers, keyCode);
return;
}
}
@@ -163,7 +164,7 @@ public class EventManager implements ResourceServer {
}
}
- GUIManager.getInstance().postKeyEvent(type, modifiers, keyCode);
+ BDJHelper.postKeyEvent(type, modifiers, keyCode);
for (Iterator it = sharedUserEventListener.iterator(); it.hasNext(); ) {
UserEventItem item = (UserEventItem)it.next();
diff --git a/src/libbluray/bdj/java/org/videolan/BDJXletContext.java b/src/libbluray/bdj/java/org/videolan/BDJXletContext.java
index 9290a49..952c785 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJXletContext.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJXletContext.java
@@ -138,7 +138,7 @@ public class BDJXletContext implements javax.tv.xlet.XletContext, javax.microedi
EventQueue eq = eventQueue;
eventQueue = null;
if (eq != null) {
- GUIManager.stopEventQueue(eq);
+ java.awt.BDJHelper.stopEventQueue(eq);
}
}
More information about the libbluray-devel
mailing list