📄 alogin.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.apps;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;
import java.util.*;
import java.text.*;
import org.apache.log4j.*;
import org.compiere.Compiere;
import org.compiere.db.*;
import org.compiere.util.*;
import org.compiere.grid.ed.*;
import org.compiere.plaf.*;
import org.compiere.swing.*;
import org.compiere.print.*;
/**
* Application Login Window
*
* @author Jorg Janke
* @version $Id: ALogin.java,v 1.43 2003/01/20 05:39:38 jjanke Exp $
*/
public final class ALogin extends JDialog
implements ActionListener, ChangeListener
{
/**
* Construct the dialog.
* Need to call initLogin for dynamic start
* @param parent parent
*/
public ALogin(Frame parent)
{
super (parent, "Login", true); // Modal
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
m_WindowNo = Env.createWindowNo (null);
res = ResourceBundle.getBundle(RESOURCE);
//
try
{
jbInit();
}
catch(Exception e)
{
System.out.println(e.toString());
}
// Focus
this.setFocusTraversalPolicy(AFocusTraversalPolicy.get());
this.getRootPane().setDefaultButton(confirmPanel.getOKButton());
} // ALogin
/**
* Set Initial & Ini Parameters
* Optional Automatic login
* @return true, if connected & parameters set
*/
public boolean initLogin()
{
m_cc = CConnection.get();
hostField.setValue(m_cc);
validateConnection ();
// Application/PWD
userTextField.setText(Ini.getProperty(Ini.P_UID));
if (Ini.getPropertyBool(Ini.P_STORE_PWD))
passwordField.setText(Ini.getProperty(Ini.P_PWD));
else
passwordField.setText("");
//
languageCombo.setSelectedItem(Ini.getProperty(Ini.P_LANGUAGE));
languageComboChanged(); // initial language setting
// Other
Env.setAutoCommit(m_ctx, Ini.getPropertyBool(Ini.P_A_COMMIT));
Env.setContext(m_ctx, "#CompiereSys", Ini.getProperty(Ini.P_COMPIERESYS));
Env.setContext(m_ctx, "#ShowAcct", Ini.getProperty(Ini.P_SHOW_ACCT));
Env.setContext(m_ctx, "#ShowTrl", Ini.getProperty(Ini.P_SHOW_TRL));
// AutoLogin - assumes that connection is OK
if (Ini.getPropertyBool(Ini.P_A_LOGIN))
{
connectionOK ();
defaultsOK ();
return m_connectionOK;
}
return false;
} // initLogin
/**
* Window Events - requestFocus
* @param e event
*/
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_OPENED)
{
this.toFront();
confirmPanel.getOKButton().requestFocusInWindow();
}
} // processWindowEvent
/**
* Validate Connection
*/
private void validateConnection()
{
m_connectionOK = false;
Logger root = Logger.getRootLogger();
Level level = root.getLevel();
root.setLevel(Level.OFF);
//
m_cc.testAppsServer();
m_cc.testDatabase();
//
Logger.getRootLogger().setLevel(level);
hostField.setDisplay();
} // validateConnection
protected static final String RESOURCE = "org.compiere.apps.ALoginRes";
private static ResourceBundle res = ResourceBundle.getBundle(RESOURCE);
private CPanel mainPanel = new CPanel(new BorderLayout());
private CTabbedPane loginTabPane = new CTabbedPane();
private BorderLayout conTabLayout = new BorderLayout();
private CPanel connectionPanel = new CPanel();
private CLabel hostLabel = new CLabel();
private CConnectionEditor hostField = new CConnectionEditor();
private CLabel userLabel = new CLabel();
private JTextField userTextField = new JTextField();
private CLabel passwordLabel = new CLabel();
private JPasswordField passwordField = new JPasswordField();
private CPanel defaultPanel = new CPanel();
private BorderLayout defaultLayout = new BorderLayout();
private CLabel clientLabel = new CLabel();
private CLabel orgLabel = new CLabel();
private CLabel dateLabel = new CLabel();
private VDate dateField = new VDate(DisplayType.Date);
private VComboBox orgCombo = new VComboBox();
private VComboBox clientCombo = new VComboBox();
private CLabel warehouseLabel = new CLabel();
private VComboBox warehouseCombo = new VComboBox();
private CLabel printerLabel = new CLabel();
private CPrinter printerField = new CPrinter();
private CLabel roleLabel = new CLabel();
private VComboBox roleCombo = new VComboBox();
private CLabel copy0Label = new CLabel();
private CLabel titleLabel = new CLabel();
private CLabel versionLabel = new CLabel();
private CLabel copy1Label = new CLabel();
private GridBagLayout connectionLayout = new GridBagLayout();
private GridBagLayout defaultPanelLayout = new GridBagLayout();
private CLabel languageLabel = new CLabel();
private VComboBox languageCombo = new VComboBox(Language.getNames());
private CLabel compileDate = new CLabel();
private CPanel southPanel = new CPanel();
private BorderLayout southLayout = new BorderLayout();
private StatusBar statusBar = new StatusBar();
private ConfirmPanel confirmPanel = new ConfirmPanel(true, false, false, false, false, false);
private OnlineHelp onlineHelp = new OnlineHelp(true);
private JPanel helpPanel = new JPanel();
private JScrollPane helpScollPane = new JScrollPane();
private BorderLayout helpLayout = new BorderLayout();
/** Server Connection */
private CConnection m_cc;
/** Application User */
private String m_user;
/** Application Password */
private String m_pwd;
private boolean m_connectionOK = false;
private int m_WindowNo;
private Properties m_ctx = Env.getCtx();
//
/*************************************************************************/
/**
* Component initialization
* @throws Exception
*/
private void jbInit() throws Exception
{
this.setName("Login");
CompiereColor.setBackground(this);
titleLabel.setFont(new java.awt.Font("Serif", 2, 10));
titleLabel.setForeground(Color.blue);
titleLabel.setRequestFocusEnabled(false);
titleLabel.setToolTipText(Compiere.getURL());
titleLabel.setHorizontalTextPosition(SwingConstants.CENTER);
titleLabel.setIcon(Compiere.getImageIconLogo());
titleLabel.setText(Compiere.getSubtitle());
titleLabel.setVerticalTextPosition(SwingConstants.BOTTOM);
versionLabel.setRequestFocusEnabled(false);
versionLabel.setHorizontalAlignment(SwingConstants.RIGHT);
versionLabel.setHorizontalTextPosition(SwingConstants.RIGHT);
hostLabel.setRequestFocusEnabled(false);
hostLabel.setLabelFor(hostField);
hostField.addActionListener(this);
userLabel.setRequestFocusEnabled(false);
userLabel.setLabelFor(userTextField);
passwordLabel.setRequestFocusEnabled(false);
passwordLabel.setLabelFor(passwordField);
languageLabel.setLabelFor(languageCombo);
copy0Label.setFont(new java.awt.Font("Serif", 2, 10));
copy0Label.setForeground(Color.blue);
copy0Label.setRequestFocusEnabled(false);
copy1Label.setRequestFocusEnabled(false);
roleLabel.setRequestFocusEnabled(false);
roleLabel.setLabelFor(roleCombo);
clientLabel.setRequestFocusEnabled(false);
orgLabel.setRequestFocusEnabled(false);
dateLabel.setRequestFocusEnabled(false);
warehouseLabel.setRequestFocusEnabled(false);
printerLabel.setRequestFocusEnabled(false);
compileDate.setHorizontalAlignment(SwingConstants.RIGHT);
compileDate.setHorizontalTextPosition(SwingConstants.RIGHT);
compileDate.setText(Compiere.DATE_VERSION);
compileDate.setToolTipText(Compiere.getImplementationVendor());
southPanel.setLayout(southLayout);
loginTabPane.addChangeListener(this);
// ConnectionTab
connectionPanel.setLayout(connectionLayout);
//
titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
versionLabel.setText(Compiere.MAIN_VERSION);
versionLabel.setToolTipText(Compiere.getImplementationVersion());
hostLabel.setHorizontalAlignment(SwingConstants.RIGHT);
hostLabel.setText("Host");
connectionPanel.add(hostLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0));
connectionPanel.add(hostField, new GridBagConstraints(1, 2, 3, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 12), 0, 0));
userLabel.setHorizontalAlignment(SwingConstants.RIGHT);
userLabel.setText("User");
connectionPanel.add(userLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0));
userTextField.setText("System"); // default
connectionPanel.add(userTextField, new GridBagConstraints(1, 3, 3, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 12), 0, 0));
passwordLabel.setHorizontalAlignment(SwingConstants.RIGHT);
passwordLabel.setText("Password");
connectionPanel.add(passwordLabel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
passwordField.setText("System"); // default
connectionPanel.add(passwordField, new GridBagConstraints(1, 4, 3, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 12), 0, 0));
languageLabel.setHorizontalAlignment(SwingConstants.RIGHT);
languageLabel.setText("Language");
connectionPanel.add(languageLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0));
languageCombo.addActionListener(this);
connectionPanel.add(languageCombo, new GridBagConstraints(1, 5, 3, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 12), 0, 0));
copy0Label.setHorizontalAlignment(SwingConstants.RIGHT);
connectionPanel.add(copy0Label, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
copy1Label.setText(Compiere.COPYRIGHT);
connectionPanel.add(copy1Label, new GridBagConstraints(1, 6, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 12, 12), 0, 0));
connectionPanel.add(compileDate, new GridBagConstraints(2, 1, 2, 1, 0.0, 0.0
,GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(2, 0, 0, 12), 0, 0));
connectionPanel.add(titleLabel, new GridBagConstraints(0, 0, 2, 2, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(12, 12, 5, 5), 0, 0));
connectionPanel.add(versionLabel, new GridBagConstraints(2, 0, 2, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(12, 5, 0, 12), 0, 0));
loginTabPane.add(connectionPanel, res.getString("Connection"));
// DefaultTab
defaultPanel.setLayout(defaultPanelLayout);
//
roleLabel.setText("Role");
roleLabel.setHorizontalAlignment(SwingConstants.RIGHT);
roleCombo.addActionListener(this);
defaultPanel.add(roleLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(12, 12, 5, 5), 0, 0));
defaultPanel.add(roleCombo, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(12, 0, 5, 12), 0, 0));
clientLabel.setText("Client");
clientLabel.setHorizontalAlignment(SwingConstants.RIGHT);
clientCombo.addActionListener(this);
defaultPanel.add(clientLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0));
defaultPanel.add(clientCombo, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 12), 0, 0));
orgLabel.setText("Organization");
orgLabel.setHorizontalAlignment(SwingConstants.RIGHT);
defaultPanel.add(orgLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
defaultPanel.add(orgCombo, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 12), 0, 0));
dateLabel.setText("Date");
dateLabel.setHorizontalAlignment(SwingConstants.RIGHT);
defaultPanel.add(dateLabel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0));
defaultPanel.add(dateField, new GridBagConstraints(1, 4, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 12), 0, 0));
//
warehouseLabel.setText("Warehouse");
warehouseLabel.setHorizontalAlignment(SwingConstants.RIGHT);
printerLabel.setText("Printer");
printerLabel.setHorizontalAlignment(SwingConstants.RIGHT);
defaultPanel.add(printerLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 12, 5), 0, 0));
defaultPanel.add(printerField, new GridBagConstraints(1, 5, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 12, 12), 0, 0));
defaultPanel.add(warehouseLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0));
defaultPanel.add(warehouseCombo, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 12), 0, 0));
//
loginTabPane.add(defaultPanel, res.getString("Defaults"));
// Help
helpPanel.setLayout(helpLayout);
helpPanel.setPreferredSize(new Dimension (100,100));
helpPanel.add(helpScollPane, BorderLayout.CENTER);
loginTabPane.add(helpPanel, "?");
//
this.getContentPane().add(mainPanel);
mainPanel.add(loginTabPane, BorderLayout.CENTER);
mainPanel.setName("loginMainPanel");
mainPanel.add(southPanel, BorderLayout.SOUTH);
//
southPanel.add(confirmPanel, BorderLayout.NORTH);
southPanel.add(statusBar, BorderLayout.SOUTH);
helpScollPane.getViewport().add(onlineHelp, null);
confirmPanel.addActionListener(this);
statusBar.setStatusDB(null);
} // jbInit
/*************************************************************************
* Exit action performed
*/
private void appExit()
{
m_connectionOK = false;
dispose();
} // appExit_actionPerformed
/**
* Return true, if logged in
* @return true if connected
*/
public boolean isConnected()
{
return m_connectionOK;
} // isConnected
/*************************************************************************/
/**
* Action Event handler
* @param e event
*/
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals(ConfirmPanel.A_OK))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -