/** * Constructs a new model codec. */ public mxModelCodec() { this(new mxGraphModel()); }
Object source = getTerminal(edge, true); Object target = getTerminal(edge, false); Object cell = null; while (source != null && !isEdge(source) && getGeometry(source) != null && getGeometry(source).isRelative()) source = getParent(source); while (target != null && !isEdge(target) && getGeometry(target) != null && getGeometry(target).isRelative()) target = getParent(target); if (isAncestor(root, source) && isAncestor(root, target)) cell = getParent(source); cell = getNearestCommonAncestor(source, target); && (getParent(cell) != root || isAncestor(cell, edge)) && getParent(edge) != cell) mxGeometry geo = getGeometry(edge); mxPoint origin1 = getOrigin(getParent(edge)); mxPoint origin2 = getOrigin(cell); setGeometry(edge, geo);
throws CloneNotSupportedException beginUpdate(); try mergeChildrenImpl(from, to, cloneAllEdges, mapping); Object terminal = getTerminal(edge, true); setTerminal(cell, terminal, true); terminal = getTerminal(edge, false); setTerminal(cell, terminal, false); endUpdate();
/** * Constructs a new graph model. If no root is specified * then a new root mxCell with a default layer is created. * * @param root Cell that represents the root cell. */ public mxGraphModel(Object root) { currentEdit = createUndoableEdit(); if (root != null) { setRoot(root); } else { clear(); } }
public Object[] cloneCells(Object[] cells, boolean includeChildren) { Map<Object, Object> mapping = new Hashtable<Object, Object>(); Object[] clones = new Object[cells.length]; for (int i = 0; i < cells.length; i++) { try { clones[i] = cloneCell(cells[i], mapping, includeChildren); } catch (CloneNotSupportedException e) { // ignore } } for (int i = 0; i < cells.length; i++) { restoreClone(clones[i], cells[i], mapping); } return clones; }
/** * Executes the given atomic change and adds it to the current edit. * * @param change Atomic change to be executed. */ public void execute(mxAtomicGraphModelChange change) { change.execute(); beginUpdate(); currentEdit.add(change); fireEvent(new mxEventObject(mxEvent.EXECUTE, "change", change)); endUpdate(); }
throws CloneNotSupportedException beginUpdate(); try mxICell target = (mxICell) ((id != null && (!isEdge(cell) || !cloneAllEdges)) ? getCell(id) : null); cellAdded(target); mergeChildrenImpl(cell, target, cloneAllEdges, mapping); endUpdate();
mxICell previous = (mxICell) getParent(cell); if (!contains(previous) && parent != null) cellAdded(cell); cellRemoved(cell);
/** * Inner helper method for cloning cells recursively. */ protected Object cloneCell(Object cell, Map<Object, Object> mapping, boolean includeChildren) throws CloneNotSupportedException { if (cell instanceof mxICell) { mxICell mxc = (mxICell) ((mxICell) cell).clone(); mapping.put(cell, mxc); if (includeChildren) { int childCount = getChildCount(cell); for (int i = 0; i < childCount; i++) { Object clone = cloneCell(getChildAt(cell, i), mapping, true); mxc.insert((mxICell) clone); } } return mxc; } return null; }
model = new mxGraphModel(); model.setRoot(rootCell);
mxGraphModel modelCopy = new mxGraphModel(); mxGraph graphCopy = new mxGraph(modelCopy); graphCopy.addCells(cells); currSrcValue = Integer.parseInt((String) modelCopy.getValue(aGraphCopy.getTerminal(currEdge, true))); currDestValue = Integer.parseInt((String) modelCopy.getValue(aGraphCopy.getTerminal(currEdge, false)));
oldModel.removeListener(updateHandler); newModel.addListener(mxEvent.CHANGE, updateHandler);
/** * Changes the root of the model. */ public void execute() { collapsed = previous; previous = ((mxGraphModel) model).collapsedStateForCellChanged( cell, previous); }
/** * Inner callback to change the root of the model and update the internal * datastructures, such as cells and nextId. Returns the previous root. */ protected Object rootChanged(Object root) { Object oldRoot = this.root; this.root = (mxICell) root; // Resets counters and datastructures nextId = 0; cells = null; cellAdded(root); return oldRoot; }
/** * Invoked after a cell has been removed from the model. This recursively * removes the cell from its terminals and removes the mapping from the Id * to the cell. * * @param cell Cell that has been removed. */ protected void cellRemoved(Object cell) { if (cell instanceof mxICell) { mxICell mxc = (mxICell) cell; int childCount = mxc.getChildCount(); for (int i = 0; i < childCount; i++) { cellRemoved(mxc.getChildAt(i)); } if (cells != null && mxc.getId() != null) { cells.remove(mxc.getId()); } } }
throws CloneNotSupportedException beginUpdate(); try mxICell target = (mxICell) ((id != null && (!isEdge(cell) || !cloneAllEdges)) ? getCell(id) : null); cellAdded(target); mergeChildrenImpl(cell, target, cloneAllEdges, mapping); endUpdate();
mxICell previous = (mxICell) getParent(cell); if (!contains(previous) && parent != null) cellAdded(cell); cellRemoved(cell);
/** * Executes the given atomic change and adds it to the current edit. * * @param change Atomic change to be executed. */ public void execute(mxAtomicGraphModelChange change) { change.execute(); beginUpdate(); currentEdit.add(change); fireEvent(new mxEventObject(mxEvent.EXECUTE, "change", change)); endUpdate(); }