📄 fontutil.java
字号:
/********************************************************************
* 项目名称 :<b>j2me学习 J2me Wap Explorer</b> <br/>
*
* Copyright 2005-2006 Wuhua. All rights reserved </br>
*
* 本程序只用于学习目的,不能用于商业目的。如有需要请联系作者
********************************************************************/
package org.wuhua.wap.util;
import java.util.Vector;
import javax.microedition.lcdui.Font;
import org.wuhua.wap.log.Logger;
/**
* <b>类名:FontUtil.java</b> </br>
* 编写日期: 2006-12-25 <br/>
* 程序功能描述: <br/>
* Demo: <br/>
* Bug: <br/>
*
* 程序变更日期 :<br/>
* 变更作者 :<br/>
* 变更说明 :<br/>
*
* @author wuhua </br> <a href="mailto:rrq12345@163.com">rrq12345@163.com</a>
*/
public final class FontUtil {
private static Logger logger = Logger.getLogger("FontUtil");
public static int getWidth(Font font, String _arg) {
return font.stringWidth(_arg);
}
/** 判断整个字符串的长度是否超过了手机屏幕的宽度 * */
public static boolean isLargeWidth(Font font, int _width, String _arg) {
return font.stringWidth(_arg) > _width ? true : false;
}
/** 返回整个字符串占用的行数 * */
public static int siptRow(Font font, int _width, String _arg) {
return font.stringWidth(_arg) / _width + 1;
}
/** 返回字符串占用的高度 单行* */
public static int getSumHeightOnly(Font font, int _width, String _arg) {
if (_width == 0)
return 0;
int row = siptRow(font, _width, _arg);
return (row) * font.getHeight() + (row - 1) * 2;
}
/** 返回字符串占用的高度 表示有很多换行时候* */
public static int getSumHeightMany(Font font, int _width, String _arg) {
if (_width == 0)
return 0;
int row = siptRow(font, _width, _arg);
return (row) * font.getHeight() + (row) * 2;
}
/**
* 分割字体,让菜单显示的更漂亮,让其他界面显示的更完美.</br> 主要用于菜单的显示,数据的显示等
*
*/
public static String[] splitOnlyStringToRowString(Font font, String label,
int width) {
Vector vector = new Vector();
String[] split = null;
StringBuffer sb = new StringBuffer();
if (font.stringWidth(label) < width) {
vector.addElement(label);
split = new String[vector.size()];
split = new String[vector.size()];
vector.copyInto(split);
vector.removeAllElements();
vector = null;
return split;
} else {
char[] ch = label.toCharArray();
int w = 0;
for (int i = 0; i < ch.length; i++) {
w = w + font.charWidth(ch[i]);
sb.append(ch[i]);
if (w >= width - 12) {
vector.addElement(sb.toString());
sb = null;
sb = new StringBuffer();
w = 0;
}
}
}
vector.addElement(sb.toString());
split = new String[vector.size()];
vector.copyInto(split);
vector.removeAllElements();
vector = null;
return split;
}
/**
* 分割字体,让菜单显示的更漂亮,让其他界面显示的更完美.</br>
* 主要用于菜单的显示,数据的显示等
*
*/
public static String divide(Font font, String label, int width){
if(font.stringWidth(label) < width){
return label;
}
char[] ch = label.toCharArray();
StringBuffer sb = new StringBuffer();
int w = 0;
for(int i =0; i < ch.length; i++){
w = w + font.charWidth(ch[i]);
sb.append(ch[i]);
if(w>=width){
return sb.toString();
}
}
return sb.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -