/**
 *
 */
package com.github.apixandru.games.rummikub.ui;

import javax.swing.*;
import java.awt.*;

/**
 * @author Alexandru-Constantin Bledea
 * @since Oct 15, 2015
 */
final class ComponentDragSource implements DragSource {

    private final Container parent;
    private final Container container;

    /**
     * @param container
     */
    public ComponentDragSource(final Container container) {
        this.parent = container.getParent();
        this.container = container;
    }

    /* (non-Javadoc)
     * @see com.github.apixandru.games.rummikub.ui.DragSource#getComponentAt(int, int)
     */
    @Override
    public JComponent getComponentAt(final int x, final int y) {
        return (JComponent) this.container.findComponentAt(x, y);
    }

    /* (non-Javadoc)
     * @see com.github.apixandru.games.rummikub.ui.DragSource#beginDrag(java.awt.Component)
     */
    @Override
    public void beginDrag(final Component component) {
        this.parent.add(component, JLayeredPane.DRAG_LAYER);
    }

    /* (non-Javadoc)
     * @see com.github.apixandru.games.rummikub.ui.DragSource#endDrag(java.awt.Component)
     */
    @Override
    public void endDrag(final Component component) {
        this.parent.remove(component);
        this.parent.repaint();
    }

}

@@ -277,32 +277,34 @@
  final Container
+%5B%5D
  container;%0A%0A   
@@ -297,16 +297,17 @@
 ontainer
+s
 ;%0A%0A    /
@@ -332,16 +332,17 @@
 ontainer
+s
 %0A     */
@@ -388,16 +388,19 @@
 ontainer
+...
  contain
@@ -401,16 +401,17 @@
 ontainer
+s
 ) %7B%0A    
@@ -437,16 +437,20 @@
 ontainer
+s%5B0%5D
 .getPare
@@ -477,16 +477,17 @@
 ontainer
+s
  = conta
@@ -490,16 +490,17 @@
 ontainer
+s
 ;%0A    %7D%0A
@@ -707,64 +707,293 @@
     
-return (JComponent) this.container.findComponentAt(x, y)
+for (Container container : containers) %7B%0A            final Component componentAt = container.findComponentAt(x - container.getX(), y - container.getY());%0A            if (null != componentAt) %7B%0A                return (JComponent) componentAt;%0A            %7D%0A        %7D%0A        return null
 ;%0A  

the component could be at a different location than 0, 0