1 package prefuse.action.assignment; 2 3 import java.util.logging.Logger ; 4 5 import prefuse.Constants; 6 import prefuse.action.EncoderAction; 7 import prefuse.data.expression.Predicate; 8 import prefuse.data.expression.parser.ExpressionParser; 9 import prefuse.visual.VisualItem; 10 11 12 46 public class ShapeAction extends EncoderAction { 47 48 protected int m_defaultShape = Constants.SHAPE_RECTANGLE; 49 50 53 public ShapeAction() { 54 super(); 55 } 56 57 61 public ShapeAction(String group) { 62 super(group); 63 } 64 65 70 public ShapeAction(String group, int shape) { 71 super(group); 72 m_defaultShape = shape; 73 } 74 75 79 public int getDefaultSize() { 80 return m_defaultShape; 81 } 82 83 88 public void setDefaultShape(int defaultShape) { 89 m_defaultShape = defaultShape; 90 } 91 92 99 public void add(Predicate p, int shape) { 100 super.add(p, new Integer (shape)); 101 } 102 103 113 public void add(String expr, int shape) { 114 Predicate p = (Predicate)ExpressionParser.parse(expr); 115 add(p, shape); 116 } 117 118 125 public void add(Predicate p, ShapeAction f) { 126 super.add(p, f); 127 } 128 129 139 public void add(String expr, ShapeAction f) { 140 Predicate p = (Predicate)ExpressionParser.parse(expr); 141 super.add(p, f); 142 } 143 144 146 149 public void process(VisualItem item, double frac) { 150 item.setShape(getShape(item)); 151 } 152 153 158 public int getShape(VisualItem item) { 159 Object o = lookup(item); 160 if ( o != null ) { 161 if ( o instanceof ShapeAction ) { 162 return ((ShapeAction)o).getShape(item); 163 } else if ( o instanceof Number ) { 164 return ((Number )o).intValue(); 165 } else { 166 Logger.getLogger(this.getClass().getName()) 167 .warning("Unrecognized Object from predicate chain."); 168 } 169 } 170 return m_defaultShape; 171 } 172 173 } | Popular Tags |