?? sdabaseedit.java
字號:
package cn.sda.ui;import cn.sda.event.BaseEditTextChangeEvent;import cn.sda.event.KeybordEvent;import cn.sda.event.NotifyEvent;import cn.sda.event.PointerEvent;import cn.sda.pinyin.InputInterface;import java.io.ByteArrayOutputStream;import java.io.DataOutputStream;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.Font;/** * @author not attributable * @version 1.0 */public class SDABaseEdit extends SDABaseControl implements InputInterface { //邊框 private int borderStyle = SDAConsts.bsNone; //是不是顯示焦點框 private boolean showFocusRect = false; //隱藏選定內容 private boolean hideSelection = true; //最大長度 private int maxLength = 32767; //是否顯示多行 private boolean multiLine = false; //密碼 private char passwordChar = 0; //只讀 protected boolean readOnly = false; //滾動邊框(多行) private int scrollBars = SDAConsts.srNone; //文字對齊方式 private int textAlign = SDAConsts.alignLeft; //是否自動換行(多行) private boolean wordWrap = true; private int barwidth = 10; //邊框線顏色 private int borderColor = SDAConsts.clBlack; //滾動條顏色 private int scrollBarColor = SDAConsts.clBtnFace; //內部變量 //行數,行最大長度 private int lineNum = 0; private int maxLineLenght = 0; //垂直開始顯示行 private int startLine = 0; //水平開始顯示位置 private int startLeft = 0; //變動前位置 private int oldStartLine = 0; private int oldStartLeft = 0; //行數 private int lineNo = 0; //水平滾條位置 private int HSLeft = 0; private int HSTop = 0; private int HSWidth = 0; private int HSHeight = 0; //垂直滾動條位置 private int VSLeft = 0; private int VSTop = 0; private int VSWidth = 0; private int VSHeight = 0; //點擊的滾動條的位置 private int oldScrollPointx = 0; private int oldScrollPointy = 0; //按下滾動條 private boolean isscrollbarpointdown = false; //記錄按下的滾動條0:水平,1:垂直的 private byte scrollbardownHV = 0; //當前光標位置 private int cursorPos = 0; //光標行列 private int cursorRow = 0; protected int cursorCol = 0; //光標絕對位置 private int cursorX = 0; private int cursorY = 0; //選擇行的起始位置和內容 private int cursorLineStartPos = 0; private String cursorLineText = ""; //前一行長度 private int priorLineLen = 0; //臨時buffer StringBuffer strBuffer = new StringBuffer(); //對齊方式 private int oldAlignType = SDAConsts.alignLeft; //輸入法 private int imeType = SDAInputPanel.imNone; //文字變動 private BaseEditTextChangeEvent onTextChange = null; // Graphics gg = null; protected SDABaseEdit() { super(); internalSDAEdit(); } private void internalSDAEdit() { setVisible(true); setLeft(0); setTop(0); setBorderStyle(SDAConsts.bsFixedSingle); super.setWidth(60); //高度根據字體高度來 setHeight(getFont().getHeight() + 4); super.setBackColor(SDAConsts.clWhite); onPointerPressed = new PointerEvent() { public void Event(SDABaseControl ctrl, int x, int y) { doPointerPressed(x, y); } }; onPointerReleased = new PointerEvent() { public void Event(SDABaseControl ctrl, int x, int y) { doPointerReleased(x, y); } }; onKeyUp = new KeybordEvent() { public void Event(SDABaseControl ctrl, int keyCode) { doKeyUp(keyCode); } }; onInternalLostFocused = new NotifyEvent() { public void Event(SDABaseControl ctrl) { doLostFocus(); } }; onInternalFocused = new NotifyEvent() { public void Event(SDABaseControl ctrl) { doGetFocus(); } }; //設置系統菜單 /* systemMenu=new SDAPopMenu(); systemMenu.AddItem("back", "退格"); systemMenu.AddItem("delete", "刪除"); systemMenu.AddItem("enter", "插入回車"); systemMenu.AddItem("", "-"); systemMenu.AddItem("ABC", "大寫字母").setRadioItem(true); systemMenu.AddItem("abc", "小寫字母").setRadioItem(true); systemMenu.AddItem("123", "數字").setRadioItem(true); systemMenu.AddItem("拼音", "中文拼音").setRadioItem(true); systemMenu.AddItem("標點", "插入標點").setRadioItem(true); systemMenu.AddItem("符號", "插入符號").setRadioItem(true); systemMenu.AddItem("", "-"); systemMenu.AddItem("全", "全角"); systemMenu.setOnClick(new PopMenuOnClickEvent() { public void Event(SDAMenuItem item, String itemName, String itemCaption) { //處理 if(itemName.equals("back")){ char ch=8; inputFuncChar(ch, false); } if(itemName.equals("delete")){ char ch=46; inputFuncChar(ch, false); } if(itemName.equals("enter")){ char ch=13; inputFuncChar(ch, false); } if (itemName.equals("ABC")) { form.Application.inputPanel.setImeType(SDAInputPanel.imUpperCase); } if (itemName.equals("abc")) { form.Application.inputPanel.setImeType(SDAInputPanel.imLowerCase); } if (itemName.equals("123")) { form.Application.inputPanel.setImeType(SDAInputPanel.imDigit); } if (itemName.equals("拼音")) { form.Application.inputPanel.setImeType(SDAInputPanel.imPinYin); } if (itemName.equals("標點")) { form.Application.inputPanel.setImeType(SDAInputPanel.imPoint); SDASelectPointForm.getInstance().open(getSelf()); } if (itemName.equals("符號")) { form.Application.inputPanel.setImeType(SDAInputPanel.imSymbol); SDASelectSymbolForm.getInstance().open(getSelf()); } if (itemName.equals("全")) { form.Application.inputPanel.setSBCCase(!form.Application.inputPanel.isSBCCase()); item.setChecked(form.Application.inputPanel.isSBCCase()); } else { item.setChecked(true); } } }); */ } public void paint() { internalPaint(); } private void internalPaint() { if (!IsCanPaint()) { return; } Graphics g = form.getGraphics(); gg = g; //設置字體 g.setFont(getFont()); gg.setFont(getFont()); //可視下才畫 if (isVisible()) { //初始化引用變量 int thisWidth = width; int thisHeight = height; int HBarWidth = getHBarWidth(); int VBarHeight = getVBarHeight(); int fontHeight = getFont().getHeight(); //對齊方式處理后,畫組件 //外框 SetClip(g); //透明 if (!isTransparent()) { g.setColor(backColor); fillRect(g, 0, 0, thisWidth, thisHeight); } if (borderStyle == SDAConsts.bsFixed3D) { g.setColor(SDAConsts.clGray); drawLine(g, 0, 0, thisWidth, 0); drawLine(g, 0, 0, 0, thisHeight); g.setColor(SDAConsts.clBlack); drawLine(g, 1, 1, thisWidth - 1, 1); drawLine(g, 1, 1, 1, thisHeight - 1); g.setColor(SDAConsts.clBtnFace); drawLine(g, 2, thisHeight - 1, thisWidth - 2, thisHeight - 1); drawLine(g, thisWidth - 1, 2, thisWidth - 1, thisHeight - 1); g.setColor(SDAConsts.clWhite); drawLine(g, 1, thisHeight, thisWidth, thisHeight); drawLine(g, thisWidth, 1, thisWidth, thisHeight); if (isFoucsed() && showFocusRect) { g.setColor(SDAConsts.clFocusShadow); drawRect(g, 1, 1, thisWidth - 2, thisHeight - 2); } } if (borderStyle == SDAConsts.bsFixedSingle) { //邊框 g.setColor(getBorderColor()); drawRect(g, 0, 0, thisWidth, thisHeight); if (isFoucsed() && showFocusRect) { g.setColor(SDAConsts.clFocusShadow); drawRect(g, 1, 1, thisWidth - 2, thisHeight - 2); } } //打字 g.setColor(getForeColor()); //文字對齊方式 if (!isMultiLine()) { if (textAlign == SDAConsts.alignLeft) { paintString(g, getText(), 2, (height - fontHeight) / 2); } if (textAlign == SDAConsts.alignCenter) { //文字長度 int Len = getFont().stringWidth(getText()); int sleft = (thisWidth - Len) / 2; paintString(g, getText(), sleft, (height - fontHeight) / 2); } if (textAlign == SDAConsts.alignRight) { //文字長度 int Len = getFont().stringWidth(getText()); int sleft = (thisWidth - Len) - 1; paintString(g, getText(), sleft, (height - fontHeight) / 2); } } else { paintString(g, getText(), 2, (height - fontHeight) / 2); } //多行滾動條 if (borderStyle == SDAConsts.bsFixed3D) { SetClip(g, 2, 2, thisWidth - 2, height - 2); } else { SetClip(g, 1, 1, thisWidth - 1, height - 1); } if (isMultiLine()) { if ((scrollBars == SDAConsts.srHorizontal) || (scrollBars == SDAConsts.srBoth)) { //水平 g.setColor(getScrollBarColor()); fillRect(g, 0, height - barwidth, barwidth, barwidth); fillRect(g, HBarWidth - barwidth, height - barwidth, barwidth, barwidth); g.setColor(getBorderColor()); drawRect(g, 0, thisHeight - barwidth, barwidth, barwidth); drawRect(g, HBarWidth - barwidth, height - barwidth, barwidth, barwidth); //滾動塊 g.setColor(backColor); fillRect(g, barwidth, height - barwidth, HBarWidth - 2 * barwidth, barwidth); g.setColor(getBorderColor()); drawRect(g, barwidth, thisHeight - barwidth, HBarWidth - 2 * barwidth, barwidth); //塊大小 int pwidth = HBarWidth - 2 * barwidth; if (!isWordWrap()) { if (maxLineLenght > HBarWidth) { pwidth = (HBarWidth * (HBarWidth - 2 * barwidth)) / maxLineLenght; } } //計算塊位置 int ppos = (startLeft * (HBarWidth - 2 * barwidth)) / maxLineLenght; //修正位置 if (ppos + pwidth > HBarWidth - 2 * barwidth) { ppos = HBarWidth - 2 * barwidth - pwidth; } //畫塊 g.setColor(getScrollBarColor()); fillRect(g, barwidth + ppos, thisHeight - barwidth, pwidth, barwidth); g.setColor(getBorderColor()); drawRect(g, barwidth + ppos, thisHeight - barwidth, pwidth, barwidth); //記錄大小 HSLeft = barwidth + ppos; HSTop = thisHeight - barwidth; HSWidth = pwidth; HSHeight = barwidth; //畫塊上的線 int tpos = HSWidth / 2 + HSLeft; drawRect(g, tpos, HSTop + 2, 0, HSHeight - 4); if (tpos - 2 > HSLeft) { drawRect(g, tpos - 2, HSTop + 2, 0, HSHeight - 4); } if (tpos + 2 < HSLeft + HSWidth) { drawRect(g, tpos + 2, HSTop + 2, 0, HSHeight - 4); } //三角 g.setColor(getBorderColor()); fillTriangle(g, barwidth / 2 - 2, thisHeight - barwidth / 2, barwidth / 2 + 2, thisHeight - barwidth / 2 - 4, barwidth / 2 + 2, thisHeight - barwidth / 2 + 4); fillTriangle(g, HBarWidth - barwidth + barwidth / 2 + 2, thisHeight - barwidth / 2, HBarWidth - barwidth + barwidth / 2 - 2, thisHeight - barwidth / 2 - 4, HBarWidth - barwidth + barwidth / 2 - 2, thisHeight - barwidth / 2 + 4); } if ((scrollBars == SDAConsts.srVertical) || (scrollBars == SDAConsts.srBoth)) { //垂直 g.setColor(getScrollBarColor()); fillRect(g, thisWidth - barwidth, 0, barwidth, barwidth); fillRect(g, thisWidth - barwidth, VBarHeight - barwidth, barwidth, barwidth); g.setColor(getBorderColor()); drawRect(g, thisWidth - barwidth, 0, barwidth, barwidth); drawRect(g, thisWidth - barwidth, VBarHeight - barwidth, barwidth, barwidth); //滾動塊 g.setColor(backColor); fillRect(g, thisWidth - barwidth, barwidth, barwidth, VBarHeight - 2 * barwidth); g.setColor(borderColor); drawRect(g, thisWidth - barwidth, barwidth, barwidth, VBarHeight - 2 * barwidth); //塊大小 int pheight = VBarHeight - 2 * barwidth; if (lineNum * getFont().getHeight() > VBarHeight) { pheight = (VBarHeight * (VBarHeight - 2 * barwidth) / (lineNum * getFont().getHeight())); } //計算塊位置 int ppos = barwidth; if (lineNum > 0) { ppos = (startLine * getFont().getHeight() * (VBarHeight - 2 * barwidth)) / (lineNum * getFont().getHeight()); } //修正位置 if (ppos + pheight > VBarHeight - 2 * barwidth) { ppos = VBarHeight - 2 * barwidth - pheight; } //畫塊 g.setColor(getScrollBarColor());
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -