1 package test.prefuse.data; 2 3 import junit.framework.TestCase; 4 import prefuse.Visualization; 5 import prefuse.data.Table; 6 import prefuse.data.Tuple; 7 import prefuse.data.expression.AbstractPredicate; 8 import prefuse.data.expression.Predicate; 9 import prefuse.data.io.DelimitedTextTableWriter; 10 import prefuse.data.util.TableIterator; 11 import prefuse.visual.VisualTable; 12 import test.prefuse.TestConfig; 13 14 public class VisualItemTableTest extends TestCase implements TableTestData { 15 16 Table t; 17 18 21 protected void setUp() throws Exception { 22 super.setUp(); 23 t = TableTest.getTestCaseTable(); 24 } 25 26 29 protected void tearDown() throws Exception { 30 super.tearDown(); 31 t = null; 32 } 33 34 37 public void testVisualItemTableTableRowFilter() { 38 final float thresh = 5.0f; 39 40 Predicate p = new AbstractPredicate() { 41 public boolean getBoolean(Tuple t) { 42 return t.getFloat(HEADERS[3]) < thresh; 43 } 44 }; 45 46 Visualization vis = new Visualization(); 47 VisualTable vt = new VisualTable(t, vis, "data", p); 48 49 for ( int i=0, r=0; i<NROWS; ++i ) { 50 float val = ((Float )TABLE[3][i]).floatValue(); 51 if ( val < thresh ) { 52 try { 53 for ( int c=0; c<NCOLS; ++c ) { 54 Object o1 = TABLE[c][i]; 55 Object o2 = vt.get(r, HEADERS[c]); 56 assertEquals(o1, o2); 57 } 58 ++r; 59 } catch ( Exception e ) { 60 fail("Caught exception: "+e); 61 } 62 } 63 } 64 65 String name = "test"; 67 vt.addColumn(name, double.class, new Double (Math.PI)); 68 TableIterator iter = vt.iterator(); 69 while ( iter.hasNext() ) { 70 int row = iter.nextInt(); 71 iter.setDouble(name, Math.E); 72 assertTrue(Math.E == vt.getDouble(row, name)); 73 } 74 75 int nr = t.addRow(); 76 t.setFloat(nr, HEADERS[3], 0.5f); 77 78 if ( TestConfig.verbose() ) { 79 try { 80 new DelimitedTextTableWriter().writeTable(vt, System.out); 81 } catch ( Exception e ) { e.printStackTrace(); } 82 } 83 } 84 85 } 86 | Popular Tags |