1 package prefuse.action.layout; 2 3 import java.awt.geom.Rectangle2D ; 4 import java.util.Iterator ; 5 6 import prefuse.Constants; 7 import prefuse.data.Table; 8 import prefuse.render.PolygonRenderer; 9 import prefuse.visual.VisualItem; 10 11 17 public class CollapsedStackLayout extends Layout { 18 19 private String m_polyField; 20 private int m_orientation = Constants.ORIENT_BOTTOM_TOP; 21 private boolean m_horiz = false; 22 private boolean m_top = false; 23 24 29 public CollapsedStackLayout(String group) { 30 this(group, PolygonRenderer.POLYGON); 31 } 32 33 38 public CollapsedStackLayout(String group, String field) { 39 super(group); 40 m_polyField = field; 41 } 42 43 51 public int getOrientation() { 52 return m_orientation; 53 } 54 55 65 public void setOrientation(int orient) { 66 if ( orient != Constants.ORIENT_TOP_BOTTOM && 67 orient != Constants.ORIENT_BOTTOM_TOP && 68 orient != Constants.ORIENT_LEFT_RIGHT && 69 orient != Constants.ORIENT_RIGHT_LEFT) { 70 throw new IllegalArgumentException ( 71 "Invalid orientation value: "+orient); 72 } 73 m_orientation = orient; 74 m_horiz = (m_orientation == Constants.ORIENT_LEFT_RIGHT || 75 m_orientation == Constants.ORIENT_RIGHT_LEFT); 76 m_top = (m_orientation == Constants.ORIENT_TOP_BOTTOM || 77 m_orientation == Constants.ORIENT_LEFT_RIGHT); 78 } 79 80 83 public void run(double frac) { 84 VisualItem lastItem = null; 85 86 Rectangle2D bounds = getLayoutBounds(); 87 float floor = (float) 88 (m_horiz ? (m_top?bounds.getMaxX():bounds.getMinX()) 89 : (m_top?bounds.getMinY():bounds.getMaxY())); 90 int bias = (m_horiz ? 0 : 1); 91 92 Iterator iter = ((Table)m_vis.getGroup(m_group)).tuplesReversed(); 94 while ( iter.hasNext() ) { 95 VisualItem item = (VisualItem)iter.next(); 96 boolean prev = item.isStartVisible(); 97 boolean cur = item.isVisible(); 98 99 if ( !prev && cur ) { 100 float[] f = (float[])item.get(m_polyField); 102 if ( f == null ) continue; 103 104 if ( lastItem == null ) { 105 for ( int i=0; i<f.length; i+=2 ) 107 f[i+bias] = floor; 108 } else { 109 float[] l = (float[])lastItem.get(m_polyField); 112 for ( int i=0; i<f.length/2; i+=2 ) 113 f[i+bias] = f[f.length-2-i+bias] 114 = l[i+bias]; 115 } 116 } else if ( prev && cur ) { 117 lastItem = item; 119 } 120 } 121 } 122 123 } | Popular Tags |