Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FrameInjector |
|
| 1.0;1 |
1 | /* | |
2 | * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport | |
3 | * (http://www.vbs.admin.ch) | |
4 | * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch) | |
5 | * All rights reserved. | |
6 | * | |
7 | * Licensed under the Open Permis License which accompanies this distribution, | |
8 | * and is available at http://www.openpermis.org/BSDlicenceKent.txt | |
9 | */ | |
10 | package org.openpermis.editor.policy; | |
11 | ||
12 | import java.awt.Dimension; | |
13 | import java.lang.reflect.Type; | |
14 | ||
15 | import javax.swing.JFrame; | |
16 | ||
17 | import org.jdesktop.application.ApplicationContext; | |
18 | import org.jdesktop.application.ResourceMap; | |
19 | import org.jdesktop.swingx.JXFrame; | |
20 | import org.picocontainer.PicoContainer; | |
21 | import org.picocontainer.injectors.FactoryInjector; | |
22 | ||
23 | ||
24 | ||
25 | /** | |
26 | * Pico factory injector that creates JXFrame for policy views. | |
27 | * @since 0.1.0 | |
28 | */ | |
29 | 0 | public class FrameInjector |
30 | extends FactoryInjector<JXFrame> | |
31 | { | |
32 | ||
33 | //---- Static | |
34 | ||
35 | /** | |
36 | * Application resource key for the default title of frames created. | |
37 | * @since 0.1.0 | |
38 | */ | |
39 | private static final String TITLE = "Application.frameTitle"; | |
40 | ||
41 | /** | |
42 | * Application resource key for the default image icon of frames created. | |
43 | * @since 0.1.0 | |
44 | */ | |
45 | private static final String ICON = "Application.frameIcon"; | |
46 | ||
47 | /** | |
48 | * Application resource key for the default size of frames created. | |
49 | * @since 0.1.0 | |
50 | */ | |
51 | private static final String SIZE = "Application.frameSize"; | |
52 | ||
53 | /** | |
54 | * The default name used to store the frame state. | |
55 | * <p>The swing application framework will use this name to store the frame state, | |
56 | * will create a file called <tt>window.xml</tt> in the application settings directory.</p> | |
57 | * @since 0.1.0 | |
58 | */ | |
59 | private static final String NAME = "window"; | |
60 | ||
61 | ||
62 | //---- FactoryInjector | |
63 | ||
64 | /** | |
65 | * @deprecated No longer supported as of Pico 2.2. | |
66 | * @since 0.3.0 | |
67 | */ | |
68 | @Override | |
69 | @Deprecated | |
70 | public JXFrame getComponentInstance (PicoContainer container) { | |
71 | 0 | return super.getComponentInstance(container); |
72 | } | |
73 | ||
74 | /** | |
75 | * @since 0.1.0 | |
76 | */ | |
77 | @Override | |
78 | public JXFrame getComponentInstance (PicoContainer container, Type into) { | |
79 | 0 | final ApplicationContext appContext = container.getComponent(ApplicationContext.class); |
80 | 0 | final ResourceMap resourceMap = appContext.getResourceMap(Application.class); |
81 | 0 | final JXFrame frame = new JXFrame(); |
82 | 0 | frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); |
83 | 0 | frame.setIconImage(resourceMap.getImageIcon(ICON).getImage()); |
84 | 0 | frame.setTitle(resourceMap.getString(TITLE)); |
85 | 0 | frame.setPreferredSize((Dimension) resourceMap.getObject(SIZE, Dimension.class)); |
86 | 0 | frame.setName(NAME); |
87 | 0 | return frame; |
88 | } | |
89 | ||
90 | } |