}
// Add radio button menu items to sub menu and make them share the same radio button group
ButtonGroup sortButtonGroup = new ButtonGroup();
for (Map.Entry<HomePieceOfFurniture.SortableProperty, Action> entry : sortActions.entrySet()) {
final HomePieceOfFurniture.SortableProperty furnitureProperty = entry.getKey();
Action sortAction = entry.getValue();
JRadioButtonMenuItem sortMenuItem = new JRadioButtonMenuItem();
// Use a special model for sort radio button menu item that is selected if
// home is sorted on furnitureProperty criterion
sortMenuItem.setModel(new JToggleButton.ToggleButtonModel() {
@Override
public boolean isSelected() {
return furnitureProperty == home.getFurnitureSortedProperty();
}
});
// Configure check box menu item action after setting its model to avoid losing its mnemonic
sortMenuItem.setAction(new ResourceAction.MenuItemAction(sortAction));
sortMenu.add(sortMenuItem);
sortButtonGroup.add(sortMenuItem);
}
Action sortOrderAction = getActionMap().get(ActionType.SORT_HOME_FURNITURE_BY_DESCENDING_ORDER);
if (sortOrderAction.getValue(Action.NAME) != null) {
sortMenu.addSeparator();
JCheckBoxMenuItem sortOrderCheckBoxMenuItem = new JCheckBoxMenuItem();
// Use a special model for sort order check box menu item that is selected depending on
// home sort order property
sortOrderCheckBoxMenuItem.setModel(new JToggleButton.ToggleButtonModel() {