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

📄 sdabaseedit.java

📁 很好的UI界面源码..还有自己的输入法,可以更换风格.可以学习和使用
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        return scrollBarColor;    }    public void setScrollBarColor(int scrollBarColor) {        this.scrollBarColor = scrollBarColor;        repaintControl();    }    protected boolean isShowFocusRect() {        return showFocusRect;    }    protected void setShowFocusRect(boolean showFocusRect) {        this.showFocusRect = showFocusRect;    }    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;        }        if (!isMultiLine()) {            swidth = getWidth();        }        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;        }        if (!isMultiLine()) {            sheight = getHeight();        }        return sheight;    }    //处理事件的执行    //点箭头滚动内容    private 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 (isMultiLine()) {            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 = ((lineNum - startLine) * getFont().getHeight() > 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) * (lineNum * getFont().getHeight())) / (VBarHeight - 2 * barwidth) / getFont().getHeight();                        if (oldline == startLine) {                            startLine = posy > VSTop ? startLine + 1 : startLine - 1;                        }                    }                }            }        }        //点到空白处,计算光标        if (InClientRect(posx, posy, 0, 0, getHBarWidth(), getVBarHeight())) {            calCursorFromXY(posx, posy);            if (form.Application.inputPanel.charsPanel.isVisible()) {                form.Application.inputPanel.numChars = null;                form.Application.inputPanel.inputChars.setLength(0);                form.Application.inputPanel.charsPanel.visible = false;                form.repaintControl();            }        }    }    private void calCursorFromXY(int x, int y) {        cursorRow = startLine + y / getFont().getHeight();        if (cursorRow + 1 > lineNum) {            cursorRow = lineNum - 1;            if (cursorRow < 0) {                cursorRow = 0;            }        }        paintString(gg, getText(), 2, -100);        int len = 0;        int cw = 0;        Font ft = getFont();        String textStr = "";        if (isMultiLine()) {            textStr = cursorLineText;        } else {            textStr = getText();        }        if(passwordChar!=0){            textStr=getPassString(textStr, passwordChar);        }        cursorCol = textStr.length();        for (int i = 0; i < textStr.length(); i++) {            cw = ft.charWidth(textStr.charAt(i));            if (len + cw / 2 - startLeft > x) {                cursorCol = i;                break;            }            if (len + cw - startLeft > x) {                cursorCol = i + 1;                break;            }            len += ft.charWidth(textStr.charAt(i));        }    }    //拖动事件处理    private 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) * (lineNum * getFont().getHeight())) / (VBarHeight - 2 * barwidth) / getFont().getHeight();                if (oldStartLine == startLine) {                    if (stepy > 0) {                        startLine = ((lineNum - 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 static byte[] string2Byte(String s) {        try {            ByteArrayOutputStream baos = new ByteArrayOutputStream();            DataOutputStream bos = new DataOutputStream(baos);            bos.writeUTF(s);            byte[] bytes = baos.toByteArray();            byte[] rbytes = new byte[bytes.length - 2];            System.arraycopy(bytes, 2, rbytes, 0, rbytes.length);            //关闭流             bos.close();            baos.close();            return rbytes;        } catch (Exception e) {            return null;        }    }    //键盘事件处理    private void doKeyUp(int keyCode) {        String key = form.getKeyName(keyCode).toUpperCase();        char ch = 0;        if (key.equals(SDAConsts.KEY_UP)) {            if (form.Application.inputPanel.numChars != null) {                form.Application.inputPanel.charsPanel.priorChar();                form.Application.inputPanel.charsPanel.repaintControl();            } else {                ch = 38;                if (form.Application.inputPanel.charsPanel.isVisible()) {                    form.Application.inputPanel.charsPanel.inputFuncChar(ch);                } else {                    inputFuncChar(ch, false);                }            }        }        if (key.equals(SDAConsts.KEY_DOWN)) {            if (form.Application.inputPanel.numChars != null) {                form.Application.inputPanel.charsPanel.nextChar();                form.Application.inputPanel.charsPanel.repaintControl();            } else {                ch = 40;                if (form.Application.inputPanel.charsPanel.isVisible()) {                    form.Application.inputPanel.charsPanel.inputFuncChar(ch);                } else {                    inputFuncChar(ch, false);                }            }        }        if (key.equals(SDAConsts.KEY_LEFT)) {            if (form.Application.inputPanel.numChars != null) {                form.Application.inputPanel.charsPanel.priorChar();                form.Application.inputPanel.charsPanel.repaintControl();            } else {                ch = 37;                if (form.Application.inputPanel.charsPanel.isVisible()) {                    form.Application.inputPanel.charsPanel.inputFuncChar(ch);                } else {                    inputFuncChar(ch, false);                }            }        }        if (key.equals(SDAConsts.KEY_RIGHT)) {            if (form.Application.inputPanel.numChars != null) {                form.Application.inputPanel.charsPanel.nextChar();                form.Application.inputPanel.charsPanel.repaintControl();            } else {                ch = 39;                if (form.Application.inputPanel.charsPanel.isVisible()) {                    form.Application.inputPanel.charsPanel.inputFuncChar(ch);                } else {                    inputFuncChar(ch, false);                }            }        }        //删除(F2)        if (key.equals(SDAConsts.KEY_SOFT2) || key.equals(SDAConsts.KEY_CLEAR)) {            if (form.Application.inputPanel.numChars != null) {                form.Application.inputPanel.numChars = null;                if (form.Application.inputPanel.inputChars.length() == 0) {                    form.Application.inputPanel.charsPanel.visible = false;                    form.repaintControl();                }            } else {                ch = 8;                if (form.Application.inputPanel.charsPanel.isVisible()) {                    form.Application.inputPanel.charsPanel.inputFuncChar(ch);                } else {                    inputFuncChar(ch, false);                }            }        }        //ESC        if (key.equals(SDAConsts.KEY_SOFT1)) {            if (form.Application.inputPanel.charsPanel.visible) {                form.Application.inputPanel.numChars = null;                form.Application.inputPanel.inputChars.setLength(0);                form.Application.inputPanel.charsPanel.visible = false;                form.repaintControl();            }        }        //System.out.println(keyCode);        if (key.equals(SDAConsts.KEY_SELECT) || key.equals(SDAConsts.KEY_ENTER)) {            if (form.Application.inputPanel.numChars != null) {                if (form.Application.inputPanel.ImeType == SDAInputPanel.imPinYin) {                    ch = form.Application.inputPanel.getKeyChar();                    form.Application.inputPanel.selectedChar = ch;                    form.Application.inputPanel.inputPinYinChar();                    form.Application.inputPanel.charsPanel.repaintControl();                }                if (form.Application.inputPanel.ImeType == SDAInputPanel.imLowerCase ||                        form.Application.inputPanel.ImeType == SDAInputPanel.imUpperCase) {                    form.Application.inputPanel.selectedChar = 13;                    form.Application.inputPanel.inputFuncChar();                }                form.Application.inputPanel.numChars = null;            } else {                ch = 13;                if (form.Application.inputPanel.charsPanel.isVisible()) {                    form.Application.inputPanel.charsPanel.inputFuncChar(ch);                } else {                    if (!form.Application.hasPointer()) {                        form.Application.ShowEditor(this);                    } else {                        inputFuncChar(ch, false);                    }                }            }        }        if ((keyCode > 47 && keyCode < 58) || keyCode == 35 || keyCode == 42) {            ch = (char) keyCode;            char[] charArray = null;            if (form.Application.inputPanel.ImeType == SDAInputPanel.imPinYin) {                if (form.Application.inputPanel.charsPanel.isInput) {                    charArray = form.Application.inputPanel.getLowerKeyChars(ch);                } else {                    form.Application.inputPanel.charsPanel.isInput = true;

⌨️ 快捷键说明

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