use of org.apache.pivot.wtk.Window in project pivot by apache.
the class DOMInteractionDemo method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
BoxPane boxPane = new BoxPane();
boxPane.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
helloButton = new PushButton("Say Hello");
boxPane.add(helloButton);
helloButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
BrowserApplicationContext.eval("sayHello(\"Hello from Pivot!\")", DOMInteractionDemo.this);
}
});
Border border = new Border(boxPane);
border.getStyles().put(Style.color, 7);
border.getStyles().put(Style.padding, 5);
window = new Window(border);
window.setMaximized(true);
window.open(display);
}
use of org.apache.pivot.wtk.Window in project pivot by apache.
the class ActionMappingTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
Action.getNamedActions().put("action1", new Action() {
@Override
public void perform(Component source) {
Alert.alert(MessageType.INFO, "Action 1 performed.", window);
}
});
Action.getNamedActions().put("action2", new Action() {
@Override
public void perform(Component source) {
Alert.alert(MessageType.INFO, "Action 2 performed.", window);
}
});
BXMLSerializer bxmlSerializer = new BXMLSerializer();
window = (Window) bxmlSerializer.readObject(ActionMappingTest.class, "action_mapping_test.bxml");
window.getActionMappings().add(new Window.ActionMapping(new Keyboard.KeyStroke(Keyboard.KeyCode.B, Keyboard.Modifier.SHIFT.getMask()), "action2"));
window.open(display);
window.requestFocus();
}
use of org.apache.pivot.wtk.Window in project pivot by apache.
the class ButtonGroupTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.getButtonGroupListeners().add(new ButtonGroupListener() {
@Override
public void selectionChanged(ButtonGroup buttonGroupArgument, Button previousSelection) {
System.out.println("selectionChanged(): previousSelection = " + previousSelection + ", selection = " + buttonGroupArgument.getSelection());
}
@Override
public void buttonAdded(ButtonGroup buttonGroupArgument, Button button) {
System.out.println("buttonAdded(): " + button);
}
@Override
public void buttonRemoved(ButtonGroup buttonGroupArgument, Button button) {
System.out.println("buttonRemoved(): " + button);
}
});
BoxPane boxPane = new BoxPane();
PushButton button1 = new PushButton("One");
button1.setToggleButton(true);
button1.setButtonGroup(buttonGroup);
boxPane.add(button1);
PushButton button2 = new PushButton("Two");
button2.setToggleButton(true);
button2.setButtonGroup(buttonGroup);
boxPane.add(button2);
PushButton button3 = new PushButton("Three");
button3.setToggleButton(true);
button3.setButtonGroup(buttonGroup);
boxPane.add(button3);
PushButton button4 = new PushButton("Four");
button4.setToggleButton(true);
button4.setButtonGroup(buttonGroup);
boxPane.add(button4);
// button1.setSelected(true);
// buttonGroup.setSelection(button1);
// buttonGroup.setSelection(null);
window = new Window(boxPane);
window.setMaximized(true);
window.open(display);
}
use of org.apache.pivot.wtk.Window in project pivot by apache.
the class WindowSkin method install.
@Override
public void install(Component component) {
super.install(component);
Window window = (Window) component;
window.getWindowListeners().add(this);
window.getWindowStateListeners().add(this);
window.setFocusTraversalPolicy(new WindowFocusTraversalPolicy());
}
use of org.apache.pivot.wtk.Window in project pivot by apache.
the class TerraMenuSkin method keyPressed.
/**
* {@link KeyCode#UP UP} Select the previous enabled menu item.<br>
* {@link KeyCode#DOWN DOWN} Select the next enabled menu item.<br>
* {@link KeyCode#LEFT LEFT} Close the current sub-menu.<br>
* {@link KeyCode#RIGHT RIGHT} Open the sub-menu of the current menu
* item.<br> {@link KeyCode#ENTER ENTER} 'presses' the active menu item if
* it does not have a sub-menu.
*/
@Override
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
boolean consumed = super.keyPressed(component, keyCode, keyLocation);
Menu menu = (Menu) component;
if (keyCode == Keyboard.KeyCode.UP) {
Menu.SectionSequence sections = menu.getSections();
int sectionCount = sections.getLength();
Menu.Item activeItem = menu.getActiveItem();
int sectionIndex;
int itemIndex;
if (activeItem == null) {
sectionIndex = sectionCount - 1;
itemIndex = -1;
} else {
Menu.Section section = activeItem.getSection();
sectionIndex = sections.indexOf(section);
itemIndex = section.indexOf(activeItem) - 1;
if (itemIndex == -1) {
sectionIndex--;
}
}
while (sectionIndex >= 0) {
Section section = sections.get(sectionIndex);
if (itemIndex == -1) {
int sectionLength = section.getLength();
itemIndex = sectionLength - 1;
}
while (itemIndex >= 0) {
Item item = section.get(itemIndex);
if (item.isEnabled()) {
item.setActive(true);
break;
}
itemIndex--;
}
if (itemIndex >= 0) {
break;
}
sectionIndex--;
}
consumed = true;
} else if (keyCode == Keyboard.KeyCode.DOWN) {
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;
}
while (sectionIndex < sectionCount) {
Section section = sections.get(sectionIndex);
int sectionLength = section.getLength();
while (itemIndex < sectionLength) {
Item item = section.get(itemIndex);
if (item.isEnabled()) {
item.setActive(true);
break;
}
itemIndex++;
}
if (itemIndex < sectionLength) {
break;
}
sectionIndex++;
itemIndex = 0;
}
consumed = true;
} else if (keyCode == Keyboard.KeyCode.LEFT) {
// Close the window if this is not a top-level menu
if (menu.getItem() != null) {
Window window = menu.getWindow();
window.close();
consumed = true;
}
} else if (keyCode == Keyboard.KeyCode.RIGHT) {
Menu.Item activeItem = menu.getActiveItem();
// Press if the item has a sub-menu
if (activeItem != null && activeItem.getMenu() != null) {
activeItem.press();
consumed = true;
}
} else if (keyCode == Keyboard.KeyCode.ENTER) {
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;
}
} else if (keyCode == Keyboard.KeyCode.TAB) {
consumed = false;
}
return consumed;
}
Aggregations