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.docking; |
16 | |
17 | import javax.swing.JComponent; |
18 | |
19 | import org.jdesktop.application.ApplicationContext; |
20 | |
21 | import net.sourceforge.hiveboard.view.DrawingAreaPanel; |
22 | import net.sourceforge.hivegui.application.ApplicationContextHolder; |
23 | import net.sourceforge.hivegui.docking.EmptyableViewport; |
24 | import net.sourceforge.hivegui.docking.ViewContentFactory; |
25 | import net.sourceforge.hiveutils.service.ObjectBuilder; |
26 | |
27 | public class HiveBoardViewContentFactory implements ViewContentFactory |
28 | { |
29 | public HiveBoardViewContentFactory( ApplicationContextHolder holder, |
30 | ObjectBuilder builder) |
31 | { |
32 | _context = holder.getContext(); |
33 | _builder = builder; |
34 | } |
35 | |
36 | public JComponent createContent(String id) |
37 | { |
38 | Views kind = Views.getView(id); |
39 | JComponent content = null; |
40 | if (kind != null) |
41 | { |
42 | content = (JComponent) _builder.create(kind.id()); |
43 | content.setName(kind.id()); |
44 | } |
45 | else if (EmptyableViewport.EMPTY_VIEW_ID.equals(id)) |
46 | { |
47 | content = new DrawingAreaPanel(); |
48 | content.setName(EmptyableViewport.EMPTY_VIEW_ID); |
49 | } |
50 | if (content != null) |
51 | { |
52 | _context.getResourceMap(content.getClass()).injectComponents(content); |
53 | } |
54 | return content; |
55 | } |
56 | |
57 | protected final ObjectBuilder _builder; |
58 | protected final ApplicationContext _context; |
59 | } |