Search in sources :

Example 1 with InputValidator

use of com.kotcrab.vis.ui.util.InputValidator in project gdx-graph by MarcinSc.

the class GraphContainer method processRightClick.

private void processRightClick(float x, float y) {
    if (!containedInWindow(x, y)) {
        NodeGroupImpl nodeGroup = null;
        for (Map.Entry<NodeGroupImpl, Rectangle> nodeGroupEntry : nodeGroups.entrySet()) {
            Rectangle rectangle = nodeGroupEntry.getValue();
            if (rectangle.contains(x, y) && y > rectangle.y + rectangle.height - GROUP_LABEL_HEIGHT) {
                // Hit the label
                nodeGroup = nodeGroupEntry.getKey();
                break;
            }
        }
        if (nodeGroup != null) {
            final NodeGroupImpl finalNodeGroup = nodeGroup;
            PopupMenu popupMenu = new PopupMenu();
            MenuItem rename = new MenuItem("Rename group");
            rename.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    Dialogs.showInputDialog(getStage(), "Enter group name", "Name", new InputValidator() {

                        @Override
                        public boolean validateInput(String input) {
                            return !input.trim().isEmpty();
                        }
                    }, new InputDialogListener() {

                        @Override
                        public void finished(String input) {
                            finalNodeGroup.setName(input.trim());
                            fire(new GraphChangedEvent(false, false));
                        }

                        @Override
                        public void canceled() {
                        }
                    });
                }
            });
            popupMenu.addItem(rename);
            MenuItem remove = new MenuItem("Remove group");
            remove.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    nodeGroups.remove(finalNodeGroup);
                    fire(new GraphChangedEvent(false, false));
                }
            });
            popupMenu.addItem(remove);
            popupMenu.showMenu(getStage(), x + getX(), y + getY());
        } else {
            PopupMenu popupMenu = popupMenuProducer.createPopupMenu(x, y);
            popupMenu.showMenu(getStage(), x + getX(), y + getY());
        }
    }
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle) MenuItem(com.kotcrab.vis.ui.widget.MenuItem) InputDialogListener(com.kotcrab.vis.ui.util.dialog.InputDialogListener) InputValidator(com.kotcrab.vis.ui.util.InputValidator) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) PopupMenu(com.kotcrab.vis.ui.widget.PopupMenu)

Example 2 with InputValidator

use of com.kotcrab.vis.ui.util.InputValidator in project vis-ui by kotcrab.

the class ArraySpinnerModel method bind.

@Override
public void bind(Spinner spinner) {
    super.bind(spinner);
    updateCurrentItem(0);
    spinner.getTextField().addValidator(new InputValidator() {

        @Override
        public boolean validateInput(String input) {
            return getItemIndexForText(input) != -1;
        }
    });
    spinner.notifyValueChanged(true);
}
Also used : InputValidator(com.kotcrab.vis.ui.util.InputValidator)

Example 3 with InputValidator

use of com.kotcrab.vis.ui.util.InputValidator in project vis-ui by kotcrab.

the class SimpleFormValidator method validate.

/**
 * Performs full check of this form, typically there is no need to call this method manually since form will be automatically
 * validated upon field content change. However calling this might be required when change made to field state does not
 * cause change event to be fired. For example disabling or enabling field.
 */
public void validate() {
    formInvalid = false;
    errorMsgText = null;
    for (CheckedButtonWrapper wrapper : buttons) {
        if (wrapper.button.isChecked() != wrapper.mustBeChecked) {
            wrapper.setButtonStateInvalid(true);
        } else {
            wrapper.setButtonStateInvalid(false);
        }
    }
    for (CheckedButtonWrapper wrapper : buttons) {
        if (treatDisabledFieldsAsValid && wrapper.button.isDisabled()) {
            continue;
        }
        if (wrapper.button.isChecked() != wrapper.mustBeChecked) {
            errorMsgText = wrapper.errorMsg;
            formInvalid = true;
            break;
        }
    }
    for (VisValidatableTextField field : fields) {
        field.validateInput();
    }
    for (VisValidatableTextField field : fields) {
        if (treatDisabledFieldsAsValid && field.isDisabled()) {
            continue;
        }
        if (field.isInputValid() == false) {
            Array<InputValidator> validators = field.getValidators();
            for (InputValidator v : validators) {
                if (v instanceof FormInputValidator == false) {
                    throw new IllegalStateException("Fields validated by FormValidator cannot have validators not added using FormValidator methods. " + "Are you adding validators to field manually?");
                }
                FormInputValidator validator = (FormInputValidator) v;
                if (validator.getLastResult() == false) {
                    if (!(validator.isHideErrorOnEmptyInput() && field.getText().equals(""))) {
                        errorMsgText = validator.getErrorMsg();
                    }
                    formInvalid = true;
                    break;
                }
            }
            break;
        }
    }
    updateWidgets();
}
Also used : InputValidator(com.kotcrab.vis.ui.util.InputValidator) VisValidatableTextField(com.kotcrab.vis.ui.widget.VisValidatableTextField)

Example 4 with InputValidator

use of com.kotcrab.vis.ui.util.InputValidator in project HyperLap2D by rednblackgames.

the class GraphContainer method setupListeners.

