Example usage for com.badlogic.gdx.scenes.scene2d.ui Dialog text

List of usage examples for com.badlogic.gdx.scenes.scene2d.ui Dialog text

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.ui Dialog text.

Prototype

public Dialog text(Label label) 

Source Link

Document

Adds the given Label to the content table

Usage

From source file:com.ray3k.skincomposer.dialog.DialogColors.java

License:Open Source License

private void showColorPicker() {
    dialogFactory.showDialogColorPicker(new DialogColorPicker.ColorListener() {
        @Override//from w w  w  .  j  a  v  a  2 s.  co m
        public void selected(Color color) {
            if (color != null) {
                final TextField field = new TextField("RGBA_" + (int) (color.r * 255) + "_"
                        + (int) (color.g * 255) + "_" + (int) (color.b * 255) + "_" + (int) (color.a * 255),
                        skin);
                final Dialog dialog = new Dialog("Color name...", skin, "bg") {
                    @Override
                    protected void result(Object object) {
                        if ((Boolean) object == true) {
                            newColor(field.getText(), color);
                        }
                    }
                };

                dialog.getTitleTable().padLeft(5.0f);

                dialog.button("Ok", true).button("Cancel", false).key(Keys.ESCAPE, false);
                final TextButton button = (TextButton) dialog.getButtonTable().getCells().first().getActor();
                button.addListener(main.getHandListener());
                dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
                dialog.getButtonTable().pad(15.0f);

                field.setTextFieldListener(new TextField.TextFieldListener() {
                    @Override
                    public void keyTyped(TextField textField, char c) {
                        if (c == '\n') {
                            if (!button.isDisabled()) {
                                String name = field.getText();
                                if (newColor(name, color)) {
                                    dialog.hide();
                                }
                            }
                            main.getStage().setKeyboardFocus(textField);
                        }
                    }
                });

                field.addListener(main.getIbeamListener());

                dialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
                dialog.text("Please enter a name for the new color: ");
                dialog.getContentTable().row();
                dialog.getContentTable().add(field).growX();
                dialog.getContentTable().row();
                dialog.text("Preview:");
                dialog.getContentTable().row();
                Table table = new Table(skin);
                table.setBackground("white");
                table.setColor(color);
                dialog.getContentTable().add(table).minSize(50.0f);
                button.setDisabled(!ColorData.validate(field.getText()));
                field.addListener(new ChangeListener() {
                    @Override
                    public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                        boolean disable = !ColorData.validate(field.getText());
                        if (!disable) {
                            for (ColorData data : jsonData.getColors()) {
                                if (data.getName().equals(field.getText())) {
                                    disable = true;
                                    break;
                                }
                            }
                        }
                        button.setDisabled(disable);
                    }
                });
                dialog.show(getStage());
                getStage().setKeyboardFocus(field);
                field.selectAll();
                field.setFocusTraversal(false);
            }
        }
    });
}

From source file:com.ray3k.skincomposer.dialog.DialogDrawables.java

License:Open Source License

private void colorSwatchesDialog(DrawableData drawableData) {
    DialogColors dialog = new DialogColors(getSkin(), "dialog", null, true, dialogFactory, jsonData,
            projectData, atlasData, main, (ColorData colorData) -> {
                if (colorData != null) {
                    final DrawableData tintedDrawable = new DrawableData(drawableData.file);
                    tintedDrawable.tintName = colorData.getName();

                    //Fix background color for new, tinted drawable
                    Color temp = Utils.averageEdgeColor(tintedDrawable.file, colorData.color);

                    if (Utils.brightness(temp) > .5f) {
                        tintedDrawable.bgColor = Color.BLACK;
                    } else {
                        tintedDrawable.bgColor = Color.WHITE;
                    }//from  w  ww .  j  av  a2 s .  co m

                    final TextField textField = new TextField(drawableData.name, getSkin());
                    final TextButton button = new TextButton("OK", getSkin());
                    button.setDisabled(!DrawableData.validate(textField.getText())
                            || checkIfNameExists(textField.getText()));
                    button.addListener(main.getHandListener());
                    textField.addListener(new ChangeListener() {
                        @Override
                        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                            button.setDisabled(!DrawableData.validate(textField.getText())
                                    || checkIfNameExists(textField.getText()));
                        }
                    });
                    textField.addListener(main.getIbeamListener());

                    Dialog approveDialog = new Dialog("TintedDrawable...", getSkin(), "bg") {
                        @Override
                        protected void result(Object object) {
                            if (object instanceof Boolean && (boolean) object) {
                                tintedDrawable.name = textField.getText();
                                atlasData.getDrawables().add(tintedDrawable);
                                projectData.setChangesSaved(false);
                            }
                        }

                        @Override
                        public boolean remove() {
                            gatherDrawables();
                            produceAtlas();
                            sortBySelectedMode();
                            getStage().setScrollFocus(scrollPane);
                            return super.remove();
                        }
                    };
                    approveDialog.addCaptureListener(new InputListener() {
                        @Override
                        public boolean keyDown(InputEvent event, int keycode2) {
                            if (keycode2 == Input.Keys.ENTER) {
                                if (!button.isDisabled()) {
                                    tintedDrawable.name = textField.getText();
                                    atlasData.getDrawables().add(tintedDrawable);
                                    projectData.setChangesSaved(false);
                                    approveDialog.hide();
                                }
                            }
                            return false;
                        }
                    });

                    approveDialog.getTitleTable().padLeft(5.0f);
                    approveDialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
                    approveDialog.getButtonTable().padBottom(15.0f);

                    approveDialog.text("What is the name of the new tinted drawable?");

                    Drawable drawable = drawablePairs.get(drawableData);
                    Drawable preview = null;
                    if (drawable instanceof SpriteDrawable) {
                        preview = ((SpriteDrawable) drawable).tint(colorData.color);
                    } else if (drawable instanceof NinePatchDrawable) {
                        preview = ((NinePatchDrawable) drawable).tint(colorData.color);
                    }
                    if (preview != null) {
                        approveDialog.getContentTable().row();
                        Table table = new Table();
                        table.setBackground(preview);
                        approveDialog.getContentTable().add(table);
                    }

                    approveDialog.getContentTable().row();
                    approveDialog.getContentTable().add(textField).growX();

                    approveDialog.button(button, true);
                    approveDialog.button("Cancel", false);
                    approveDialog.getButtonTable().getCells().get(1).getActor()
                            .addListener(main.getHandListener());
                    approveDialog.key(Input.Keys.ESCAPE, false);
                    approveDialog.show(getStage());
                    getStage().setKeyboardFocus(textField);
                    textField.selectAll();

                    textField.setFocusTraversal(false);
                }
            });
    dialog.setFillParent(true);
    dialog.show(getStage());
    dialog.populate();
}

From source file:com.ray3k.skincomposer.dialog.DialogDrawables.java

License:Open Source License

/**
 * Shows a dialog to confirm deletion of all TintedDrawables based on the
 * provided drawable data. This is called when the delete button is pressed
 * on a drawable in the drawable list./*  w  ww.  j a  v  a2s.c o  m*/
 * @param drawable 
 */
private void showConfirmDeleteDialog(DrawableData drawable) {
    Dialog dialog = new Dialog("Delete duplicates?", getSkin(), "bg") {
        @Override
        protected void result(Object object) {
            if ((boolean) object) {
                removeDuplicateDrawables(drawable.file);
                gatherDrawables();
                sortBySelectedMode();
            }
        }
    };

    dialog.getTitleTable().padLeft(5.0f);
    dialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
    dialog.getButtonTable().padBottom(15.0f);

    dialog.text(
            "Deleting this drawable will also delete one or more tinted drawables.\n" + "Delete duplicates?");
    dialog.button("OK", true);
    dialog.button("Cancel", false);
    dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    dialog.key(Input.Keys.ENTER, true);
    dialog.key(Input.Keys.ESCAPE, false);
    dialog.show(getStage());
}

From source file:com.ray3k.skincomposer.dialog.DialogDrawables.java

License:Open Source License

/**
 * Show an setStatusBarError indicating a drawable that exceeds project specifications
 *//* w w w  .j a v  a  2  s .  co m*/
private void showDrawableError() {
    Dialog dialog = new Dialog("Error...", getSkin(), "bg");

    dialog.getTitleTable().padLeft(5.0f);
    dialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
    dialog.getButtonTable().padBottom(15.0f);

    Label label = new Label(
            "Error while adding new drawables.\nEnsure that image dimensions are\nless than maximums specified in project.\nRolling back changes...",
            getSkin());
    label.setAlignment(Align.center);
    dialog.text(label);
    dialog.button("OK");
    dialog.show(getStage());
}

From source file:com.ray3k.skincomposer.dialog.DialogDrawables.java

License:Open Source License

/**
 * Shows a dialog to confirm removal of duplicate drawables that have the
 * same name without extension. This is called after selecting new drawables.
 * @param unhandledFiles/*ww w.  j a v a  2  s .c  om*/
 * @param backup
 * @param filesToProcess 
 */
private void showRemoveDuplicatesDialog(Array<FileHandle> unhandledFiles, Array<DrawableData> backup,
        Array<FileHandle> filesToProcess) {
    Dialog dialog = new Dialog("Delete duplicates?", getSkin(), "bg") {
        @Override
        protected void result(Object object) {
            if ((boolean) object) {
                for (FileHandle fileHandle : unhandledFiles) {
                    removeDuplicateDrawables(fileHandle);
                    filesToProcess.add(fileHandle);
                }
            }
            finalizeDrawables(backup, filesToProcess);
        }
    };

    dialog.getTitleTable().padLeft(5.0f);
    dialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
    dialog.getButtonTable().padBottom(15.0f);

    dialog.text("Adding this drawable will overwrite one or more drawables\n" + "Delete duplicates?");
    dialog.button("OK", true);
    dialog.button("Cancel", false);
    dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    dialog.key(Input.Keys.ENTER, true);
    dialog.key(Input.Keys.ESCAPE, false);
    dialog.show(getStage());
}

From source file:com.ray3k.skincomposer.dialog.DialogDrawables.java

License:Open Source License

/**
 * Creates a TintedDrawable based on the provided DrawableData. Prompts
 * user for a Color and name.//from ww  w .  j a v a2 s  .  co m
 * @param drawableData 
 */
private void newTintedDrawable(DrawableData drawableData) {
    Color previousColor = Color.WHITE;
    if (drawableData.tint != null) {
        previousColor = drawableData.tint;
    }
    dialogFactory.showDialogColorPicker(previousColor, new DialogColorPicker.ColorListener() {
        @Override
        public void selected(Color color) {
            if (color != null) {
                final DrawableData tintedDrawable = new DrawableData(drawableData.file);
                tintedDrawable.tint = color;

                //Fix background color for new, tinted drawable
                Color temp = Utils.averageEdgeColor(tintedDrawable.file, tintedDrawable.tint);

                if (Utils.brightness(temp) > .5f) {
                    tintedDrawable.bgColor = Color.BLACK;
                } else {
                    tintedDrawable.bgColor = Color.WHITE;
                }

                final TextField textField = new TextField(drawableData.name, getSkin());
                final TextButton button = new TextButton("OK", getSkin());
                button.setDisabled(
                        !DrawableData.validate(textField.getText()) || checkIfNameExists(textField.getText()));
                textField.addListener(new ChangeListener() {
                    @Override
                    public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                        button.setDisabled(!DrawableData.validate(textField.getText())
                                || checkIfNameExists(textField.getText()));
                    }
                });
                textField.addListener(main.getIbeamListener());

                Dialog dialog = new Dialog("TintedDrawable...", getSkin(), "bg") {
                    @Override
                    protected void result(Object object) {
                        if (object instanceof Boolean && (boolean) object) {
                            tintedDrawable.name = textField.getText();
                            atlasData.getDrawables().add(tintedDrawable);
                            projectData.setChangesSaved(false);
                        }
                    }

                    @Override
                    public boolean remove() {
                        gatherDrawables();
                        produceAtlas();
                        sortBySelectedMode();
                        getStage().setScrollFocus(scrollPane);
                        return super.remove();
                    }
                };
                dialog.getTitleTable().getCells().first().padLeft(5.0f);
                dialog.addCaptureListener(new InputListener() {
                    @Override
                    public boolean keyDown(InputEvent event, int keycode2) {
                        if (keycode2 == Input.Keys.ENTER) {
                            if (!button.isDisabled()) {
                                tintedDrawable.name = textField.getText();
                                atlasData.getDrawables().add(tintedDrawable);
                                projectData.setChangesSaved(false);
                                dialog.hide();
                            }
                        }
                        return false;
                    }
                });
                dialog.text("What is the name of the new tinted drawable?");
                dialog.getContentTable().getCells().first().pad(10.0f);

                Drawable drawable = drawablePairs.get(drawableData);
                Drawable preview = null;
                if (drawable instanceof SpriteDrawable) {
                    preview = ((SpriteDrawable) drawable).tint(color);
                } else if (drawable instanceof NinePatchDrawable) {
                    preview = ((NinePatchDrawable) drawable).tint(color);
                }
                if (preview != null) {
                    dialog.getContentTable().row();
                    Table table = new Table();
                    table.setBackground(preview);
                    dialog.getContentTable().add(table);
                }

                dialog.getContentTable().row();
                dialog.getContentTable().add(textField).growX().pad(10.0f);

                dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
                dialog.button(button, true);
                button.addListener(main.getHandListener());
                dialog.button("Cancel", false);
                dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
                dialog.key(Input.Keys.ESCAPE, false);
                dialog.show(getStage());
                getStage().setKeyboardFocus(textField);
                textField.selectAll();
                textField.setFocusTraversal(false);
            }
        }
    });
}

