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

📄 sdaform.java

📁 很好的UI界面源码..还有自己的输入法,可以更换风格.可以学习和使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package cn.sda.ui;

import java.util.*;

import javax.microedition.lcdui.*;

import cn.sda.event.*;

public class SDAForm extends SDABaseControl {

    protected String caption = "Form";
    private SDAFormCaption formCatpion = null;
    private SDAFormContainer formContainer = null;
    protected final SDAApplication Application = SDAApplication.GetInstance();
    protected Canvas canvas = null;
    protected Graphics graphics = null;
    protected SDABaseControl focusControl = null;
    private SDABaseControl operateControl = null;
    protected SDABaseControl popControl = null;
    private boolean inputAbort = false;
    private SDAInputPanel inputPanel = null;
    private Hashtable hotKeyList = new Hashtable();
    //标题
    private Image captionBackImage = null;
    private int captionAlignType = SDAConsts.alignLeft;
    private Image captionIcon = null;
    private boolean showCloseButton = true;
    //主菜单
    private SDAMainMenu mainMemu = null;

    private void InitForm(String caption) {
        this.caption = caption;
        this.form = this;
        this.width = 100;
        this.height = 100;
        this.setBackColor(SDAConsts.clWhite);
        this.graphics = Application.GetGraphics();
        this.canvas = Application.GetCanvas();
        this.formContainer = new SDAFormContainer();
        this.formContainer.form = this;

        this.formContainer.setWidth(this.canvas.getWidth());
        this.formContainer.setHeight(this.canvas.getHeight());
        this.formCatpion = new SDAFormCaption();
        this.formCatpion.form = this;
        this.formCatpion.setDock(SDAConsts.dsTop);
        this.formContainer.AddControl(this.formCatpion);
        this.setDock(SDAConsts.dsFill);
        this.formContainer.AddControl(this);
    }

    public SDAForm() {
        InitForm("Form");
    }

    public SDAForm(String caption) {
        InitForm(caption);
    }

    public void setLeft(int left) {
        this.formContainer.left = left;
    }

    public void setTop(int top) {
        this.formContainer.top = top;
    }

    public void setHeight(int height) {
        this.formContainer.height = height;
    }

    public void setWidth(int width) {
        this.formContainer.width = width;
    }

    //初始化方法
    public Canvas GetCanvas() {
        return this.canvas;
    }

    protected void closePopCtrl() {
        this.inputAbort = true;
        this.popControl = null;
    }

    protected String getKeyName(int keyCode) {
        return String.valueOf(keyCode);
    }

    private void NextTabOrder() {
        //System.out.println("NextTabOrder");
        SDABaseControl nextTabCtrl = null;
        if (focusControl != null) {
            nextTabCtrl = focusControl.FindNextFocusedCtrl(null, false);
            if (nextTabCtrl == null && focusControl.parent != null) {
                nextTabCtrl = focusControl.parent.FindNextFocusedCtrl(
                        focusControl, false);
            }
        }
        if (nextTabCtrl == null) {
            nextTabCtrl = this.FindNextFocusedCtrl(null, false);
        }
        if (nextTabCtrl != null) {
            nextTabCtrl.setFoucsed();
        }
    }

    private void PriorTabOrder() {
        //System.out.println("PriorTabOrder");
        SDABaseControl nextTabCtrl = null;
        if (focusControl != null && focusControl.parent != null) {
            nextTabCtrl = focusControl.parent.FindNextFocusedCtrl(focusControl, true);
        }
        if (nextTabCtrl == null) {
            nextTabCtrl = this.FindNextFocusedCtrl(null, true);
        }
        if (nextTabCtrl != null) {
            nextTabCtrl.setFoucsed();
        }
    }

    public void Repaint() {
        this.paint();
        serviceRepaints();
    }

    private final void DrawForm() {
        //ConsoleInfo("DrawFormBegin,width="+this.width+",height="+this.height);
        SetClip(graphics, 0, 0, this.width, this.height);
        if (Application.getSkins() == null) {
            graphics.setColor(this.getBackColor());
            fillRect(graphics, 1, 0, this.width - 2, this.height - 1);
        } else {
            Image skin = Application.getSkins().getImage("form_bg.png");
            skin = SDAImageUtils.processImage(skin, this.width - 2,
                    this.height - 1,
                    SDAImageUtils.MODE_STRETCH);
            drawImage(graphics, skin, 1, 0, 0);
        }
    }

    public void paint() {
        this.ctl3d = Application.isCtrl3d();
        this.formContainer.paint();
        this.formCatpion.paint();

        if (!IsCanPaint()) {
            return;
        }
        DrawForm();
        PaintChilds();
        if (this.equals(Application.getFoucsedForm())) {
            if (focusControl != null && !focusControl.equals(this)) {
                focusControl.paint();
            }
            if (popControl != null && !popControl.equals(focusControl)) {
                popControl.paint();
            }
            if (inputPanel != null) {
                inputPanel.paint();
            }
        }
    }

    protected final void pointerPressed(int x,
            int y) {
        if (this.formCatpion.visible && this.formCatpion.InScreenRect(x, y)) {
            if (this.formCatpion.onPointerPressed != null) {
                this.formCatpion.onPointerPressed.Event(null, x, y);
            }
            return;
        }
        inputAbort = false;
        if (popControl != null) {
            if (popControl.onPointerPressed != null) {
                popControl.onPointerPressed.Event(popControl, x, y);
            }
        } else {
            SDABaseControl ctrl = FindControl(x, y);
            operateControl = ctrl;
            if (operateControl != null) {
                operateControl.setFoucsed();
                if (!operateControl.isDown()) {
                    operateControl.setDown(true);
                }
                if (operateControl.onPointerPressed != null) {
                    operateControl.onPointerPressed.Event(ctrl, x, y);
                }

            }
        }
        if (this.equals(Application.getFoucsedForm())) {
            this.serviceRepaints();
        }
    }

    protected final void pointerReleased(int x,
            int y) {
        if (inputAbort) {
            return;
        }
        if (this.formCatpion.visible && this.formCatpion.InScreenRect(x, y)) {
            if (this.formCatpion.onPointerReleased != null) {
                this.formCatpion.onPointerReleased.Event(null, x, y);
            }
            return;
        }
        if (popControl != null) {
            if (popControl.onPointerReleased != null) {
                popControl.onPointerReleased.Event(popControl, x, y);
            }
            if (popControl != null && !popControl.InScreenRect(x, y)) {
                popControl = null;
                this.paint();
            }
        } else {
            if (operateControl != null) {

                if (operateControl.isDown()) {
                    operateControl.setDown(false);
                }
                if (operateControl.InScreenRect(x, y)) {
                    if (operateControl.onPointerReleased != null) {
                        operateControl.onPointerReleased.Event(operateControl,
                                x, y);
                    }
                    operateControl.Click();
                }
            }
        }
        operateControl = null;
        if (this.equals(Application.getFoucsedForm())) {
            this.serviceRepaints();
        }

    }

    protected final void pointerDragged(int x, int y) {
        if (inputAbort) {
            return;
        }
        if (popControl != null) {
            if (popControl.onPointerDragged != null) {
                popControl.onPointerDragged.Event(popControl, x, y);
                if (popControl != null) {
                    popControl.paint();
                }
            }
        } else {
            if (operateControl != null) {
                if (operateControl.InScreenRect(x, y)) {
                    operateControl.setDown(true);
                } else {
                    operateControl.setDown(false);
                }
                operateControl.paint();
            }
            SDABaseControl ctrl = FindControl(x, y);
            if (ctrl != null && ctrl.onPointerDragged != null) {
                ctrl.onPointerDragged.Event(ctrl, x, y);
                ctrl.paint();
            }
        }
        if (this.equals(Application.getFoucsedForm())) {
            this.serviceRepaints();
        }
    }

    protected final void keyPressed(int keyCode) {
        inputAbort = false;
        if (popControl != null) {
            if (popControl.onKeyDown != null) {
                popControl.onKeyDown.Event(popControl, keyCode);
                if (popControl != null) {
                    popControl.paint();
                }
            }
        } else {
            //keydown
            this.operateControl = focusControl;
            if (operateControl != null && operateControl.onKeyDown != null) {
                operateControl.onKeyDown.Event(operateControl, keyCode);
                operateControl.paint();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -