if (!getModel().contains(group)) { newCells.add(group); for (int i = 0; i < children.length; i++) { pm.addEntry(children[i], group); if (!getModel().contains(children[i])) { newCells.add(children[i]); AttributeMap attrs = getModel().getAttributes(children[i]); if (attrs != null) nested.put(children[i], attrs); edit(nested, null, pm, null); else insert(newCells.toArray(), nested, null, pm);
setVisibleImpl(getCells(views), true); getMapping(change.getInserted(), true); views = removeCells(change.getRemoved()); if (isPartial()) { showCellsForChange(change); hideCellsForChange(change); CellView view = getMapping(changed[i], false); if (view != null) { view.refresh(this, this, true); update(view); reloadRoots(); refresh(getMapping(getContext(change), false), false); updatePorts();
/** * Removes cells from the model, including all children and connected edges * if <code>children</code> or <code>edges</code> is true, respectively. * * @param cells * The cells to remove. * @param descendants * Whether to remove all descendants as well. * @param edges * Whether to remove all connected edges as well. */ public void remove(Object[] cells, boolean descendants, boolean edges) { if (cells != null && cells.length > 0) { if (edges) { Object[] tmp = DefaultGraphModel.getEdges(getModel(), cells) .toArray(); Object[] newCells = new Object[cells.length + tmp.length]; System.arraycopy(cells, 0, newCells, 0, cells.length); System.arraycopy(tmp, 0, newCells, cells.length, tmp.length); cells = newCells; } if (descendants) cells = DefaultGraphModel.getDescendants(getModel(), cells) .toArray(); remove(cells); } }
/** * Returns the minimal rectangular bounds that enclose all the elements in * the <code>bounds</code> map. After a layout has completed this method * will return the collective bounds of the new laid out graph. * Note this method may return null and should be checked before using. * * @return the collective bounds of the elements in <code>bounds</code> */ public Rectangle2D getGraphBounds() { return GraphLayoutCache.getBounds(graphLayoutCache.getCellViews()); }
/** * Sets the current model. */ public void setModel(GraphModel model) { roots.clear(); mapping.clear(); hiddenMapping.clear(); visibleSet.clear(); graphModel = model; if (!isPartial()) { Object[] cells = DefaultGraphModel.getRoots(getModel()); CellView[] cellViews = getMapping(cells, true); insertViews(cellViews); } // Update PortView Cache and Notify Observers update(); }
/** * Sets the GraphLayoutCache (geometric pattern). This invokes * <code>updateSize</code>. */ protected void setGraphLayoutCache(GraphLayoutCache cache) { cancelEditing(graph); if (graphLayoutCache != null && graphLayoutCacheListener != null) graphLayoutCache .removeGraphLayoutCacheListener(graphLayoutCacheListener); graphLayoutCache = cache; if (graphLayoutCache != null && graphLayoutCacheListener != null) graphLayoutCache .addGraphLayoutCacheListener(graphLayoutCacheListener); updateSize(); }
private void initializeJPanel() { initiate = true; graph.setGraphLayoutCache(new GraphLayoutCache(new DefaultGraphModel(), new DefaultCellViewFactory(), true)); graph.setEditable(false); for (K key : stateKeys) stateCells.put(key, createCell(key, new Point2D(0, 0))); for (K key : stateKeys) createStateTransitionDiagram(key); graph.getGraphLayoutCache().insert(stateCells.values().toArray()); JGraphFacade facade = new JGraphFacade(graph.getGraphLayoutCache()); facade.setEdgePromotion(false); JGraphTreeLayout layout = new JGraphTreeLayout(); layout.run(facade); Map<?, ?> map = facade.createNestedMap(true, true); graph.getGraphLayoutCache().edit(map); }
/** * Obtains the cell view corresponding the cell passed in * @param cell the cell whose view is to be obtained * @return the cell view, if any, assoicated with this cell */ public Object getCellView(Object cell) { if (graphLayoutCache != null){ Object view = graphLayoutCache.getMapping(cell, false); return view; } return null; }
/** * Inserts the specified vertex into the graph model. This method does in * fact nothing, it calls insert edge with the vertex and the source and * target port set to null. This example shows how to add a vertex with a * port and a black border: * * <pre> * DefaultGraphCell vertex = new DefaultGraphCell("Hello, world!"); * Map attrs = vertex.getAttributes(); * GraphConstants.setOpaque(attrs, false); * GraphConstants.setBorderColor(attrs, Color.black); * DefaultPort port = new DefaultPort(); * vertex.add(port); * port.setParent(vertex); * graph.getGraphLayoutCache().insert(vertex); * </pre> * * @param cell * inserts the specified cell in the cache */ public void insert(Object cell) { insert(new Object[] { cell }); }
getGraphLayoutCache().setVisible(vertex,true);// makes the cell visible because VertexView vv=null; while (!created){ CellView[] cellviews = this.getGraphLayoutCache().getCellViews(); for (CellView cv:cellviews){ if (cv.getCell()==vertex){
public void objEntityChanged(EntityEvent e) { remapEntity(e); updateEntityCell(e.getEntity()); // maybe super entity was changed ObjEntity entity = (ObjEntity) e.getEntity(); DefaultEdge inheritanceEdge = inheritanceEdges.get(entity); if (inheritanceEdge != null) { if (entity.getSuperEntity() == null) { graph.getGraphLayoutCache().remove(new Object[] { inheritanceEdge }); inheritanceEdges.remove(entity); } else { inheritanceEdge.setTarget(entityCells.get( entity.getSuperEntity().getName()).getChildAt(0)); Map nested = new HashMap(); nested.put(inheritanceEdge, inheritanceEdge.getAttributes()); graph.getGraphLayoutCache().edit(nested); } } else { if (entity.getSuperEntity() != null) { DefaultEdge edge = createInheritanceEdge(entity); graph.getGraphLayoutCache().insert(edge); } } }
if (isAutoSizeOnValueChange()) { CellView view = getMapping(cell, false); if (view != null) { AttributeMap attrs = view.getAllAttributes(); nested.put(cell, new Hashtable()); augmentNestedMapForValueChange(nested, cell, newValue); edit(nested, null, null, null);
GraphLayoutCache.translateViews(views, tmp.getX(), tmp.getY()); .getAllDescendants(views); Map attributes = GraphConstants.createAttributes(all, null); .getHiddenMapping(); for (int i = 0; i < cells.length; i++) { Object witness = attributes.get(cells[i]); ParentMap pm = ParentMap.create(graphModel, cells, false, true); cells = graphLayoutCache.insertClones(cells, graph.cloneCells(cells), attributes, cs, pm, 0, 0); pm = new ParentMap(context.getCells(), null); graph.getGraphLayoutCache().edit(attributes, disconnect, pm, null);
/** * A shortcut method that takes a nested map and passes it to the edit * method. */ public void edit(Map attributes) { edit(attributes, null, null, null); }
setDataDomain(domain); GraphLayoutCache view = new GraphLayoutCache(model, new DefaultCellViewFactory()); graph.setGraphLayoutCache(view); view.insert(createdObjects.toArray()); view.insert(isolatedObjects.toArray()); graph.getModel().addUndoableEditListener(this);
CellView view = graph .getGraphLayoutCache() .getMapping(cells[i], false); if (view != null && !view.isLeaf()) { double dx = p.getX() - tmp.getY(); GraphLayoutCache .translateViews( new CellView[] { view }, dx, dy); cache.edit(nested, null, null, null);
private void showAllChildren(final DefaultGraphCell vertex) { Vector<Object> toShow = new Vector<Object>(); for (DefaultGraphCell o : getChildren(vertex)) { glc.setVisible(o, true); glc.remove(new Object[] { k.getB() }); processed.add(k); boolean allVisible=true; for (DefaultGraphCell cell:extremes){ allVisible=allVisible&& glc.isVisible(cell); glc.setVisible(o, true); glc.setVisible(o, true);
@Override public void endElement(String uri, String localName, String qName) throws SAXException { if (GRAPH_TAG.equalsIgnoreCase(localName)) { //apply changes builder.getGraph().getGraphLayoutCache().getModel().removeUndoableEditListener(builder); builder.getGraph().getGraphLayoutCache().edit(propertiesMap, null, null, new UndoableEdit[0]); builder.getGraph().getGraphLayoutCache().getModel().addUndoableEditListener(builder); } }
for (int i = 0; i < cells.length; i++) { int childCount = getModel().getChildCount(cells[i]); for (int j = 0; j < childCount; j++) { Object child = getModel().getChild(cells[i], j); pm.addEntry(child, cells[i]); AttributeMap attrs = getModel().getAttributes(child); if (attrs != null) nested.put(child, attrs); Map attrs = getModel().getAttributes(cells[i]); if (attrsTmp != null) attrs.putAll(attrsTmp); Object sourcePort = getModel().getSource(cells[i]); if (sourcePort != null) cs.connect(cells[i], sourcePort, true); Object targetPort = getModel().getTarget(cells[i]); if (targetPort != null) cs.connect(cells[i], targetPort, false); cells = DefaultGraphModel.getDescendants(getModel(), cells) .toArray(); insert(cells, nested, cs, pm, null);