01: package org.swingml.component;
02:
03: import java.awt.*;
04:
05: import org.swingml.*;
06:
07: public class FontFactory {
08:
09: static String encodeStyle(Font aFont) {
10: String style = "PLAIN";
11: if (aFont.isBold() && aFont.isItalic()) {
12: style = "BOLDITALIC";
13: } else if (aFont.isBold()) {
14: style = "BOLD";
15: } else if (aFont.isItalic()) {
16: style = "ITALIC";
17: }
18: return style;
19: }
20:
21: public static Font getFontForModel(SwingMLModel model,
22: Font defaultFont) {
23: String fontFamilyName;
24: String fontStyle;
25: String fontSize;
26:
27: if (defaultFont == null) {
28: defaultFont = Font.decode("dialog");
29: }
30:
31: if (model.getFontName() == null) {
32: fontFamilyName = defaultFont.getFamily();
33: } else {
34: fontFamilyName = model.getFontName();
35: }
36:
37: if (model.getFontStyle() == null) {
38: fontStyle = encodeStyle(defaultFont);
39: } else {
40: fontStyle = model.getFontStyle();
41: }
42:
43: if (model.getFontSize() == null) {
44: fontSize = Integer.toString(defaultFont.getSize());
45: } else {
46: fontSize = model.getFontSize();
47: }
48:
49: return Font.decode(fontFamilyName + "-" + fontStyle + "-"
50: + fontSize);
51: }
52: }
|