Search in sources :

Example 1 with ButtonGroup

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);
            }
        }
    });
}
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 2 with ButtonGroup

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));
}
Also used : Frame(org.apache.pivot.wtk.Frame) CardPane(org.apache.pivot.wtk.CardPane) Vote(org.apache.pivot.util.Vote) BoxPane(org.apache.pivot.wtk.BoxPane) ButtonGroup(org.apache.pivot.wtk.ButtonGroup) Button(org.apache.pivot.wtk.Button) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) ButtonGroupListener(org.apache.pivot.wtk.ButtonGroupListener) CardPaneListener(org.apache.pivot.wtk.CardPaneListener)

Example 3 with ButtonGroup

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);
}
Also used : Window(org.apache.pivot.wtk.Window) ButtonGroup(org.apache.pivot.wtk.ButtonGroup) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) ButtonGroupListener(org.apache.pivot.wtk.ButtonGroupListener)

Example 4 with ButtonGroup

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

Aggregations

Button (org.apache.pivot.wtk.Button)4 ButtonGroup (org.apache.pivot.wtk.ButtonGroup)4 ButtonGroupListener (org.apache.pivot.wtk.ButtonGroupListener)3 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)2 BoxPane (org.apache.pivot.wtk.BoxPane)2 PushButton (org.apache.pivot.wtk.PushButton)2 IOException (java.io.IOException)1 URL (java.net.URL)1 List (org.apache.pivot.collections.List)1 Path (org.apache.pivot.collections.Sequence.Tree.Path)1 SerializationException (org.apache.pivot.serialization.SerializationException)1 Vote (org.apache.pivot.util.Vote)1 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)1 CardPane (org.apache.pivot.wtk.CardPane)1 CardPaneListener (org.apache.pivot.wtk.CardPaneListener)1 Component (org.apache.pivot.wtk.Component)1 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)1 Frame (org.apache.pivot.wtk.Frame)1 Mouse (org.apache.pivot.wtk.Mouse)1 ScrollBarPolicy (org.apache.pivot.wtk.ScrollPane.ScrollBarPolicy)1