c28c82d58194cb43e6f3406b8038fbbdad7356c6
[habeas.git] / src / habeas / DatabaseSettingsDialog.java
1 /*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6 package habeas;
7
8 import javax.swing.JFileChooser;
9
10 /**
11 *
12 * @author hari
13 */
14 public class DatabaseSettingsDialog extends javax.swing.JDialog {
15
16 /**
17 * Creates new form DatabaseSettings
18 */
19 public DatabaseSettingsDialog(java.awt.Frame parent, boolean modal) {
20 super(parent, modal);
21 initComponents();
22 txtDatabaseURL.setText(Utility.connectionURL);
23 }
24
25 /**
26 * This method is called from within the constructor to initialize the form.
27 * WARNING: Do NOT modify this code. The content of this method is always
28 * regenerated by the Form Editor.
29 */
30 @SuppressWarnings("unchecked")
31 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
32 private void initComponents() {
33
34 jLabel1 = new javax.swing.JLabel();
35 txtDatabaseURL = new javax.swing.JTextField();
36 buttonChooseFile = new javax.swing.JButton();
37 buttonClose = new javax.swing.JButton();
38 buttonApply = new javax.swing.JButton();
39
40 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
41 setTitle("Connection");
42 setLocationByPlatform(true);
43
44 jLabel1.setText("Path to Database");
45
46 buttonChooseFile.setText("Choose...");
47 buttonChooseFile.addActionListener(new java.awt.event.ActionListener() {
48 public void actionPerformed(java.awt.event.ActionEvent evt) {
49 buttonChooseFileActionPerformed(evt);
50 }
51 });
52
53 buttonClose.setText("Close");
54 buttonClose.addActionListener(new java.awt.event.ActionListener() {
55 public void actionPerformed(java.awt.event.ActionEvent evt) {
56 buttonCloseActionPerformed(evt);
57 }
58 });
59
60 buttonApply.setText("Apply");
61 buttonApply.addActionListener(new java.awt.event.ActionListener() {
62 public void actionPerformed(java.awt.event.ActionEvent evt) {
63 buttonApplyActionPerformed(evt);
64 }
65 });
66
67 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
68 getContentPane().setLayout(layout);
69 layout.setHorizontalGroup(
70 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
71 .addGroup(layout.createSequentialGroup()
72 .addContainerGap()
73 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
74 .addGroup(layout.createSequentialGroup()
75 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
76 .addGap(0, 0, Short.MAX_VALUE))
77 .addGroup(layout.createSequentialGroup()
78 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
79 .addComponent(txtDatabaseURL, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE)
80 .addComponent(buttonApply, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
81 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
82 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
83 .addComponent(buttonClose, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
84 .addComponent(buttonChooseFile, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE))))
85 .addContainerGap())
86 );
87 layout.setVerticalGroup(
88 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
89 .addGroup(layout.createSequentialGroup()
90 .addContainerGap()
91 .addComponent(jLabel1)
92 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
93 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
94 .addComponent(txtDatabaseURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
95 .addComponent(buttonChooseFile))
96 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
97 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
98 .addComponent(buttonClose)
99 .addComponent(buttonApply))
100 .addContainerGap())
101 );
102
103 pack();
104 }// </editor-fold>//GEN-END:initComponents
105
106 private void buttonApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonApplyActionPerformed
107 // TODO add your handling code here
108 Utility.setConnectionURL (txtDatabaseURL.getText());
109 }//GEN-LAST:event_buttonApplyActionPerformed
110
111 private void buttonCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCloseActionPerformed
112 // TODO add your handling code here:
113 dispose();
114 }//GEN-LAST:event_buttonCloseActionPerformed
115
116 private void buttonChooseFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonChooseFileActionPerformed
117 // TODO add your handling code here:
118 JFileChooser chooser = new JFileChooser ();
119 int i = chooser.showOpenDialog(this);
120 if (i == JFileChooser.APPROVE_OPTION) {
121 txtDatabaseURL.setText(chooser.getSelectedFile().getAbsolutePath());
122 }
123 }//GEN-LAST:event_buttonChooseFileActionPerformed
124
125 /**
126 * @param args the command line arguments
127 */
128 public static void main(String args[]) {
129 /* Set the Nimbus look and feel */
130 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
131 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
132 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
133 */
134 try {
135 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
136 if ("Nimbus".equals(info.getName())) {
137 javax.swing.UIManager.setLookAndFeel(info.getClassName());
138 break;
139 }
140 }
141 } catch (ClassNotFoundException ex) {
142 java.util.logging.Logger.getLogger(DatabaseSettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
143 } catch (InstantiationException ex) {
144 java.util.logging.Logger.getLogger(DatabaseSettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
145 } catch (IllegalAccessException ex) {
146 java.util.logging.Logger.getLogger(DatabaseSettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
147 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
148 java.util.logging.Logger.getLogger(DatabaseSettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
149 }
150 //</editor-fold>
151 //</editor-fold>
152
153 /* Create and display the dialog */
154 java.awt.EventQueue.invokeLater(new Runnable() {
155 public void run() {
156 DatabaseSettingsDialog dialog = new DatabaseSettingsDialog(new javax.swing.JFrame(), true);
157 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
158 @Override
159 public void windowClosing(java.awt.event.WindowEvent e) {
160 System.exit(0);
161 }
162 });
163 dialog.setVisible(true);
164 }
165 });
166 }
167
168 // Variables declaration - do not modify//GEN-BEGIN:variables
169 private javax.swing.JButton buttonApply;
170 private javax.swing.JButton buttonChooseFile;
171 private javax.swing.JButton buttonClose;
172 private javax.swing.JLabel jLabel1;
173 private javax.swing.JTextField txtDatabaseURL;
174 // End of variables declaration//GEN-END:variables
175 }