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