Search in sources :

Example 6 with Component

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;
}
Also used : FloatValidator(org.apache.pivot.wtk.validation.FloatValidator) TextInput(org.apache.pivot.wtk.TextInput) Component(org.apache.pivot.wtk.Component) ComponentStateListener(org.apache.pivot.wtk.ComponentStateListener)

Example 7 with Component

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);
        }
    }
}
Also used : ArrayList(org.apache.pivot.collections.ArrayList) Component(org.apache.pivot.wtk.Component)

Example 8 with Component

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);
            }
        }
    });
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) SerializationException(org.apache.pivot.serialization.SerializationException) IOException(java.io.IOException) URL(java.net.URL) ButtonGroupListener(org.apache.pivot.wtk.ButtonGroupListener) Mouse(org.apache.pivot.wtk.Mouse) ButtonGroup(org.apache.pivot.wtk.ButtonGroup) Button(org.apache.pivot.wtk.Button) ScrollBarPolicy(org.apache.pivot.wtk.ScrollPane.ScrollBarPolicy) TreeViewSelectionListener(org.apache.pivot.wtk.TreeViewSelectionListener) TreeView(org.apache.pivot.wtk.TreeView) ComponentMouseButtonListener(org.apache.pivot.wtk.ComponentMouseButtonListener) List(org.apache.pivot.collections.List) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 9 with Component

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);
    }
}
Also used : Component(org.apache.pivot.wtk.Component)

Example 10 with Component

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;
}
Also used : Sequence(org.apache.pivot.collections.Sequence) DefaultProperty(org.apache.pivot.beans.DefaultProperty) TreeBranch(org.apache.pivot.wtk.content.TreeBranch) TreeNode(org.apache.pivot.wtk.content.TreeNode) BeanAdapter(org.apache.pivot.beans.BeanAdapter) Component(org.apache.pivot.wtk.Component) TablePane(org.apache.pivot.wtk.TablePane)

Aggregations

Component (org.apache.pivot.wtk.Component)209 Dimensions (org.apache.pivot.wtk.Dimensions)40 Point (org.apache.pivot.wtk.Point)38 GradientPaint (java.awt.GradientPaint)33 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)24 TextInput (org.apache.pivot.wtk.TextInput)21 Label (org.apache.pivot.wtk.Label)20 BoxPane (org.apache.pivot.wtk.BoxPane)18 Paint (java.awt.Paint)17 Button (org.apache.pivot.wtk.Button)15 PushButton (org.apache.pivot.wtk.PushButton)14 ScrollPane (org.apache.pivot.wtk.ScrollPane)14 TablePane (org.apache.pivot.wtk.TablePane)14 Window (org.apache.pivot.wtk.Window)14 IOException (java.io.IOException)13 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)13 Frame (org.apache.pivot.wtk.Frame)13 FlowPane (org.apache.pivot.wtk.FlowPane)12 ComponentStateListener (org.apache.pivot.wtk.ComponentStateListener)11 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)10