/*
 * Assistant.java
 *
 */

package com.uvigo.tMaestro.SCOCreator.tool.adaptation;
import com.uvigo.tMaestro.SCOCreator.tool.MainFrame;
import com.uvigo.tMaestro.SCOCreator.tool.MyOptionPane;

/**
 * Es el asistente de reglas, elemento grafico (dialogo)
 * que ayuda al usuario en la generacion de las reglas de adaptacion.
 * @author  raul
 * @version 0.1
 */
public class Assistant extends javax.swing.JDialog {
    
    
    /**
     * Referencia al MainFrame de la herramienta
     */
    private MainFrame oMainFrame;
    
    /**
     * Referencia a la regla cargada en el asistente.
     */
    private Rule oRule;
    
    /**
     * Indica si el panel de expresion logica esta habilitado o no.
     */
    private boolean bExpression=true;
    
    /**
     * Indica si los operadores logicos AND y OR estan habilitados o no.
     */
    private boolean bOperators=true;
    
    
    /**
     * Indica si los elementos para elegir opci�n est�n habilitados o no.
     */
    private boolean bOptions=true;
    
    final private static int NONE=0;
    final private static int EQUALS=1;
    final private static int ALL=2;
    
    /**
     * Tipo de operadores actualmente activo
     */
    private int iOperatorsType=-1;
    
    
    /**
     * Todos los operadores
     */
    final private static String[] oOperatorsAll={"==","<=",">=","<",">"};
    
    /**
     * Combo con todos los operadores
     */
    final private javax.swing.JComboBox oComboAll = new javax.swing.JComboBox(oOperatorsAll);
    
    /**
     * El Operador equals
     */
    final private static String[] oOperatorsEquals={"=="};
    
    
    /**
     * Combo con el operador equals.
     */
    final private javax.swing.JComboBox oComboEquals = new javax.swing.JComboBox(oOperatorsEquals);
    
    /**
     * Etiqueta para cuando no hay operadores seleccionables
     */
    final private javax.swing.JLabel oLabelComplex = new javax.swing.JLabel(MainFrame.oMainFrame.getMessage("Label24"));
    
    /**
     * Numero de complex panel abiertos sobre este asistente
     */
    private int iComplexPanel=0;
    
    /**
     * Indica si se ha producido algun cambio
     * en las reglas respecto a los valores guardados.
     */
    private boolean bChanged;
    
    
    /**
     * Crea un instancia de la clase
     */
    public Assistant(java.awt.Frame parent) {
        super(parent, true);
        oMainFrame = (MainFrame) parent;
        initComponents();
        
        //Solo permitimos seleccionar un unico elemento
        oJList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        
        //Anadimos el listener de la JList
        oJList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void  valueChanged(javax.swing.event.ListSelectionEvent oE) {
                ruleSelected(oE);
            }
        });
        
        oJList1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent oEvent) {
                if (oEvent.getClickCount()>1) { //Si es mas de un click
                    mouse(oEvent);
                }
            }
        });
        
        oJPanel11.setBorder(new javax.swing.border.TitledBorder(oMainFrame.getMessage("Border9")));
        oJPanel12.setBorder(new javax.swing.border.TitledBorder(oMainFrame.getMessage("Border10")));
        oJPanel13.setBorder(new javax.swing.border.TitledBorder(oMainFrame.getMessage("Border11")));
        oJPanel14.setBorder(new javax.swing.border.TitledBorder(oMainFrame.getMessage("Border12")));
        
        
        
        //Intentamos cargar las reglas (si existen)
        javax.swing.DefaultListModel oModel = new javax.swing.DefaultListModel();
        for (int i=0;i<oMainFrame.sizeRules();i++) {
            oModel.addElement(oMainFrame.getRule(i).getName());
        }
        
        oJList1.setModel(oModel);
        
        oJList1.setCellRenderer(new RuleListRenderer());
        
        //A�adimos los parametros indicados por el gestor de parametros
        oJComboBox1.setModel(new javax.swing.DefaultComboBoxModel(oMainFrame.getParameterManager().getParameterNames()));
        oJComboBox1.setSelectedIndex(0);
        
        //A�adimos las opciones actuales al ComboBox de opciones
        for (int i=0;i<oMainFrame.sizeOptions();i++) {
            oJComboBox3.addItem(oMainFrame.getOption(i));
        }
        
        
        
        //Por defecto no se encuentra seleccionada ninguna regla y todo esta desactivado
        disableAllComponents();
        bChanged=false;
    }
    
    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        oJPanel1 = new javax.swing.JPanel();
        oJPanelCont = new javax.swing.JPanel();
        oJPanel11 = new javax.swing.JPanel();
        oJLabel1 = new javax.swing.JLabel();
        oJLabel1.setText(oMainFrame.getMessage("Label17"));
        oJComboBox1 = new javax.swing.JComboBox();
        oJLabel2 = new javax.swing.JLabel();
        oJLabel2.setText(oMainFrame.getMessage("Label18"));
        oJLabel3 = new javax.swing.JLabel();
        oJLabel3.setText(oMainFrame.getMessage("Label19"));
        oJPanel111 = new javax.swing.JPanel();
        oJButton5 = new javax.swing.JButton();
        oJButton5.setText(oMainFrame.getMessage("Button3"));
        oJPanel112 = new javax.swing.JPanel();
        oJPanel12 = new javax.swing.JPanel();
        oJButton6 = new javax.swing.JButton();
        oJButton7 = new javax.swing.JButton();
        oJButton8 = new javax.swing.JButton();
        oJPanel13 = new javax.swing.JPanel();
        oJButton9 = new javax.swing.JButton();
        oJButton10 = new javax.swing.JButton();
        oJButton11 = new javax.swing.JButton();
        oJPanel14 = new javax.swing.JPanel();
        oJScrollPane2 = new javax.swing.JScrollPane();
        oJTextArea1 = new javax.swing.JTextArea();
        oJPanel15 = new javax.swing.JPanel();
        oJLabel4 = new javax.swing.JLabel();
        oJLabel4.setText(oMainFrame.getMessage("Label20"));
        oJComboBox3 = new javax.swing.JComboBox();
        oJButton4 = new javax.swing.JButton();
        oJButton4.setText(oMainFrame.getMessage("Button15"));
        oJPanel2 = new javax.swing.JPanel();
        oJScrollPane1 = new javax.swing.JScrollPane();
        oJList1 = new javax.swing.JList();
        oJButton2 = new javax.swing.JButton();
        oJButton2.setText(oMainFrame.getMessage("Button13"));
        oJButton3 = new javax.swing.JButton();
        oJButton3.setText(oMainFrame.getMessage("Button14"));
        oJButton12 = new javax.swing.JButton();
        oJButton13 = new javax.swing.JButton();
        oJPanel3 = new javax.swing.JPanel();
        oJButton1 = new javax.swing.JButton();
        oJButton1.setText(oMainFrame.getMessage("Button16"));

        getContentPane().setLayout(new java.awt.GridBagLayout());

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        oJPanel1.setLayout(new java.awt.GridBagLayout());

        oJPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        oJPanel1.setPreferredSize(new java.awt.Dimension(530, 390));
        oJPanelCont.setLayout(new java.awt.GridBagLayout());

        oJPanelCont.setPreferredSize(new java.awt.Dimension(510, 210));
        oJPanel11.setLayout(new java.awt.GridBagLayout());

        oJPanel11.setPreferredSize(new java.awt.Dimension(510, 105));
        oJLabel1.setMinimumSize(new java.awt.Dimension(75, 19));
        oJLabel1.setPreferredSize(new java.awt.Dimension(75, 19));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0);
        oJPanel11.add(oJLabel1, gridBagConstraints);

        oJComboBox1.setMinimumSize(new java.awt.Dimension(175, 19));
        oJComboBox1.setPreferredSize(new java.awt.Dimension(175, 19));
        oJComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                oJComboBox1ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.25;
        oJPanel11.add(oJComboBox1, gridBagConstraints);

        oJLabel2.setMinimumSize(new java.awt.Dimension(75, 19));
        oJLabel2.setPreferredSize(new java.awt.Dimension(75, 19));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(0, 35, 0, 0);
        oJPanel11.add(oJLabel2, gridBagConstraints);

        oJLabel3.setMaximumSize(new java.awt.Dimension(75, 19));
        oJLabel3.setPreferredSize(new java.awt.Dimension(75, 19));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        oJPanel11.add(oJLabel3, gridBagConstraints);

        oJPanel111.setLayout(new java.awt.GridLayout(1, 0));

        oJPanel111.setMinimumSize(new java.awt.Dimension(175, 19));
        oJPanel111.setPreferredSize(new java.awt.Dimension(175, 19));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.25;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
        oJPanel11.add(oJPanel111, gridBagConstraints);

        oJButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                oJButton5ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(10, 35, 0, 0);
        oJPanel11.add(oJButton5, gridBagConstraints);

        oJPanel112.setLayout(new java.awt.GridLayout(1, 0));

        oJPanel112.setMinimumSize(new java.awt.Dimension(100, 19));
        oJPanel112.setPreferredSize(new java.awt.Dimension(100, 19));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 10);
        oJPanel11.add(oJPanel112, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        oJPanelCont.add(oJPanel11, gridBagConstraints);

        oJPanel12.setLayout(new java.awt.GridBagLayout());

        oJPanel12.setPreferredSize(new java.awt.Dimension(255, 105));
        oJPanel12.setRequestFocusEnabled(false);
        oJButton6.setText("AND");
        oJButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                oJButton6ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        oJPanel12.add(oJButton6, gridBagConstraints);

        oJButton7.setText("OR");
        oJButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                oJButton7ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        oJPanel12.add(oJButton7, gridBagConstraints);

        oJButton8.setText("NOT");
        oJButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                oJButton8ActionPerformed(evt);
            }
        });

        oJPanel12.add(oJButton8, new java.awt.GridBagConstraints());

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        oJPanelCont.add(oJPanel12, gridBagConstraints);

        oJPanel13.setLayout(new java.awt.GridBagLayout());

        oJPanel13.setPreferredSize(new java.awt.Dimension(255, 105));
        oJButton9.setText("(");
        oJButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                oJButton9ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        oJPanel13.add(oJButton9, gridBagConstraints);

        oJButton10.setText(")");
        oJButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                oJButton10ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        oJPanel13.add(oJButton10, gridBagConstraints);

        oJButton11.setText("<<");
        oJButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                oJButton11ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        oJPanel13.add(oJButton11, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        oJPanelCont.add(oJPanel13, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 0.91;
        oJPanel1.add(oJPanelCont, gridBagConstraints);

        oJPanel14.setLayout(new java.awt.GridBagLayout());

        oJPanel14.setPreferredSize(new java.awt.Dimension(510, 115));
        oJTextArea1.setEditable(false);
        oJTextArea1.setFont(new java.awt.Font("Courier", 1, 13));
        oJTextArea1.setLineWrap(true);
        oJTextArea1.setWrapStyleWord(true);
        oJScrollPane2.setViewportView(oJTextArea1);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        oJPanel14.add(oJScrollPane2, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        oJPanel1.add(oJPanel14, gridBagConstraints);

        oJPanel15.setLayout(new java.awt.GridBagLayout());

        oJPanel15.setPreferredSize(new java.awt.Dimension(510, 45));
        oJLabel4.setMinimumSize(new java.awt.Dimension(75, 19));
        oJLabel4.setPreferredSize(new java.awt.Dimension(75, 19));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0);
        oJPanel15.add(oJLabel4, gridBagConstraints);

        oJComboBox3.setMinimumSize(new java.awt.Dimension(100, 19));
        oJComboBox3.setPreferredSize(new java.awt.Dimension(100, 19));
        oJComboBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                oJComboBox3ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        oJPanel15.add(oJComboBox3, gridBagConstraints);

        oJButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                oJButton4ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.weightx = 2.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        oJPanel15.add(oJButton4, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 0.39;
        oJPanel1.add(oJPanel15, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        getContentPane().add(oJPanel1, gridBagConstraints);

        oJPanel2.setLayout(new java.awt.GridBagLayout());

        oJPanel2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        oJPanel2.setPreferredSize(new java.awt.Dimension(130, 390));
        oJScrollPane1.setPreferredSize(new java.awt.Dimension(120, 300));
        oJScrollPane1.setViewportView(oJList1);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 0.9;
        oJPanel2.add(oJScrollPane1, gridBagConstraints);

        oJButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                oJButton2ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.PAGE_END;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 0.1;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 2, 2);
        oJPanel2.add(oJButton2, gridBagConstraints);

        oJButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                oJButton3ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.PAGE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 0.1;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 2);
        oJPanel2.add(oJButton3, gridBagConstraints);

        oJButton12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/uvigo/tMaestro/SCOCreator/tool/adaptation/arriba.png")));
        oJButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                oJButton12ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.PAGE_END;
        gridBagConstraints.weightx = 0.5;
        gridBagConstraints.weighty = 0.1;
        gridBagConstraints.insets = new java.awt.Insets(5, 2, 2, 0);
        oJPanel2.add(oJButton12, gridBagConstraints);

        oJButton13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/uvigo/tMaestro/SCOCreator/tool/adaptation/abajo.png")));
        oJButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                oJButton13ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.PAGE_START;
        gridBagConstraints.weightx = 0.5;
        gridBagConstraints.weighty = 0.1;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 0, 0);
        oJPanel2.add(oJButton13, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.25;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
        getContentPane().add(oJPanel2, gridBagConstraints);

        oJPanel3.setLayout(new java.awt.GridBagLayout());

        oJPanel3.setPreferredSize(new java.awt.Dimension(660, 50));
        oJButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                oJButton1ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        oJPanel3.add(oJButton1, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 0.128;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        getContentPane().add(oJPanel3, gridBagConstraints);

        setSize(new java.awt.Dimension(680, 480));
    }// </editor-fold>//GEN-END:initComponents
    
    
    /**
     * Metodo llamado cuando el usuario hace doble click sobre el Jlist
     * de reglas. Permite editar el nombre de la regla en el JList
     */
    public void mouse(java.awt.event.MouseEvent oEvt) {
        int iClosestIndex = oJList1.locationToIndex(oEvt.getPoint());
        if (iClosestIndex!=-1) { //iClosestIndex es el indice mas cercano al punto
            //Debemos comprobar si el punto cae dentro del elemento correpondiente al indice
            if (oJList1.getCellBounds(iClosestIndex,iClosestIndex).contains(oEvt.getPoint())) {
                //Podemos editar el nombre del elemento del JList
                String sNuevo = MyOptionPane.showInputDialog(this,oMainFrame.getMessage("Question13")+" "+oJList1.getSelectedValue().toString(),oMainFrame.getMessage("Title46"),javax.swing.JOptionPane.QUESTION_MESSAGE);
                if (sNuevo==null) return;
                if ( ((javax.swing.DefaultListModel)oJList1.getModel()).contains(sNuevo)) {
                    java.awt.Toolkit.getDefaultToolkit().beep();
                    MyOptionPane.showMessageDialog(this,oMainFrame.getMessage("Error32"),oMainFrame.getMessage("Title12"),javax.swing.JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if (sNuevo.equals("")) {
                    java.awt.Toolkit.getDefaultToolkit().beep();
                    MyOptionPane.showMessageDialog(this,oMainFrame.getMessage("Error31"),oMainFrame.getMessage("Title12"),javax.swing.JOptionPane.ERROR_MESSAGE);
                    return;
                }
                ((javax.swing.DefaultListModel)oJList1.getModel()).set(iClosestIndex,sNuevo);
            }
            
        }
    }
    
    
    
    /**
     * Metodo llamado cuando el usuario pulsa sobre el boton de flecha abajo
     * Desplaza una regla hacia arriba
     */
    private void oJButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oJButton13ActionPerformed
        //Si bien se evita que el boton pueda ser pulsado cuando la regla es la ultima
        //nos curamos en salud voloviendo a comprobar
        if (oJList1.getSelectedIndex()==oJList1.getModel().getSize()-1) return;
        //Desplazamos la regla en el MainFrame y en el Model del JList
        int iIndex=oJList1.getSelectedIndex();
        oMainFrame.moveRule(false,iIndex);
        //Reestablecemos el modelo
        javax.swing.DefaultListModel oModel=(javax.swing.DefaultListModel) oJList1.getModel();
        String oTemp = (String) oModel.get(iIndex+1);
        oModel.set(iIndex+1,oModel.get(iIndex));
        oModel.set(iIndex,oTemp);
        oJList1.setSelectedIndex(iIndex+1);
    }//GEN-LAST:event_oJButton13ActionPerformed
    
    /**
     * Metodo llamado cuando el usuario pulsa sobre el boton de flecha arriba
     * Desplaza una regla hacia abajo
     */
    private void oJButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oJButton12ActionPerformed
        //Si bien se evita que el boton pueda ser pulsado cuando la regla es la �ltima
        //nos curamos en salud voloviendo a comprobar
        if (oJList1.getSelectedIndex()==0) return;
        //Desplazamos la regla en el MainFrame y en el Model del JList
        int iIndex=oJList1.getSelectedIndex();
        oMainFrame.moveRule(true,iIndex);
        //Reestablecemos el modelo
        javax.swing.DefaultListModel oModel=(javax.swing.DefaultListModel) oJList1.getModel();
        String oTemp = (String) oModel.get(iIndex-1);
        oModel.set(iIndex-1,oModel.get(iIndex));
        oModel.set(iIndex,oTemp);
        oJList1.setSelectedIndex(iIndex-1);
    }//GEN-LAST:event_oJButton12ActionPerformed
    
    
    /**
     * Metodo llamado cuado el usuario cambia la opcion en el ComboBox de opciones
     */
    private void oJComboBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oJComboBox3ActionPerformed
        if (oRule!=null) {
            oRule.setOption(oJComboBox3.getSelectedIndex());
            if (!bChanged) bChanged=true;
        }
    }//GEN-LAST:event_oJComboBox3ActionPerformed
    
    
    /**
     * Metodo llamado cuando se produce un cambio en el JComboBox de selecci�n
     * de parametro
     */
    private void oJComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oJComboBox1ActionPerformed
        //Vemos cual es el parametro seleccionado y presentamos el componente
        //adecuado para su configuracion (lo proporciona el ParameterManager)
        oJPanel111.removeAll();
        oJPanel111.add(oMainFrame.getParameterManager().getComponent(oJComboBox1.getSelectedIndex()));
        //Seleccionamos el combo con los operadores seleccionables en funcion del tipo de parametro
        switch (oMainFrame.getParameterManager().getParameter(oJComboBox1.getSelectedIndex()).getType()) {
            case Parameter.ENUMERATION:
            case Parameter.BOOLEAN:
            case Parameter.LANCODE:
            case Parameter.TEXT:
                if (iOperatorsType!=EQUALS) {
                    iOperatorsType=EQUALS;
                    if (!oJButton5.isEnabled()) oJButton5.setEnabled(true);
                    oJPanel112.removeAll();
                    oJPanel112.add(oComboEquals);
                }
                break;
            case Parameter.INTEGER:
            case Parameter.REAL:
                if (iOperatorsType!=ALL) {
                    iOperatorsType=ALL;
                    if (!oJButton5.isEnabled()) oJButton5.setEnabled(true);
                    oJPanel112.removeAll();
                    oJPanel112.add(oComboAll);
                }
                break;
            case Parameter.COLLECTION:
            case Parameter.COMPLEX:
                if (iOperatorsType!=NONE) {
                    iOperatorsType=NONE;
                    oJButton5.setEnabled(false);
                    oJPanel112.removeAll();
                    oJPanel112.add(oLabelComplex);
                    break;
                }
        }
        //Como se han a�adido y eliminado elementos a los paneles (siendo visibles) es necesario validarlos
        oJPanel111.validate();
        oJPanel112.validate();
        oJPanel111.repaint();
        oJPanel112.repaint();
    }//GEN-LAST:event_oJComboBox1ActionPerformed
    
    /**
     * M�todo llamado cuando el usuario pulsa sobre el aspa de cerrar la ventana
     */
    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        close();
    }//GEN-LAST:event_formWindowClosing
    
    /**
     * M�todo llamado cuando el usuario pulsa sobre el bot�n de finalizar
     */
    private void oJButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oJButton1ActionPerformed
        close();
    }//GEN-LAST:event_oJButton1ActionPerformed
    
    /**
     * Comprueba si todas las reglas han sido validadas. Pregunta al usuario
     * si esta� seguro de cerrar si no han sido todas validadas. Cierra
     */
    private void close() {
        boolean bValidated=true;
        for (int i=0;i<oMainFrame.sizeRules();i++) {
            if (!oMainFrame.getRule(i).isValid()) {
                bValidated=false;
                break;
            }
        }
        if (!bValidated)
            if (MyOptionPane.showConfirmDialog(this,oMainFrame.getMessage("Question6"),oMainFrame.getMessage("Title39"),javax.swing.JOptionPane.YES_NO_OPTION, javax.swing.JOptionPane.WARNING_MESSAGE)==javax.swing.JOptionPane.NO_OPTION) return;
        if (bChanged) oMainFrame.valueChanged();
        dispose();
    }
    
    
    //Este m�todo es llamado cuando el usuario pulsa sobre el bot�n de validar regla
    private void oJButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oJButton4ActionPerformed
        if (!bChanged) bChanged=true;
        //Aqu� debemos llamar a la funci�n encargada de validar la regla
        //Releemos adem�s la opci�n
        oRule.setOption(oJComboBox3.getSelectedIndex());
        oRule.validate(oJTextArea1);
        oJList1.repaint();
        MyOptionPane.showMessageDialog(this, oMainFrame.getMessage("Label22"), oMainFrame.getMessage("Title38"),javax.swing.JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_oJButton4ActionPerformed
    
    /**
     * M�todo llamado cuando el usuario pulsa sobre el bot�n de borrar regla
     */
    private void oJButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oJButton3ActionPerformed
        if (!bChanged) bChanged=true;
        //Preguntamos al usuario si est�s seguro
        int iResul=MyOptionPane.showConfirmDialog(this,oMainFrame.getMessage("Question5"),oMainFrame.getMessage("Title36"),javax.swing.JOptionPane.YES_NO_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE);
        if (iResul==javax.swing.JOptionPane.YES_OPTION) {
            int iIndexRule = oJList1.getSelectedIndex();
            //Seleccionamos la nueva regla
            if (((javax.swing.DefaultListModel)oJList1.getModel()).getSize()==1) {
                //S�lo queda esta la regla que vamos a borrar
                oJList1.clearSelection();
                //Despu�s de eliminar esta regla ya no habr�
                //m�s reglas. Por tanto ni se pueden eliminar, ni validar.
                oJButton3.setEnabled(false);
                disableAllComponents();
            } else { //Seleccionamos la nueva regla (la anterior si es posible)
                if (iIndexRule==0) oJList1.setSelectedIndex(1);
                else oJList1.setSelectedIndex(iIndexRule-1);
            }
            //Borramos la regla del MainFrame
            oMainFrame.removeRule(iIndexRule);
            //Borramos la regla de la lista
            ((javax.swing.DefaultListModel)oJList1.getModel()).remove(iIndexRule);
            updateFlechas();
        }
        
    }//GEN-LAST:event_oJButton3ActionPerformed
    
    /**
     * Funci�n llamada cuando el usuario pulsa sobre el bot�n de deshacer
     */
    private void oJButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oJButton11ActionPerformed
        if (!bChanged) bChanged=true;
        oRule.removeLastAction();
        stateChange(oRule.getLastAction());
        oJTextArea1.setText(oRule.getText());
    }//GEN-LAST:event_oJButton11ActionPerformed
    
    /**
     * Funci�n llamada cuando el usuario pulsa sobre el bot�n
     * de crear una expresi�n
     */
    private void oJButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oJButton5ActionPerformed
        if (!bChanged) bChanged=true;
        Expression oExpression = new Expression((String)oJComboBox1.getSelectedItem(),((javax.swing.JComboBox)oJPanel112.getComponent(0)).getSelectedIndex(), getValue());
        oRule.addExpression(oExpression);
        String sExpression = oExpression.getExpression();
        int iLastState = oRule.getLastAction();
        if (iLastState==Rule.AND || iLastState==Rule.OR) {
            oJTextArea1.append(" "+sExpression);
            oRule.addAction(Rule.EXPRESSION, " "+sExpression);
        } else {
            oJTextArea1.append(sExpression);
            oRule.addAction(Rule.EXPRESSION, sExpression);
        }
        stateChange(Rule.EXPRESSION);
    }//GEN-LAST:event_oJButton5ActionPerformed
    
    /**
     * Devuelve el valor seleccionado en el ComboBox de valor del par�metro
     */
    private Object getValue() {
        java.awt.Component oComponent = oJPanel111.getComponent(0);
        Object oValue;
        if (oComponent instanceof javax.swing.JComboBox) oValue=((javax.swing.JComboBox)oComponent).getSelectedItem();
        else if (oComponent instanceof javax.swing.JSpinner) oValue = ((javax.swing.JSpinner)oComponent).getValue();
        else oValue=((javax.swing.JTextField)oComponent).getText();
        return oValue;
    }
    
    
    /**
     * Funci�n llamada cuando el usuario pulsa sobre cerrar un par�ntesis
     */
    private void oJButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oJButton10ActionPerformed
        if (!bChanged) bChanged=true;
        oRule.decPar();
        oJTextArea1.append(")");
        oRule.addAction(Rule.PARC,")");
        stateChange(Rule.PARC);
    }//GEN-LAST:event_oJButton10ActionPerformed
    
    /**
     * Funci�n llamada cuando el usuario pulsa sobre abrir un par�ntesis
     */
    private void oJButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oJButton9ActionPerformed
        if (!bChanged) bChanged=true;
        oRule.incPar();
        int iLastAction=oRule.getLastAction();
        if (iLastAction==Rule.PARO || iLastAction==Rule.INITIAL || iLastAction==Rule.NOT) {
            oJTextArea1.append("(");
            oRule.addAction(Rule.PARO,"(");
        } else {
            oJTextArea1.append(" (");
            oRule.addAction(Rule.PARO," (");
        }
        stateChange(Rule.PARO);
    }//GEN-LAST:event_oJButton9ActionPerformed
    
    /**
     * Funci�n llamada al pulsar sobre el operador l�gico NOT
     */
    private void oJButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oJButton8ActionPerformed
        if (!bChanged) bChanged=true;
        int iLastAction = oRule.getLastAction();
        if (iLastAction==Rule.INITIAL || iLastAction==Rule.PARO) {
            oJTextArea1.append("!");
            oRule.addAction(Rule.NOT,"!");
        } else {
            oJTextArea1.append(" !");
            oRule.addAction(Rule.NOT," !");
        }
        stateChange(Rule.NOT);
    }//GEN-LAST:event_oJButton8ActionPerformed
    
    
    /**
     * Funci�n llamada al pulsar sobre el operador l�gico OR
     */
    private void oJButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oJButton7ActionPerformed
        if (!bChanged) bChanged=true;
        oJTextArea1.append(" OR");
        oRule.addAction(Rule.OR," OR");
        stateChange(Rule.OR);
    }//GEN-LAST:event_oJButton7ActionPerformed
    
    /**
     * Funci�n llamada al pulsar sobre el operador l�gico AND
     */
    private void oJButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oJButton6ActionPerformed
        if (!bChanged) bChanged=true;
        oJTextArea1.append(" AND");
        oRule.addAction(Rule.AND," AND");
        stateChange(Rule.AND);
    }//GEN-LAST:event_oJButton6ActionPerformed
    
    /**
     * Esta funci�n es llamada cuando el usuario pulsa sobre el bot�n de crear regla
     */
    private void oJButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oJButton2ActionPerformed
        if (!bChanged) bChanged=true;
        boolean bRight;
        String sName = null;
        do {
            bRight=true;
            sName = MyOptionPane.showInputDialog(this,oMainFrame.getMessage("Label21"),oMainFrame.getMessage("Title37"),javax.swing.JOptionPane.QUESTION_MESSAGE);
            if (sName==null) return;
            if (sName.equals("")) {
                bRight=false;
                continue;
            }
            for (int i=0;i<oMainFrame.sizeRules();i++) {
                if (oMainFrame.getRule(i).getName().equals(sName)) {
                    MyOptionPane.showMessageDialog(this, oMainFrame.getMessage("Label23"), oMainFrame.getMessage("Title2"), javax.swing.JOptionPane.WARNING_MESSAGE);
                    bRight=false;
                    break;
                }
            }
        } while (!bRight);
        oRule = new Rule(sName);
        oMainFrame.addRule(oRule);
        ((javax.swing.DefaultListModel)oJList1.getModel()).addElement(oRule.getName());
        updateFlechas();
        
    }//GEN-LAST:event_oJButton2ActionPerformed
    
    /**
     * Deshabilita todos los componentes del asistente (excepto el bot�n Nueva
     * y el bot�n Finalizar)
     */
    private void disableAllComponents() {
        //oJButton1.setEnabled(bEnable);
        //oJButton2.setEnabled(bEnable);
        enableExpression(false);
        enableOperators(false);
        enableOptions(false);
        oJButton3.setEnabled(false);    //Bot�n de borrar regla
        oJButton4.setEnabled(false);    //Bot�n de validar
        oJButton8.setEnabled(false);    //Bot�n del NOT
        oJButton9.setEnabled(false);    //Bot�n del Par�ntesis (abrir)
        oJButton10.setEnabled(false);   //Bot�n del Par�ntesis (cerrar)
        oJButton11.setEnabled(false);   //Bot�n de deshacer
        oJButton12.setEnabled(false);   //Boton de subir regla
        oJButton13.setEnabled(false);   //Boton de bajar regla
        oJTextArea1.setText(null);      //Area para la expresi�n l�gica
    }
    
    /**
     * M�todo que actualiza el estado de presentaci�n de los botones flecha
     */
    private void updateFlechas() {
        int iIndex =  oJList1.getSelectedIndex();
        if (iIndex==-1) return;
        if (oJList1.getModel().getSize()==1) {
            if (oJButton12.isEnabled()) oJButton12.setEnabled(false);
            if (oJButton13.isEnabled()) oJButton13.setEnabled(false);
        } else {
            if (iIndex!=0)  {
                if (!oJButton12.isEnabled()) oJButton12.setEnabled(true);
            } else if (oJButton12.isEnabled()) oJButton12.setEnabled(false);
            if (iIndex!=oJList1.getModel().getSize()-1) {
                if (!oJButton13.isEnabled()) oJButton13.setEnabled(true);
            } else if (oJButton13.isEnabled()) oJButton13.setEnabled(false);
        }
    }
    
    /**
     * Funci�n llamada cuando el usuario selecciona
     * una regla en la JList de Reglas
     */
    private void ruleSelected(javax.swing.event.ListSelectionEvent oE) {
        if (oE.getValueIsAdjusting()) return;
        //Cargamos la regla
        int iIndex;
        if ((iIndex=oJList1.getSelectedIndex())==-1) return;
        oRule = oMainFrame.getRule(iIndex);
        oJTextArea1.setText(oRule.getText());
        stateChange(oRule.getLastAction());
        //Vemos si la regla ya tiene una opci�n asignada
        if (oRule.getOption()!=-1 && oRule.getOption()<oMainFrame.sizeOptions()) oJComboBox3.setSelectedIndex(oRule.getOption());
        else oJComboBox3.setSelectedIndex(0);
        //Cuando una regla se encuentra seleccionada
        //se puede borrar, validar y seleccionar su opci�n asociada
        if (!oJButton3.isEnabled()) oJButton3.setEnabled(true);
        enableOptions(true);
        updateFlechas();
    }
    
    /**
     * Esta funci�n habilita o deshabilita los elementos
     * del panel que permite definir una expresi�n l�gica
     * a partir de una criterio.
     */
    private void enableExpression(boolean bEnable) {
        if (bExpression!=bEnable) {
            bExpression=bEnable;
            oJComboBox1.setEnabled(bEnable);
            oJPanel111.getComponent(0).setEnabled(bEnable);
            oJPanel112.getComponent(0).setEnabled(bEnable);
            oJLabel1.setEnabled(bEnable);
            oJLabel2.setEnabled(bEnable);
            oJLabel3.setEnabled(bEnable);
            int iType = MainFrame.oMainFrame.getParameterManager().getParameter(oJComboBox1.getSelectedIndex()).getType();
            if (bEnable && iType!=Parameter.COMPLEX && iType!=Parameter.COLLECTION)
                oJButton5.setEnabled(true);
            else  oJButton5.setEnabled(false);
        }
    }
    
    /**
     * Esta funci�n habilita o deshabilita los operadores
     * l�gicos AND y OR
     */
    private void enableOperators(boolean bEnable) {
        if (bOperators!=bEnable) {
            bOperators=bEnable;
            oJButton6.setEnabled(bEnable);
            oJButton7.setEnabled(bEnable);
        }
    }
    
    /**
     * Esta funci�n habilita o deshabilita los elementos
     * para elegir la opci�n asociada a la regla
     */
    private void enableOptions(boolean bEnable) {
        if (bOptions!=bEnable) {
            bOptions=bEnable;
            oJLabel4.setEnabled(bEnable);
            oJComboBox3.setEnabled(bEnable);
        }
    }
    
    /**
     * M�todo que solicita que el asistente actualice el combo box
     * de opciones con las opciones del MainFrame
     */
    public void updateOptions() {
        //A�adimos las opciones actuales al ComboBox de opciones
        int iIndex= oJComboBox3.getSelectedIndex();
        oJComboBox3.removeAllItems();
        for (int i=0;i<oMainFrame.sizeOptions();i++) {
            oJComboBox3.addItem(oMainFrame.getOption(i));
        }
        if (iIndex<oMainFrame.sizeOptions()) oJComboBox3.setSelectedIndex(iIndex);
    }
    
    /**
     * Esta funci�n se utiliza para notificar un cambio
     * en el estado de edici�n de una regla. B�sicamente
     * informa del �ltimo bot�n pulsado por el usuario y
     * en funci�n de ello, activa o desactiva otros elementos.
     * De esta forma evitamos que el usuario cree expresiones
     * l�gicas incoherentes.
     * Los posibles estados son los indicados mediante variables
     * est�ticas al principio de la clase Rule
     * @param iState Un entero que indica el nuevo estado de edici�n
     */
    public void stateChange(int iState) {
        //El entrar en esta fuci�n implica que la regla no est� validada
        //ya que previa llamada a esta funci�n se llama a la funci�n que altera
        //el estado de la regla (y que la invalida). No obstante,
        //es necesario saber si antes de la llamada a estas dos funciones la regla
        //era v�lida, ya que si fuese as�, es necesario actualizar el estado de validaci�n
        //de la regla en este asistente indicado en la JList mediante el color de la regla
        if (oRule.hasTransition()) oJList1.repaint();
        //Actualizamos el estado de los botones seg�n la acci�n que se ha a�adido a la regla
        switch (iState) {
            case Rule.INITIAL: enableExpression(true);
            enableOperators(false);
            if (oJButton4.isEnabled()) oJButton4.setEnabled(false); //Validar
            if (!oJButton8.isEnabled()) oJButton8.setEnabled(true); //NOT
            if (!oJButton9.isEnabled()) oJButton9.setEnabled(true); //PARO
            if (oJButton10.isEnabled()) oJButton10.setEnabled(false); //PARC
            if (oJButton11.isEnabled()) oJButton11.setEnabled(false); //DESHACER
            break;
            case Rule.PARO: //El comportamiento es el mismo que el del OR
            case Rule.AND:  //El comportamiento es el mismo que el del OR
            case Rule.OR:  enableExpression(true);
            enableOperators(false);
            if (oJButton4.isEnabled()) oJButton4.setEnabled(false);
            if (!oJButton8.isEnabled()) oJButton8.setEnabled(true);
            if (!oJButton9.isEnabled()) oJButton9.setEnabled(true);
            if (oJButton10.isEnabled()) oJButton10.setEnabled(false);
            if (!oJButton11.isEnabled()) oJButton11.setEnabled(true);
            break;
            case Rule.NOT: enableExpression(true);
            enableOperators(false);
            if (oJButton4.isEnabled()) oJButton4.setEnabled(false);
            if (oJButton8.isEnabled()) oJButton8.setEnabled(false);
            if (!oJButton9.isEnabled()) oJButton9.setEnabled(true);
            if (oJButton10.isEnabled()) oJButton10.setEnabled(false);
            if (!oJButton11.isEnabled()) oJButton11.setEnabled(true);
            break;
            case Rule.PARC:  //El comportamiento es el mismo que el de EXPRESSION
            case Rule.EXPRESSION:enableExpression(false);
            enableOperators(true);
            if (!oJButton4.isEnabled()) oJButton4.setEnabled(true);
            if (oJButton8.isEnabled()) oJButton8.setEnabled(false);
            if (oJButton9.isEnabled()) oJButton9.setEnabled(false);
            if (oRule.getPar()>0) {
                if (!oJButton10.isEnabled()) oJButton10.setEnabled(true);
            } else {
                if (oJButton10.isEnabled()) oJButton10.setEnabled(false);
            }
            if (!oJButton11.isEnabled()) oJButton11.setEnabled(true);
            break;
            
        }
    }
    
    
    /**
     * Esta funci�n coloca el panel oPanel sobre el Asistente (es una panel de
     * configuracion de par�metro complejo)
     * Lo utilizan los par�metros complejos para proporcionar
     * la interfaz de configuraci�n al usuario.
     */
    private void setConfigurationPanel(ComplexPanel oPanel) {
        java.awt.GridBagConstraints oConstraints =((java.awt.GridBagLayout)oJPanel1.getLayout()).getConstraints(oJPanelCont);
        oPanel.setPreferredSize(new java.awt.Dimension(510,210));
        oJPanel1.add(oPanel,oConstraints, 0); //Lo a�adimos con z=0, para que sea visible
        oJPanel1.getComponent(1).setVisible(false);
        oPanel.setVisible(true);
    }
    
    /**
     * Elimina el �ltimo panel de configuraci�n de par�metro complejo
     * a�adido sobre oJPanelCont.
     */
    private void removeLastConfigurationPanel() {
        java.awt.Component oComplexPanel = oJPanel1.getComponent(0);
        if (oComplexPanel instanceof ComplexPanel) {
            oJPanel1.remove(oComplexPanel);
            oJPanel1.getComponent(0).setVisible(true);
        }
    }
    
    /**
     * Elimina todos los Complex Panel situados sobre este asistente.
     * @return Una pila que representa el nombre compuesto del par�metro
     */
    private java.util.Stack removeAllConfigurationPanel() {
        java.util.Stack oIndexes=new java.util.Stack();
        java.awt.Component[] oComponents = oJPanel1.getComponents();
        for (java.awt.Component oComponent: oComponents) {
            if (oComponent instanceof ComplexPanel) {
                oJPanel1.remove(oComponent);
                ComplexPanel oComplexPanel = (ComplexPanel)oComponent;
                if (oComplexPanel.getParameter().getType()==Parameter.COLLECTION) {
                    oIndexes.push(oComplexPanel.getIndex());
                    oIndexes.push("n");
                }
                oIndexes.push(oComplexPanel.getParameter().getName());
            } else {
                oComponent.setVisible(true); //Si entra aqui es porque es el �ltimo componente (el oJPanelCont)
                break;
            }
            //Por tanto no es necesario hacer el break;
        }
        return oIndexes;
    }
    
    /**
     * Este m�todo impide el cambio de la regla en edici�n
     * y desactiva los botones de borrar o crear regla, o realiza todo lo
     * contrario, es decir, los habilita. Depende del valor de bEnabled
     */
    private void enableRules(boolean bEnabled) {
        if (oJList1.isEnabled()!=bEnabled) {
            if (bEnabled && iComplexPanel!=0) return;
            oJList1.setEnabled(bEnabled);
            oJButton2.setEnabled(bEnabled);
            oJButton3.setEnabled(bEnabled);
            if (!bEnabled) {
                oJButton12.setEnabled(false);
                oJButton13.setEnabled(false);
            } else updateFlechas();
        }
    }
    
    /**
     * Esta funci�n abre el ComplexPanel oPanel sonre el asistente
     * @param oPanel El panel a situar sobre el asistente
     */
    public void openComplexPanel(ComplexPanel oPanel) {
        iComplexPanel++;
        enableRules(false);
        setConfigurationPanel(oPanel);
    }
    
    /**
     * Este m�todo es llamado por el �ltimo complex panel
     * abierto sobre el asistente, para crear una expresion v�lida
     * @param oComplesPanel El �ltimo ComplexPanel, a partir del cual se crea
     * la expresi�n l�gica
     */
    public void createComplexExpression(ComplexPanel oComplexPanel) {
        //Eliminamos todos los complex panel abiertos y pillamos el nombre del par�metro complejo
        java.util.Stack oIndexes=removeAllConfigurationPanel();
        String sParameterName = new String(oIndexes.pop().toString());
        while (!oIndexes.empty()) sParameterName = sParameterName.concat("."+oIndexes.pop().toString());
        sParameterName = sParameterName.concat("."+oComplexPanel.getSubParameterName());
        Expression oExpression = new Expression(sParameterName, oComplexPanel.getOperator(),oComplexPanel.getValue());
        oRule.addExpression(oExpression);
        String sExpression = oExpression.getExpression();
        int iLastState = oRule.getLastAction();
        if (iLastState==Rule.AND || iLastState==Rule.OR) {
            oJTextArea1.append(" "+sExpression);
            oRule.addAction(Rule.EXPRESSION, " "+sExpression);
        } else {
            oJTextArea1.append(sExpression);
            oRule.addAction(Rule.EXPRESSION, sExpression);
        }
        stateChange(Rule.EXPRESSION);
        
        iComplexPanel=0;
        enableRules(true);
    }
    
    
    /**
     * Cierra el �ltimo ComplexPanel situado sobre este asistente
     */
    public void closeLastComplexPanel() {
        iComplexPanel--;
        removeLastConfigurationPanel();
        enableRules(true);
    }
    
    /**
     * Devuelve el �ndice de la opci�n actualmente seleccionada
     */
    public int getSelectedOption() {
        return oJComboBox3.getSelectedIndex();
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton oJButton1;
    private javax.swing.JButton oJButton10;
    private javax.swing.JButton oJButton11;
    private javax.swing.JButton oJButton12;
    private javax.swing.JButton oJButton13;
    private javax.swing.JButton oJButton2;
    private javax.swing.JButton oJButton3;
    private javax.swing.JButton oJButton4;
    private javax.swing.JButton oJButton5;
    private javax.swing.JButton oJButton6;
    private javax.swing.JButton oJButton7;
    private javax.swing.JButton oJButton8;
    private javax.swing.JButton oJButton9;
    private javax.swing.JComboBox oJComboBox1;
    private javax.swing.JComboBox oJComboBox3;
    private javax.swing.JLabel oJLabel1;
    private javax.swing.JLabel oJLabel2;
    private javax.swing.JLabel oJLabel3;
    private javax.swing.JLabel oJLabel4;
    private javax.swing.JList oJList1;
    private javax.swing.JPanel oJPanel1;
    private javax.swing.JPanel oJPanel11;
    private javax.swing.JPanel oJPanel111;
    private javax.swing.JPanel oJPanel112;
    private javax.swing.JPanel oJPanel12;
    private javax.swing.JPanel oJPanel13;
    private javax.swing.JPanel oJPanel14;
    private javax.swing.JPanel oJPanel15;
    private javax.swing.JPanel oJPanel2;
    private javax.swing.JPanel oJPanel3;
    private javax.swing.JPanel oJPanelCont;
    private javax.swing.JScrollPane oJScrollPane1;
    private javax.swing.JScrollPane oJScrollPane2;
    private javax.swing.JTextArea oJTextArea1;
    // End of variables declaration//GEN-END:variables
    
}
