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

📄 bqitem.java

📁 J2me唆哈的代码
💻 JAVA
字号:
/*
 * Created on 2005-9-21 by pcy
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package a.a.a.midp.lcdui;
import java.awt.*;
import javax.swing.JLabel;
import javax.swing.JPanel;
//import javax.swing.JComponent;
import javax.microedition.lcdui.*;

import a.a.a.b.e;

public abstract class BQItem extends JPanel{

    Component instance;
    JLabel label;
    Item shell;

    final static BQFont LABEL_FONT = BQFont.getFont(
            BQScreen.CONTENT_FONT.getFace(),
            javax.microedition.lcdui.Font.STYLE_BOLD,
            BQScreen.CONTENT_FONT.getSize());
    
    final static int VALID_LAYOUT;

    static {
        VALID_LAYOUT =
            Item.LAYOUT_DEFAULT |
            Item.LAYOUT_LEFT |
            Item.LAYOUT_RIGHT |
            Item.LAYOUT_CENTER |
            Item.LAYOUT_TOP |
            Item.LAYOUT_BOTTOM |
            Item.LAYOUT_VCENTER |
            Item.LAYOUT_SHRINK |
            Item.LAYOUT_EXPAND |
            Item.LAYOUT_VSHRINK |
            Item.LAYOUT_VEXPAND |
            Item.LAYOUT_NEWLINE_BEFORE |
            Item.LAYOUT_NEWLINE_AFTER |
            Item.LAYOUT_2;
    }
    
    BQScreen owner;
    
    boolean hasFocus;
    
    boolean sizeChanged;

    BQItemCommandListener commandListener; // = null;

    String labelStr;

    int layout;       // = 0 ; LAYOUT_DEFAULT = 0

    BQCommand defaultCommand;

    int numCommands;
    
    private BQCommand commands[];
    
    
    int lockedWidth=-1;
    
    int lockedHeight=-1;
    
    BQItem(String labelText) {
        super();
        this.setLayout(new FlowLayout());
        this.labelStr=labelText;
        this.label=new JLabel(labelText);
        this.label.setFont(LABEL_FONT.getTrueFont());
        this.add(this.label);
//        label.setBounds(0,0,a.a.a.b.e.getInstance().getScreenWidth()>>1,30);
//        label.setMaximumSize(new Dimension(a.a.a.b.e.getInstance().getScreenWidth()>>1,50));
        this.setAutoscrolls(true);
        /*int w=Emulator.getScreenWidth();
        int h=Emulator.getScreenHeight()-BQDisplayable.COMMAND_BAR_HEIGHT-BQDisplayable.TITLE_BAR_HEIGHT;
        this.setMaximumSize(new Dimension(w-10,h-10));
        */
    }

   
    public void setLabel(String labelText){
        labelStr=labelText;
        this.label.setText(labelText);
    }
    
    public String getLabel(){
        return labelStr;
    }
    
    public int getMLayout(){
        return layout;
    }
    
    public void setLayout(int layout){
        setLayoutImpl(layout);
    }
    
    public void addCommand(BQCommand cmd){
        addCommandImpl(cmd);
    }
    
    public void removeCommand(BQCommand cmd){
        removeCommandImpl(cmd);
    }
    
    public void setItemCommandListener(BQItemCommandListener l){
        commandListener=l;
    }
    
    public int getPreferredWidth(){
        return (lockedWidth != -1) ? lockedWidth :
            this.callPreferredWidth(lockedWidth);
    }
    
    public int getPreferredHeight(){
        return (lockedHeight != -1) ? lockedHeight :
            this.callPreferredHeight(lockedHeight);
    }
    
    public void setPreferredSize(int width, int height){
        if (width < -1 || height < -1) {
            throw new IllegalArgumentException();
        }
        //synchronized (Display.LCDUILock) {
            if (owner != null && owner instanceof BQAlert) {
                throw new IllegalStateException();
            }

            int minWidth  = getMinimumWidth();
            int minHeight = getMinimumHeight();

            this.lockedWidth  = (width != -1 && width < minWidth) 
                              ? minWidth 
                              : width;

            this.lockedHeight = (height != -1 && height < minHeight) 
                              ? minHeight 
                              : height;

       // } // synchronized
    }
    
    public int getMinimumWidth(){
        return this.callMinimumWidth()+label.getPreferredSize().width;
    }
    
    public int getMinimumHeight(){
        int h=this.callMinimumHeight();
        if(h<label.getPreferredSize().height){
            h=label.getPreferredSize().height;
        }
        return h;
    }
    
    public void setDefaultCommand(BQCommand cmd){
        if(cmd!=null){
            addCommand(cmd);
        }
        defaultCommand=cmd;
    }
    
    public void notifyStateChanged(){
        
    }
    
    void setLayoutImpl(int layout) {

        if ((layout & ~VALID_LAYOUT) != 0) {
            throw new IllegalArgumentException();
        }

        this.layout = layout;
    }
    
    void addCommandImpl(BQCommand cmd){
        if (cmd == null) {
            throw new NullPointerException();
        }

        for (int i = 0; i < numCommands; ++i) {
            if (commands[i] == cmd) {
                return;
            }
        }

        if ((commands == null) || (numCommands == commands.length)) {
            BQCommand[] newCommands = new BQCommand[numCommands + 4];
            if (commands != null) {
                System.arraycopy(commands, 0, newCommands, 0,
                                 numCommands);
            }
            commands = newCommands;
        }

        commands[numCommands] = cmd;
        ++numCommands;

        /*if (owner != null) {
            owner.updateCommandSet();
        }*/
        
    }
    
    void removeCommandImpl(BQCommand cmd) {

        for (int i = 0; i < numCommands; ++i) {
            if (commands[i] == cmd) {
                commands[i] = commands[--numCommands];
                commands[numCommands] = null;

                if (cmd == defaultCommand) {
                    defaultCommand = null;
                }

                /*if (owner != null) {
                    owner.updateCommandSet();
                }*/
                break;
            }
        }
    }
    
    final void setOwner(BQScreen ow){
        owner=ow;
    }
    
    final BQScreen getOwner() {
        return owner;
    }
    

    abstract int callPreferredWidth(int height);


    abstract int callPreferredHeight(int width);


    abstract int callMinimumWidth();


    abstract int callMinimumHeight();
    
    public void setShell(Item it){
    	shell=it;
    }
    
    public Item getShell(){
    	return shell;
    }
    
    int getCommandCount() {
        return numCommands;
    }
    
    BQItemCommandListener getItemCommandListener() {
        return commandListener;
    }
    
    public void reBounds(){
        int w=this.getWidth();
        int h=this.getHeight();
        int w1=label.getPreferredSize().width;
        if(w1>w/2){
        	w1=w/2;
        }
        label.setBounds(0,0,w1,h);
        if(instance!=null){
            instance.setBounds(w1+5,0,w-w1-5,h);
        }
    }
    
}

⌨️ 快捷键说明

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