Search in sources :

Example 1 with FloatValidator

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

the class KeyframesWindow method build.

@Override
protected void build() {
    /*
         * Right and left tables
         */
    Table left = new Table(skin);
    left.align(Align.top | Align.left);
    Table right = new Table(skin);
    right.align(Align.top | Align.left);
    /* LEFT - CONTROLS */
    // ADD
    OwnTextIconButton addKeyframe = new OwnTextIconButton(I18n.txt("gui.keyframes.add.end"), skin, "add");
    addKeyframe.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.kf.add.end"), skin));
    addKeyframe.pad(pad5);
    left.add(addKeyframe).left().colspan(2).padBottom(pad5).row();
    addKeyframe.addListener(event -> {
        if (event instanceof ChangeEvent) {
            // Add at end
            return addKeyframe(-1);
        }
        return false;
    });
    // SECONDS
    FloatValidator secondsValidator = new FloatValidator(0.0001f, 9999.0f);
    secondsValidator.setIsValidCallback(() -> {
        // Enable add button
        addKeyframe.setDisabled(false);
    });
    secondsValidator.setIsInvalidCallback(() -> {
        // Disable add button
        addKeyframe.setDisabled(true);
    });
    secondsInput = new OwnTextField("1.0", skin, secondsValidator);
    secondsInput.setWidth(96f);
    OwnLabel secondsLabel = new OwnLabel(I18n.txt("gui.keyframes.secsafter") + ":", skin);
    left.add(secondsLabel).center().left().padRight(pad10).padBottom(pad10);
    left.add(secondsInput).center().left().padBottom(pad10).row();
    // NAME
    LengthValidator lengthValidator = new LengthValidator(0, 15);
    RegexpValidator nameValidator = new RegexpValidator(lengthValidator, "^[^*&%\\s\\+\\=\\\\\\/@#\\$&\\*()~]*$");
    nameInput = new OwnTextField("", skin, nameValidator);
    nameInput.setWidth(96f);
    OwnLabel nameLabel = new OwnLabel(I18n.txt("gui.keyframes.name") + ":", skin);
    left.add(nameLabel).center().left().padRight(pad10).padBottom(pad10);
    left.add(nameInput).center().left().padBottom(pad10).row();
    left.pack();
    /* RIGHT - KEYFRAMES */
    OwnLabel keyframesTitle = new OwnLabel(I18n.txt("gui.keyframes.list"), skin, "hud-header");
    // KEYFRAMES TABLE
    keyframesTable = buildKeyframesTable();
    // ADD SCROLL
    rightScroll = new OwnScrollPane(keyframesTable, skin, "minimalist-nobg");
    rightScroll.setExpand(true);
    rightScroll.setScrollingDisabled(true, false);
    rightScroll.setHeight(160f);
    rightScroll.setWidth(540f);
    rightScroll.setFadeScrollBars(true);
    right.add(keyframesTitle).top().left().padBottom(pad10).row();
    right.add(rightScroll).center().left();
    right.pack();
    /* RE-NORMALIZE TIME */
    OwnTextButton normalizeTime = new OwnTextButton(I18n.txt("gui.keyframes.normalize"), skin);
    normalizeTime.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.kf.normalize"), skin));
    normalizeTime.pad(pad10);
    normalizeTime.addListener((event) -> {
        if (event instanceof ChangeEvent) {
            if (keyframes != null && keyframes.size > 2) {
                Vector3d aux = new Vector3d();
                int n = keyframes.size;
                double totalTime = 0;
                double totalDist = 0;
                for (int i = 1; i < n; i++) {
                    Keyframe kf0 = keyframes.get(i - 1);
                    Keyframe kf1 = keyframes.get(i);
                    totalTime += kf1.seconds;
                    totalDist += aux.set(kf1.pos).sub(kf0.pos).len();
                }
                // Loop over keyframes and assign new times
                for (int i = 1; i < n; i++) {
                    Keyframe kf0 = keyframes.get(i - 1);
                    Keyframe kf1 = keyframes.get(i);
                    double dist = aux.set(kf1.pos).sub(kf0.pos).len();
                    kf1.seconds = totalTime * dist / totalDist;
                }
                // Reload window contents
                reinitialiseKeyframes(keyframes, null);
                keyframesPathObject.unselect();
                logger.info(I18n.txt("gui.keyframes.normalize.done"));
            }
            return true;
        }
        return false;
    });
    /* ACTION BUTTONS */
    HorizontalGroup buttons = new HorizontalGroup();
    buttons.space(pad10);
    // Open keyframes
    OwnTextIconButton open = new OwnTextIconButton(I18n.txt("gui.keyframes.load"), skin, "open");
    open.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.kf.load"), skin));
    open.pad(pad5);
    open.addListener((event) -> {
        if (event instanceof ChangeEvent) {
            FileChooser fc = new FileChooser(I18n.txt("gui.download.pickloc"), skin, stage, SysUtils.getDefaultCameraDir(), FileChooser.FileChooserTarget.FILES);
            fc.setShowHidden(Settings.settings.program.fileChooser.showHidden);
            fc.setShowHiddenConsumer((showHidden) -> Settings.settings.program.fileChooser.showHidden = showHidden);
            fc.setFileFilter(pathname -> pathname.getFileName().toString().endsWith(".gkf"));
            fc.setAcceptedFiles("*.gkf");
            fc.setResultListener((success, result) -> {
                if (success) {
                    if (Files.exists(result) && Files.isRegularFile(result)) {
                        // Load selected file
                        try {
                            Array<Keyframe> kfs = CameraKeyframeManager.instance.loadKeyframesFile(result);
                            // Update current instance
                            reinitialiseKeyframes(kfs, null);
                            keyframesPathObject.unselect();
                            lastKeyframeFileName = result.getFileName().toString();
                            logger.info(I18n.txt("gui.keyframes.load.success", keyframes.size, result.getFileName()));
                        } catch (RuntimeException e) {
                            logger.error(I18n.txt("gui.keyframes.load.error", result.getFileName()), e);
                            Label warn = new OwnLabel(I18n.txt("error.loading.format", result.getFileName()), skin);
                            warn.setColor(1f, .4f, .4f, 1f);
                            notice.setActor(warn);
                            return false;
                        }
                    } else {
                        logger.error(I18n.txt("error.loading.notexistent", result.getFileName()));
                        Label warn = new OwnLabel(I18n.txt("error.loading.notexistent", result.getFileName()), skin);
                        warn.setColor(1f, .4f, .4f, 1f);
                        notice.setActor(warn);
                        return false;
                    }
                }
                notice.clearActor();
                return true;
            });
            fc.show(stage);
            return true;
        }
        return false;
    });
    // Save keyframes
    OwnTextIconButton save = new OwnTextIconButton(I18n.txt("gui.keyframes.save"), skin, "save");
    save.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.kf.save"), skin));
    save.pad(pad5);
    save.addListener((event) -> {
        if (event instanceof ChangeEvent) {
            String suggestedName = lastKeyframeFileName == null ? df.format(new Date()) + "_keyframes.gkf" : lastKeyframeFileName;
            FileNameWindow fnw = new FileNameWindow(suggestedName, stage, skin);
            OwnTextField textField = fnw.getFileNameField();
            fnw.setAcceptRunnable(() -> {
                if (textField.isValid()) {
                    EventManager.publish(Event.KEYFRAMES_FILE_SAVE, fnw, keyframes, textField.getText());
                    lastKeyframeFileName = textField.getText();
                    notice.clearActor();
                } else {
                    Label warn = new OwnLabel(I18n.txt("error.file.name.notvalid", textField.getText()), skin);
                    warn.setColor(1f, .4f, .4f, 1f);
                    notice.setActor(warn);
                }
            });
            fnw.show(stage);
            return true;
        }
        return false;
    });
    // Export to camera path
    OwnTextIconButton export = new OwnTextIconButton(I18n.txt("gui.keyframes.export"), skin, "export");
    export.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.kf.export"), skin));
    export.pad(pad5);
    export.addListener((event) -> {
        if (event instanceof ChangeEvent) {
            String suggestedName = df.format(new Date()) + ".gsc";
            FileNameWindow fnw = new FileNameWindow(suggestedName, stage, skin);
            OwnTextField textField = fnw.getFileNameField();
            fnw.setAcceptRunnable(() -> {
                if (textField.isValid()) {
                    EventManager.publish(Event.KEYFRAMES_EXPORT, fnw, keyframes, textField.getText());
                    notice.clearActor();
                } else {
                    Label warn = new OwnLabel(I18n.txt("error.file.name.notvalid", textField.getText()), skin);
                    warn.setColor(1f, .4f, .4f, 1f);
                    notice.setActor(warn);
                }
            });
            fnw.show(stage);
            return true;
        }
        return false;
    });
    // Keyframe preferences
    Button preferences = new OwnTextIconButton(I18n.txt("gui.preferences"), skin, "preferences");
    preferences.setName("keyframe preferences");
    preferences.pad(pad5);
    preferences.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.kf.editprefs"), skin));
    preferences.addListener((event) -> {
        if (event instanceof ChangeEvent) {
            KeyframePreferencesWindow kpw = new KeyframePreferencesWindow(stage, skin);
            kpw.setAcceptRunnable(() -> {
                // Resample
                GaiaSky.postRunnable(() -> {
                    keyframesPathObject.resamplePath();
                });
            });
            kpw.setCancelRunnable(() -> {
            });
            kpw.show(stage, me.getWidth(), 0);
            return true;
        }
        return false;
    });
    buttons.addActor(open);
    buttons.addActor(save);
    buttons.addActor(export);
    buttons.addActor(preferences);
    /* FINAL LAYOUT */
    content.add(left).top().left().padRight(pad10 * 2f).padBottom(pad10 * 3f);
    content.add(right).width(592f).top().left().padBottom(pad10).row();
    notice = content.add();
    notice.padBottom(pad10 * 2f).expandY().center().colspan(2).row();
    content.add(normalizeTime).colspan(2).bottom().center().padBottom(pad10).row();
    content.add(buttons).colspan(2).bottom().right().row();
    // CLEAR
    OwnTextButton clear = new OwnTextButton(I18n.txt("gui.clear"), skin);
    clear.setName("clear");
    clear.addListener((event) -> {
        if (event instanceof ChangeEvent) {
            GaiaSky.postRunnable(this::clean);
            return true;
        }
        return false;
    });
    buttonGroup.addActorAt(0, clear);
    // HIDE
    OwnTextButton hide = new OwnTextButton(I18n.txt("gui.hide"), skin);
    hide.setName("hide");
    hide.addListener((event) -> {
        if (event instanceof ChangeEvent) {
            hide();
            return true;
        }
        return false;
    });
    buttonGroup.addActorAt(1, hide);
    recalculateButtonSize();
}
Also used : LengthValidator(gaiasky.util.validator.LengthValidator) Keyframe(gaiasky.desktop.util.camera.Keyframe) FloatValidator(gaiasky.util.validator.FloatValidator) RegexpValidator(gaiasky.util.validator.RegexpValidator) Date(java.util.Date) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) Vector3d(gaiasky.util.math.Vector3d)

