/* * Copyright (C) 2008 Universidade Federal de Campina Grande * * This file is part of OurGrid. * * OurGrid is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.ourgrid.peer.ui.async.gui; import javax.swing.JOptionPane; import org.ourgrid.peer.ui.async.util.XMPPUtils; /** * AddXMPPUserDialog provides a simple mechanism for the user to add a XMPP User. * @author thiago */ public class AddXMPPUserDialog extends javax.swing.JDialog { /** A return status code - returned if Cancel button has been pressed */ public static final int RET_CANCEL = 0; /** A return status code - returned if OK button has been pressed */ public static final int RET_OK = 1; /** Creates new form AddXMPPUserDialog */ public AddXMPPUserDialog(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); } /** @return the return status of this dialog - one of RET_OK or RET_CANCEL */ public int getReturnStatus() { return returnStatus; } /** 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() { okButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); xMPPUserRegistrationPanel1 = new org.ourgrid.peer.ui.async.gui.XMPPUserRegistrationPanel(); setTitle("Add XMPP user"); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { closeDialog(evt); } }); okButton.setText("OK"); okButton.setName("OK"); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonActionPerformed(evt); } }); cancelButton.setText("Cancel"); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(evt); } }); 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() .addContainerGap(272, Short.MAX_VALUE) .add(okButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 67, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(cancelButton) .addContainerGap()) .add(xMPPUserRegistrationPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE) ); layout.linkSize(new java.awt.Component[] {cancelButton, okButton}, org.jdesktop.layout.GroupLayout.HORIZONTAL); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() .add(xMPPUserRegistrationPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(cancelButton) .add(okButton)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents /** * Confirms the addition of a new XMPP User. * @param evt The event the represents the clicking of the ok button. */ private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed String password = new String(xMPPUserRegistrationPanel1.getPassword()); String retype = new String(xMPPUserRegistrationPanel1.getRetypePassword()); if (!password.equals(retype)) { JOptionPane.showMessageDialog(null, "Wrong password", "Wrong password", JOptionPane.ERROR_MESSAGE); return; } try { new XMPPUtils().addUser( xMPPUserRegistrationPanel1.getServer(), xMPPUserRegistrationPanel1.getUser(), password, xMPPUserRegistrationPanel1.getPort(), xMPPUserRegistrationPanel1.getSecurePort()); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage(), "Error on creating user", JOptionPane.ERROR_MESSAGE); return; } doClose(RET_OK); }//GEN-LAST:event_okButtonActionPerformed /** * Cancel and close this dialog. * @param evt The event the represents the clicking of the cancel button. */ private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed doClose(RET_CANCEL); }//GEN-LAST:event_cancelButtonActionPerformed /** Closes this dialog */ private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog doClose(RET_CANCEL); }//GEN-LAST:event_closeDialog /** * Close this dialog using the status provided. * @param retStatus The status of this dialog. */ private void doClose(int retStatus) { returnStatus = retStatus; setVisible(false); dispose(); } /** * Main method. * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { AddXMPPUserDialog dialog = new AddXMPPUserDialog(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton cancelButton; private javax.swing.JButton okButton; private org.ourgrid.peer.ui.async.gui.XMPPUserRegistrationPanel xMPPUserRegistrationPanel1; // End of variables declaration//GEN-END:variables private int returnStatus = RET_CANCEL; }