//$Header: /cvsroot-fuse/mec-as2/39/mendelson/util/clientserver/gui/JDialogLogin.java,v 1.1 2012/04/18 14:10:44 heller Exp $ package de.mendelson.util.clientserver.gui; import de.mendelson.util.MecResourceBundle; import java.awt.Color; import java.awt.KeyEventDispatcher; import java.awt.KeyboardFocusManager; import java.awt.event.KeyEvent; import java.util.MissingResourceException; import java.util.ResourceBundle; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JRootPane; /* * Copyright (C) mendelson-e-commerce GmbH Berlin Germany * * This software is subject to the license agreement set forth in the license. * Please read and agree to all terms before using this software. * Other product and brand names are trademarks of their respective owners. */ /** * Login dialog for server authentication * @author S.Heller * @version $Revision: 1.1 $ */ public class JDialogLogin extends JDialog { private boolean cancel = false; private char[] pass = null; private String user = null; private MecResourceBundle rb = null; /** Creates new form JDialogPassword */ public JDialogLogin(JFrame parent, String infoText) { super(parent, true); //load resource bundle try { this.rb = (MecResourceBundle) ResourceBundle.getBundle( ResourceBundleLogin.class.getName()); } catch (MissingResourceException e) { throw new RuntimeException("Oops..resource bundle " + e.getClassName() + " not found."); } initComponents(); if (infoText != null) { this.jLabelInfo.setText(infoText); } this.getRootPane().setDefaultButton(this.jButtonOk); KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() { @Override public boolean dispatchKeyEvent(KeyEvent e) { if (e.getID() == KeyEvent.KEY_PRESSED) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { jButtonCancel.doClick(); } } return false; } }); } /**Sets a color to this dialog*/ public void setColor(Color backgroundColor, Color foregroundColor) { this.jPanelGradient.setUI(new JPanelGradientUI(backgroundColor, 1f)); this.jLabelInfo.setForeground(foregroundColor); } public void setDefaultUser(String defaultUser) { this.jTextFieldUser.setText(defaultUser); if (defaultUser != null && defaultUser.length() > 0) { this.jTextFieldUser.setSelectionStart(0); this.jTextFieldUser.setSelectionEnd(defaultUser.length()); } } public boolean isCanceled() { return cancel; } public char[] getPass() { return (this.pass); } public String getUser() { return (this.user); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; jPanelMain = new javax.swing.JPanel(); jPasswordField = new javax.swing.JPasswordField(); jTextFieldUser = new javax.swing.JTextField(); jLabelUser = new javax.swing.JLabel(); jLabelPasswd = new javax.swing.JLabel(); jPanelGradient = new javax.swing.JPanel(); jLabelInfo = new javax.swing.JLabel(); jPanelButtons = new javax.swing.JPanel(); jButtonOk = new javax.swing.JButton(); jButtonCancel = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); setTitle(this.rb.getResourceString( "title.login")); setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); setResizable(false); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosed(java.awt.event.WindowEvent evt) { formWindowClosed(evt); } }); getContentPane().setLayout(new java.awt.GridBagLayout()); jPanelMain.setLayout(new java.awt.GridBagLayout()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); jPanelMain.add(jPasswordField, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); jPanelMain.add(jTextFieldUser, gridBagConstraints); jLabelUser.setText(this.rb.getResourceString( "label.user" )); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); jPanelMain.add(jLabelUser, gridBagConstraints); jLabelPasswd.setText(this.rb.getResourceString( "label.passwd" )); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); jPanelMain.add(jLabelPasswd, gridBagConstraints); jPanelGradient.setLayout(new java.awt.GridBagLayout()); jLabelInfo.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jLabelInfo.setText("Server login"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = 2; gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); jPanelGradient.add(jLabelInfo, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 5, 15, 5); jPanelMain.add(jPanelGradient, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(jPanelMain, gridBagConstraints); jPanelButtons.setLayout(new java.awt.GridBagLayout()); jButtonOk.setText(this.rb.getResourceString( "button.ok" )); jButtonOk.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonOkActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); jPanelButtons.add(jButtonOk, gridBagConstraints); jButtonCancel.setText(this.rb.getResourceString( "button.cancel" )); jButtonCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonCancelActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); jPanelButtons.add(jButtonCancel, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(jPanelButtons, gridBagConstraints); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setBounds((screenSize.width-355)/2, (screenSize.height-221)/2, 355, 221); }// </editor-fold>//GEN-END:initComponents private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed this.cancel = true; }//GEN-LAST:event_formWindowClosed private void jButtonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOkActionPerformed this.pass = this.jPasswordField.getPassword(); this.user = this.jTextFieldUser.getText(); this.setVisible(false); }//GEN-LAST:event_jButtonOkActionPerformed private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed this.cancel = true; this.setVisible(false); }//GEN-LAST:event_jButtonCancelActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButtonCancel; private javax.swing.JButton jButtonOk; private javax.swing.JLabel jLabelInfo; private javax.swing.JLabel jLabelPasswd; private javax.swing.JLabel jLabelUser; private javax.swing.JPanel jPanelButtons; private javax.swing.JPanel jPanelGradient; private javax.swing.JPanel jPanelMain; private javax.swing.JPasswordField jPasswordField; private javax.swing.JTextField jTextFieldUser; // End of variables declaration//GEN-END:variables }