From b086f57f56bf0eb9dab9cf321a0f69aaaae84347 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 30 May 2012 08:37:45 +0200 Subject: Initial Maven Conversion --- src/main/java/com/c2kernel/gui/LoginBox.java | 327 +++++++++++++++++++++++++++ 1 file changed, 327 insertions(+) create mode 100644 src/main/java/com/c2kernel/gui/LoginBox.java (limited to 'src/main/java/com/c2kernel/gui/LoginBox.java') diff --git a/src/main/java/com/c2kernel/gui/LoginBox.java b/src/main/java/com/c2kernel/gui/LoginBox.java new file mode 100644 index 0000000..aee469f --- /dev/null +++ b/src/main/java/com/c2kernel/gui/LoginBox.java @@ -0,0 +1,327 @@ +package com.c2kernel.gui; + +/** + *

Title:

+ *

Description:

+ *

Copyright: Copyright (c) 2003

+ *

Company:

+ * @author not attributable + * @version 1.0 + */ +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; + +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JPasswordField; +import javax.swing.JTextField; +import javax.swing.border.EmptyBorder; + +import com.c2kernel.common.InvalidDataException; +import com.c2kernel.entity.proxy.AgentProxy; +import com.c2kernel.process.Gateway; +import com.c2kernel.utils.Language; +import com.c2kernel.utils.Logger; +import com.c2kernel.utils.Resource; + + +//import com.borland.jbcl.layout.*; + +/** + *

Title:

+ *

Description:

+ *

Copyright: Copyright (c) 2003

+ *

Company:

+ * @author not attributable + * @version 1.0 + */ + +public class LoginBox extends JFrame { + private final int xMov; + private final int yMov; + public String errorMessage=new String(""); + private int maxNumberLogon; + public boolean action = false; + public int loginAttemptNumber= 0; + JLabel passwordLabel = new JLabel(); + JTextField username = new JTextField(); + JButton OK = new JButton(); + JLabel errorLabel = new JLabel(); + JPasswordField password = new JPasswordField(); + JButton Cancel = new JButton(); + JLabel userLabel = new JLabel(); + ImageIcon imageMainHolder = new ImageIcon(); + JLabel pictureLabel = new JLabel(); + GridBagLayout gridBagLayout1 = new GridBagLayout(); + MainFrame mainFrameFather; + public static AgentProxy userAgent; + private boolean logged; + private boolean errorSet; + + public LoginBox(int attempt,String title,String lastUser,String bottomMessage, + javax.swing.ImageIcon imageHolder,MainFrame mainFrame) { + String iconFile = Gateway.getProperty("AppIcon"); + if (iconFile != null) + this.setIconImage(Resource.findImage(iconFile).getImage()); + this.errorLabel.setText(bottomMessage); + if (errorMessage.compareTo("")!=0) this.errorLabel.setText(errorMessage); + mainFrameFather=mainFrame; + xMov=imageHolder.getIconWidth()+90; + yMov=imageHolder.getIconHeight()+40; + imageMainHolder=imageHolder; + try { + jbInit(); + } + catch(Exception e) { + e.printStackTrace(); + } + if (attempt==0) maxNumberLogon=5; + else maxNumberLogon=attempt; + if (title == null) + title = "Cristal2"; + title = Language.translate("Log in to ")+title; + setTitle(title); + username.setText(lastUser); + + } +//OK button pressed OR Enter Hit + private void loginClicked(){ + errorSet=false; + try { + if (this.getUser().length()>0 && this.getPassword().length()>0) + userAgent = Gateway.connect(this.getUser(), this.getPassword()); + logged = (userAgent != null); + Logger.msg(7, "AbstractMain::standardSetUp() - Gateway.connect() OK."); + } + catch (InvalidDataException ex) { + String message = ex.getMessage(); + int i = ex.getMessage().indexOf(' '); + if (i > -1 ) message = message.substring(i); + //Here us elanguage translate I guess :) + //if (message.length()>65 && message.substring(1,5).compareTo("User")==0) + // message = (message.substring(1,50)+ "... not found" ); + this.errorLabel.setText(message); + logged= false; + errorSet=true; + } + if (!logged) { + Logger.msg("Login attempt "+loginAttemptNumber+" of "+maxNumberLogon+" failed"); + if (loginAttemptNumber>=maxNumberLogon) Logger.die("Login failure limit reached"); + if (!errorSet) this.errorLabel.setText(Language.translate("Please enter username & password")); +// int posx=xMov+120; +// int posy=yMov; +// if (posy<135) posy=135; +// float texstSize = errorLabel.getFont().getSize2D(); +// if (posx-xMov