Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/jabbee/ui/dialogs/AddClientPort.java


1   /*
2    * AddAdmin.java
3    *
4    * Created on October 25, 2002, 8:47 AM
5    *
6    *
7    * License:
8    *
9    * The contents of this file are subject to the Jabber Open Source
10   * License Version 1.0 (the "License"). You may not copy or use this
11   * file, in either source code or executable form, except in compliance
12   * with the License. You may obtain a copy of the License at
13   * http://www.jabber.com/license/ or at http://www.opensource.org/.
14   * Software distributed under the License is distributed on an "AS IS" 
15   * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
16   * the License for the specific language governing rights and limitations
17   * under the License.
18   *
19   * Copyrights:
20   *
21   * Portions created by or assigned to Jabber.com, Inc. are Copyright
22   * (c) 1999-2000 Jabber.com, Inc. All Rights Reserved. Contact information
23   * for Jabber.com, Inc. is available at http://www.jabber.com/. Portions
24   * Copyright (c) 1998-1999 Jeremie Miller.
25   *
26   * Acknowledgements:
27   *
28   * Special thanks to the Jabber Open Source Contributors for their
29   * suggestions and support of Jabber.
30   *
31   */
32  
33  package org.jabbee.ui.dialogs;
34  
35  import java.awt.event.KeyEvent;
36  import java.awt.event.KeyListener;
37  
38  /** Dialog which allows user to specifiy listening ports for Jabber clients 
39   *  connecting to the Jabber server.
40   *
41   * @author  Gregory Kaczmarczyk
42   *
43   * @version 0.01
44   */
45  public final class AddClientPort extends javax.swing.JDialog implements KeyListener {
46      /** A return status code - returned if Cancel button has been pressed */
47      public static final int RET_CANCEL = 0;
48      /** A return status code - returned if OK button has been pressed */
49      public static final int RET_OK = 1;
50      /**  Port number */
51      public String port = "";
52      /** IP Address of the connecting port */
53      public String ipAddress = "";
54      /**  Port type - true for IP, false for SSL */
55      public boolean typeIP = true;
56      
57      /** Creates new form AddAdmin */
58      public AddClientPort(java.awt.Frame parent, boolean modal) {
59          super(parent, modal);
60          setResizable(false);
61          initComponents();
62  
63          getRootPane().setDefaultButton(okButton);
64  
65          java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
66          this.setLocation(screenSize.width/2 - (this.getPreferredSize().width/2), screenSize.height/2 - (this.getPreferredSize().height/2));
67      }
68      
69      /** @return the return status of this dialog - one of RET_OK or RET_CANCEL */
70      public int getReturnStatus() {
71          return returnStatus;
72      }
73      
74      /** This method is called from within the constructor to
75       * initialize the form.
76       * WARNING: Do NOT modify this code. The content of this method is
77       * always regenerated by the Form Editor.
78       */
79      private void initComponents() {//GEN-BEGIN:initComponents
80          java.awt.GridBagConstraints gridBagConstraints;
81  
82          typeButtonGroup = new javax.swing.ButtonGroup();
83          infoPanel = new javax.swing.JPanel();
84          ipAddressPanel = new javax.swing.JPanel();
85          portLabel = new javax.swing.JLabel();
86          portTextField = new javax.swing.JTextField();
87          ipAddressLabel = new javax.swing.JLabel();
88          ipAddressTextField = new javax.swing.JTextField();
89          ipAddressMessageLabel = new javax.swing.JLabel();
90          filterPanel = new javax.swing.JPanel();
91          ipRadioButton = new javax.swing.JRadioButton();
92          sslRadioButton = new javax.swing.JRadioButton();
93          buttonPanel = new javax.swing.JPanel();
94          okButton = new javax.swing.JButton();
95          cancelButton = new javax.swing.JButton();
96  
97          setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
98          setTitle("Add Client Port");
99          addWindowListener(new java.awt.event.WindowAdapter() {
100             public void windowClosing(java.awt.event.WindowEvent evt) {
101                 closeDialog(evt);
102             }
103         });
104 
105         infoPanel.setLayout(new java.awt.GridBagLayout());
106 
107         infoPanel.setBorder(new javax.swing.border.EtchedBorder());
108         ipAddressPanel.setLayout(new java.awt.GridBagLayout());
109 
110         portLabel.setText("Port: ");
111         gridBagConstraints = new java.awt.GridBagConstraints();
112         gridBagConstraints.gridx = 0;
113         gridBagConstraints.gridy = 0;
114         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
115         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
116         gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 0);
117         ipAddressPanel.add(portLabel, gridBagConstraints);
118 
119         portTextField.setColumns(15);
120         portTextField.addKeyListener(this);
121         gridBagConstraints = new java.awt.GridBagConstraints();
122         gridBagConstraints.gridx = 1;
123         gridBagConstraints.gridy = 0;
124         gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 3);
125         ipAddressPanel.add(portTextField, gridBagConstraints);
126 
127         ipAddressLabel.setText("IP Address: ");
128         gridBagConstraints = new java.awt.GridBagConstraints();
129         gridBagConstraints.gridx = 0;
130         gridBagConstraints.gridy = 1;
131         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
132         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
133         gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 0);
134         ipAddressPanel.add(ipAddressLabel, gridBagConstraints);
135 
136         ipAddressTextField.setColumns(15);
137         ipAddressTextField.addKeyListener(this);
138         gridBagConstraints = new java.awt.GridBagConstraints();
139         gridBagConstraints.gridx = 1;
140         gridBagConstraints.gridy = 1;
141         gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 3);
142         ipAddressPanel.add(ipAddressTextField, gridBagConstraints);
143 
144         ipAddressMessageLabel.setFont(new java.awt.Font("Dialog", 0, 10));
145         ipAddressMessageLabel.setForeground(new java.awt.Color(51, 51, 51));
146         ipAddressMessageLabel.setText("(The IP address field is not mandatory)");
147         gridBagConstraints = new java.awt.GridBagConstraints();
148         gridBagConstraints.gridx = 0;
149         gridBagConstraints.gridy = 2;
150         gridBagConstraints.gridwidth = 2;
151         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
152         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
153         gridBagConstraints.insets = new java.awt.Insets(0, 3, 3, 3);
154         ipAddressPanel.add(ipAddressMessageLabel, gridBagConstraints);
155 
156         gridBagConstraints = new java.awt.GridBagConstraints();
157         gridBagConstraints.gridx = 0;
158         gridBagConstraints.gridy = 0;
159         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
160         infoPanel.add(ipAddressPanel, gridBagConstraints);
161 
162         filterPanel.setLayout(new java.awt.GridBagLayout());
163 
164         filterPanel.setBorder(new javax.swing.border.TitledBorder(null, "Port Type", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 0, 11), new java.awt.Color(51, 51, 51)));
165         ipRadioButton.setSelected(true);
166         ipRadioButton.setText("IP");
167         typeButtonGroup.add(ipRadioButton);
168         ipRadioButton.addKeyListener(this);
169         gridBagConstraints = new java.awt.GridBagConstraints();
170         gridBagConstraints.gridx = 0;
171         gridBagConstraints.gridy = 0;
172         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
173         gridBagConstraints.insets = new java.awt.Insets(0, 6, 3, 3);
174         filterPanel.add(ipRadioButton, gridBagConstraints);
175 
176         sslRadioButton.setText("SSL");
177         typeButtonGroup.add(sslRadioButton);
178         sslRadioButton.addKeyListener(this);
179         gridBagConstraints = new java.awt.GridBagConstraints();
180         gridBagConstraints.gridx = 1;
181         gridBagConstraints.gridy = 0;
182         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
183         gridBagConstraints.insets = new java.awt.Insets(0, 3, 3, 3);
184         filterPanel.add(sslRadioButton, gridBagConstraints);
185 
186         gridBagConstraints = new java.awt.GridBagConstraints();
187         gridBagConstraints.gridx = 0;
188         gridBagConstraints.gridy = 1;
189         gridBagConstraints.insets = new java.awt.Insets(0, 0, 3, 0);
190         infoPanel.add(filterPanel, gridBagConstraints);
191 
192         getContentPane().add(infoPanel, java.awt.BorderLayout.CENTER);
193 
194         okButton.setText("OK");
195         okButton.addKeyListener(this);
196         okButton.addActionListener(new java.awt.event.ActionListener() {
197             public void actionPerformed(java.awt.event.ActionEvent evt) {
198                 okButtonActionPerformed(evt);
199             }
200         });
201 
202         buttonPanel.add(okButton);
203 
204         cancelButton.setText("Cancel");
205         cancelButton.addKeyListener(this);
206         cancelButton.addActionListener(new java.awt.event.ActionListener() {
207             public void actionPerformed(java.awt.event.ActionEvent evt) {
208                 cancelButtonActionPerformed(evt);
209             }
210         });
211 
212         buttonPanel.add(cancelButton);
213 
214         getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH);
215 
216         pack();
217     }//GEN-END:initComponents
218     
219     private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
220         port = portTextField.getText();
221         ipAddress = ipAddressTextField.getText();
222         typeIP = ipRadioButton.isSelected();
223         doClose(RET_OK);
224     }//GEN-LAST:event_okButtonActionPerformed
225     
226     private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
227         doClose(RET_CANCEL);
228     }//GEN-LAST:event_cancelButtonActionPerformed
229     
230     /** Closes the dialog */
231     private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
232         doClose(RET_CANCEL);
233     }//GEN-LAST:event_closeDialog
234     
235     private void doClose(int retStatus) {
236         returnStatus = retStatus;
237         setVisible(false);
238         dispose();
239     }
240     
241     public void keyPressed(KeyEvent keyEvent) {
242         if (keyEvent.getKeyCode() == KeyEvent.VK_ESCAPE)
243             doClose(RET_CANCEL);
244     }
245     
246     public void keyReleased(KeyEvent keyEvent) {
247     }
248     
249     public void keyTyped(KeyEvent keyEvent) {
250     }
251     
252     // Variables declaration - do not modify//GEN-BEGIN:variables
253     private javax.swing.JPanel ipAddressPanel;
254     private javax.swing.JPanel infoPanel;
255     private javax.swing.JLabel portLabel;
256     private javax.swing.JPanel buttonPanel;
257     private javax.swing.JButton okButton;
258     private javax.swing.JPanel filterPanel;
259     private javax.swing.JLabel ipAddressLabel;
260     private javax.swing.JRadioButton ipRadioButton;
261     private javax.swing.JRadioButton sslRadioButton;
262     private javax.swing.JLabel ipAddressMessageLabel;
263     private javax.swing.ButtonGroup typeButtonGroup;
264     private javax.swing.JButton cancelButton;
265     private javax.swing.JTextField portTextField;
266     private javax.swing.JTextField ipAddressTextField;
267     // End of variables declaration//GEN-END:variables
268     
269     private int returnStatus = RET_CANCEL;
270 }