?? sdainputpanel.java
字號:
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 + -