取得系统字体
来源:互联网 发布:算法谜题 pdf 编辑:程序博客网 时间:2024/06/02 19:44
工具类如下:
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
public class FontUtil {
private static String[] FONT_NAMES;
public static final String COMMA = ",";
/**
* array of font sizes
*/
protected static final String[] FONT_SIZES = { "8", "9", "10", "11", "12", "14", "16", "18", "20", "22", "24", "26", "28", "36", "48", "72" };
/**
* @return String array of font names as String objects for the default display.
*/
static public String[] getFontNames() {
if (FONT_NAMES != null)
return FONT_NAMES;
// add the names into a set to get a set of unique names
Set<String> stringItems = new HashSet<String>();
FontData[] fontDatas = getDisplay().getFontList(null, true);
for (int i = 0; i < fontDatas.length; i++) {
if (fontDatas[i].getName() != null) {
stringItems.add(fontDatas[i].getName());
}
}
// add strings into the array
String strings[] = new String[stringItems.size()];
int i = 0;
for (String item : stringItems) {
strings[i++] = item;
}
// sort the array
Arrays.sort(strings);
return FONT_NAMES = strings;
}
/**
* @return - array of fomt sizes
*/
public static final String[] getFontSizes() {
return FONT_SIZES;
}
public static Display getDisplay() {
Display display = Display.getCurrent();
if (display == null && PlatformUI.isWorkbenchRunning()) {
display = PlatformUI.getWorkbench().getDisplay();
}
return display != null ? display : Display.getDefault();
}
public static int getIntFontStyle(String style) {
if ("NORMAL".equals(style)) {
return 0;
} else if ("BOLD".equals(style)) {
return 1;
} else if ("ITALIC".equals(style)) {
return 2;
} else if ("BOLD|ITALIC".equals(style)) {
return 3;
}
return 4;
}
public static String getStringFontStyle(int style) {
if (style == 0) {
return "NORMAL";
} else if (style == 1) {
return "BOLD";
} else if (style == 2) {
return "ITALIC";
} else if (style == 3) {
return "BOLD|ITALIC";
}
return "";
}
// public static String getFontStr(FontData fontData) {
// return StringUtil.format(new Object[] { fontData.getName(), fontData.getHeight(), getStringFontStyle(fontData.getStyle()) });
// }
}
- 取得系统字体
- C#中如何取得系统字体
- C#中如何取得系统字体
- C#中如何取得系统字体
- WPF中取得系统字体列表
- C#中如何取得系统字体
- 系统字体
- 如何取得系统错误信息!
- 取得系统当前时间
- java系统属性取得
- java系统属性取得
- 取得系统当前时间
- C 取得系统时间!
- 取得系统硬件信息
- 取得系统当前时间
- 取得系统图标
- iOS 取得系统版本号
- C++取得系统时间
- http://www.cnblogs.com/yungboy/archive/2010/06/08/1754273.html
- Eclipse快捷键总结
- http://www.cnblogs.com/yungboy/archive/2010/06/09/1754407.html
- C# ASP.NET 最常用的通用权限的3个方法例子展示(每个功能一行代码实现)
- ubuntu 10.04 codeblocks10.05安装问题 安装后不能启动
- 取得系统字体
- http://www.cnblogs.com/yungboy/archive/2010/06/23/1762994.html
- line_iterator
- http://www.cnblogs.com/yungboy/archive/2010/06/24/1763000.html
- ubuntu下ADT编译之后的安装
- 每日学习笔记(6)
- Android一个listview分页实例
- http://www.cnblogs.com/yungboy/archive/2010/06/25/1765280.html
- DSP