Search in sources :

Example 1 with Button

use of org.apache.pivot.wtk.Button in project pivot by apache.

the class ComponentInspectorSkin method addBooleanControl.

private Component addBooleanControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
    boolean value = dictionary.getBoolean(key);
    Checkbox checkbox = new Checkbox();
    checkbox.setSelected(value);
    section.add(checkbox);
    Form.setLabel(checkbox, key);
    checkbox.getButtonStateListeners().add(new ButtonStateListener() {

        private boolean updating = false;

        @Override
        public void stateChanged(Button button, Button.State previousState) {
            if (!updating) {
                updating = true;
                try {
                    dictionary.put(key, button.isSelected());
                } catch (Exception exception) {
                    displayErrorMessage(exception, button.getWindow());
                    button.setState(previousState);
                } finally {
                    updating = false;
                }
            }
        }
    });
    return checkbox;
}
Also used : CalendarButton(org.apache.pivot.wtk.CalendarButton) ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton) Button(org.apache.pivot.wtk.Button) ListButton(org.apache.pivot.wtk.ListButton) Checkbox(org.apache.pivot.wtk.Checkbox) ButtonStateListener(org.apache.pivot.wtk.ButtonStateListener)

Example 2 with Button

use of org.apache.pivot.wtk.Button 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 3 with Button

use of org.apache.pivot.wtk.Button in project pivot by apache.

the class Pivot964Pivot method startup.

@Override
public void startup(Display display, Map<String, String> properties) {
    // force dimensions for host frame
    display.getHostWindow().setSize(1028, 600);
    window = new Window();
    prepareSVG();
    final ImageView image = new ImageView(new Drawing(diagram));
    BoxPane bp = new BoxPane();
    TablePane tp = new TablePane();
    setStyles(tp, "{padding: 4}");
    TablePane.Column c1 = new TablePane.Column(-1);
    TablePane.Column c2 = new TablePane.Column(-1);
    tp.getColumns().add(c1);
    tp.getColumns().add(c2);
    TablePane.Row r1 = new TablePane.Row(-1);
    TablePane.Row r2 = new TablePane.Row(-1);
    TablePane.Row r3 = new TablePane.Row(-1);
    PushButton pb1 = new PushButton("Visible");
    PushButton pb2 = new PushButton("Invisible (bug)");
    r1.add(pb1);
    r1.add(pb2);
    final Spinner sp1 = new Spinner(new ListAdapter<>(spinnerData));
    sp1.setPreferredWidth(80);
    sp1.setSelectedIndex(0);
    final Spinner sp2 = new Spinner(new ListAdapter<>(spinnerData));
    sp2.setPreferredWidth(80);
    sp2.setSelectedIndex(0);
    BoxPane bp1 = new BoxPane();
    setStyles(bp1, "{verticalAlignment:'center', padding: 4, spacing: 2}");
    bp1.add(new Label("X:"));
    bp1.add(sp1);
    r2.add(bp1);
    BoxPane bp2 = new BoxPane();
    setStyles(bp2, "{verticalAlignment:'center', padding: 4, spacing: 2}");
    bp2.add(new Label("Y:"));
    bp2.add(sp2);
    r2.add(bp2);
    tp.getRows().add(r1);
    tp.getRows().add(r2);
    r3.add(new Label("   Max X=507"));
    r3.add(new Label("   Max Y=269"));
    tp.getRows().add(r3);
    bp.add(image);
    bp.add(tp);
    pb1.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button arg0) {
            try {
                root.setAttribute("viewBox", AnimationElement.AT_XML, "0 0 2368 1652");
                root.updateTime(0f);
                image.repaint();
            } catch (SVGElementException e) {
                e.printStackTrace();
            } catch (SVGException e) {
                e.printStackTrace();
            }
        }
    });
    pb2.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button arg0) {
            try {
                String xOffset = (String) sp1.getSelectedItem();
                String yOffset = (String) sp2.getSelectedItem();
                String viewBox = String.format("%1$s %2$s 2368 1652", xOffset, yOffset);
                root.setAttribute("viewBox", AnimationElement.AT_XML, viewBox);
                root.updateTime(0f);
                image.repaint();
            } catch (SVGElementException e) {
                e.printStackTrace();
            } catch (SVGException e) {
                e.printStackTrace();
            }
        }
    });
    window.setContent(bp);
    window.setMaximized(true);
    window.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) Drawing(org.apache.pivot.wtk.media.Drawing) Spinner(org.apache.pivot.wtk.Spinner) SVGException(com.kitfox.svg.SVGException) Label(org.apache.pivot.wtk.Label) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) ImageView(org.apache.pivot.wtk.ImageView) SVGElementException(com.kitfox.svg.SVGElementException) PushButton(org.apache.pivot.wtk.PushButton) TablePane(org.apache.pivot.wtk.TablePane)

