Search in sources :

Example 56 with Button

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

the class BoxPanes method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    boxPane = (BoxPane) namespace.get("boxPane");
    horizontalOrientationButton = (RadioButton) namespace.get("horizontalOrientationButton");
    verticalOrientationButton = (RadioButton) namespace.get("verticalOrientationButton");
    horizontalAlignmentRightButton = (RadioButton) namespace.get("horizontalAlignmentRightButton");
    horizontalAlignmentLeftButton = (RadioButton) namespace.get("horizontalAlignmentLeftButton");
    horizontalAlignmentCenterButton = (RadioButton) namespace.get("horizontalAlignmentCenterButton");
    verticalAlignmentTopButton = (RadioButton) namespace.get("verticalAlignmentTopButton");
    verticalAlignmentBottomButton = (RadioButton) namespace.get("verticalAlignmentBottomButton");
    verticalAlignmentCenterButton = (RadioButton) namespace.get("verticalAlignmentCenterButton");
    fillCheckbox = (Checkbox) namespace.get("fillCheckbox");
    ButtonStateListener buttonStateListener = new ButtonStateListener() {

        @Override
        public void stateChanged(Button button, Button.State previousState) {
            updateBoxPaneState();
        }
    };
    horizontalOrientationButton.getButtonStateListeners().add(buttonStateListener);
    verticalOrientationButton.getButtonStateListeners().add(buttonStateListener);
    horizontalAlignmentLeftButton.getButtonStateListeners().add(buttonStateListener);
    horizontalAlignmentRightButton.getButtonStateListeners().add(buttonStateListener);
    horizontalAlignmentCenterButton.getButtonStateListeners().add(buttonStateListener);
    verticalAlignmentTopButton.getButtonStateListeners().add(buttonStateListener);
    verticalAlignmentBottomButton.getButtonStateListeners().add(buttonStateListener);
    verticalAlignmentCenterButton.getButtonStateListeners().add(buttonStateListener);
    fillCheckbox.getButtonStateListeners().add(buttonStateListener);
    updateBoxPaneState();
}
Also used : RadioButton(org.apache.pivot.wtk.RadioButton) Button(org.apache.pivot.wtk.Button) ButtonStateListener(org.apache.pivot.wtk.ButtonStateListener)

Example 57 with Button

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

the class FlowPanes method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    flowPane = (FlowPane) namespace.get("flowPane");
    leftRadioButton = (RadioButton) namespace.get("leftRadioButton");
    rightRadioButton = (RadioButton) namespace.get("rightRadioButton");
    centerRadioButton = (RadioButton) namespace.get("centerRadioButton");
    alignToBaselineCheckbox = (Checkbox) namespace.get("alignToBaselineCheckbox");
    ButtonStateListener buttonStateListener = new ButtonStateListener() {

        @Override
        public void stateChanged(Button button, Button.State previousState) {
            updateFlowPaneState();
        }
    };
    leftRadioButton.getButtonStateListeners().add(buttonStateListener);
    rightRadioButton.getButtonStateListeners().add(buttonStateListener);
    centerRadioButton.getButtonStateListeners().add(buttonStateListener);
    alignToBaselineCheckbox.getButtonStateListeners().add(buttonStateListener);
    updateFlowPaneState();
}
Also used : RadioButton(org.apache.pivot.wtk.RadioButton) Button(org.apache.pivot.wtk.Button) ButtonStateListener(org.apache.pivot.wtk.ButtonStateListener)

Example 58 with Button

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

the class RepeatableListButtons method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    colorListButton = (ListButton) namespace.get("colorListButton");
    checkboxBoxPane = (BoxPane) namespace.get("checkboxBoxPane");
    ButtonStateListener buttonStateListener = new ButtonStateListener() {

        @Override
        public void stateChanged(Button button, State previousState) {
            if (button.isSelected()) {
                selectedCount++;
            } else {
                selectedCount--;
            }
            applyColorAction.setEnabled(selectedCount > 0);
        }
    };
    ArrayList<String> numbers = new ArrayList<>("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten");
    for (String number : numbers) {
        Checkbox checkbox = new Checkbox(number);
        checkbox.getButtonStateListeners().add(buttonStateListener);
        checkboxBoxPane.add(checkbox);
    }
}
Also used : Button(org.apache.pivot.wtk.Button) ListButton(org.apache.pivot.wtk.ListButton) State(org.apache.pivot.wtk.Button.State) Checkbox(org.apache.pivot.wtk.Checkbox) ArrayList(org.apache.pivot.collections.ArrayList) ButtonStateListener(org.apache.pivot.wtk.ButtonStateListener)

Example 59 with Button

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

