我使用提供拖放的小部件。这就是我的UiBinder的样子:
mainPanel = new FlowPanel();
dropPanel = new DropPanel();
dropLabel = new Label("Drop Image here!");
mainPanel.add(dropPanel);
mainPanel.add(dropLabel);
initWidget(mainPanel);
dropPanel支持以下事件:
dropPanel.addDragEnterHandler(new DragEnterHandler() {
@Override
public void onDragEnter(DragEnterEvent event) {
event.stopPropagation();
event.preventDefault();
dropPanel.addStyleName(resources.css().active());
dropLabel.removeStyleName(resources.css().hide());
GWT.log("onDragEnter");
}
});
dropPanel.addDragLeaveHandler(new DragLeaveHandler() {
@Override
public void onDragLeave(DragLeaveEvent event) {
event.stopPropagation();
event.preventDefault();
dropPanel.removeStyleName(resources.css().active());
dropLabel.addStyleName(resources.css().hide());
GWT.log("onDragLeave");
}
});
这是我使用的风格:
.mainPanel {
position: relative;
}
.active {
border: 2pt solid green;
}
.dropLabel {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
width: 50%;
height: 50%;
text-align: center;
vertical-align: middle;
color: #ccc;
font-size: 20pt;
line-height: 14pt;
font-weight: bold;
background-color: yellow;
}
.hide {
display: none;
}
当我拖动dropPanel时,标签变得可见。当我在dropPanel内的标签上拖动某些东西时,DragLeaveEvent
被触发。
当我将Label拖到底层的dropPanel上时,有什么方法可以转发DragEvents吗?