KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > gui > filter > FontDisplayFilter


1 package net.suberic.pooka.gui.filter;
2 import java.awt.*;
3
4 /**
5  * This represents a DisplayFilter which modifies the font of the
6  * given messages.
7  */

8 public class FontDisplayFilter implements DisplayFilter {
9   
10   int fontStyle = -1;
11   
12   java.util.HashMap JavaDoc derivedFontMap;
13   
14   /**
15    * Creates a new FontDisplayFilter.
16    */

17   public FontDisplayFilter() {
18   }
19   
20   /**
21    * a no-op.
22    */

23   public java.util.List JavaDoc performFilter(java.util.List JavaDoc tmp) {
24     return tmp;
25   }
26   
27   /**
28    * Configures the filter from the given property.
29    */

30   public void initializeFilter(String JavaDoc propertyName) {
31     derivedFontMap = new java.util.HashMap JavaDoc();
32     
33     String JavaDoc fontString = net.suberic.pooka.Pooka.getProperty(propertyName + ".style", "bold");
34     if (fontString.equalsIgnoreCase("bold"))
35       fontStyle = Font.BOLD;
36     else if (fontString.equalsIgnoreCase("italic"))
37       fontStyle = Font.ITALIC;
38     else if (fontString.equalsIgnoreCase("plain"))
39       fontStyle = Font.PLAIN;
40   }
41   
42   /**
43    * Applies the filter to the given component.
44    */

45   public void apply(java.awt.Component JavaDoc target) {
46     Font currentFont = target.getFont();
47     Font derivedFont = (Font) derivedFontMap.get(currentFont);
48     if (derivedFont != null) {
49       target.setFont(derivedFont);
50     } else {
51       derivedFont = currentFont.deriveFont(fontStyle);
52       derivedFontMap.put(currentFont, derivedFont);
53       target.setFont(derivedFont);
54     }
55   }
56 }
57
Popular Tags