[libbluray-devel] Implement HContainer

Ian Curtis git at videolan.org
Sun Apr 13 16:14:56 CEST 2014


libbluray | branch: master | Ian Curtis <i.curtis at gmail.com> | Sun Apr 13 17:14:24 2014 +0300| [fd968f43de09967f934009a0f81ba5ee0a7028c6] | committer: hpi1

Implement HContainer

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

 src/libbluray/bdj/java/org/havi/ui/HContainer.java |  234 ++++++++++++++++++--
 1 file changed, 217 insertions(+), 17 deletions(-)

diff --git a/src/libbluray/bdj/java/org/havi/ui/HContainer.java b/src/libbluray/bdj/java/org/havi/ui/HContainer.java
index 646b4fd..cdf67f9 100644
--- a/src/libbluray/bdj/java/org/havi/ui/HContainer.java
+++ b/src/libbluray/bdj/java/org/havi/ui/HContainer.java
@@ -23,92 +23,292 @@ import java.awt.Component;
 import java.awt.Container;
 import org.dvb.ui.TestOpacity;
 
+//https://www.jinahya.com/mvn/site/com.googlecode.jinahya/ocap-api/1.3.1/apidocs/org/havi/ui/HContainer.html
+
 public class HContainer extends Container implements HMatteLayer,
         HComponentOrdering, TestOpacity {
     public HContainer()
     {
-        org.videolan.Logger.unimplemented(HContainer.class.getName(), "");
+        this(0,0,0,0);
     }
 
     public HContainer(int x, int y, int width, int height)
     {
-        org.videolan.Logger.unimplemented(HContainer.class.getName(), "");
+        setBounds(x,y,width,height);
     }
 
     public void setMatte(HMatte m) throws HMatteException
     {
-        throw new Error("Not implemented");
+        throw new HMatteException("Matte is not supported");
     }
 
     public HMatte getMatte()
     {
-        throw new Error("Not implemented");
+        return hMatte;
     }
 
     public boolean isDoubleBuffered()
     {
-        throw new Error("Not implemented");
+        return false;   // can this be true ?
     }
 
     public boolean isOpaque()
     {
-        throw new Error("Not implemented");
+        return false;   // can this be true ?
+    }
+
+    private int getOffset(java.awt.Component c) throws ArrayIndexOutOfBoundsException
+    {
+        Component cs[] = getComponents();
+        for (int i = 0; i < cs.length; ++i)
+            if (cs[i] == c) return i;
+
+        throw new ArrayIndexOutOfBoundsException("Component not contained within");
+    }
+
+    private void checkLineage(java.awt.Component c)
+    {
+        if (c.getParent() != this) throw new ArrayIndexOutOfBoundsException("Component not contained within");
     }
 
     public Component addBefore(Component component, Component behind)
     {
-        throw new Error("Not implemented");
+        // check to see if behind is an element of this container
+        try
+        {
+            getOffset(behind);
+        }
+        catch (Exception e)
+        {
+            return null;
+        }
+
+        if (component == behind) return component;
+        synchronized (getTreeLock())
+        {
+            try
+            {
+                // Explicitly remove component if in this container.
+                // Should have no effect if not in this container.
+                // This must be done so that problems don't occur
+                // when componentIndex < frontIndex.
+                remove(component);
+
+                int offset = getOffset(behind);
+
+                return add(component, offset);
+            }
+            catch (Exception e)
+            {
+                return null;
+            }
+        }
     }
 
     public Component addAfter(Component component, Component front)
     {
-        throw new Error("Not implemented");
+        // check to see if front is an element of this container
+        try
+        {
+            getOffset(front);
+        }
+        catch (Exception e)
+        {
+            return null;
+        }
+
+        if (component == front) return component;
+        synchronized (getTreeLock())
+        {
+            try
+            {
+                // Explicitly remove component if in this container.
+                // Should have no effect if not in this container.
+                // This must be done so that problems don't occur
+                // when componentIndex < frontIndex.
+                remove(component);
+
+                int offset = getOffset(front);
+
+                return add(component, offset + 1);
+            }
+            catch (Exception e)
+            {
+                return null;
+            }
+        }
     }
 
     public boolean popToFront(Component component)
     {
-        throw new Error("Not implemented");
+        synchronized (getTreeLock())
+        {
+            try
+            {
+                // Ensure it is there
+                checkLineage(component);
+
+                // explicitly remove component
+                // (even if reparenting is implicit)
+                remove(component);
+                add(component, 0);
+                return true;
+            }
+            catch (Exception e)
+            {
+                return false;
+            }
+        }
     }
 
     public boolean pushToBack(Component component)
     {
-        throw new Error("Not implemented");
+        synchronized (getTreeLock())
+        {
+            try
+            {
+                // Ensure it is there
+                checkLineage(component);
+
+                // explicitly remove component
+                // (even if reparenting is implicit)
+                remove(component);
+                add(component, -1);
+                return true;
+            }
+            catch (Exception e)
+            {
+                return false;
+            }
+        }
     }
 
     public boolean pop(Component component)
     {
-        throw new Error("Not implemented");
+        synchronized (getTreeLock())
+        {
+            try
+            {
+                int offset = getOffset(component);
+
+                if (offset > 0)
+                {
+                    // explicitly remove component
+                    // (even if reparenting is implicit)
+                    remove(component);
+                    add(component, offset - 1);
+                    return true;
+                }
+            }
+            catch (Exception e)
+            {
+            }
+            return false;
+        }
     }
 
     public boolean push(Component component)
     {
-        throw new Error("Not implemented");
+        synchronized (getTreeLock())
+        {
+            try
+            {
+                int offset = getOffset(component);
+                int count = getComponentCount();
+
+                if (offset == (count - 1))
+                {
+                    return true;
+                }
+
+                if (offset < (count - 1))
+                {
+                    // explicitly remove component
+                    // (even if reparenting is implicit)
+                    remove(component);
+                    add(component, offset + 1);
+                    return true;
+                }
+            }
+            catch (Exception e)
+            {
+            }
+
+            return false;
+        }
     }
 
     public boolean popInFrontOf(Component move, Component behind)
     {
-        throw new Error("Not implemented");
+        synchronized (getTreeLock())
+        {
+            try
+            {
+                if (move != behind)
+                {
+                    // Ensure they are present
+                    checkLineage(move);
+                    checkLineage(behind);
+
+                    // explicitly remove component
+                    // (even if reparenting is implicit)
+                    remove(move);
+                    // Re-add
+                    addBefore(move, behind);
+                }
+                return true;
+            }
+            catch (Exception e)
+            {
+                return false;
+            }
+        }
     }
 
     public boolean pushBehind(Component move, Component front)
     {
-        throw new Error("Not implemented");
+        synchronized (getTreeLock())
+        {
+            try
+            {
+                if (move != front)
+                {
+                    // Ensure they are present
+                    checkLineage(move);
+                    checkLineage(front);
+
+                    // explicitly remove component
+                    // (even if reparenting is implicit)
+                    remove(move);
+                    // re-add in proper location
+                    addAfter(move, front);
+                }
+                return true;
+            }
+            catch (Exception e)
+            {
+                return false;
+            }
+        }
     }
 
     public void group()
     {
-        throw new Error("Not implemented");
+        grouped = true;
     }
 
     public void ungroup()
     {
-        throw new Error("Not implemented");
+        grouped = false;
     }
 
     public boolean isGrouped()
     {
-        throw new Error("Not implemented");
+       return grouped;
     }
 
+    private HMatte hMatte = null;
+    private boolean grouped = false;
+
     private static final long serialVersionUID = 263606166411114032L;
 }



More information about the libbluray-devel mailing list