/** * Returns an instance of <code>JGraph</code> which displays the data * model using the specified view. * * @param cache * the <code>GraphLayoutCache</code> to use as the view */ public JGraph(GraphLayoutCache cache) { this((cache != null) ? cache.getModel() : null, cache); }
boolean ignoresUnconnectedCells, boolean directed, JGraphCostFunction distanceCostFunction, JGraphAlgebra algebra) { this(cache == null ? null : cache.getModel(), cache, roots, ignoresHiddenCells, ignoresCellsInGroups, ignoresUnconnectedCells, directed,
/** * Checks if the port or one of its parents is visible. */ protected boolean hasVisibleParent(Object cell, Set invisible) { boolean isVisible = false; do { isVisible = (invisible == null || !invisible.contains(cell)) ? isVisible(cell) : false; cell = getModel().getParent(cell); } while (cell != null && !isVisible); return isVisible; }
/** * Hook for subclassers to return the first or last visible port to replace * the current source or target port of the edge. This is called when groups * are collapsed for the edges that cross the group, ie. go from a child * cell to a cell which is outside the group. This implementation returns * the first port of the parent group if source is true, otherwise it * returns the last port of the parent group. */ protected Object getParentPort(Object edge, boolean source) { // Contains the parent of the parent vertex, eg. the group Object parent = getModel().getParent( (source) ? DefaultGraphModel.getSourceVertex(getModel(), edge) : DefaultGraphModel.getTargetVertex(getModel(), edge)); // Finds a port in the group int c = getModel().getChildCount(parent); for (int i = (source) ? c - 1 : 0; i < getModel().getChildCount(parent) && i >= 0; i += (source) ? -1 : +1) { Object child = getModel().getChild(parent, i); if (getModel().isPort(child)) { return child; } } return null; }
/** * Shows the specified cells with all children if <code>descandants</code> * is true. * NOTE: Your GraphLayoutCache must be <code>partial</code> (set * <code>partial</code> to <code>true</code> in the constructor) * in order to use the visibility functionality of expand/collapse, * setVisible, etc. */ public void showCells(Object[] cells, boolean descandants) { if (cells != null && cells.length > 0) { if (descandants) cells = DefaultGraphModel.getDescendants(getModel(), cells) .toArray(); setVisible(cells, true); } }
/** * 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); } }
/** * Hides the specified cells with all children if <code>descandants</code> * is true. * NOTE: Your GraphLayoutCache must be <code>partial</code> (set * <code>partial</code> to <code>true</code> in the constructor) * in order to use the visibility functionality of expand/collapse, * setVisible, etc. */ public void hideCells(Object[] cells, boolean descandants) { if (cells != null && cells.length > 0) { if (descandants) cells = DefaultGraphModel.getDescendants(getModel(), cells) .toArray(); setVisible(cells, false); } }
/** * 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(); }
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();
@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); } }
boolean visibleCells) { GraphModel model = getModel(); Object[] fanout = (directed) ? DefaultGraphModel.getOutgoingEdges( model, cell) : DefaultGraphModel.getEdges(model,
protected void cellWillCollapse(Object cell) { GraphModel model = getModel(); if (movesParentsOnCollapse) { CellView view = getMapping(cell, false); if (view != null && !view.isLeaf()) { // Uses view-local attribute if available AttributeMap attrs = view.getAttributes(); if (!attrs.contains(GraphConstants.BOUNDS) && !localAttributes.contains(GraphConstants.BOUNDS)) attrs = model.getAttributes(cell); // Moves the group to the origin of the children Rectangle2D src = GraphConstants.getBounds(attrs); Rectangle2D b = view.getBounds(); // FIXME: What if the group is exactly at "defaultBounds"? if (resizesParentsOnCollapse || src == null || src.equals(VertexView.defaultBounds)) { src = attrs.createRect(b.getX(), b.getY(), b.getWidth() * collapseXScale, b.getHeight() * collapseYScale); attrs.applyValue(GraphConstants.BOUNDS, src); } else { src.setFrame(b.getX(), b.getY(), src.getWidth(), src .getHeight()); } } } }
/** * A helper method to return various arrays of cells that are visible in * this cache. For example, to get all selected vertices in a graph, do * <code>graph.getSelectionCells(graph.getGraphLayoutCache().getCells(false, true, false, false));</code> */ public Object[] getCells(boolean groups, boolean vertices, boolean ports, boolean edges) { CellView[] views = getCellViews(); List result = new ArrayList(views.length); GraphModel model = getModel(); for (int i = 0; i < views.length; i++) { Object cell = views[i].getCell(); boolean isEdge = model.isEdge(cell); if ((ports || !model.isPort(cell))) { if (((((ports || vertices) && !isEdge) || (edges && isEdge)) && views[i] .isLeaf()) || (groups && !views[i].isLeaf())) result.add(views[i].getCell()); } } return result.toArray(); }
/** * Sets the <code>GraphModel</code> that will provide the data. Note: * Updates the current GraphLayoutCache's model using setModel if the * GraphLayoutCache points to a different model. * <p> * Fires a property change for the GRAPH_MODEL_PROPERTY. * * @param newModel * the <code>GraphModel</code> that is to provide the data */ public void setModel(GraphModel newModel) { GraphModel oldModel = graphModel; graphModel = newModel; clearOffscreen(); firePropertyChange(GRAPH_MODEL_PROPERTY, oldModel, graphModel); // FIX: Use Listener if (graphLayoutCache != null && graphLayoutCache.getModel() != graphModel) graphLayoutCache.setModel(graphModel); clearSelection(); invalidate(); }
boolean createDependentViews) { GraphModel model = cache.getModel(); allAttributes = getCellAttributes(model);
GraphModel model = getModel();
/** * Hook for subclassers to return the port to be used for edges that have * been connected to the group. This is called from expand. This returns the * first port of the first or last vertex depending on <code>source</code>. */ protected Object getChildPort(Object edge, boolean source) { GraphModel model = getModel(); // Contains the parent of the port, eg. the group Object parent = (source) ? DefaultGraphModel.getSourceVertex(model, edge) : DefaultGraphModel.getTargetVertex(model, edge); // Finds a vertex in the group int c = model.getChildCount(parent); for (int i = (source) ? c - 1 : 0; i < c && i >= 0; i += (source) ? -1 : +1) { Object child = model.getChild(parent, i); if (!model.isEdge(child) && !model.isPort(child)) { // Finds a port in the vertex for (int j = 0; j < model.getChildCount(child); j++) { Object port = model.getChild(child, j); if (model.isPort(port)) { return port; } } } } return null; }
/** * Overrides the parent method to udpate the cached points, source and * target port. If the source or target is removed, a point is inserted into * the array of points. */ public void refresh(GraphLayoutCache cache, CellMapper mapper, boolean createDependentViews) { // Makes sure the manual control points are passed to // the router instead of the cached control points after // changes to the edge (normally manual point changes). initialiseDefaultPoints(); super.refresh(cache, mapper, createDependentViews); // Re-sync source- and targetportviews GraphModel model = cache.getModel(); Object modelSource = model.getSource(cell); Object modelTarget = model.getTarget(cell); setSource(mapper.getMapping(modelSource, createDependentViews)); setTarget(mapper.getMapping(modelTarget, createDependentViews)); if (modelSource != null && getSource() == null) sourceParentView = getVisibleParent(model, mapper, modelSource); else sourceParentView = null; if (modelTarget != null && getTarget() == null) targetParentView = getVisibleParent(model, mapper, modelTarget); else targetParentView = null; }