?? sdatabcontrol.java
字號:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package cn.sda.ui;import cn.sda.event.KeybordEvent;import cn.sda.event.PointerEvent;import cn.sda.event.TabSheetChangeEvent;import java.util.Vector;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.Image;import javax.microedition.lcdui.Font;/** * * @author Administrator */public class SDATabControl extends SDABaseControl { private byte buttonAlignType = SDAConsts.ktHorizontal; private int borderColor = SDAConsts.clBlack; //是否顯示標題 private boolean showCaption = true; //是否按照標題自動伸縮按鈕 private boolean autoSizeButton = true; //組件列表 private Vector controlList = null; //當前位置 private SDATabSheet curSheet = null; //事件 private TabSheetChangeEvent onChangeEvent = null; //背景圖 private Image backImage = null; private boolean stretchImage = true; //按鈕圖片排布方式 private int glyphAlignType = SDAConsts.blGlyphLeft; //按鈕位置 private int buttonPosition = SDAConsts.tabButtonsTop; //按鈕的缺省尺寸 private int buttonSize = 40; //按鈕區大小 private int SelectbuttonSize = 0; //偏移 private int offset = 0; //按鈕總長度(判斷是否顯示滾動按鈕) private int buttonsLen = 0; //開始顯示的按鈕 private int StartButtonPos = 0; //最后完整顯示按鈕index private int endButtonPos = 0; //滾動按鈕背景色 private int scrollButtonColor = SDAConsts.clWhite; //滾動按鈕大小 private int scrollButtonSize = 14; //是否可以繼續向后滾動 private boolean canScroll = false; public SDATabControl() { super(); setWidth(120); setHeight(100); controlList = new Vector(); setOnKeyUp(new KeybordEvent() { public void Event(SDABaseControl ctrl, int keyCode) { //鍵盤 doKeyUp(keyCode); } }); setOnPointerPressed(new PointerEvent() { public void Event(SDABaseControl ctrl, int x, int y) { //點 doPointerPress(x, y); } }); } public void paint() { if (!IsCanPaint()) { return; } Graphics g = form.getGraphics(); SetClip(g); g.setFont(getFont()); int thisWidth = getWidth(); int thisHeight = getHeight(); //框 if (!transparent) { g.setColor(backColor); fillRect(g, 0, 0, thisWidth, thisHeight); } //畫按鈕和分割線 paintButton(g); //畫滾動按鈕 paintScrollButton(g); //畫子組件 setSheetVisible(); PaintChilds(); //焦點 if (isFoucsed()) { g.setColor(SDAConsts.clFocusShadow); if (buttonAlignType == SDAConsts.ktHorizontal) { if (buttonPosition == SDAConsts.tabButtonsTop) { drawRect(g, 1, SelectbuttonSize + 1, thisWidth - 2, thisHeight - 2 - SelectbuttonSize); } if (buttonPosition == SDAConsts.tabButtonsBottom) { drawRect(g, 1, 1, thisWidth - 2, offset - 2); } } else { if (buttonPosition == SDAConsts.tabButtonsLeft) { drawRect(g, SelectbuttonSize + 1, 1, thisWidth - 2 - SelectbuttonSize, thisHeight - 2); } if (buttonPosition == SDAConsts.tabButtonsRight) { drawRect(g, 1, 1, offset - 2, thisHeight - 2); } } } SetClip(g); g.setColor(borderColor); drawRect(g, 0, 0, thisWidth, thisHeight); PaintChilds(); } //計算設置按鈕的寬度 private void setButtonSize() { SDATabSheet sheet = null; int buttonHeight = getHeight() - 4; int buttonWidth = getWidth() - 4; Font ft = getFont(); int fontheight = ft.getHeight(); int num = 0; int bsize = 0; buttonsLen = 0; for (int i = 0; i < controlList.size(); i++) { sheet = (SDATabSheet) controlList.elementAt(i); if (autoSizeButton) { if (buttonAlignType == SDAConsts.ktHorizontal) { if (glyphAlignType == SDAConsts.blGlyphTop || glyphAlignType == SDAConsts.blGlyphBottom) { num = fontheight + 2 + (sheet.getImage() != null ? sheet.getImage().getHeight() + 2 : 0); if (bsize < num) { bsize = num; } } else { num = fontheight + 2; if (sheet.getImage() != null) { if (num < sheet.getImage().getHeight() + 2) { num = sheet.getImage().getHeight() + 2; } } if (bsize < num) { bsize = num; } } } else { if (glyphAlignType == SDAConsts.blGlyphLeft || glyphAlignType == SDAConsts.blGlyphRight) { num = ft.stringWidth(sheet.getCaption() + "xx") + (sheet.getImage() != null ? sheet.getImage().getWidth() + 2 : 0); if (bsize < num) { bsize = num; } } else { num = ft.stringWidth(sheet.getCaption() + "xx"); if (sheet.getImage() != null) { if (num < sheet.getImage().getWidth() + 2) { num = sheet.getImage().getWidth() + 2; } } if (bsize < num) { bsize = num; } } } } } SelectbuttonSize = bsize; for (int i = 0; i < controlList.size(); i++) { sheet = (SDATabSheet) controlList.elementAt(i); if (autoSizeButton) { if (buttonAlignType == SDAConsts.ktHorizontal) { sheet.setButtonHeight(bsize); if (sheet.getImage() != null && sheet.getCaption().length() > 0 && (glyphAlignType == SDAConsts.blGlyphLeft || glyphAlignType == SDAConsts.blGlyphRight)) { sheet.setButtonWidth(ft.stringWidth(sheet.getCaption() + "xx") + sheet.getImage().getWidth()); } else { num = ft.stringWidth(sheet.getCaption() + "xx"); if (sheet.getImage() != null) { if (num < sheet.getImage().getWidth()) { num = sheet.getImage().getWidth(); } } sheet.setButtonWidth(num); } buttonsLen += sheet.getButtonWidth(); } else { sheet.setButtonWidth(bsize); if (sheet.getImage() != null && sheet.getCaption().length() > 0 && (glyphAlignType == SDAConsts.blGlyphTop || glyphAlignType == SDAConsts.blGlyphBottom)) { sheet.setButtonHeight(fontheight + 4 + sheet.getImage().getHeight()); } else { num = fontheight + 2; if (sheet.getImage() != null) { if (num < sheet.getImage().getHeight() + 2) { num = sheet.getImage().getHeight() + 2; } } sheet.setButtonHeight(num); } buttonsLen += sheet.getButtonHeight(); } } else { if (buttonAlignType == SDAConsts.ktHorizontal) { sheet.setButtonHeight(buttonHeight); sheet.setButtonWidth(buttonSize); buttonsLen += sheet.getButtonWidth(); } else { sheet.setButtonWidth(buttonWidth); sheet.setButtonHeight(buttonSize); buttonsLen += sheet.getButtonHeight(); } } } } //畫按鈕 private void paintButton(Graphics g) { int thisWidth = getWidth(); int thisHeight = getHeight(); Font ft = getFont(); int fontHeight = ft.getHeight(); //設置大小 setButtonSize(); SetClip(g); //畫 int buttonPos = 0; if (buttonPosition == SDAConsts.tabButtonsTop) { offset = 0; buttonAlignType = SDAConsts.ktHorizontal; } if (buttonPosition == SDAConsts.tabButtonsBottom) { offset = getHeight() - SelectbuttonSize; buttonAlignType = SDAConsts.ktHorizontal; } if (buttonPosition == SDAConsts.tabButtonsLeft) { offset = 0; buttonAlignType = SDAConsts.ktVertical; } if (buttonPosition == SDAConsts.tabButtonsRight) { offset = getWidth() - SelectbuttonSize; buttonAlignType = SDAConsts.ktVertical; } SDATabSheet button = null; Image image = null; String caption = ""; //畫背景 if (backImage != null) { if (stretchImage) { image = SDAImageUtils.processImage(backImage, thisWidth, thisHeight, SDAImageUtils.MODE_STRETCH); } else { image = backImage; } drawImage(g, image, 0, 0, 0); } if (buttonAlignType == SDAConsts.ktHorizontal) { //橫線 g.setColor(borderColor); int linePos = buttonPosition == SDAConsts.tabButtonsTop ? SelectbuttonSize : offset; drawLine(g, 0, linePos, getWidth(), linePos); for (int i = StartButtonPos; i < controlList.size(); i++) { button = (SDATabSheet) controlList.elementAt(i); caption = button.getCaption(); g.setColor(borderColor); drawRect(g, buttonPos, offset, button.getButtonWidth(), button.getButtonHeight()); //SetClip(g, buttonPos, offset, button.getButtonWidth(), button.getButtonHeight() + 1); image = button.getImage(); //焦點按鈕 if (button.equals(curSheet)) { g.setColor(button.backColor); fillRect(g, buttonPos + 1, offset + (buttonPosition == SDAConsts.tabButtonsTop ? 1 : 0), button.getButtonWidth() - 1, button.getButtonHeight() + (buttonPosition == SDAConsts.tabButtonsTop ? 1 : 0)); } if (image != null) { if (showCaption && caption.length() > 0) { if (glyphAlignType == SDAConsts.blGlyphTop) { drawImage(g, image, buttonPos + (button.getButtonWidth() - image.getWidth()) / 2 + 1, offset + (button.getButtonHeight() - image.getHeight() - fontHeight) / 2 + 1, 0); g.setColor(foreColor); drawString(g, caption, buttonPos + (button.getButtonWidth() - ft.stringWidth(caption)) / 2 + 1, offset + (button.getButtonHeight() - image.getHeight() - fontHeight) / 2 + image.getHeight() + 1);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -