final HomeController controller = new HomeAppletController(
home, AppletApplication.this, getViewFactory(), getContentManager(), getPluginManager(),
newHomeEnabled, openEnabled, saveEnabled, saveAsEnabled);
JRootPane homeView = (JRootPane)controller.getView();
// Remove menu bar
homeView.setJMenuBar(null);
// As the applet has no menu, activate accelerators directly on home view
for (HomeView.ActionType actionType : HomeView.ActionType.values()) {
Action action = homeView.getActionMap().get(actionType);
if (action != null) {
ResourceAction.MenuItemAction menuAction = new ResourceAction.MenuItemAction(action);
KeyStroke accelerator = (KeyStroke)menuAction.getValue(Action.ACCELERATOR_KEY);
if (accelerator != null) {
homeView.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(accelerator, actionType);
}
}
}
// Change default buttons in toolbar
JToolBar toolBar = (JToolBar)homeView.getContentPane().getComponent(0);
toolBar.setFloatable(false);
// Retrieve all buttons that are plug-in actions
List<JComponent> pluginButtons = new ArrayList<JComponent>();
for (int i = 0; i < toolBar.getComponentCount(); i++) {
JComponent component = (JComponent)toolBar.getComponent(i);
if (component instanceof AbstractButton
&& ((AbstractButton)component).getAction().
getValue(PluginAction.Property.TOOL_BAR.name()) == Boolean.TRUE) {
pluginButtons.add(component);
}
}
toolBar.removeAll();
// Add New, Open, Save, Save as buttons if they are enabled
Action newHomeAction = getToolBarAction(homeView, HomeView.ActionType.NEW_HOME);
if (newHomeAction != null && newHomeAction.isEnabled()) {
toolBar.add(newHomeAction);
}
Action openAction = getToolBarAction(homeView, HomeView.ActionType.OPEN);
if (openAction != null && openAction.isEnabled()) {
toolBar.add(openAction);
}
Action saveAction = getToolBarAction(homeView, HomeView.ActionType.SAVE);
if (saveAction != null && saveAction.isEnabled()) {
toolBar.add(saveAction);
}
Action saveAsAction = getToolBarAction(homeView, HomeView.ActionType.SAVE_AS);
if (saveAsAction != null && saveAsAction.isEnabled()) {
toolBar.add(saveAsAction);
}
if (getAppletBooleanParameter(this.applet, ENABLE_EXPORT_TO_SH3D)) {
try {
// Add export to SH3D action
Action exportToSH3DAction = new ControllerAction(getUserPreferences(),
AppletApplication.class, "EXPORT_TO_SH3D", controller, "exportToSH3D");
exportToSH3DAction.setEnabled(true);
toolBar.add(new ResourceAction.ToolBarAction(exportToSH3DAction));
} catch (NoSuchMethodException ex) {
ex.printStackTrace();
}
}
if (toolBar.getComponentCount() > 0) {
toolBar.add(Box.createRigidArea(new Dimension(2, 2)));
}
addToolBarAction(homeView, HomeView.ActionType.PAGE_SETUP, toolBar);
addToolBarAction(homeView, HomeView.ActionType.PRINT, toolBar);
Action printToPdfAction = getToolBarAction(homeView, HomeView.ActionType.PRINT_TO_PDF);
if (printToPdfAction != null
&& getAppletBooleanParameter(this.applet, ENABLE_PRINT_TO_PDF)
&& !OperatingSystem.isMacOSX()) {
controller.getView().setEnabled(HomeView.ActionType.PRINT_TO_PDF, true);
toolBar.add(printToPdfAction);
}
Action preferencesAction = getToolBarAction(homeView, HomeView.ActionType.PREFERENCES);
if (preferencesAction != null) {
toolBar.add(Box.createRigidArea(new Dimension(2, 2)));
toolBar.add(preferencesAction);
}
toolBar.addSeparator();
addToolBarAction(homeView, HomeView.ActionType.UNDO, toolBar);
addToolBarAction(homeView, HomeView.ActionType.REDO, toolBar);
toolBar.add(Box.createRigidArea(new Dimension(2, 2)));
addToolBarAction(homeView, HomeView.ActionType.CUT, toolBar);
addToolBarAction(homeView, HomeView.ActionType.COPY, toolBar);
addToolBarAction(homeView, HomeView.ActionType.PASTE, toolBar);
toolBar.add(Box.createRigidArea(new Dimension(2, 2)));
addToolBarAction(homeView, HomeView.ActionType.DELETE, toolBar);
toolBar.addSeparator();
Action addHomeFurnitureAction = getToolBarAction(homeView, HomeView.ActionType.ADD_HOME_FURNITURE);
if (addHomeFurnitureAction != null) {
toolBar.add(addHomeFurnitureAction);
toolBar.addSeparator();
}
final JToggleButton selectToggleButton =
new JToggleButton(getToolBarAction(homeView, HomeView.ActionType.SELECT));
selectToggleButton.setSelected(true);
toolBar.add(selectToggleButton);
final JToggleButton panToggleButton =
new JToggleButton(getToolBarAction(homeView, HomeView.ActionType.PAN));
toolBar.add(panToggleButton);
final JToggleButton createWallsToggleButton =
new JToggleButton(getToolBarAction(homeView, HomeView.ActionType.CREATE_WALLS));
toolBar.add(createWallsToggleButton);
final JToggleButton createRoomsToggleButton =
new JToggleButton(getToolBarAction(homeView, HomeView.ActionType.CREATE_ROOMS));
toolBar.add(createRoomsToggleButton);
final JToggleButton createDimensionLinesToggleButton =
new JToggleButton(getToolBarAction(homeView, HomeView.ActionType.CREATE_DIMENSION_LINES));
toolBar.add(createDimensionLinesToggleButton);
final JToggleButton createLabelsToggleButton =
new JToggleButton(getToolBarAction(homeView, HomeView.ActionType.CREATE_LABELS));
toolBar.add(createLabelsToggleButton);
// Add Select, Create Walls and Create dimensions buttons to radio group
ButtonGroup group = new ButtonGroup();
group.add(selectToggleButton);
group.add(panToggleButton);
group.add(createWallsToggleButton);
group.add(createRoomsToggleButton);
group.add(createDimensionLinesToggleButton);
group.add(createLabelsToggleButton);
controller.getPlanController().addPropertyChangeListener(PlanController.Property.MODE,
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
PlanController.Mode mode = controller.getPlanController().getMode();
selectToggleButton.setSelected(mode == PlanController.Mode.SELECTION);
panToggleButton.setSelected(mode == PlanController.Mode.PANNING);
createWallsToggleButton.setSelected(mode == PlanController.Mode.WALL_CREATION);
createRoomsToggleButton.setSelected(mode == PlanController.Mode.ROOM_CREATION);
createDimensionLinesToggleButton.setSelected(mode == PlanController.Mode.DIMENSION_LINE_CREATION);
createLabelsToggleButton.setSelected(mode == PlanController.Mode.LABEL_CREATION);
}
});
toolBar.add(Box.createRigidArea(new Dimension(2, 2)));
addToolBarAction(homeView, HomeView.ActionType.ZOOM_OUT, toolBar);
addToolBarAction(homeView, HomeView.ActionType.ZOOM_IN, toolBar);
Action createPhotoAction = getToolBarAction(homeView, HomeView.ActionType.CREATE_PHOTO);
if (createPhotoAction != null) {
boolean enableCreatePhoto = getAppletBooleanParameter(this.applet, ENABLE_CREATE_PHOTO);
controller.getView().setEnabled(HomeView.ActionType.CREATE_PHOTO, enableCreatePhoto);
if (enableCreatePhoto) {
toolBar.addSeparator();
toolBar.add(createPhotoAction);
}
}
// Add plug-in buttons
if (pluginButtons.size() > 0) {
toolBar.addSeparator();
for (JComponent pluginButton : pluginButtons) {
toolBar.add(pluginButton);
}
}
Action aboutAction = getToolBarAction(homeView, HomeView.ActionType.ABOUT);
if (aboutAction != null) {
toolBar.addSeparator();
toolBar.add(aboutAction);
}
controller.getView().setEnabled(HomeView.ActionType.EXPORT_TO_SVG,
getAppletBooleanParameter(this.applet, ENABLE_EXPORT_TO_SVG));
controller.getView().setEnabled(HomeView.ActionType.EXPORT_TO_OBJ,
getAppletBooleanParameter(this.applet, ENABLE_EXPORT_TO_OBJ));
controller.getView().setEnabled(HomeView.ActionType.CREATE_VIDEO,
getAppletBooleanParameter(this.applet, ENABLE_CREATE_VIDEO));
// Add a border
homeView.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
return controller;
}