?? menulist.java
字號(hào):
/*
* Created on 2005-02-28
*
* Copyright (c) 2005 nanoGames. All Rights Reserved.
*
*/
//package com.nano.KangooJumper;
import javax.microedition.lcdui.*;
/**
* @author diamentos
* MenuList
*/
public class MenuList {
// blank space between lines
private final static int SPACE_Y = 2;
private final static int DEFAULT_BAR_COLOR = (100 << 16) | (140 << 8) | (164);
//
private FontWriter m_Font;
private FontWriter m_FontDisabled;
//
private String[] m_Lines;
// marks disabled lines. disabled lines are crossed with a red bar.
private boolean[] m_Disabled;
// selected line num (if any). selected line is drawed on bar.
private int m_SelectedLine;
private int m_BarColor;
private int oldKerning;
//
// rendering rectangle
//
private int m_Left;
private int m_Top;
private int m_Width;
private int m_Height;
public int barY;
public int barX;
public int nKerning;
public boolean bDrawRectangle;
public Image iBackImage = null;
// how many lines fit in visible rect
private int m_VisibleLines;
//
// some lookups for speed purposes
//
private int[] m_LineWidth; // line width in pixels
private int[] m_LineX; //
//
//
//
public MenuList (FontWriter font,
FontWriter fontDisabled,
String[] strTab,
int x,
int y,
int width,
int height,
int kerning)
{
m_Font = font;
m_FontDisabled = fontDisabled;
m_Lines = strTab;
m_Left = x;
m_Top = y;
m_Width = width;
m_Height = height;
m_VisibleLines = height / (font.getHeight() + SPACE_Y) - 1;
// initialy no lines are disabled and no line is selected
m_Disabled = new boolean[m_Lines.length];
m_SelectedLine = -1;
// no background
bDrawRectangle = false;
// calculate lookups
m_LineWidth = new int[m_Lines.length];
m_LineX = new int[m_Lines.length];
int center = x + width / 2;
oldKerning = m_Font.kerning;
m_Font.kerning = kerning;
for (int lp = 0; lp < m_Lines.length; lp++)
{
m_LineWidth[lp] = m_Font.strLen (m_Lines[lp]);
m_LineX[lp] = center - m_LineWidth[lp] / 2;
}
m_Font.kerning = oldKerning;
m_BarColor = DEFAULT_BAR_COLOR;
}
//
//
//
public boolean canScrollUp ()
{
if (m_SelectedLine > m_VisibleLines)
return true;
return false;
}
//
//
//
public boolean canScrollDown ()
{
int firstVisible = m_SelectedLine - m_VisibleLines;
int lastVisible = firstVisible + m_VisibleLines;
// if (lastVisible < m_Lines.length - 1)
// return true;
return false;
}
//
//
//
public void paint (Graphics g)
{
int firstVisible = 0;
int lastVisible = m_VisibleLines;
int fontHeight = m_Font.getHeight ();
// center the menu on rectangle
int y = m_Top + (m_Height >> 1) - ((m_Lines.length * (fontHeight + SPACE_Y)) >> 1);
if (m_SelectedLine > m_VisibleLines)
{
firstVisible = m_SelectedLine - m_VisibleLines;
lastVisible = firstVisible + m_VisibleLines;
}
if (lastVisible >= m_Lines.length)
lastVisible = m_Lines.length - 1;
g.setClip (m_Left, m_Top, m_Width, m_Height);
if (bDrawRectangle)
{
if (iBackImage != null)
{
g.drawImage(iBackImage, 0, 0, Config.ANCHOR);
g.drawRect(m_Left, m_Top, m_Width - 1, m_Height - 1);
}
else
{
g.setColor(Config.FRAME_BACKGROUND);
g.fillRoundRect(m_Left, m_Top, m_Width, m_Height, 2, 2);
g.setColor(Config.FRAME_BORDER);
g.drawRect(m_Left, m_Top, m_Width - 1, m_Height - 1);
}
}
for (int line = firstVisible; line <= lastVisible; line++)
{
// draw selection bar?
if (line == m_SelectedLine)
{
barY = y - 1;
barX = m_Left;
g.setColor (m_BarColor);
g.setClip (m_Left,
barY,
m_Width,
fontHeight + 3);
g.fillRoundRect (m_Left + 2,
barY,
m_Width - 4,
fontHeight + 2,
fontHeight,
fontHeight);
// reset clip
g.setClip (m_Left, m_Top, m_Width, m_Height);
}
oldKerning = m_Font.kerning;
m_Font.kerning = 1;
if (m_Disabled[line] == false)
m_Font.drawText (g,
m_Lines[line],
m_LineX[line],
y);
else
{
m_FontDisabled.drawText (g,
m_Lines[line],
m_LineX[line],
y);
}
m_Font.kerning = oldKerning;
y += fontHeight + SPACE_Y;
}
}
//
//
//
public void moveSelectionUp ()
{
// are we on the top
//if (m_SelectedLine > 0)
{
int newSelection = m_SelectedLine;
for (;;)
{
if (--newSelection < 0)
{
newSelection = m_Lines.length - 1;
//break; // all options above were disabled
}
if (m_Disabled[newSelection] == false)
{
m_SelectedLine = newSelection;
break;
}
}
}
}
//
//
//
public void moveSelectionDown ()
{
// are we on the top
//if (m_SelectedLine < m_Lines.length - 1)
{
int newSelection = m_SelectedLine;
for (;;)
{
if (++newSelection == m_Lines.length)
{
newSelection = 0;
//break; // all options
}
if (m_Disabled[newSelection] == false)
{
m_SelectedLine = newSelection;
break;
}
}
}
}
//
//
//
public void setSelectedLine (int line)
{
m_SelectedLine = line;
}
//
// returns selected line index or -1 if none is selected
//
public int getSelectedLine ()
{
return m_SelectedLine;
}
//
//
//
public void disableLine (int line)
{
m_Disabled[line] = true;
}
//
//
//
public void enableLine (int line)
{
m_Disabled[line] = false;
}
//
//
//
public void replaceLine (int index, String str)
{
if (index < m_Lines.length)
m_Lines[index] = str;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -