📄 bqdisplayable.java
字号:
/*
* Created on 2005-9-20 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 javax.swing.JComponent;
import javax.microedition.lcdui.*;
import a.a.a.b.*;
import java.awt.Color;
public abstract class BQDisplayable extends JComponent{
public static final long serialVersionUID=1;
public static final int TICKER_BAR_HEIGHT=20;
public static final int TITLE_BAR_HEIGHT=20;
public static final int COMMAND_BAR_HEIGHT=20;
public static final Color BACKGROUND_COLOR=new Color(200,200,200);
public static final Color WHITE_COLOR=new Color(255,255,255);
Displayable shell;
BQCommandListener bqCommandListener;
private BQTitleBar titleBar;
private BQTickerBar tickerBar;
private BQCommandBar commandBar;
protected JComponent screenPanel;
private int screenWidth;
private int screenHeight;
private int displayHeight;
protected boolean isFullScreenMode;
protected boolean hasTicker;
protected boolean hasTitle;
private boolean isLeftMenuShow;
private boolean isRightMenuShow;
public BQDisplayable() {
super();
screenWidth=e.getInstance(null).getScreenWidth();
screenHeight=e.getInstance(null).getScreenHeight();
displayHeight=screenHeight-COMMAND_BAR_HEIGHT;
this.setLayout(null);
commandBar=new BQCommandBar(this);
tickerBar=new BQTickerBar();
titleBar=new BQTitleBar(this);
if(this instanceof BQCanvas){
screenPanel=new BQScreenCanvas();
}else if(this instanceof BQList){
screenPanel=new BQListPanel();
}else if(this instanceof BQForm){
screenPanel=new BQScreenForm(this);
}else if(this instanceof BQAlert){
screenPanel=new BQAlertPanel();
}else if(this instanceof BQTextBox){
screenPanel=new BQTextBoxPanel(null);
}
PointerEventHandler handler=new PointerEventHandler();
this.addMouseListener(handler);
this.addMouseMotionListener(handler);
//this.setFocusable(false);
reBounds();
}
public void addCommand(BQCommand cmd){
if(commandBar==null){
commandBar=new BQCommandBar(this);
}
commandBar.addCommand(cmd);
}
public int getDisplayHeight(){
return displayHeight;
}
public int getDisplayWidth(){
return screenWidth;
}
public BQTicker getTicker(){
if(tickerBar!=null){
return tickerBar.getTicker();
}
return null;
}
public String getTitle(){
if(titleBar!=null){
return titleBar.getTitle();
}
return null;
}
public void setTicker(BQTicker ticker){
if(ticker==null){
hasTicker=false;
}else{
hasTicker=true;
tickerBar.setTicker(ticker);
}
reBounds();
}
public void setTitle(String title){
if(title==null){
hasTitle=false;
}else{
hasTitle=true;
titleBar.setTitleText(title);
}
reBounds();
}
public boolean isShown(){
return this.isVisible();
}
public void removeCommand(BQCommand cmd){
commandBar.removeCommand(cmd);
}
public void setCommandListener(BQCommandListener l){
bqCommandListener=l;
}
public void setFullScreenMode(boolean mode){
isFullScreenMode=mode;
reBounds();
}
protected int getCommandCount() {
return commandBar.getCommandCount();
}
protected int appendItem(BQItem item){
if(this instanceof BQCanvas){
return -1;
}else{
return ((BQScreenForm)screenPanel).appndItem(item);
}
}
protected void deleteItem(int index){
if(this instanceof BQCanvas){
return;
}else{
((BQScreenForm)screenPanel).deleteItem(index);
}
}
protected void deleteAllItems(){
if(this instanceof BQCanvas){
return;
}else{
((BQScreenForm)screenPanel).deleteAllItems();
}
}
protected void insertItem(int index, BQItem item){
if(this instanceof BQCanvas){
return;
}else{
((BQScreenForm)screenPanel).insertItemByIndex(index, item);
}
}
protected void setItemByIndex(int index, BQItem item){
if(this instanceof BQCanvas){
return;
}else{
((BQScreenForm)screenPanel).setItemByIndex(index,item);
}
}
protected BQItem getItemByIndex(int index){
if(this instanceof BQCanvas){
return null;
}else{
return ((BQScreenForm)screenPanel).getItemByIndex(index);
}
}
protected int getFormItemCount(){
if(this instanceof BQCanvas){
return -1;
}else{
return ((BQScreenForm)screenPanel).getTotalItemCount();
}
}
public void setShell(Displayable s){
shell=s;
}
public Displayable getShell(){
return shell;
}
public JComponent getScreenPanel(){
return screenPanel;
}
public void commandAction(BQCommand cmd){
if(bqCommandListener!=null){
((CommandListener)bqCommandListener).
commandAction(cmd.getShell(),this.getShell());
}
isLeftMenuShow=false;
isRightMenuShow=false;
}
public void onKeyDown(int keyCode){
if(!isFullScreenMode){
if(keyCode==e.KEY_SOFT1){
int cnt=commandBar.getLeftSoftCmdCnt();
if(cnt>1){
if(isLeftMenuShow){
//commandAction(selectedCmdIdx,true);
//commandBar.getSelectedIndex(true);
}else{
isRightMenuShow=false;
isLeftMenuShow=true;
commandBar.pressedMenu(true);
}
}else if(cnt==1){
//commandAction(0,true);
commandBar.pressedMenu(true);
}
}else if(keyCode==e.KEY_SOFT2){
int cnt=commandBar.getRightSoftCmdCnt();
if(cnt>1){
if(isRightMenuShow){
//commandAction(selectedCmdIdx,false);
}else{
isLeftMenuShow=false;
isRightMenuShow=true;
commandBar.pressedMenu(false);
}
}else if(cnt==1){
//commandAction(0,false);
commandBar.pressedMenu(false);
}
}else if(this instanceof BQCanvas){
((Canvas)shell).onKeyDown(this,keyCode);
}
}else if(this instanceof BQCanvas){
((Canvas)shell).onKeyDown(this,keyCode);
}
}
public void onKeyUp(int keyCode){
if(!isFullScreenMode){
if(keyCode==e.KEY_SOFT1){
}else if(keyCode==e.KEY_SOFT2){
}else if(this instanceof BQCanvas){
((Canvas)shell).onKeyUp(this,keyCode);
}
}else if(this instanceof BQCanvas){
((Canvas)shell).onKeyUp(this,keyCode);
}
}
public void onMouseDown(int x, int y){
if(this instanceof BQCanvas){
if(hasTicker){
y-=TICKER_BAR_HEIGHT;
}
if(hasTitle){
y-=TITLE_BAR_HEIGHT;
}
((Canvas)shell).onMouseDown(this,x,y);
}
}
public void onMouseUp(int x, int y){
if(this instanceof BQCanvas){
if(hasTicker){
y-=TICKER_BAR_HEIGHT;
}
if(hasTitle){
y-=TITLE_BAR_HEIGHT;
}
((Canvas)shell).onMouseUp(this,x,y);
}
}
public void onMouseDrag(int x,int y){
if(this instanceof BQCanvas){
if(hasTicker){
y-=TICKER_BAR_HEIGHT;
}
if(hasTitle){
y-=TITLE_BAR_HEIGHT;
}
((Canvas)shell).onMouseDrag(this,x,y);
}
}
synchronized public void resizeScreen(){
{
screenWidth=e.getInstance(null).getScreenWidth();
screenHeight=e.getInstance(null).getScreenHeight();
if(titleBar!=null){
titleBar.resizeScreen();
}
if(tickerBar!=null){
tickerBar.resizeScreen();
}
if(screenPanel!=null&&screenPanel instanceof BQScreenCanvas){
((BQScreenCanvas)screenPanel).resizeScreen();
}
if(commandBar!=null){
commandBar.resizeScreen();
}
reBounds();
}
}
public void reBounds(){
this.removeAll();
if(isFullScreenMode){
this.add(screenPanel);
displayHeight=screenHeight;
screenPanel.setBounds(0,0,screenWidth,screenHeight);
}else{
int y=0;
if(hasTicker){
this.add(tickerBar);
tickerBar.setBounds(0,0,screenWidth,TICKER_BAR_HEIGHT);
y+=TICKER_BAR_HEIGHT;
}
if(hasTitle){
this.add(titleBar);
titleBar.setBounds(0,y,screenWidth,TITLE_BAR_HEIGHT);
y+=TITLE_BAR_HEIGHT;
}
displayHeight=screenHeight-y-COMMAND_BAR_HEIGHT;
this.add(screenPanel);
screenPanel.setBounds(0,y,screenWidth,displayHeight);
this.add(commandBar);
commandBar.setBounds(0,screenHeight-COMMAND_BAR_HEIGHT,screenWidth,COMMAND_BAR_HEIGHT);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -