package _VisualDVM.TestingSystem.DVM.DVMSettings.UI;
import _VisualDVM.Current;
import Common.Visual.TextField.StyledTextField;
import Common.Visual.Windows.Dialog.DialogFields;
import Visual_DVM_2021.Passes.PassCode;
import Common.Passes.Pass;
import _VisualDVM.Global;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class DVMSettingsFields implements DialogFields {
    private JPanel content;
    public JTextField tfName;
    public JSpinner sMinDimProc;
    public JSpinner sMaxDimProc;
    public JSpinner sMaxProc;
    public JCheckBox cbCube;
    public JTextField tfFlags;
    public JTextField tfEnvironments;
    private JButton bAddFlags;
    private JButton bAddEnvironments;
    private JButton bDeleteFlags;
    private JButton bDeleteEnvironment;
    public JCheckBox cbDvmStat;
    @Override
    public Component getContent() {
        return content;
    }
    private void createUIComponents() {
        // TODO: place custom component creation code here
        tfName = new StyledTextField();
    }
    public DVMSettingsFields(){
        sMinDimProc.setModel(new SpinnerNumberModel(1, 0, 128, 1));
        sMaxDimProc.setModel(new SpinnerNumberModel(1, 0, 128, 1));
        sMaxProc.setModel(new SpinnerNumberModel(0, 0, 128, 1));
        bAddFlags.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Pass pass =  Global.mainModule.getPass(PassCode.PickCompilerOptions);
                if (pass.Do(Global.mainModule.getCompiler())) {
                    tfFlags.setText((String)pass.target);
                }
            }
        });
        bAddEnvironments.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Pass pass =  Global.mainModule.getPass(PassCode.PickCompilerEnvironmentsForTesting);
                if (pass.Do(Global.mainModule.getCompiler()))
                    tfEnvironments.setText((String)pass.target);
            }
        });
        bDeleteFlags.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                tfFlags.setText("");
            }
        });
        bDeleteEnvironment.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                tfEnvironments.setText("");
            }
        });
    }
}
