X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Fxdf-swing%2Fsrc%2Fmain%2Fjava%2Fjp%2Fac%2Faiit%2Fxdf%2Fcomponent%2Fswing%2Ftypeconvert%2FFontConverter.java;fp=src%2Fxdf-swing%2Fsrc%2Fmain%2Fjava%2Fjp%2Fac%2Faiit%2Fxdf%2Fcomponent%2Fswing%2Ftypeconvert%2FFontConverter.java;h=da642b1d86ece0c4e7a2e1967ace5f780e3ee453;hb=166b2cd59861220a2953ec6b47c1f664beeb107b;hp=0000000000000000000000000000000000000000;hpb=1d99ad9ebda309edc105ef6c634ec145b6d2314e;p=xdf%2Fgit-repos.git diff --git a/src/xdf-swing/src/main/java/jp/ac/aiit/xdf/component/swing/typeconvert/FontConverter.java b/src/xdf-swing/src/main/java/jp/ac/aiit/xdf/component/swing/typeconvert/FontConverter.java new file mode 100644 index 0000000..da642b1 --- /dev/null +++ b/src/xdf-swing/src/main/java/jp/ac/aiit/xdf/component/swing/typeconvert/FontConverter.java @@ -0,0 +1,52 @@ +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 { + 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; + } + } +}