From source file:com.ray3k.skincomposer.dialog.DialogFactory.java

License:Open Source License

public void showNewStyleDialog(Skin skin, Stage stage) {
    Class selectedClass = main.getRootTable().getSelectedClass();

    final TextField textField = new TextField("", skin);
    Dialog dialog = new Dialog("New Style", skin, "bg") {
        @Override//from   ww w.j  a  v  a2 s .c o m
        protected void result(Object object) {
            if ((Boolean) object) {
                main.getUndoableManager()
                        .addUndoable(new NewStyleUndoable(selectedClass, textField.getText(), main), true);
            }
        }
    };
    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    dialog.button("OK", true).button("Cancel", false);
    dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    final TextButton okButton = (TextButton) dialog.getButtonTable().getCells().get(0).getActor();

    textField.setTextFieldListener((TextField textField1, char c) -> {
        if (c == '\n') {
            if (!okButton.isDisabled()) {
                main.getUndoableManager()
                        .addUndoable(new NewStyleUndoable(selectedClass, textField1.getText(), main), true);
                dialog.hide();
            }
            main.getStage().setKeyboardFocus(textField1);
        }
    });

    textField.addListener(main.getIbeamListener());

    dialog.getTitleLabel().setAlignment(Align.center);
    dialog.getContentTable().defaults().padLeft(10.0f).padRight(10.0f);
    dialog.text("What is the name of the new style?");
    dialog.getContentTable().getCells().first().pad(10.0f);
    dialog.getContentTable().row();
    dialog.getContentTable().add(textField).growX();
    okButton.setDisabled(true);

    Array<StyleData> currentStyles = main.getProjectData().getJsonData().getClassStyleMap().get(selectedClass);
    textField.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            boolean disable = !StyleData.validate(textField.getText());

            if (!disable) {
                for (StyleData data : currentStyles) {
                    if (data.name.equals(textField.getText())) {
                        disable = true;
                        break;
                    }
                }
            }

            okButton.setDisabled(disable);
        }
    });

    dialog.key(Input.Keys.ESCAPE, false);

    dialog.show(stage);
    stage.setKeyboardFocus(textField);
    textField.setFocusTraversal(false);
}

From source file:com.ray3k.skincomposer.dialog.DialogFactory.java

License:Open Source License

public void showDuplicateStyleDialog(Skin skin, Stage stage) {
    Class selectedClass = main.getRootTable().getSelectedClass();
    StyleData originalStyle = main.getRootTable().getSelectedStyle();

    final TextField textField = new TextField("", skin);
    Dialog dialog = new Dialog("Duplicate Style", skin, "bg") {
        @Override/*from w  w w  .j  av a  2s. co m*/
        protected void result(Object object) {
            if ((Boolean) object) {
                main.getUndoableManager().addUndoable(
                        new DuplicateStyleUndoable(originalStyle, textField.getText(), main), true);
            }
        }
    };

    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    dialog.button("OK", true).button("Cancel", false);
    final TextButton okButton = (TextButton) dialog.getButtonTable().getCells().get(0).getActor();
    okButton.addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());

    textField.setTextFieldListener((TextField textField1, char c) -> {
        if (c == '\n') {
            if (!okButton.isDisabled()) {
                main.getUndoableManager().addUndoable(
                        new DuplicateStyleUndoable(originalStyle, textField.getText(), main), true);
                dialog.hide();
            }
            main.getStage().setKeyboardFocus(textField1);
        }
    });

    textField.addListener(main.getIbeamListener());

    dialog.getTitleLabel().setAlignment(Align.center);
    dialog.getContentTable().defaults().padLeft(10.0f).padRight(10.0f);
    dialog.text("What is the name of the new, duplicated style?");
    dialog.getContentTable().getCells().first().pad(10.0f);
    dialog.getContentTable().row();
    dialog.getContentTable().add(textField).growX();
    okButton.setDisabled(true);

    Array<StyleData> currentStyles = main.getProjectData().getJsonData().getClassStyleMap().get(selectedClass);
    textField.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            boolean disable = !StyleData.validate(textField.getText());

            if (!disable) {
                for (StyleData data : currentStyles) {
                    if (data.name.equals(textField.getText())) {
                        disable = true;
                        break;
                    }
                }
            }

            okButton.setDisabled(disable);
        }
    });

    dialog.key(Input.Keys.ESCAPE, false);

    dialog.show(stage);
    stage.setKeyboardFocus(textField);

    textField.setFocusTraversal(false);
}

From source file:com.ray3k.skincomposer.dialog.DialogFactory.java

License:Open Source License

public void showDeleteStyleDialog(Skin skin, Stage stage) {
    StyleData styleData = main.getRootTable().getSelectedStyle();

    Dialog dialog = new Dialog("Delete Style", skin, "bg") {
        @Override/*from   www.  j  av  a2 s.co  m*/
        protected void result(Object object) {
            if ((Boolean) object) {
                main.getUndoableManager().addUndoable(new DeleteStyleUndoable(styleData, main), true);
            }
        }
    };
    dialog.getTitleLabel().setAlignment(Align.center);
    dialog.getContentTable().defaults().padLeft(10.0f).padRight(10.0f);
    dialog.text("Are you sure you want to delete style " + styleData.name + "?");
    dialog.getContentTable().getCells().first().pad(10.0f);

    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    dialog.button("Yes, delete the style", true).button("No", false);
    dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());

    dialog.key(Input.Keys.ENTER, true).key(Input.Keys.ESCAPE, false);

    dialog.show(stage);
}

From source file:com.ray3k.skincomposer.dialog.DialogFactory.java

License:Open Source License

public void showRenameStyleDialog(Skin skin, Stage stage) {
    Class selectedClass = main.getRootTable().getSelectedClass();

    final TextField textField = new TextField(main.getRootTable().getSelectedStyle().name, skin);
    Dialog dialog = new Dialog("Rename Style", skin, "bg") {
        @Override//w  w w .j ava  2s  .c o m
        protected void result(Object object) {
            if ((Boolean) object) {
                main.getUndoableManager().addUndoable(new UndoableManager.RenameStyleUndoable(
                        main.getRootTable().getSelectedStyle(), main, textField.getText()), true);
            }
        }
    };
    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    dialog.button("OK", true).button("Cancel", false);
    dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    final TextButton okButton = (TextButton) dialog.getButtonTable().getCells().get(0).getActor();

    textField.setTextFieldListener((TextField textField1, char c) -> {
        if (c == '\n') {
            if (!okButton.isDisabled()) {
                main.getUndoableManager().addUndoable(new UndoableManager.RenameStyleUndoable(
                        main.getRootTable().getSelectedStyle(), main, textField1.getText()), true);
                dialog.hide();
            }
            main.getStage().setKeyboardFocus(textField1);
        }
    });

    textField.addListener(main.getIbeamListener());

    dialog.getTitleLabel().setAlignment(Align.center);
    dialog.getContentTable().defaults().padLeft(10.0f).padRight(10.0f);
    dialog.text("What would you like to rename the style \"" + main.getRootTable().getSelectedStyle().name
            + "\" to?");
    dialog.getContentTable().getCells().first().pad(10.0f);
    dialog.getContentTable().row();
    dialog.getContentTable().add(textField).growX();
    okButton.setDisabled(true);

    Array<StyleData> currentStyles = main.getProjectData().getJsonData().getClassStyleMap().get(selectedClass);
    textField.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            boolean disable = !StyleData.validate(textField.getText());

            if (!disable) {
                for (StyleData data : currentStyles) {
                    if (data.name.equals(textField.getText())) {
                        disable = true;
                        break;
                    }
                }
            }

            okButton.setDisabled(disable);
        }
    });

    dialog.key(Input.Keys.ESCAPE, false);

    dialog.show(stage);
    stage.setKeyboardFocus(textField);
    textField.selectAll();
    textField.setFocusTraversal(false);
}