Example 2 with FloatValidator

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

the class SlaveConfigWindow method build.

@Override
protected void build() {
    FloatValidator angleVal = new FloatValidator(-1000f, 1000f);
    FloatValidator fovVal = new FloatValidator(Constants.MIN_FOV, 170f);
    float tw = 96f;
    // Send button (does not close dialog)
    OwnTextButton sendButton = new OwnTextButton(I18n.txt("gui.send"), skin, "default");
    sendButton.setName("send");
    sendButton.addListener((event) -> {
        if (event instanceof ChangeEvent) {
            accept();
            return true;
        }
        return false;
    });
    buttonGroup.addActor(sendButton);
    recalculateButtonSize();
    // Get slaves
    List<String> slaves = MasterManager.instance.getSlaves();
    // Status
    slaveStatuses = new OwnLabel[slaves.size()];
    OwnLabel statusLabel = new OwnLabel(I18n.txt("gui.slave.config.status") + ":", skin);
    Table statusTable = new Table(skin);
    for (int i = 0; i < slaves.size(); i++) {
        OwnLabel slaveMarker = new OwnLabel("[" + (i + 1) + "]", skin);
        if (MasterManager.instance.isSlaveConnected(slaves.get(i))) {
            slaveMarker.setColor(Color.GREEN);
        } else {
            slaveMarker.setColor(Color.RED);
        }
        slaveStatuses[i] = slaveMarker;
        statusTable.add(slaveMarker).left().padRight(pad10);
    }
    content.add(statusLabel).center().left().padRight(pad10).padBottom(pad10 * 2f);
    content.add(statusTable).center().left().padBottom(pad10 * 2f).row();
    // Instance
    Array<String> slaveList = getSlaveBeans();
    slaveSelect = new OwnSelectBox<>(skin);
    slaveSelect.setWidth(tw * 4f);
    slaveSelect.setItems(slaveList);
    slaveSelect.addListener((event) -> {
        if (event instanceof ChangeEvent) {
            String newSlave = slaveSelect.getSelected();
            pullParameters(newSlave);
            updateSlaveStatusText(newSlave);
            return true;
        }
        return false;
    });
    OwnLabel slaveLabel = new OwnLabel(I18n.txt("gui.slave.config.instance") + ":", skin);
    content.add(slaveLabel).center().left().padRight(pad10).padBottom(pad10);
    content.add(slaveSelect).center().left().padBottom(pad10).row();
    // Slave status label
    slaveStatusLabel = new OwnLabel("", skin);
    content.add(slaveStatusLabel).colspan(2).center().padBottom(pad10 * 2f).row();
    if (slaves.size() > 0)
        updateSlaveStatusText(slaves.get(0));
    // Yaw
    yaw = new OwnTextField("", skin, angleVal);
    yaw.setWidth(tw);
    OwnLabel yawLabel = new OwnLabel(I18n.txt("gui.slave.config.yaw") + ":", skin);
    content.add(yawLabel).center().left().padRight(pad10).padBottom(pad10);
    content.add(yaw).center().left().padBottom(pad10).row();
    // Pitch
    pitch = new OwnTextField("", skin, angleVal);
    pitch.setWidth(tw);
    OwnLabel pitchLabel = new OwnLabel(I18n.txt("gui.slave.config.pitch") + ":", skin);
    content.add(pitchLabel).center().left().padRight(pad10).padBottom(pad10);
    content.add(pitch).center().left().padBottom(pad10).row();
    // Roll
    roll = new OwnTextField("", skin, angleVal);
    roll.setWidth(tw);
    OwnLabel rollLabel = new OwnLabel(I18n.txt("gui.slave.config.roll") + ":", skin);
    content.add(rollLabel).center().left().padRight(pad10).padBottom(pad10);
    content.add(roll).center().left().padBottom(pad10).row();
    // FOV
    fov = new OwnTextField("", skin, fovVal);
    fov.setWidth(tw);
    OwnLabel fovLabel = new OwnLabel(I18n.txt("gui.slave.config.fov") + ":", skin);
    content.add(fovLabel).center().left().padRight(pad10).padBottom(pad10);
    content.add(fov).center().left().padBottom(pad10).row();
    if (slaveSelect.getSelected() != null)
        pullParameters(slaveSelect.getSelected());
}
Also used : OwnTextButton(gaiasky.util.scene2d.OwnTextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) OwnTextField(gaiasky.util.scene2d.OwnTextField) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) OwnLabel(gaiasky.util.scene2d.OwnLabel) FloatValidator(gaiasky.util.validator.FloatValidator)

