1 package prefuse.action.distortion; 2 3 import java.awt.geom.Point2D ; 4 import java.awt.geom.Rectangle2D ; 5 import java.util.Iterator ; 6 7 import prefuse.action.layout.Layout; 8 import prefuse.visual.VisualItem; 9 10 11 17 public abstract class Distortion extends Layout { 18 19 private Point2D m_tmp = new Point2D.Double (); 20 protected boolean m_distortSize = true; 21 protected boolean m_distortX = true; 22 protected boolean m_distortY = true; 23 24 26 29 public Distortion() { 30 super(); 31 } 32 33 37 public Distortion(String group) { 38 super(group); 39 } 40 41 43 47 public void setSizeDistorted(boolean s) { 48 m_distortSize = s; 49 } 50 51 56 public boolean isSizeDistorted() { 57 return m_distortSize; 58 } 59 60 62 65 public void run(double frac) { 66 Rectangle2D bounds = getLayoutBounds(); 67 Point2D anchor = correct(m_anchor, bounds); 68 69 final Iterator iter = getVisualization().visibleItems(m_group); 70 71 while ( iter.hasNext() ) { 72 VisualItem item = (VisualItem)iter.next(); 73 if ( item.isFixed() ) continue; 74 75 item.setX(item.getEndX()); 78 item.setY(item.getEndY()); 79 item.setSize(item.getEndSize()); 80 81 if ( anchor != null ) { 83 Rectangle2D bbox = item.getBounds(); 84 double x = item.getX(); 85 double y = item.getY(); 86 87 if ( m_distortX ) 89 item.setX(x=distortX(x, anchor, bounds)); 90 if ( m_distortY ) 91 item.setY(y=distortY(y, anchor, bounds)); 92 93 if ( m_distortSize ) { 95 double sz = distortSize(bbox, x, y, anchor, bounds); 96 item.setSize(sz*item.getSize()); 97 } 98 } 99 } 100 } 101 102 110 protected Point2D correct(Point2D anchor, Rectangle2D bounds) { 111 if ( anchor == null ) return anchor; 112 double x = anchor.getX(), y = anchor.getY(); 113 double x1 = bounds.getMinX(), y1 = bounds.getMinY(); 114 double x2 = bounds.getMaxX(), y2 = bounds.getMaxY(); 115 x = (x < x1 ? x1 : (x > x2 ? x2 : x)); 116 y = (y < y1 ? y1 : (y > y2 ? y2 : y)); 117 118 m_tmp.setLocation(x,y); 119 return m_tmp; 120 } 121 122 129 protected abstract double distortX(double x, Point2D anchor, Rectangle2D bounds); 130 131 138 protected abstract double distortY(double y, Point2D anchor, Rectangle2D bounds); 139 140 149 protected abstract double distortSize(Rectangle2D bbox, double x, double y, 150 Point2D anchor, Rectangle2D bounds); 151 152 } | Popular Tags |