[libbluray-devel] Added shutdown to BDToolkit and BDKeyboardFocusManagerPeer
hpi1
git at videolan.org
Sat Mar 30 01:39:09 CET 2013
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Sat Mar 30 00:27:35 2013 +0200| [5a1535455d55ce252bcf32bf6682765e9757f0c2] | committer: hpi1
Added shutdown to BDToolkit and BDKeyboardFocusManagerPeer
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=5a1535455d55ce252bcf32bf6682765e9757f0c2
---
.../bdj/java-j2me/java/awt/BDToolkit.java | 17 +++++++-
.../bdj/java-j2se/java/awt/BDToolkit.java | 18 +++++++-
.../java/awt/peer/BDKeyboardFocusManagerPeer.java | 45 ++++++++++++++------
src/libbluray/bdj/java/org/videolan/Libbluray.java | 2 +
4 files changed, 68 insertions(+), 14 deletions(-)
diff --git a/src/libbluray/bdj/java-j2me/java/awt/BDToolkit.java b/src/libbluray/bdj/java-j2me/java/awt/BDToolkit.java
index 5e74d3e..c439fad 100644
--- a/src/libbluray/bdj/java-j2me/java/awt/BDToolkit.java
+++ b/src/libbluray/bdj/java-j2me/java/awt/BDToolkit.java
@@ -35,7 +35,7 @@ import sun.awt.image.URLImageSource;
import org.videolan.BDJXletContext;
import org.videolan.Logger;
-class BDToolkit extends Toolkit {
+public class BDToolkit extends Toolkit {
private EventQueue eventQueue = new EventQueue();
private BDGraphicsEnvironment localEnv = new BDGraphicsEnvironment();
private BDGraphicsConfiguration defaultGC = (BDGraphicsConfiguration)localEnv.getDefaultScreenDevice().getDefaultConfiguration();
@@ -48,6 +48,21 @@ class BDToolkit extends Toolkit {
/* nothing to do */
}
+ public static void shutdown() {
+ Toolkit toolkit = getDefaultToolkit();
+ if (toolkit instanceof BDToolkit) {
+ ((BDToolkit)toolkit).dispose();
+ }
+ }
+
+ public void dispose() {
+ if (eventQueue != null) {
+ eventQueue.getDispatchThread().stopDispatching();
+ eventQueue = null;
+ }
+ cachedImages = null;
+ }
+
public Dimension getScreenSize() {
Rectangle dims = defaultGC.getBounds();
return new Dimension(dims.width, dims.height);
diff --git a/src/libbluray/bdj/java-j2se/java/awt/BDToolkit.java b/src/libbluray/bdj/java-j2se/java/awt/BDToolkit.java
index dba8074..fecec43 100644
--- a/src/libbluray/bdj/java-j2se/java/awt/BDToolkit.java
+++ b/src/libbluray/bdj/java-j2se/java/awt/BDToolkit.java
@@ -50,6 +50,21 @@ public class BDToolkit extends Toolkit implements KeyboardFocusManagerPeerProvid
public BDToolkit () {
}
+ public static void shutdown() {
+ Toolkit toolkit = getDefaultToolkit();
+ if (toolkit instanceof BDToolkit) {
+ ((BDToolkit)toolkit).dispose();
+ }
+ }
+
+ public void dispose() {
+ if (eventQueue != null) {
+ eventQueue.getDispatchThread().stopDispatching();
+ eventQueue = null;
+ }
+ BDKeyboardFocusManagerPeer.shutdown();
+ }
+
public static void setFocusedWindow(Window window) {
/* hook KeyboardFocusManagerPeer (not doing this leads to crash) */
BDKeyboardFocusManagerPeer.init(window);
@@ -57,7 +72,7 @@ public class BDToolkit extends Toolkit implements KeyboardFocusManagerPeerProvid
public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager kfm)
{
- return BDKeyboardFocusManagerPeer.init(kfm);
+ return BDKeyboardFocusManagerPeer.getInstance();
}
public Dimension getScreenSize() {
@@ -94,6 +109,7 @@ public class BDToolkit extends Toolkit implements KeyboardFocusManagerPeerProvid
}
public void sync() {
+ org.videolan.GUIManager.getInstance().sync();
}
static void clearCache(BDImage image) {
diff --git a/src/libbluray/bdj/java-j2se/java/awt/peer/BDKeyboardFocusManagerPeer.java b/src/libbluray/bdj/java-j2se/java/awt/peer/BDKeyboardFocusManagerPeer.java
index 9edc938..76ef4a8 100644
--- a/src/libbluray/bdj/java-j2se/java/awt/peer/BDKeyboardFocusManagerPeer.java
+++ b/src/libbluray/bdj/java-j2se/java/awt/peer/BDKeyboardFocusManagerPeer.java
@@ -25,17 +25,37 @@ import java.awt.Window;
import java.lang.reflect.Field;
public class BDKeyboardFocusManagerPeer implements KeyboardFocusManagerPeer {
- private Component focusOwner;
- private Window window; /* used in java 6 only */
+ private static boolean java7 = false;
+ static BDKeyboardFocusManagerPeer instance = null;
- private static KeyboardFocusManager kfm = null; /* used in java 7 only */
+ /* used in java 7 only */
+ public static KeyboardFocusManagerPeer getInstance() {
+ java7 = true;
+
+ if (instance == null)
+ instance = new BDKeyboardFocusManagerPeer();
+ return instance;
+ }
+
+ public static void shutdown()
+ {
+ if (instance != null) {
+ instance.dispose();
+ instance = null;
+ }
+ }
public static void init(Window window)
{
/* running in java 7 ? */
- if (kfm != null)
+ if (java7 == true)
return;
+ if (instance == null)
+ instance = new BDKeyboardFocusManagerPeer();
+ instance.focusOwner = null;
+ instance.window = window;
+
/* replace default keyboard focus manager peer */
Field kbPeer;
try {
@@ -51,21 +71,22 @@ public class BDKeyboardFocusManagerPeer implements KeyboardFocusManagerPeer {
}
try {
kbPeer.set(KeyboardFocusManager.getCurrentKeyboardFocusManager(),
- new BDKeyboardFocusManagerPeer(window));
+ instance);
} catch (java.lang.IllegalAccessException e) {
throw new Error("java.awt.KeyboardFocusManager.peer not accessible:" + e);
}
}
- /* used in java 7 only */
- public static KeyboardFocusManagerPeer init(KeyboardFocusManager _kfm) {
- kfm = _kfm;
- return new BDKeyboardFocusManagerPeer(null);
- }
+ private Component focusOwner = null;
+ private Window window = null; /* used in java 6 only */
- private BDKeyboardFocusManagerPeer(Window w) {
- window = w;
+ public void dispose()
+ {
focusOwner = null;
+ window = null;
+ }
+
+ private BDKeyboardFocusManagerPeer() {
}
public void clearGlobalFocusOwner(Window w) {
diff --git a/src/libbluray/bdj/java/org/videolan/Libbluray.java b/src/libbluray/bdj/java/org/videolan/Libbluray.java
index 7b88a36..4ec7134 100644
--- a/src/libbluray/bdj/java/org/videolan/Libbluray.java
+++ b/src/libbluray/bdj/java/org/videolan/Libbluray.java
@@ -19,6 +19,7 @@
package org.videolan;
+import java.awt.BDToolkit;
import java.awt.event.KeyEvent;
import java.util.Vector;
@@ -127,6 +128,7 @@ public class Libbluray {
MountManager.unmountAll();
org.havi.ui.HSceneFactory.shutdown();
GUIManager.shutdown();
+ BDToolkit.shutdown();
} catch (Throwable e) {
e.printStackTrace();
}
More information about the libbluray-devel
mailing list