Search in sources :

Example 1 with AttributeComboBoxBean

use of gaiasky.interafce.beans.AttributeComboBoxBean 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

Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)1 Array (com.badlogic.gdx.utils.Array)1 AttributeComboBoxBean (gaiasky.interafce.beans.AttributeComboBoxBean)1 ParticleGroup (gaiasky.scenegraph.ParticleGroup)1 StarGroup (gaiasky.scenegraph.StarGroup)1 OctreeWrapper (gaiasky.scenegraph.octreewrapper.OctreeWrapper)1 IParticleRecord (gaiasky.scenegraph.particle.IParticleRecord)1 FilterRule (gaiasky.util.filter.FilterRule)1 IComparator (gaiasky.util.filter.FilterRule.IComparator)1 UCD (gaiasky.util.ucd.UCD)1 FloatValidator (gaiasky.util.validator.FloatValidator)1