01: package net.suberic.pooka.gui.filter;
02:
03: import java.awt.*;
04:
05: /**
06: * This represents a DisplayFilter which modifies the font of the
07: * given messages.
08: */
09: public class FontDisplayFilter implements DisplayFilter {
10:
11: int fontStyle = -1;
12:
13: java.util.HashMap derivedFontMap;
14:
15: /**
16: * Creates a new FontDisplayFilter.
17: */
18: public FontDisplayFilter() {
19: }
20:
21: /**
22: * a no-op.
23: */
24: public java.util.List performFilter(java.util.List tmp) {
25: return tmp;
26: }
27:
28: /**
29: * Configures the filter from the given property.
30: */
31: public void initializeFilter(String propertyName) {
32: derivedFontMap = new java.util.HashMap();
33:
34: String fontString = net.suberic.pooka.Pooka.getProperty(
35: propertyName + ".style", "bold");
36: if (fontString.equalsIgnoreCase("bold"))
37: fontStyle = Font.BOLD;
38: else if (fontString.equalsIgnoreCase("italic"))
39: fontStyle = Font.ITALIC;
40: else if (fontString.equalsIgnoreCase("plain"))
41: fontStyle = Font.PLAIN;
42: }
43:
44: /**
45: * Applies the filter to the given component.
46: */
47: public void apply(java.awt.Component target) {
48: Font currentFont = target.getFont();
49: Font derivedFont = (Font) derivedFontMap.get(currentFont);
50: if (derivedFont != null) {
51: target.setFont(derivedFont);
52: } else {
53: derivedFont = currentFont.deriveFont(fontStyle);
54: derivedFontMap.put(currentFont, derivedFont);
55: target.setFont(derivedFont);
56: }
57: }
58: }
|