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

📄 sdatabcontrol.java

📁 很好的UI界面源码..还有自己的输入法,可以更换风格.可以学习和使用
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * 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 + -