📄 list.java
字号:
/********************************************************************
*
* 版权说明,此程序仅供学习参考。不能用于商业
*
********************************************************************/
package org.pook.ui;
import java.util.Vector;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import org.pook.ui.core.Platform;
import org.pook.ui.util.GraphicsUtil;
/**
* <b>类名:List.java</b> </br>
* 编写日期: 2006-10-14 <br/>
* 程序功能描述: <br/>
* Demo: <br/>
* Bug: <br/>
*
* 程序变更日期 :<br/>
* 变更作者 :<br/>
* 变更说明 :<br/>
*
* @author wuhua </br> <a href="mailto:rrq12345@163.com">rrq12345@163.com</a>
*/
public class List extends Part {
Image icon;
Vector items;
int numOfEls;
int paintSize;
int space;
/** 开始索引 * */
private int startIndex;
public List(Image icon) {
super(0, 21, Platform.WIDTH, Platform.HEIGHT - 41);
this.icon = icon;
items = new Vector();
}
public void changeViewAndSize(){
if (Platform.HEIGHT - 20 > view[HEIGHT]) {
view[HEIGHT] = Platform.HEIGHT - 41;
space = font.getHeight() + 2;
paintSize = view[HEIGHT] / space;
}
}
public void append(Vector items){
if(items == null)
return;
this.items = items;
this.numOfEls = items.size();
}
public void append(String stringItem){
this.items.addElement(stringItem);
this.numOfEls = items.size();
}
public void insert(String stringItem){
this.items.insertElementAt(stringItem,0);
this.numOfEls = items.size();
}
public int getSelectIndex(){
return this.selectIndex;
}
public String getSelectString(){
//System.out.println(this.numOfEls);
return (String) this.items.elementAt(selectIndex+startIndex );
}
public void paint(Graphics g) {
changeViewAndSize();
GraphicsUtil.fillScreen(g, this.bgColor, view[X], view[Y], view[WIDTH], view[HEIGHT]);
paintStrings(g);
}
private void paintStrings(Graphics g) {
if (items.size() == 0)
return;
int size = this.paintSize > this.numOfEls? this.numOfEls:this.paintSize + startIndex;
paintSelect(g, view[Y] + space * selectIndex + 2 );
g.setColor(this.fontColor);
for(int i =startIndex,j=0; i< size; i++, j++){
String it = (String) items.elementAt(i);
if(this.selectIndex == j){
it = (String) items.elementAt(selectIndex+startIndex);
//this.select.paint(view[X], height, view[WIDTH],it.getItemHeight(),g);
}else{
}
GraphicsUtil.darwString(g,it, view[X] + 10, view[Y] + space *j + 2);
// 变化的高度
}
}
private void paintSelect(Graphics g, int height) {
g.setColor(0x909090);
g.fillRect(view[X], height, view[WIDTH], space);
}
public void onClick(int keyCode) {
keyUpAndDown(keyCode);
}
/**
* 内部实现按钮向上向下时候的动作,有具体类的keyPress调用.
*
* @param keyCode
*/
void keyUpAndDown(int keyCode) {
if(this.numOfEls == 0)
return;
switch (keyCode) {
case Platform.KEY_UP: {
selectIndex--;
break;
}
case Platform.KEY_DOWN: {
selectIndex++;
break;
}
}
changeSelectIndex();
}
/**
* 判断当前选择条是否到了底部,经过用户的选择,这些选择条会不断的变化</br> 变化的依据是当selectPosition >=
* viewPart[HEIGHT]*/
private void changeSelectIndex(){
int num = (this.paintSize < numOfEls)?paintSize:numOfEls;//取可显示的菜单项数目
if (selectIndex>num-1)
{
startIndex++;
selectIndex=(byte)(num-1);
}
if (selectIndex < 0)
{
if (startIndex>0)
{
selectIndex =0;
startIndex--;
}
else
{
startIndex = numOfEls-num;
selectIndex=num-1;
}
}
if (startIndex+ selectIndex > numOfEls -1)
{
startIndex= 0;
selectIndex = 0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -