Package com.ytec.jdap.panel

Source Code of com.ytec.jdap.panel.SysConfigFrame

package com.ytec.jdap.panel;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import com.ytec.jdap.common.Constants;
import com.ytec.jdap.common.MD5EncryptTool;
import com.ytec.jdap.common.StringUtil;
import com.ytec.jdap.config.ConfigMamager;
import com.ytec.jdap.model.Server;

/**
*
* <pre>
* Title: ϵͳ���ý���
* Description:ϵͳ���ý���
* </pre>
*
* @author CaiJiuFa
* @version 1.00.00
*
*          <pre>
* �޸ļ�¼
*    �޸ĺ�汾:     �޸��ˣ�  �޸�����:     �޸�����:
* </pre>
*/
public class SysConfigFrame extends BaseFrame {
  private static final long serialVersionUID = 8397759257889318625L;
  private Server server;
  JLabel label;
  JLabel javaHomeLabel;
  JLabel passLabel;
  JTextField textField;
  JTextField javaHomeTextField;
  JPasswordField passField;
  JButton select;
  JButton javaHomeSelect;
  JButton passReset;
  JButton save;
  JButton cancel;
  JPanel jp1;
  Container con;

  public SysConfigFrame() {
    this.getServer();
    this.setTitle(Constants.SYS_CONFIG_TITLE);
    this.setIconImage(new ImageIcon(Constants.IMAGE_TITLE).getImage());
    con = getContentPane();
    con.setLayout(new BorderLayout());
    jp1 = new JPanel(new FlowLayout(FlowLayout.LEADING));
    label = new JLabel("Ӧ��·������ ");
    javaHomeLabel = new JLabel("javahome����");
    passLabel = new JLabel("������������ ");
    textField = new JTextField(20);
    javaHomeTextField = new JTextField(20);
    passField = new JPasswordField(20);
    select = new JButton("ѡ��");
    javaHomeSelect = new JButton("ѡ��");
    passReset = new JButton("����");
    select.setPreferredSize(new Dimension(63, 21));
    javaHomeSelect.setPreferredSize(new Dimension(63, 21));
    passReset.setPreferredSize(new Dimension(63, 21));   
    textField.setText(server.getDeployPath());
    javaHomeTextField.setText(server.getJavaHome());
    select.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (e.getSource() == select) {
          JFileChooser dialog = new JFileChooser();
          dialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
          if (StringUtil.isNotBlank(textField.getText()))
            dialog.setCurrentDirectory(new File(textField.getText()));
          int result = dialog.showOpenDialog(con);
          if (result == JFileChooser.APPROVE_OPTION) {
            File file = dialog.getSelectedFile();
            textField.setText(file.getPath());
          }
        }
      }
    });
    javaHomeSelect.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (e.getSource() == javaHomeSelect) {
          JFileChooser javaDialog = new JFileChooser();
          javaDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
          if (StringUtil.isNotBlank(javaHomeTextField.getText()))
            javaDialog.setCurrentDirectory(new File(javaHomeTextField.getText()));
          int result = javaDialog.showOpenDialog(con);
          if (result == JFileChooser.APPROVE_OPTION) {
            File file = javaDialog.getSelectedFile();
            javaHomeTextField.setText(file.getPath());
          }
        }
      }
    });
        passReset.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
        if (e.getSource() == passReset) {
          try {
            server.setPassWord(MD5EncryptTool.encryptMD5(new String(passField.getPassword())));
            ConfigMamager.getReader().modifyPassword(server);
            BaseFrame.alert("�޸�����ɹ���");
          } catch (Exception e1) {
            BaseFrame.alert("�޸��������");
          }
        }
          }
    });
    jp1.add(label);
    jp1.add(textField);
    jp1.add(select);
    jp1.add(javaHomeLabel);
    jp1.add(javaHomeTextField);
    jp1.add(javaHomeSelect);
    jp1.add(passLabel);
    jp1.add(passField);
    jp1.add(passReset);
    con.add(jp1, BorderLayout.CENTER);
    JPanel jp2 = new JPanel(new FlowLayout());
    save = new JButton("ȷ��");
    cancel = new JButton("�ر�");
    jp2.add(save);
    jp2.add(cancel);
    con.add(jp2, BorderLayout.SOUTH);
    final JFrame thiz = this;
    save.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        try {
          server.setDeployPath(textField.getText());
          server.setJavaHome(javaHomeTextField.getText());
          ConfigMamager.getReader().modifyServer(server);
          thiz.dispose();
        } catch (Exception e1) {
          alert(e1.getMessage());
        }
      }
    });
    cancel.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        thiz.dispose();
      }
    });
    this.addWindowFocusListener(new WindowFocusListener(){
      public void windowGainedFocus(WindowEvent e) {       
      }
      public void windowLostFocus(WindowEvent e) {
        e.getWindow().toFront();
      }     
    });
  }
  public Server getServer() {
    try {
      server = ConfigMamager.getReader().getServer();
    } catch (Exception e) {
      alert(e.getMessage());
    }
    return server;
  }
  public void setServer(Server server) {
    this.server = server;
  }
}
TOP

Related Classes of com.ytec.jdap.panel.SysConfigFrame

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.