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 java
.util
.prefs
.Preferences
;
9 import javax
.swing
.JFileChooser
;
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();
41 setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
42 setTitle("Connection");
43 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
.setText("Close");
56 buttonClose
.addActionListener(new java
.awt
.event
.ActionListener() {
57 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
58 buttonCloseActionPerformed(evt
);
62 buttonApply
.setText("Apply");
63 buttonApply
.addActionListener(new java
.awt
.event
.ActionListener() {
64 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
65 buttonApplyActionPerformed(evt
);
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()
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
))))
89 layout
.setVerticalGroup(
90 layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
91 .addGroup(layout
.createSequentialGroup()
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
))
106 }// </editor-fold>//GEN-END:initComponents
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
113 private void buttonCloseActionPerformed(java
.awt
.event
.ActionEvent evt
) {//GEN-FIRST:event_buttonCloseActionPerformed
114 // TODO add your handling code here:
116 }//GEN-LAST:event_buttonCloseActionPerformed
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());
125 }//GEN-LAST:event_buttonChooseFileActionPerformed
128 * @param args the command line arguments
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
137 for (javax
.swing
.UIManager
.LookAndFeelInfo info
: javax
.swing
.UIManager
.getInstalledLookAndFeels()) {
138 if ("Nimbus".equals(info
.getName())) {
139 javax
.swing
.UIManager
.setLookAndFeel(info
.getClassName());
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
);
155 /* Create and display the dialog */
156 java
.awt
.EventQueue
.invokeLater(new Runnable() {
158 DatabaseSettingsDialog dialog
= new DatabaseSettingsDialog(new javax
.swing
.JFrame(), true);
159 dialog
.addWindowListener(new java
.awt
.event
.WindowAdapter() {
161 public void windowClosing(java
.awt
.event
.WindowEvent e
) {
165 dialog
.setVisible(true);
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