
package turgen.config;

import javax.swing.JComponent;
import turgen.generator.PulseCrate;


public class PulseCorrectionConfigEntry extends AbstractConfigEntry {
    
    private final String defaultValue;
    
    public PulseCorrectionConfigEntry(String key,String name) {
        this.setEntryKey(key);
        this.name=name;
        PulseCrate defaultCorrectionCrate = new PulseCrate();
        defaultValue = defaultCorrectionCrate.toPropertyValueString();
    }
    
    
    public int getAsInt() {
        return 0;
    }

    public boolean getAsBoolean() {
       return false;
    }

    public String getAsString() {
        String retVal = this.getEntryValue();
        if (retVal==null) return defaultValue;
        return retVal;
    }

    public double getAsDouble() {
        return (double)getAsInt();
    }
    
    public PulseCrate getAsPulseCrate() {
        PulseCrate pc = new PulseCrate();
        pc.readFromPropertyValueString(this.getAsString());
        return pc;
    }

    public JComponent createEntryEditor() {
        
        PulseCorrectionPanel p = new PulseCorrectionPanel();
        fillEntryEditor(p);
        return p;
    }

    public void flushValueFromEditor(JComponent c) {
        PulseCorrectionPanel p = (PulseCorrectionPanel)c;
        PulseCrate pulseCorrection = p.getCorrectionCrate();
        setEntryValue(pulseCorrection.toPropertyValueString());
    }

    public String verifyEntry(JComponent c) {
        return null;
    }

    public void fillEntryEditor(JComponent c) {
        PulseCorrectionPanel p = (PulseCorrectionPanel)c;
        PulseCrate pulseCorrection = new PulseCrate();
        pulseCorrection.readFromPropertyValueString(getAsString());
        p.setCorrectionCrate(pulseCorrection);
        
    }
    
    public boolean isComponentUnderCaption() {
        return true;
    }

}
