Package es.unizar.cps.tecnodiscap.gui

Source Code of es.unizar.cps.tecnodiscap.gui.AdministrationUser

package es.unizar.cps.tecnodiscap.gui;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextField;

import es.unizar.cps.tecnodiscap.data.Usuario;
import es.unizar.cps.tecnodiscap.i18n.Messages;

import javax.swing.BorderFactory;
import java.awt.Font;
import javax.swing.JProgressBar;
import javax.swing.ImageIcon;
import javax.swing.border.EtchedBorder;
import javax.swing.border.BevelBorder;

public class AdministrationUser extends JDialog {

  /**
   *
   */
  private static final long serialVersionUID = 1L;

  private JPanel jContentPane = null;

  JTextField textFieldName = null;

  private JLabel labelName = null;

  private JPanel panelFields = null;

  private JLabel labelThresholdLeft = null;

  private JSlider sliderThresholdLeft = null;

  private JLabel labelThresholdRight = null;

  private JSlider sliderThresholdRight = null;

  private JLabel labelHysteresisLeft = null;

  private JLabel labelHysteresisRight = null;

  private JLabel labelActionLeft = null;

  private JLabel labelActionCenter = null;

  private JLabel labelDerecha = null;

  private JComboBox comboBoxRight = null;

  private JComboBox comboBoxCentre = null;

  private JComboBox comboBoxLeft = null;

  private JSlider sliderLeft = null;

  private JSlider sliderRight = null;

  private JPanel panelAction = null;

  private JButton buttonOK = null;

  private JButton buttonCancel = null;

  private WizardDialog wizard;

  private final String[] estadoPosiciones = { Messages.getString("gui.AdministrationUser.2"),
      Messages.getString("gui.AdministrationUser.1")}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

  Usuario user; // @jve:decl-index=0:

  private Usuario userBackup; // @jve:decl-index=0:

  private boolean modificado = false;

  private boolean modificando = false;

  private GUI gui;

  private JComboBox comboBoxUsuarios = null;

  private JButton buttonNuevoUsuario = null;

  private JProgressBar progressBarValorXActualizado = null;

  private JPanel panelLeds = null;

  private JLabel labelLedLeft = null;

  private JLabel labelLedRight = null;

  private JLabel labelLedCenter = null;

  private JButton buttonGuardar = null;

  private JPanel panelUsuarios = null;

  private JButton buttonEliminarUsuario = null;

  private JButton buttonWizard = null;

  private JPanel panelAcciones = null;

  /**
   * This method initializes jFrame
   *
   * @return javax.swing.JFrame
   */

  public void actualizaValores(Usuario usuario) {
    user = usuario;
    gui.user = usuario;
    if (user != null) {
      modificando = true;
      textFieldName.setText(user.getNombre());
      sliderThresholdLeft.setValue((int) user.getUmbralIzquierda());
      sliderThresholdRight.setValue((int) user.getUmbralDerecha());
      sliderLeft.setValue((int) user.getHisteresisIzquierda());
      sliderRight.setValue((int) user.getHisteresisDerecha());
      modificando = false;
    }
  }

  public void actualiza() {
    progressBarValorXActualizado.setValue(gui.getDeviceManager().getRemoteControl().getX());
    labelLedLeft.setEnabled(gui.getDeviceManager().getRemoteControl().isLeft()&& gui.user.getIzquierda()==1);
    labelLedRight.setEnabled(gui.getDeviceManager().getRemoteControl().isRight()&& gui.user.getDerecha()==1);
    labelLedCenter.setEnabled(gui.getDeviceManager().getRemoteControl().isCenter());
    if (wizard != null) {
      wizard.actualiza();
    }
  }

  private void userBackup() {
    userBackup = new Usuario(gui.user.getNombre(), gui.user
        .getUmbralDerecha(), gui.user.getUmbralIzquierda(), gui.user
        .getHisteresisIzquierda(), gui.user.getHisteresisDerecha(),
        gui.user.getDerecha(), gui.user.getCentro(), gui.user
            .getIzquierda());
  }

  public AdministrationUser(Frame owner, boolean modal) {
    super(owner, modal);
    gui = ((GUI) owner);
    user = gui.user;
    userBackup();
    this.dialogInit();
    initialize();
  }

