1 package com.explosion.expf.menusandtools.menu;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.awt.Component;
23 import java.util.Map;
24
25 import javax.swing.JMenu;
26
27 import com.explosion.expf.menusandtools.CookieChecker;
28 import com.explosion.expf.menusandtools.menu.segmented.ExpMenuSegment;
29 import com.explosion.expf.menusandtools.menu.segmented.ExpSegmentedMenu;
30 import com.explosion.expf.menusandtools.menu.segmented.SegmentedMenuHelper;
31
32 /***
33 * @author Stephen Cowx
34 */
35
36 public class ExpMenu extends JMenu implements ExpSegmentedMenu
37 {
38 private static org.apache.log4j.Logger log = org.apache.log4j.LogManager.getLogger(ExpMenu.class);
39 private CookieChecker cookieChecker;
40 private SegmentedMenuHelper menuHelper;
41
42 /***
43 * Creates a new ExpSegmentedMenu if this type
44 * @param name
45 * @param cookieName
46 * @param enabledThreshold
47 */
48 public ExpMenu(String name, String cookieName, int enabledThreshold)
49 {
50 super(name);
51 this.cookieChecker = new CookieChecker(cookieName, enabledThreshold);
52 this.menuHelper = new SegmentedMenuHelper(this, this);
53 }
54
55 /***
56 * This method checks for an object of type Integer
57 */
58 public void checkEnabled(Map componentCookies, Map localCookies,Map globalCookies) throws Exception
59 {
60 cookieChecker.checkEnabled(componentCookies, localCookies, globalCookies, this);
61 }
62
63 /***
64 * Creates a new segment in this menu
65 */
66 public ExpMenuSegment createNewSegment(int relativePositionOfSegmentOnMenu) throws Exception
67 {
68 return menuHelper.createNewSegment(relativePositionOfSegmentOnMenu);
69 }
70
71 /***
72 * @param segment
73 * @param item
74 * @throws InvalidOrUnknownSegmentException
75 */
76 public void addElementToSegment(ExpMenuSegment segment, Component item) throws InvalidOrUnknownSegmentException
77 {
78 menuHelper.addElementToSegment(segment, item);
79 }
80
81 /***
82 * Removes all the elements except the separator from this menu
83 * @param segment
84 * @param item
85 * @throws InvalidOrUnknownSegmentException
86 */
87 public void removeSegment(ExpMenuSegment segment) throws InvalidOrUnknownSegmentException
88 {
89 menuHelper.removeSegment(segment);
90 }
91
92 /***
93 * Returns the first segment in this helper or null if there isn't one
94 * @return
95 */
96 public ExpMenuSegment getFirstSegment()
97 {
98 return menuHelper.getFirstSegment();
99 }
100
101 /***
102 * Returns the last segment in this helper or null if there isn't one
103 * @return
104 */
105 public ExpMenuSegment getLastSegment()
106 {
107 return menuHelper.getLastSegment();
108 }
109
110 }
111