Singleton that implements a clipboard for graph cells.

Clipboard.copy(graph);
Clipboard.paste(graph2);

This copies the selection cells from the graph to the clipboard and pastes them into graph2.

For fine-grained control of the clipboard data the graph.canExportCell and graph.canImportCell functions can be overridden.

To restore previous parents for pasted cells, the implementation for copy and paste can be changed as follows.

Clipboard.copy = function(graph, cells)
{
cells = cells || graph.getSelectionCells();
var result = graph.getExportableCells(cells);

Clipboard.parents = new Object();

for (var i = 0; i < result.length; i++)
{
Clipboard.parents[i] = graph.model.getParent(cells[i]);
}

Clipboard.insertCount = 1;
Clipboard.setCells(graph.cloneCells(result));

return result;
};

Clipboard.paste = function(graph)
{
if (!Clipboard.isEmpty())
{
var cells = graph.getImportableCells(Clipboard.getCells());
var delta = Clipboard.insertCount * Clipboard.STEPSIZE;
var parent = graph.getDefaultParent();

graph.model.beginUpdate();
try
{
for (var i = 0; i < cells.length; i++)
{
var tmp = (Clipboard.parents != null && graph.model.contains(Clipboard.parents[i])) ?
Clipboard.parents[i] : parent;
cells[i] = graph.importCells([cells[i]], delta, delta, tmp)[0];
}
}
finally
{
graph.model.endUpdate();
}

// Increments the counter and selects the inserted cells
Clipboard.insertCount++;
graph.setSelectionCells(cells);
}
};

Constructors

Properties

cells: Cell[]

Holds the array of mxCell currently in the clipboard.

insertCount: number = 1

Counts the number of times the clipboard data has been inserted.

STEPSIZE: number = 10

Defines the step size to offset the cells after each paste operation. Default is 10.

Methods

  • Copies the given array of mxCell from the specified graph to cells. Returns the original array of cells that has been cloned. Descendants of cells in the array are ignored.

    Parameters

    • graph: Graph

      graph that contains the cells to be copied.

    • Optionalcells: Cell[]

      Optional array of mxCell to be copied.

    Returns Cell[]

  • Cuts the given array of mxCell from the specified graph. If cells is null then the selection cells of the graph will be used. Returns the cells that have been cut from the graph.

    Parameters

    • graph: Graph

      graph that contains the cells to be cut.

    • cells: Cell[] = []

      Optional array of mxCell to be cut.

    Returns Cell[]

  • Returns true if the clipboard currently has not data stored.

    Returns boolean

  • Pastes the cells into the specified graph restoring the relation to parents, if possible. If the parents are no longer in the graph or invisible then the cells are added to the graph's default or into the swimlane under the cell's new location if one exists. The cells are added to the graph using graph.importCells and returned.

    Parameters

    Returns null | Cell[]

  • Hook to remove the given cells from the given graph after a cut operation.

    Parameters

    • graph: Graph

      graph that contains the cells to be cut.

    • cells: Cell[]

      Array of mxCell to be cut.

    Returns void

  • Sets the cells in the clipboard. Fires a mxEvent.CHANGE event.

    Parameters

    Returns void