简体   繁体   English

GWT拖放小部件

[英]GWT Drag & Drop Widgets

I am using allen sauer's gwt dnd library to manage a simple drag functionality of gwt widgets across an absolute panel. 我正在使用allen sauer的gwt dnd库来管理gwt小部件在绝对面板上的简单拖动功能。

While this works fine with simple widgets (like images), I want to do it using my own widget (by extending composite). 尽管这对于简单的小部件(例如图像)可以很好地工作,但我想使用自己的小部件(通过扩展Composite)来实现。 It simply does not drag & drop the custom widgets when I want it to. 当我想要时,它根本不会拖放自定义窗口小部件。

Below you have my code for the custom widget and how they are added to the absolute panel: 下面是自定义窗口小部件的代码以及如何将它们添加到绝对面板中:

package GWTest.artid.client;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class DraggableWidget extends Composite {

    private Image image;

    private Label label = new Label();

    private Button button = new Button("Configure");

    private VerticalPanel panel = new VerticalPanel();

    public DraggableWidget(String imagePath, String labelText, boolean hasButton) {
        super();
        this.image = new Image(imagePath);
        this.label.setText(labelText);

        this.panel.add(image);
        this.panel.add(label);
        if (hasButton) {
            this.panel.add(button);
        }

        initWidget(panel);
    }

    public Image getImage() {
        return image;
    }

    public void setImage(String imagePath) {
        this.image = new Image(imagePath);
    }

    public Label getLabel() {
        return label;
    }

    public void setLabelText(String labelText) {
        this.label.setText(labelText);
    }

    public Button getButton() {
        return button;
    }

    public void setButtonText(String buttonText) {
        this.button.setText(buttonText);
    }
}

In onModuleLoad (COMPUTER_WIDGET and ROUTER_WIDGET are only Strings, paths to image resources): 在onModuleLoad中(COMPUTER_WIDGET和ROUTER_WIDGET只是字符串,是图像资源的路径):

absolutePanel.setPixelSize(600, 200);
dropController = new AbsolutePositionDropController(absolutePanel);
dragController = new PickupDragController(absolutePanel, true);
dragController.registerDropController(dropController);

DraggableWidget w = new DraggableWidget(DraggableFactory.COMPUTER_WIDGET, "Label 1", false);
DraggableWidget w1 = new DraggableWidget(DraggableFactory.ROUTER_WIDGET, "Label 2", true);

dragController.makeDraggable(w1);
dragController.makeDraggable(w);

dropController.drop(w1, 10, 30);
dropController.drop(w, 10, 30);

Is there anything I'm missing when building these custom widgets? 构建这些自定义窗口小部件时我缺少什么?

Hopefully someone with a bit more experience can help me out here... 希望有更多经验的人可以在这里帮助我...

I finally found this: 我终于找到了这个:

public class MyWidget extends Composite implements HasAllMouseHandlers, HasClickHandlers {

...

      public HandlerRegistration addClickHandler(ClickHandler handler) {
        return addDomHandler(handler, ClickEvent.getType());
      }

      public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
          return addDomHandler(handler, MouseDownEvent.getType());
      }

      public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
        return addDomHandler(handler, MouseMoveEvent.getType());
      }

      public HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
        return addDomHandler(handler, MouseOutEvent.getType());
      }

      public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
        return addDomHandler(handler, MouseOverEvent.getType());
      }

      public HandlerRegistration addMouseUpHandler(MouseUpHandler handler) {
        return addDomHandler(handler, MouseUpEvent.getType());
      }

      public HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler) {
        return addDomHandler(handler, MouseWheelEvent.getType());
      }

}

This answer: Issue in making composite widget draggable solved my issue and I can use any sort of Composite widgets with dnd now 这个答案: 使复合窗口小部件可拖动的问题解决了我的问题,我现在可以将任何类型的复合窗口小部件与dnd一起使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM