📄 sdatreeview.java
字号:
} SDATreeNode cnode = null; if (node.hasChild() && node.isExpand()) { for (int i = 0; i < node.getChildsCount(); i++) { cnode = node.getChild(i); getNodeNum(cnode); } } } private int getmaxVisibleLineNum() { maxVisibleLineNum = getVBarHeight() / getFont().getHeight(); if (maxVisibleLineNum > maxLineNum) { maxVisibleLineNum = maxLineNum; } return maxVisibleLineNum; } public int getBorderColor() { return borderColor; } public void setBorderColor(int borderColor) { this.borderColor = borderColor; internalPaint(); } public int getScrollBarColor() { return scrollBarColor; } public void setScrollBarColor(int scrollBarColor) { this.scrollBarColor = scrollBarColor; internalPaint(); } public int getIndent() { return indent; } public void setIndent(int indent) { this.indent = indent; } 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 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(); //确定点击了滚动条区域 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 = ((maxLineNum - 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) * (maxLineNum * 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; SDATreeNode node = getNodeFromItemIndex(itemIndex); if (node != null) { CurNode = node; doSelectChange(); doSelectNode(); if (node.hasChild()) { if (InClientRect(posx, posy, indent * (node.getLayerIndex() + 1) - 2 - startLeft, (itemIndex - startLine + 1) * fontHeight - fontHeight / 2 - 2, 8, 8)) { node.setExpand(!node.isExpand()); } } } } } //拖动事件处理 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) * (maxLineNum * getFont().getHeight())) / (VBarHeight - 2 * barwidth) / getFont().getHeight(); if (oldStartLine == startLine) { if (stepy > 0) { startLine = ((maxLineNum - 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) { maxVisibleLineNum = getmaxVisibleLineNum(); String key = form.getKeyName(keyCode).toUpperCase(); try { if (key.equals(SDAConsts.KEY_UP)) { if (itemIndex > startLine) { itemIndex--; return; } //上 if (startLine > 0) { startLine--; itemIndex = startLine; } } if (key.equals(SDAConsts.KEY_DOWN)) { if (itemIndex < startLine + maxVisibleLineNum - 1) { itemIndex++; return; } //下 startLine = ((maxLineNum - startLine) * getFont().getHeight() > getVBarHeight()) ? startLine + 1 : startLine; itemIndex = startLine + maxVisibleLineNum - 1; } if (itemIndex < startLine) { itemIndex = startLine; } if (itemIndex > startLine + maxVisibleLineNum) { itemIndex = startLine + maxVisibleLineNum; } } finally { getCurNode(); doSelectChange(); if (key.equals(SDAConsts.KEY_LEFT)) { setExp(false); } if (key.equals(SDAConsts.KEY_RIGHT)) { //右 setExp(true); } repaintControl(); } } private void setExp(boolean expand) { SDATreeNode node = getNodeFromItemIndex(itemIndex); if (node != null) { CurNode = node; if (node.hasChild()) { node.setExpand(expand); } } } public SDATreeNode getCurNode() { SDATreeNode node = getNodeFromItemIndex(itemIndex); if (node != null) { CurNode = node; } return CurNode; } public void setOnSelectChange(TreeViewSelectChangeEvent onSelectChange) { this.onSelectChange = onSelectChange; } public void setOnSelectNode(TreeViewSelectNodeEvent onSelectNode) { this.onSelectNode = onSelectNode; } private void doSelectChange() { if (this.onSelectChange != null) { if (CurNode != null) { onSelectChange.Event(CurNode); } } } private void doSelectNode() { if (this.onSelectNode != null) { if (CurNode != null) { onSelectNode.Event(CurNode); } } } protected boolean canDownTabNext() { boolean result=false; if(absIndex==getChildsCount()-1){ result=true; } return result; } protected boolean canRightTabNext() { boolean result=false; if(absIndex==-1||absIndex==0){ result=true; } return result; } protected boolean canUpTabPrior() { return false; } protected boolean canLeftTabPrior() { return false; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -