1 | // Copyright 2004-2007 Jean-Francois Poilpret |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | package net.sourceforge.hiveboard.drawing; |
16 | |
17 | import java.awt.Cursor; |
18 | import java.util.Map; |
19 | |
20 | import javax.swing.ActionMap; |
21 | import javax.swing.JComponent; |
22 | |
23 | import org.jdesktop.application.ApplicationContext; |
24 | import org.jdesktop.application.Resource; |
25 | import org.jdesktop.application.ResourceMap; |
26 | |
27 | import net.sourceforge.hivegui.application.ApplicationContextHolder; |
28 | import net.sourceforge.hivegui.application.HiveGuiApplicationMain; |
29 | |
30 | public abstract class AbstractTool implements Tool |
31 | { |
32 | public void setPropertyMap(Map<String, Object> properties) |
33 | { |
34 | _properties = properties; |
35 | initProperty(); |
36 | } |
37 | |
38 | public void setApplicationContextHolder(ApplicationContextHolder holder) |
39 | { |
40 | _context = holder.getContext(); |
41 | _application = holder.getApplication(); |
42 | } |
43 | |
44 | public Cursor getCursor() |
45 | { |
46 | return _cursor; |
47 | } |
48 | |
49 | final public void init(String toolName, ToolHandler handler) |
50 | { |
51 | _name = toolName; |
52 | _handler = handler; |
53 | |
54 | initName(); |
55 | // Set actions of tool |
56 | ActionMap actions = _context.getActionMap(AbstractTool.class, this); |
57 | initActions(actions); |
58 | // Set resources of tool |
59 | ResourceMap map = _context.getResourceMap(getClass(), AbstractTool.class); |
60 | initResources(map); |
61 | } |
62 | |
63 | protected void initName() |
64 | { |
65 | } |
66 | |
67 | protected void initProperty() |
68 | { |
69 | } |
70 | |
71 | protected void initResources(ResourceMap map) |
72 | { |
73 | map.injectFields(this, _name); |
74 | for (JComponent comp: getToolBarComponents()) |
75 | { |
76 | map.injectComponent(comp); |
77 | } |
78 | } |
79 | |
80 | protected void initActions(ActionMap map) |
81 | { |
82 | } |
83 | |
84 | protected ApplicationContext _context; |
85 | protected HiveGuiApplicationMain _application; |
86 | protected Map<String, Object> _properties; |
87 | protected ToolHandler _handler; |
88 | protected String _name; |
89 | @Resource(key = "toolcursor") |
90 | protected Cursor _cursor; |
91 | } |