/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * AdditionalLoginDialog.java * * Created on 7.12.2010, 10:48:35 */ package cz.cvut.fel.restauracefel.library.library_gui; import cz.cvut.fel.restauracefel.library.Enums.EnumLoginResult; import cz.cvut.fel.restauracefel.library.controller.CommonController; import javax.swing.JOptionPane; import javax.swing.JTextField; /** * * @author Vizi */ public class AdditionalLogin extends javax.swing.JDialog { private Keyboard keyboard; private JTextField actualTF; private String requestRight; private CommonController controller; /** Creates new form AdditionalLoginDialog */ public AdditionalLogin( java.awt.Frame parent, boolean modal, String requestRight) { super( parent, modal ); this.controller = CommonController.getInstance(); actualTF = jTextFieldUsername; keyboard = new Keyboard( null, actualTF ); this.requestRight = requestRight; this.setLocation( parent.getX( ) + ( parent.getWidth( ) / 2 ) - 300 , parent.getY( ) + ( parent.getHeight( ) / 2 ) - 150 ); this.add( keyboard ); initComponents( ); this.setVisible( true ); } /** 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. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabelInfo = new javax.swing.JLabel(); jPasswordField = new javax.swing.JPasswordField(); jTextFieldUsername = new javax.swing.JTextField(); jLabelPassword = new javax.swing.JLabel(); jButtonClose = new javax.swing.JButton(); jButtonLog = new javax.swing.JButton(); jLabelUsername = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jLabelInfo.setFont(new java.awt.Font("Tahoma", 1, 12)); jLabelInfo.setText("Přihlášení do systému RestauraceFEL"); jPasswordField.setText("1234"); jPasswordField.addFocusListener(new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { jPasswordFieldFocusGained(evt); } }); jTextFieldUsername.setText("NOVAK"); jTextFieldUsername.addFocusListener(new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { jTextFieldUsernameFocusGained(evt); } }); jLabelPassword.setText("Heslo"); jButtonClose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/cvut/fel/restauracefel/buttons/ko.png"))); // NOI18N jButtonClose.setText("Konec"); jButtonClose.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonCloseActionPerformed(evt); } }); jButtonLog.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/cvut/fel/restauracefel/buttons/ok.png"))); // NOI18N jButtonLog.setText("Přihlásit se"); jButtonLog.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonLogActionPerformed(evt); } }); jLabelUsername.setText("Uživatelské jméno"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(20, 20, 20) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jButtonClose, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jButtonLog, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jLabelPassword) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jLabelUsername) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextFieldUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE))))) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(jLabelInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addGap(25, 25, 25) .addComponent(jLabelInfo) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelUsername) .addComponent(jTextFieldUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(21, 21, 21) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelPassword) .addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(48, 48, 48) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButtonClose, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButtonLog, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(585, Short.MAX_VALUE) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void jPasswordFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jPasswordFieldFocusGained keyboard.setActualTF( jPasswordField ); actualTF = jPasswordField; }//GEN-LAST:event_jPasswordFieldFocusGained private void jTextFieldUsernameFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldUsernameFocusGained keyboard.setActualTF( jTextFieldUsername ); actualTF = jTextFieldUsername; }//GEN-LAST:event_jTextFieldUsernameFocusGained private void jButtonCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCloseActionPerformed this.setVisible( false ); }//GEN-LAST:event_jButtonCloseActionPerformed private void jButtonLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLogActionPerformed String username = jTextFieldUsername.getText( ); String password = String.copyValueOf( jPasswordField.getPassword( ) ); EnumLoginResult result = controller.additionalLogin( username, password, requestRight ); switch ( result ) { case LoginSuccesful: controller.setAdditionalUserAccessable( true ); keyboard.setVisible( false ); setVisible( false ); break; case WrongLoginData: controller.setAdditionalUserAccessable( false ); jTextFieldUsername.setText( "" ); jPasswordField.setText( "" ); JOptionPane.showMessageDialog( this, "Nesprávné uživatelské jméno nebo heslo", "Chyba", JOptionPane.ERROR_MESSAGE ); break; case ScantRights: controller.setAdditionalUserAccessable( false ); JOptionPane.showMessageDialog( this, "Nedostatečná práva", "Chyba", JOptionPane.ERROR_MESSAGE ); break; } }//GEN-LAST:event_jButtonLogActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButtonClose; private javax.swing.JButton jButtonLog; private javax.swing.JLabel jLabelInfo; private javax.swing.JLabel jLabelPassword; private javax.swing.JLabel jLabelUsername; private javax.swing.JPanel jPanel1; private javax.swing.JPasswordField jPasswordField; private javax.swing.JTextField jTextFieldUsername; // End of variables declaration//GEN-END:variables }