Search in sources :

Example 1 with TextFieldComparatorValidator

use of gaiasky.util.validator.TextFieldComparatorValidator in project gaiasky by langurmonkey.

the class DatasetPreferencesWindow method addFadeAttributes.

private void addFadeAttributes(Table container) {
    float tfw = 220f;
    OwnLabel fadeLabel = new OwnLabel(I18n.txt("gui.dsload.fade"), skin, "hud-header");
    container.add(fadeLabel).colspan(2).left().padTop(pad15).padBottom(pad10).row();
    // Info
    String ssInfoStr = I18n.txt("gui.dsload.fade.info") + '\n';
    int ssLines = GlobalResources.countOccurrences(ssInfoStr, '\n');
    TextArea fadeInfo = new OwnTextArea(ssInfoStr, skin, "info");
    fadeInfo.setDisabled(true);
    fadeInfo.setPrefRows(ssLines + 1);
    fadeInfo.setWidth(taWidth);
    fadeInfo.clearListeners();
    container.add(fadeInfo).colspan(2).left().padTop(pad5).padBottom(pad10).row();
    // Fade in
    fadeIn = new OwnCheckBox(I18n.txt("gui.dsload.fade.in"), skin, pad5);
    Vector2d fi = ci.object != null ? ci.object.getFadeIn() : null;
    container.add(fadeIn).left().padRight(pad10).padBottom(pad5);
    HorizontalGroup fadeInGroup = new HorizontalGroup();
    fadeInGroup.space(pad5);
    fadeInMin = new OwnTextField(fi != null ? String.format("%.14f", fi.x * Constants.U_TO_PC) : "0", skin);
    fadeInMin.setWidth(tfw);
    fadeInMax = new OwnTextField(fi != null ? String.format("%.14f", fi.y * Constants.U_TO_PC) : "1", skin);
    fadeInMax.setWidth(tfw);
    fadeInGroup.addActor(new OwnLabel("[", skin));
    fadeInGroup.addActor(fadeInMin);
    fadeInGroup.addActor(new OwnLabel(", ", skin));
    fadeInGroup.addActor(fadeInMax);
    fadeInGroup.addActor(new OwnLabel("] " + I18n.txt("gui.unit.pc"), skin));
    fadeIn.addListener((event) -> {
        if (event instanceof ChangeEvent) {
            boolean disable = !fadeIn.isChecked();
            for (Actor child : fadeInGroup.getChildren()) {
                if (child instanceof OwnLabel) {
                    ((OwnLabel) child).setDisabled(disable);
                } else if (child instanceof OwnTextField) {
                    ((OwnTextField) child).setDisabled(disable);
                }
            }
            return true;
        }
        return false;
    });
    fadeIn.setChecked(fi == null);
    fadeIn.setProgrammaticChangeEvents(true);
    fadeIn.setChecked(fi != null);
    container.add(fadeInGroup).left().padBottom(pad5).row();
    // Fade out
    fadeOut = new OwnCheckBox(I18n.txt("gui.dsload.fade.out"), skin, pad5);
    Vector2d fo = ci.object != null ? ci.object.getFadeOut() : null;
    container.add(fadeOut).left().padRight(pad10).padBottom(pad5);
    HorizontalGroup fadeOutGroup = new HorizontalGroup();
    fadeOutGroup.space(pad5);
    fadeOutMin = new OwnTextField(fo != null ? String.format("%.10f", fo.x * Constants.U_TO_PC) : "5000", skin);
    fadeOutMin.setWidth(tfw);
    fadeOutMax = new OwnTextField(fo != null ? String.format("%.10f", fo.y * Constants.U_TO_PC) : "10000", skin);
    fadeOutMax.setWidth(tfw);
    fadeOutGroup.addActor(new OwnLabel("[", skin));
    fadeOutGroup.addActor(fadeOutMin);
    fadeOutGroup.addActor(new OwnLabel(", ", skin));
    fadeOutGroup.addActor(fadeOutMax);
    fadeOutGroup.addActor(new OwnLabel("] " + I18n.txt("gui.unit.pc"), skin));
    fadeOut.addListener((event) -> {
        if (event instanceof ChangeEvent) {
            boolean disable = !fadeOut.isChecked();
            for (Actor child : fadeOutGroup.getChildren()) {
                if (child instanceof OwnLabel) {
                    ((OwnLabel) child).setDisabled(disable);
                } else if (child instanceof OwnTextField) {
                    ((OwnTextField) child).setDisabled(disable);
                }
            }
            return true;
        }
        return false;
    });
    fadeOut.setChecked(fo == null);
    fadeOut.setProgrammaticChangeEvents(true);
    fadeOut.setChecked(fo != null);
    // Validators
    FloatValidator fadeVal = new FloatValidator(0f, 1e10f);
    IValidator fadeInMinVal = new TextFieldComparatorValidator(fadeVal, new OwnTextField[] { fadeInMax, fadeOutMin, fadeOutMax }, null);
    IValidator fadeInMaxVal = new TextFieldComparatorValidator(fadeVal, new OwnTextField[] { fadeOutMin, fadeOutMax }, new OwnTextField[] { fadeInMin });
    IValidator fadeOutMinVal = new TextFieldComparatorValidator(fadeVal, new OwnTextField[] { fadeOutMax }, new OwnTextField[] { fadeInMin, fadeInMax });
    IValidator fadeOutMaxVal = new TextFieldComparatorValidator(fadeVal, null, new OwnTextField[] { fadeInMin, fadeInMax, fadeOutMin });
    // Set them
    fadeInMin.setValidator(fadeInMinVal);
    fadeInMax.setValidator(fadeInMaxVal);
    fadeOutMin.setValidator(fadeOutMinVal);
    fadeOutMax.setValidator(fadeOutMaxVal);
    container.add(fadeOutGroup).left().padBottom(pad5).row();
}
Also used : TextFieldComparatorValidator(gaiasky.util.validator.TextFieldComparatorValidator) TextArea(com.badlogic.gdx.scenes.scene2d.ui.TextArea) Vector2d(gaiasky.util.math.Vector2d) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) IValidator(gaiasky.util.validator.IValidator) Actor(com.badlogic.gdx.scenes.scene2d.Actor) HorizontalGroup(com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup) FloatValidator(gaiasky.util.validator.FloatValidator)

