/
tool.service.ts
60 lines (53 loc) · 1.53 KB
/
tool.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {Injectable} from 'angular2/core';
import {ToolbarOption} from '../../controls';
import {EntityCreatorTool, BaseTool, EntityMoveTool} from '../tools';
/**
* Provide access to tools for the canvas.
* @return {[type]} [description]
*/
@Injectable()
export class ToolService {
private _tools : {[key:string]:BaseTool} = {};
private _default : BaseTool;
constructor(entityCreator : EntityCreatorTool,
entityMoveTool : EntityMoveTool) {
this._default = entityMoveTool;
this.addTool(entityCreator);
this.addTool(entityMoveTool);
}
/**
* The default tool.
*/
get defaultTool() : BaseTool {
return this._default;
}
/**
* Get the select options for the available tools.
*/
get toolOptions() : ToolbarOption[] {
var options : ToolbarOption[] = [];
for (var toolKey in this._tools) {
options.push({
value : toolKey,
title : this._tools[toolKey].label,
icon : this._tools[toolKey].icon
});
}
return options;
}
/**
* Get the tool corresponding to the given key.
* @param key Key of the tool that should be retrieved.
* @return A tool instance.
*/
getTool(key : string) : BaseTool {
return this._tools[key];
}
/**
* Add a tool to the storage in the system.
* @param baseTool Tool to add to the service.
*/
addTool(baseTool : BaseTool) {
this._tools[baseTool.key] = baseTool;
}
}