gpt4 book ai didi

java - gxt 网格中的鼠标移动事件

转载 作者:行者123 更新时间:2023-12-01 05:19:31 24 4
gpt4 key购买 nike

我想在鼠标拖动时选择网格中的行,因为我有以下代码:

我的鼠标事件监听器是DragMultiSelectListener.java

import java.util.List;

import com.myexample.client.ui.items.AbstractContentItem;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.GridEvent;
import com.extjs.gxt.ui.client.event.Listener;

public class DragMultiSelectListener implements Listener<BaseEvent> {

Presenter presenter = null;

/* multiple select on drag */
private boolean mousePressed = false;
private boolean dragEnable = false;
private boolean selected = false;
private List<AbstractContentItem> currentSelected = null;
private int startIndex = -1;
private int endIndex = -1;
private int startX=0;
private int startY=0;
private int endX=0;
private int endY=0;

/** mouseMovedStarted used for preventing calling Grid onClick event for IE while using multiple select on DND **/
private boolean mouseMovedStarted = false;

public DragMultiSelectListener(Presenter pPresenter) {
this.presenter = pPresenter;
}

@Override
public void handleEvent(BaseEvent be) {
if(be.getType() == Events.OnMouseDown){
GridEvent ge = (GridEvent) be;

/* Multiple Row Select */
mouseMovedStarted = false;
mousePressed = true;
startIndex = ge.getRowIndex();

/* Deselect All */
if(ge.getTarget().getClassName().equals("x-grid3-scroller")){
if(ge.getTarget().getClientWidth() < ge.getTarget().getScrollWidth()){
if(ge.getTarget().getClientHeight() < (ge.getClientY() - ge.getTarget().getAbsoluteTop())){
mousePressed = false;
}
if(ge.getTarget().getClientWidth() < (ge.getClientX() - ge.getTarget().getAbsoluteLeft())){
mousePressed = false;
}
}
presenter.deselectAllContentItem();
}

/* Select Record */
if(currentSelected != null && (!presenter.getSelectedContent().isEmpty())){
selected = false;
for(AbstractContentItem item : currentSelected){
AbstractContentItem clickedItem = (AbstractContentItem) ge.getGrid().getStore().getAt(ge.getRowIndex());
if(clickedItem != null && item.getDTO().getId() == clickedItem.getDTO().getId()){
selected = true;
}
}
}else{
currentSelected = presenter.getSelectedContent();
selected = false;
}

dragEnable = false;

if(ge.getTarget().getNodeName().equalsIgnoreCase("SPAM")){
dragEnable = true;
}

if(selected){
dragEnable = true;
}

/* draw box */
if(mousePressed){
startX = ge.getClientX();
startY = ge.getClientY();
}

}else if(be.getType() == Events.OnMouseMove){
GridEvent ge = (GridEvent) be;

if(mousePressed && !dragEnable && (ge.getRowIndex() != -1) ){

if(startIndex == -1){
startIndex = ge.getRowIndex();
}

endIndex = ge.getRowIndex();
presenter.deselectAllContentItem();
if((startIndex - endIndex) >= 0){
for(int i = endIndex; i<=startIndex; i++ ){
presenter.selectContentItem(i, true);
}
}else{
for(int i = startIndex; i<=endIndex; i++ ){
presenter.selectContentItem(i, true);
}
}

/* Show selection box */
endX = ge.getClientX();
endY = ge.getClientY();



}else if(mousePressed && !dragEnable){

/* Show selection box */
endX = ge.getClientX();
endY = ge.getClientY();

if(ge.getTarget().getClassName().equals("x-grid3-scroller")){
if(startY > endY){
presenter.deselectAllContentItem();
}
}

displaySelectionBox(ge.getGrid().getAbsoluteLeft(), ge.getGrid().getAbsoluteTop());
}
mouseMovedStarted = true;

}else if(be.getType() == Events.OnMouseUp){
GridEvent ge = (GridEvent) be;
mousePressed = false;
currentSelected = presenter.getSelectedContent();

}
}

public boolean isMouseMovedStarted() {
return mouseMovedStarted;
}

public boolean isDragEnable() {
return dragEnable;
}

public void setEndX(int endX) {
this.endX = endX;
}

public void setEndY(int endY) {
this.endY = endY;
}

public boolean isSelected() {
return selected;
}

public void setSelected(boolean selected) {
this.selected = selected;
}

public List<AbstractContentItem> getCurrentSelected() {
return currentSelected;
}

public void setCurrentSelected(List<AbstractContentItem> currentSelected) {
this.currentSelected = currentSelected;
}

public void setMousePressed(boolean mousePressed) {
this.mousePressed = mousePressed;
}

}

通过以下代码注册网格事件

      dragMultiSelectListener = new DragMultiSelectListener(presenter);
grid.addListener(Events.OnMouseDown, dragMultiSelectListener);
grid.addListener(Events.OnMouseMove, dragMultiSelectListener);
grid.addListener(Events.OnMouseUp, dragMultiSelectListener);

问题是,当我快速移动鼠标时,它会跳过选择某些行。

我不明白,如何提高执行速度以防止跳行。

谢谢

最佳答案

您可以选择从 DragStart x y 到当前 x y 的所有行。唯一的事情是,您将需要行高来计算行。

关于java - gxt 网格中的鼠标移动事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10650336/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com