1. /*
  2. * Copyright 1999,2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package peaklau.eaglefund;
  17. import javax.microedition.lcdui.Command;
  18. import javax.microedition.lcdui.CommandListener;
  19. import javax.microedition.lcdui.Displayable;
  20. import javax.microedition.lcdui.Font;
  21. import javax.microedition.lcdui.Graphics;
  22. import javax.microedition.lcdui.Image;
  23. /**
  24. * Show a title on the top of the screen<br>
  25. *
  26. * <br>
  27. * @author peaklau <br>
  28. * email:<A HREF="mailto:peaklau@hotmail.com">peaklau@hotmail.com</A> <br>
  29. * <a href="http://www.peaklau.com/fund/english/">HomePage</a>
  30. * @version $Revision: 1.1 $ $Date: 2007/05/09 16:07:04 $
  31. */
  32. public class TitleScreen extends BaseCanvas implements CommandListener {
  33. private Font defaultFont=Font.getDefaultFont();
  34. protected int FONT_HEIGHT=defaultFont.getHeight();
  35. protected int Line_HIGHT=FONT_HEIGHT+1;
  36. protected int width=0;
  37. protected int height=0;
  38. private String title=" ";
  39. private Command back=new Command("返回",Command.BACK,1);
  40. private Command refresh=new Command("刷新",Command.OK,1);
  41. private String backDisplayable=null;
  42. private Image logo=null;
  43. public TitleScreen(String title,String backDisplayable,INavigator navigator){
  44. super(navigator);
  45. if(title!=null){
  46. this.title=title;
  47. }
  48. if(backDisplayable!=null){
  49. this.backDisplayable=backDisplayable;
  50. }
  51. try{
  52. logo=Image.createImage("/logo.png");
  53. }catch(Exception e){
  54. e.printStackTrace();
  55. }
  56. this.navigator=navigator;
  57. addCommand(back);
  58. addCommand(refresh);
  59. setCommandListener(this);
  60. width=getWidth();
  61. height=getHeight();
  62. }
  63. public void setTitle(String title){
  64. this.title=title;
  65. }
  66. private String status=null;
  67. public void setStatus(String status){
  68. this.status=status;
  69. repaint();
  70. }
  71. protected void paint(Graphics g){
  72. g.setColor(0x00FFFFFF);
  73. g.fillRect(0,0,width,height);
  74. g.setColor(0xff6282B6);
  75. g.fillRect(0,0,width,Line_HIGHT);
  76. //title bar
  77. g.drawImage(logo,0,0,Graphics.LEFT|Graphics.TOP);
  78. g.setColor(0x00ff7F7F);
  79. int titleX=(width-logo.getWidth()-defaultFont.stringWidth(title))/2+logo.getWidth();
  80. g.drawString(title,titleX,0,Graphics.LEFT|Graphics.TOP);
  81. //status bar
  82. g.setColor(0x00D4D0C8);
  83. g.setStrokeStyle(Graphics.DOTTED);
  84. g.drawLine(0,height-Line_HIGHT-1,width,height-Line_HIGHT-1);
  85. g.setColor(0x00000000);
  86. if((status==null)||(status.trim().length()==0)){
  87. status="";
  88. }
  89. g.drawString(status,0,height-Line_HIGHT,Graphics.LEFT|Graphics.TOP);
  90. }
  91. public void commandAction(Command command, Displayable displayable) {
  92. if(command == back){
  93. navigator.getDisplay().setCurrent(navigator.getDisplayable(backDisplayable));
  94. }else if(command == refresh){
  95. refresh();
  96. }
  97. }
  98. protected void keyPressed(int keyCode) {
  99. super.keyPressed(keyCode);
  100. switch (getGameAction(keyCode)) {
  101. default:
  102. break;
  103. }
  104. }
  105. }