package com.vci.client.logon.client;
|
|
import java.awt.Dimension;
|
import java.awt.FlowLayout;
|
import java.awt.Frame;
|
import java.awt.GridBagConstraints;
|
import java.awt.GridBagLayout;
|
import java.awt.Insets;
|
import java.awt.Panel;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.io.File;
|
import java.io.IOException;
|
import java.util.Hashtable;
|
|
import javax.swing.BorderFactory;
|
import javax.swing.JPanel;
|
import javax.swing.border.Border;
|
|
import com.vci.client.common.objects.UserEntityObject;
|
import com.vci.client.framework.delegate.SystemCfgClientDelegate;
|
import com.vci.client.ui.image.BundleImage;
|
import com.vci.client.ui.locale.LocaleDisplay;
|
import com.vci.client.ui.swing.KPasswordField;
|
import com.vci.client.ui.swing.KTextField;
|
import com.vci.client.ui.swing.VCIOptionPane;
|
import com.vci.client.ui.swing.components.VCIJButton;
|
import com.vci.client.ui.swing.components.VCIJCheckBox;
|
import com.vci.client.ui.swing.components.VCIJLabel;
|
|
|
public class LogonPanel extends JPanel {
|
|
private static final long serialVersionUID = 4361687524661657762L;
|
private VCIJLabel userNameLabel = new VCIJLabel();
|
private VCIJLabel passwordLabel = new VCIJLabel();
|
|
private KTextField userNameText = new KTextField();
|
protected KPasswordField psText = new KPasswordField();
|
private VCIJCheckBox isSave = new VCIJCheckBox();
|
protected VCIJLabel loginLabel = new VCIJLabel();
|
public VCIJButton logonButton = new VCIJButton();
|
private VCIJButton cancelButton = new VCIJButton();
|
protected Frame frame = null;
|
private int iTag = 0;
|
private Boolean isSaveShow = true;
|
public LogonPanel(Frame frame, int iTag) {
|
super();
|
try{
|
isSaveShow = new SystemCfgClientDelegate(new UserEntityObject("", "")).getConfigValue("logon.saveBut").equalsIgnoreCase("on");
|
}catch(Throwable e){
|
isSaveShow = true;
|
e.printStackTrace();
|
System.out.println("从配置Server端配置文件中读取 logon.saveBut 的配置值时发生错误,此时按默认值 true进行处理!\n" + e.toString());
|
}
|
this.frame = frame;
|
this.iTag = iTag;
|
try {
|
init();
|
this.setOpaque(false);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
private void init() throws Exception {
|
String nameText = LocaleDisplay.getI18nString("rmip.framework.logon.name", "RMIPFramework", getLocale());
|
userNameLabel.setText(nameText);
|
userNameLabel.setIcon(new BundleImage().createImageIcon ("group.png"));
|
userNameLabel.setMinimumSize(new Dimension(80, 30));
|
userNameLabel.setPreferredSize(new Dimension(80, 30));
|
userNameText.setMinimumSize(new Dimension(200, 30));
|
userNameText.setPreferredSize(new Dimension(200, 30));
|
String passwordText = LocaleDisplay.getI18nString("rmip.framework.logon.password", "RMIPFramework", getLocale());
|
passwordLabel.setText(passwordText);
|
passwordLabel.setIcon(new BundleImage().createImageIcon ("password.gif"));
|
passwordLabel.setMinimumSize(new Dimension(80, 30));
|
passwordLabel.setPreferredSize(new Dimension(80, 30));
|
psText.setMinimumSize(new Dimension(200, 30));
|
psText.setPreferredSize(new Dimension(200, 30));
|
String isSaveText = LocaleDisplay.getI18nString("rmip.framework.logon.isSave.password", "RMIPFramework", getLocale());
|
isSave.setText(isSaveText);
|
String saveText = LocaleDisplay.getI18nString("rmip.framework.logon.button.logon", "RMIPFramework", getLocale());
|
String cancelText = LocaleDisplay.getI18nString("rmip.framework.button.cancel", "RMIPFramework", getLocale());
|
logonButton.setText(saveText);
|
cancelButton.setText(cancelText);
|
logonButton.setIcon(new BundleImage().createImageIcon("ok.gif"));
|
logonButton.setPreferredSize(new Dimension(100, 30));
|
cancelButton.setIcon(new BundleImage().createImageIcon("cancel.gif"));
|
cancelButton.setPreferredSize(new Dimension(100, 30));
|
loginLabel.setMinimumSize(new Dimension(280, 30));
|
loginLabel.setPreferredSize(new Dimension(280, 30));
|
|
setUserName();
|
Border border = BorderFactory.createEmptyBorder(20,40,10,40);
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
this.setLayout(gridBagLayout);
|
this.setBorder(border);
|
this.add(userNameLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
|
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 0, 10, 0), 0, 0));
|
this.add(userNameText, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
|
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 0, 10, 0), 0, 0));
|
this.add(passwordLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
|
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 0, 10, 0), 0, 0));
|
this.add(psText, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
|
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 0, 10, 0), 0, 0));
|
this.add(isSave, new GridBagConstraints(0, 2, 2, 1, 0.0, 0.0
|
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 0, 10, 0), 0, 0));
|
|
this.add(loginLabel, new GridBagConstraints(0, 3, 2, 1, 0.0, 0.0
|
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
|
|
Panel btnPanel = new Panel();
|
this.add(btnPanel, new GridBagConstraints(0, 4, 2, 1, 1.0, 1.0
|
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
|
|
btnPanel.setLayout(new FlowLayout(FlowLayout.CENTER,30,0));
|
btnPanel.add(logonButton);
|
btnPanel.add(cancelButton);
|
|
// this.add(logonButton, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
|
// ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 20, 10, 0), 0, 0));
|
// this.add(cancelButton, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0
|
// ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 0, 10, 20), 0, 0));
|
|
if (isSaveShow){
|
isSave.setVisible(true);
|
}else {
|
isSave.setVisible(false);
|
isSave.setSelected(false);
|
}
|
|
userNameText.addActionListener(new ActionListener(){
|
|
public void actionPerformed(ActionEvent e) {
|
userNameText_actionPerformed(e);
|
}});
|
|
psText.addActionListener(new ActionListener(){
|
|
public void actionPerformed(ActionEvent e) {
|
passwordText_actionPerformed(e);
|
}});
|
logonButton.addActionListener (new ActionListener ()
|
{
|
public void actionPerformed (ActionEvent e)
|
{
|
logonButton_actionPerformed (e);
|
}
|
});
|
|
cancelButton.addActionListener (new ActionListener ()
|
{
|
public void actionPerformed (ActionEvent e)
|
{
|
cancelButton_actionPerformed(e);
|
}
|
});
|
|
this.requestFocus();
|
//
|
// if (this.userNameText.getText().equals(""))
|
// this.userNameText.requestFocus();
|
// else
|
// this.psText.requestFocus();
|
}
|
|
public static String hanlderOS() {//系统分割�?
|
String strNewFileName = "\\";
|
String osStr = System.getProperty("os.name");
|
if ( !osStr.startsWith("Win") )
|
{
|
//Unix
|
strNewFileName = strNewFileName.replace('\\','/');
|
}
|
return strNewFileName;
|
}
|
|
|
private void setUserName()
|
{
|
String path = System.getProperty("user.home");
|
if (path == null) {
|
path = System.getProperty("user.homepath");
|
}
|
File file = new File(path, "vcicode.properties");
|
if (!file.exists()) {
|
try {
|
file.createNewFile();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
String filePath = file.getAbsolutePath();
|
String[] userNames= GetOrSetProperty.readValues(filePath, new String[]{"currentUserName","currentUserPassword"});
|
|
|
if(userNames!=null)
|
{
|
userNameText.setText(userNames[0]);
|
if(userNames[1]!=null &&isSaveShow){
|
psText.setText(userNames[1]);
|
isSave.setSelected(!userNames[1].equals(""));
|
}else {
|
psText.setText("");
|
}
|
}
|
}
|
|
public void saveUserName(){
|
String path = System.getProperty("user.home");
|
if (path == null) {
|
path = System.getProperty("user.homepath");
|
}
|
File file = new File(path, "vcicode.properties");
|
if (!file.exists()) {
|
try {
|
file.createNewFile();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
String filePath = file.getAbsolutePath();
|
Hashtable<String, String> ht = new Hashtable<String, String>();
|
boolean empty = isSave.isSelected();
|
String userName = userNameText.getText();
|
String pwd = String.valueOf(psText.getPassword());
|
if(!empty){
|
pwd = "";
|
}
|
ht.put("currentUserName", userName);
|
ht.put("currentUserPassword", pwd);
|
GetOrSetProperty.writeProperties(filePath, ht);
|
}
|
|
|
public void logonButton_actionPerformed(ActionEvent e) {
|
try {
|
if(checkInput()){
|
logonButton.setEnabled(false);
|
String userName = getUserName();
|
String password = getPassword();
|
loginLabel.setIcon(new BundleImage().createImageIcon ("login.gif"));
|
LoginThread loginThread = new LoginThread(frame, userName, password, this.psText, this);
|
loginThread.start();
|
} else {
|
logonButton.setEnabled(true);
|
clearLoadingIcon();
|
}
|
} catch (Exception exp) {
|
VCIOptionPane.showError(this, exp.getMessage());
|
return;
|
}
|
}
|
|
public void clearLoadingIcon(){
|
loginLabel.setIcon(new BundleImage().createImageIcon ("blank.gif"));
|
this.repaint();
|
}
|
|
|
protected boolean checkInput(){
|
boolean res = false;
|
String userName = getUserName();
|
String password = getPassword();
|
|
if(userName.equals("")){
|
String msg = LocaleDisplay.getI18nString("rmip.framework.logon.name.isNotNull", "RMIPFramework", getLocale());
|
VCIOptionPane.showError(this, msg);
|
userNameText.requestFocus();
|
}else if(password.equals("")){
|
psText.requestFocus();
|
String msg = LocaleDisplay.getI18nString("rmip.framework.logon.password.isNotNull", "RMIPFramework", getLocale());
|
VCIOptionPane.showError(this, msg);
|
}else {
|
res = true;
|
}
|
return res;
|
}
|
|
protected String getUserName(){
|
return userNameText.getText();
|
}
|
|
protected String getPassword(){
|
return String.valueOf(psText.getPassword());
|
}
|
|
private void cancelButton_actionPerformed(ActionEvent e) {
|
if (this.iTag == 0) {
|
System.exit(0);
|
} else {
|
this.frame.dispose();
|
}
|
}
|
|
private void userNameText_actionPerformed(ActionEvent e) {
|
logonButton.requestFocus();
|
logonButton.doClick();
|
}
|
|
private void passwordText_actionPerformed(ActionEvent e) {
|
logonButton.requestFocus();
|
logonButton.doClick();
|
}
|
|
public void setDefaultFocus() {
|
if (this.userNameText.getText().equals(""))
|
this.userNameText.requestFocus();
|
else
|
this.psText.requestFocus();
|
}
|
}
|