1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- class SelectionHandler {
- constructor(getUserId, userColors) {
- this.userColors = userColors;
- this.getUserId = getUserId;
- this.map = new Map();
- }
- install(graph, controller) {
- graph.selectionModel.addListener(mxEvent.CHANGE, (source, eventObj) => {
- if (listenerEnabled) {
- const {added, removed} = eventObj.properties;
- controller.addInput(
- "broadcast",
- // "selection_change",
- "in",
- [{
- userId: this.getUserId(),
- addedIds: removed ? removed.map(cell => cell.id) : [],
- removedIds: added ? added.map(cell => cell.id) : [],
- }],
- controller.wallclockToSimtime(),
- );
- }
- });
- controller.addMyOwnOutputListener({
- 'add': event => {
- if (event.name === "selection_change") {
- const [{userId, addedIds, removedIds}] = event.parameters;
- const color = this.userColors.getColor(userId);
- for (const cellId of addedIds) {
- const cell = graph.model.cells[cellId];
- const highlight = new mxCellHighlight(graph, color,
- 6); // width
- highlight.highlight(graph.view.getState(cell));
- this.map.set(cellId, highlight);
- }
- for (const cellId of removedIds) {
- const cell = graph.model.cells[cellId];
- const highlight = this.map.get(cellId);
- highlight.destroy();
- this.map.delete(cellId);
- }
- }
- }
- })
- }
- clearAll() {
- this.map.forEach(highlight => highlight.destroy());
- this.map.clear();
- }
- }
|