Search in sources :

Example 1 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class EventLoggerSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    EventLogger eventLogger = (EventLogger) component;
    eventLogger.getEventLoggerListeners().add(this);
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    try {
        content = (Component) bxmlSerializer.readObject(EventLoggerSkin.class, "event_logger_skin.bxml", true);
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    } catch (SerializationException exception) {
        throw new RuntimeException(exception);
    }
    eventLogger.add(content);
    declaredEventsTreeView = (TreeView) bxmlSerializer.getNamespace().get("declaredEventsTreeView");
    firedEventsTableView = (TableView) bxmlSerializer.getNamespace().get("firedEventsTableView");
    // Propagate check state upwards or downwards as necessary
    declaredEventsTreeView.getTreeViewNodeStateListeners().add(new TreeViewNodeStateListener() {

        @Override
        public void nodeCheckStateChanged(TreeView treeView, Path path, TreeView.NodeCheckState previousCheckState) {
            TreeView.NodeCheckState checkState = treeView.getNodeCheckState(path);
            if (!updating) {
                // Set the updating flag for the life of this event loop
                updating = true;
                ApplicationContext.queueCallback(new Runnable() {

                    @Override
                    public void run() {
                        updating = false;
                    }
                });
                EventLogger eventLoggerLocal = (EventLogger) getComponent();
                boolean checked = (checkState == TreeView.NodeCheckState.CHECKED);
                List<?> treeData = treeView.getTreeData();
                TreeNode treeNode = (TreeNode) Sequence.Tree.get(treeData, path);
                if (treeNode instanceof List<?>) {
                    if (previousCheckState == TreeView.NodeCheckState.CHECKED || checkState == TreeView.NodeCheckState.CHECKED) {
                        // Propagate downward
                        List<?> treeBranch = (List<?>) treeNode;
                        Path childPath = new Path(path);
                        int lastIndex = childPath.getLength();
                        childPath.add(0);
                        for (int i = 0, n = treeBranch.getLength(); i < n; i++) {
                            childPath.update(lastIndex, i);
                            treeView.setNodeChecked(childPath, checked);
                            EventNode eventNode = (EventNode) treeBranch.get(i);
                            Method event = eventNode.getEvent();
                            if (checked) {
                                eventLoggerLocal.getIncludeEvents().add(event);
                            } else {
                                eventLoggerLocal.getIncludeEvents().remove(event);
                            }
                        }
                    }
                } else {
                    Path parentPath = new Path(path, path.getLength() - 1);
                    EventNode eventNode = (EventNode) treeNode;
                    Method event = eventNode.getEvent();
                    if (checked) {
                        List<?> treeBranch = (List<?>) Sequence.Tree.get(treeData, parentPath);
                        Path childPath = new Path(path);
                        int lastIndex = parentPath.getLength();
                        int i = 0, n = treeBranch.getLength();
                        while (i < n) {
                            childPath.update(lastIndex, i);
                            if (!treeView.isNodeChecked(childPath)) {
                                break;
                            }
                            i++;
                        }
                        if (i == n) {
                            // Propagate upward
                            treeView.setNodeChecked(parentPath, checked);
                        }
                        eventLoggerLocal.getIncludeEvents().add(event);
                    } else {
                        // Propagate upward
                        treeView.setNodeChecked(parentPath, checked);
                        eventLoggerLocal.getIncludeEvents().remove(event);
                    }
                }
            }
        }
    });
    sourceChanged(eventLogger, null);
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) TreeViewNodeStateListener(org.apache.pivot.wtk.TreeViewNodeStateListener) SerializationException(org.apache.pivot.serialization.SerializationException) IOException(java.io.IOException) Method(java.lang.reflect.Method) TreeNode(org.apache.pivot.wtk.content.TreeNode) TreeView(org.apache.pivot.wtk.TreeView) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 2 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class ComponentExplorer method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    window = (ComponentExplorerWindow) bxmlSerializer.readObject(ComponentExplorer.class, "component_explorer_window.bxml", true);
    window.setClassProperty(properties.get(CLASS_PROPERTY));
    window.open(display);
}
Also used : BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 3 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer 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 4 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class Pivot965Main method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    window = (Window) bxmlSerializer.readObject(Window.class, "/org/apache/pivot/tests/issues/pivot965/Window965.bxml");
    window.open(display);
    TextInput textInput = (TextInput) bxmlSerializer.getNamespace().get("textInput");
    textInput.requestFocus();
}
Also used : TextInput(org.apache.pivot.wtk.TextInput) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 5 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class KitchenSink method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    this.window = (Window) bxmlSerializer.readObject(KitchenSink.class, "kitchen_sink.bxml");
    bxmlSerializer.bind(this, KitchenSink.class);
    this.infoRollup = (Rollup) bxmlSerializer.getNamespace().get("infoRollup");
    this.infoRollup.getRollupStateListeners().add(new InfoRollupStateHandler());
    this.buttonsRollup = (Rollup) bxmlSerializer.getNamespace().get("buttonsRollup");
    this.buttonsRollup.getRollupStateListeners().add(new ButtonsRollupStateHandler());
    this.listsRollup = (Rollup) bxmlSerializer.getNamespace().get("listsRollup");
    this.listsRollup.getRollupStateListeners().add(new ListsRollupStateHandler());
    this.textRollup = (Rollup) bxmlSerializer.getNamespace().get("textRollup");
    this.textRollup.getRollupStateListeners().add(new TextRollupStateHandler());
    this.calendarsRollup = (Rollup) bxmlSerializer.getNamespace().get("calendarsRollup");
    this.calendarsRollup.getRollupStateListeners().add(new CalendarsRollupStateHandler());
    this.colorChoosersRollup = (Rollup) bxmlSerializer.getNamespace().get("colorChoosersRollup");
    this.colorChoosersRollup.getRollupStateListeners().add(new ColorChoosersRollupStateHandler());
    this.navigationRollup = (Rollup) bxmlSerializer.getNamespace().get("navigationRollup");
    this.navigationRollup.getRollupStateListeners().add(new NavigationRollupStateHandler());
    this.splittersRollup = (Rollup) bxmlSerializer.getNamespace().get("splittersRollup");
    this.splittersRollup.getRollupStateListeners().add(new SplittersRollupStateHandler());
    this.menusRollup = (Rollup) bxmlSerializer.getNamespace().get("menusRollup");
    this.menusRollup.getRollupStateListeners().add(new MenusRollupStateHandler());
    this.metersRollup = (Rollup) bxmlSerializer.getNamespace().get("metersRollup");
    this.metersRollup.getRollupStateListeners().add(new MetersRollupStateHandler());
    this.spinnersRollup = (Rollup) bxmlSerializer.getNamespace().get("spinnersRollup");
    this.spinnersRollup.getRollupStateListeners().add(new SpinnersRollupStateHandler());
    this.tablesRollup = (Rollup) bxmlSerializer.getNamespace().get("tablesRollup");
    this.tablesRollup.getRollupStateListeners().add(new TablesRollupStateHandler());
    this.treesRollup = (Rollup) bxmlSerializer.getNamespace().get("treesRollup");
    this.treesRollup.getRollupStateListeners().add(new TreesRollupStateHandler());
    this.dragDropRollup = (Rollup) bxmlSerializer.getNamespace().get("dragDropRollup");
    this.dragDropRollup.getRollupStateListeners().add(new DragDropRollupStateHandler());
    this.alertsRollup = (Rollup) bxmlSerializer.getNamespace().get("alertsRollup");
    this.alertsRollup.getRollupStateListeners().add(new AlertsRollupStateHandler());
    this.window.open(display);
    // Start with the "Info" rollup expanded
    ApplicationContext.scheduleCallback(new Runnable() {

        @Override
        public void run() {
            KitchenSink.this.infoRollup.setExpanded(true);
        }
    }, 0);
}
Also used : BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Aggregations

BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)86 Component (org.apache.pivot.wtk.Component)24 IOException (java.io.IOException)19 SerializationException (org.apache.pivot.serialization.SerializationException)14 Window (org.apache.pivot.wtk.Window)13 Button (org.apache.pivot.wtk.Button)11 PushButton (org.apache.pivot.wtk.PushButton)11 File (java.io.File)9 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)9 Frame (org.apache.pivot.wtk.Frame)8 TextInput (org.apache.pivot.wtk.TextInput)8 ArrayList (org.apache.pivot.collections.ArrayList)7 List (org.apache.pivot.collections.List)7 Mouse (org.apache.pivot.wtk.Mouse)6 Sequence (org.apache.pivot.collections.Sequence)5 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)5 ListButton (org.apache.pivot.wtk.ListButton)5 TextInputContentListener (org.apache.pivot.wtk.TextInputContentListener)5 URL (java.net.URL)4 MalformedURLException (java.net.MalformedURLException)3