/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.zaproxy.zap.extension.automacrobuilder.generated;

import java.awt.*;
import java.util.ResourceBundle;
import javax.swing.*;

import org.zaproxy.zap.extension.automacrobuilder.Encode;
import org.zaproxy.zap.extension.automacrobuilder.InterfaceLangOKNG;

/**
 *
 * @author gdgd009xcd
 */
@SuppressWarnings("serial")
public class LangSelectDialog extends javax.swing.JDialog {
    private static final ResourceBundle bundle = ResourceBundle.getBundle("burp/Bundle");

    MacroBuilderUI mbui = null;
    InterfaceLangOKNG LangOKNG = null;
    Encode selected_lang ;

    /**
     * new instance method<br>
     * you must define this in your extended classes for instantiation
     *
     * @param mbui
     * @param _lokng
     * @param lang
     * @param modal
     * @return this
     */
    public static LangSelectDialog newInstance(MacroBuilderUI mbui, InterfaceLangOKNG _lokng, Encode lang, Dialog.ModalityType modal) {
        return new LangSelectDialog(mbui, _lokng, lang, modal).buildThis(mbui, _lokng, lang, modal);
    }

    /**
     * Do not call this constructor directly for instantiating this class.<br>
     * use newInstance() method instead.
     *
     * @param mbui
     * @param _lokng
     * @param lang
     * @param modal
     */
    protected LangSelectDialog(MacroBuilderUI mbui, InterfaceLangOKNG _lokng, Encode lang, Dialog.ModalityType modal) {
        super(SwingUtilities.windowForComponent(mbui), bundle.getString("LangSelectDialog.Title.text"), modal);
    }

    /**
     * you must call this method in newInstance method after creating this object<br>
     * See newInstance() method.
     *
     * @param mbui
     * @param _lokng
     * @param lang
     * @param modal
     * @return
     */
    protected LangSelectDialog buildThis(MacroBuilderUI mbui, InterfaceLangOKNG _lokng, Encode lang, Dialog.ModalityType modal) {
        this.mbui = mbui;
        initComponents();
        LangOKNG = _lokng;
        selected_lang = lang;
        DefaultComboBoxModel<String> cbmodel = new DefaultComboBoxModel<String>();
        Encode[] enclist = Encode.values();
        for(Encode charset : enclist){
            cbmodel.addElement(charset.getIANACharsetName());
        }
        LANGUAGE.setModel(cbmodel);
        LANGUAGE.setSelectedItem(lang.getIANACharsetName());
        pack();
        setLocationRelativeTo(getOwner());
        return this;
    }
    
    public void setLang(Encode lang){
        selected_lang = lang;
        LANGUAGE.setSelectedItem(lang.getIANACharsetName());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        LANGUAGE = new javax.swing.JComboBox<>();
        jSeparator1 = new javax.swing.JSeparator();
        NG = new javax.swing.JButton();
        Ok = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setModal(true);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText(bundle.getString("LangSelectDialog.SelectLanguage.text")); // NOI18N

        LANGUAGE.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        LANGUAGE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LANGUAGEActionPerformed(evt);
            }
        });

        NG.setText("Cancel");
        NG.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NGActionPerformed(evt);
            }
        });

        Ok.setText("OK");
        Ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OkActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator1)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(31, 31, 31))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(Ok)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(NG)
                        .addGap(20, 20, 20))))
            .addGroup(layout.createSequentialGroup()
                .addGap(86, 86, 86)
                .addComponent(LANGUAGE, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(LANGUAGE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(39, 39, 39)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Ok)
                    .addComponent(NG))
                .addGap(32, 32, 32))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void OkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OkActionPerformed
        // TODO add your handling code here:
        LangOKNG.LangOK(selected_lang);
        dispose();
    }//GEN-LAST:event_OkActionPerformed

    private void NGActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NGActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_NGActionPerformed

    private void LANGUAGEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LANGUAGEActionPerformed
        // TODO add your handling code here:
        int idx = LANGUAGE.getSelectedIndex();
        String str = (String)LANGUAGE.getSelectedItem();  // cast Object to String
        selected_lang = Encode.getEnum(str);
    }//GEN-LAST:event_LANGUAGEActionPerformed

    /**
     * @param args the command line arguments
     */
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox<String> LANGUAGE;
    private javax.swing.JButton NG;
    private javax.swing.JButton Ok;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JSeparator jSeparator1;
    // End of variables declaration//GEN-END:variables
}
