📄 sdalistview.java
字号:
int swidth = 0; if ((scrollBars == SDAConsts.srHorizontal) || (scrollBars == SDAConsts.srNone)) { swidth = getWidth(); } if ((scrollBars == SDAConsts.srBoth) || (scrollBars == SDAConsts.srVertical)) { swidth = getWidth() - barwidth; } return swidth; } private int getVBarHeight() { int sheight = 0; if ((scrollBars == SDAConsts.srVertical) || (scrollBars == SDAConsts.srNone)) { sheight = getHeight(); } if ((scrollBars == SDAConsts.srBoth) || (scrollBars == SDAConsts.srHorizontal)) { sheight = getHeight() - barwidth; } return sheight; } private void getItemByPos(int x, int y) { int itemWidth = maxLenght / colCount; int col = (x + startLeft) / itemWidth; int row = (y + startTop) / rowHeight; SDAListViewItem item = getItemByColRow(col, row); if (item != null) { curItem = item; } } private SDAListViewItem getItemByColRow(int col, int row) { SDAListViewItem item = null; int index = row * colCount + col; if ((index < itemList.size()) && index > -1) { item = (SDAListViewItem) itemList.elementAt(index); } return item; } //处理事件的执行 //点箭头滚动内容 protected void doPointerPressed(int x, int y) { int posx = screenXToClient(x); int posy = screenYToClient(y); int thisWidth = getWidth(); int thisHeight = getHeight(); int VBarHeight = getVBarHeight(); int HBarWidth = getHBarWidth(); //确定点击了滚动条区域 if ((scrollBars == SDAConsts.srHorizontal) || (scrollBars == SDAConsts.srBoth)) { //判断是否点击了左箭头 if (InClientRect(posx, posy, 0, thisHeight - barwidth, barwidth, barwidth)) { //向右滚动 if (startLeft > 0) { int step = getFont().charWidth('x'); startLeft -= step; if (startLeft < 0) { startLeft = 0; } } } else //右箭头 if (InClientRect(posx, posy, HBarWidth - barwidth, thisHeight - barwidth, barwidth, barwidth)) { //向左滚动 if (maxLenght - startLeft > HBarWidth) { int step = getFont().charWidth('x'); startLeft += step; } } else //滚动条 if (InClientRect(posx, posy, HSLeft, HSTop, HSWidth, HSHeight)) { //记录点击的滚动条位置 oldScrollPointx = posx; oldScrollPointy = posy; isscrollbarpointdown = true; scrollbardownHV = 0; oldStartLeft = startLeft; } else { if (InClientRect(posx, posy, 0, thisHeight - barwidth, HBarWidth, barwidth)) { //点了空白的,滚动到点击的位置 //计算滚动块要到位置 int tpos = posx > HSLeft ? (posx - HSWidth) : (posx); //计算StartLeft startLeft = ((tpos - barwidth) * (maxLenght)) / (HBarWidth - 2 * barwidth); } } } if ((scrollBars == SDAConsts.srVertical) || (scrollBars == SDAConsts.srBoth)) { //只有垂直滚动条 //判断是否点击了上箭头 if (InClientRect(posx, posy, thisWidth - barwidth, 0, barwidth, barwidth)) { //向下滚动 if (startTop > 0) { startTop--; } } else //下箭头 if (InClientRect(posx, posy, thisWidth - barwidth, VBarHeight - barwidth, barwidth, barwidth)) { //向上滚动 startTop = (maxHeight - startTop > VBarHeight) ? startTop + 1 : startTop; } else //滚动条 if (InClientRect(posx, posy, VSLeft, VSTop, VSWidth, VSHeight)) { //记录位置 oldScrollPointx = posx; oldScrollPointy = posy; isscrollbarpointdown = true; scrollbardownHV = 1; oldStartLine = startTop; } else { if (InClientRect(posx, posy, thisWidth - barwidth, 0, barwidth, VBarHeight)) { //空白的 //计算滚动块要到位置 int tpos = posy > VSTop ? (posy - VSHeight) : (posy); //计算StartLine int oldline = startTop; startTop = ((tpos - barwidth) * maxHeight) / (VBarHeight - 2 * barwidth); if (oldline == startTop) { startTop = posy > VSTop ? startTop + 1 : startTop - 1; } } } } //点到空白按钮位置,获取当前Item if (InClientRect(posx, posy, 0, 0, getHBarWidth(), getVBarHeight())) { getItemByPos(posx, posy); doSelectChange(); doSelectItem(); } } //拖动事件处理 protected void doPointerReleased(int x, int y) { int posx = screenXToClient(x); int posy = screenYToClient(y); int VBarHeight = getVBarHeight(); int HBarWidth = getHBarWidth(); //根据点击的位置,判断滚动的多少 if ((scrollBars == SDAConsts.srHorizontal) || ((scrollBars == SDAConsts.srBoth) && (scrollbardownHV == 0))) { if (isscrollbarpointdown) { int stepx = posx - oldScrollPointx; //根据滚动多少来重新定位 //计算滚动块要到位置 int tpos = HSLeft + stepx; HSLeft = tpos < barwidth ? barwidth : tpos; HSLeft = HSLeft + HSWidth > HBarWidth - barwidth ? HBarWidth - barwidth - HSWidth : HSLeft; //计算StartLeft startLeft = ((HSLeft - barwidth) * (maxLenght)) / (HBarWidth - 2 * barwidth); if (oldStartLeft != startLeft) { oldScrollPointx = posx; oldStartLeft = startLeft; } else { oldStartLeft = startLeft; if (stepx > 0) { startLeft = maxLenght - startLeft < getHBarWidth() ? startLeft + 1 : startLeft; } if (stepx < 0) { startLeft = startLeft == 0 ? 0 : startLeft - 1; } } } } if ((scrollBars == SDAConsts.srVertical) || ((scrollBars == SDAConsts.srBoth) && (scrollbardownHV == 1))) { if (isscrollbarpointdown) { int stepy = posy - oldScrollPointy; //根据滚动多少来重新定位 //计算滚动块要到位置 int tpos = VSTop + stepy; VSTop = tpos < barwidth ? barwidth : tpos; VSTop = VSTop + VSHeight > VBarHeight - barwidth ? VBarHeight - barwidth - VSHeight : VSTop; //计算StartLine startTop = ((VSTop - barwidth) * (maxHeight * getFont().getHeight())) / (VBarHeight - 2 * barwidth) / getFont().getHeight(); if (oldStartLine == startTop) { if (stepy > 0) { startTop = ((maxHeight - startTop) * getFont().getHeight() > getVBarHeight()) ? startTop + 1 : startTop; } if (stepy < 0) { startTop = startTop > 0 ? startTop - 1 : startTop; } oldStartLine = startTop; } else { if ((stepy > 0) && (startTop < oldStartLine)) { startTop = oldStartLine; } oldStartLine = startTop; } } } isscrollbarpointdown = false; } //键盘事件处理 protected void doKeyUp(int keyCode) { String key = form.getKeyName(keyCode).toUpperCase(); SDAListViewItem item = null; if (key.equals(SDAConsts.KEY_UP)) { if (curItem != null) { item = getItemByColRow(curItem.getCol(), curItem.getRow() - 1); if (item != null) { curItem = item; doSelectChange(); if (curItem.getRow() * rowHeight < startTop) { startTop = curItem.getRow() * rowHeight; } } } } if (key.equals(SDAConsts.KEY_DOWN)) { if (curItem != null) { item = getItemByColRow(curItem.getCol(), curItem.getRow() + 1); if (item != null) { curItem = item; doSelectChange(); if (curItem.getRow() * rowHeight - startTop > getVBarHeight() - rowHeight) { startTop = curItem.getRow() * rowHeight - getVBarHeight() + rowHeight; } } } } if (key.equals(SDAConsts.KEY_LEFT)) { if (curItem != null) { item = getItemByColRow(curItem.getCol() - 1, curItem.getRow()); if (item != null) { curItem = item; doSelectChange(); if (curItem.getRow() * rowHeight < startTop) { startTop = curItem.getRow() * rowHeight; } } } } if (key.equals(SDAConsts.KEY_RIGHT)) { if (curItem != null) { item = getItemByColRow(curItem.getCol() + 1, curItem.getRow()); if (item != null) { curItem = item; doSelectChange(); if (curItem.getRow() * rowHeight - startTop > getVBarHeight() - rowHeight) { startTop = curItem.getRow() * rowHeight - getVBarHeight() + rowHeight; } } } } if (key.equals(SDAConsts.KEY_SELECT) || key.equals(SDAConsts.KEY_ENTER)) { doSelectItem(); } repaintControl(); } public void setOnSelectChange(ListViewSelectChangeEvent onSelectChange) { this.onSelectChange = onSelectChange; } private void doSelectChange() { if (this.onSelectChange != null) { if (curItem != null) { onSelectChange.Event(curItem); } } } public void setOnSelectItem(ListViewSelectItemEvent onSelectItem) { this.onSelectItem = onSelectItem; } private void doSelectItem() { if (this.onSelectItem != null) { if (curItem != null) { onSelectItem.Event(curItem); } } } protected boolean canDownTabNext() { return false; } protected boolean canLeftTabPrior() { return false; } protected boolean canRightTabNext() { return false; } protected boolean canUpTabPrior() { return false; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -