use of com.ray3k.skincomposer.UndoableManager.NewStyleUndoable in project skin-composer by raeleus.
the class DialogFactory method showNewStyleDialog.
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
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);
}
Aggregations