}
// Javadoc inherited.
public MenuItemRenderer selectMenuItemRenderer(Menu menu)
throws RendererException {
PropertyValues properties =
menu.getElementDetails().getStyles().getPropertyValues();
SeparatorRenderer separator;
// Initialise the renderer to return.
MenuItemRenderer itemRenderer = null;
// Initialise the top component renderer.
MenuItemComponentRenderer top = null;
// Select the text renderer to use.
MenuItemComponentRenderer textRenderer = selectTextRenderer(properties);
// Select the image renderer to use, if there is no text renderer then
// it will need to provide alternate text.
boolean provideAltText = (textRenderer == null);
MenuItemComponentRenderer imageRenderer
= selectImageRenderer(properties,
provideAltText);
// Sort out the numeric emulation required (or not)...
// Get the menu link style
StyleValue menuLinkStyle = properties.getComputedValue(
StylePropertyDetails.MCS_MENU_LINK_STYLE);
// See if numeric shortcuts were specified in the style
// Null indicates that no emulation is required - default to this
NumericShortcutEmulationRenderer emulation = null;
if (menuLinkStyle == MCSMenuLinkStyleKeywords.NUMERIC_SHORTCUT) {
// Numeric shortcuts were specified so get an emulation object from
// the factory and use this. NOTE: this may still be a null object
// if the factory/protocol does not support or require numeric
// emulation it can return null from this call to indicate that.
emulation = factory.createNumericShortcutEmulationRenderer();
}
// If they have both been specified then look at some other styles.
if (imageRenderer != null && textRenderer != null) {
// Now see what order they should be in.
MenuItemComponentRenderer first;
MenuItemComponentRenderer second;
final StyleProperty ORDER_PROPERTY
= StylePropertyDetails.MCS_MENU_ITEM_ORDER;
StyleValue order = properties.getComputedValue(ORDER_PROPERTY);
if (order == MCSMenuItemOrderKeywords.IMAGE_FIRST) {
first = imageRenderer;
second = textRenderer;
} else if (order == MCSMenuItemOrderKeywords.TEXT_FIRST) {
first = textRenderer;
second = imageRenderer;
} else {
throw new IllegalStateException
("Unknown keyword " + order + " for "
+ ORDER_PROPERTY.getName());
}
// Determine which component, or components is active.
final StyleProperty ACTIVE_AREA_PROPERTY
= StylePropertyDetails.MCS_MENU_ITEM_ACTIVE_AREA;
// Get the enumeration value from the properties.
StyleValue activeArea = properties.getComputedValue(ACTIVE_AREA_PROPERTY);
ActiveMenuItemComponent activeComponent;
if (activeArea == MCSMenuItemActiveAreaKeywords.IMAGE_ONLY) {
if (first == imageRenderer) {
activeComponent = ActiveMenuItemComponent.FIRST;