use of org.apache.pivot.wtk.Menu in project pivot by apache.
the class Pivot765 method startup.
@Override
public void startup(final Display display, Map<String, String> properties) throws Exception {
final MenuButton button = new MenuButton();
button.setButtonData("Populate menu and open!");
Window window = new Window(button);
button.getListPopup().getWindowStateListeners().add(new WindowStateListener() {
@Override
public Vote previewWindowOpen(Window windowArgument) {
Menu menu = new Menu();
Menu.Section section = new Menu.Section();
menu.getSections().add(section);
section.add(new Menu.Item("A dynamically added menu item"));
button.setMenu(menu);
menuPopulated = true;
return Vote.APPROVE;
}
@Override
public void windowOpened(Window windowArgument) {
if (!menuPopulated) {
Alert.alert("Window was opened before the menu was populated." + "Either previewWindowOpen threw an exception, or it wasn't called before the Window was opened.", windowArgument);
}
}
@Override
public void windowClosed(Window windowArgument, Display displayArgument, Window owner) {
// Remove menu for subsequent open attempt
button.setMenu(null);
menuPopulated = false;
}
});
window.open(display);
}
use of org.apache.pivot.wtk.Menu 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 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 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 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;
}
Aggregations