use of org.apache.pivot.wtk.ButtonGroup in project pivot by apache.
the class ComponentExplorerWindow method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
splitPane = (SplitPane) namespace.get("splitPane");
treeView = (TreeView) namespace.get("treeView");
contentScrollPane = (ScrollPane) namespace.get("contentScrollPane");
contentPane = (Border) namespace.get("contentPane");
sourceTextArea = (TextArea) namespace.get("sourceTextArea");
componentPropertyInspector = (ComponentPropertyInspector) namespace.get("componentPropertyInspector");
componentStyleInspector = (ComponentStyleInspector) namespace.get("componentStyleInspector");
eventLogger = (EventLogger) namespace.get("eventLogger");
horizontalScrollBarPolicyGroup = (ButtonGroup) namespace.get("horizontalScrollBarPolicyGroup");
verticalScrollBarPolicyGroup = (ButtonGroup) namespace.get("verticalScrollBarPolicyGroup");
horizontalAutoButton = (Button) namespace.get("horizontalAutoButton");
horizontalFillButton = (Button) namespace.get("horizontalFillButton");
horizontalFillToCapacityButton = (Button) namespace.get("horizontalFillToCapacityButton");
horizontalNeverButton = (Button) namespace.get("horizontalNeverButton");
horizontalAlwaysButton = (Button) namespace.get("horizontalAlwaysButton");
verticalAutoButton = (Button) namespace.get("verticalAutoButton");
verticalFillButton = (Button) namespace.get("verticalFillButton");
verticalFillToCapacityButton = (Button) namespace.get("verticalFillToCapacityButton");
verticalNeverButton = (Button) namespace.get("verticalNeverButton");
verticalAlwaysButton = (Button) namespace.get("verticalAlwaysButton");
treeView.getTreeViewSelectionListeners().add(new TreeViewSelectionListener() {
@Override
public void selectedPathsChanged(TreeView treeViewArgument, Sequence<Path> previousSelectedPaths) {
Component component = null;
Object node = treeViewArgument.getSelectedNode();
if (node instanceof ComponentNode) {
ComponentNode componentNode = (ComponentNode) node;
URL url = componentNode.getSrc();
try {
sourceTextArea.setText(url);
} catch (IOException exception) {
throw new RuntimeException(exception);
}
BXMLSerializer bxmlSerializer = new BXMLSerializer();
try {
component = (Component) bxmlSerializer.readObject(url);
} catch (IOException exception) {
throw new RuntimeException(exception);
} catch (SerializationException exception) {
throw new RuntimeException(exception);
}
switch(componentNode.getHorizontalScrollBarPolicy()) {
case AUTO:
horizontalScrollBarPolicyGroup.setSelection(horizontalAutoButton);
break;
case FILL:
horizontalScrollBarPolicyGroup.setSelection(horizontalFillButton);
break;
case FILL_TO_CAPACITY:
horizontalScrollBarPolicyGroup.setSelection(horizontalFillToCapacityButton);
break;
case NEVER:
horizontalScrollBarPolicyGroup.setSelection(horizontalNeverButton);
break;
case ALWAYS:
horizontalScrollBarPolicyGroup.setSelection(horizontalAlwaysButton);
break;
default:
break;
}
switch(componentNode.getVerticalScrollBarPolicy()) {
case AUTO:
verticalScrollBarPolicyGroup.setSelection(verticalAutoButton);
break;
case FILL:
verticalScrollBarPolicyGroup.setSelection(verticalFillButton);
break;
case FILL_TO_CAPACITY:
verticalScrollBarPolicyGroup.setSelection(verticalFillToCapacityButton);
break;
case NEVER:
verticalScrollBarPolicyGroup.setSelection(verticalNeverButton);
break;
case ALWAYS:
verticalScrollBarPolicyGroup.setSelection(verticalAlwaysButton);
break;
default:
break;
}
} else {
sourceTextArea.setText("");
}
contentPane.setContent(component);
componentPropertyInspector.setSource(component);
componentStyleInspector.setSource(component);
eventLogger.setSource(component);
eventLogger.clearLog();
}
});
treeView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {
@Override
public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
if (button == Mouse.Button.LEFT && count == 2) {
Path path = treeView.getNodeAt(y);
if (path != null) {
List<?> treeData = treeView.getTreeData();
Object node = Tree.get(treeData, path);
if (node instanceof List<?>) {
treeView.setBranchExpanded(path, !treeView.isBranchExpanded(path));
}
}
}
return false;
}
});
horizontalScrollBarPolicyGroup.getButtonGroupListeners().add(new ButtonGroupListener() {
@Override
public void selectionChanged(ButtonGroup buttonGroup, Button previousSelection) {
Button button = buttonGroup.getSelection();
ScrollBarPolicy horizontalScrollBarPolicy = null;
if (button == horizontalAutoButton) {
horizontalScrollBarPolicy = ScrollBarPolicy.AUTO;
} else if (button == horizontalFillButton) {
horizontalScrollBarPolicy = ScrollBarPolicy.FILL;
} else if (button == horizontalFillToCapacityButton) {
horizontalScrollBarPolicy = ScrollBarPolicy.FILL_TO_CAPACITY;
} else if (button == horizontalNeverButton) {
horizontalScrollBarPolicy = ScrollBarPolicy.NEVER;
} else if (button == horizontalAlwaysButton) {
horizontalScrollBarPolicy = ScrollBarPolicy.ALWAYS;
}
if (horizontalScrollBarPolicy != null) {
contentScrollPane.setHorizontalScrollBarPolicy(horizontalScrollBarPolicy);
}
}
});
verticalScrollBarPolicyGroup.getButtonGroupListeners().add(new ButtonGroupListener() {
@Override
public void selectionChanged(ButtonGroup buttonGroup, Button previousSelection) {
Button button = buttonGroup.getSelection();
ScrollBarPolicy verticalScrollBarPolicy = null;
if (button == verticalAutoButton) {
verticalScrollBarPolicy = ScrollBarPolicy.AUTO;
} else if (button == verticalFillButton) {
verticalScrollBarPolicy = ScrollBarPolicy.FILL;
} else if (button == verticalFillToCapacityButton) {
verticalScrollBarPolicy = ScrollBarPolicy.FILL_TO_CAPACITY;
} else if (button == verticalNeverButton) {
verticalScrollBarPolicy = ScrollBarPolicy.NEVER;
} else if (button == verticalAlwaysButton) {
verticalScrollBarPolicy = ScrollBarPolicy.ALWAYS;
}
if (verticalScrollBarPolicy != null) {
contentScrollPane.setVerticalScrollBarPolicy(verticalScrollBarPolicy);
}
}
});
}
use of org.apache.pivot.wtk.ButtonGroup in project pivot by apache.
the class CardPaneTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
frame = new Frame(new BoxPane());
frame.getStyles().put(Style.padding, 0);
frame.setTitle("Component Pane Test");
frame.setPreferredSize(800, 600);
frame.setLocation(20, 20);
BXMLSerializer bxmlSerializer = new BXMLSerializer();
sheet = (Sheet) bxmlSerializer.readObject(CardPaneTest.class, "card_pane_test.bxml");
cardPane = (CardPane) bxmlSerializer.getNamespace().get("cardPane");
sizeGroup = (ButtonGroup) bxmlSerializer.getNamespace().get("sizeGroup");
sizeGroup.getButtonGroupListeners().add(new ButtonGroupListener() {
@Override
public void selectionChanged(ButtonGroup buttonGroup, Button previousSelection) {
final Button selection = buttonGroup.getSelection();
int selectedIndex = selection == null ? -1 : selection.getParent().indexOf(selection);
cardPane.getCardPaneListeners().add(new CardPaneListener() {
@Override
public Vote previewSelectedIndexChange(CardPane cardPaneArgument, int selectedIndexArgument) {
if (selection != null) {
selection.getParent().setEnabled(false);
}
return Vote.APPROVE;
}
@Override
public void selectedIndexChangeVetoed(CardPane cardPaneArgument, Vote reason) {
if (selection != null && reason == Vote.DENY) {
selection.getParent().setEnabled(true);
}
}
@Override
public void selectedIndexChanged(CardPane cardPaneArgument, int previousSelectedIndex) {
if (selection != null) {
selection.getParent().setEnabled(true);
}
}
});
cardPane.setSelectedIndex(selectedIndex);
}
});
frame.open(display);
ApplicationContext.queueCallback(() -> sheet.open(frame));
}
use of org.apache.pivot.wtk.ButtonGroup 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.ButtonGroup in project pivot by apache.
the class RadioButtons method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
selectButton = (PushButton) namespace.get("selectButton");
// Get a reference to the button group
final ButtonGroup numbersGroup = (ButtonGroup) namespace.get("numbers");
// Add a button press listener
selectButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
String message = "You selected \"" + numbersGroup.getSelection().getButtonData() + "\".";
Alert.alert(MessageType.INFO, message, RadioButtons.this);
}
});
}
Aggregations