1 23 24 package org.objectweb.medor.tuple.lib; 25 26 import org.objectweb.medor.api.MedorException; 27 import org.objectweb.medor.api.TupleStructure; 28 import org.objectweb.medor.tuple.api.TupleCollection; 29 30 import javax.swing.*; 31 import java.awt.*; 32 import java.awt.event.WindowAdapter ; 33 import java.awt.event.WindowEvent ; 34 import java.util.LinkedList ; 35 36 public class TupleCollectionView extends JFrame { 37 public TupleCollectionView(TupleCollection tc) throws MedorException { 38 org.objectweb.medor.tuple.api.Tuple t; 39 Object o; 40 int nbTuple; 41 Object [][] data; 42 int nbAtt = tc.getMetaData().getSize(); 43 LinkedList tuples = new LinkedList (); 44 int c; 45 int l; 46 tc.first(); 47 if (tc.isEmpty()) 48 throw new MedorException("The TupleCollection is empty"); 49 else { 50 do { 51 o = tc.getTuple(); tuples.add(o); 55 } while (tc.next()); 56 nbTuple = tuples.size(); 57 data = new Object [nbTuple][nbAtt]; 58 for (l = 0; (l < nbTuple); l++) { 59 t = (org.objectweb.medor.tuple.api.Tuple) tuples.get(l); 60 for (c = 1; (c <= nbAtt); c++) data[l][c - 1] = t.getObject(c); 61 } 62 63 TupleStructure md1 = tc.getMetaData(); 64 String [] columnNames = new String [nbAtt]; 65 c = 0; 66 while (c <= (nbAtt - 1)) { 67 columnNames[c] = md1.getField(c + 1).getName(); 68 c++; 69 } 70 71 final JTable table = new JTable(data, columnNames); 72 table.setPreferredScrollableViewportSize(new Dimension(1000, 150)); 73 74 JScrollPane scrollPane = new JScrollPane(table); 76 77 getContentPane().add(scrollPane, BorderLayout.CENTER); 79 80 addWindowListener(new WindowAdapter () { 81 public void windowClosing(WindowEvent e) { 82 System.exit(0); 83 } 84 }); 85 } 86 } 87 } 88 | Popular Tags |