📄 sdalistbox.java
字号:
public void setSelectedForeColor(int selectedForeColor) { this.selectedForeColor = selectedForeColor; repaintControl(); } private int getHBarWidth() { 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; } public int getItemIndex() { return itemIndex; } public int getItemIndex(String itemValue) { return internalGetItemIndex(itemValue); } private int internalGetItemIndex(String itemValue) { SDAListItem item = null; int result = -1; for (int i = 0; i < itemList.size(); i++) { item = (SDAListItem) itemList.elementAt(i); if (item.getItemString().equals(itemValue)) { result = i; break; } } return result; } public void setItemIndex(int itemIndex) { this.itemIndex = itemIndex; internalPaint(); } //处理事件的执行 //点箭头滚动内容 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(); int fontHeight = getFont().getHeight(); maxLineLenght = getMaxLineLenght(); //确定点击了滚动条区域 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 (maxLineLenght - 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) * (maxLineLenght)) / (HBarWidth - 2 * barwidth); } } } if ((scrollBars == SDAConsts.srVertical) || (scrollBars == SDAConsts.srBoth)) { //只有垂直滚动条 //判断是否点击了上箭头 if (InClientRect(posx, posy, thisWidth - barwidth, 0, barwidth, barwidth)) { //向下滚动 if (startLine > 0) { startLine--; } } else //下箭头 if (InClientRect(posx, posy, thisWidth - barwidth, VBarHeight - barwidth, barwidth, barwidth)) { //向上滚动 startLine = ((itemList.size() - startLine) * fontHeight > VBarHeight) ? startLine + 1 : startLine; } else //滚动条 if (InClientRect(posx, posy, VSLeft, VSTop, VSWidth, VSHeight)) { //记录位置 oldScrollPointx = posx; oldScrollPointy = posy; isscrollbarpointdown = true; scrollbardownHV = 1; oldStartLine = startLine; } else { if (InClientRect(posx, posy, thisWidth - barwidth, 0, barwidth, VBarHeight)) { //空白的 //计算滚动块要到位置 int tpos = posy > VSTop ? (posy - VSHeight) : (posy); //计算StartLine int oldline = startLine; startLine = ((tpos - barwidth) * (itemList.size() * fontHeight)) / (VBarHeight - 2 * barwidth) / fontHeight; if (oldline == startLine) { startLine = posy > VSTop ? startLine + 1 : startLine - 1; } } } } //点了滚动条外 if (InClientRect(posx, posy, 0, 0, HBarWidth, VBarHeight)) { itemIndex = posy / fontHeight + startLine; if (itemIndex > itemList.size() - 1) { itemIndex = itemList.size() - 1; //处理选择 } if (InClientRect(posx, posy, 2, 2 + fontHeight * (itemIndex - startLine), fontHeight, fontHeight)) { setItemChecked(itemIndex, !getItemChecked(itemIndex)); } } } //拖动事件处理 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) * (maxLineLenght)) / (HBarWidth - 2 * barwidth); if (oldStartLeft != startLeft) { oldScrollPointx = posx; oldStartLeft = startLeft; } else { oldStartLeft = startLeft; if (stepx > 0) { startLeft = maxLineLenght - 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 startLine = ((VSTop - barwidth) * (itemList.size() * getFont().getHeight())) / (VBarHeight - 2 * barwidth) / getFont().getHeight(); if (oldStartLine == startLine) { if (stepy > 0) { startLine = ((itemList.size() - startLine) * getFont().getHeight() > getVBarHeight()) ? startLine + 1 : startLine; } if (stepy < 0) { startLine = startLine > 0 ? startLine - 1 : startLine; } oldStartLine = startLine; } else { if ((stepy > 0) && (startLine < oldStartLine)) { startLine = oldStartLine; } oldStartLine = startLine; } } } isscrollbarpointdown = false; } //键盘事件处理 protected void doKeyUp(int keyCode) { maxLineLenght = getMaxLineLenght(); maxVisibleLineNum = getmaxVisibleLineNum(); String key = form.getKeyName(keyCode).toUpperCase(); if (key.equals(SDAConsts.KEY_UP)) { if (itemIndex > startLine) { itemIndex--; repaintControl(); return; } //上 if (startLine > 0) { startLine--; itemIndex = startLine; } } if (key.equals(SDAConsts.KEY_DOWN)) { if (itemIndex < startLine + maxVisibleLineNum - 1) { itemIndex++; repaintControl(); return; } //下 startLine = ((itemList.size() - startLine) * getFont().getHeight() > getVBarHeight()) ? startLine + 1 : startLine; itemIndex = startLine + maxVisibleLineNum - 1; } if (itemIndex < startLine) { itemIndex = startLine; } if (itemIndex > startLine + maxVisibleLineNum) { itemIndex = startLine + maxVisibleLineNum; } if (key.equals(SDAConsts.KEY_LEFT)) { //左 if (startLeft > 0) { int step = getFont().charWidth('x'); startLeft -= step; if (startLeft < 0) { startLeft = 0; } } } if (key.equals(SDAConsts.KEY_RIGHT)) { //右 if (maxLineLenght - startLeft > getHBarWidth()) { int step = getFont().charWidth('x'); startLeft += step; } } if(key.equals(SDAConsts.KEY_SELECT)||key.equals(SDAConsts.KEY_ENTER)){ setItemChecked(itemIndex, !getItemChecked(itemIndex)); } repaintControl(); } protected boolean canDownTabNext() { boolean result = false; if (itemIndex == itemList.size() - 1) { result = true; } return result; } protected boolean canLeftTabPrior() { boolean result = false; if (scrollBars == SDAConsts.srHorizontal || scrollBars == SDAConsts.srBoth) { if (startLeft > 0) { result = false; } else { result = true; } } else { if (itemIndex == 0 || itemIndex == -1) { result = true; } } return result; } protected boolean canRightTabNext() { boolean result = false; if (scrollBars == SDAConsts.srHorizontal || scrollBars == SDAConsts.srBoth) { if (maxLineLenght - startLeft > getHBarWidth()) { result = false; } else { result = true; } } else { if (itemIndex == itemList.size() - 1) { result = true; } } return result; } protected boolean canUpTabPrior() { boolean result = false; if (itemIndex == 0 || itemIndex == -1) { result = true; } return result; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -