public void setEditEnabled(boolean enabled) {
if (editMenu != null) {
editMenu.setEnabled(enabled);
}
}
public void setEditAddMenu(JMenu menu) {
// If the Add menu already exists, remove it.
if (edit_add != null) {
editMenu.remove(edit_add);
}
// Insert the Add menu as the first menu item in the Edit menu.
edit_add = menu;
editMenu.insert(edit_add, 0);
}
public void setEditMenu(JPopupMenu menu) {
if (menu != null) {
editMenu.removeAll();
Component[] comps = menu.getComponents();
for (int i = 0; i < comps.length; i++) {
editMenu.add(comps[i]);
}
editMenu.setEnabled(true);
}
else
[[#variabledf01700]]
}
public void setEditAddEnabled(boolean enabled) {
// There was a NPE being thrown without the null check here.. JKB
if (edit_add != null) {
edit_add.setEnabled(enabled);
}
// If we are enabling the Edit-->Add menu item, then we also need to
// enable the Edit menu. The Edit menu may already be enabled, but
// there's no harm it trying to enable it again.
if (enabled) {
setEditEnabled(true);
}
else {
// If we are disabling the Edit-->Add menu item and the
// Edit-->Remove menu item is disabled, then we also need to
// disable the Edit menu.
// The Java Look and Feel Guidelines say to disable a menu if all
// menu items are disabled.
if ( !edit_remove.isEnabled()) {
editMenu.setEnabled(false);
}
}
}
public void setEditRemoveEnabled(boolean enabled) {
edit_remove.setEnabled(enabled);
// If we are enabling the Edit-->Remove menu item, then we also need to
// enable the Edit menu. The Edit menu may already be enabled, but
// there's no harm it trying to enable it again.
if (enabled) {
setEditEnabled(true);
}
else {
// If we are disabling the Edit-->Remove menu item and the
// Edit-->Add menu item is disabled, then we also need to disable
// the Edit menu.
// The Java Look and Feel Guidelines say to disable a menu if all
// menu items are disabled.
if ( !edit_add.isEnabled()) {
editMenu.setEnabled(false);
}
}
}
/**
* Creates the MenuBar for this application. I believe in my heart that this
* should be defined in a file somewhere, but that is for later.
*/
public void createMenuBar() {
makeFileMenu();
makeEditMenu();
makeRunMenu();
makeOptionsMenu();
makeHelpMenu();
this.add(fileMenu);
this.add(editMenu);
this.add(runMenu);
this.add(optionsMenu);
this.add(helpMenu);
}
|