Example 3 with FloatValidator

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

the class DatasetLoadDialog method addParticlesWidget.

private void addParticlesWidget(Table container) {
    OwnLabel particleProps = new OwnLabel(I18n.txt("gui.dsload.particles.properties"), skin, "hud-subheader");
    container.add(particleProps).colspan(2).left().padTop(pad15).padBottom(pad10).row();
    // Name
    addFileName(container);
    // Particle color
    addParticleColor(container);
    // Color noise
    colorNoise = new OwnSliderPlus(I18n.txt("gui.dsload.color.noise"), Constants.MIN_COLOR_NOISE, Constants.MAX_COLOR_NOISE, Constants.SLIDER_STEP_TINY, false, skin);
    colorNoise.setName("profile decay");
    colorNoise.setWidth(sliderWidth);
    colorNoise.setValue(0.2f);
    colorNoise.addListener(event -> {
        if (event instanceof ChangeEvent) {
            updateFrameBuffer();
            return true;
        }
        return false;
    });
    container.add(GuiUtils.tooltipHg(colorNoise, "gui.dsload.color.noise.tooltip", skin)).colspan(2).left().padBottom(pad15).row();
    // Label color
    addLabelColor(container);
    // Particle size
    particleSize = new OwnSliderPlus(I18n.txt("gui.dsload.size"), Constants.MIN_PARTICLE_SIZE, Constants.MAX_PARTICLE_SIZE, Constants.SLIDER_STEP_SMALL, false, skin);
    particleSize.setName("profile decay");
    particleSize.setWidth(sliderWidth);
    particleSize.setValue(10f);
    particleSize.addListener(event -> {
        if (event instanceof ChangeEvent) {
            updateFrameBuffer();
            return true;
        }
        return false;
    });
    container.add(particleSize).colspan(2).left().padBottom(pad10).row();
    // Profile falloff
    FloatValidator falloffVal = new FloatValidator(0.3f, 200f);
    profileDecay = new OwnTextField("5.0", skin, falloffVal);
    profileDecay.setWidth(fieldWidth);
    container.add(new OwnLabel(I18n.txt("gui.dsload.profiledecay"), skin, titleWidth)).left().padRight(pad10).padBottom(pad15);
    container.add(GuiUtils.tooltipHg(profileDecay, "gui.dsload.profiledecay.tooltip", skin)).left().padBottom(pad15).row();
    // Component type
    ComponentType[] componentTypes = new ComponentType[] { ComponentType.Others, ComponentType.Stars, ComponentType.Galaxies, ComponentType.Clusters, ComponentType.Asteroids, ComponentType.Locations };
    componentType = new OwnSelectBox<>(skin);
    componentType.setWidth(fieldWidth);
    componentType.setItems(componentTypes);
    componentType.setSelected(ComponentType.Galaxies);
    container.add(new OwnLabel(I18n.txt("gui.dsload.ct"), skin, titleWidth)).left().padRight(pad10).padBottom(pad5);
    container.add(componentType).left().padBottom(pad5).row();
    // Fade
    addFadeAttributes(container);
}
Also used : ComponentType(gaiasky.render.ComponentTypes.ComponentType) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) FloatValidator(gaiasky.util.validator.FloatValidator)

Example 4 with FloatValidator

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

the class DatasetLoadDialog method addVariableStarsWidget.

private void addVariableStarsWidget(Table container) {
    OwnLabel starProps = new OwnLabel(I18n.txt("gui.dsload.variable.properties"), skin, "hud-subheader");
    container.add(starProps).colspan(2).left().padTop(pad15).padBottom(pad10).row();
    // Info
    String scInfoStr = I18n.txt("gui.dsload.variable.info") + '\n';
    int scLines = GlobalResources.countOccurrences(scInfoStr, '\n');
    TextArea scInfo = new OwnTextArea(scInfoStr, skin, "info");
    scInfo.setDisabled(true);
    scInfo.setPrefRows(scLines + 1);
    scInfo.setWidth(taWidth);
    scInfo.clearListeners();
    container.add(scInfo).colspan(2).left().padTop(pad5).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 5 with FloatValidator

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

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