private void setupListeners() {
    addListener(new ClickListener(Input.Buttons.RIGHT) {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (!containedInWindow(x, y)) {
                NodeGroupImpl nodeGroup = null;
                for (Map.Entry<NodeGroupImpl, Rectangle> nodeGroupEntry : nodeGroups.entrySet()) {
                    Rectangle rectangle = nodeGroupEntry.getValue();
                    if (rectangle.contains(x, y) && y > rectangle.y + rectangle.height - GROUP_LABEL_HEIGHT) {
                        // Hit the label
                        nodeGroup = nodeGroupEntry.getKey();
                        break;
                    }
                }
                if (nodeGroup != null) {
                    final NodeGroupImpl finalNodeGroup = nodeGroup;
                    H2DPopupMenu popupMenu = new H2DPopupMenu();
                    MenuItem rename = new MenuItem("Rename group");
                    rename.addListener(new ClickListener(Input.Buttons.LEFT) {

                        @Override
                        public void clicked(InputEvent event, float x, float y) {
                            Dialogs.showInputDialog(getStage(), "Enter group name", "Name", new InputValidator() {

                                @Override
                                public boolean validateInput(String input) {
                                    return !input.trim().isEmpty();
                                }
                            }, new InputDialogListener() {

                                @Override
                                public void finished(String input) {
                                    finalNodeGroup.setName(input.trim());
                                    fire(new GraphChangedEvent(false, false));
                                }

                                @Override
                                public void canceled() {
                                }
                            }).setText(finalNodeGroup.getName(), true);
                        }
                    });
                    popupMenu.addItem(rename);
                    MenuItem remove = new MenuItem("Remove group");
                    remove.addListener(new ClickListener(Input.Buttons.LEFT) {

                        @Override
                        public void clicked(InputEvent event, float x, float y) {
                            nodeGroups.remove(finalNodeGroup);
                            fire(new GraphChangedEvent(false, false));
                        }
                    });
                    popupMenu.addItem(remove);
                    showPopupMenu(popupMenu);
                } else {
                    H2DPopupMenu popupMenu = popupMenuProducer.createPopupMenu(x, y);
                    showPopupMenu(popupMenu);
                }
            }
        }
    });
    addListener(new ClickListener(Input.Buttons.LEFT) {

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            processLeftClick(x, y);
            return super.touchDown(event, x, y, pointer, button);
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            super.touchUp(event, x, y, pointer, button);
            processLeftClick(x, y);
        }
    });
    DragListener dragListener = new DragListener() {

        private float canvasXStart;

        private float canvasYStart;

        private NodeGroup dragGroup;

        private float movedByX = 0;

        private float movedByY = 0;

        @Override
        public void dragStart(InputEvent event, float x, float y, int pointer) {
            if (event.getTarget() == GraphContainer.this) {
                canvasXStart = canvasX;
                canvasYStart = canvasY;
                movedByX = 0;
                movedByY = 0;
                dragGroup = null;
                for (Map.Entry<NodeGroupImpl, Rectangle> nodeGroupEntry : nodeGroups.entrySet()) {
                    Rectangle rectangle = nodeGroupEntry.getValue();
                    if (rectangle.contains(x, y) && y > rectangle.y + rectangle.height - GROUP_LABEL_HEIGHT) {
                        // Hit the label
                        dragGroup = nodeGroupEntry.getKey();
                        break;
                    }
                }
            }
        }

        @Override
        public void drag(InputEvent event, float x, float y, int pointer) {
            if (event.getTarget() == GraphContainer.this) {
                if (dragGroup != null) {
                    movingSelected = true;
                    float moveByX = x - getDragStartX() - movedByX;
                    float moveByY = y - getDragStartY() - movedByY;
                    for (String nodeId : dragGroup.getNodeIds()) {
                        getBoxWindow(nodeId).moveBy(moveByX, moveByY);
                    }
                    movedByX += moveByX;
                    movedByY += moveByY;
                    windowsMoved();
                    updateNodeGroups();
                    movingSelected = false;
                } else {
                    navigateTo(canvasXStart + getDragStartX() - x, canvasYStart + getDragStartY() - y);
                }
            }
        }
    };
    dragListener.setTapSquareSize(0f);
    dragListener.setButton(Input.Buttons.MIDDLE);
    addListener(dragListener);
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle) H2DPopupMenu(games.rednblack.h2d.common.view.ui.widget.H2DPopupMenu) MenuItem(com.kotcrab.vis.ui.widget.MenuItem) InputDialogListener(com.kotcrab.vis.ui.util.dialog.InputDialogListener) DragListener(com.badlogic.gdx.scenes.scene2d.utils.DragListener) InputValidator(com.kotcrab.vis.ui.util.InputValidator) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

InputValidator (com.kotcrab.vis.ui.util.InputValidator)4 Rectangle (com.badlogic.gdx.math.Rectangle)2 InputDialogListener (com.kotcrab.vis.ui.util.dialog.InputDialogListener)2 MenuItem (com.kotcrab.vis.ui.widget.MenuItem)2 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)1 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)1 DragListener (com.badlogic.gdx.scenes.scene2d.utils.DragListener)1 PopupMenu (com.kotcrab.vis.ui.widget.PopupMenu)1 VisValidatableTextField (com.kotcrab.vis.ui.widget.VisValidatableTextField)1 H2DPopupMenu (games.rednblack.h2d.common.view.ui.widget.H2DPopupMenu)1