  /**
   * This method initializes jContentPane
   *
   * @return javax.swing.JPanel
   */
  private JPanel getJContentPane() {
    if (jContentPane == null) {
      GridBagConstraints gridBagConstraints111 = new GridBagConstraints();
      gridBagConstraints111.gridx = 0;
      gridBagConstraints111.insets = new Insets(10, 0, 0, 0);
      gridBagConstraints111.gridy = 0;
      GridBagConstraints gridBagConstraints21 = new GridBagConstraints();
      gridBagConstraints21.gridx = 0;
      gridBagConstraints21.insets = new Insets(50, 0, 10, 0);
      gridBagConstraints21.gridy = 5;
      GridBagConstraints gridBagConstraints = new GridBagConstraints();
      gridBagConstraints.fill = GridBagConstraints.VERTICAL;
      gridBagConstraints.gridy = 0;
      gridBagConstraints.weightx = 1.0;
      gridBagConstraints.gridx = 1;
      GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
      gridBagConstraints3.gridx = 0;
      gridBagConstraints3.gridy = 1;
      GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
      gridBagConstraints2.gridx = 0;
      gridBagConstraints2.insets = new Insets(20, 40, 10, 10);
      gridBagConstraints2.gridheight = 2;
      gridBagConstraints2.weightx = 0.0;
      gridBagConstraints2.ipadx = 500;
      gridBagConstraints2.gridy = 3;
      labelName = new JLabel();
      labelName.setText(Messages.getString("gui.AdministrationUser.3")); //$NON-NLS-1$
      jContentPane = new JPanel();
      jContentPane.setLayout(new GridBagLayout());
      jContentPane.add(getPanelFields(), gridBagConstraints2);
      jContentPane.add(getPanelAction(), gridBagConstraints21);
      jContentPane.add(getPanelUsuarios(), gridBagConstraints111);
    }
    return jContentPane;
  }

  /**
   * This method initializes textFieldName
   *
   * @return javax.swing.JTextField
   */
  private JTextField getTextFieldName() {
    if (textFieldName == null) {
      textFieldName = new JTextField();
      textFieldName.setText(user.getNombre());
      textFieldName.setPreferredSize(new Dimension(290, 25));
      textFieldName.setMinimumSize(new Dimension(200, 25));
      textFieldName.setHorizontalAlignment(JTextField.CENTER);
      textFieldName.setColumns(0);
    }
    return textFieldName;
  }

  /**
   * This method initializes panelFields
   *
   * @return javax.swing.JPanel
   */
  private JPanel getPanelFields() {
    if (panelFields == null) {
      GridBagConstraints gridBagConstraints31 = new GridBagConstraints();
      gridBagConstraints31.gridx = 1;
      gridBagConstraints31.gridy = 11;
      GridBagConstraints gridBagConstraints30 = new GridBagConstraints();
      gridBagConstraints30.gridx = 0;
      gridBagConstraints30.anchor = GridBagConstraints.SOUTHWEST;
      gridBagConstraints30.insets = new Insets(0, 20, 20, 0);
      gridBagConstraints30.gridy = 12;
      GridBagConstraints gridBagConstraints27 = new GridBagConstraints();
      gridBagConstraints27.gridx = 1;
      gridBagConstraints27.anchor = GridBagConstraints.SOUTHEAST;
      gridBagConstraints27.insets = new Insets(40, 0, 20, 20);
      gridBagConstraints27.gridy = 12;
      GridBagConstraints gridBagConstraints23 = new GridBagConstraints();
      gridBagConstraints23.gridx = 1;
      gridBagConstraints23.insets = new Insets(0, 0, 20, 0);
      gridBagConstraints23.gridy = 1;
      GridBagConstraints gridBagConstraints20 = new GridBagConstraints();
      gridBagConstraints20.fill = GridBagConstraints.HORIZONTAL;
      gridBagConstraints20.gridy = 2;
      gridBagConstraints20.weightx = 100.0;
      gridBagConstraints20.gridwidth = 250;
      gridBagConstraints20.insets = new Insets(0, 7, 0, 20);
      gridBagConstraints20.gridx = 1;
      GridBagConstraints gridBagConstraints17 = new GridBagConstraints();
      gridBagConstraints17.fill = GridBagConstraints.BOTH;
      gridBagConstraints17.gridy = 6;
      gridBagConstraints17.weightx = 1.0;
      gridBagConstraints17.insets = new Insets(0, 5, 0, 20);
      gridBagConstraints17.gridx = 1;
      GridBagConstraints gridBagConstraints16 = new GridBagConstraints();
      gridBagConstraints16.fill = GridBagConstraints.BOTH;
      gridBagConstraints16.gridy = 5;
      gridBagConstraints16.weightx = 1.0;
      gridBagConstraints16.insets = new Insets(0, 5, 0, 20);
      gridBagConstraints16.gridx = 1;
      labelDerecha = new JLabel();
      labelDerecha
          .setText(Messages.getString("gui.AdministrationUser.4")); //$NON-NLS-1$
      labelActionCenter = new JLabel();
      labelActionCenter.setText(Messages
          .getString("gui.AdministrationUser.5")); //$NON-NLS-1$
      labelActionCenter.setVisible(false);
      labelActionLeft = new JLabel();
      labelActionLeft.setText(Messages
          .getString("gui.AdministrationUser.6")); //$NON-NLS-1$
      GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
      gridBagConstraints8.gridx = 0;
      gridBagConstraints8.anchor = GridBagConstraints.WEST;
      gridBagConstraints8.insets = new Insets(0, 20, 5, 0);
      gridBagConstraints8.gridy = 6;
      labelHysteresisRight = new JLabel();
      labelHysteresisRight.setText("Desactiva derecha:"); //$NON-NLS-1$
      GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
      gridBagConstraints7.gridx = 0;
      gridBagConstraints7.anchor = GridBagConstraints.WEST;
      gridBagConstraints7.insets = new Insets(0, 20, 5, 0);
      gridBagConstraints7.gridy = 5;
      labelHysteresisLeft = new JLabel();
      labelHysteresisLeft.setText("Desactiva Izquierda:"); //$NON-NLS-1$
      GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
      gridBagConstraints6.gridx = 0;
      gridBagConstraints6.anchor = GridBagConstraints.WEST;
      gridBagConstraints6.insets = new Insets(0, 20, 5, 0);
      gridBagConstraints6.gridy = 3;
      GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
      gridBagConstraints5.fill = GridBagConstraints.BOTH;
      gridBagConstraints5.gridy = 4;
      gridBagConstraints5.weightx = 1.0;
      gridBagConstraints5.insets = new Insets(0, 5, 0, 20);
      gridBagConstraints5.gridx = 1;
      GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
      gridBagConstraints4.gridx = 0;
      gridBagConstraints4.anchor = GridBagConstraints.WEST;
      gridBagConstraints4.insets = new Insets(0, 20, 5, 0);
      gridBagConstraints4.gridy = 4;
      labelThresholdRight = new JLabel();
      labelThresholdRight.setText("Activa Derecha:"); //$NON-NLS-1$
      GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
      gridBagConstraints11.fill = GridBagConstraints.BOTH;
      gridBagConstraints11.gridy = 3;
      gridBagConstraints11.weightx = 1.0;
      gridBagConstraints11.gridwidth = 251;
      gridBagConstraints11.insets = new Insets(0, 5, 0, 20);
      gridBagConstraints11.gridx = 1;
      labelThresholdLeft = new JLabel();
      labelThresholdLeft.setText("Activa Izquierda:"); //$NON-NLS-1$
      GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
      gridBagConstraints1.gridx = -1;
      gridBagConstraints1.anchor = GridBagConstraints.WEST;
      gridBagConstraints1.insets = new Insets(40, 20, 5, 0);
      gridBagConstraints1.gridy = -1;
      GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
      gridBagConstraints2.anchor = GridBagConstraints.CENTER;
      gridBagConstraints2.gridx = -1;
      gridBagConstraints2.gridheight = 1;
      gridBagConstraints2.gridwidth = 1;
      gridBagConstraints2.weightx = 0.0D;
      gridBagConstraints1.gridx = 0;
      gridBagConstraints1.anchor = GridBagConstraints.WEST;
      gridBagConstraints1.gridy = -1;
      panelFields = new JPanel();
      panelFields.setLayout(new GridBagLayout());
      panelFields.setBorder(BorderFactory.createCompoundBorder(
          BorderFactory.createBevelBorder(BevelBorder.RAISED),
          BorderFactory.createBevelBorder(BevelBorder.LOWERED))); //$NON-NLS-1$ //$NON-NLS-2$
      panelFields.setPreferredSize(new Dimension(800, 900));
      panelFields.add(labelName, gridBagConstraints1);
      panelFields.add(labelThresholdLeft, gridBagConstraints6);
      panelFields.add(getSliderThresholdLeft(), gridBagConstraints11);
      panelFields.add(getTextFieldName(), gridBagConstraints2);
      panelFields.add(labelThresholdRight, gridBagConstraints4);
      panelFields.add(getSliderThresholdRight(), gridBagConstraints5);
      panelFields.add(labelHysteresisLeft, gridBagConstraints7);
      panelFields.add(labelHysteresisRight, gridBagConstraints8);
      panelFields.add(getSliderLeft(), gridBagConstraints16);
      panelFields.add(getSliderRight(), gridBagConstraints17);
      panelFields.add(getProgressBarValorXActualizado(),
          gridBagConstraints20);
      panelFields.add(getPanelLeds(), gridBagConstraints23);
      panelFields.add(getButtonGuardar(), gridBagConstraints27);
      panelFields.add(getButtonWizard(), gridBagConstraints30);
      panelFields.add(getPanelAcciones(), gridBagConstraints31);
    }
    return panelFields;
  }

