package projecto;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import com.borland.dx.sql.dataset.*;
import com.borland.dx.dataset.*;

/**
 * <p>Title: SQL Server + JBuilder Foundation</p>
 * <p>Description: BD Exemplo + Java</p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: DI-UBI</p>
 * @author Bases de dados
 * @version 1.0
 */

public class dlgDepInserir extends JDialog {
  JPanel panel1 = new JPanel();
  BorderLayout borderLayout1 = new BorderLayout();
  JPanel jPanel1 = new JPanel();
  JLabel jlDepCod = new JLabel();
  JTextField jtfDepCod = new JTextField();
  JLabel jlNome = new JLabel();
  JTextField jtfNome = new JTextField();
  JLabel jlLocal = new JLabel();
  JTextField jtfLocal = new JTextField();
  JPanel jPanel2 = new JPanel();
  JButton jbtOK = new JButton();
  JButton jbtCancel = new JButton();

  boolean isClickedjbtOK= false;

  public dlgDepInserir(Frame frame, String title, boolean modal) {
    super(frame, title, modal);
    try {
      jbInit();
      pack();
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }

  public dlgDepInserir() {
    this(null, "", false);
  }

  private void jbInit() throws Exception {
    panel1.setLayout(borderLayout1);
    this.setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
    jlDepCod.setHorizontalAlignment(SwingConstants.LEFT);
    jlDepCod.setHorizontalTextPosition(SwingConstants.LEFT);
    jlDepCod.setIconTextGap(4);
    jlDepCod.setLabelFor(jtfDepCod);
    jlDepCod.setText("Codigo");
    jlDepCod.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
    jlDepCod.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jtfDepCod.addActionListener(new dlgDepInserir_jtfDepCod_actionAdapter(this));
    jtfDepCod.setEnabled(false);
    jtfDepCod.setMinimumSize(new Dimension(50, 20));
    jtfDepCod.setOpaque(true);
    jtfDepCod.setPreferredSize(new Dimension(50, 20));
    jtfDepCod.setRequestFocusEnabled(true);
    jtfDepCod.setEditable(false);
    jtfDepCod.setText("");
    jlNome.setForeground(Color.black);
    jlNome.setHorizontalTextPosition(SwingConstants.LEADING);
    jlNome.setText("Nome");
    jlLocal.setNextFocusableComponent(jtfDepCod);
    jlLocal.setRequestFocusEnabled(true);
    jlLocal.setLabelFor(jtfLocal);
    jlLocal.setText("Local");
    jtfNome.setMinimumSize(new Dimension(70, 20));
    jtfNome.setNextFocusableComponent(jtfLocal);
    jtfNome.setPreferredSize(new Dimension(70, 20));
    jtfNome.setText("");
    jtfLocal.setMinimumSize(new Dimension(70, 20));
    jtfLocal.setPreferredSize(new Dimension(70, 20));
    jtfLocal.setText("");
    jbtOK.setText("OK");
    jbtOK.addActionListener(new dlgDepInserir_jbtOK_actionAdapter(this));
    jbtCancel.setText("Cancel");
    jbtCancel.addActionListener(new dlgDepInserir_jbtCancel_actionAdapter(this));

    panel1.setNextFocusableComponent(jtfNome);
    getContentPane().add(panel1);
    panel1.add(jPanel1, BorderLayout.CENTER);
    jPanel1.add(jlDepCod, null);
    jPanel1.add(jtfDepCod, null);
    jPanel1.add(jlNome, null);
    jPanel1.add(jtfNome, null);
    jPanel1.add(jlLocal, null);
    jPanel1.add(jtfLocal, null);
    panel1.add(jPanel2,  BorderLayout.SOUTH);
    jPanel2.add(jbtOK, null);
    jPanel2.add(jbtCancel, null);


  }

//.............................................................................
// showDepInsAlt(int DepNum, String Nome, String Local)
//   Parameters:
//      [in]:
//            DepNum - the number of department.
//      [inout]:
//            Nome   - string, the name of department
//            Local  - string, Location
//   Result: Integer
//      0  - Button Ok has clicked and (Nome or Local modified)
//      >0 - Button Cancel has clicked
//      <0 - An error has ocurred
//
// purpose: get the department Name and Location.
//.............................................................................

  public int showDepInsAlt(int DepNum, StringBuffer Nome, StringBuffer Local){

    jtfDepCod.setText( Integer.toString( DepNum));
    jtfNome.setText(Nome.toString());
    jtfLocal.setText(Local.toString());
    this.show();

    jtfNome.setText(jtfNome.getText().trim());
    jtfLocal.setText(jtfLocal.getText().trim());

    if (isClickedjbtOK && (Nome.toString() != jtfNome.getText()) &&
        (Local.toString() != jtfLocal.getText())){
      Nome.append(jtfNome.getText());
      Local.append(jtfLocal.getText());
      return 0;
    }
    else
      return 1;
   }


  void jtfDepCod_actionPerformed(ActionEvent e) {

  }

  void jbtOK_actionPerformed(ActionEvent e) {
    isClickedjbtOK = true;
    this.hide();
  }

  void jbtCancel_actionPerformed(ActionEvent e) {
    this.hide();
  }
}

class dlgDepInserir_jtfDepCod_actionAdapter implements java.awt.event.ActionListener {
  dlgDepInserir adaptee;

  dlgDepInserir_jtfDepCod_actionAdapter(dlgDepInserir adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jtfDepCod_actionPerformed(e);
  }
}

class dlgDepInserir_jbtOK_actionAdapter implements java.awt.event.ActionListener {
  dlgDepInserir adaptee;

  dlgDepInserir_jbtOK_actionAdapter(dlgDepInserir adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jbtOK_actionPerformed(e);
  }
}

class dlgDepInserir_jbtCancel_actionAdapter implements java.awt.event.ActionListener {
  dlgDepInserir adaptee;

  dlgDepInserir_jbtCancel_actionAdapter(dlgDepInserir adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jbtCancel_actionPerformed(e);
  }
}
