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

📄 sdainputpanel.java

📁 很好的UI界面源码..还有自己的输入法,可以更换风格.可以学习和使用
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                                isInput = true;                            }                        }                    }                }                //小写字母                if (ImeType == imLowerCase || ImeType == imUpperCase) {                    if (numChars != null) {                        selectedChar = numChars[charIndex];                        inputVisibleChar();                        charsPanel.visible = false;                        numChars = null;                    }                }            }            //空格            if (inChar == ' ' || inChar == ' ') {            }            if (isVisible()) {                repaintControl();            } else {                if (form != null) {                    form.repaintControl();                }            }        }        //翻页        private void priorPage() {            if (pageNo > 1) {                pageNo--;                selectedHanziIndex = (pageNo - 1) * 8;            }        }        private void nextpage() {            if (pageNo < pageCount) {                pageNo++;                selectedHanziIndex = (pageNo - 1) * 8;            }        }        //设置大小        protected void setSize(int colNum, int rowNum) {            setWidth(30 * colNum);            setHeight(getFont().getHeight() * rowNum);        }        public void paint() {            if (!IsCanPaint()) {                return;            }            Graphics g = form.getGraphics();            g.setFont(getFont());            SetClip(g);            //输入内容            if (ImeType == imPinYin) {                //画框                paintRect(g);                paintInputPYChars(g);                paintHanzi(g);                //翻页                paintPages(g);            }            if (ImeType == imLowerCase || ImeType == imUpperCase) {                //画框                paintRect(g);                //画选择的一键多值                paintCase(g);            }        }        //根据当前的组件输入点位置画输入内容显示框和选择框        public void getCursorPosInForm() {            SDABaseEdit control = null;            if (form != null) {                if (form.focusControl != null) {                    if (form.focusControl instanceof SDABaseEdit) {                        control = (SDABaseEdit) form.focusControl;                        control.setCursorVisible();                        oraX = control.getCursorX() + 2;                        oraY = control.getCursorY();                    }                }            }        }        //画        private void paintRect(Graphics g) {            g.setColor(backColor);            fillRect(g, 0, 0, width, height);            g.setColor(foreColor);            drawRect(g, 0, 0, width, height);        }        //画一键多字母        private void paintCase(Graphics g) {            Font ft = getFont();            int fontHeight = ft.getHeight();            if (ImeType == imLowerCase || ImeType == imUpperCase) {                if (numChars != null) {                    for (int i = 0; i < numChars.length; i++) {                        if (i == charIndex) {                            g.setColor(selectedBackColor);                            fillRect(g, 1, fontHeight * i + 1, width - 1, fontHeight - 1);                            g.setColor(selectedFontColor);                            drawString(g, String.valueOf(numChars[i]), (width - ft.charWidth(numChars[i])) / 2, fontHeight * i);                        } else {                            g.setColor(foreColor);                            drawString(g, String.valueOf(numChars[i]), (width - ft.charWidth(numChars[i])) / 2, fontHeight * i);                        }                    }                }            }        }        //画翻页        private void paintPages(Graphics g) {            int fontHeight = getFont().getHeight();            g.setColor(pageScrollBarColor);            fillRect(g, 0, 5 * fontHeight, width, fontHeight);            g.setColor(pageScrollBarFontColor);            drawRect(g, 0, 5 * fontHeight, width, fontHeight);            //计算页码            pageCount = (hanziCount % 8 > 0) ? hanziCount / 8 + 1 : hanziCount / 8;            if (pageCount == 0) {                pageNo = 0;            } else {                if (pageNo == 0) {                    pageNo = 1;                }            }            drawString(g, pageNo + "/" + pageCount, 1, 5 * getFont().getHeight());            //箭头            if (pageNo > 1) {                fillTriangle(g, width / 2 + width / 8 - 2, 5 * fontHeight + fontHeight / 2,                        width / 2 + width / 8 + 2, 5 * fontHeight + fontHeight / 2 - 4,                        width / 2 + width / 8 + 2, 5 * fontHeight + fontHeight / 2 + 4);            }            if (pageCount > pageNo) {                fillTriangle(g, width - width / 8 + 2, 5 * fontHeight + fontHeight / 2,                        width - width / 8 - 2, 5 * fontHeight + fontHeight / 2 - 4,                        width - width / 8 - 2, 5 * fontHeight + fontHeight / 2 + 4);            }        }        //画输入内容(拼音输入字母)        private void paintInputPYChars(Graphics g) {            Font ft = getFont();            int fontHeight = ft.getHeight();            String inString = inputChars.toString();            g.setColor(inputBarColor);            fillRect(g, 0, 0, width, fontHeight);            g.setColor(foreColor);            drawRect(g, 0, 0, width, fontHeight);            drawString(g, inString, 2, 0);            //画光标            if (isInput) {                if (cursorPos > -1 && cursorPos < inString.length() + 1) {                    //System.out.println(inString.substring(0, cursorPos));                    drawLine(g, ft.stringWidth(inString.substring(0, cursorPos)) + 2, 2, ft.stringWidth(inString.substring(0, cursorPos)) + 2, fontHeight - 3);                }            }            //画未选择的一键多字母            if (numChars != null && numChars.length > 0) {                drawString(g, String.valueOf(numChars), width - ft.charsWidth(numChars, 0, numChars.length) - 1, 0);                //根据索引画选择的                g.setColor(selectedBackColor);                fillRect(g, width - ft.charsWidth(numChars, charIndex, numChars.length - charIndex) - 1, 1, ft.charWidth(numChars[charIndex]), fontHeight - 1);                g.setColor(selectedFontColor);                drawString(g, String.valueOf(numChars[charIndex]), width - ft.charsWidth(numChars, charIndex, numChars.length - charIndex) - 1, 0);            }        }        //切换选择的一键多字母        public void nextChar() {            if (numChars != null) {                if (charIndex < numChars.length - 1) {                    charIndex++;                }            }        }        public void priorChar() {            if (numChars != null) {                if (charIndex > 0) {                    charIndex--;                }            }        }        //画汉字选择        private void paintHanzi(Graphics g) {            int fontHeight = getFont().getHeight();            g.setColor(backColor);            fillRect(g, 0, fontHeight, width, 4 * fontHeight);            g.setColor(foreColor);            drawRect(g, 0, fontHeight, width, 4 * fontHeight);            //中间分隔条,显示两列汉字            g.setColor(borderColor);            drawLine(g, width / 2, fontHeight, width / 2, 5 * fontHeight);            //查询对应汉字            hanziChars = Spell2Chars.getSpell2Chars(inputChars);            hanziCount = 0;            if (hanziChars != null) {                //计算汉字数目                hanziCount = hanziChars.length;                if (selectedHanziIndex >= hanziCount) {                    selectedHanziIndex = 0;                }                if (pageNo == 0) {                    pageNo = 1;                }                //画汉字                int HanziLine = 1;                int index = 1;                for (int i = (pageNo - 1) * 8; i < hanziChars.length; i++) {                    //左边的                    if (!isInput) {                        if (i == selectedHanziIndex) {                            g.setColor(selectedBackColor);                            fillRect(g, 1, HanziLine * fontHeight + 1, width / 2 - 1, fontHeight - 1);                            g.setColor(selectedFontColor);                            drawString(g, index + ":" + hanziChars[i], 2, HanziLine * fontHeight);                        } else {                            g.setColor(foreColor);                            drawString(g, index + ":" + hanziChars[i], 2, HanziLine * fontHeight);                        }                    } else {                        g.setColor(foreColor);                        drawString(g, index + ":" + hanziChars[i], 2, HanziLine * fontHeight);                    }                    //右边的                    if (!isInput) {                        if (i + 4 < hanziChars.length) {                            if (i + 4 == selectedHanziIndex) {                                g.setColor(selectedBackColor);                                fillRect(g, width / 2 + 1, HanziLine * fontHeight + 1, width / 2 - 1, fontHeight - 1);                                g.setColor(selectedFontColor);                                drawString(g, index + 4 + ":" + hanziChars[i + 4], 2 + width / 2, HanziLine * fontHeight);                            } else {                                g.setColor(foreColor);                                drawString(g, index + 4 + ":" + hanziChars[i + 4], 2 + width / 2, HanziLine * fontHeight);                            }                        }                    } else {                        if (i + 4 < hanziChars.length) {                            g.setColor(foreColor);                            drawString(g, index + 4 + ":" + hanziChars[i + 4], 2 + width / 2, HanziLine * fontHeight);                        }                    }                    if (i >= (pageNo - 1) * 8 + 3) {                        return;                    }                    index++;                    HanziLine++;                }            }        }    }    protected SDAInputPanel() {        super();        setVisible(false);        setLeft(0);        setTop(0);        setWidth(200);        setHeight(getFont().getHeight() * 4);        super.setDock(SDAConsts.dsBottom);        tabStop = false;        backColor = SDAConsts.clWhite;        foreColor = SDAConsts.clBlack;        charsPanel = new inputCharsPanel();        hashLowerKeyChars = new Hashtable();        hashUpperKeyChars = new Hashtable();        //拼音        inputChars = new StringBuffer();        selectedChars = new StringBuffer();        setOnPointerReleased(new PointerEvent() {            public void Event(SDABaseControl ctrl, int x, int y) {                doPointerReleased(x, y);            }        });        setOnPointerReleased(new PointerEvent() {            public void Event(SDABaseControl ctrl, int x, int y) {                doPointerReleased(x, y);            }        });        //字符内容        UpperCaseChars = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',            'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'        };        SBCUpperCaseChars = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',            'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'        };        LowerCaseChars =                new char[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'        };        SBCLowerCaseChars =                new char[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'        };        DigitChars =                new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};        SBCDigitChars =                new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};        PointChars =                new char[]{'`', ';', '.', ',', '\'', '.', '/', '~', '!', '@', '#', '%', '^', '&',            '*', '(', ')', '_', '+', '{', '}', '[', ']', ':', '"', '<', '>', '?', ' '        };        SBCPointChars =                new char[]{'`', ';', '.', ',', ''', '。', '/', '~', '!', '@', '#', '%', '^', '&',            '*', '(', ')', '_', '+', '{', '}', '[', ']', ':', '"', '<', '>', '?', ' '        };        SymbolChars =                new char[]{'\\', '%', '=', '±', '/', '-', '+', '¥', '€', '£', '$', '(', ')',            '◎', '『', '』', '○', '「', '」', '●', '《', '》', '§', '】', '【', '※'        };        SBCSymbolChars =                new char[]{'\', '%', '=', '±', '/', '-', '+', '¥', '€', '£', '$', '(', ')',            '◎', '『', '』', '○', '「', '」', '●', '《', '》', '§', '】', '【', '※'        };        //键盘一键多字母组合        setKeyChars('2', new char[]{'a', 'b', 'c'}, new char[]{'A', 'B', 'C'});        setKeyChars('3', new char[]{'d', 'e', 'f'}, new char[]{'D', 'E', 'F'});        setKeyChars('4', new char[]{'g', 'h', 'i'}, new char[]{'G', 'H', 'I'});        setKeyChars('5', new char[]{'j', 'k', 'l'}, new char[]{'J', 'K', 'L'});        setKeyChars('6', new char[]{'m', 'n', 'o'}, new char[]{'M', 'N', 'O'});        setKeyChars('7', new char[]{'p', 'q', 'r', 's'}, new char[]{'P', 'Q', 'R', 'S'});        setKeyChars('8', new char[]{'t', 'u', 'v'}, new char[]{'T', 'U', 'V'});        setKeyChars('9', new char[]{'w', 'x', 'y', 'z'}, new char[]{'W', 'X', 'Y', 'Z'});    }//字母组合    public void setKeyChars(char ch, char[] lowerArrayChar, char[] UpperArrayChar) {        hashLowerKeyChars.put(String.valueOf(ch), lowerArrayChar);        hashUpperKeyChars.put(String.valueOf(ch), UpperArrayChar);    }//获取输入的char对应的数组    protected char[] getLowerKeyChars(char ch) {        charIndex = 0;

⌨️ 快捷键说明

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