1 package prefuse.action.assignment; 2 3 import java.awt.Font ; 4 import java.util.logging.Logger ; 5 6 import prefuse.action.EncoderAction; 7 import prefuse.data.expression.Predicate; 8 import prefuse.data.expression.parser.ExpressionParser; 9 import prefuse.util.FontLib; 10 import prefuse.visual.VisualItem; 11 12 13 32 public class FontAction extends EncoderAction { 33 34 protected Font defaultFont = FontLib.getFont("SansSerif",Font.PLAIN,10); 35 36 39 public FontAction() { 40 super(); 41 } 42 43 47 public FontAction(String group) { 48 super(group); 49 } 50 51 56 public FontAction(String group, Font defaultFont) { 57 super(group); 58 this.defaultFont = defaultFont; 59 } 60 61 63 68 public void setDefaultFont(Font f) { 69 defaultFont = f; 70 } 71 72 76 public Font getDefaultFont() { 77 return defaultFont; 78 } 79 80 87 public void add(Predicate p, Font font) { 88 super.add(p, font); 89 } 90 91 101 public void add(String expr, Font font) { 102 Predicate p = (Predicate)ExpressionParser.parse(expr); 103 super.add(p, font); 104 } 105 106 113 public void add(Predicate p, FontAction f) { 114 super.add(p, f); 115 } 116 117 127 public void add(String expr, FontAction f) { 128 Predicate p = (Predicate)ExpressionParser.parse(expr); 129 super.add(p, f); 130 } 131 132 134 137 public void process(VisualItem item, double frac) { 138 Font f = getFont(item); 139 Font o = item.getFont(); 140 item.setStartFont(o); 141 item.setEndFont(f); 142 item.setFont(f); 143 } 144 145 151 public Font getFont(VisualItem item) { 152 Object o = lookup(item); 153 if ( o != null ) { 154 if ( o instanceof FontAction ) { 155 return ((FontAction)o).getFont(item); 156 } else if ( o instanceof Font ) { 157 return (Font )o; 158 } else { 159 Logger.getLogger(this.getClass().getName()) 160 .warning("Unrecognized Object from predicate chain."); 161 } 162 } 163 return defaultFont; 164 } 165 166 } | Popular Tags |