123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- /*
- * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
- package org.ownage.dmdirc.ui;
-
- import org.ownage.dmdirc.Server;
- import org.ownage.dmdirc.ServerManager;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.WindowEvent;
- import java.awt.event.WindowListener;
- import javax.swing.InputVerifier;
- import javax.swing.JComponent;
- import javax.swing.JTextField;
-
- /**
- * Dialog that allows the user to enter details of a new server to connect to
- * @author chris
- */
- public class NewServerDialog extends javax.swing.JDialog {
-
- /**
- * A previously created instance of NewServerDialog
- */
- private static NewServerDialog me;
-
- /**
- * Creates a new instance of the dialog
- */
- private NewServerDialog() {
- super((java.awt.Frame)MainFrame.getMainFrame(), false);
-
- initComponents();
-
- if (ServerManager.getServerManager().numServers() == 0) {
- jCheckBox1.setSelected(true);
- jCheckBox1.setEnabled(false);
- }
-
- jTextField2.setInputVerifier(new PortVerifier());
-
- addCallbacks();
-
- setVisible(true);
- }
-
- /**
- * Creates the new server dialog if one doesn't exist, and displays it.
- */
- public static void showNewServerDialog() {
- if (me == null) {
- me = new NewServerDialog();
- } else {
- me.setVisible(true);
- me.requestFocus();
- }
- }
-
- /**
- * Adds listeners for various objects in the dialog
- */
- private void addCallbacks() {
- jButton2.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent actionEvent) {
- NewServerDialog.this.setVisible(false);
- }
- });
- jButton1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent actionEvent) {
- String host = jTextField1.getText();
- String pass = jTextField3.getText();
- int port = Integer.parseInt(jTextField2.getText());
-
- // Open in a new window?
- if (jCheckBox1.isSelected()) {
- Server server = new Server(host, port, pass);
- } else {
-
- }
-
- NewServerDialog.this.setVisible(false);
- }
- });
- }
-
- /** 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() {
- jLabel1 = new javax.swing.JLabel();
- jTextField1 = new javax.swing.JTextField();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- jTextField2 = new javax.swing.JTextField();
- jLabel4 = new javax.swing.JLabel();
- jTextField3 = new javax.swing.JTextField();
- jCheckBox1 = new javax.swing.JCheckBox();
- jCheckBox2 = new javax.swing.JCheckBox();
- jCheckBox3 = new javax.swing.JCheckBox();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
-
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- setTitle("Connect to a new server");
- jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
- jLabel1.setText("Server:");
-
- jTextField1.setText("irc.quakenet.org");
-
- jLabel2.setText("To connect to a new IRC server, enter the server name below");
-
- jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
- jLabel3.setText("Port:");
-
- jTextField2.setText("6667");
-
- jLabel4.setText("Password:");
-
- jCheckBox1.setText("Open in a new server window");
- jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
- jCheckBox1.setMargin(new java.awt.Insets(0, 0, 0, 0));
-
- jCheckBox2.setText("Remember server password");
- jCheckBox2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
- jCheckBox2.setMargin(new java.awt.Insets(0, 0, 0, 0));
-
- jCheckBox3.setText("Connect to this server automatically in the future");
- jCheckBox3.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
- jCheckBox3.setMargin(new java.awt.Insets(0, 0, 0, 0));
-
- jButton1.setText("OK");
-
- jButton2.setText("Cancel");
-
- 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(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
- .add(layout.createSequentialGroup()
- .addContainerGap()
- .add(jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .add(layout.createSequentialGroup()
- .add(16, 16, 16)
- .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
- .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
- .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
- .add(layout.createSequentialGroup()
- .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 56, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
- .add(jLabel4)
- .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
- .add(jTextField3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE))
- .add(jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE)))
- .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
- .add(232, 232, 232)
- .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 76, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
- .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 76, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
- .add(layout.createSequentialGroup()
- .add(28, 28, 28)
- .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
- .add(jCheckBox2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)
- .add(jCheckBox1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)
- .add(jCheckBox3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE))))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
- .add(layout.createSequentialGroup()
- .addContainerGap()
- .add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
- .add(16, 16, 16)
- .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
- .add(jLabel1)
- .add(jTextField1, 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(jLabel3)
- .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
- .add(jLabel4)
- .add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
- .add(15, 15, 15)
- .add(jCheckBox1)
- .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
- .add(jCheckBox2)
- .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
- .add(jCheckBox3)
- .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 19, Short.MAX_VALUE)
- .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
- .add(jButton1)
- .add(jButton2))
- .addContainerGap())
- );
- pack();
- }// </editor-fold>//GEN-END:initComponents
-
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JCheckBox jCheckBox1;
- private javax.swing.JCheckBox jCheckBox2;
- private javax.swing.JCheckBox jCheckBox3;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JTextField jTextField1;
- private javax.swing.JTextField jTextField2;
- private javax.swing.JTextField jTextField3;
- // End of variables declaration//GEN-END:variables
-
- }
-
- /**
- * Verifies that the port number is a valid port
- */
- class PortVerifier extends InputVerifier {
-
- /**
- * Verifies that the number specified in the textfield is a valid port
- * @param jComponent The component to be tested
- * @return true iff the number is a valid port, false otherwise
- */
- public boolean verify(JComponent jComponent) {
- JTextField tf = (JTextField)jComponent;
- try {
- Integer port = Integer.parseInt(tf.getText());
- return (port > 0 && port <= 65535);
- } catch (Exception e) {
- return false;
- }
- }
-
- }
|