- /*
- * Copyright 1999,2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package peaklau.eaglefund;
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.CommandListener;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.lcdui.Font;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
- /**
- * Show a title on the top of the screen<br>
- *
- * <br>
- * @author peaklau <br>
- * email:<A HREF="mailto:peaklau@hotmail.com">peaklau@hotmail.com</A> <br>
- * <a href="http://www.peaklau.com/fund/english/">HomePage</a>
- * @version $Revision: 1.1 $ $Date: 2007/05/09 16:07:04 $
- */
- public class TitleScreen extends BaseCanvas implements CommandListener {
- private Font defaultFont=Font.getDefaultFont();
- protected int FONT_HEIGHT=defaultFont.getHeight();
- protected int Line_HIGHT=FONT_HEIGHT+1;
- protected int width=0;
- protected int height=0;
- private String title=" ";
- private Command back=new Command("返回",Command.BACK,1);
- private Command refresh=new Command("刷新",Command.OK,1);
- private String backDisplayable=null;
- private Image logo=null;
- public TitleScreen(String title,String backDisplayable,INavigator navigator){
- super(navigator);
- if(title!=null){
- this.title=title;
- }
- if(backDisplayable!=null){
- this.backDisplayable=backDisplayable;
- }
- try{
- logo=Image.createImage("/logo.png");
- }catch(Exception e){
- e.printStackTrace();
- }
- this.navigator=navigator;
- addCommand(back);
- addCommand(refresh);
- setCommandListener(this);
- width=getWidth();
- height=getHeight();
- }
- public void setTitle(String title){
- this.title=title;
- }
- private String status=null;
- public void setStatus(String status){
- this.status=status;
- repaint();
- }
- protected void paint(Graphics g){
- g.setColor(0x00FFFFFF);
- g.fillRect(0,0,width,height);
- g.setColor(0xff6282B6);
- g.fillRect(0,0,width,Line_HIGHT);
- //title bar
- g.drawImage(logo,0,0,Graphics.LEFT|Graphics.TOP);
- g.setColor(0x00ff7F7F);
- int titleX=(width-logo.getWidth()-defaultFont.stringWidth(title))/2+logo.getWidth();
- g.drawString(title,titleX,0,Graphics.LEFT|Graphics.TOP);
- //status bar
- g.setColor(0x00D4D0C8);
- g.setStrokeStyle(Graphics.DOTTED);
- g.drawLine(0,height-Line_HIGHT-1,width,height-Line_HIGHT-1);
- g.setColor(0x00000000);
- if((status==null)||(status.trim().length()==0)){
- status="";
- }
- g.drawString(status,0,height-Line_HIGHT,Graphics.LEFT|Graphics.TOP);
- }
- public void commandAction(Command command, Displayable displayable) {
- if(command == back){
- navigator.getDisplay().setCurrent(navigator.getDisplayable(backDisplayable));
- }else if(command == refresh){
- refresh();
- }
- }
- protected void keyPressed(int keyCode) {
- super.keyPressed(keyCode);
- switch (getGameAction(keyCode)) {
- default:
- break;
- }
- }
- }