public class ToolKit
1:
2: package draw1;
3:
4: import java.util.*;
5: import scribble3.Tool;
6:
7: public class ToolKit {
8:
9: public ToolKit() {
10: }
11:
12: /**
13: Add a new tool to the tool kit.
14: Return the index of the new tool.
15: */
16: public int addTool(Tool tool) {
17: if (tool != null) {
18: tools.add(tool);
19: return (tools.size() - 1);
20: }
21: return -1;
22: }
23:
24: public int getToolCount() {
25: return tools.size();
26: }
27:
28: public Tool getTool(int i) {
29: if (i >= 0 &&
30: i < tools.size()) {
31: return (Tool) tools.get(i);
32: }
33: return null;
34: }
35:
36: public Tool findTool(String name) {
37: if (name != null) {
38: for (int i = 0; i < tools.size(); i++) {
39: Tool tool = (Tool) tools.get(i);
40: if (name.equals(tool.getName())) {
41: return tool;
42: }
43: }
44: }
45: return null;
46: }
47:
48: public void setSelectedTool(int i) {
49: Tool tool = getTool(i);
50: if (tool != null) {
51: selectedTool = tool;
52: }
53: }
54:
55: public Tool setSelectedTool(String name) {
56: Tool tool = findTool(name);
57: if (tool != null) {
58: selectedTool = tool;
59: }
60: return tool;
61: }
62:
63: public void setSelectedTool(Tool tool) {
64: selectedTool = tool;
65: }
66:
67: public Tool getSelectedTool() {
68: return selectedTool;
69: }
70:
71: protected List tools = new ArrayList(16);
72: protected Tool selectedTool = null;
73:
74: }