public void selectMode( final ModeController oldModeController, final ModeController newModeController) {
if (oldModeController == newModeController) {
return;
}
if (oldModeController != null) {
final IUserInputListenerFactory userInputListenerFactory = oldModeController.getUserInputListenerFactory();
for (int j = 0; j < 4; j++) {
final Iterable<JComponent> modeToolBars = userInputListenerFactory.getToolBars(j);
if (modeToolBars != null) {
for (final Component toolBar : modeToolBars) {
toolbarPanel[j].remove(toolBar);
}
toolbarPanel[j].revalidate();
}
}
}
final IUserInputListenerFactory newUserInputListenerFactory = newModeController.getUserInputListenerFactory();
for (int j = 0; j < 4; j++) {
final Iterable<JComponent> newToolBars = newUserInputListenerFactory.getToolBars(j);
if (newToolBars != null) {
int i = 0;
for (final JComponent toolBar : newToolBars) {
UIComponentVisibilityDispatcher dispatcher = UIComponentVisibilityDispatcher.dispatcher(toolBar);
if(dispatcher != null) {
dispatcher.resetVisible();
toolbarPanel[j].add(toolBar, i++);
}
}
toolbarPanel[j].revalidate();
toolbarPanel[j].repaint();
}
}
if(newUserInputListenerFactory.useRibbonMenu()) {
newUserInputListenerFactory.getMenuBuilder(RibbonBuilder.class).buildRibbon();
}
else {
setFreeplaneMenuBar(newUserInputListenerFactory.getMenuBar());
setUIComponentsVisible(newModeController.getController().getMapViewManager(), isMenubarVisible());
}
}