1 | public void setEditEnabled(boolean enabled) {↵ | | 1 | public void setEditEnabled(boolean enabled) {↵
|
2 | if (editMenu != null) {↵ | | 2 | if (editMenu != null) {↵
|
3 | editMenu.setEnabled(enabled);↵ | | 3 | editMenu.setEnabled(enabled);↵
|
4 | }↵ | | 4 | }↵
|
5 | }↵ | | 5 | }↵
|
|
6 | public void setEditAddMenu(JMenu menu) {↵ | | 6 | public void setEditAddMenu(JMenu menu) {↵
|
7 | // If the Add menu already exists, remove it.↵ | | 7 | // If the Add menu already exists, remove it.↵
|
8 | if (edit_add != null) {↵ | | 8 | if (edit_add != null) {↵
|
9 | editMenu.remove(edit_add);↵ | | 9 | editMenu.remove(edit_add);↵
|
10 | }↵ | | 10 | }↵
|
11 | // Insert the Add menu as the first menu item in the Edit menu.↵ | | 11 | // Insert the Add menu as the first menu item in the Edit menu.↵
|
12 | edit_add = menu;↵ | | 12 | edit_add = menu;↵
|
13 | editMenu.insert(edit_add, 0);↵ | | 13 | editMenu.insert(edit_add, 0);↵
|
14 | }↵ | | 14 | }↵
|
|
15 | public void setEditMenu(JPopupMenu menu) {↵ | | 15 | public void setEditMenu(JPopupMenu menu) {↵
|
16 | if (menu != null) {↵ | | 16 | if (menu != null) {↵
|
17 | editMenu.removeAll();↵ | | 17 | editMenu.removeAll();↵
|
18 | Component[] comps = menu.getComponents();↵ | | 18 | Component[] comps = menu.getComponents();↵
|
19 | for (int i = 0; i < comps.length; i++) {↵ | | 19 | for (int i = 0; i < comps.length; i++) {↵
|
20 | editMenu.add(comps[i]);↵ | | 20 | editMenu.add(comps[i]);↵
|
21 | }↵ | | 21 | }↵
|
22 | editMenu.setEnabled(true);↵ | | 22 | editMenu.setEnabled(true);↵
|
23 | } else {↵ | | 23 | } else {↵
|
24 | editMenu.setEnabled(false);↵ | | 24 | // editMenu.setEnabled(false);↵
|
25 | }↵ | | 25 | }↵
|
26 | }↵ | | 26 | }↵
|
|
27 | public void setEditAddEnabled(boolean enabled) {↵ | | 27 | public void setEditAddEnabled(boolean enabled) {↵
|
28 | // There was a NPE being thrown without the null check here.. JKB↵ | | 28 | // There was a NPE being thrown without the null check here.. JKB↵
|
29 | if (edit_add != null) {↵ | | 29 | if (edit_add != null) {↵
|
30 | edit_add.setEnabled(enabled);↵ | | 30 | edit_add.setEnabled(enabled);↵
|
31 | }↵ | | 31 | }↵
|
32 | // If we are enabling the Edit-->Add menu item, then we also need to↵ | | 32 | // If we are enabling the Edit-->Add menu item, then we also need to↵
|
33 | // enable the Edit menu. The Edit menu may already be enabled, but↵ | | 33 | // enable the Edit menu. The Edit menu may already be enabled, but↵
|
34 | // there's no harm it trying to enable it again.↵ | | 34 | // there's no harm it trying to enable it again.↵
|
35 | if (enabled) {↵ | | 35 | if (enabled) {↵
|
36 | setEditEnabled(true);↵ | | 36 | setEditEnabled(true);↵
|
37 | } else {↵ | | 37 | } else {↵
|
38 | // If we are disabling the Edit-->Add menu item and the↵ | | 38 | // If we are disabling the Edit-->Add menu item and the↵
|
39 | // Edit-->Remove menu item is disabled, then we also need to↵ | | 39 | // Edit-->Remove menu item is disabled, then we also need to↵
|
40 | // disable the Edit menu.↵ | | 40 | // disable the Edit menu.↵
|
41 | // The Java Look and Feel Guidelines say to disable a menu if all↵ | | 41 | // The Java Look and Feel Guidelines say to disable a menu if all↵
|
42 | // menu items are disabled.↵ | | 42 | // menu items are disabled.↵
|
43 | if (!edit_remove.isEnabled()) {↵ | | 43 | if (!edit_remove.isEnabled()) {↵
|
44 | editMenu.setEnabled(false);↵ | | 44 | editMenu.setEnabled(false);↵
|
45 | }↵ | | 45 | }↵
|
46 | }↵ | | 46 | }↵
|
47 | }↵ | | 47 | }↵
|
|
48 | public void setEditRemoveEnabled(boolean enabled) {↵ | | 48 | public void setEditRemoveEnabled(boolean enabled) {↵
|
49 | edit_remove.setEnabled(enabled);↵ | | 49 | edit_remove.setEnabled(enabled);↵
|
50 | // If we are enabling the Edit-->Remove menu item, then we also need to↵ | | 50 | // If we are enabling the Edit-->Remove menu item, then we also need to↵
|
51 | // enable the Edit menu. The Edit menu may already be enabled, but↵ | | 51 | // enable the Edit menu. The Edit menu may already be enabled, but↵
|
52 | // there's no harm it trying to enable it again.↵ | | 52 | // there's no harm it trying to enable it again.↵
|
53 | if (enabled) {↵ | | 53 | if (enabled) {↵
|
54 | setEditEnabled(true);↵ | | 54 | setEditEnabled(true);↵
|
55 | } else {↵ | | 55 | } else {↵
|
56 | // If we are disabling the Edit-->Remove menu item and the↵ | | 56 | // If we are disabling the Edit-->Remove menu item and the↵
|
57 | // Edit-->Add menu item is disabled, then we also need to disable↵ | | 57 | // Edit-->Add menu item is disabled, then we also need to disable↵
|
58 | // the Edit menu.↵ | | 58 | // the Edit menu.↵
|
59 | // The Java Look and Feel Guidelines say to disable a menu if all↵ | | 59 | // The Java Look and Feel Guidelines say to disable a menu if all↵
|
60 | // menu items are disabled.↵ | | 60 | // menu items are disabled.↵
|
61 | if (!edit_add.isEnabled()) {↵ | | 61 | if (!edit_add.isEnabled()) {↵
|
62 | editMenu.setEnabled(false);↵ | | 62 | editMenu.setEnabled(false);↵
|
63 | }↵ | | 63 | }↵
|
64 | }↵ | | 64 | }↵
|
65 | }↵ | | 65 | }↵
|
|
66 | /**↵ | | 66 | /**↵
|
67 | * Creates the MenuBar for this application. I believe in my heart that this↵ | | 67 | * Creates the MenuBar for this application. I believe in my heart that this↵
|
68 | * should be defined in a file somewhere, but that is for later.↵ | | 68 | * should be defined in a file somewhere, but that is for later.↵
|
69 | */↵ | | 69 | */↵
|
70 | public void createMenuBar() {↵ | | 70 | public void createMenuBar() {↵
|
71 | makeFileMenu();↵ | | 71 | makeFileMenu();↵
|
72 | makeEditMenu();↵ | | 72 | makeEditMenu();↵
|
73 | makeRunMenu();↵ | | 73 | makeRunMenu();↵
|
74 | makeOptionsMenu();↵ | | 74 | makeOptionsMenu();↵
|
75 | makeHelpMenu();↵ | | 75 | makeHelpMenu();↵
|
76 | this.add(fileMenu);↵ | | 76 | this.add(fileMenu);↵
|
77 | this.add(editMenu);↵ | | 77 | this.add(editMenu);↵
|
78 | this.add(runMenu);↵ | | 78 | this.add(runMenu);↵
|
79 | this.add(optionsMenu);↵ | | 79 | this.add(optionsMenu);↵
|
80 | this.add(helpMenu) | | 80 | this.add(helpMenu)
|