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

📄 sdascrollbox.java

📁 很好的UI界面源码..还有自己的输入法,可以更换风格.可以学习和使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }    //对子组件重新定位    private void setChildsPos() {        //设置容器位置        backPanel.left = 2;        backPanel.top = 2;        backPanel.width = this.getHBarWidth() - 4;        backPanel.height = this.getVBarHeight() - 4;        backPanel.setBackColor(backColor);        backPanel.setTransparent(this.transparent);        //最大信息        getMaxInfo();        SDABaseControl ctrl = null;        //全部重新定位        for (int i = 0; i < backPanel.ctrlList.size(); i++) {            ctrl = (SDABaseControl) backPanel.ctrlList.elementAt(i);            if (!ctrl.visible) {                continue;            }            if (ctrl.dock == SDAConsts.dsNone) {                if (!ctrl.equals(refLeftControl)) {                    ctrl.left = (ctrl.left - refLeftControl.left) - startLeft;                }                if (!ctrl.equals(refTopControl)) {                    ctrl.top = (ctrl.top - refTopControl.top) - startTop;                }            }        }        refLeftControl.left = -startLeft;        refTopControl.top = -startTop;    }    public final void AddControl(SDABaseControl control) {        backPanel.AddControl(control);    }    //获取最大长度和高度    private void getMaxInfo() {        int minLeft = Integer.MAX_VALUE;        int minTop = Integer.MAX_VALUE;        int maxRight = Integer.MIN_VALUE;        int maxBottom = Integer.MIN_VALUE;        SDABaseControl ctrl = null;        for (int i = 0; i < backPanel.ctrlList.size(); i++) {            ctrl = (SDABaseControl) backPanel.ctrlList.elementAt(i);            if (!ctrl.visible) {                continue;            }            if (ctrl.getLeft() < minLeft) {                minLeft = ctrl.getLeft();                refLeftControl = ctrl;            }            maxRight = ctrl.getLeft() + ctrl.getWidth() > maxRight ? ctrl.getLeft() + ctrl.getWidth() : maxRight;            if (ctrl.getTop() < minTop) {                minTop = ctrl.getTop();                refTopControl = ctrl;            }            maxBottom = ctrl.getTop() + ctrl.getHeight() > maxBottom ? ctrl.getTop() + ctrl.getHeight() : maxBottom;        }        maxHeight = maxBottom - minTop + 4;        maxLenght = maxRight - minLeft + 4;    }    public int getBorderStyle() {        return borderStyle;    }    public void setBorderStyle(int borderStyle) {        this.borderStyle = borderStyle;        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 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();    }    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;    }    //处理事件的执行    //点箭头滚动内容    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;                    }                }            }        }    }    //拖动事件处理    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;    }    }

⌨️ 快捷键说明

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