use of org.apache.pivot.wtk.Menu in project pivot by apache.
the class TerraMenuPopupSkin method windowOpened.
@Override
public void windowOpened(Window window) {
super.windowOpened(window);
Display display = window.getDisplay();
display.getContainerMouseListeners().add(displayMouseListener);
MenuPopup menuPopup = (MenuPopup) window;
Menu menu = menuPopup.getMenu();
if (menu != null) {
Menu.Item activeItem = menu.getActiveItem();
if (activeItem != null) {
activeItem.setActive(false);
}
menu.requestFocus();
}
panorama.setScrollTop(0);
// Always ensure that the menu popup fits on the display.
ApplicationContext.queueCallback(repositionCallback);
}
use of org.apache.pivot.wtk.Menu in project pivot by apache.
the class ContextMenuTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
window = (Window) bxmlSerializer.readObject(ContextMenuTest.class, "context_menu_test.bxml");
bxmlSerializer.bind(this, ContextMenuTest.class);
window.setMenuHandler(new MenuHandler() {
@Override
public boolean configureContextMenu(Component component, Menu menu, int x, int y) {
menu.getSections().add(globalSection);
menu.getSections().add(helpSection);
menu.getSections().add(hoursSection);
return false;
}
});
window.open(display);
}
use of org.apache.pivot.wtk.Menu in project pivot by apache.
the class ContextMenusSampleMenuHandlerAdapter method configureContextMenu.
@Override
public boolean configureContextMenu(Component component, Menu menu, int x, int y) {
Menu.Section menuSection = new Menu.Section();
menu.getSections().add(menuSection);
menuSection.add(new Menu.Item("Do Nothing"));
Menu.Item doNothingMenuItem = new Menu.Item("Do Nothing and disabled");
doNothingMenuItem.setEnabled(false);
menuSection.add(doNothingMenuItem);
Menu.Item whatIsThisMenuItem = new Menu.Item("What is this?");
whatIsThisMenuItem.setAction(new Action() {
@Override
public void perform(Component source) {
String description = (descendant != null) ? (String) descendant.getUserData().get("description") : "empty";
String message = "This is a " + description + " description.";
System.out.println("perform: " + message);
}
});
menuSection.add(whatIsThisMenuItem);
Menu.Item nullActionMenuItem = new Menu.Item("Item with null action");
nullActionMenuItem.setAction((Action) null);
menuSection.add(nullActionMenuItem);
Menu.Item disabledActionMenuItem = new Menu.Item("Item with disabled action");
disabledActionMenuItem.setAction(new Action() {
@Override
public void perform(Component source) {
System.out.println("in perform");
}
});
disabledActionMenuItem.getAction().setEnabled(false);
menuSection.add(disabledActionMenuItem);
return false;
}
use of org.apache.pivot.wtk.Menu in project pivot by apache.
the class MenuItemDataRenderer method render.
@Override
public void render(Object data, Button button, boolean highlighted) {
Image icon = null;
String text = null;
Keyboard.KeyStroke keyboardShortcut = null;
if (data instanceof BaseContent) {
BaseContent buttonData = (BaseContent) data;
icon = buttonData.getIcon();
if (buttonData instanceof MenuItemData) {
MenuItemData menuItemData = (MenuItemData) buttonData;
keyboardShortcut = menuItemData.getKeyboardShortcut();
}
} else if (data instanceof Image) {
icon = (Image) data;
}
text = toString(data);
// attempt to retrieve icon from button data
if (button.isSelected()) {
icon = (Image) button.getStyles().get(Style.checkmarkImage);
}
// Update the image view
Menu.Item menuItem = (Menu.Item) button;
Menu menu = (Menu) menuItem.getParent();
int margin = menu.getStyles().getInt(Style.margin);
Insets padding = (Insets) getStyles().get(Style.padding);
imageView.setImage(icon);
imageView.setPreferredWidth(margin - padding.left * 2);
imageView.getStyles().put(Style.opacity, button.isEnabled() ? new Float(1.0f) : new Float(0.5f));
// Update the labels
textLabel.setText(text != null ? text : "");
Font font = menu.getStyles().getFont(Style.font);
textLabel.getStyles().put(Style.font, font);
keyboardShortcutLabel.getStyles().put(Style.font, font.deriveFont(Font.ITALIC));
Color color;
if (button.isEnabled()) {
if (highlighted) {
color = menu.getStyles().getColor(Style.activeColor);
} else {
color = menu.getStyles().getColor(Style.color);
}
} else {
color = menu.getStyles().getColor(Style.disabledColor);
}
textLabel.getStyles().put(Style.color, color);
keyboardShortcutLabel.getStyles().put(Style.color, color);
boolean showKeyboardShortcuts = false;
if (menu.getStyles().containsKey(Style.showKeyboardShortcuts)) {
showKeyboardShortcuts = menu.getStyles().getBoolean(Style.showKeyboardShortcuts);
}
if (showKeyboardShortcuts) {
keyboardShortcutLabel.setVisible(true);
keyboardShortcutLabel.setText(keyboardShortcut != null ? keyboardShortcut.toString() : "");
} else {
keyboardShortcutLabel.setVisible(false);
}
}
use of org.apache.pivot.wtk.Menu in project pivot by apache.
the class MenuItemSkin method buttonPressed.
@Override
public void buttonPressed(Button button) {
Menu.Item menuItem = (Menu.Item) getComponent();
Menu menu = menuItem.getMenu();
if (menu != null && !menuPopup.isOpen()) {
// Size and position the popup
Display display = menuItem.getDisplay();
Dimensions displaySize = display.getSize();
Point location = menuItem.mapPointToAncestor(display, getWidth(), 0);
menuPopup.setLocation(location.x, location.y);
int width = getWidth();
// If the popup extends over the right edge of the display,
// move it so that the right edge of the popup lines up with the
// left edge of the menu item
int popupWidth = menuPopup.getPreferredWidth();
if (location.x + popupWidth > displaySize.width) {
menuPopup.setX(location.x - width - popupWidth);
}
menuPopup.open(menuItem.getWindow());
menuPopup.requestFocus();
}
}
Aggregations