Option for creating a new Legal Database
[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 import javax.swing.JOptionPane;
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 jButton1 = new javax.swing.JButton();
41
42 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
43 setTitle("Connection");
44 setLocationByPlatform(true);
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.setMnemonic('C');
56 buttonClose.setText("Close");
57 buttonClose.addActionListener(new java.awt.event.ActionListener() {
58 public void actionPerformed(java.awt.event.ActionEvent evt) {
59 buttonCloseActionPerformed(evt);
60 }
61 });
62
63 buttonApply.setMnemonic('a');
64 buttonApply.setText("Apply");
65 buttonApply.addActionListener(new java.awt.event.ActionListener() {
66 public void actionPerformed(java.awt.event.ActionEvent evt) {
67 buttonApplyActionPerformed(evt);
68 }
69 });
70
71 jButton1.setText("Create...");
72 jButton1.addActionListener(new java.awt.event.ActionListener() {
73 public void actionPerformed(java.awt.event.ActionEvent evt) {
74 jButton1ActionPerformed(evt);
75 }
76 });
77
78 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
79 getContentPane().setLayout(layout);
80 layout.setHorizontalGroup(
81 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
82 .addGroup(layout.createSequentialGroup()
83 .addContainerGap()
84 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
85 .addGroup(layout.createSequentialGroup()
86 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
87 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
88 .addGroup(layout.createSequentialGroup()
89 .addComponent(txtDatabaseURL, javax.swing.GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE)
90 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
91 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
92 .addComponent(buttonChooseFile, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
93 .addComponent(buttonApply, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
94 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
95 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
96 .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
97 .addComponent(buttonClose, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
98 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
99 );
100 layout.setVerticalGroup(
101 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
102 .addGroup(layout.createSequentialGroup()
103 .addContainerGap()
104 .addComponent(jLabel1)
105 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
106 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
107 .addComponent(txtDatabaseURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
108 .addComponent(buttonChooseFile)
109 .addComponent(jButton1))
110 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
111 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
112 .addComponent(buttonApply)
113 .addComponent(buttonClose))
114 .addContainerGap())
115 );
116
117 pack();
118 }// </editor-fold>//GEN-END:initComponents
119
120 private void buttonApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonApplyActionPerformed
121 // TODO add your handling code here
122 Utility.saveConnectionURL (txtDatabaseURL.getText());
123 }//GEN-LAST:event_buttonApplyActionPerformed
124
125 private void buttonCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCloseActionPerformed
126 // TODO add your handling code here:
127 dispose();
128 }//GEN-LAST:event_buttonCloseActionPerformed
129
130 private void buttonChooseFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonChooseFileActionPerformed
131 // TODO add your handling code here:
132 JFileChooser chooser = new JFileChooser ();
133 int i = chooser.showOpenDialog(this);
134 if (i == JFileChooser.APPROVE_OPTION) {
135 txtDatabaseURL.setText(chooser.getSelectedFile().getAbsolutePath());
136 }
137 }//GEN-LAST:event_buttonChooseFileActionPerformed
138
139 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
140 // TODO add your handling code here:
141 JFileChooser chooser = new JFileChooser ();
142 int i = chooser.showSaveDialog(this);
143 if (i == JFileChooser.APPROVE_OPTION) {
144 String db_path = chooser.getSelectedFile().getAbsolutePath();
145 boolean rt = Utility.createDatabase (db_path);
146 if (rt == false)
147 JOptionPane.showMessageDialog(this, ERROR_CREATING_TABLE);
148 else
149 txtDatabaseURL.setText(db_path);
150 }
151 }//GEN-LAST:event_jButton1ActionPerformed
152 private static final String ERROR_CREATING_TABLE = "Error creating database. "
153 + "Please check connection settings and driver";
154
155 /**
156 * @param args the command line arguments
157 */
158 public static void main(String args[]) {
159 /* Set the Nimbus look and feel */
160 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
161 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
162 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
163 */
164 try {
165 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
166 if ("Nimbus".equals(info.getName())) {
167 javax.swing.UIManager.setLookAndFeel(info.getClassName());
168 break;
169 }
170 }
171 } catch (ClassNotFoundException ex) {
172 java.util.logging.Logger.getLogger(DatabaseSettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
173 } catch (InstantiationException ex) {
174 java.util.logging.Logger.getLogger(DatabaseSettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
175 } catch (IllegalAccessException ex) {
176 java.util.logging.Logger.getLogger(DatabaseSettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
177 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
178 java.util.logging.Logger.getLogger(DatabaseSettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
179 }
180 //</editor-fold>
181 //</editor-fold>
182
183 /* Create and display the dialog */
184 java.awt.EventQueue.invokeLater(new Runnable() {
185 public void run() {
186 DatabaseSettingsDialog dialog = new DatabaseSettingsDialog(new javax.swing.JFrame(), true);
187 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
188 @Override
189 public void windowClosing(java.awt.event.WindowEvent e) {
190 System.exit(0);
191 }
192 });
193 dialog.setVisible(true);
194 }
195 });
196 }
197
198 // Variables declaration - do not modify//GEN-BEGIN:variables
199 private javax.swing.JButton buttonApply;
200 private javax.swing.JButton buttonChooseFile;
201 private javax.swing.JButton buttonClose;
202 private javax.swing.JButton jButton1;
203 private javax.swing.JLabel jLabel1;
204 private javax.swing.JTextField txtDatabaseURL;
205 // End of variables declaration//GEN-END:variables
206 }