the class StockTrackerWindow method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    // Add stocks table view event handlers
    stocksTableView.getTableViewRowListeners().add(new TableViewRowListener() {

        @Override
        public void rowsSorted(TableView tableView) {
            List<?> tableData = stocksTableView.getTableData();
            if (tableData.getLength() > 0) {
                stocksTableView.setSelectedIndex(0);
            }
        }
    });
    stocksTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener() {

        @Override
        public void selectedRangesChanged(TableView tableView, Sequence<Span> previousSelectedRanges) {
            int firstSelectedIndex = stocksTableView.getFirstSelectedIndex();
            removeSymbolsAction.setEnabled(firstSelectedIndex != -1);
            refreshDetail();
        }
    });
    stocksTableView.getTableViewSortListeners().add(new TableViewSortListener() {

        @Override
        public void sortChanged(TableView tableView) {
            @SuppressWarnings("unchecked") List<Object> tableData = (List<Object>) tableView.getTableData();
            tableData.setComparator(new TableViewRowComparator(tableView));
        }
    });
    stocksTableView.getComponentKeyListeners().add(new ComponentKeyListener() {

        @Override
        public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
            if (keyCode == Keyboard.KeyCode.DELETE || keyCode == Keyboard.KeyCode.BACKSPACE) {
                removeSymbolsAction.perform(component);
            } else if (keyCode == Keyboard.KeyCode.A && Keyboard.isPressed(Platform.getCommandModifier())) {
                stocksTableView.selectAll();
            }
            return false;
        }
    });
    // Add symbol text input event handlers
    symbolTextInput.getTextInputContentListeners().add(new TextInputContentListener() {

        @Override
        public void textChanged(TextInput textInput) {
            addSymbolAction.setEnabled(textInput.getCharacterCount() > 0);
        }
    });
    symbolTextInput.getComponentKeyListeners().add(new ComponentKeyListener() {

        @Override
        public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
            if (keyCode == Keyboard.KeyCode.ENTER) {
                if (addSymbolAction.isEnabled()) {
                    addSymbolAction.perform(component);
                }
            }
            return false;
        }
    });
    // Assign actions to add and remove symbol buttons
    addSymbolButton.setAction(addSymbolAction);
    removeSymbolsButton.setAction(removeSymbolsAction);
    // Add a button press listener to open the Yahoo! Finance web page when
    // the link is clicked
    yahooFinanceButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            Desktop desktop = Desktop.getDesktop();
            try {
                desktop.browse(new URL(YAHOO_FINANCE_HOME).toURI());
            } catch (MalformedURLException exception) {
                throw new RuntimeException(exception);
            } catch (URISyntaxException exception) {
                throw new RuntimeException(exception);
            } catch (IOException exception) {
                System.out.println("Unable to open " + YAHOO_FINANCE_HOME + " in default browser.");
            }
        }
    });
}
Also used : MalformedURLException(java.net.MalformedURLException) TableViewSortListener(org.apache.pivot.wtk.TableViewSortListener) URISyntaxException(java.net.URISyntaxException) Span(org.apache.pivot.wtk.Span) URL(java.net.URL) TableViewRowListener(org.apache.pivot.wtk.TableViewRowListener) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) TableViewRowComparator(org.apache.pivot.wtk.content.TableViewRowComparator) TextInputContentListener(org.apache.pivot.wtk.TextInputContentListener) Button(org.apache.pivot.wtk.Button) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) Component(org.apache.pivot.wtk.Component) TextInput(org.apache.pivot.wtk.TextInput) TableViewSelectionListener(org.apache.pivot.wtk.TableViewSelectionListener) TableView(org.apache.pivot.wtk.TableView) Keyboard(org.apache.pivot.wtk.Keyboard) IOException(java.io.IOException) ComponentKeyListener(org.apache.pivot.wtk.ComponentKeyListener) Desktop(java.awt.Desktop)

Example 60 with Button

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

the class CardPanes method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    cardPane = (CardPane) namespace.get("cardPane");
    previousButton = (LinkButton) namespace.get("previousButton");
    nextButton = (LinkButton) namespace.get("nextButton");
    sizeToSelectionCheckbox = (Checkbox) namespace.get("sizeToSelectionCheckbox");
    crossfadeRadioButton = (RadioButton) namespace.get("crossfadeRadioButton");
    horizontalSlideRadioButton = (RadioButton) namespace.get("horizontalSlideRadioButton");
    verticalSlideRadioButton = (RadioButton) namespace.get("verticalSlideRadioButton");
    horizontalFlipRadioButton = (RadioButton) namespace.get("horizontalFlipRadioButton");
    verticalFlipRadioButton = (RadioButton) namespace.get("verticalFlipRadioButton");
    zoomRadioButton = (RadioButton) namespace.get("zoomRadioButton");
    noneRadioButton = (RadioButton) namespace.get("noneRadioButton");
    cardPane.getCardPaneListeners().add(new CardPaneListener() {

        @Override
        public void selectedIndexChanged(CardPane cardPaneArgument, int previousSelectedIndex) {
            updateLinkButtonState();
        }
    });
    previousButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            cardPane.setSelectedIndex(cardPane.getSelectedIndex() - 1);
        }
    });
    nextButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            cardPane.setSelectedIndex(cardPane.getSelectedIndex() + 1);
        }
    });
    ButtonStateListener checkboxStateListener = new ButtonStateListener() {

        @Override
        public void stateChanged(Button button, Button.State previousState) {
            updateCardPane();
        }
    };
    sizeToSelectionCheckbox.getButtonStateListeners().add(checkboxStateListener);
    ButtonStateListener radioButtonStateListener = new ButtonStateListener() {

        @Override
        public void stateChanged(Button button, Button.State previousState) {
            if (button.isSelected()) {
                updateCardPane();
            }
        }
    };
    crossfadeRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    horizontalSlideRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    verticalSlideRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    horizontalFlipRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    verticalFlipRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    zoomRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    noneRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    updateCardPane();
    updateLinkButtonState();
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) CardPane(org.apache.pivot.wtk.CardPane) LinkButton(org.apache.pivot.wtk.LinkButton) RadioButton(org.apache.pivot.wtk.RadioButton) Button(org.apache.pivot.wtk.Button) ButtonStateListener(org.apache.pivot.wtk.ButtonStateListener) CardPaneListener(org.apache.pivot.wtk.CardPaneListener)

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