/** * Converts an Obvious tree to an infovis tree. * @param tree tree to convert * @return the converted infovis tree */ private infovis.Tree convertToIvtkTree(Tree<Node, Edge> tree) { if (tree.getEdges().size() != 0 && tree.getNodes().size() != 0) { Schema nodeSchema = tree.getNodes().iterator().next().getSchema() .getDataSchema(); Schema edgeSchema = tree.getEdges().iterator().next().getSchema() .getDataSchema(); Tree<Node, Edge> ivtkTree = new IvtkObviousTree(nodeSchema, edgeSchema); ObviousLib.fillTree(tree, ivtkTree); return (infovis.Tree) ivtkTree.getUnderlyingImpl(infovis.Tree.class); } else { throw new ObviousRuntimeException("Empty tree!"); } }
/** * Adds a given node to the current graph. * @param node node to add to the graph * @return true if the node is added */ public boolean addNode(Node node) { try { int rowId = graph.addVertex(); for (int i = 0; i < node.getSchema().getColumnCount(); i++) { if (nodeSchema.hasColumn(node.getSchema().getColumnName(i))) { TypedFormat format = formatFactory.getFormat( node.getSchema().getColumnType(i).getSimpleName()); StringBuffer v = format.format(node.get(i), new StringBuffer(), new FieldPosition(0)); graph.getVertexTable().setValueAt(v.toString(), rowId, graph.getVertexTable().indexOf( node.getSchema().getColumnName(i))); } } nodeToId.put(node, rowId); fireNetworkEvent(node.getRow(), node.getRow(), 0, NetworkListener.INSERT_NODE); return true; } catch (Exception e) { throw new ObviousRuntimeException(e); } }
/** * Constructor. * @param inNetwork obvious network to wrap */ public WrapToPrefGraph(Network inNetwork) { super(new WrapToPrefTable(inNetwork.getNodeTable()), new WrapToPrefTable(inNetwork.getEdgeTable()), true); this.network = inNetwork; if (network.getNodes().size() != 0) { this.nodeSchema = network.getNodes().iterator().next().getSchema(); } if (network.getEdges().size() != 0) { this.edgeSchema = network.getEdges().iterator().next().getSchema(); } m_nodeTuples = new TupleManager(getNodeTable(), this, Table.class); m_edgeTuples = new TupleManager(getEdgeTable(), this, Table.class); }
/** * Adds a given node to the current graph. * @param node node to add to the graph * @return true if the node is added */ public boolean addNode(Node node) { try { // if prefNode (prefuse) tuple and node (obvious) tuple are compatible // i.e their schema are compatible. prefuse.data.Node prefNode = this.graph.addNode(); for (int i = 0; i < node.getTable().getSchema().getColumnCount(); i++) { prefNode.set(node.getSchema().getColumnName(i), node.get(i)); } int nodeId = prefNode.getRow(); fireNetworkEvent(nodeId, nodeId, 0, NetworkListener.INSERT_NODE); return true; } catch (Exception e) { throw new ObviousRuntimeException(e); } }