1 19 27 28 package org.netbeans.modules.xml.nbprefuse.layout; 29 30 import java.awt.geom.Rectangle2D ; 31 import java.util.Iterator ; 32 import prefuse.Visualization; 33 import prefuse.action.layout.Layout; 34 import prefuse.util.GraphicsLib; 35 import prefuse.visual.AggregateItem; 36 import prefuse.visual.AggregateTable; 37 import prefuse.visual.VisualItem; 38 39 43 44 48 public class AggregateLayout extends Layout { 49 50 private int m_margin = 5; private double[] m_pts; private Visualization m_vis; 53 54 public AggregateLayout(Visualization vis, String aggrGroup) { 55 super(aggrGroup); 56 m_vis = vis; 57 } 58 59 62 public void run(double frac) { 63 64 AggregateTable aggr = (AggregateTable)m_vis.getGroup(m_group); 65 int num = aggr.getTupleCount(); 67 if ( num == 0 ) return; 68 69 int maxsz = 0; 71 for ( Iterator aggrs = aggr.tuples(); aggrs.hasNext(); ) 72 maxsz = Math.max(maxsz, 4*2* 73 ((AggregateItem)aggrs.next()).getAggregateSize()); 74 if ( m_pts == null || maxsz > m_pts.length ) { 75 m_pts = new double[maxsz]; 76 } 77 78 Iterator aggrs = m_vis.visibleItems(m_group); 80 while ( aggrs.hasNext() ) { 81 AggregateItem aitem = (AggregateItem)aggrs.next(); 82 83 int idx = 0; 84 if ( aitem.getAggregateSize() == 0 ) continue; 85 VisualItem item = null; 86 Iterator iter = aitem.items(); 87 while ( iter.hasNext() ) { 88 item = (VisualItem)iter.next(); 89 if ( item.isVisible() ) { 90 addPoint(m_pts, idx, item, m_margin); 91 idx += 2*4; 92 } 93 } 94 if ( idx == 0 ) continue; 96 97 double[] nhull = GraphicsLib.convexHull(m_pts, idx); 99 100 float[] fhull = (float[])aitem.get(VisualItem.POLYGON); 102 if ( fhull == null || fhull.length < nhull.length ) 103 fhull = new float[nhull.length]; 104 else if ( fhull.length > nhull.length ) 105 fhull[nhull.length] = Float.NaN; 106 107 for ( int j=0; j<nhull.length; j++ ) 109 fhull[j] = (float)nhull[j]; 110 aitem.set(VisualItem.POLYGON, fhull); 111 aitem.setValidated(false); } 113 } 114 115 private static void addPoint(double[] pts, int idx, 116 VisualItem item, int growth) 117 { 118 Rectangle2D b = item.getBounds(); 119 double minX = (b.getMinX())-growth, minY = (b.getMinY())-growth; 120 double maxX = (b.getMaxX())+growth, maxY = (b.getMaxY())+growth; 121 pts[idx] = minX; pts[idx+1] = minY; 122 pts[idx+2] = minX; pts[idx+3] = maxY; 123 pts[idx+4] = maxX; pts[idx+5] = minY; 124 pts[idx+6] = maxX; pts[idx+7] = maxY; 125 } 126 127 } | Popular Tags |