Example 4 with Button

use of org.apache.pivot.wtk.Button in project pivot by apache.

the class PushButtons method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    pushButton = (PushButton) namespace.get("pushButton");
    pushButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            Alert.alert(MessageType.INFO, "You clicked me!", PushButtons.this);
        }
    });
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button)

Example 5 with Button

use of org.apache.pivot.wtk.Button in project pivot by apache.

the class Transitions method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    button1 = (PushButton) namespace.get("button1");
    button2 = (PushButton) namespace.get("button2");
    button3 = (PushButton) namespace.get("button3");
    button4 = (PushButton) namespace.get("button4");
    ButtonPressListener buttonPressListener = new ButtonPressListener() {

        @Override
        public void buttonPressed(final Button button) {
            if (collapseTransition == null) {
                collapseTransition = new CollapseTransition(button, TRANSITION_DURATION, TRANSITION_RATE);
                TransitionListener transitionListener = new TransitionListener() {

                    @Override
                    public void transitionCompleted(Transition transition) {
                        CollapseTransition collapseTransitionLocal = (CollapseTransition) transition;
                        if (!transition.isReversed()) {
                            Component component = collapseTransitionLocal.getComponent();
                            component.getParent().remove(component);
                        }
                        Transitions.this.collapseTransition = null;
                    }
                };
                collapseTransition.start(transitionListener);
            } else {
                collapseTransition.reverse();
                if (collapseTransition.getComponent() != button) {
                    collapseTransition.end();
                }
            }
        }
    };
    button1.getButtonPressListeners().add(buttonPressListener);
    button2.getButtonPressListeners().add(buttonPressListener);
    button3.getButtonPressListeners().add(buttonPressListener);
    button4.getButtonPressListeners().add(buttonPressListener);
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) Transition(org.apache.pivot.wtk.effects.Transition) TransitionListener(org.apache.pivot.wtk.effects.TransitionListener) Component(org.apache.pivot.wtk.Component)

Aggregations

Button (org.apache.pivot.wtk.Button)61 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)43 PushButton (org.apache.pivot.wtk.PushButton)40 Component (org.apache.pivot.wtk.Component)15 ListButton (org.apache.pivot.wtk.ListButton)12 IOException (java.io.IOException)11 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)11 File (java.io.File)9 BoxPane (org.apache.pivot.wtk.BoxPane)9 Sheet (org.apache.pivot.wtk.Sheet)9 ListView (org.apache.pivot.wtk.ListView)8 SheetCloseListener (org.apache.pivot.wtk.SheetCloseListener)8 ButtonStateListener (org.apache.pivot.wtk.ButtonStateListener)7 List (org.apache.pivot.collections.List)6 Sequence (org.apache.pivot.collections.Sequence)6 FileBrowserSheet (org.apache.pivot.wtk.FileBrowserSheet)6 Point (org.apache.pivot.wtk.Point)6 Span (org.apache.pivot.wtk.Span)6 GradientPaint (java.awt.GradientPaint)5 SerializationException (org.apache.pivot.serialization.SerializationException)5