Search in sources :

Example 1 with IValidator

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

the class NewBookmarkFolderDialog method build.

public void build() {
    // Info message
    IValidator val = new FolderValidator();
    input = new OwnTextField("", skin, val);
    input.setWidth(480f);
    input.setMessageText("New folder");
    content.add(input).top().left().expand().row();
}
Also used : OwnTextField(gaiasky.util.scene2d.OwnTextField) IValidator(gaiasky.util.validator.IValidator) FolderValidator(gaiasky.util.validator.FolderValidator)

Example 2 with IValidator

use of gaiasky.util.validator.IValidator 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 3 with IValidator

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

the class DatasetPreferencesWindow method build.

@Override
protected void build() {
    // Name
    content.add(new OwnLabel(I18n.txt("gui.dataset.name"), skin, "hud-subheader")).right().padRight(pad10).padBottom(pad10);
    content.add(new OwnLabel(ci.name, skin)).left().padRight(pad10).padBottom(pad10).row();
    // Type
    content.add(new OwnLabel(I18n.txt("gui.dataset.type"), skin, "hud-subheader")).right().padRight(pad10).padBottom(pad10);
    content.add(new OwnLabel(ci.type.toString(), skin)).left().padRight(pad10).padBottom(pad10).row();
    // Added
    content.add(new OwnLabel(I18n.txt("gui.dataset.loaded"), skin, "hud-subheader")).right().padRight(pad10).padBottom(pad10);
    content.add(new OwnLabel(ci.loadDateUTC.atZone(ZoneId.systemDefault()).toString(), skin)).left().padRight(pad10).padBottom(pad10).row();
    // Desc
    content.add(new OwnLabel(I18n.txt("gui.dataset.description"), skin, "hud-subheader")).right().padRight(pad10).padBottom(pad10 * 2f);
    content.add(new OwnLabel(TextUtils.capString(ci.description, 55), skin)).left().padRight(pad10).padBottom(pad10 * 2f).row();
    // Highlight
    content.add(new OwnLabel(I18n.txt("gui.dataset.highlight"), skin, "hud-header")).left().colspan(2).padBottom(pad10).row();
    // Highlight size factor
    IValidator pointSizeValidator = new FloatValidator(Constants.MIN_DATASET_SIZE_FACTOR, Constants.MAX_DATASET_SIZE_FACTOR);
    highlightSizeFactor = new OwnTextField(Float.toString(ci.hlSizeFactor), skin, pointSizeValidator);
    content.add(new OwnLabel(I18n.txt("gui.dataset.highlight.size"), skin)).left().padRight(pad10).padBottom(pad15);
    content.add(highlightSizeFactor).left().padRight(pad10).padBottom(pad10).row();
    // All visible
    allVisible = new OwnCheckBox(I18n.txt("gui.dataset.highlight.allvisible"), skin, pad10);
    allVisible.setChecked(ci.hlAllVisible);
    content.add(allVisible).left().colspan(2).padBottom(pad10 * 2f).row();
    // Fade
    addFadeAttributes(content);
    if (ci.hasParticleAttributes()) {
        // Filters
        content.add(new OwnLabel(I18n.txt("gui.dataset.filter"), skin, "hud-header")).left().colspan(2).padBottom(pad10).padTop(pad15).row();
        filterTable = new Table(skin);
        content.add(filterTable).left().colspan(2).row();
        filter = ci.filter != null ? ci.filter.deepCopy() : null;
        generateFilterTable(filter);
    }
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) IValidator(gaiasky.util.validator.IValidator) FloatValidator(gaiasky.util.validator.FloatValidator)

Example 4 with IValidator

use of gaiasky.util.validator.IValidator 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

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