⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdatreeview.java

📁 很好的UI界面源码..还有自己的输入法,可以更换风格.可以学习和使用
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            }            if (scrollBars == SDAConsts.srVertical) {                SetClip(g, 2, 2, thisWidth - barwidth - 4, thisHeight - 4);            }            if (scrollBars == SDAConsts.srBoth) {                SetClip(g, 2, 2, thisWidth - barwidth - 4, thisHeight - barwidth - 4);            }            SDATreeNode node = null;            maxLineLenght = getHBarWidth();            absIndex = 0;            for (int i = 0; i < TreeNodes.size(); i++) {                node = (SDATreeNode) TreeNodes.elementAt(i);                paintNodes(g, node);            }            //滚动条            if (borderStyle == SDAConsts.bsFixed3D) {                SetClip(g, 2, 2, thisWidth - 2, thisHeight - 2);            } else {                SetClip(g, 1, 1, thisWidth - 1, thisHeight - 1);            }            if ((scrollBars == SDAConsts.srHorizontal) || (scrollBars == SDAConsts.srBoth)) {                //水平                g.setColor(scrollBarColor);                fillRect(g, 0, thisHeight - barwidth, barwidth, barwidth);                fillRect(g, HBarWidth - barwidth, thisHeight - barwidth, barwidth, barwidth);                g.setColor(getBorderColor());                drawRect(g, 0, thisHeight - barwidth, barwidth, barwidth);                drawRect(g, HBarWidth - barwidth, thisHeight - barwidth, barwidth, barwidth);                //滚动块                g.setColor(backColor);                fillRect(g, barwidth, thisHeight - barwidth, HBarWidth - 2 * barwidth, barwidth);                g.setColor(this.getBorderColor());                drawRect(g, barwidth, thisHeight - barwidth, HBarWidth - 2 * barwidth, barwidth);                //块大小                int pwidth = HBarWidth - 2 * barwidth;                if (maxLineLenght > HBarWidth) {                    pwidth = ((HBarWidth) * (HBarWidth - 2 * barwidth)) / maxLineLenght;                }                //计算块位置                int ppos = (startLeft * (HBarWidth - 2 * barwidth)) / maxLineLenght;                //修正位置                if (ppos + pwidth > HBarWidth - 2 * barwidth) {                    ppos = HBarWidth - 2 * barwidth - pwidth;                }                //画块                g.setColor(scrollBarColor);                fillRect(g, barwidth + ppos, thisHeight - barwidth, pwidth, barwidth);                g.setColor(getBorderColor());                drawRect(g, barwidth + ppos, thisHeight - barwidth, pwidth, barwidth);                //记录大小                HSLeft = barwidth + ppos;                HSTop = thisHeight - barwidth;                HSWidth = pwidth;                HSHeight = barwidth;                //画块上的线                int tpos = HSWidth / 2 + HSLeft;                drawRect(g, tpos, HSTop + 2, 0, HSHeight - 4);                if (tpos - 2 > HSLeft) {                    drawRect(g, tpos - 2, HSTop + 2, 0, HSHeight - 4);                }                if (tpos + 2 < HSLeft + HSWidth) {                    drawRect(g, tpos + 2, HSTop + 2, 0, HSHeight - 4);                }                //三角                g.setColor(getBorderColor());                fillTriangle(g, barwidth / 2 - 2, thisHeight - barwidth / 2,                        barwidth / 2 + 2, thisHeight - barwidth / 2 - 4,                        barwidth / 2 + 2, thisHeight - barwidth / 2 + 4);                fillTriangle(g, HBarWidth - barwidth + barwidth / 2 + 2, thisHeight - barwidth / 2,                        HBarWidth - barwidth + barwidth / 2 - 2, thisHeight - barwidth / 2 - 4,                        HBarWidth - barwidth + barwidth / 2 - 2, thisHeight - barwidth / 2 + 4);            }            if ((scrollBars == SDAConsts.srVertical) || (scrollBars == SDAConsts.srBoth)) {                //垂直                g.setColor(scrollBarColor);                fillRect(g, thisWidth - barwidth, 0, barwidth, barwidth);                fillRect(g, thisWidth - barwidth, VBarHeight - barwidth, barwidth, barwidth);                g.setColor(getBorderColor());                drawRect(g, thisWidth - barwidth, 0, barwidth, barwidth);                drawRect(g, thisWidth - barwidth, VBarHeight - barwidth, barwidth, barwidth);                //滚动块                g.setColor(backColor);                fillRect(g, thisWidth - barwidth, barwidth, barwidth, VBarHeight - 2 * barwidth);                g.setColor(getBorderColor());                drawRect(g, thisWidth - barwidth, barwidth, barwidth, VBarHeight - 2 * barwidth);                //块大小                                    int pheight = VBarHeight - 2 * barwidth;                if (maxLineNum * getFont().getHeight() > VBarHeight) {                    pheight = ((VBarHeight) * (VBarHeight - 2 * barwidth) / (maxLineNum * getFont().getHeight()));                }                //计算块位置                int ppos = barwidth;                if (maxLineNum > 0) {                    ppos = (startLine * getFont().getHeight() * (VBarHeight - 2 * barwidth)) / (maxLineNum * getFont().getHeight());                }                //修正位置                if (ppos + pheight > VBarHeight - 2 * barwidth) {                    ppos = VBarHeight - 2 * barwidth - pheight;                }                //画块                g.setColor(scrollBarColor);                fillRect(g, thisWidth - barwidth, barwidth + ppos, barwidth, pheight);                g.setColor(getBorderColor());                drawRect(g, thisWidth - barwidth, barwidth + ppos, barwidth, pheight);                //记录大小                VSLeft = thisWidth - barwidth;                VSTop = barwidth + ppos;                VSWidth = barwidth;                VSHeight = pheight;                //画块上的线                int tpos = VSHeight / 2 + VSTop;                drawRect(g, VSLeft + 2, tpos, barwidth - 4, 0);                if (tpos - 2 > VSTop) {                    drawRect(g, VSLeft + 2, tpos - 2, VSWidth - 4, 0);                }                if (tpos + 2 < VSTop + VSHeight) {                    drawRect(g, VSLeft + 2, tpos + 2, VSWidth - 4, 0);                }                //三角                g.setColor(getBorderColor());                fillTriangle(g, thisWidth - barwidth + barwidth / 2, barwidth / 2 - 2,                        thisWidth - barwidth + barwidth / 2 - 4, barwidth / 2 + 2,                        thisWidth - barwidth + barwidth / 2 + 4, barwidth / 2 + 2);                fillTriangle(g, thisWidth - barwidth + barwidth / 2 - 4, VBarHeight - barwidth + barwidth / 2 - 2,                        thisWidth - barwidth + barwidth / 2 + 4, VBarHeight - barwidth + barwidth / 2 - 2,                        thisWidth - barwidth + barwidth / 2, VBarHeight - barwidth / 2 + 2);            }        }    }    //画节点    private void paintNodes(Graphics g, SDATreeNode node) {        getMaxLineInfo();        //根据传递的SDATreeNode来画        //int HBarWidth = getHBarWidth();        int fontHeight = getFont().getHeight();        int imageWidth = node.getImage() != null ? fontHeight : 0;        //画自己        if (node.equals(CurNode)) {            //画背景            g.setColor(SDAConsts.clActiveCaption);            fillRect(g, indent + 4 - startLeft + indent * (node.getLayerIndex() + 1) + imageWidth, 2 + fontHeight * (absIndex - startLine),                    getFont().stringWidth(node.getNodeString()), fontHeight);            //线            g.setColor(getForeColor());            drawDotLine(g, 2 - startLeft + indent * (node.getLayerIndex() + 1), 2 + fontHeight * (absIndex - startLine) + fontHeight / 2,                    indent, 0);            p_len = 0;            getVLineLength(node);            if (p_len > 0) {                drawDotLine(g, indent + 2 - startLeft + indent * (node.getLayerIndex() + 1),                        2 + fontHeight * (absIndex - startLine) + fontHeight / 2, 0, p_len * fontHeight);            }            //画图标            if (node.getImage() != null) {                if (node.getSelectedImage() != null) {                    drawImage(g, node.getSelectedImage(), indent + 4 - startLeft + indent * (node.getLayerIndex() + 1),                            1 + fontHeight * (absIndex - startLine) + (fontHeight - node.getSelectedImage().getHeight()) / 2, 0);                } else {                    drawImage(g, node.getImage(), indent + 4 - startLeft + indent * (node.getLayerIndex() + 1),                            1 + fontHeight * (absIndex - startLine) + (fontHeight - node.getImage().getHeight()) / 2, 0);                }                //打字                g.setColor(selectedFontColor);                drawString(g, node.getNodeString(), indent + 4 - startLeft + indent * (node.getLayerIndex() + 1) + imageWidth,                        2 + fontHeight * (absIndex - startLine));            } else {                //打字                g.setColor(selectedFontColor);                drawString(g, node.getNodeString(), indent + 4 - startLeft + indent * (node.getLayerIndex() + 1),                        2 + fontHeight * (absIndex - startLine));            }        } else {            //打字            g.setColor(getForeColor());            drawDotLine(g, 2 - startLeft + indent * (node.getLayerIndex() + 1), 2 + fontHeight * (absIndex - startLine) + fontHeight / 2,                    indent, 0);            p_len = 0;            getVLineLength(node);            if (p_len > 0) {                drawDotLine(g, indent + 2 - startLeft + indent * (node.getLayerIndex() + 1),                        2 + fontHeight * (absIndex - startLine) + fontHeight / 2, 0, p_len * fontHeight);            }            //画图标            if (node.getImage() != null) {                drawImage(g, node.getImage(), indent + 4 - startLeft + indent * (node.getLayerIndex() + 1),                        1 + fontHeight * (absIndex - startLine) + (fontHeight - node.getImage().getHeight()) / 2, 0);                //打字                drawString(g, node.getNodeString(), indent + 4 - startLeft + indent * (node.getLayerIndex() + 1) + imageWidth,                        2 + fontHeight * (absIndex - startLine));            } else {                //打字                drawString(g, node.getNodeString(), indent + 4 - startLeft + indent * (node.getLayerIndex() + 1),                        2 + fontHeight * (absIndex - startLine));            }        }        absIndex++;        //遍历下一级        SDATreeNode cnode = null;        //int         if (node.isExpand()) {            if (node.hasChild()) {                g.setColor(backColor);                fillRect(g, 2 - startLeft + indent * (node.getLayerIndex() + 1) - 4,                        2 + fontHeight * (absIndex - startLine) - fontHeight / 2 - 4,                        8, 8);                g.setColor(foreColor);                drawRect(g, 2 - startLeft + indent * (node.getLayerIndex() + 1) - 4,                        2 + fontHeight * (absIndex - startLine) - fontHeight / 2 - 4,                        8, 8);                drawLine(g, 2 - startLeft + indent * (node.getLayerIndex() + 1) - 4,                        2 + fontHeight * (absIndex - startLine) - fontHeight / 2,                        2 - startLeft + indent * (node.getLayerIndex() + 1) + 4,                        2 + fontHeight * (absIndex - startLine) - fontHeight / 2);                for (int i = 0; i < node.getChildsCount(); i++) {                    cnode = node.getChild(i);                    paintNodes(g, cnode);                }            }        } else {            if (node.hasChild()) {                g.setColor(backColor);                fillRect(g, 2 - startLeft + indent * (node.getLayerIndex() + 1) - 4,                        2 + fontHeight * (absIndex - startLine) - fontHeight / 2 - 4,                        8, 8);                g.setColor(foreColor);                drawRect(g, 2 - startLeft + indent * (node.getLayerIndex() + 1) - 4,                        2 + fontHeight * (absIndex - startLine) - fontHeight / 2 - 4,                        8, 8);                drawLine(g, 2 - startLeft + indent * (node.getLayerIndex() + 1) - 4,                        2 + fontHeight * (absIndex - startLine) - fontHeight / 2,                        2 - startLeft + indent * (node.getLayerIndex() + 1) + 4,                        2 + fontHeight * (absIndex - startLine) - fontHeight / 2);                drawLine(g, 2 - startLeft + indent * (node.getLayerIndex() + 1),                        2 + fontHeight * (absIndex - startLine) - fontHeight / 2 - 4,                        2 - startLeft + indent * (node.getLayerIndex() + 1),                        2 + fontHeight * (absIndex - startLine) - fontHeight / 2 + 4);            }        }    }    //获取向下画的线长度    private void getVLineLength(SDATreeNode node) {        if (node.hasChild() && node.isExpand()) {            SDATreeNode cnode = null;            for (int i = 0; i < node.getChildsCount(); i++) {                cnode = node.getChild(i);                p_len++;                if (cnode.hasChild() && cnode.isExpand()) {                    getVLineLength(cnode);                }            }        }    }    //根据位置获取Node    private SDATreeNode getNodeFromItemIndex(int index) {        SDATreeNode node = null;        int clickLine = index;        p_len = -1;        p_node = null;        for (int i = 0; i < TreeNodes.size(); i++) {            node = (SDATreeNode) TreeNodes.elementAt(i);            calClickLine(node, clickLine);        }        return p_node;    }    private void calClickLine(SDATreeNode node, int lineID) {        p_len++;        if (p_len == lineID) {            p_node = node;            return;        }        SDATreeNode cnode = null;        if (node.isExpand() && node.hasChild()) {            for (int i = 0; i < node.getChildsCount(); i++) {                cnode = node.getChild(i);                calClickLine(cnode, lineID);            }        }    }    public int getSelectedFontColor() {        return selectedFontColor;    }    public void setSelectedFontColor(int selectedFontColor) {        this.selectedFontColor = selectedFontColor;        internalPaint();    }    public int getBorderStyle() {        return borderStyle;    }    public void setBorderStyle(int borderStyle) {        this.borderStyle = borderStyle;        internalPaint();    }    public boolean isHideSelection() {        return hideSelection;    }    public void setHideSelection(boolean hideSelection) {        this.hideSelection = hideSelection;        internalPaint();    }    public int getScrollBars() {        return scrollBars;    }    public void setScrollBars(int scrollBars) {        this.scrollBars = scrollBars;        internalPaint();    }    public int getScrollBarWidth() {        return barwidth;    }    public void setScrollBarWidth(int barwidth) {        this.barwidth = barwidth;        internalPaint();    }    private void getMaxLineInfo() {        //获取总行数        p_len = 0;        maxLineLenght = getHBarWidth();        SDATreeNode node = null;        for (int i = 0; i < TreeNodes.size(); i++) {            node = (SDATreeNode) TreeNodes.elementAt(i);            getNodeNum(node);        }        maxLineNum = p_len;        if (maxLineNum <= getmaxVisibleLineNum()) {            startLine = 0;        }    }    private void getNodeNum(SDATreeNode node) {        p_len++;        int cwidth = getFont().stringWidth(node.getNodeString()) +                indent * (node.getLayerIndex() + 2) + (node.getImage() != null ? getFont().getHeight() : 0);        if (maxLineLenght < cwidth) {            maxLineLenght = cwidth;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -