//Sample code file: var/ndk/webBuildengine/tmp/viewable_samples/a4ad0b48-dd95-46b6-8289-721e99c8dc76/login_method/mgmt/ldap/src/MainFrame.java //Warning: This code has been marked up for HTML

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.io.File;

/**
 * <p>Title: NMAS Clear Password Utility</p>
 * <p>Description: Used to set the NMAS Clear Password on Linux</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: Novell, Inc.</p>
 * @author Gordon Mathis
 * @version 1.0
 */

public class MainFrame extends JFrame {
  JPanel contentPane;
  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JLabel jLabel4 = new JLabel();
  JLabel jLabel5 = new JLabel();
  JLabel jLabel6 = new JLabel();
  JLabel jLabel7 = new JLabel();
  JLabel jLabel8 = new JLabel();
  
  JTextField hostAddress = new JTextField();
  JTextField hostPort = new JTextField();
  JTextField keyStore = new JTextField();
  JTextField loginDN = new JTextField();
  JPasswordField password = new JPasswordField();
  JTextField objectDN = new JTextField();
  JPasswordField secret = new JPasswordField();
  JTextArea resultArea = new JTextArea();
  JButton browseButton = new JButton();
  JButton loginButton = new JButton();
  JButton exitButton = new JButton();//  TitledBorder titledBorder1;
  Border border1;
  JScrollPane jScrollPane1 = new JScrollPane();

 //Construct the frame
  public MainFrame() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

 //Component initialization
  private void jbInit() throws Exception  {
    contentPane = (JPanel) this.getContentPane();//    titledBorder1 = new TitledBorder("");
    border1 = BorderFactory.createBevelBorder(BevelBorder.LOWERED,Color.white,Color.white,new Color(115, 114, 105),new Color(165, 163, 151));
    this.setSize(new Dimension(510, 450));
    this.setTitle("NMAS Clear Password Utility");
    jLabel1.setText("Host Address");
    jLabel1.setBounds(new Rectangle(45, 15, 150, 15));
    jLabel2.setText("Host Port");
    jLabel2.setBounds(new Rectangle(190, 15, 150, 15));
    jLabel3.setText("Path to Java KeyStore (Required)");
    jLabel3.setBounds(new Rectangle(45, 60, 250, 15));
    jLabel4.setText("Admin DN");
    jLabel4.setBounds(new Rectangle(45, 105, 150, 15));
    jLabel5.setText("Password");
    jLabel5.setBounds(new Rectangle(270, 105, 150, 15));
    jLabel6.setText("User DN");
    jLabel6.setBounds(new Rectangle(45, 150, 150, 15));
    jLabel7.setText("Clear Text Password");
    jLabel7.setBounds(new Rectangle(270, 150, 150, 15));
    jLabel8.setText("Results");
    jLabel8.setBounds(new Rectangle(45, 195, 50, 15));
    
    hostAddress.setText("127.0.0.1");
    hostAddress.setBounds(new Rectangle(45, 30, 125, 20));
    hostPort.setText("636");
    hostPort.setBounds(new Rectangle(190, 30, 125, 20));
    keyStore.setBounds(new Rectangle(45, 75, 325, 20));
    loginDN.setText("cn=admin,o=novell");
    loginDN.setBounds(new Rectangle(45, 120, 200, 20));
    password.setBounds(new Rectangle(270, 120, 190, 20));
    objectDN.setBounds(new Rectangle(45, 165, 200, 20));
    secret.setBounds(new Rectangle(270, 165, 190, 20));

    resultArea.setBorder(null);
    resultArea.setEditable(true);
    resultArea.setText("");
    resultArea.setLineWrap(false);
    resultArea.setRows(0);
    jScrollPane1.setBorder(BorderFactory.createLoweredBevelBorder());
    jScrollPane1.setBounds(new Rectangle(45, 210, 415, 125));
    jScrollPane1.getViewport().add(resultArea, null);
    browseButton.setBounds(new Rectangle(380, 75, 80, 20));
    browseButton.setSelected(false);
    browseButton.setText("Browse");
    browseButton.addActionListener(new MainFrame_browseButton_actionAdapter(this));    
    loginButton.setBounds(new Rectangle(165, 370, 70, 23));
    loginButton.setSelected(false);
    loginButton.setText("OK");
    loginButton.addActionListener(new MainFrame_loginButton_actionAdapter(this));
    exitButton.setBounds(new Rectangle(280, 370, 70, 23));
    exitButton.setText("Exit");
    exitButton.addActionListener(new MainFrame_exitButton_actionAdapter(this));
    contentPane.setLayout(null);
    contentPane.setBackground(SystemColor.control);
    contentPane.setBorder(BorderFactory.createRaisedBevelBorder());
    contentPane.add(jLabel1, null);
    contentPane.add(jLabel2, null);
    contentPane.add(jLabel3, null);
    contentPane.add(jLabel4, null);
    contentPane.add(jLabel5, null);
    contentPane.add(jLabel6, null);
    contentPane.add(jLabel7, null);
    contentPane.add(jLabel8, null);
    contentPane.add(hostAddress, null);
    contentPane.add(hostPort, null);
    contentPane.add(keyStore, null);
    contentPane.add(loginDN, null);
    contentPane.add(password, null);
    contentPane.add(objectDN, null);
    contentPane.add(secret, null);
    contentPane.add(jScrollPane1, null);
    contentPane.add(browseButton, null);
    contentPane.add(loginButton, null);
    contentPane.add(exitButton, null);
  }

 //Overridden so we can exit when window is closed
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }
  
  void browseButton_actionPerformed(ActionEvent e) {
    JFileChooser fc = new JFileChooser();
    int rc = fc.showOpenDialog(this);
    if(rc == JFileChooser.APPROVE_OPTION) {
       File file = fc.getSelectedFile();
   keyStore.setText(file.getPath());
    }
  }

  void loginButton_actionPerformed(ActionEvent e) {
    String host = hostAddress.getText();
    int port = Integer.parseInt(hostPort.getText());
    String path = keyStore.getText();
    String lgnDN = loginDN.getText();
    String lgnpswd = new String(password.getPassword());
    String objDN = objectDN.getText();
    String objpswd = new String(secret.getPassword());

    SetClrPwd cn = new SetClrPwd(host, port, path, lgnDN, lgnpswd, objDN, objpswd);
    cn.setPassword(resultArea);
  }

  void exitButton_actionPerformed(ActionEvent e) {
    System.exit(0);
  }
}

class MainFrame_browseButton_actionAdapter implements java.awt.event.ActionListener {
  MainFrame adaptee;

  MainFrame_browseButton_actionAdapter(MainFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.browseButton_actionPerformed(e);
  }
}

class MainFrame_loginButton_actionAdapter implements java.awt.event.ActionListener {
  MainFrame adaptee;

  MainFrame_loginButton_actionAdapter(MainFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.loginButton_actionPerformed(e);
  }
}

class MainFrame_exitButton_actionAdapter implements java.awt.event.ActionListener {
  MainFrame adaptee;

  MainFrame_exitButton_actionAdapter(MainFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.exitButton_actionPerformed(e);
  }
}