Source code: org/jabbee/ui/dialogs/GetConfigPath.java
1 /*
2 * GetConfigPath.java
3 *
4 * Created on October 23, 2002, 9:14 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 javax.swing.JOptionPane;
38 import org.jabbee.Jabbee;
39
40 /**
41 * Window which prompts user for path to a jabber configuration file.
42 *
43 * @author Gregory Kaczmarczyk
44 *
45 * @version 0.01
46 */
47 public class GetConfigPath extends javax.swing.JFrame implements KeyListener {
48
49 /** Creates new form GetConfigPath */
50 public GetConfigPath() {
51 setResizable(false);
52
53 initComponents();
54
55 getRootPane().setDefaultButton(okButton);
56
57 // Center window
58 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
59 this.setLocation(screenSize.width/2 - (this.getPreferredSize().width/2), screenSize.height/2 - (this.getPreferredSize().height/2));
60 }
61
62 /** This method is called from within the constructor to
63 * initialize the form.
64 * WARNING: Do NOT modify this code. The content of this method is
65 * always regenerated by the Form Editor.
66 */
67 private void initComponents() {//GEN-BEGIN:initComponents
68 java.awt.GridBagConstraints gridBagConstraints;
69
70 configPanel = new javax.swing.JPanel();
71 enterLabel = new javax.swing.JLabel();
72 pathTextField = new javax.swing.JTextField();
73 browseButton = new javax.swing.JButton();
74 actionPanel = new javax.swing.JPanel();
75 okButton = new javax.swing.JButton();
76 quitButton = new javax.swing.JButton();
77
78 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
79 setTitle("Jabbee - Config File");
80 setIconImage(new javax.swing.ImageIcon(getClass().getResource("/org/jabbee/resources/images/logo-16.png")).getImage());
81 addWindowListener(new java.awt.event.WindowAdapter() {
82 public void windowClosing(java.awt.event.WindowEvent evt) {
83 exitForm(evt);
84 }
85 });
86
87 configPanel.setLayout(new java.awt.GridBagLayout());
88
89 configPanel.setBorder(new javax.swing.border.EtchedBorder());
90 enterLabel.setText("Please enter the full path to your Jabber configuration file: ");
91 gridBagConstraints = new java.awt.GridBagConstraints();
92 gridBagConstraints.gridx = 0;
93 gridBagConstraints.gridy = 0;
94 gridBagConstraints.gridwidth = 2;
95 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
96 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
97 configPanel.add(enterLabel, gridBagConstraints);
98
99 pathTextField.setColumns(25);
100 pathTextField.addKeyListener(this);
101 gridBagConstraints = new java.awt.GridBagConstraints();
102 gridBagConstraints.gridx = 0;
103 gridBagConstraints.gridy = 1;
104 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
105 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
106 configPanel.add(pathTextField, gridBagConstraints);
107
108 browseButton.setText("Browse...");
109 browseButton.addKeyListener(this);
110 browseButton.addActionListener(new java.awt.event.ActionListener() {
111 public void actionPerformed(java.awt.event.ActionEvent evt) {
112 browseButtonActionPerformed(evt);
113 }
114 });
115
116 gridBagConstraints = new java.awt.GridBagConstraints();
117 gridBagConstraints.gridx = 1;
118 gridBagConstraints.gridy = 1;
119 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
120 configPanel.add(browseButton, gridBagConstraints);
121
122 getContentPane().add(configPanel, java.awt.BorderLayout.CENTER);
123
124 okButton.setText("OK");
125 okButton.addKeyListener(this);
126 okButton.addActionListener(new java.awt.event.ActionListener() {
127 public void actionPerformed(java.awt.event.ActionEvent evt) {
128 okButtonActionPerformed(evt);
129 }
130 });
131
132 actionPanel.add(okButton);
133
134 quitButton.setText("Quit");
135 quitButton.addKeyListener(this);
136 quitButton.addActionListener(new java.awt.event.ActionListener() {
137 public void actionPerformed(java.awt.event.ActionEvent evt) {
138 quitButtonActionPerformed(evt);
139 }
140 });
141
142 actionPanel.add(quitButton);
143
144 getContentPane().add(actionPanel, java.awt.BorderLayout.SOUTH);
145
146 pack();
147 }//GEN-END:initComponents
148
149 private void quitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitButtonActionPerformed
150 System.exit(0);
151 }//GEN-LAST:event_quitButtonActionPerformed
152
153 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
154 String file = pathTextField.getText();
155 if ((file.length() != 0) && (new java.io.File(file).exists())) {
156 Jabbee jabbee = new Jabbee(file);
157 setVisible(false);
158 dispose();
159 jabbee.show();
160 } else
161 JOptionPane.showMessageDialog(this, "This does not appear to be a valid file", "Bad Filename", JOptionPane.ERROR_MESSAGE);
162 }//GEN-LAST:event_okButtonActionPerformed
163
164 private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
165 javax.swing.JFileChooser setChooser = new javax.swing.JFileChooser();
166 setChooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
167 public boolean accept(java.io.File f) {
168 return f.isDirectory() || f.getName().toLowerCase().endsWith(".xml");
169 }
170 public String getDescription() {
171 return "XML files";
172 }
173 });
174 setChooser.setApproveButtonText("Select");
175 setChooser.setFileSelectionMode(javax.swing.JFileChooser.FILES_ONLY);
176 int returnVal = setChooser.showOpenDialog(this);
177 if(returnVal == javax.swing.JFileChooser.APPROVE_OPTION) {
178 pathTextField.setText(setChooser.getSelectedFile().getPath());
179 }
180 }//GEN-LAST:event_browseButtonActionPerformed
181
182 /** Exit the Application */
183 private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
184 System.exit(0);
185 }//GEN-LAST:event_exitForm
186
187 public void keyPressed(KeyEvent keyEvent) {
188 if (keyEvent.getKeyCode() == KeyEvent.VK_ESCAPE)
189 System.exit(0);
190 }
191
192 public void keyReleased(KeyEvent keyEvent) {
193 }
194
195 public void keyTyped(KeyEvent keyEvent) {
196 }
197
198 // Variables declaration - do not modify//GEN-BEGIN:variables
199 private javax.swing.JLabel enterLabel;
200 private javax.swing.JButton okButton;
201 private javax.swing.JPanel actionPanel;
202 private javax.swing.JTextField pathTextField;
203 private javax.swing.JPanel configPanel;
204 private javax.swing.JButton quitButton;
205 private javax.swing.JButton browseButton;
206 // End of variables declaration//GEN-END:variables
207
208 }