📄 loginpanel.java
字号:
package openicq.gui;import java.awt.*;import java.awt.event.*;import java.util.Observable;import java.util.Observer;import javax.swing.*;import javax.swing.border.Border;import javax.swing.border.TitledBorder;import openicq.Start;import openicq.data.Default;import openicq.data.Resource;import openicq.management.Oscar;import openicq.management.Settings;import openicq.net.*;import org.javalib.dynamic.DynLoader;import org.javalib.dynamic.localize.Localization;import org.javalib.gui.SpringToolkit;import org.javalib.gui.WholeNumberField;import org.javalib.gui.image.ImageRotationPanel;import org.javalib.io.CryptFile;import org.javalib.io.FileSystemView;import org.javalib.util.MessageBuffer;import org.javalib.util.TitledList;import JOscarLib.Core.OscarConnection;import JOscarLib.Management.Contact;import JOscarLib.Management.ContactList;import JOscarLib.Setting.Enum.StatusModeEnum;import JOscarLib.Tool.OscarInterface;/** * The <code>LoginPanel</code> class is the basic panel for the login * procedure. * @author Hansgeorg Schwibbe * @copyright 2004 */public class LoginPanel extends JPanel{ private LoginFrame loginFrame; private Object[] fileData; protected JPanel jPanelAccount = new JPanel(); protected JPanel jPanelServer = new JPanel(); protected JPanel jPanelButton = new JPanel(); protected JLabel jLabelUserID = new JLabel(); protected JLabel jLabelPassword = new JLabel(); protected JLabel jLabelHost = new JLabel(); protected JLabel jLabelPort = new JLabel(); protected TitledBorder accountPanelBorder = new TitledBorder(""); protected TitledBorder serverPanelBorder = new TitledBorder(""); protected JTextField jTextFieldHost = new JTextField(); protected JComboBox jComboBoxUserID = new JComboBox(); protected WholeNumberField wholeNumberFieldPort = new WholeNumberField(); protected JPasswordField jPasswordField = new JPasswordField(); protected JCheckBox jCheckBoxAutoSave = new JCheckBox(); protected JCheckBox jCheckBoxAutoLogin = new JCheckBox(); protected JButton jButtonConnect = new JButton(); protected JButton jButtonCancel = new JButton(); protected ImageRotationPanel imageRotationPanel; private MessageBuffer errorMessageSave; /** * Initializes a new instance of the class <code>LoginPanel</code>. * @param parent the parent frame */ public LoginPanel(JFrame parent) { loginFrame = (LoginFrame) parent; // AccountPanel Object[] dirnames = FileSystemView.listDirNames(Default.FOLDER_NAME_HOME); for (int index = 0; index < dirnames.length; index++) { jComboBoxUserID.addItem(dirnames[index]); } int width = 135; int height = jComboBoxUserID.getPreferredSize().height; jComboBoxUserID.setEditable(true); jComboBoxUserID.setPreferredSize(new Dimension(width, height)); jPasswordField.setPreferredSize(new Dimension(width, height)); jPasswordField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { action_connectToServer(); } }); jCheckBoxAutoSave.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { action_selectCheckBoxAutoSave(); } }); jPanelAccount.setBorder(accountPanelBorder); jPanelAccount.setLayout(new SpringLayout()); jPanelAccount.add(jLabelUserID); jPanelAccount.add(jComboBoxUserID); jPanelAccount.add(jLabelPassword); jPanelAccount.add(jPasswordField); jPanelAccount.add(jCheckBoxAutoSave); SpringToolkit.makeCompactGrid(jPanelAccount, 5, 1, 5, 0, 5, 5); // ServerPanel jPanelServer.setBorder(serverPanelBorder); jTextFieldHost.setBackground(this.getBackground()); jTextFieldHost.setPreferredSize(new Dimension(width, height)); jTextFieldHost.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { action_connectToServer(); } }); wholeNumberFieldPort.setBackground(this.getBackground()); wholeNumberFieldPort.setPreferredSize(new Dimension(width, height)); wholeNumberFieldPort.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { action_connectToServer(); } }); jCheckBoxAutoLogin.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { action_selectCheckBoxAutoLogin(); } }); jPanelServer.setBorder(serverPanelBorder); jPanelServer.setLayout(new SpringLayout()); jPanelServer.add(jLabelHost); jPanelServer.add(jTextFieldHost); jPanelServer.add(jLabelPort); jPanelServer.add(wholeNumberFieldPort); jPanelServer.add(jCheckBoxAutoLogin); SpringToolkit.makeCompactGrid(jPanelServer, 5, 1, 5, 0, 5, 5); // ButtonPanel imageRotationPanel = new ImageRotationPanel(Resource.ICON_SOURCE_LOGIN, 1, 250); imageRotationPanel.setBackground(this.getBackground()); jButtonConnect.setFocusable(false); jButtonConnect.setPreferredSize(new Dimension(135, 27)); jButtonConnect.setBorder(BorderFactory.createRaisedBevelBorder()); jButtonConnect.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { action_connectToServer(); } }); jButtonCancel.setFocusable(false); jButtonCancel.setPreferredSize(new Dimension(135, 27)); jButtonCancel.setBorder(BorderFactory.createRaisedBevelBorder()); jButtonCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { action_cancelConnection(); } }); jPanelButton.setLayout(new FlowLayout(FlowLayout.LEFT)); jPanelButton.add(imageRotationPanel); jPanelButton.add(jButtonConnect); jPanelButton.add(jButtonCancel); // This panel this.setLayout(new BorderLayout()); this.add(jPanelAccount, BorderLayout.WEST); this.add(jPanelServer, BorderLayout.CENTER); this.add(jPanelButton, BorderLayout.SOUTH); Border innerBorder = BorderFactory.createLoweredBevelBorder(); Border outerBorder = BorderFactory.createEmptyBorder(3, 3, 1, 3); setBorder(BorderFactory.createCompoundBorder(innerBorder, outerBorder)); showUserID(); showUserData(); KeyListener keyListn = new KeyListener() { public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { synchronized (Start.env) { String item = String.valueOf(jComboBoxUserID.getEditor().getItem()); if (!Start.env.getOwnContact().getContactId().equals(item)) { setUserID(); showUserData(); loginFrame.localize(); } else if (e.getKeyCode() == 10) { action_connectToServer(); } } } public void keyTyped(KeyEvent e) { } }; this.jComboBoxUserID.getEditor() .getEditorComponent() .addKeyListener(keyListn); jComboBoxUserID.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { synchronized (Start.env) { String item = String.valueOf(jComboBoxUserID.getEditor().getItem()); if (!Start.env.getOwnContact().getContactId().equals(item)) { setUserID(); showUserData(); loginFrame.localize(); } } } }); synchronized (Start.env) { if (Start.env.getSecurityLevel() > Settings.MEDIUM_SECURITY) { this.jCheckBoxAutoLogin.setEnabled(false); this.jCheckBoxAutoSave.setEnabled(false); this.jPasswordField.setText(""); } this.jButtonCancel.setEnabled(false); if (Start.env.getLoginMode() == Oscar.AUTOLOGIN && Start.env.getSecurityLevel() != Settings.HIGH_SECURITY) { action_connectToServer(); } } } /** * Action 'Cancel the connection'. */ protected synchronized void action_cancelConnection() { synchronized (Start.env) { if (Start.env.getConnection() != null && !Start.env.getConnection().isLogged()) { try { Start.env.getConnection().close(); } catch (Exception ex) { System.err.println(this.getClass().getName() + ": " + ex.toString()); } Start.env.setConnection(null); imageRotationPanel.stopImageRotation(); try { Thread.sleep(1000); } catch (Exception ex) { System.err.println(this.getClass().getName() + ": " + ex.toString()); } jComboBoxUserID.setEnabled(true); jPasswordField.setEnabled(true); jTextFieldHost.setEnabled(true); wholeNumberFieldPort.setEnabled(true); showLoginMode(); jButtonConnect.setEnabled(true); jButtonCancel.setEnabled(false); } } } /** * Action 'Connect to the server'. */ protected synchronized void action_connectToServer() { String msg, title; synchronized (Start.env) { final TitledList localized = Start.env.getLocalizedList(); int value = ((String) jComboBoxUserID.getEditor().getItem()).length(); if (value < 1) { msg = ((String[]) localized.get("errorMessages"))[19]; title = ((String[]) localized.get("messageTitles"))[0]; JOptionPane.showMessageDialog(loginFrame, msg, title, JOptionPane.ERROR_MESSAGE); return; } if (jTextFieldHost.getText().equals("")) { msg = ((String[]) localized.get("errorMessages"))[20]; title = ((String[]) localized.get("messageTitles"))[0]; JOptionPane.showMessageDialog(loginFrame, msg, title, JOptionPane.ERROR_MESSAGE); return; } if (wholeNumberFieldPort.getValue() < 1 || wholeNumberFieldPort.getValue() > 65535) { msg = ((String[]) localized.get("errorMessages"))[2]; title = ((String[]) localized.get("messageTitles"))[0]; JOptionPane.showMessageDialog(loginFrame, msg, title, JOptionPane.ERROR_MESSAGE); return; } this.jComboBoxUserID.setEnabled(false); this.jPasswordField.setEnabled(false); this.jTextFieldHost.setEnabled(false); this.wholeNumberFieldPort.setEnabled(false); this.jCheckBoxAutoLogin.setEnabled(false); this.jCheckBoxAutoSave.setEnabled(false); this.jButtonConnect.setEnabled(false); setUserData(); imageRotationPanel.startImageRotation(); String host = jTextFieldHost.getText(); int port = (int) wholeNumberFieldPort.getValue(); String userId = String.valueOf(jComboBoxUserID.getEditor().getItem()); String password = String.valueOf(jPasswordField.getPassword()); Start.env.setConnection(new OscarConnection(host, port, userId, password)); Start.env.getConnection().addObserver(new Observer() { public void update(Observable obs, Object obj) { String path, msg, title; jButtonCancel.setEnabled(false); synchronized (Start.env) { int ownId = Integer.parseInt(Start.env.getOwnContact() .getContactId()); loginFrame.jMenuItemExit.setEnabled(false); try { path = Default.FOLDER_NAME_HOME + "/" + Start.env.getOwnContact().getContactId() + "/" + Default.FILE_NAME_KNOWN_LIST; Start.env.setKnownList(Start.env.loadContactList(path)); } catch (Exception ex) { System.err.println(this.getClass().getName() + ": " + ex.toString()); } ContactList updateList = new ContactList(); Contact contact; int size = Start.env.getKnownList().getContactListSize(); for (int i = 0; i < size; i++) { contact = Start.env.getKnownList().get(i); if (contact.getIsInVisibleList()) { updateList.addToContactList(contact);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -