Source code: org/jabbee/ui/dialogs/AddSSLAddress.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 import org.jabbee.resources.PreferencesHandler;
38 import org.jabbee.util.PathParser;
39
40 /** Dialog which allows user to add an IP address for SSL connection to Jabber.
41 *
42 * @author Gregory Kaczmarczyk
43 *
44 * @version 0.01
45 */
46 public final class AddSSLAddress extends javax.swing.JDialog implements KeyListener {
47 /** A return status code - returned if Cancel button has been pressed */
48 public static final int RET_CANCEL = 0;
49 /** A return status code - returned if OK button has been pressed */
50 public static final int RET_OK = 1;
51 /** IP Address for SSL connection */
52 public String ipAddress = "";
53 /** path to certficate file */
54 public String certificate = "";
55
56 /** Creates new form AddAdmin */
57 public AddSSLAddress(java.awt.Frame parent, boolean modal) {
58 super(parent, modal);
59 setResizable(false);
60 initComponents();
61
62 getRootPane().setDefaultButton(okButton);
63
64 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
65 this.setLocation(screenSize.width/2 - (this.getPreferredSize().width/2), screenSize.height/2 - (this.getPreferredSize().height/2));
66 }
67
68 /** @return the return status of this dialog - one of RET_OK or RET_CANCEL */
69 public int getReturnStatus() {
70 return returnStatus;
71 }
72
73 /** This method is called from within the constructor to
74 * initialize the form.
75 * WARNING: Do NOT modify this code. The content of this method is
76 * always regenerated by the Form Editor.
77 */
78 private void initComponents() {//GEN-BEGIN:initComponents
79 java.awt.GridBagConstraints gridBagConstraints;
80
81 privilegeButtonGroup = new javax.swing.ButtonGroup();
82 infoPanel = new javax.swing.JPanel();
83 ipAddrLabel = new javax.swing.JLabel();
84 ipAddrTextField = new javax.swing.JTextField();
85 certLabel = new javax.swing.JLabel();
86 certTextField = new javax.swing.JTextField();
87 certBrowseButton = new javax.swing.JButton();
88 buttonPanel = new javax.swing.JPanel();
89 okButton = new javax.swing.JButton();
90 cancelButton = new javax.swing.JButton();
91
92 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
93 setTitle("Add SSL IP");
94 addWindowListener(new java.awt.event.WindowAdapter() {
95 public void windowClosing(java.awt.event.WindowEvent evt) {
96 closeDialog(evt);
97 }
98 });
99
100 infoPanel.setLayout(new java.awt.GridBagLayout());
101
102 infoPanel.setBorder(new javax.swing.border.EtchedBorder());
103 ipAddrLabel.setText("IP Address: ");
104 gridBagConstraints = new java.awt.GridBagConstraints();
105 gridBagConstraints.gridx = 0;
106 gridBagConstraints.gridy = 0;
107 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
108 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
109 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 0);
110 infoPanel.add(ipAddrLabel, gridBagConstraints);
111
112 ipAddrTextField.setColumns(15);
113 ipAddrTextField.addKeyListener(this);
114 gridBagConstraints = new java.awt.GridBagConstraints();
115 gridBagConstraints.gridx = 1;
116 gridBagConstraints.gridy = 0;
117 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
118 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
119 infoPanel.add(ipAddrTextField, gridBagConstraints);
120
121 certLabel.setText("Certificate: ");
122 gridBagConstraints = new java.awt.GridBagConstraints();
123 gridBagConstraints.gridx = 0;
124 gridBagConstraints.gridy = 1;
125 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
126 gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 0);
127 infoPanel.add(certLabel, gridBagConstraints);
128
129 certTextField.setColumns(30);
130 certTextField.addKeyListener(this);
131 gridBagConstraints = new java.awt.GridBagConstraints();
132 gridBagConstraints.gridx = 1;
133 gridBagConstraints.gridy = 1;
134 gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 3);
135 infoPanel.add(certTextField, gridBagConstraints);
136
137 certBrowseButton.setText("Browse for Certificate...");
138 certBrowseButton.addKeyListener(this);
139 certBrowseButton.addActionListener(new java.awt.event.ActionListener() {
140 public void actionPerformed(java.awt.event.ActionEvent evt) {
141 certBrowseButtonActionPerformed(evt);
142 }
143 });
144
145 gridBagConstraints = new java.awt.GridBagConstraints();
146 gridBagConstraints.gridx = 1;
147 gridBagConstraints.gridy = 2;
148 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
149 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
150 infoPanel.add(certBrowseButton, gridBagConstraints);
151
152 getContentPane().add(infoPanel, java.awt.BorderLayout.CENTER);
153
154 okButton.setText("OK");
155 okButton.addKeyListener(this);
156 okButton.addActionListener(new java.awt.event.ActionListener() {
157 public void actionPerformed(java.awt.event.ActionEvent evt) {
158 okButtonActionPerformed(evt);
159 }
160 });
161
162 buttonPanel.add(okButton);
163
164 cancelButton.setText("Cancel");
165 cancelButton.addKeyListener(this);
166 cancelButton.addActionListener(new java.awt.event.ActionListener() {
167 public void actionPerformed(java.awt.event.ActionEvent evt) {
168 cancelButtonActionPerformed(evt);
169 }
170 });
171
172 buttonPanel.add(cancelButton);
173
174 getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH);
175
176 pack();
177 }//GEN-END:initComponents
178
179 private void certBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_certBrowseButtonActionPerformed
180 PathParser pp = new PathParser(prefsHandler.getConfigFile());
181 javax.swing.JFileChooser selectChooser = new javax.swing.JFileChooser(pp.getConfigPath());
182 selectChooser.setApproveButtonText("Select");
183 selectChooser.setFileSelectionMode(javax.swing.JFileChooser.FILES_ONLY);
184 int returnVal = selectChooser.showOpenDialog(this);
185 if(returnVal == javax.swing.JFileChooser.APPROVE_OPTION) {
186 String filePath = selectChooser.getSelectedFile().getPath();
187 if (prefsHandler.useRelativePaths())
188 certTextField.setText(pp.getRelativePath(filePath));
189 else
190 certTextField.setText(filePath);
191 }
192 }//GEN-LAST:event_certBrowseButtonActionPerformed
193
194 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
195 ipAddress = ipAddrTextField.getText();
196 certificate = certTextField.getText();
197 doClose(RET_OK);
198 }//GEN-LAST:event_okButtonActionPerformed
199
200 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
201 doClose(RET_CANCEL);
202 }//GEN-LAST:event_cancelButtonActionPerformed
203
204 /** Closes the dialog */
205 private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
206 doClose(RET_CANCEL);
207 }//GEN-LAST:event_closeDialog
208
209 private void doClose(int retStatus) {
210 returnStatus = retStatus;
211 setVisible(false);
212 dispose();
213 }
214
215 public void setPrefsHandler(PreferencesHandler h) {
216 prefsHandler = h;
217 }
218
219 public void keyPressed(KeyEvent keyEvent) {
220 if (keyEvent.getKeyCode() == KeyEvent.VK_ESCAPE)
221 doClose(RET_CANCEL);
222 }
223
224 public void keyReleased(KeyEvent keyEvent) {
225 }
226
227 public void keyTyped(KeyEvent keyEvent) {
228 }
229
230 // Variables declaration - do not modify//GEN-BEGIN:variables
231 private javax.swing.ButtonGroup privilegeButtonGroup;
232 private javax.swing.JPanel infoPanel;
233 private javax.swing.JTextField ipAddrTextField;
234 private javax.swing.JPanel buttonPanel;
235 private javax.swing.JLabel certLabel;
236 private javax.swing.JButton okButton;
237 private javax.swing.JButton certBrowseButton;
238 private javax.swing.JLabel ipAddrLabel;
239 private javax.swing.JButton cancelButton;
240 private javax.swing.JTextField certTextField;
241 // End of variables declaration//GEN-END:variables
242 private PreferencesHandler prefsHandler;
243 private int returnStatus = RET_CANCEL;
244 }