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