*/
private JMenuBar createMenuBar(final Home home,
UserPreferences preferences,
final HomeController controller) {
// Create File menu
JMenu fileMenu = new JMenu(this.menuActionMap.get(MenuActionType.FILE_MENU));
addActionToMenu(ActionType.NEW_HOME, fileMenu);
addActionToMenu(ActionType.OPEN, fileMenu);
final JMenu openRecentHomeMenu =
new JMenu(this.menuActionMap.get(MenuActionType.OPEN_RECENT_HOME_MENU));
addActionToMenu(ActionType.DELETE_RECENT_HOMES, openRecentHomeMenu);
openRecentHomeMenu.addMenuListener(new MenuListener() {
public void menuSelected(MenuEvent ev) {
updateOpenRecentHomeMenu(openRecentHomeMenu, controller);
}
public void menuCanceled(MenuEvent ev) {
}
public void menuDeselected(MenuEvent ev) {
}
});
fileMenu.add(openRecentHomeMenu);
fileMenu.addSeparator();
addActionToMenu(ActionType.CLOSE, fileMenu);
addActionToMenu(ActionType.SAVE, fileMenu);
addActionToMenu(ActionType.SAVE_AS, fileMenu);
addActionToMenu(ActionType.SAVE_AND_COMPRESS, fileMenu);
fileMenu.addSeparator();
addActionToMenu(ActionType.PAGE_SETUP, fileMenu);
addActionToMenu(ActionType.PRINT_PREVIEW, fileMenu);
addActionToMenu(ActionType.PRINT, fileMenu);
// Don't add PRINT_TO_PDF, PREFERENCES and EXIT menu items under Mac OS X,
// because PREFERENCES and EXIT items are displayed in application menu
// and PRINT_TO_PDF is available in standard Mac OS X Print dialog
if (!OperatingSystem.isMacOSX()) {
addActionToMenu(ActionType.PRINT_TO_PDF, fileMenu);
fileMenu.addSeparator();
addActionToMenu(ActionType.PREFERENCES, fileMenu);
}
// Create Edit menu
JMenu editMenu = new JMenu(this.menuActionMap.get(MenuActionType.EDIT_MENU));
addActionToMenu(ActionType.UNDO, editMenu);
addActionToMenu(ActionType.REDO, editMenu);
editMenu.addSeparator();
addActionToMenu(ActionType.CUT, editMenu);
addActionToMenu(ActionType.COPY, editMenu);
addActionToMenu(ActionType.PASTE, editMenu);
editMenu.addSeparator();
addActionToMenu(ActionType.DELETE, editMenu);
addActionToMenu(ActionType.SELECT_ALL, editMenu);
// Create Furniture menu
JMenu furnitureMenu = new JMenu(this.menuActionMap.get(MenuActionType.FURNITURE_MENU));
addActionToMenu(ActionType.ADD_HOME_FURNITURE, furnitureMenu);
addActionToMenu(ActionType.MODIFY_FURNITURE, furnitureMenu);
addActionToMenu(ActionType.GROUP_FURNITURE, furnitureMenu);
addActionToMenu(ActionType.UNGROUP_FURNITURE, furnitureMenu);
furnitureMenu.addSeparator();
addActionToMenu(ActionType.ALIGN_FURNITURE_ON_TOP, furnitureMenu);
addActionToMenu(ActionType.ALIGN_FURNITURE_ON_BOTTOM, furnitureMenu);
addActionToMenu(ActionType.ALIGN_FURNITURE_ON_LEFT, furnitureMenu);
addActionToMenu(ActionType.ALIGN_FURNITURE_ON_RIGHT, furnitureMenu);
furnitureMenu.addSeparator();
addActionToMenu(ActionType.IMPORT_FURNITURE, furnitureMenu);
addActionToMenu(ActionType.IMPORT_FURNITURE_LIBRARY, furnitureMenu);
addActionToMenu(ActionType.IMPORT_TEXTURES_LIBRARY, furnitureMenu);
furnitureMenu.addSeparator();
furnitureMenu.add(createFurnitureSortMenu(home, preferences));
furnitureMenu.add(createFurnitureDisplayPropertyMenu(home, preferences));
// Create Plan menu
JMenu planMenu = new JMenu(this.menuActionMap.get(MenuActionType.PLAN_MENU));
addToggleActionToMenu(ActionType.SELECT,
this.selectToggleModel, true, planMenu);
addToggleActionToMenu(ActionType.PAN,
this.panToggleModel, true, planMenu);
addToggleActionToMenu(ActionType.CREATE_WALLS,
this.createWallsToggleModel, true, planMenu);
addToggleActionToMenu(ActionType.CREATE_ROOMS,
this.createRoomsToggleModel, true, planMenu);
addToggleActionToMenu(ActionType.CREATE_DIMENSION_LINES,
this.createDimensionLinesToggleModel, true, planMenu);
addToggleActionToMenu(ActionType.CREATE_LABELS,
this.createLabelsToggleModel, true, planMenu);
planMenu.addSeparator();
JMenuItem lockUnlockBasePlanMenuItem = createLockUnlockBasePlanMenuItem(home, false);
if (lockUnlockBasePlanMenuItem != null) {
planMenu.add(lockUnlockBasePlanMenuItem);
}
addActionToMenu(ActionType.MODIFY_COMPASS, planMenu);
addActionToMenu(ActionType.MODIFY_WALL, planMenu);
addActionToMenu(ActionType.REVERSE_WALL_DIRECTION, planMenu);
addActionToMenu(ActionType.SPLIT_WALL, planMenu);
addActionToMenu(ActionType.MODIFY_ROOM, planMenu);
addActionToMenu(ActionType.MODIFY_LABEL, planMenu);
planMenu.add(createTextStyleMenu(home, preferences, false));
planMenu.addSeparator();
JMenuItem importModifyBackgroundImageMenuItem = createImportModifyBackgroundImageMenuItem(home, false);
if (importModifyBackgroundImageMenuItem != null) {
planMenu.add(importModifyBackgroundImageMenuItem);
}
JMenuItem hideShowBackgroundImageMenuItem = createHideShowBackgroundImageMenuItem(home, false);
if (hideShowBackgroundImageMenuItem != null) {
planMenu.add(hideShowBackgroundImageMenuItem);
}
addActionToMenu(ActionType.DELETE_BACKGROUND_IMAGE, planMenu);
planMenu.addSeparator();
addActionToMenu(ActionType.ZOOM_IN, planMenu);
addActionToMenu(ActionType.ZOOM_OUT, planMenu);
planMenu.addSeparator();
addActionToMenu(ActionType.EXPORT_TO_SVG, planMenu);
// Create 3D Preview menu
JMenu preview3DMenu = new JMenu(this.menuActionMap.get(MenuActionType.VIEW_3D_MENU));
addToggleActionToMenu(ActionType.VIEW_FROM_TOP,
this.viewFromTopToggleModel, true, preview3DMenu);
addToggleActionToMenu(ActionType.VIEW_FROM_OBSERVER,
this.viewFromObserverToggleModel, true, preview3DMenu);
addActionToMenu(ActionType.STORE_POINT_OF_VIEW, preview3DMenu);
preview3DMenu.add(createGoToPointOfViewMenu(home, preferences, controller));
preview3DMenu.addSeparator();
JMenuItem attachDetach3DViewMenuItem = createAttachDetach3DViewMenuItem(controller, false);
if (attachDetach3DViewMenuItem != null) {
preview3DMenu.add(attachDetach3DViewMenuItem);
}
addActionToMenu(ActionType.MODIFY_3D_ATTRIBUTES, preview3DMenu);
preview3DMenu.addSeparator();
addActionToMenu(ActionType.CREATE_PHOTO, preview3DMenu);
addActionToMenu(ActionType.CREATE_VIDEO, preview3DMenu);
preview3DMenu.addSeparator();
addActionToMenu(ActionType.EXPORT_TO_OBJ, preview3DMenu);
// Create Help menu
JMenu helpMenu = new JMenu(this.menuActionMap.get(MenuActionType.HELP_MENU));
addActionToMenu(ActionType.HELP, helpMenu);
if (!OperatingSystem.isMacOSX()) {
addActionToMenu(ActionType.ABOUT, helpMenu);
}
// Add menus to menu bar
JMenuBar menuBar = new JMenuBar();
menuBar.add(fileMenu);
menuBar.add(editMenu);
menuBar.add(furnitureMenu);
if (controller.getPlanController().getView() != null) {
menuBar.add(planMenu);
}
if (controller.getHomeController3D().getView() != null) {
menuBar.add(preview3DMenu);
}
menuBar.add(helpMenu);
// Add plugin actions menu items
for (Action pluginAction : this.pluginActions) {
String pluginMenu = (String)pluginAction.getValue(PluginAction.Property.MENU.name());
if (pluginMenu != null) {
boolean pluginActionAdded = false;
for (int i = 0; i < menuBar.getMenuCount(); i++) {
JMenu menu = menuBar.getMenu(i);
if (menu.getText().equals(pluginMenu)) {
// Add menu item to existing menu
menu.addSeparator();
menu.add(new ResourceAction.MenuItemAction(pluginAction));
pluginActionAdded = true;
break;
}
}
if (!pluginActionAdded) {
// Create missing menu before last menu
JMenu menu = new JMenu(pluginMenu);
menu.add(new ResourceAction.MenuItemAction(pluginAction));
menuBar.add(menu, menuBar.getMenuCount() - 1);
}
}
}