Example 2 with TextFieldComparatorValidator

use of gaiasky.util.validator.TextFieldComparatorValidator in project gaiasky by langurmonkey.

the class DatasetLoadDialog method addFadeAttributes.

private void addFadeAttributes(Table container) {
    OwnLabel fadeLabel = new OwnLabel(I18n.txt("gui.dsload.fade"), skin, "hud-subheader");
    container.add(fadeLabel).colspan(2).left().padTop(pad15).padBottom(pad10).row();
    // Info
    String ssInfoStr = I18n.txt("gui.dsload.fade.info") + '\n';
    int ssLines = GlobalResources.countOccurrences(ssInfoStr, '\n');
    TextArea fadeInfo = new OwnTextArea(ssInfoStr, skin, "info");
    fadeInfo.setDisabled(true);
    fadeInfo.setPrefRows(ssLines + 1);
    fadeInfo.setWidth(taWidth);
    fadeInfo.clearListeners();
    container.add(fadeInfo).colspan(2).left().padTop(pad5).padBottom(pad10).row();
    // Fade in
    fadeIn = new OwnCheckBox(I18n.txt("gui.dsload.fade.in"), skin, pad5);
    container.add(fadeIn).left().padRight(pad10).padBottom(pad5);
    HorizontalGroup fadeInGroup = new HorizontalGroup();
    fadeInGroup.space(pad5);
    fadeInMin = new OwnTextField("0", skin);
    fadeInMax = new OwnTextField("10", skin);
    fadeInGroup.addActor(new OwnLabel("[", skin));
    fadeInGroup.addActor(fadeInMin);
    fadeInGroup.addActor(new OwnLabel(", ", skin));
    fadeInGroup.addActor(fadeInMax);
    fadeInGroup.addActor(new OwnLabel("] pc", skin));
    fadeIn.addListener((event) -> {
        if (event instanceof ChangeEvent) {
            boolean disable = !fadeIn.isChecked();
            for (Actor child : fadeInGroup.getChildren()) {
                if (child instanceof OwnLabel) {
                    ((OwnLabel) child).setDisabled(disable);
                } else if (child instanceof OwnTextField) {
                    ((OwnTextField) child).setDisabled(disable);
                }
            }
            return true;
        }
        return false;
    });
    fadeIn.setChecked(true);
    fadeIn.setProgrammaticChangeEvents(true);
    fadeIn.setChecked(false);
    container.add(fadeInGroup).left().padBottom(pad5).row();
    // Fade out
    fadeOut = new OwnCheckBox(I18n.txt("gui.dsload.fade.out"), skin, pad5);
    container.add(fadeOut).left().padRight(pad10).padBottom(pad5);
    HorizontalGroup fadeOutGroup = new HorizontalGroup();
    fadeOutGroup.space(pad5);
    fadeOutMin = new OwnTextField("3000", skin);
    fadeOutMax = new OwnTextField("6000", skin);
    fadeOutGroup.addActor(new OwnLabel("[", skin));
    fadeOutGroup.addActor(fadeOutMin);
    fadeOutGroup.addActor(new OwnLabel(", ", skin));
    fadeOutGroup.addActor(fadeOutMax);
    fadeOutGroup.addActor(new OwnLabel("] pc", skin));
    fadeOut.addListener((event) -> {
        if (event instanceof ChangeEvent) {
            boolean disable = !fadeOut.isChecked();
            for (Actor child : fadeOutGroup.getChildren()) {
                if (child instanceof OwnLabel) {
                    ((OwnLabel) child).setDisabled(disable);
                } else if (child instanceof OwnTextField) {
                    ((OwnTextField) child).setDisabled(disable);
                }
            }
            return true;
        }
        return false;
    });
    fadeOut.setChecked(true);
    fadeOut.setProgrammaticChangeEvents(true);
    fadeOut.setChecked(false);
    // Validators
    FloatValidator fadeVal = new FloatValidator(0f, 1e10f);
    IValidator fadeInMinVal = new TextFieldComparatorValidator(fadeVal, new OwnTextField[] { fadeInMax, fadeOutMin, fadeOutMax }, null);
    IValidator fadeInMaxVal = new TextFieldComparatorValidator(fadeVal, new OwnTextField[] { fadeOutMin, fadeOutMax }, new OwnTextField[] { fadeInMin });
    IValidator fadeOutMinVal = new TextFieldComparatorValidator(fadeVal, new OwnTextField[] { fadeOutMax }, new OwnTextField[] { fadeInMin, fadeInMax });
    IValidator fadeOutMaxVal = new TextFieldComparatorValidator(fadeVal, null, new OwnTextField[] { fadeInMin, fadeInMax, fadeOutMin });
    // Set them
    fadeInMin.setValidator(fadeInMinVal);
    fadeInMax.setValidator(fadeInMaxVal);
    fadeOutMin.setValidator(fadeOutMinVal);
    fadeOutMax.setValidator(fadeOutMaxVal);
    container.add(fadeOutGroup).left().padBottom(pad5).row();
}
Also used : TextFieldComparatorValidator(gaiasky.util.validator.TextFieldComparatorValidator) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) IValidator(gaiasky.util.validator.IValidator) Actor(com.badlogic.gdx.scenes.scene2d.Actor) FloatValidator(gaiasky.util.validator.FloatValidator)

Aggregations

Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)2 FloatValidator (gaiasky.util.validator.FloatValidator)2 IValidator (gaiasky.util.validator.IValidator)2 TextFieldComparatorValidator (gaiasky.util.validator.TextFieldComparatorValidator)2 HorizontalGroup (com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup)1 TextArea (com.badlogic.gdx.scenes.scene2d.ui.TextArea)1 Vector2d (gaiasky.util.math.Vector2d)1