?? sdainputpanel.java
字號:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package cn.sda.ui;import cn.sda.event.PointerEvent;import cn.sda.pinyin.InputInterface;import cn.sda.pinyin.Spell2Chars;import java.util.Hashtable;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.Font;/** * * @author Administrator */public class SDAInputPanel extends SDABaseControl { //類型 public static final int imNone = 0; public static final int imUpperCase = 1; public static final int imLowerCase = 2; public static final int imDigit = 3; public static final int imPoint = 4; public static final int imSymbol = 5; public static final int imPinYin = 6; //輸入法類型 protected int ImeType = imPinYin; //顏色 private int borderColor = SDAConsts.clBlack; //選中顏色 private int selectedBackColor = SDAConsts.clBlack; private int selectedForeColor = SDAConsts.clWhite; //當前行位置 private int curHeight = 0; //是否打開全角 private boolean SBCCase = false; //輸入顯示 protected inputCharsPanel charsPanel = null; //點的位置() private int charXPos = -1; private int charYPos = -1; //當前被選中的Char內容(可見) protected char selectedChar = 0; //功能鍵名字 //private String funcKeyName=""; //graphic private Graphics gg = null; //拼音處理 //輸入的字母(包括拼音,非觸摸屏下的字母(字母和數字靠輸入法類型區分)) protected StringBuffer inputChars; //選擇的內容(包括拼音或者非觸摸屏下的字母等) private StringBuffer selectedChars; //對應一個拼音組合的所有漢字 protected char[] hanziChars; //選擇的漢字index protected int selectedHanziIndex = 0; //查詢到的漢字數 private int hanziCount = 0; //大寫字母 private char[] UpperCaseChars = null; private char[] SBCUpperCaseChars = null; //小寫字母 private char[] LowerCaseChars = null; private char[] SBCLowerCaseChars = null; //數字 private char[] DigitChars = null; private char[] SBCDigitChars = null; //標點 private char[] PointChars = null; private char[] SBCPointChars = null; //符號 private char[] SymbolChars = null; private char[] SBCSymbolChars = null; //對于一鍵多字母的切換處理 private Hashtable hashLowerKeyChars = null; private Hashtable hashUpperKeyChars = null; //獲取的一鍵多字母的所有字母組合 protected char[] numChars = null; //這些字母的選擇的index private int charIndex = 0; //輸入內容顯示和選擇框 protected class inputCharsPanel extends SDABaseControl { //光標在屏幕中的絕對位置 protected int oraX = 0, oraY = 0; private int pageScrollBarColor = SDAConsts.clBtnFace; private int pageScrollBarFontColor = SDAConsts.clBlack; private int inputBarColor = SDAConsts.clWhite; //選擇 private int selectedBackColor = SDAConsts.clFocusShadow; private int selectedFontColor = SDAConsts.clWhite; //當前頁 private int pageNo = 1; //總頁 private int pageCount = 1; //輸入內容焦點位置(拼音才有) public int cursorPos = 0; //輸入狀態(拼音) protected boolean isInput = true; public inputCharsPanel() { super(); setVisible(false); tabStop = false; setWidth(60); setHeight(80); setBackColor(SDAConsts.clWhite); foreColor = SDAConsts.clBlack; setOnPointerPressed(new PointerEvent() { public void Event(SDABaseControl ctrl, int x, int y) { doPointerPressed(x, y); } }); } //點擊 private void doPointerPressed(int x, int y) { int posx = screenXToClient(x); int posy = screenYToClient(y); int fontHeight = getFont().getHeight(); //根據點擊的位置判斷 if (ImeType == imPinYin) { if (InClientRect(posx, posy, 0, fontHeight, width, height - 2 * fontHeight)) { selectedHanziIndex = (posy - fontHeight) / fontHeight + 4 * (posx / (width / 2)); getHanziByIndex(); } //翻頁 if (InClientRect(posx, posy, width / 2, height - fontHeight, width / 4, fontHeight)) { //左 priorPage(); } if (InClientRect(posx, posy, 3 * width / 4, height - fontHeight, width / 4, fontHeight)) { //左 nextpage(); } } //字母 if (ImeType == imUpperCase || ImeType == imLowerCase) { charIndex=posy/fontHeight; char ch=13; inputFuncChar(ch); } } //點擊選擇漢字 protected boolean getHanziByIndex() { boolean result = false; if (hanziChars != null) { if (selectedHanziIndex + (pageNo - 1) * 8 < hanziChars.length && selectedHanziIndex + (pageNo - 1) * 8 > -1) { result = true; selectedChar = hanziChars[selectedHanziIndex + (pageNo - 1) * 8]; inputVisibleChar(); selectedHanziIndex = -1; inputChars.setLength(0); hanziChars = null; isInput = true; visible = false; form.repaintControl(); } } return result; } public int getPageScrollBarColor() { return pageScrollBarColor; } public void setPageScrollBarColor(int pageScrollBarColor) { this.pageScrollBarColor = pageScrollBarColor; } public int getPageScrollBarFontColor() { return pageScrollBarFontColor; } public void setPageScrollBarFontColor(int pageScrollBarFontColor) { this.pageScrollBarFontColor = pageScrollBarFontColor; } public int getSelectedBackColor() { return selectedBackColor; } public void setSelectedBackColor(int selectedBackColor) { this.selectedBackColor = selectedBackColor; } public int getSelectedFontColor() { return selectedFontColor; } public void setSelectedFontColor(int selectedFontColor) { this.selectedFontColor = selectedFontColor; } public int getInputBarColor() { return inputBarColor; } public void setInputBarColor(int inputBarColor) { this.inputBarColor = inputBarColor; } //對功能鍵的處理 protected void inputFuncChar(char inChar) { //左(輸入時移動光標,輸入后漢字翻頁) if (inChar == 37) { if (ImeType == imPinYin) { if (isInput && cursorPos > 0) { cursorPos--; } if (!isInput) { priorPage(); } } if (ImeType == imUpperCase || ImeType == imLowerCase) { if (numChars != null) { priorChar(); } } } //上(對漢字等上下滾動) if (inChar == 38) { if (!isInput && ImeType == imPinYin) { //翻頁 if (pageNo > 1 && selectedHanziIndex == (pageNo - 1) * 8) { priorPage(); return; } //選擇向上 if (selectedHanziIndex > 0) { selectedHanziIndex--; } else { isInput = true; } } if (ImeType == imUpperCase || ImeType == imLowerCase) { if (numChars != null) { priorChar(); } } } //右 if (inChar == 39) { if (ImeType == imPinYin) { if (isInput && cursorPos < inputChars.length()) { cursorPos++; } if (!isInput) { nextpage(); } } if (ImeType == imUpperCase || ImeType == imLowerCase) { if (numChars != null) { nextChar(); } } } //下(滾動選擇內容) if (inChar == 40) { if (ImeType == imPinYin) { if (!isInput) { if (pageNo < pageCount && selectedHanziIndex == (pageNo - 1) * 8 + 7) { nextpage(); return; } if (selectedHanziIndex < hanziCount - 1) { selectedHanziIndex++; } } else { if (hanziChars != null) { selectedHanziIndex = 0; isInput = false; } } } if (ImeType == imLowerCase || ImeType == imUpperCase) { if (numChars != null) { nextChar(); } } } //刪除 if (inChar == 46) { if (ImeType == imPinYin) { if (cursorPos < inputChars.length()) { inputChars.deleteCharAt(cursorPos); } if (inputChars.length() == 0) { visible = false; } } if (ImeType == imLowerCase || ImeType == imUpperCase) { numChars = null; visible = false; } } //退格 if (inChar == 8) { if (ImeType == imPinYin) { if (cursorPos > 0 && cursorPos < inputChars.length() + 1) { inputChars.deleteCharAt(cursorPos - 1); cursorPos--; } if (inputChars.length() == 0) { visible = false; } } if (ImeType == imLowerCase || ImeType == imUpperCase) { numChars = null; visible = false; } } //回車 if (inChar == 13) { if (ImeType == imPinYin) { if (isInput) { if (hanziChars != null) { if (hanziChars.length > 0) { isInput = false; selectedHanziIndex = 0; } } } else { //選擇的內容 if (hanziChars != null) { if (selectedHanziIndex > -1 && selectedHanziIndex < hanziCount) { selectedChar = hanziChars[selectedHanziIndex]; inputVisibleChar(); selectedHanziIndex = -1; inputChars.setLength(0); hanziChars = null; charsPanel.visible = false;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -