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

📄 sdalistbox.java

📁 很好的UI界面源码..还有自己的输入法,可以更换风格.可以学习和使用
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    g.setColor(SDAConsts.clFocusShadow);                    drawRect(g, 1, 1, thisWidth - 2, thisHeight - 2);                }            }            if (borderStyle == SDAConsts.bsFixedSingle) {                //边框                g.setColor(this.getBorderColor());                drawRect(g, 0, 0, thisWidth, thisHeight);                if (isFoucsed()) {                    g.setColor(SDAConsts.clFocusShadow);                    drawRect(g, 1, 1, thisWidth - 2, thisHeight - 2);                }            }            //打字            g.setColor(this.getForeColor());            paintString(g);            //滚动条            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 (itemList.size() * getFont().getHeight() > VBarHeight) {                    pheight = ((VBarHeight) * (VBarHeight - 2 * barwidth) / (itemList.size() * getFont().getHeight()));                }                //计算块位置                int ppos = barwidth;                if (itemList.size() > 0) {                    ppos = (startLine * getFont().getHeight() * (VBarHeight - 2 * barwidth)) / (itemList.size() * 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 paintString(Graphics g) {        int thisWidth = getWidth();        int thisHeight = getHeight();        int HBarWidth = getHBarWidth();        maxVisibleLineNum = getmaxVisibleLineNum();        maxLineNum = getMaxLineNum();        maxLineLenght = getMaxLineLenght();        g.setColor(getForeColor());        if (scrollBars == SDAConsts.srNone) {            SetClip(g, 2, 2, thisWidth - 3, thisHeight - 3);        }        if (scrollBars == SDAConsts.srHorizontal) {            SetClip(g, 2, 2, thisWidth - 3, thisHeight - barwidth - 3);        }        if (scrollBars == SDAConsts.srVertical) {            SetClip(g, 2, 2, thisWidth - barwidth - 3, thisHeight - 3);        }        if (scrollBars == SDAConsts.srBoth) {            SetClip(g, 2, 2, thisWidth - barwidth - 3, thisHeight - barwidth - 3);        }        //打字,根据item打印        SDAListItem item;        int fontHeight = getFont().getHeight();        int CheckWidth = showCheckBox ? fontHeight : 0;        int ImageWidth = showItemImage ? fontHeight : 0;        String str = "";        int endline = maxLineNum - startLine - maxVisibleLineNum > 0 ? startLine + maxVisibleLineNum : maxLineNum;        for (int i = startLine; i < endline; i++) {            item = (SDAListItem) itemList.elementAt(i);            str = item.getItemString();            //参照select,check,image            if (itemIndex == i) {                //画背景                g.setColor(selectedBackColor);                fillRect(g, 2, 2 + fontHeight * (i - startLine), HBarWidth, fontHeight);                //打字                g.setColor(selectedForeColor);                drawString(g, item.getItemString(), 2 - startLeft + CheckWidth + ImageWidth, 2 + fontHeight * (i - startLine));            } else {                //打字                g.setColor(getForeColor());                drawString(g, item.getItemString(), 2 - startLeft + CheckWidth + ImageWidth, 2 + fontHeight * (i - startLine));            }            if (showCheckBox) {                g.setColor(getBackColor());                fillRect(g, 2, 2 + fontHeight * (i - startLine), fontHeight, fontHeight);                //选择                g.setColor(borderColor);                drawRect(g, 2 + fontHeight / 4, 2 + fontHeight * (i - startLine) + fontHeight / 4, fontHeight / 2, fontHeight / 2);                if (item.isChecked()) {                    //选择                    fillRect(g, 2 + fontHeight / 4 + 2, 2 + fontHeight * (i - startLine) + fontHeight / 4 + 2, fontHeight / 2 - 3, fontHeight / 2 - 3);                }            }            //图            if (showItemImage && item.getImage() != null) {                drawImage(g, item.getImage(), 2 - startLeft + CheckWidth, 2 + fontHeight * (i - startLine) + (fontHeight - item.getImage().getHeight()) / 2, 0);            }        }    }    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();    }    public void setText(String text) {        internalSetText(text);    }    private void internalSetText(String text) {        super.setText(text);        //内容处理为行        String str = "";        maxLineLenght = 0;        while (text.indexOf('\n') > -1) {            str = text.substring(0, text.indexOf('\n'));            //加入            addItem(str, null, false);            text = text.substring(text.indexOf('\n') + 1);        }        if (text.length() > 0) {            //text,最后一行            addItem(text, null, false);        }        internalPaint();    }    private int getMaxLineNum() {        //获取总行数        maxLineNum = itemList.size();        return maxLineNum;    }    private int getmaxVisibleLineNum() {        maxVisibleLineNum = getVBarHeight() / getFont().getHeight();        getMaxLineNum();        if (maxVisibleLineNum > maxLineNum) {            maxVisibleLineNum = maxLineNum;        }        return maxVisibleLineNum;    }    private int getMaxLineLenght() {        //获取最大行长度        int fontHeight = getFont().getHeight();        int CheckWidth = showCheckBox ? fontHeight : 0;        int ImageWidth = showItemImage ? fontHeight : 0;        String str = null;        SDAListItem item = null;        maxLineLenght = getHBarWidth();        for (int i = 0; i < itemList.size(); i++) {            item = (SDAListItem) itemList.elementAt(i);            str = item.getItemString();            if (maxLineLenght < getFont().stringWidth(str) + CheckWidth + ImageWidth) {                maxLineLenght = getFont().stringWidth(str) + CheckWidth + ImageWidth;            }        }        return maxLineLenght;    }    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 getSelectedBackColor() {        return selectedBackColor;    }    public void setSelectedBackColor(int selectedBackColor) {        this.selectedBackColor = selectedBackColor;    }    public int getSelectedForeColor() {        return selectedForeColor;    }

⌨️ 快捷键说明

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