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

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class DVMSettingsFields implements DialogFields {
    public JTextField tfName;
    public JSpinner sMinDimProc;
    public JSpinner sMaxDimProc;
    public JSpinner sMaxProc;
    public JCheckBox cbCube;
    public JTextField tfFlags;
    public JTextField tfEnvironments;
    public JCheckBox cbDvmStat;
    private JPanel content;
    private JButton bAddFlags;
    private JButton bAddEnvironments;
    private JButton bDeleteFlags;
    private JButton bDeleteEnvironment;
    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("");
            }
        });
    }
    @Override
    public Component getContent() {
        return content;
    }
    private void createUIComponents() {
        // TODO: place custom component creation code here
        tfName = new StyledTextField();
    }
}
