Search in sources :

Example 6 with FloatValidator

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

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

the class OwnTextField method addValidatorTooltip.

private void addValidatorTooltip(IValidator validator) {
    if (validator != null) {
        if (validator instanceof FloatValidator) {
            FloatValidator fv = (FloatValidator) validator;
            addListener(new OwnTextTooltip(I18n.txt("gui.validator.values", fv.getMin(), fv.getMax()), skin));
        } else if (validator instanceof IntValidator) {
            IntValidator iv = (IntValidator) validator;
            addListener(new OwnTextTooltip(I18n.txt("gui.validator.values", iv.getMin(), iv.getMax()), skin));
        }
        if (validator instanceof CallbackValidator) {
            CallbackValidator cv = (CallbackValidator) validator;
            addValidatorTooltip(cv.getParent());
        }
    }
}
Also used : IntValidator(gaiasky.util.validator.IntValidator) FloatValidator(gaiasky.util.validator.FloatValidator) CallbackValidator(gaiasky.util.validator.CallbackValidator)

Example 8 with FloatValidator

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

Example 9 with FloatValidator

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

the class DatasetLoadDialog method addStarsWidget.

private void addStarsWidget(Table container) {
    OwnLabel starProps = new OwnLabel(I18n.txt("gui.dsload.stars.properties"), skin, "hud-subheader");
    container.add(starProps).colspan(2).left().padTop(pad15).padBottom(pad10).row();
    // Name
    addFileName(container);
    // Label color
    addLabelColor(container);
    // Magnitude multiplier
    FloatValidator sclValidator = new FloatValidator(-100f, 100f);
    magnitudeScale = new OwnTextField("0.0", skin, sclValidator);
    magnitudeScale.setWidth(fieldWidth);
    container.add(new OwnLabel(I18n.txt("gui.dsload.magnitude.scale"), skin, titleWidth)).left().padRight(pad10).padBottom(pad10);
    container.add(GuiUtils.tooltipHg(magnitudeScale, "gui.dsload.magnitude.scale.tooltip", skin)).left().padBottom(pad10).row();
    // Fade
    addFadeAttributes(container);
    // Default fade out for stars
    fadeOut.setChecked(true);
    fadeOutMin.setText("10000");
    fadeOutMax.setText("80000");
}
Also used : FloatValidator(gaiasky.util.validator.FloatValidator)

Example 10 with FloatValidator

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

the class DatasetPreferencesWindow method generateFilterTable.

