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.hivegui.docking; |
16 | |
17 | import javax.swing.Icon; |
18 | import javax.swing.JComponent; |
19 | |
20 | import org.flexdock.view.View; |
21 | import org.jdesktop.application.ApplicationContext; |
22 | |
23 | import net.sourceforge.hivegui.application.ApplicationContextHolder; |
24 | |
25 | public class DefaultViewFactory implements ViewFactory |
26 | { |
27 | public void setContextHolder(ApplicationContextHolder holder) |
28 | { |
29 | _context = holder.getContext(); |
30 | } |
31 | |
32 | public View createView(String id, JComponent content) |
33 | { |
34 | if (content == null) |
35 | { |
36 | return null; |
37 | } |
38 | View view = createView(id); |
39 | view.setName(id); |
40 | view.setContentPane(content); |
41 | initView(view, id); |
42 | _context.getResourceMap(View.class).injectComponents(view); |
43 | return view; |
44 | } |
45 | |
46 | protected View createView(String id) |
47 | { |
48 | return new ViewBean(id); |
49 | } |
50 | |
51 | protected void initView(View view, String id) |
52 | { |
53 | if (EmptyableViewport.EMPTY_VIEW_ID.equals(id)) |
54 | { |
55 | view.setTitlebar(null); |
56 | } |
57 | else |
58 | { |
59 | view.addAction(View.CLOSE_ACTION); |
60 | } |
61 | } |
62 | |
63 | // This class exists only to make flexdock's View more JavaBean-compliant |
64 | // (at least with regard to the "icon" property, renamed to "viewIcon") |
65 | static protected class ViewBean extends View |
66 | { |
67 | public ViewBean(String id) |
68 | { |
69 | super(id); |
70 | } |
71 | |
72 | public Icon getViewIcon() |
73 | { |
74 | return (titlepane == null ? null : titlepane.getIcon()); |
75 | } |
76 | |
77 | public void setViewIcon(Icon icon) |
78 | { |
79 | setIcon(icon); |
80 | } |
81 | } |
82 | |
83 | protected ApplicationContext _context; |
84 | } |