use of org.apache.pivot.wtk.MenuBar in project pivot by apache.
the class MenuBarItemDataRenderer method render.
@Override
public void render(Object data, Button button, boolean highlighted) {
Image icon = null;
String text = null;
if (data instanceof BaseContent) {
BaseContent baseContent = (BaseContent) data;
icon = baseContent.getIcon();
} else if (data instanceof Image) {
icon = (Image) data;
}
text = toString(data);
// Update the image view
MenuBar.Item menuBarItem = (MenuBar.Item) button;
MenuBar menuBar = (MenuBar) menuBarItem.getParent();
if (icon == null) {
imageView.setVisible(false);
} else {
imageView.setVisible(true);
imageView.setImage(icon);
imageView.getStyles().put(Style.opacity, button.isEnabled() ? 1.0f : 0.5f);
}
// Update the label
label.setText(text != null ? text : "");
if (text == null) {
label.setVisible(false);
} else {
label.setVisible(true);
Font font = menuBar.getStyles().getFont(Style.font);
label.getStyles().put(Style.font, font);
Color color;
if (button.isEnabled()) {
if (highlighted) {
color = menuBar.getStyles().getColor(Style.activeColor);
} else {
color = menuBar.getStyles().getColor(Style.color);
}
} else {
color = menuBar.getStyles().getColor(Style.disabledColor);
}
label.getStyles().put(Style.color, color);
}
}
use of org.apache.pivot.wtk.MenuBar in project pivot by apache.
the class TerraFrameSkin method getPreferredWidth.
@Override
public int getPreferredWidth(int height) {
int preferredWidth = 0;
Frame frame = (Frame) getComponent();
// Include title bar width plus left/right title bar borders
Dimensions titleBarSize = titleBarTablePane.getPreferredSize();
preferredWidth = Math.max(titleBarSize.width + 2, preferredWidth);
if (height != -1) {
// Subtract title bar height and top/bottom title bar borders
// from height constraint
height -= titleBarSize.height + 2;
}
// Include menu bar width
MenuBar menuBar = frame.getMenuBar();
if (menuBar != null) {
Dimensions menuBarSize = menuBar.getPreferredSize();
preferredWidth = Math.max(preferredWidth, menuBarSize.width);
if (height != -1) {
// Subtract menu bar height from height constraint
height -= menuBarSize.height;
}
}
Component content = frame.getContent();
if (content != null) {
if (height != -1) {
// Subtract padding, top/bottom content borders, and content bevel
// from height constraint
height -= (padding.top + padding.bottom) + (showContentBevel ? 1 : 0) + 2;
height = Math.max(height, 0);
}
preferredWidth = Math.max(preferredWidth, content.getPreferredWidth(height));
}
// Add padding and left/right content borders
preferredWidth += (padding.left + padding.right) + 2;
return preferredWidth;
}
use of org.apache.pivot.wtk.MenuBar in project pivot by apache.
the class TerraFrameSkin method getPreferredHeight.
@Override
public int getPreferredHeight(int width) {
int preferredHeight = 0;
Frame frame = (Frame) getComponent();
// Include title bar height plus top/bottom title bar borders
preferredHeight += titleBarTablePane.getPreferredHeight() + 2;
// Include menu bar height
MenuBar menuBar = frame.getMenuBar();
if (menuBar != null) {
preferredHeight += menuBar.getPreferredHeight();
}
Component content = frame.getContent();
if (content != null) {
if (width != -1) {
// Subtract padding and left/right content borders from constraint
width -= (padding.left + padding.right) + 2;
width = Math.max(width, 0);
}
preferredHeight += content.getPreferredHeight(width);
}
// Add padding, top/bottom content borders, and content bevel
preferredHeight += (padding.top + padding.bottom) + (showContentBevel ? 1 : 0) + 2;
return preferredHeight;
}
use of org.apache.pivot.wtk.MenuBar in project pivot by apache.
the class TerraFrameSkin method keyPressed.
@Override
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
boolean consumed = super.keyPressed(component, keyCode, keyLocation);
Frame frame = (Frame) component;
MenuBar menuBar = frame.getMenuBar();
if (menuBar != null && keyCode == Keyboard.KeyCode.SPACE && Keyboard.isPressed(Keyboard.Modifier.ALT)) {
MenuBar.Item activeItem = menuBar.getActiveItem();
MenuBar.ItemSequence items = menuBar.getItems();
if (activeItem == null && items.getLength() > 0) {
items.get(0).setActive(true);
consumed = true;
}
}
return consumed;
}
use of org.apache.pivot.wtk.MenuBar in project pivot by apache.
the class TerraMenuBarSkin method install.
@Override
public void install(Component component) {
super.install(component);
MenuBar menuBar = (MenuBar) component;
menuBar.getMenuBarListeners().add(this);
}
Aggregations