All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jdplus.toolkit.desktop.plugin.ui.properties.l2fprod.RampDescriptor Maven / Gradle / Ivy

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jdplus.toolkit.desktop.plugin.ui.properties.l2fprod;

import jdplus.toolkit.base.api.timeseries.regression.Ramp;
import jdplus.toolkit.base.api.timeseries.regression.Variable;
import jdplus.toolkit.desktop.plugin.descriptors.EnhancedPropertyDescriptor;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.time.Clock;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Jean Palate
 */
public class RampDescriptor extends VariableDescriptor {

    @Override
    public String name() {
        return "rp: " + VariableDescriptor.toShortString(core.getStart(), core.getEnd(), UserInterfaceContext.INSTANCE.getDomain());
    }

    private Ramp core;

    public RampDescriptor() {
        core = new Ramp(LocalDateTime.now(Clock.systemDefaultZone()), LocalDateTime.now(Clock.systemDefaultZone()));
    }

    public RampDescriptor duplicate() {
        return new RampDescriptor(this);
    }

    public RampDescriptor(Variable ramp) {
        super(ramp);
        core = ramp.getCore();
        setName(ramp.getName());
    }

    public RampDescriptor(RampDescriptor desc) {
        super(desc);
        this.core = desc.core;
    }

    @Override
    public Ramp getCore() {
        return core;
    }

    public LocalDate getStart() {
        return core.getStart().toLocalDate();
    }

    public void setStart(LocalDate day) {
        core = new Ramp(day.atStartOfDay(), core.getEnd());
    }

    public LocalDate getEnd() {
        return core.getEnd().toLocalDate();
    }

    public void setEnd(LocalDate day) {
        core = new Ramp(core.getStart(), day.atStartOfDay());
    }

    @Override
    public List getProperties() {
        ArrayList descs = new ArrayList<>();
        EnhancedPropertyDescriptor desc;
        desc = nameDesc();
        if (desc != null) {
            descs.add(desc);
        }
        desc = startDesc();
        if (desc != null) {
            descs.add(desc);
        }
        desc = endDesc();
        if (desc != null) {
            descs.add(desc);
        }
        desc = parameterDesc();
        if (desc != null) {
            descs.add(desc);
        }
        return descs;
    }
    private static final int START_ID = 10,
            END_ID = 11;

    private EnhancedPropertyDescriptor startDesc() {
        try {
            PropertyDescriptor desc = new PropertyDescriptor("start", this.getClass());
            EnhancedPropertyDescriptor edesc = new EnhancedPropertyDescriptor(desc, START_ID);
            desc.setDisplayName("Start");
            //edesc.setReadOnly(true);
            return edesc;
        } catch (IntrospectionException ex) {
            return null;
        }
    }

    private EnhancedPropertyDescriptor endDesc() {
        try {
            PropertyDescriptor desc = new PropertyDescriptor("end", this.getClass());
            EnhancedPropertyDescriptor edesc = new EnhancedPropertyDescriptor(desc, END_ID);
            desc.setDisplayName("End");
            //edesc.setReadOnly(true);
            return edesc;
        } catch (IntrospectionException ex) {
            return null;
        }
    }

    @Override
    public String getDisplayName() {
        return "Ramp";
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy