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.
8 import javax
.swing
.JFileChooser
;
9 import javax
.swing
.JOptionPane
;
15 public class DatabaseSettingsDialog
extends javax
.swing
.JDialog
{
18 * Creates new form DatabaseSettings
20 public DatabaseSettingsDialog(java
.awt
.Frame parent
, boolean modal
) {
23 txtDatabaseURL
.setText(Utility
.connectionURL
);
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.
31 @SuppressWarnings("unchecked")
32 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
33 private void initComponents() {
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();
42 setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
43 setTitle("Connection");
44 setLocationByPlatform(true);
46 jLabel1
.setText("Path to Database");
48 buttonChooseFile
.setText("Choose...");
49 buttonChooseFile
.addActionListener(new java
.awt
.event
.ActionListener() {
50 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
51 buttonChooseFileActionPerformed(evt
);
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
);
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
);
71 jButton1
.setText("Create...");
72 jButton1
.addActionListener(new java
.awt
.event
.ActionListener() {
73 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
74 jButton1ActionPerformed(evt
);
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()
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
))))
100 layout
.setVerticalGroup(
101 layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
102 .addGroup(layout
.createSequentialGroup()
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
))
118 }// </editor-fold>//GEN-END:initComponents
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
125 private void buttonCloseActionPerformed(java
.awt
.event
.ActionEvent evt
) {//GEN-FIRST:event_buttonCloseActionPerformed
126 // TODO add your handling code here:
128 }//GEN-LAST:event_buttonCloseActionPerformed
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());
137 }//GEN-LAST:event_buttonChooseFileActionPerformed
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
);
147 JOptionPane
.showMessageDialog(this, ERROR_CREATING_TABLE
);
149 txtDatabaseURL
.setText(db_path
);
151 }//GEN-LAST:event_jButton1ActionPerformed
152 private static final String ERROR_CREATING_TABLE
= "Error creating database. "
153 + "Please check connection settings and driver";
156 * @param args the command line arguments
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
165 for (javax
.swing
.UIManager
.LookAndFeelInfo info
: javax
.swing
.UIManager
.getInstalledLookAndFeels()) {
166 if ("Nimbus".equals(info
.getName())) {
167 javax
.swing
.UIManager
.setLookAndFeel(info
.getClassName());
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
);
183 /* Create and display the dialog */
184 java
.awt
.EventQueue
.invokeLater(new Runnable() {
186 DatabaseSettingsDialog dialog
= new DatabaseSettingsDialog(new javax
.swing
.JFrame(), true);
187 dialog
.addWindowListener(new java
.awt
.event
.WindowAdapter() {
189 public void windowClosing(java
.awt
.event
.WindowEvent e
) {
193 dialog
.setVisible(true);
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