private void setVertexColor(Object vertex, Color color) { DefaultGraphCell cell = m_jgAdapter.getVertexCell(vertex); AttributeMap attr = cell.getAttributes(); GraphConstants.setBackground(attr, color); AttributeMap cellAttr = new AttributeMap(); cellAttr.put(cell, attr); m_jgAdapter.edit(cellAttr, null, null, null); }
private void positionVertexAt(Object vertex, int x, int y) { DefaultGraphCell cell = m_jgAdapter.getVertexCell(vertex); AttributeMap attr = cell.getAttributes(); Rectangle2D b = GraphConstants.getBounds(attr); Rectangle2D newBounds = new Rectangle2D.Double(x, y, 5, 5); GraphConstants.setBounds(attr, newBounds); AttributeMap cellAttr = new AttributeMap(); cellAttr.put(cell, attr); m_jgAdapter.edit(cellAttr, null, null, null); }
/** * Filters a list of vertices out of an array of JGraph GraphCell objects. Other objects are * thrown away. * * @param cells Array of cells to be filtered. * @return a list of vertices. */ private List<Object> filterVertices(Object[] cells) { List<Object> jVertices = new ArrayList<Object>(); for (int i = 0; i < cells.length; i++) { Object cell = cells[i]; if (cell instanceof org.jgraph.graph.Edge) { // ignore -- we don't care about edges. } else if (cell instanceof Port) { // ignore -- we don't care about ports. } else if (cell instanceof DefaultGraphCell) { DefaultGraphCell graphCell = (DefaultGraphCell) cell; // If a DefaultGraphCell has a Port as a child, it is a // vertex. // Note: do not change the order of following conditions; // the code uses the short-circuit evaluation of ||. if (graphCell.isLeaf() || (graphCell.getFirstChild() instanceof Port)) { jVertices.add(cell); } } else if (cell instanceof GraphCell) { // If it is not a DefaultGraphCell, it doesn't have // children. jVertices.add(cell); } } return jVertices; }
/** * Adds the specified JGraphT vertex to be reflected by this graph model. To be called only for * edges that already exist in the JGraphT graph. * * @param jtVertex a JGraphT vertex to be reflected by this graph model. */ void handleJGraphTAddedVertex(V jtVertex) { DefaultGraphCell vertexCell = cellFactory.createVertexCell(jtVertex); vertexCell.add(new DefaultPort()); vertexToCell.put(jtVertex, vertexCell); cellToVertex.put(vertexCell, jtVertex); internalInsertCell(vertexCell, createVertexAttributeMap(vertexCell), null); }
/** * Returns the JGraph port cell that corresponds to the specified JGraphT vertex. If no * corresponding port found, returns <code>null</code>. * * @param jGraphTVertex a JGraphT vertex of the JGraphT graph. * @return the JGraph port cell that corresponds to the specified JGraphT vertex, or <code>null * </code> if no corresponding cell found. */ public DefaultPort getVertexPort(Object jGraphTVertex) { DefaultGraphCell vertexCell = getVertexCell(jGraphTVertex); if (vertexCell == null) { return null; } else { return (DefaultPort) vertexCell.getChildAt(0); } }
/** * Removes the specified JGraphT vertex from being reflected by this graph model. To be called * only for vertices that have already been removed from the JGraphT graph. * * @param jtVertex a JGraphT vertex to be removed from being reflected by this graph model. */ void handleJGraphTRemoveVertex(Object jtVertex) { DefaultGraphCell vertexCell = (DefaultGraphCell) vertexToCell.remove(jtVertex); cellToVertex.remove(vertexCell); List<Object> ports = new ArrayList<Object>(); for (Object child : vertexCell.getChildren()) { if (this.isPort(child)) { ports.add(child); } } this.remove(ports.toArray()); internalRemoveCell(vertexCell); }