use of org.apache.pivot.wtk.Menu in project pivot by apache.
the class TerraMenuSkin method keyReleased.
/**
* {@link KeyCode#SPACE SPACE} 'presses' the active menu item if it does not
* have a sub-menu.
*/
@Override
public boolean keyReleased(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
boolean consumed = super.keyReleased(component, keyCode, keyLocation);
Menu menu = (Menu) component;
if (keyCode == Keyboard.KeyCode.SPACE) {
Menu.Item activeItem = menu.getActiveItem();
// Press if the item does not have a sub-menu
if (activeItem != null && activeItem.getMenu() == null) {
activeItem.press();
consumed = true;
}
}
return consumed;
}
use of org.apache.pivot.wtk.Menu 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;
}
}
use of org.apache.pivot.wtk.Menu in project pivot by apache.
the class TerraMenuItemSkin method paint.
@Override
public void paint(Graphics2D graphics) {
Menu.Item menuItem = (Menu.Item) getComponent();
Menu menu = (Menu) menuItem.getParent();
int width = getWidth();
int height = getHeight();
boolean highlight = menuItem.isActive();
// Paint highlight state
if (highlight) {
Color activeBackgroundColor = menu.getStyles().getColor(Style.activeBackgroundColor);
graphics.setPaint(new GradientPaint(width / 2f, 0, TerraTheme.brighten(activeBackgroundColor), width / 2f, height, activeBackgroundColor));
graphics.fillRect(0, 0, width, height);
}
// Paint the content
Button.DataRenderer dataRenderer = prepare(menuItem, highlight);
dataRenderer.setSize(Math.max(width - EXPANDER_SIZE, 0), height);
dataRenderer.paint(graphics);
// Paint the expander
if (menuItem.getMenu() != null) {
Color color = menu.getStyles().getColor(highlight ? Style.activeColor : Style.color);
graphics.setColor(color);
graphics.setStroke(new BasicStroke(0));
GraphicsUtilities.setAntialiasingOn(graphics);
graphics.translate(dataRenderer.getWidth() + (EXPANDER_SIZE - EXPANDER_ICON_SIZE) / 2, (height - EXPANDER_ICON_SIZE) / 2);
int[] xPoints = { 0, EXPANDER_ICON_SIZE, 0 };
int[] yPoints = { 0, EXPANDER_ICON_SIZE / 2, EXPANDER_ICON_SIZE };
graphics.fillPolygon(xPoints, yPoints, 3);
graphics.drawPolygon(xPoints, yPoints, 3);
}
}
use of org.apache.pivot.wtk.Menu in project pivot by apache.
the class TerraMenuItemSkin method isOpaque.
@Override
public boolean isOpaque() {
boolean opaque = false;
Menu.Item menuItem = (Menu.Item) getComponent();
if (menuItem.isActive()) {
Menu menu = (Menu) menuItem.getParent();
Color activeBackgroundColor = menu.getStyles().getColor(Style.activeBackgroundColor);
opaque = (activeBackgroundColor.getTransparency() == Transparency.OPAQUE);
}
return opaque;
}
use of org.apache.pivot.wtk.Menu in project pivot by apache.
the class TerraMenuPopupSkin method install.
@Override
public void install(Component component) {
super.install(component);
MenuPopup menuPopup = (MenuPopup) component;
menuPopup.getMenuPopupListeners().add(this);
menuPopup.getMenuPopupStateListeners().add(this);
Menu menu = menuPopup.getMenu();
if (menu != null) {
menu.getMenuItemSelectionListeners().add(menuItemSelectionListener);
}
panorama.setView(menu);
menuPopup.setContent(border);
// Attach the drop-shadow decorator
if (!themeIsFlat()) {
dropShadowDecorator = new DropShadowDecorator();
menuPopup.getDecorators().add(dropShadowDecorator);
}
}
Aggregations