  /**
   * This method initializes sliderThresholdLeft
   *
   * @return javax.swing.JSlider
   */
  private JSlider getSliderThresholdLeft() {
    if (sliderThresholdLeft == null) {
      sliderThresholdLeft = new JSlider();
      sliderThresholdLeft.setMaximum(255);
      sliderThresholdLeft.setPaintTicks(false);
      sliderThresholdLeft.setPaintLabels(false);
      sliderThresholdLeft.setValue((int) user.getUmbralIzquierda());
      sliderThresholdLeft
          .addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent e) {

              user.setUmbralIzquierda(sliderThresholdLeft
                  .getValue());
              if (!modificando) {
                // No permitir valores il�gicos
                if (sliderThresholdLeft.getValue() > sliderLeft
                    .getValue()) {
                  sliderLeft.setValue(sliderThresholdLeft
                      .getValue());
                }
                if (sliderThresholdLeft.getValue() > sliderRight
                    .getValue()) {
                  sliderRight.setValue(sliderThresholdLeft
                      .getValue());
                }
                if (sliderThresholdLeft.getValue() > sliderThresholdRight
                    .getValue()) {
                  sliderThresholdRight
                      .setValue(sliderThresholdLeft
                          .getValue());
                }
                modificado = true;// En este evento entra
                          // aunque el cambio de valor
                          // sea en el c�digo
              }
            }
          });
    }
    return sliderThresholdLeft;
  }

  /**
   * This method initializes sliderThresholdRight
   *
   * @return javax.swing.JSlider
   */
  private JSlider getSliderThresholdRight() {
    if (sliderThresholdRight == null) {
      sliderThresholdRight = new JSlider();
      sliderThresholdRight.setMaximum(255);
      sliderThresholdRight.setValue((int) user.getUmbralDerecha());
      sliderThresholdRight
          .addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent e) {
              user.setUmbralDerecha(sliderThresholdRight
                  .getValue());

              if (!modificando) {
                // No permitir valores il�gicos
                if (sliderThresholdRight.getValue() < sliderRight
                    .getValue()) {
                  sliderRight.setValue(sliderThresholdRight
                      .getValue());
                }
                if (sliderLeft.getValue() > sliderThresholdRight
                    .getValue()) {
                  sliderLeft.setValue(sliderThresholdRight
                      .getValue());
                }
                if (sliderThresholdLeft.getValue() > sliderThresholdRight
                    .getValue()) {
                  sliderThresholdLeft
                      .setValue(sliderThresholdRight
                          .getValue());
                }
                modificado = true;// En este evento entra
                          // aunque el cambio de valor
                          // sea en el c�digo
              }
            }
          });
    }
    return sliderThresholdRight;
  }

  /**
   * This method initializes comboBoxRight
   *
   * @return javax.swing.JComboBox
   */
  private JComboBox getComboBoxRight() {
    if (comboBoxRight == null) {
      comboBoxRight = new JComboBox( this.estadoPosiciones );
      comboBoxRight.setSelectedIndex(user.getDerecha());
      modifyStateRight();
      comboBoxRight.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent e) {
          if (e.getStateChange() == java.awt.event.ItemEvent.SELECTED) {
            user.setDerecha(comboBoxRight.getSelectedIndex());
            modificado=true;
            modifyStateRight();
          }
        }
      });
    }
    return comboBoxRight;
  }
 
  private void modifyStateRight(){
    switch(comboBoxRight.getSelectedIndex()){
    case 0:
      sliderRight.setEnabled(false);
      sliderThresholdRight.setEnabled(false);
      break;
    case 1:
      sliderRight.setEnabled(true);
      sliderThresholdRight.setEnabled(true);             
      break;
    case 2:
      sliderRight.setEnabled(false);
      sliderThresholdRight.setEnabled(false);
      break;
    }
  }

  /**
   * This method initializes comboBoxCentre
   *
   * @return javax.swing.JComboBox
   */
  private JComboBox getComboBoxCentre() {
    if (comboBoxCentre == null) {
      comboBoxCentre = new JComboBox( this.estadoPosiciones );
      comboBoxCentre.setSelectedIndex(user.getCentro());
      comboBoxCentre.setVisible(false);
      comboBoxCentre.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent e) {
          if (e.getStateChange() == java.awt.event.ItemEvent.SELECTED) {
            user.setCentro(comboBoxCentre.getSelectedIndex());
            modificado=true;
          }
        }
      });
    }
    return comboBoxCentre;
  }

  /**
   * This method initializes comboBoxLeft
   *
   * @return javax.swing.JComboBox
   */
  private JComboBox getComboBoxLeft() {
    if (comboBoxLeft == null) {
      comboBoxLeft = new JComboBox( this.estadoPosiciones );
      comboBoxLeft.setSelectedIndex(user.getIzquierda());
      modifyStateLeft();
      comboBoxLeft.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent e) {
          if (e.getStateChange() == java.awt.event.ItemEvent.SELECTED) {
            user.setIzquierda(comboBoxLeft.getSelectedIndex());
            modificado=true;
            modifyStateLeft();
          }
        }
      });
    }
    return comboBoxLeft;
  }
 
  private void modifyStateLeft(){
    switch(comboBoxLeft.getSelectedIndex()){
    case 0:
      sliderLeft.setEnabled(false);
      sliderThresholdLeft.setEnabled(false);
      break;
    case 1:
      sliderLeft.setEnabled(true);
      sliderThresholdLeft.setEnabled(true);             
      break;
    case 2:
      sliderLeft.setEnabled(false);
      sliderThresholdLeft.setEnabled(false);
      break;
    }
  }

  /**
   * This method initializes sliderLeft
   *
   * @return javax.swing.JSlider
   */
  private JSlider getSliderLeft() {
    if (sliderLeft == null) {
      sliderLeft = new JSlider();
      sliderLeft.setMaximum(255);
      sliderLeft.setValue((int) user.getHisteresisIzquierda());
      sliderLeft
          .addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent e) {
              gui.user.setHisteresisIzquierda(sliderLeft
                  .getValue());

              if (!modificando) {
                // No permitir valores il�gicos
                if (sliderThresholdLeft.getValue() > sliderLeft
                    .getValue()) {
                  sliderThresholdLeft.setValue(sliderLeft
                      .getValue());
                }
                if (sliderThresholdRight.getValue() < sliderLeft
                    .getValue()) {
                  sliderThresholdRight.setValue(sliderLeft
                      .getValue());
                }
                if (sliderLeft.getValue() > sliderRight
                    .getValue()) {
                  sliderRight.setValue(sliderLeft.getValue());
                }
                modificado = true;// En este evento entra
                          // aunque el cambio de valor
                          // sea en el c�digo
              }
            }
          });
    }
    return sliderLeft;
  }

  /**
   * This method initializes sliderRight
   *
   * @return javax.swing.JSlider
   */
  private JSlider getSliderRight() {
    if (sliderRight == null) {
      sliderRight = new JSlider();
      sliderRight.setMaximum(255);
      sliderRight.setValue((int) user.getHisteresisDerecha());
      sliderRight
          .addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent e) {
              user.setHisteresisDerecha(sliderRight.getValue());
              if (!modificando) {
                // No permitir valores il�gicos
                if (sliderThresholdRight.getValue() < sliderRight
                    .getValue()) {
                  sliderThresholdRight.setValue(sliderRight
                      .getValue());
                }
                if (sliderLeft.getValue() > sliderRight
                    .getValue()) {
                  sliderLeft.setValue(sliderRight.getValue());
                }
                if (sliderThresholdLeft.getValue() > sliderRight
                    .getValue()) {
                  sliderThresholdLeft.setValue(sliderRight
                      .getValue());
                }
                modificado = true;// En este evento entra
                          // aunque el cambio de valor
                          // sea en el c�digo
              }
            }
          });
    }
    return sliderRight;
  }

  /**
   * This method initializes panelAction
   *
   * @return javax.swing.JPanel
   */
  private JPanel getPanelAction() {
    if (panelAction == null) {
      GridBagConstraints gridBagConstraints19 = new GridBagConstraints();
      gridBagConstraints19.gridx = 1;
      gridBagConstraints19.insets = new Insets(20, 20, 20, 20);
      gridBagConstraints19.gridy = 0;
      GridBagConstraints gridBagConstraints18 = new GridBagConstraints();
      gridBagConstraints18.gridx = 0;
      gridBagConstraints18.ipadx = 6;
      gridBagConstraints18.insets = new Insets(20, 20, 20, 20);
      gridBagConstraints18.gridy = 0;
      panelAction = new JPanel();
      panelAction.setLayout(new GridBagLayout());
      panelAction.setBorder(BorderFactory.createCompoundBorder(
          BorderFactory.createBevelBorder(BevelBorder.RAISED),
          BorderFactory.createBevelBorder(BevelBorder.LOWERED)));
      panelAction.add(getButtonOK(), gridBagConstraints18);
      panelAction.add(getButtonCancel(), gridBagConstraints19);
    }
    return panelAction;
  }

  /**
   * This method initializes buttonOK
   *
   * @return javax.swing.JButton
   */
  private JButton getButtonOK() {
    if (buttonOK == null) {
      buttonOK = new JButton();
      buttonOK.setText(Messages.getString("gui.AdministrationUser.13")); //$NON-NLS-1$
      buttonOK.setFont(new Font("Dialog", Font.BOLD, 18));
      buttonOK.setIcon(new ImageIcon("data/icons/apply.png"));
      buttonOK.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          preguntaSalvarDatos();
          dispose();
//          if(gui.salida==0)
            gui.pararAcelerometro();
        }
      });
    }
    return buttonOK;
  }

  /**
   * This method initializes buttonCancel
   *
   * @return javax.swing.JButton
   */
  private JButton getButtonCancel() {
    if (buttonCancel == null) {
      buttonCancel = new JButton();
      buttonCancel.setText(Messages
          .getString("gui.AdministrationUser.14")); //$NON-NLS-1$
      buttonCancel.setFont(new Font("Dialog", Font.BOLD, 18));
      buttonCancel.setIcon(new ImageIcon("data/icons/cancel.png"));
      buttonCancel.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          user.setValues(userBackup);
          gui.user.setValues(userBackup);
          dispose();
          gui.pararAcelerometro();
        }
      });
    }
    return buttonCancel;
  }

  /**
   * This method initializes jDialog
   *
   * @return javax.swing.JDialog
   */
  private void initialize() {
    this.setSize(new Dimension(1189, 799));
    this.setContentPane(getJContentPane());
    this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    this.setSize(gui.getSize());
    this.setVisible(true);
  }

  /**
   * This method initializes comboBoxUsuarios
   *
   * @return javax.swing.JComboBox
   */
  private JComboBox getComboBoxUsuarios() {
    if (comboBoxUsuarios == null) {
      comboBoxUsuarios = new JComboBox(gui.procesadorXML
          .getUsuariosArray2());
      comboBoxUsuarios.setSelectedIndex(gui.procesadorXML
          .getUsuarioPosition(user));
      comboBoxUsuarios.setFont(new Font("Dialog", Font.BOLD, 18));
      // TODO aqui se producen excepciones :S: selec. modif, cancelar y al
      // volver a iniciar.
      comboBoxUsuarios.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent e) {
          if (e.getStateChange() == java.awt.event.ItemEvent.SELECTED) {
            preguntaSalvarDatos();
            actualizaValores((Usuario) comboBoxUsuarios
                .getSelectedItem());
            userBackup();
          }
        }
      });
    }
    return comboBoxUsuarios;
  }

  /**
   * This method initializes buttonNuevoUsuario
   *
   * @return javax.swing.JButton
   */
  private JButton getButtonNuevoUsuario() {
    if (buttonNuevoUsuario == null) {
      buttonNuevoUsuario = new JButton();
      buttonNuevoUsuario.setText(Messages
          .getString("gui.AdministrationUser.15")); //$NON-NLS-1$
      buttonNuevoUsuario.setFont(new Font("Dialog", Font.BOLD, 18));
      buttonNuevoUsuario.setIcon(new ImageIcon("data/icons/add_user.png"));
      buttonNuevoUsuario
          .addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
              preguntaSalvarDatos();
              if (dialogoAdminUsuarios()) {
                actualizaValores(user);
                modificado = false;
                gui.procesadorXML.addUsuario(user);
                comboBoxUsuarios.addItem(user);
                comboBoxUsuarios.setSelectedItem(user);
              }
            }
          });
    }
    return buttonNuevoUsuario;
  }

  private boolean dialogoAdminUsuarios() {
    NombreUsuario dialogUsuarios = new NombreUsuario(this);
    if (dialogUsuarios.isAceptar()) {
      if (gui.procesadorXML.getUsuario(dialogUsuarios.getNombre()) == null) {
        user = new Usuario();
        user.setNombre(dialogUsuarios.getNombre());
       
      } else {
        JOptionPane.showMessageDialog(this,
            "No se puede repetir el nombre: "
                + dialogUsuarios.getNombre(),
            "El nombre ya existe", JOptionPane.ERROR_MESSAGE);
        return false;
      }
    }
    return dialogUsuarios.isAceptar();
  }

  /**
   * This method initializes progressBarValorXActualizado
   *
   * @return javax.swing.JProgressBar
   */
  private JProgressBar getProgressBarValorXActualizado() {
    if (progressBarValorXActualizado == null) {
      progressBarValorXActualizado = new JProgressBar();
      progressBarValorXActualizado.setMaximum(255);
    }
    return progressBarValorXActualizado;
  }

  /**
   * This method initializes panelLeds
   *
   * @return javax.swing.JPanel
   */
  private JPanel getPanelLeds() {
    if (panelLeds == null) {
      GridBagConstraints gridBagConstraints26 = new GridBagConstraints();
      gridBagConstraints26.gridx = 1;
      gridBagConstraints26.gridy = 0;
      labelLedCenter = new JLabel();
      labelLedCenter.setText(""); //$NON-NLS-1$
      labelLedCenter.setEnabled(false);
      labelLedCenter.setIcon(new ImageIcon("data/icons/ledlightblue.png")); //$NON-NLS-1$
      GridBagConstraints gridBagConstraints25 = new GridBagConstraints();
      gridBagConstraints25.insets = new Insets(0, 60, 0, 0);
      gridBagConstraints25.gridx = 2;
      GridBagConstraints gridBagConstraints24 = new GridBagConstraints();
      gridBagConstraints24.insets = new Insets(0, 0, 0, 60);
      labelLedRight = new JLabel();
      labelLedRight.setText(Messages
          .getString("gui.AdministrationUser.18")); //$NON-NLS-1$
      labelLedRight.setEnabled(false);
      labelLedRight
          .setIcon(new ImageIcon("data/icons/ledlightgreen.png")); //$NON-NLS-1$
      labelLedLeft = new JLabel();
      labelLedLeft.setText(Messages
          .getString("gui.AdministrationUser.20")); //$NON-NLS-1$
      labelLedLeft.setEnabled(false);
      labelLedLeft
          .setIcon(new ImageIcon("data/icons/ledlightgreen.png")); //$NON-NLS-1$
      panelLeds = new JPanel();
      panelLeds.setLayout(new GridBagLayout());
      panelLeds.add(labelLedLeft, gridBagConstraints24);
      panelLeds.add(labelLedRight, gridBagConstraints25);
      panelLeds.add(labelLedCenter, gridBagConstraints26);
    }
    return panelLeds;
  }

  /**
   * This method initializes buttonGuardar
   *
   * @return javax.swing.JButton
   */
  private JButton getButtonGuardar() {
    if (buttonGuardar == null) {
      buttonGuardar = new JButton();
      buttonGuardar.setText(Messages
          .getString("gui.AdministrationUser.22")); //$NON-NLS-1$
      buttonGuardar.setIcon(new ImageIcon("data/icons/color_line.png"));
      buttonGuardar
          .addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
              modificado = false;
            }
          });
    }
    return buttonGuardar;
  }

  /**
   * This method initializes panelUsuarios
   *
   * @return javax.swing.JPanel
   */
  private JPanel getPanelUsuarios() {
    if (panelUsuarios == null) {
      GridBagConstraints gridBagConstraints29 = new GridBagConstraints();
      gridBagConstraints29.gridx = 0;
      gridBagConstraints29.insets = new Insets(20, 20, 20, 20);
      gridBagConstraints29.gridy = 0;
      GridBagConstraints gridBagConstraints28 = new GridBagConstraints();
      // gridBagConstraints28.fill = GridBagConstraints.VERTICAL;
      gridBagConstraints28.gridy = 0;
      gridBagConstraints28.weightx = 0.0;
      gridBagConstraints28.fill = GridBagConstraints.NONE;
      gridBagConstraints28.insets = new Insets(20, 20, 20, 20);
      gridBagConstraints28.gridx = 1;
      GridBagConstraints gridBagConstraints22 = new GridBagConstraints();
      gridBagConstraints22.gridx = 2;
      gridBagConstraints22.insets = new Insets(20, 20, 20, 20);
      gridBagConstraints22.gridy = 0;
      panelUsuarios = new JPanel();
      panelUsuarios.setLayout(new GridBagLayout());
      panelUsuarios.setBorder(BorderFactory.createCompoundBorder(
          BorderFactory.createEtchedBorder(EtchedBorder.RAISED),
          BorderFactory.createBevelBorder(BevelBorder.LOWERED)));
      panelUsuarios.add(getButtonNuevoUsuario(), gridBagConstraints22);
      panelUsuarios.add(getComboBoxUsuarios(), gridBagConstraints28);
      panelUsuarios.add(getButtonEliminarUsuario(), gridBagConstraints29);
    }
    return panelUsuarios;
  }

  private void preguntaSalvarDatos() {
    if (modificado) {
      int n = JOptionPane
          .showConfirmDialog(
              null,
              Messages.getString("gui.AdministrationUser.23"), //$NON-NLS-1$
              Messages.getString("gui.AdministrationUser.24"), JOptionPane.YES_NO_OPTION); //$NON-NLS-1$
      if (n == JOptionPane.YES_OPTION) {
      } else if (n == JOptionPane.NO_OPTION) {
        gui.user.setValues(userBackup);
        user = gui.user;
      } else {
      }
      modificado = false;
    }
  }

  /**
   * This method initializes buttonEliminarUsuario
   *
   * @return javax.swing.JButton
   */
  private JButton getButtonEliminarUsuario() {
    if (buttonEliminarUsuario == null) {
      buttonEliminarUsuario = new JButton();
      buttonEliminarUsuario.setText(Messages
          .getString("gui.AdministrationUser.25")); //$NON-NLS-1$
      buttonEliminarUsuario.setFont(new Font("Dialog", Font.BOLD, 18));
      buttonEliminarUsuario.setIcon(new ImageIcon("data/icons/delete_user.png"));
      buttonEliminarUsuario
          .addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
              if(comboBoxUsuarios.getItemCount()!=1){
                gui.procesadorXML.removeUsuario(user);
                comboBoxUsuarios.removeItem(user);
              }
            }
          });
    }
    return buttonEliminarUsuario;
  }

  /**
   * This method initializes buttonWizard
   *
   * @return javax.swing.JButton
   */
  private JButton getButtonWizard() {
    if (buttonWizard == null) {
      buttonWizard = new JButton();
      buttonWizard.setText("Autoconfiguraci�n");
      buttonWizard.setIcon(new ImageIcon("data/icons/wizard.png"));
      buttonWizard.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          wizardDialog();
        }
      });
    }
    return buttonWizard;
  }

  private void wizardDialog() {
    wizard = new WizardDialog(this);
    this.modificado = true;
//    //Para calcular la izquierda
//    if (wizard.getIzqMax() > wizard.getCentMin()) {
//      user.setUmbralIzquierda(wizard.getCentMin());
//      user.setHisteresisIzquierda(wizard.getIzqMax());
//    } else {
//      user.setUmbralIzquierda(wizard.getIzqMax());
//      user.setHisteresisIzquierda(wizard.getCentMin());
//    }
//    //Para calcular la derecha
//    if (wizard.getDchaMin() < wizard.getCentMax()) {
//      user.setUmbralDerecha(wizard.getCentMax());
//      user.setHisteresisDerecha(wizard.getDchaMin());
//    } else {
//      user.setUmbralDerecha(wizard.getDchaMin());
//      user.setHisteresisDerecha(wizard.getCentMax());
//    }
    actualizaValores(user);
  }

  public GUI getGui() {
    return gui;
  }

  /**
   * This method initializes panelAcciones 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getPanelAcciones() {
    if (panelAcciones == null) {
      GridBagConstraints gridBagConstraints14 = new GridBagConstraints();
      gridBagConstraints14.fill = GridBagConstraints.BOTH;
      gridBagConstraints14.gridx = 4;
      gridBagConstraints14.gridy = 0;
      gridBagConstraints14.weightx = 1.0;
      gridBagConstraints14.insets = new Insets(0, 0, 0, 20);
      GridBagConstraints gridBagConstraints15 = new GridBagConstraints();
      gridBagConstraints15.fill = GridBagConstraints.NONE;
      gridBagConstraints15.gridx = 0;
      gridBagConstraints15.gridy = 1;
      gridBagConstraints15.weightx = 1.0;
      gridBagConstraints15.anchor = GridBagConstraints.WEST;
      gridBagConstraints15.insets = new Insets(20, 0, 0, 200);
      GridBagConstraints gridBagConstraints13 = new GridBagConstraints();
      gridBagConstraints13.fill = GridBagConstraints.NONE;
      gridBagConstraints13.gridx = 5;
      gridBagConstraints13.gridy = 1;
      gridBagConstraints13.weightx = 1.0;
      gridBagConstraints13.anchor = GridBagConstraints.EAST;
      gridBagConstraints13.insets = new Insets(20, 200, 0, 20);
      GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
      gridBagConstraints10.anchor = GridBagConstraints.WEST;
      gridBagConstraints10.gridx = 2;
      gridBagConstraints10.gridy = 0;
      gridBagConstraints10.insets = new Insets(0, 20, 5, 0);
      GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
      gridBagConstraints12.anchor = GridBagConstraints.CENTER;
      gridBagConstraints12.gridx = 5;
      gridBagConstraints12.gridy = 0;
      gridBagConstraints12.insets = new Insets(20, 200, 10, 0);
      GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
      gridBagConstraints9.anchor = GridBagConstraints.CENTER;
      gridBagConstraints9.gridx = -1;
      gridBagConstraints9.gridy = -1;
      gridBagConstraints9.insets = new Insets(20, 0, 10, 200);
      panelAcciones = new JPanel();
      panelAcciones.setLayout(new GridBagLayout());
      panelAcciones.add(labelActionLeft, gridBagConstraints9);
      panelAcciones.add(labelDerecha, gridBagConstraints12);
      panelAcciones.add(labelActionCenter, gridBagConstraints10);
      panelAcciones.add(getComboBoxRight(), gridBagConstraints13);
      panelAcciones.add(getComboBoxLeft(), gridBagConstraints15);
      panelAcciones.add(getComboBoxCentre(), gridBagConstraints14);
    }
    return panelAcciones;
  }

} //  @jve:decl-index=0:visual-constraint="10,134"
TOP

Related Classes of es.unizar.cps.tecnodiscap.gui.AdministrationUser

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.