本文整理汇总了Java中javax.microedition.lcdui.Font类的典型用法代码示例。如果您正苦于以下问题:Java Font类的具体用法?Java Font怎么用?Java Font使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Font类属于javax.microedition.lcdui包,在下文中一共展示了Font类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawTopRow
import javax.microedition.lcdui.Font; //导入依赖的package包/类
/**
* Draws the top row.
*
* @param g Graphics context.
* @param rect Rectangle to draw in.
* @param useWholeArea if true then top row will occupy the whole rect.
* @return Height used for top row.
*/
protected int drawTopRow(Graphics g, int[] rect, boolean useWholeArea){
if (Log.TEST) Log.note("[ListItem#drawTopRow]-->");
int x = rect[0];
int y = rect[1];
int width = rect[2];
int height = rect[3];
Font font = null;
if((itemType & TYPE_ONE_ROW) > 0){
font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE);
} else if ((itemType & TYPE_TWO_ROW) > 0){
font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
}
if(!useWholeArea){
height = font.getHeight() + V_PAD * 2;
}
// Draw the text to the middle of the top row
Util.drawStringCenteredAndTruncated(g, text1, font, x, y + V_PAD, width, height, Graphics.TOP | Graphics.LEFT );
return height;
}
示例2: paintTextRow
import javax.microedition.lcdui.Font; //导入依赖的package包/类
/**
* Renders a text row to Canvas.
*/
private int paintTextRow(Graphics g, String text, int x, int y) {
int w = getWidth();
Font font = g.getFont();
for (int j = 0; j < text.length(); j++) {
char c = text.charAt(j);
int cw = font.charWidth(c);
if (x + cw > w) {
x = 0;
y += font.getHeight();
}
g.drawChar(c, x, y, Graphics.TOP | Graphics.LEFT);
x += cw;
}
if (touch || nHD_portrait) {
y += (2 * font.getHeight());
} else {
y += font.getHeight();
}
return y;
}
示例3: getFont
import javax.microedition.lcdui.Font; //导入依赖的package包/类
public static Font getFont(boolean isBold, int size) {
switch (size) {
case smallSize:
return (isBold || Config.getInstance().forceBoldFont)
? getSmallBoldFont()
: getSmallFont();
case middleSize:
return (isBold || Config.getInstance().forceBoldFont)
? getMiddleBoldFont()
: getMiddleFont();
case bigSize:
return (isBold || Config.getInstance().forceBoldFont)
? getBigBoldFont()
: getBigFont();
}
return getSmallFont();
}
示例4: setupFields
import javax.microedition.lcdui.Font; //导入依赖的package包/类
private void setupFields() {
imageItem = new ImageItem("Category: " + note.getCategory().toString(), note.getCategory().getIcon(), 0, "ctgimg");
titleItem = new StringItem("Title", null);
titleItem.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE));
contentItem = new StringItem("Content", null);
dateItem = new StringItem("Date", null);
priorityItem = new StringItem("Priority", null);
this.append(imageItem);
this.append(titleItem);
this.append(contentItem);
this.append(dateItem);
this.append(priorityItem);
}
示例5: reset
import javax.microedition.lcdui.Font; //导入依赖的package包/类
public void reset(Canvas canvas) {
this.canvas = canvas;
Rect tmp = this.canvas.getClipBounds();
AndroidDeviceDisplay deviceDisplay = (AndroidDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay();
width = deviceDisplay.getFullWidth();
height = deviceDisplay.getFullHeight();
this.canvas.setMatrix(identityMatrix);
// setMatrix changes the clipping too
this.canvas.clipRect(tmp, Region.Op.REPLACE);
clip = this.canvas.getClipBounds();
setFont(Font.getDefaultFont());
}
示例6: paint
import javax.microedition.lcdui.Font; //导入依赖的package包/类
protected void paint(Graphics g, int w, int h)
{
if(gObj == null)
{
gObj = g;
}
else if(width < 0)
{
width = w;
}
else if(height < 0)
{
height = h;
}
//g.drawString("I am a " + "SimpleDateField. Hear me ROAR!", w/2, h/2, 0);
//g.drawString("MM/DD/YYYY", w/3 + 5, h/3 + 30, Graphics.TOP|Graphics.RIGHT);
dateRectX = w/3;
dateRectY = h/3;
if(!validDate())
{
invalidDate();
}
drawDateBox(dateRectX - 50, dateRectY + 2);
int adjMonth = currMonth + 1;
g.drawString("MM/DD/YYYY", dateRectX + 15, dateRectY - 25, Graphics.TOP|Graphics.RIGHT);
//Fit the format for drawing dates
String adjMonthStr = (new Integer(adjMonth)).toString();
if(adjMonth < 10 && adjMonth > 0)
adjMonthStr = "0" + adjMonthStr;
String dayStr = (new Integer(currDay)).toString();
if(currDay < 10 && currDay > 0)
dayStr = "0" + dayStr;
g.drawString(adjMonthStr + "/" + dayStr + "/" + currYear, dateRectX, dateRectY, Graphics.TOP|Graphics.RIGHT);
g.drawString(NO_DATE_STR, dateRectX + (Font.getDefaultFont()).stringWidth(NO_DATE_STR) + 10 , dateRectY, Graphics.TOP|Graphics.RIGHT);
}
示例7: RatingItem
import javax.microedition.lcdui.Font; //导入依赖的package包/类
/**
* Constructor.
*
* @param imageProvider For image retrieval.
* @param width Width of the item.
* @param rating Initial rating.
* @throws FavouriteArtistsException
*/
protected RatingItem(ImageProvider imageProvider, int width, short rating) throws FavouriteArtistsException {
super(null);
this.width = width;
this.rating = rating;
// Create images
starImgFilled = imageProvider.getImage(BIG_STAR_FILLED_IMG_FILE);
starImgEmpty = imageProvider.getImage(BIG_STAR_EMPTY_IMG_FILE);
// Get font
font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
// Calculate height
height += V_PAD * 2;
height += font.getHeight();
height += GESTURE_ZONE_HEIGHT;
// Create GIZ for each star icon
zones = new GestureInteractiveZone[STAR_COUNT];
int starX = 0;
int starY = font.getHeight() + V_PAD;
for(int i = 0; i < STAR_COUNT; i++){
GestureInteractiveZone zone =
new GestureInteractiveZone(GestureInteractiveZone.GESTURE_TAP);
// Set dimensions of the GIZ in relation to the Displayable
zone.setRectangle(starX, starY, GESTURE_ZONE_WIDTH, GESTURE_ZONE_HEIGHT);
// Register the GIZ
if(GestureRegistrationManager.register(this, zone) != true){
throw new FavouriteArtistsException("GestureRegistrationManager.register() failed!");
}
// Add a listener for gesture events.
GestureRegistrationManager.setListener(this, this);
zones[i] = zone;
starX += starImgFilled.getWidth() + H_PAD;
}
}
示例8: drawContents
import javax.microedition.lcdui.Font; //导入依赖的package包/类
/**
* Draw item contents.
*
* @param g Graphics context
* @param x X-coordinate.
* @param y Y-coordinate.
* @param width Width of the drawable area.
* @param height Height of the drawable area.
*/
protected void drawContents(Graphics g, int x, int y, int width, int height){
if (Log.TEST) Log.note("[GridItem#drawContents]-->");
// Divide item vertically to three parts: icon+name, rating and comment
int topRowHeight = height / 3;
int middleRowY = y + topRowHeight;
int middleRowHeight = topRowHeight;
int bottomRowY = middleRowY + middleRowHeight;
int bottomRowHeight = y + height - bottomRowY;
// Draw icon to the top left area
Util.drawImageCentered(g, icon, x, y, ICON_MAX_W, ICON_MAX_H);
// Draw artist name next to icon
Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
Util.drawStringCenteredAndTruncated(g, favData.getName(), font, x + ICON_MAX_H + ICON_TEXT_MARGIN, y,
width - ICON_MAX_H - ICON_TEXT_MARGIN, topRowHeight,
Graphics.TOP | Graphics.LEFT );
// Draw rating in the middle part
int starImgX = x + STAR_IMG_H_PAD;
for(int i = 1; i <= favData.getRating(); i++) {
Util.drawImageCentered(g, starImg, starImgX, middleRowY, starImg.getWidth()+ STAR_IMG_H_PAD * 2, middleRowHeight);
starImgX += STAR_IMG_H_PAD + starImg.getWidth();
}
// Draw comment in the bottom part
font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
Util.drawStringCenteredAndTruncated(g, favData.getComment(), font, x, bottomRowY,
width, bottomRowHeight,
Graphics.TOP | Graphics.LEFT );
}
示例9: truncateText
import javax.microedition.lcdui.Font; //导入依赖的package包/类
/**
* Returns the given text truncated to fit the specified width.
* If text needs to be truncated then three dots are appended to the end.
*
* @param original the original text.
* @param width the width in pixels.
* @param font the font used in drawing the text.
* @return the truncated text or the original if no truncation is needed.
*
* @throws NullPointerException if <code>text</code> or <code>font</code> is <code>null</code>.
*/
public static final String truncateText(String original, int width, Font font) {
int textWidth = font.stringWidth(original);
if (textWidth > width) {
// Text needs to be truncated.
final int indicatorWidth = font.stringWidth(TRUNCATION_INDICATOR);
final int truncateToWidth = width - indicatorWidth;
if (indicatorWidth >= truncateToWidth) {
// Unlikely situation normally but there isn't enough space
// for even the indicator.
return "";
}
int len = 0;
// Find out how many chars can be added before exceeding the reserved width:
while (font.substringWidth(original, 0, ++len) <= truncateToWidth) {
}
len--;
StringBuffer sb = new StringBuffer(len + TRUNCATION_INDICATOR.length());
sb.append(original.substring(0, len));
sb.append(TRUNCATION_INDICATOR);
return sb.toString();
} else {
return original;
}
}
示例10: drawBottomRow
import javax.microedition.lcdui.Font; //导入依赖的package包/类
/**
* Draws the bottom row.
*
* @param g Graphics context.
* @param rect Rectangle to draw in.
*/
protected void drawBottomRow(Graphics g, int[] rect){
if (Log.TEST) Log.note("[ListItem#drawBottomRow]-->");
int x = rect[0];
int y = rect[1];
int width = rect[2];
int height = rect[3];
Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
height = font.getHeight() + V_PAD * 2;
// Draw the text to the middle of the bottom row
Util.drawStringCenteredAndTruncated(g, text2, font, x, y + V_PAD, width, height, Graphics.TOP | Graphics.LEFT );
}
示例11: CanvasTextBox
import javax.microedition.lcdui.Font; //导入依赖的package包/类
public CanvasTextBox(Canvas parent, String label, int type, int textLimit,
boolean multiline) {
super(1, 1);
this.setParent(parent);
this.label = label;
this.textLimit = textLimit;
this.multiline = multiline;
this.labelFont = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN,
Font.SIZE_LARGE);
this.initializeTextEditor(parent, type);
this.createStates();
this.setAutomaticSize();
}
示例12: TextItem
import javax.microedition.lcdui.Font; //导入依赖的package包/类
/**
* Create a TextItem with the specified font.
*
* @param text Item text
* @param preferredWidth Preferred width
* @param font Font to use
*/
public TextItem(String text, int preferredWidth, Font font, Form form) {
super(form, preferredWidth, null);
this.text = text;
if (font != null) {
this.font = font;
}
textLines = getTextLines();
this.height = getPrefContentHeight(width);
}
示例13: initContent
import javax.microedition.lcdui.Font; //导入依赖的package包/类
/**
* Initialize the graphic elements needed for this item.
*/
protected void initContent(int firstLineWidth, int availWidth, int availHeight){
if (this.font == null)
{
this.font = Font.getDefaultFont();
this.fontColor = 0x000000;
}
contentHeight = font.getHeight() + this.linePadding;
contentWidth = availWidth;
}
示例14: getFont
import javax.microedition.lcdui.Font; //导入依赖的package包/类
private static Font getFont(String face, String style, String size) {
int meFace = 0;
if (face.equalsIgnoreCase("system")) {
meFace |= Font.FACE_SYSTEM;
} else if (face.equalsIgnoreCase("monospace")) {
meFace |= Font.FACE_MONOSPACE;
} else if (face.equalsIgnoreCase("proportional")) {
meFace |= Font.FACE_PROPORTIONAL;
}
int meStyle = 0;
String testStyle = style.toLowerCase();
if (testStyle.indexOf("plain") != -1) {
meStyle |= Font.STYLE_PLAIN;
}
if (testStyle.indexOf("bold") != -1) {
meStyle |= Font.STYLE_BOLD;
}
if (testStyle.indexOf("italic") != -1) {
meStyle |= Font.STYLE_ITALIC;
}
if (testStyle.indexOf("underlined") != -1) {
meStyle |= Font.STYLE_UNDERLINED;
}
int meSize = 0;
if (size.equalsIgnoreCase("small")) {
meSize |= Font.SIZE_SMALL;
} else if (size.equalsIgnoreCase("medium")) {
meSize |= Font.SIZE_MEDIUM;
} else if (size.equalsIgnoreCase("large")) {
meSize |= Font.SIZE_LARGE;
}
return Font.getFont(meFace, meStyle, meSize);
}
示例15: setFont
import javax.microedition.lcdui.Font; //导入依赖的package包/类
public void setFont(String face, String style, String size, org.microemu.device.impl.Font font) {
int key = 0;
if (face.equalsIgnoreCase("system")) {
key |= Font.FACE_SYSTEM;
} else if (face.equalsIgnoreCase("monospace")) {
key |= Font.FACE_MONOSPACE;
} else if (face.equalsIgnoreCase("proportional")) {
key |= Font.FACE_PROPORTIONAL;
}
String testStyle = style.toLowerCase();
if (testStyle.indexOf("plain") != -1) {
key |= Font.STYLE_PLAIN;
}
if (testStyle.indexOf("bold") != -1) {
key |= Font.STYLE_BOLD;
}
if (testStyle.indexOf("italic") != -1) {
key |= Font.STYLE_ITALIC;
}
if (testStyle.indexOf("underlined") != -1) {
key |= Font.STYLE_UNDERLINED;
}
if (size.equalsIgnoreCase("small")) {
key |= Font.SIZE_SMALL;
} else if (size.equalsIgnoreCase("medium")) {
key |= Font.SIZE_MEDIUM;
} else if (size.equalsIgnoreCase("large")) {
key |= Font.SIZE_LARGE;
}
fonts.put(new Integer(key), font);
}