[libbluray-devel] Implement UOMaskTableControlImpl listener interface

hpi1 git at videolan.org
Wed Feb 6 22:18:53 CET 2013


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Wed Feb  6 12:01:48 2013 +0200| [2f9ec89e473748a7827c819624d2e76017fe7923] | committer: hpi1

Implement UOMaskTableControlImpl listener interface

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=2f9ec89e473748a7827c819624d2e76017fe7923
---

 .../content/playlist/UOMaskTableControlImpl.java   |   69 ++++++++++++++++++--
 1 file changed, 62 insertions(+), 7 deletions(-)

diff --git a/src/libbluray/bdj/java/org/videolan/media/content/playlist/UOMaskTableControlImpl.java b/src/libbluray/bdj/java/org/videolan/media/content/playlist/UOMaskTableControlImpl.java
index 60596d0..c324acc 100644
--- a/src/libbluray/bdj/java/org/videolan/media/content/playlist/UOMaskTableControlImpl.java
+++ b/src/libbluray/bdj/java/org/videolan/media/content/playlist/UOMaskTableControlImpl.java
@@ -1,6 +1,7 @@
 /*
  * This file is part of libbluray
  * Copyright (C) 2010  William Hahne
+ * Copyright (C) 2012  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
@@ -20,12 +21,17 @@
 package org.videolan.media.content.playlist;
 
 import java.awt.Component;
+import java.util.LinkedList;
 
 import org.bluray.media.UOMaskTableControl;
 import org.bluray.media.UOMaskTableListener;
+import org.bluray.media.UOMaskTableChangedEvent;
+import org.bluray.media.UOMaskedEvent;
+
+import org.videolan.BDJAction;
+import org.videolan.BDJActionManager;
 import org.videolan.PlaylistInfo;
 
-// TODO: don't know what this is for
 public class UOMaskTableControlImpl implements UOMaskTableControl {
     protected UOMaskTableControlImpl(Handler player) {
         this.player = player;
@@ -36,22 +42,71 @@ public class UOMaskTableControlImpl implements UOMaskTableControl {
     }
 
     public void addUOMaskTableEventListener(UOMaskTableListener listener) {
-        throw new Error("Not implemented"); // TODO: Not implemented
+        synchronized(listeners) {
+            listeners.add(listener);
+        }
     }
 
     public void removeUOMaskTableEventListener(UOMaskTableListener listener) {
-        throw new Error("Not implemented"); // TODO: Not implemented
+        synchronized(listeners) {
+            listeners.remove(listener);
+        }
     }
 
     public boolean[] getMaskedUOTable() {
-        PlaylistInfo pi = player.getPlaylistInfo();
-        if (pi == null)
-                return new boolean[0];
+        org.videolan.Logger.unimplemented("UOMaskTableControlImpl", "getMaskedUOTable");
+        // TODO: set masks
+
         boolean[] table = new boolean[64];
         for (int i = 0; i < 64; i++)
-                table[i] = false;
+            table[i] = false;
+
         return table;
     }
 
+    protected void onUOMasked(int position) {
+        // TODO: this method is not called
+        notifyListeners(new UOMaskedEvent(this, position));
+    }
+
+    protected void onPlayItemReach(int param) {
+        // TODO: check if masked UO table actually changed
+        notifyListeners(new UOMaskTableChangedEvent(this));
+    }
+
+    private void notifyListeners(Object event) {
+        synchronized (listeners) {
+            if (!listeners.isEmpty())
+                BDJActionManager.getInstance().putCallback(
+                        new UOMaskTableCallback(this, event));
+        }
+    }
+
+    private class UOMaskTableCallback extends BDJAction {
+        private UOMaskTableCallback(UOMaskTableControlImpl control, Object event) {
+            this.control = control;
+            this.event = event;
+        }
+
+        protected void doAction() {
+            LinkedList list;
+            synchronized (control.listeners) {
+                list = (LinkedList)control.listeners.clone();
+            }
+            if (event instanceof UOMaskTableChangedEvent) {
+                for (int i = 0; i < list.size(); i++)
+                    ((UOMaskTableListener)list.get(i)).receiveUOMaskTableChangedEvent((UOMaskTableChangedEvent)event);
+            }
+            else if (event instanceof UOMaskedEvent) {
+                for (int i = 0; i < list.size(); i++)
+                    ((UOMaskTableListener)list.get(i)).receiveUOMaskedEvent((UOMaskedEvent)event);
+            }
+        }
+
+        private UOMaskTableControlImpl control;
+        private Object event;
+    }
+
+    private LinkedList listeners = new LinkedList();
     private Handler player;
 }



More information about the libbluray-devel mailing list