Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: javax/microedition/lcdui/Screen.java


1   /*
2    *  MicroEmulator
3    *  Copyright (C) 2001 Bartek Teodorczyk <barteo@it.pl>
4    *
5    *  This library is free software; you can redistribute it and/or
6    *  modify it under the terms of the GNU Lesser General Public
7    *  License as published by the Free Software Foundation; either
8    *  version 2.1 of the License, or (at your option) any later version.
9    *
10   *  This library is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   *  Lesser General Public License for more details.
14   *
15   *  You should have received a copy of the GNU Lesser General Public
16   *  License along with this library; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19   
20  package javax.microedition.lcdui;
21  
22  import com.barteo.emulator.device.DeviceFactory;
23  
24  
25  public abstract class Screen extends Displayable
26  {
27  
28    StringComponent title;
29    Ticker ticker;
30    int viewPortY;
31    int viewPortHeight;
32  
33  
34    Screen(String title)
35    {
36      this.title = new StringComponent(title);
37      viewPortY = 0;
38      viewPortHeight = DeviceFactory.getDevice().getDeviceDisplay().getHeight() - this.title.getHeight() - 1;
39    }
40  
41  
42    public Ticker getTicker()
43    {
44      return ticker;
45    }
46  
47  
48    public String getTitle()
49    {
50      return title.getText();
51    }
52  
53  
54    public void setTitle(String s)
55    {
56      title.setText(s);
57    }
58  
59  
60    public void setTicker(Ticker ticker)
61    {
62      if (this.ticker != null) {
63        viewPortHeight += this.ticker.getHeight();
64      }
65      this.ticker = ticker;
66      if (this.ticker != null) {
67        viewPortHeight -= this.ticker.getHeight();
68      }
69      repaint();
70    }
71  
72  
73    abstract int traverse(int gameKeyCode, int top, int bottom);
74  
75  
76    void keyPressed(int keyCode)
77    {
78      int gameKeyCode = Display.getGameAction(keyCode);
79  
80      if (gameKeyCode == Canvas.UP || gameKeyCode == Canvas.DOWN) {
81        viewPortY += traverse(gameKeyCode, viewPortY, viewPortY + viewPortHeight);
82        repaint();
83      }
84    }
85  
86  
87    void hideNotify()
88    {
89      super.hideNotify();
90    }
91  
92  
93    void keyRepeated(int keyCode)
94    {
95      keyPressed(keyCode);
96    }
97  
98  
99    final void paint(Graphics g)
100   {
101     int contentHeight = 0;
102     int translatedY;
103 
104     if (viewPortY == 0) {
105       currentDisplay.setScrollUp(false);
106     } else {
107       currentDisplay.setScrollUp(true);
108     }
109 
110     g.setGrayScale(255);
111     g.fillRect(0, 0, 
112         DeviceFactory.getDevice().getDeviceDisplay().getWidth(), 
113         DeviceFactory.getDevice().getDeviceDisplay().getHeight());
114 
115     g.setGrayScale(0);
116 
117     if (ticker != null) {
118       contentHeight += ticker.paintContent(g);
119     }
120 
121     g.translate(0, contentHeight);
122     translatedY = contentHeight;
123 
124     contentHeight += title.paint(g);
125     g.drawLine(0, title.getHeight(), 
126         DeviceFactory.getDevice().getDeviceDisplay().getWidth(), title.getHeight());
127     contentHeight += 1;
128 
129     g.translate(0, contentHeight - translatedY);
130     translatedY = contentHeight;
131 
132     g.setClip(0, 0, 
133         DeviceFactory.getDevice().getDeviceDisplay().getWidth(), 
134         DeviceFactory.getDevice().getDeviceDisplay().getHeight() - contentHeight);
135     g.translate(0, -viewPortY);
136     contentHeight += paintContent(g);
137     g.translate(0, viewPortY);
138 
139     if (contentHeight - viewPortY > DeviceFactory.getDevice().getDeviceDisplay().getHeight()) {
140       currentDisplay.setScrollDown(true);
141     } else {
142       currentDisplay.setScrollDown(false);
143     }
144     g.translate(0, -translatedY);
145   }
146 
147 
148   abstract int paintContent(Graphics g);
149 
150 
151   void repaint()
152   {
153     super.repaint();
154   }
155 
156 
157   void showNotify()
158   {
159     viewPortY = 0;
160     
161     super.showNotify();
162   }
163 
164 }