textsprite.java
来自「Sony Ericsson手机上的Facebook客户端全套代码」· Java 代码 · 共 290 行
JAVA
290 行
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3)
// Source File Name: TextSprite.java
package se.southend.drops.gui;
import java.util.Vector;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import se.southend.drops.scene.Sprite;
import se.southend.drops.tools.Tools;
// Referenced classes of package se.southend.drops.gui:
// TextPart, TextStyle
public class TextSprite extends Sprite
{
public TextSprite()
{
maxWidth = -1;
maxLines = -1;
truncation = 0;
pressedLinkColor = 0xffffff;
focusLinkIndex = -1;
focusedLinkPressed = false;
setFont(Font.getDefaultFont());
}
public TextSprite(String text, Font font, int color)
{
maxWidth = -1;
maxLines = -1;
truncation = 0;
pressedLinkColor = 0xffffff;
focusLinkIndex = -1;
focusedLinkPressed = false;
setText(text, font, color);
}
public String getText()
{
return text;
}
public void setText(String text, Font font, int color)
{
setColor(color);
setText(text);
setFont(font);
}
public void setText(String text)
{
if(text != null && text.equals(this.text))
{
return;
} else
{
this.text = text;
update();
return;
}
}
public void setTruncation(int truncation)
{
this.truncation = truncation;
update();
}
public void setHTMLSupport(boolean handleHTML)
{
this.handleHTML = handleHTML;
update();
}
public Font getFont()
{
return font;
}
public void setFont(Font font)
{
this.font = font;
update();
}
public int getColor()
{
return color;
}
public void setColor(int color)
{
this.color = color;
update();
}
public int getWidth()
{
doUpdate();
return width;
}
public int getHeight()
{
doUpdate();
return height;
}
public void setMaxWidth(int width)
{
maxWidth = width;
update();
}
public void setMaxLines(int nbrLines)
{
maxLines = nbrLines;
update();
}
private void update()
{
needsUpdate = true;
}
private void doUpdate()
{
if(!needsUpdate)
return;
needsUpdate = false;
if(text != null && font != null)
{
text = Tools.format(text);
lines = maxWidth != -1 || handleHTML ? Tools.splitStringByWidth(text, maxWidth, font, color, truncation, handleHTML, maxLines) : null;
if(lines != null)
{
width = 0;
height = 0;
for(int i = 0; i < lines.size(); i++)
{
TextPart part = (TextPart)lines.elementAt(i);
int lineWidth = part.xPos + part.width;
if(lineWidth > width)
width = lineWidth;
int tmpHeight = part.yPos + part.style.font.getHeight();
if(tmpHeight > height)
height = tmpHeight;
}
} else
{
width = font.stringWidth(text);
height = font.getHeight();
}
} else
{
lines = null;
width = 0;
height = 0;
}
}
public void paint(Graphics graphics)
{
if(!isOnScreen())
return;
doUpdate();
if(text != null)
{
int xScr = getScreenX();
int yScr = getScreenY();
if(lines == null)
{
graphics.setColor(color);
graphics.setFont(font);
graphics.drawString(text, getScreenX(), getScreenY(), 20);
} else
{
int linkIndex = 0;
for(int i = 0; i < lines.size(); i++)
{
TextPart part = (TextPart)lines.elementAt(i);
boolean isSelectedLink = false;
if(part.link != null)
{
isSelectedLink = linkIndex == focusLinkIndex;
linkIndex++;
}
if(isSelectedLink)
{
graphics.setColor(focusedLinkPressed ? pressedLinkColor : part.style.color);
graphics.setFont(Font.getFont(part.style.font.getFace(), part.style.font.getStyle() | 0x4, part.style.font.getSize()));
} else
{
graphics.setColor(part.style.color);
graphics.setFont(part.style.font);
}
graphics.drawString(part.text, xScr + part.xPos, yScr + part.yPos, 20);
}
}
}
}
public int getLinkCount()
{
doUpdate();
if(lines == null)
return 0;
int count = 0;
for(int i = 0; i < lines.size(); i++)
{
TextPart part = (TextPart)lines.elementAt(i);
if(part.link != null)
count++;
}
return count;
}
public boolean focusLink(int index, boolean pressed)
{
if(index >= 0 && index < getLinkCount())
{
focusLinkIndex = index;
focusedLinkPressed = pressed;
update();
return true;
} else
{
return false;
}
}
public void unFocusLinks()
{
if(focusLinkIndex >= 0)
{
focusLinkIndex = -1;
update();
}
}
public void setPressedLinkColor(int color)
{
pressedLinkColor = color;
if(focusLinkIndex >= 0)
update();
}
public String getLink(int index)
{
int linkIndex = 0;
for(int i = 0; i < lines.size(); i++)
{
TextPart part = (TextPart)lines.elementAt(i);
if(part.link == null)
continue;
if(linkIndex == index)
return part.link;
linkIndex++;
}
return null;
}
public static final int INFINITE = -1;
public static final int TRUNCATION_NONE = 0;
public static final int TRUNCATION_END_ELLIPSIS = 1;
public static final int TRUNCATION_WORD_ELLIPSIS = 2;
private String text;
private Vector lines;
private Font font;
private int color;
private int maxWidth;
private int maxLines;
private boolean needsUpdate;
private boolean handleHTML;
private int width;
private int height;
private int truncation;
private int pressedLinkColor;
private int focusLinkIndex;
private boolean focusedLinkPressed;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?