/** @see prefuse.data.io.TableWriter#writeTable(prefuse.data.Table, java.io.OutputStream) */ public void writeTable(Table table, OutputStream os) throws DataIOException { try { // get print stream PrintWriter out = new PrintWriter(new OutputStreamWriter(os, "UTF-8")); // write out header row if (m_printHeader) { for (int i = 0; i < table.getColumnCount(); ++i) { if (i > 0) out.print(','); out.print(makeCSVSafe(table.getColumnName(i))); } out.println(); } // write out data for (IntIterator rows = table.rows(); rows.hasNext(); ) { int row = rows.nextInt(); for (int i = 0; i < table.getColumnCount(); ++i) { if (i > 0) out.print(','); String str = table.getString(row, table.getColumnName(i)); out.print(makeCSVSafe(str)); } out.println(); } // finish up out.flush(); } catch (Exception e) { throw new DataIOException(e); } }
private DatabaseTable inferTableToBeMerged(Table mergingTable) throws AlgorithmExecutionException { String header = mergingTable.getColumnName(mergingTable.getColumnCount() - 1); String name = extractNameFromHeader(header); try { return DatabaseTable.fromRepresentation(name); } catch (InvalidRepresentationException e) { throw new AlgorithmExecutionException(INVALID_TABLE_NAME_HEADER_MESSAGE); } }
public void testLoadFromMySQLDatabase() { String host = "localhost"; String database = "friendster"; String user = "******"; String password = ""; String keyField = "uid"; String query1 = "SELECT profiles.* FROM profiles, graph WHERE " + "(graph.uid1 = 186297 AND profiles.uid = graph.uid2)"; String query2 = "SELECT profiles.* FROM profiles, graph WHERE " + "(graph.uid1 = 21721 AND profiles.uid = graph.uid2)"; // String query = "SELECT gender, age, COUNT(*) FROM profiles GROUP BY gender,age"; s_logger.info(TestConfig.memUse()); Table t = null; try { DatabaseDataSource db = ConnectionFactory.getMySQLConnection(host, database, user, password); s_logger.info(TestConfig.memUse()); t = db.getData(t, query1, keyField); db.loadData(t, query2, keyField); } catch (Exception e) { e.printStackTrace(); fail("Error connecting to database"); } // text-dump StringBuffer sbuf = new StringBuffer('\n'); sbuf.append("--[Table: ") .append(t.getRowCount()) .append(" rows, ") .append(t.getColumnCount()) .append(" cols]--\n"); for (int c = 0, idx = -1; c < t.getColumnCount(); ++c) { String name = t.getColumnType(c).getName(); if ((idx = name.lastIndexOf('.')) >= 0) name = name.substring(idx + 1); sbuf.append(c).append("\t").append(name).append("\t").append(t.getColumnName(c)).append('\n'); } sbuf.append('\n'); sbuf.append(TestConfig.memUse()).append('\n'); s_logger.info(sbuf.toString()); m_table = t; }
private static JToolBar getEncodingToolbar( final ScatterPlot sp, final String xfield, final String yfield, final String sfield) { int spacing = 10; // create list of column names Table t = (Table) sp.getVisualization().getSourceData(group); String[] colnames = new String[t.getColumnCount()]; for (int i = 0; i < colnames.length; ++i) colnames[i] = t.getColumnName(i); // create toolbar that allows visual mappings to be changed JToolBar toolbar = new JToolBar(); toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS)); toolbar.add(Box.createHorizontalStrut(spacing)); final JComboBox xcb = new JComboBox(colnames); xcb.setSelectedItem(xfield); xcb.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Visualization vis = sp.getVisualization(); AxisLayout xaxis = (AxisLayout) vis.getAction("x"); xaxis.setDataField((String) xcb.getSelectedItem()); vis.run("draw"); } }); toolbar.add(new JLabel("X: ")); toolbar.add(xcb); toolbar.add(Box.createHorizontalStrut(2 * spacing)); final JComboBox ycb = new JComboBox(colnames); ycb.setSelectedItem(yfield); ycb.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Visualization vis = sp.getVisualization(); AxisLayout yaxis = (AxisLayout) vis.getAction("y"); yaxis.setDataField((String) ycb.getSelectedItem()); vis.run("draw"); } }); toolbar.add(new JLabel("Y: ")); toolbar.add(ycb); toolbar.add(Box.createHorizontalStrut(2 * spacing)); final JComboBox scb = new JComboBox(colnames); scb.setSelectedItem(sfield); scb.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Visualization vis = sp.getVisualization(); DataShapeAction s = (DataShapeAction) vis.getAction("shape"); s.setDataField((String) scb.getSelectedItem()); vis.run("draw"); } }); toolbar.add(new JLabel("Shape: ")); toolbar.add(scb); toolbar.add(Box.createHorizontalStrut(spacing)); toolbar.add(Box.createHorizontalGlue()); return toolbar; }
/** @see javax.swing.table.TableModel#getColumnName(int) */ public String getColumnName(int columnIndex) { return m_table.getColumnName(columnIndex); }