Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 瓦丁阻力和阻力分量_Java_Drag And Drop_Vaadin_Vaadin7 - Fatal编程技术网

Java 瓦丁阻力和阻力分量

Java 瓦丁阻力和阻力分量,java,drag-and-drop,vaadin,vaadin7,Java,Drag And Drop,Vaadin,Vaadin7,我有一个垂直布局,我需要在垂直布局中上下移动组件。我使用了DragAndDropWrapper,但我不确定在DropHandler的drop函数下实现什么。我找到了Absolute布局的示例,它很有效 class MoveHandler implements DropHandler { public AcceptCriterion getAcceptCriterion() { return AcceptAll.get();

我有一个垂直布局,我需要在垂直布局中上下移动组件。我使用了DragAndDropWrapper,但我不确定在DropHandler的drop函数下实现什么。我找到了Absolute布局的示例,它很有效

class MoveHandler implements DropHandler
    {
        public AcceptCriterion getAcceptCriterion()
        {
            return AcceptAll.get();
        }

        public void drop(DragAndDropEvent event)
        {
            WrapperTransferable t = (WrapperTransferable) event.getTransferable();
            WrapperTargetDetails details = (WrapperTargetDetails) event.getTargetDetails();

            // Calculate the drag coordinate difference
            int xChange = details.getMouseEvent().getClientX() - t.getMouseDownEvent().getClientX();
            int yChange = details.getMouseEvent().getClientY() - t.getMouseDownEvent().getClientY();

            // Move the component in the absolute layout
             ComponentPosition pos = ((AbsoluteLayout)
             questionButtonLayout).getPosition(t.getSourceComponent());
             pos.setLeftValue(pos.getLeftValue() + xChange);
             pos.setTopValue(pos.getTopValue() + yChange);
        }
    }

上面是抽象布局的代码。不确定垂直布局要做什么。

vaadin 7.4.5中的拖放功能存在缺陷。如果在drag n drop wrapper下的布局中有多个文本字段,它将永远不会获得鼠标焦点(这意味着您将无法使用鼠标选择它,无法在其中键入任何内容)。它固定在7.7.5中。因此,我使用了以下方法

class MoveHandler implements DropHandler
{
    private static final long       serialVersionUID    = -5709370299130660699L;
    private AbstractOrderedLayout   layout;
    private Level                   level;

    public MoveHandler(AbstractOrderedLayout layout, Level level)
    {
        this.layout = layout;
        this.level = level;
    }

    public AcceptCriterion getAcceptCriterion()
    {
        return AcceptAll.get();
    }

    @SuppressWarnings("deprecation")
    public void drop(DragAndDropEvent dropEvent)
    {
        Transferable transferable = dropEvent.getTransferable();
        Component sourceComponent = transferable.getSourceComponent();
        TargetDetails dropTargetData = dropEvent.getTargetDetails();
        DropTarget target = dropTargetData.getTarget();

        // First question cann't be dragged.
        if (layout.getComponent(0).equals(sourceComponent))
            return;

        // find the location of the dragged component
        Iterator<Component> componentIterator = layout.getComponentIterator();
        Component next = null;
        int indexSourceComponent = 0;
        while (componentIterator.hasNext())
        {
            next = componentIterator.next();
            if (next == sourceComponent)
                break;
            indexSourceComponent++;
        }

        // find the location where to move the dragged component
        boolean sourceWasAfterTarget = true;
        int index = 0;
        componentIterator = layout.getComponentIterator();
        next = null;

        while (next != target && componentIterator.hasNext())
        {
            next = componentIterator.next();

            if (next != sourceComponent)
            {
                index++;
            }
            else
            {
                sourceWasAfterTarget = false;
            }
        }
        if (next == null || next != target)
        {
            // component not found - if dragging from another layout
            return;
        }

        // drop on top of target?
        if (dropTargetData.getData("verticalLocation").equals(VerticalDropLocation.MIDDLE.toString()))
        {
            if (sourceWasAfterTarget)
            {
                index--;
            }
        }

        // drop before the target?
        else if (dropTargetData.getData("verticalLocation").equals(VerticalDropLocation.TOP.toString()))
        {
            index--;
            if (index < 0)
            {
                index = 0;
            }
        }

        // Nothing can be dragged to 1st position. 1st positions is secured for default question.
        if (index == 0)
            return;

        // move component within the layout
        layout.removeComponent(sourceComponent);
        layout.addComponent(sourceComponent, index);

    }
}
类MoveHandler实现DropHandler
{
私有静态最终长serialVersionUID=-5709370299130660699L;
私有抽象有序布局;
私人层面;
公共移动处理程序(AbstractOrderedLayout,级别)
{
this.layout=布局;
这个水平=水平;
}
公共AcceptCriteria GetAcceptCriteria()
{
返回AcceptAll.get();
}
@抑制警告(“弃用”)
公共作废删除(DragAndDropEvent dropEvent)
{
可转移=dropEvent.getTransferable();
Component sourceComponent=transferable.getSourceComponent();
TargetDetails dropTargetData=dropEvent.getTargetDetails();
DropTarget=dropTargetData.getTarget();
//第一个问题不能拖。
if(layout.getComponent(0.equals)(sourceComponent))
返回;
//查找被拖动零部件的位置
迭代器componentiator=layout.getcomponentiator();
组件next=null;
int indexSourceComponent=0;
while(componentIterator.hasNext())
{
next=componentiator.next();
if(next==sourceComponent)
打破
indexSourceComponent++;
}
//查找要移动拖动零部件的位置
布尔sourceWasAfterTarget=true;
int指数=0;
componentiator=layout.getcomponentiator();
next=null;
while(next!=target&&componentiator.hasNext())
{
next=componentiator.next();
如果(下一步!=源组件)
{
索引++;
}
其他的
{
sourceWasAfterTarget=false;
}
}
if(next==null | | next!=target)
{
//未找到组件-如果从其他布局拖动
返回;
}
//落在目标上?
if(dropTargetData.getData(“verticalLocation”).equals(VerticalDropLocation.MIDDLE.toString())
{
如果(sourceWasAfterTarget)
{
索引--;
}
}
//在目标之前降落?
else if(dropTargetData.getData(“verticalLocation”).equals(VerticalDropLocation.TOP.toString())
{
索引--;
如果(指数<0)
{
指数=0;
}
}
//不能将任何内容拖到第一个位置。默认问题的第一个位置是安全的。
如果(索引==0)
返回;
//在布局中移动零部件
布局。移除组件(sourceComponent);
layout.addComponent(sourceComponent,index);
}
}