[英]GWT Drag & Drop Widgets
我正在使用allen sauer的gwt dnd庫來管理gwt小部件在絕對面板上的簡單拖動功能。
盡管這對於簡單的小部件(例如圖像)可以很好地工作,但我想使用自己的小部件(通過擴展Composite)來實現。 當我想要時,它根本不會拖放自定義窗口小部件。
下面是自定義窗口小部件的代碼以及如何將它們添加到絕對面板中:
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);
}
}
在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);
構建這些自定義窗口小部件時我缺少什么?
希望有更多經驗的人可以在這里幫助我...
我終於找到了這個:
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());
}
}
這個答案: 使復合窗口小部件可拖動的問題解決了我的問題,我現在可以將任何類型的復合窗口小部件與dnd一起使用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.