use of org.apache.pivot.wtk.Component in project pivot by apache.
the class ComponentInspectorSkin method addFloatControl.
private static Component addFloatControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
float value = (Float) dictionary.get(key);
TextInput textInput = new TextInput();
textInput.setTextSize(10);
textInput.setValidator(new FloatValidator());
textInput.setText(String.valueOf(value));
section.add(textInput);
Form.setLabel(textInput, key);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
try {
dictionary.put(key, Float.parseFloat(textInputLocal.getText()));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
float valueLocal = (Float) dictionary.get(key);
textInputLocal.setText(String.valueOf(valueLocal));
}
}
}
});
return textInput;
}
use of org.apache.pivot.wtk.Component in project pivot by apache.
the class ComponentStyleInspectorSkin method sourceChanged.
@Override
public void sourceChanged(ComponentInspector componentInspector, Component previousSource) {
Component source = componentInspector.getSource();
clearControls();
if (previousSource != null) {
previousSource.getComponentStyleListeners().remove(componentStyleHandler);
}
if (source != null) {
source.getComponentStyleListeners().add(componentStyleHandler);
Component.StyleDictionary styles = source.getStyles();
ArrayList<String> keys = new ArrayList<>(new Comparator<String>() {
@Override
public int compare(String key1, String key2) {
return key1.compareTo(key2);
}
});
// Filter (exclude read-only) and sort the keys
for (String key : styles) {
if (!styles.isReadOnly(key)) {
keys.add(key);
}
}
// Add the controls
for (String key : keys) {
addControl(styles, key, styles.getType(key), stylesSection);
}
}
}
use of org.apache.pivot.wtk.Component 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.Component in project pivot by apache.
the class ComponentInspector method setSource.
public void setSource(Component source) {
Component previousSource = this.source;
if (source != previousSource) {
this.source = source;
componentInspectorListeners.sourceChanged(this, previousSource);
}
}
use of org.apache.pivot.wtk.Component in project pivot by apache.
the class BXMLExplorerDocument method analyseObjectTree.
@SuppressWarnings("unchecked")
private TreeNode analyseObjectTree(Object container) {
// doesn't look neat
if (container instanceof TablePane) {
TreeBranch branch = new TreeBranch(nameForObject(container));
TablePane table = (TablePane) container;
for (TablePane.Row row : table.getRows()) {
TreeNode childBranch = analyseObjectTree(row);
branch.add(childBranch);
}
setComponentIconOnTreeNode(container, branch);
return branch;
}
// We don't want to analyse the components that are added as part of the
// skin, so use similar logic to BXMLSerializer
DefaultProperty defaultProperty = container.getClass().getAnnotation(DefaultProperty.class);
if (defaultProperty != null) {
TreeBranch branch = new TreeBranch(nameForObject(container));
String defaultPropertyName = defaultProperty.value();
BeanAdapter beanAdapter = new BeanAdapter(container);
if (!beanAdapter.containsKey(defaultPropertyName)) {
throw new IllegalStateException("default property " + defaultPropertyName + " not found on " + container);
}
Object defaultPropertyValue = beanAdapter.get(defaultPropertyName);
if (defaultPropertyValue != null) {
if (defaultPropertyValue instanceof Component) {
TreeNode childBranch = analyseObjectTree(defaultPropertyValue);
branch.add(childBranch);
}
}
// so make empty branches into nodes.
if (branch.isEmpty()) {
TreeNode node = new TreeNode(branch.getText());
setComponentIconOnTreeNode(container, node);
return node;
}
setComponentIconOnTreeNode(container, branch);
return branch;
}
if (container instanceof Sequence<?>) {
TreeBranch branch = new TreeBranch(nameForObject(container));
Iterable<Object> sequence = (Iterable<Object>) container;
for (Object child : sequence) {
TreeNode childBranch = analyseObjectTree(child);
branch.add(childBranch);
}
setComponentIconOnTreeNode(container, branch);
return branch;
}
TreeNode node = new TreeNode(nameForObject(container));
setComponentIconOnTreeNode(container, node);
return node;
}
Aggregations