1 package jp.ac.aiit.xdf.component.swing.typeconvert;
4 import java.util.regex.Matcher;
5 import java.util.regex.Pattern;
7 import jp.ac.aiit.xdf.core.typeconvert.TypeConverter;
10 * フォント指定文字列からjava.awt.Fontのインスタンスへの変換を行う
12 * @author Takagi Pin.Yuan
15 public class FontConverter implements TypeConverter<Font> {
16 private static final Pattern APPLIABLE_PATTERN = Pattern.compile("([^\\,]*)(\\,([1-9][0-9]*)pt)?(\\,(italic|bold|normal))?");
19 public Font apply(String target) {
20 Matcher m = APPLIABLE_PATTERN.matcher(target);
23 // System.out.println("DebugInfo:1<" + m.group(1) + "> 3<" + m.group(3) + "> 3<" + m.group(5));
24 String name = m.group(1);
25 int size = Integer.valueOf(m.group(3));
26 int style = asStyle( m.group(5) );
28 return new Font(name, style, size);
35 public boolean isAppliable(String target) {
36 return APPLIABLE_PATTERN.matcher(target).matches();
39 private int asStyle(String style) {
42 } else if( style.equals("italic") ) {
44 } else if( style.equals("bold") ) {
46 } else if( style.equals("normal") ) {