/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * ConnectionSettingsDialog.java * * Created on Jun 25, 2009, 8:49:30 PM */ package com.eas.client.login; import java.awt.Frame; import java.awt.event.ActionEvent; import java.util.ResourceBundle; import javax.swing.AbstractAction; import javax.swing.JOptionPane; /** * * @author pk, mg */ public class ConnectionSettingsEditor 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; private int returnStatus = RET_CANCEL; private static final ResourceBundle bundle = ResourceBundle.getBundle("com/eas/client/login/Bundle"); private final AddConnectionAction addConnectionAction = new AddConnectionAction(); /** * Creates new form ConnectionSettingsDialog * */ public ConnectionSettingsEditor() { super((Frame)null, true); initComponents(); tfConnectionUrl.requestFocus(); getRootPane().setDefaultButton(btnOk); } @Override public void setVisible(boolean b) { super.setVisible(b); } private void doClose(int retStatus) { returnStatus = retStatus; setVisible(false); dispose(); } /** * 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() { btnCancel = new javax.swing.JButton(); btnOk = new javax.swing.JButton(); tfName = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); tfConnectionUrl = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle(bundle.getString("ConnectionSettingsDialog.title")); // NOI18N setLocationByPlatform(true); btnCancel.setText(bundle.getString("Dialog.CancelButton.text")); // NOI18N btnCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCancelActionPerformed(evt); } }); btnOk.setAction(addConnectionAction); btnOk.setText(bundle.getString("Dialog.OKButton.text")); // NOI18N jLabel4.setLabelFor(tfName); jLabel4.setText(bundle.getString("ConnectionSettingsDialog.lblConnectionTitle.text")); // NOI18N jLabel1.setLabelFor(tfConnectionUrl); jLabel1.setText(bundle.getString("ConnectionSettingsDialog.lblConnectionUrl.text")); // NOI18N 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() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(tfName, javax.swing.GroupLayout.DEFAULT_SIZE, 313, Short.MAX_VALUE) .addComponent(tfConnectionUrl)) .addGap(10, 10, 10)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(284, Short.MAX_VALUE) .addComponent(btnOk, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnCancel) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel4) .addComponent(tfName, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(tfConnectionUrl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnCancel) .addComponent(btnOk)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// </editor-fold>//GEN-END:initComponents private void btnCancelActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnCancelActionPerformed {//GEN-HEADEREND:event_btnCancelActionPerformed doClose(RET_CANCEL); }//GEN-LAST:event_btnCancelActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnCancel; private javax.swing.JButton btnOk; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel4; private javax.swing.JTextField tfConnectionUrl; private javax.swing.JTextField tfName; // End of variables declaration//GEN-END:variables /** * @return the returnStatus */ public int getReturnStatus() { return returnStatus; } public String getUrl() { return tfConnectionUrl.getText().trim(); } public String getConnectionName() { return tfName.getText(); } public void setUrl(String url) { tfConnectionUrl.setText(url); } public void setConnectionName(String name) { tfName.setText(name); } private class AddConnectionAction extends AbstractAction { @Override public void actionPerformed(ActionEvent e) { String url = tfConnectionUrl.getText(); if (url != null) { url = url.trim(); } if (url.isEmpty()) { JOptionPane.showMessageDialog(ConnectionSettingsEditor.this, bundle.getString("ConnectionSettingsDialog.EmptyUrlMessage"), bundle.getString("ConnectionSettingsDialog.BadSettingsMessage"), JOptionPane.ERROR_MESSAGE); tfConnectionUrl.requestFocus(); } else { doClose(RET_OK); } } } }