/** * Execute this edit such that the next invocation to this method will * invert the last execution. */ public void execute() { for (int i = 0; i < cells.length; i++) { List list = getParentList(cells[i]); if (list != null) { prev[i] = list.indexOf(cells[i]); if (prev[i] >= 0) { list.remove(prev[i]); int n = next[i]; if (n == FRONT) n = list.size(); else if (n == BACK) n = 0; list.add(n, cells[i]); next[i] = prev[i]; } } } updateListeners(); }
/** * Constructs a GraphModelEdit. This modifies the order of the cells in * the model. */ public GraphModelLayerEdit(Object[] cells, int layer) { // A copy is made to avoid changes in the original array affect this listener this.cells = new Object[cells.length]; System.arraycopy(cells, 0, this.cells, 0, cells.length); this.layer = layer; next = new int[cells.length]; prev = new int[cells.length]; updateNext(); // Compute array of changed cells (roots or parents of cells) Set par = new HashSet(); for (int i = 0; i < cells.length; i++) { Object cell = DefaultGraphModel.this.getParent(cells[i]); if (cell == null) cell = cells[i]; par.add(cell); } changed = par.toArray(); }
protected GraphModelLayerEdit createLayerEdit(Object[] cells, int layer) { return new GraphModelLayerEdit(cells, layer); }
/** * Sends <code>cells</code> to back. */ public void toBack(Object[] cells) { GraphModelLayerEdit edit = createLayerEdit(cells, GraphModelLayerEdit.BACK); if (edit != null) { edit.execute(); postEdit(edit); } }
/** * Undoes a change. * * @exception CannotUndoException * if the change cannot be undone */ public void undo() throws CannotUndoException { super.undo(); execute(); }
/** * Brings <code>cells</code> to front. */ public void toFront(Object[] cells) { GraphModelLayerEdit edit = createLayerEdit(cells, GraphModelLayerEdit.FRONT); if (edit != null) { edit.execute(); postEdit(edit); } }
/** * Redoes a change. * * @exception CannotRedoException * if the change cannot be redone */ public void redo() throws CannotRedoException { super.redo(); updateNext(); execute(); }