1 package prefuse.action.layout; 2 3 import java.awt.Insets ; 4 import java.awt.geom.Point2D ; 5 import java.awt.geom.Rectangle2D ; 6 7 import prefuse.Display; 8 import prefuse.action.GroupAction; 9 import prefuse.util.PrefuseLib; 10 import prefuse.visual.VisualItem; 11 12 17 public abstract class Layout extends GroupAction { 18 19 20 protected Rectangle2D m_bounds = null; 21 23 protected Point2D m_anchor = null; 24 25 protected boolean m_margin = false; 26 protected Insets m_insets = new Insets (0,0,0,0); 27 protected double[] m_bpts = new double[4]; 28 protected Rectangle2D m_tmpb = new Rectangle2D.Double (); 29 protected Point2D m_tmpa = new Point2D.Double (); 30 31 33 36 public Layout() { 37 super(); 38 } 39 40 44 public Layout(String group) { 45 super(group); 46 } 47 48 public Layout(String group, long duration) { 49 super(group, duration); 50 } 51 52 54 61 public void setMargin(int top, int left, int bottom, int right) { 62 m_insets.top = top; 63 m_insets.left = left; 64 m_insets.bottom = bottom; 65 m_insets.right = right; 66 m_margin = true; 67 } 68 69 77 public Rectangle2D getLayoutBounds() { 78 if ( m_bounds != null ) 79 return m_bounds; 80 81 if ( m_vis != null && m_vis.getDisplayCount() > 0 ) 82 { 83 Display d = m_vis.getDisplay(0); 84 Insets i = m_margin ? m_insets : d.getInsets(m_insets); 85 m_bpts[0] = i.left; 86 m_bpts[1] = i.top; 87 m_bpts[2] = d.getWidth()-i.right; 88 m_bpts[3] = d.getHeight()-i.bottom; 89 d.getInverseTransform().transform(m_bpts,0,m_bpts,0,2); 90 m_tmpb.setRect(m_bpts[0],m_bpts[1], 91 m_bpts[2]-m_bpts[0], 92 m_bpts[3]-m_bpts[1]); 93 return m_tmpb; 94 } else { 95 return null; 96 } 97 } 98 99 106 public void setLayoutBounds(Rectangle2D b) { 107 m_bounds = b; 108 } 109 110 118 public Point2D getLayoutAnchor() { 119 if ( m_anchor != null ) 120 return m_anchor; 121 122 m_tmpa.setLocation(0,0); 123 if ( m_vis != null ) { 124 Display d = m_vis.getDisplay(0); 125 m_tmpa.setLocation(d.getWidth()/2.0,d.getHeight()/2.0); 126 d.getInverseTransform().transform(m_tmpa, m_tmpa); 127 } 128 return m_tmpa; 129 } 130 131 137 public void setLayoutAnchor(Point2D a) { 138 m_anchor = a; 139 } 140 141 154 public void setX(VisualItem item, VisualItem referrer, double x) { 155 PrefuseLib.setX(item, referrer, x); 156 } 157 158 171 public void setY(VisualItem item, VisualItem referrer, double y) { 172 PrefuseLib.setY(item, referrer, y); 173 } 174 175 } | Popular Tags |