private void generateFilterTable(Filter filter) {
    float minSelectWidth = 160f;
    filterTable.clearChildren();
    if (filter != null && filter.hasRules()) {
        // Operation
        OwnSelectBox<String> operation = new OwnSelectBox<>(skin);
        operation.setWidth(minSelectWidth);
        operation.setItems("and", "or", "xor");
        operation.setSelected(filter.getOperationString().toLowerCase());
        operation.addListener(event -> {
            if (event instanceof ChangeEvent) {
                String newOp = operation.getSelected();
                filter.setOperation(newOp);
                filterEdited = true;
                return true;
            }
            return false;
        });
        filterTable.add(new OwnLabel(I18n.txt("gui.dataset.filter.operation"), skin)).left().padRight(pad10 * 2f).padBottom(pad10);
        filterTable.add(operation).left().expandX().padBottom(pad10).row();
        // Rules
        Array<FilterRule> rules = filter.getRules();
        Table rulesTable = new Table(skin);
        filterTable.add(rulesTable).colspan(2);
        for (FilterRule rule : rules) {
            // UNIT
            OwnLabel unit = new OwnLabel(rule.getAttribute().getUnit(), skin);
            // ATTRIBUTE
            boolean stars = ci.object instanceof StarGroup || ci.object instanceof OctreeWrapper;
            Array<AttributeComboBoxBean> attrs = new Array<>(false, stars ? 12 : 7);
            // Add particle attributes (dist, alpha, delta)
            attrs.add(new AttributeComboBoxBean(new AttributeDistance()));
            attrs.add(new AttributeComboBoxBean(new AttributeRA()));
            attrs.add(new AttributeComboBoxBean(new AttributeDEC()));
            attrs.add(new AttributeComboBoxBean(new AttributeEclLatitude()));
            attrs.add(new AttributeComboBoxBean(new AttributeEclLongitude()));
            attrs.add(new AttributeComboBoxBean(new AttributeGalLatitude()));
            attrs.add(new AttributeComboBoxBean(new AttributeGalLongitude()));
            if (stars) {
                // Star-only attributes (appmag, absmag, mualpha, mudelta, radvel)
                attrs.add(new AttributeComboBoxBean(new AttributeAppmag()));
                attrs.add(new AttributeComboBoxBean(new AttributeAbsmag()));
                attrs.add(new AttributeComboBoxBean(new AttributeMualpha()));
                attrs.add(new AttributeComboBoxBean(new AttributeMudelta()));
                attrs.add(new AttributeComboBoxBean(new AttributeRadvel()));
            }
            // Colors
            attrs.add(new AttributeComboBoxBean(new AttributeColorRed()));
            attrs.add(new AttributeComboBoxBean(new AttributeColorGreen()));
            attrs.add(new AttributeComboBoxBean(new AttributeColorBlue()));
            // Extra attributes
            if (ci.object instanceof ParticleGroup) {
                ParticleGroup pg = (ParticleGroup) ci.object;
                if (pg.size() > 0) {
                    IParticleRecord first = pg.get(0);
                    if (first.hasExtra()) {
                        ObjectDoubleMap.Keys<UCD> ucds = first.extraKeys();
                        for (UCD ucd : ucds) attrs.add(new AttributeComboBoxBean(new AttributeUCD(ucd)));
                    }
                }
            }
            OwnSelectBox<AttributeComboBoxBean> attribute = new OwnSelectBox<>(skin);
            attribute.setItems(attrs);
            attribute.setSelected(getAttributeBean(rule.getAttribute(), attrs));
            attribute.addListener(event -> {
                if (event instanceof ChangeEvent) {
                    IAttribute newAttr = attribute.getSelected().attr;
                    rule.setAttribute(newAttr);
                    // Update unit
                    unit.setText(newAttr.getUnit());
                    filterEdited = true;
                    return true;
                }
                return false;
            });
            rulesTable.add(attribute).left().padRight(pad10).padBottom(pad5);
            // COMPARATOR
            String[] cmps = new String[] { "<", "<=", ">", ">=", "==", "!=" };
            OwnSelectBox<String> comparator = new OwnSelectBox<>(skin);
            comparator.setWidth(minSelectWidth);
            comparator.setItems(cmps);
            comparator.setSelected(rule.getComparator().toString());
            comparator.addListener(event -> {
                if (event instanceof ChangeEvent) {
                    IComparator newComp = rule.getComparatorFromString(comparator.getSelected());
                    rule.setComparator(newComp);
                    filterEdited = true;
                    return true;
                }
                return false;
            });
            rulesTable.add(comparator).left().padRight(pad10).padBottom(pad5);
            // VALUE
            FloatValidator fval = new FloatValidator(-Float.MAX_VALUE, Float.MAX_VALUE);
            OwnTextField value = new OwnTextField(Double.toString(rule.getValue()), skin, fval);
            value.addListener(event -> {
                if (event instanceof ChangeEvent) {
                    if (value.isValid()) {
                        try {
                            rule.setValue(Float.parseFloat(value.getText()));
                            filterEdited = true;
                            return true;
                        } catch (Exception e) {
                            logger.error(e);
                            return false;
                        }
                    }
                    return false;
                }
                return false;
            });
            rulesTable.add(value).left().padRight(pad10).padBottom(pad5);
            // UNIT
            rulesTable.add(unit).left().padRight(pad10 * 3f).padBottom(pad5);
            // RUBBISH
            OwnTextIconButton rubbish = new OwnTextIconButton("", skin, "rubbish");
            rubbish.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.dataset.filter.rule.remove"), skin));
            rubbish.addListener(event -> {
                if (event instanceof ChangeEvent) {
                    deleteRule(filter, rule);
                    filterEdited = true;
                    return true;
                }
                return false;
            });
            rulesTable.add(rubbish).left().padBottom(pad5).row();
        }
        // New rule button
        OwnTextIconButton addRule = new OwnTextIconButton(I18n.txt("gui.dataset.filter.rule.add"), skin, "add");
        addRule.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.dataset.filter.rule.add"), skin));
        addRule.pad(pad10);
        rulesTable.add(addRule).left().padTop(pad10).row();
        addRule.addListener(event -> {
            if (event instanceof ChangeEvent) {
                dpw.addRule(filter);
                filterEdited = true;
                return true;
            }
            return false;
        });
    } else {
        // Add
        filterTable.add(new OwnLabel(I18n.txt("gui.dataset.filter.nofilters"), skin)).left().padBottom(pad10).row();
        OwnTextIconButton addFilter = new OwnTextIconButton(I18n.txt("gui.dataset.filter.add"), skin, "add");
        addFilter.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.dataset.filter.add"), skin));
        addFilter.pad(pad10);
        filterTable.add(addFilter).left().padBottom(pad5).row();
        addFilter.addListener(event -> {
            if (event instanceof ChangeEvent) {
                dpw.addFilter();
                filterEdited = true;
                return true;
            }
            return false;
        });
    }
    pack();
}
Also used : FilterRule(gaiasky.util.filter.FilterRule) IComparator(gaiasky.util.filter.FilterRule.IComparator) AttributeComboBoxBean(gaiasky.interafce.beans.AttributeComboBoxBean) FloatValidator(gaiasky.util.validator.FloatValidator) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ParticleGroup(gaiasky.scenegraph.ParticleGroup) Array(com.badlogic.gdx.utils.Array) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) StarGroup(gaiasky.scenegraph.StarGroup) UCD(gaiasky.util.ucd.UCD) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord) OctreeWrapper(gaiasky.scenegraph.octreewrapper.OctreeWrapper)

Aggregations

FloatValidator (gaiasky.util.validator.FloatValidator)12 ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)8 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)3 OwnLabel (gaiasky.util.scene2d.OwnLabel)3 OwnTextField (gaiasky.util.scene2d.OwnTextField)3 IValidator (gaiasky.util.validator.IValidator)3 Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 HorizontalGroup (com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup)2 OwnCheckBox (gaiasky.util.scene2d.OwnCheckBox)2 TextFieldComparatorValidator (gaiasky.util.validator.TextFieldComparatorValidator)2 EventListener (com.badlogic.gdx.scenes.scene2d.EventListener)1 ButtonGroup (com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup)1 TextArea (com.badlogic.gdx.scenes.scene2d.ui.TextArea)1 Array (com.badlogic.gdx.utils.Array)1 Keyframe (gaiasky.desktop.util.camera.Keyframe)1 AttributeComboBoxBean (gaiasky.interafce.beans.AttributeComboBoxBean)1 ComponentType (gaiasky.render.ComponentTypes.ComponentType)1 ParticleGroup (gaiasky.scenegraph.ParticleGroup)1 StarGroup (gaiasky.scenegraph.StarGroup)1 OctreeWrapper (gaiasky.scenegraph.octreewrapper.OctreeWrapper)1