// Copyright 2004-2014 Jim Voris
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package com.qumasoft.guitools.admin;
import com.qumasoft.guitools.AbstractQVCSCommandDialog;
/**
* The server login dialog. Used for logging in to a server.
*
* @author Jim Voris
*/
public class ServerLoginDialog extends AbstractQVCSCommandDialog {
private static final long serialVersionUID = 838997264673347172L;
private String password = null;
private String userNameString = null;
/**
* Creates new form ServerLoginDialog.
*
* @param parent the parent frame.
* @param modal is this to be a modal dialog.
* @param serverName the name of the server.
*/
public ServerLoginDialog(java.awt.Frame parent, boolean modal, String serverName) {
super(parent, modal);
initComponents();
// Make the OK button work with the return key.
getRootPane().setDefaultButton(okButton);
serverNameValue.setText(serverName);
// Center the dialog.
center();
}
/**
* 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() {
serverNameLabel = new javax.swing.JLabel();
serverNameValue = new javax.swing.JLabel();
serverPasswordLabel = new javax.swing.JLabel();
serverPasswordField = new javax.swing.JPasswordField();
okButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
userNameLabel = new javax.swing.JLabel();
userNameField = new javax.swing.JTextField();
setTitle("Login To Server");
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
serverNameLabel.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
serverNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
serverNameLabel.setText("Login to server:");
serverNameValue.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
serverNameValue.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
serverNameValue.setText("Server Name:");
serverNameValue.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
serverPasswordLabel.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
serverPasswordLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
serverPasswordLabel.setText("Password:");
serverPasswordField.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
okButton.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
okButton.setText(" OK ");
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
cancelButton.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
userNameLabel.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
userNameLabel.setText("User Name:");
userNameField.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(12, 12, 12)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(serverNameLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 300, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(serverNameValue, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 300, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(userNameLabel)
.add(userNameField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 300, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(serverPasswordLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 300, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(layout.createSequentialGroup()
.add(6, 6, 6)
.add(okButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(cancelButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(serverPasswordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 300, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(15, 15, 15))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(12, 12, 12)
.add(serverNameLabel)
.add(4, 4, 4)
.add(serverNameValue)
.add(12, 12, 12)
.add(userNameLabel)
.add(6, 6, 6)
.add(userNameField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(4, 4, 4)
.add(serverPasswordLabel)
.add(6, 6, 6)
.add(serverPasswordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(okButton)
.add(cancelButton))
.addContainerGap(13, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void okButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_okButtonActionPerformed
{//GEN-HEADEREND:event_okButtonActionPerformed
// Get the password.
char[] passwordFromDialog = serverPasswordField.getPassword();
this.password = new String(passwordFromDialog);
this.userNameString = userNameField.getText();
// If both have been selected, then OK can dismiss the dialog.
if (this.userNameString.length() > 0 && this.password.length() > 0) {
closeDialog(null);
}
}//GEN-LAST:event_okButtonActionPerformed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cancelButtonActionPerformed
{//GEN-HEADEREND:event_cancelButtonActionPerformed
this.password = null;
closeDialog(null);
}//GEN-LAST:event_cancelButtonActionPerformed
/**
* Closes the dialog
*/
private void closeDialog(java.awt.event.WindowEvent evt)
{//GEN-FIRST:event_closeDialog
setVisible(false);
dispose();
}//GEN-LAST:event_closeDialog
@Override
public void dismissDialog() {
cancelButtonActionPerformed(null);
}
public String getPassword() {
return this.password;
}
public String getUserName() {
return this.userNameString;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JButton okButton;
private javax.swing.JLabel serverNameLabel;
private javax.swing.JLabel serverNameValue;
private javax.swing.JPasswordField serverPasswordField;
private javax.swing.JLabel serverPasswordLabel;
private javax.swing.JTextField userNameField;
private javax.swing.JLabel userNameLabel;
// End of variables declaration//GEN-END:variables
}