use of org.apache.pivot.wtk.Menu.Section in project pivot by apache.
the class TerraMenuSkin method install.
@Override
public void install(Component component) {
super.install(component);
Menu menu = (Menu) component;
menu.getMenuListeners().add(this);
for (Menu.Section section : menu.getSections()) {
section.getSectionListeners().add(this);
}
menu.setFocusTraversalPolicy(new IndexFocusTraversalPolicy(true));
}
use of org.apache.pivot.wtk.Menu.Section in project pivot by apache.
the class TerraMenuSkin method getPreferredHeight.
@Override
public int getPreferredHeight(int width) {
int preferredHeight = 0;
Menu menu = (Menu) getComponent();
Menu.SectionSequence sections = menu.getSections();
for (int i = 0, n = sections.getLength(); i < n; i++) {
Menu.Section section = sections.get(i);
for (Menu.Item item : section) {
if (item.isVisible()) {
preferredHeight += item.getPreferredHeight(width);
}
}
if (i > 0) {
preferredHeight += sectionSpacing;
}
}
return preferredHeight;
}
use of org.apache.pivot.wtk.Menu.Section in project pivot by apache.
the class TerraMenuSkin method getPreferredWidth.
@Override
public int getPreferredWidth(int height) {
int preferredWidth = 0;
Menu menu = (Menu) getComponent();
Menu.SectionSequence sections = menu.getSections();
for (int i = 0, n = sections.getLength(); i < n; i++) {
Menu.Section section = sections.get(i);
for (Menu.Item item : section) {
if (item.isVisible()) {
preferredWidth = Math.max(item.getPreferredWidth(-1), preferredWidth);
}
}
}
return preferredWidth;
}
use of org.apache.pivot.wtk.Menu.Section in project pivot by apache.
the class TerraMenuSkin method keyTyped.
/**
* Select the next enabled menu item where the first character of the
* rendered text matches the typed key (case insensitive).
*/
@Override
public boolean keyTyped(Component component, char character) {
boolean consumed = super.keyTyped(component, character);
Menu menu = (Menu) component;
Menu.SectionSequence sections = menu.getSections();
int sectionCount = sections.getLength();
Menu.Item activeItem = menu.getActiveItem();
int sectionIndex;
int itemIndex;
if (activeItem == null) {
sectionIndex = 0;
itemIndex = 0;
} else {
Menu.Section section = activeItem.getSection();
sectionIndex = sections.indexOf(section);
itemIndex = section.indexOf(activeItem) + 1;
}
char characterUpper = Character.toUpperCase(character);
while (sectionIndex < sectionCount) {
Section section = sections.get(sectionIndex);
int sectionLength = section.getLength();
while (itemIndex < sectionLength) {
Item item = section.get(itemIndex);
if (item.isEnabled()) {
Button.DataRenderer itemDataRenderer = item.getDataRenderer();
String string = itemDataRenderer.toString(item.getButtonData());
if (string != null && string.length() > 0) {
char first = Character.toUpperCase(string.charAt(0));
if (first == characterUpper) {
item.setActive(true);
consumed = true;
break;
}
}
}
itemIndex++;
}
if (itemIndex < sectionLength) {
break;
}
sectionIndex++;
itemIndex = 0;
}
return consumed;
}
use of org.apache.pivot.wtk.Menu.Section in project pivot by apache.
the class TerraMenuSkin method layout.
@Override
public void layout() {
Menu menu = (Menu) getComponent();
Menu.SectionSequence sections = menu.getSections();
int width = getWidth();
int itemY = 0;
for (int i = 0, n = sections.getLength(); i < n; i++) {
Menu.Section section = sections.get(i);
for (Menu.Item item : section) {
if (item.isVisible()) {
item.setSize(width, item.getPreferredHeight(width));
item.setLocation(0, itemY);
itemY += item.getHeight();
}
}
itemY += sectionSpacing;
}
}