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