Package systole.view.settings

Source Code of systole.view.settings.ControllerSettings

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package systole.view.settings;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import systole.processor.correlation.CorrelationKind;
import systole.propertiesController.SettingsProperties;
import systole.view.abstractController.AbstractEditViewController;

/**
*
* @author jmj
*/
public class ControllerSettings extends AbstractEditViewController {

    private JDialogSettings dialogSettings;
    private SettingsProperties settingsProperties;

    /**
     *
     * @param parent
     */
    public ControllerSettings(java.awt.Frame parent) {
        super();
        this.settingsProperties = new SettingsProperties();
        this.dialogSettings = new JDialogSettings(parent, this);
        this.setCloseListener(dialogSettings);
    }

    /**
     *
     */
    public void showSettings() {
        this.initForm();
        this.loadPropertiesOnForm();
        this.dialogSettings.setLocationRelativeTo(dialogSettings.getParent());
        this.dialogSettings.setVisible(true);
    }

    /**
     *
     */
    public void ok() {
        this.loadPropertiesFromForm();
        this.settingsProperties.saveProperties();
        this.dialogSettings.setVisible(false);
    }

    public void cancel() {
        this.dialogSettings.setVisible(false);
    }

    private void loadPropertiesFromForm() {
        this.settingsProperties.saveImportSignalPath(this.dialogSettings.getjTxtImportDir().getText());
        this.settingsProperties.saveExportReportPath(this.dialogSettings.getjTxtExportDir().getText());
        this.settingsProperties.saveCorrelationValue((Integer) this.dialogSettings.getjSpnCorrelation().getValue());
        this.settingsProperties.saveMaxAmountOfSegments((Integer) this.dialogSettings.getjSpnAmount().getValue());
        this.settingsProperties.saveCorrelationKind((CorrelationKind) this.dialogSettings.getjCmbCorrelation().getSelectedItem());
    }

    private void loadPropertiesOnForm() {
        this.dialogSettings.getjTxtImportDir().setText(this.settingsProperties.loadImportSignalPath());
        this.dialogSettings.getjTxtExportDir().setText(this.settingsProperties.loadExportReportPath());
        this.dialogSettings.getjSpnAmount().setValue(this.settingsProperties.loadMaxAmountOfSegments());
        this.dialogSettings.getjSpnCorrelation().setValue(this.settingsProperties.loadCorrelationValue());
        this.dialogSettings.getjCmbCorrelation().setSelectedItem(this.settingsProperties.loadCorrelationKind());
    }

    private void initForm() {
        this.dialogSettings.getjCmbCorrelation().removeAllItems();
        ComboBoxModel cbModel = new DefaultComboBoxModel(CorrelationKind.values());
        this.dialogSettings.getjCmbCorrelation().setModel(cbModel);
    }
}
TOP

Related Classes of systole.view.settings.ControllerSettings

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.