01 package net.sf.annocon.examples.configuration.menu;
02
03 import javax.swing.JFrame;
04 import javax.swing.JMenu;
05 import javax.swing.JMenuBar;
06 import javax.swing.JMenuItem;
07
08 import net.sf.annocon.annotations.Configuration;
09 import net.sf.annocon.annotations.Context;
10 import net.sf.annocon.annotations.Service;
11 import net.sf.annocon.annotations.Subcontext;
12
13 /**
14 * Context for swing application. Demonstrates how a subcontext contributes to a
15 * configuration defined in the main context. The subcontext
16 * {@link net.sf.annocon.examples.configuration.menu.Plugin1} adds menu items to
17 * the main menu defined in this context. This plugin-like mechanism allows to
18 * reuse a subcontext in different applications.
19 *
20 * @author Achim Huegen
21 */
22 @Context(id = "swing.application")
23 public class SwingContext
24 {
25 @Service(id = "MainFrame")
26 public JFrame getMainFrame()
27 {
28 JFrame frame = new JFrame("Menu-Contributions");
29 frame.setBounds(10, 10, 200, 200);
30 frame.setJMenuBar(getMenuBar());
31 return frame;
32 }
33
34 @Configuration(id = "Menu")
35 public JMenuBar getMenuBar()
36 {
37 JMenuBar menuBar = new JMenuBar();
38
39 JMenu menu = new JMenu("File");
40 menuBar.add(menu);
41
42 JMenuItem item = new JMenuItem("Exit");
43 menu.add(item);
44
45 return menuBar;
46 }
47
48 @Subcontext()
49 public Plugin1 getPlugin1()
50 {
51 return new Plugin1();
52 }
53
54 }
|