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
;
14 public class DatabaseSettingsDialog
extends javax
.swing
.JDialog
{
17 * Creates new form DatabaseSettings
19 public DatabaseSettingsDialog(java
.awt
.Frame parent
, boolean modal
) {
22 txtDatabaseURL
.setText(Utility
.connectionURL
);
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.
30 @SuppressWarnings("unchecked")
31 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
32 private void initComponents() {
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();
40 setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
41 setTitle("Connection");
42 setLocationByPlatform(true);
45 jLabel1
.setText("Path to Database");
47 buttonChooseFile
.setText("Choose...");
48 buttonChooseFile
.addActionListener(new java
.awt
.event
.ActionListener() {
49 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
50 buttonChooseFileActionPerformed(evt
);
54 buttonClose
.setText("Close");
55 buttonClose
.addActionListener(new java
.awt
.event
.ActionListener() {
56 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
57 buttonCloseActionPerformed(evt
);
61 buttonApply
.setText("Apply");
62 buttonApply
.addActionListener(new java
.awt
.event
.ActionListener() {
63 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
64 buttonApplyActionPerformed(evt
);
68 javax
.swing
.GroupLayout layout
= new javax
.swing
.GroupLayout(getContentPane());
69 getContentPane().setLayout(layout
);
70 layout
.setHorizontalGroup(
71 layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
72 .addGroup(layout
.createSequentialGroup()
74 .addGroup(layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
75 .addGroup(layout
.createSequentialGroup()
76 .addComponent(jLabel1
, javax
.swing
.GroupLayout
.PREFERRED_SIZE
, 139, javax
.swing
.GroupLayout
.PREFERRED_SIZE
)
77 .addGap(0, 0, Short
.MAX_VALUE
))
78 .addGroup(layout
.createSequentialGroup()
79 .addGroup(layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.TRAILING
)
80 .addComponent(txtDatabaseURL
, javax
.swing
.GroupLayout
.PREFERRED_SIZE
, 231, javax
.swing
.GroupLayout
.PREFERRED_SIZE
)
81 .addComponent(buttonApply
, javax
.swing
.GroupLayout
.PREFERRED_SIZE
, 92, javax
.swing
.GroupLayout
.PREFERRED_SIZE
))
82 .addPreferredGap(javax
.swing
.LayoutStyle
.ComponentPlacement
.RELATED
)
83 .addGroup(layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
84 .addComponent(buttonClose
, javax
.swing
.GroupLayout
.DEFAULT_SIZE
, javax
.swing
.GroupLayout
.DEFAULT_SIZE
, Short
.MAX_VALUE
)
85 .addComponent(buttonChooseFile
, javax
.swing
.GroupLayout
.DEFAULT_SIZE
, 93, Short
.MAX_VALUE
))))
88 layout
.setVerticalGroup(
89 layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
90 .addGroup(layout
.createSequentialGroup()
92 .addComponent(jLabel1
)
93 .addPreferredGap(javax
.swing
.LayoutStyle
.ComponentPlacement
.RELATED
)
94 .addGroup(layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.BASELINE
)
95 .addComponent(txtDatabaseURL
, javax
.swing
.GroupLayout
.PREFERRED_SIZE
, javax
.swing
.GroupLayout
.DEFAULT_SIZE
, javax
.swing
.GroupLayout
.PREFERRED_SIZE
)
96 .addComponent(buttonChooseFile
))
97 .addPreferredGap(javax
.swing
.LayoutStyle
.ComponentPlacement
.RELATED
, 29, Short
.MAX_VALUE
)
98 .addGroup(layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.BASELINE
)
99 .addComponent(buttonClose
)
100 .addComponent(buttonApply
))
105 }// </editor-fold>//GEN-END:initComponents
107 private void buttonApplyActionPerformed(java
.awt
.event
.ActionEvent evt
) {//GEN-FIRST:event_buttonApplyActionPerformed
108 // TODO add your handling code here
109 Utility
.setConnectionURL (txtDatabaseURL
.getText());
110 }//GEN-LAST:event_buttonApplyActionPerformed
112 private void buttonCloseActionPerformed(java
.awt
.event
.ActionEvent evt
) {//GEN-FIRST:event_buttonCloseActionPerformed
113 // TODO add your handling code here:
115 }//GEN-LAST:event_buttonCloseActionPerformed
117 private void buttonChooseFileActionPerformed(java
.awt
.event
.ActionEvent evt
) {//GEN-FIRST:event_buttonChooseFileActionPerformed
118 // TODO add your handling code here:
119 JFileChooser chooser
= new JFileChooser ();
120 int i
= chooser
.showOpenDialog(this);
121 if (i
== JFileChooser
.APPROVE_OPTION
) {
122 txtDatabaseURL
.setText(chooser
.getSelectedFile().getAbsolutePath());
124 }//GEN-LAST:event_buttonChooseFileActionPerformed
127 * @param args the command line arguments
129 public static void main(String args
[]) {
130 /* Set the Nimbus look and feel */
131 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
132 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
133 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
136 for (javax
.swing
.UIManager
.LookAndFeelInfo info
: javax
.swing
.UIManager
.getInstalledLookAndFeels()) {
137 if ("Nimbus".equals(info
.getName())) {
138 javax
.swing
.UIManager
.setLookAndFeel(info
.getClassName());
142 } catch (ClassNotFoundException ex
) {
143 java
.util
.logging
.Logger
.getLogger(DatabaseSettingsDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
144 } catch (InstantiationException ex
) {
145 java
.util
.logging
.Logger
.getLogger(DatabaseSettingsDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
146 } catch (IllegalAccessException ex
) {
147 java
.util
.logging
.Logger
.getLogger(DatabaseSettingsDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
148 } catch (javax
.swing
.UnsupportedLookAndFeelException ex
) {
149 java
.util
.logging
.Logger
.getLogger(DatabaseSettingsDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
154 /* Create and display the dialog */
155 java
.awt
.EventQueue
.invokeLater(new Runnable() {
157 DatabaseSettingsDialog dialog
= new DatabaseSettingsDialog(new javax
.swing
.JFrame(), true);
158 dialog
.addWindowListener(new java
.awt
.event
.WindowAdapter() {
160 public void windowClosing(java
.awt
.event
.WindowEvent e
) {
164 dialog
.setVisible(true);
169 // Variables declaration - do not modify//GEN-BEGIN:variables
170 private javax
.swing
.JButton buttonApply
;
171 private javax
.swing
.JButton buttonChooseFile
;
172 private javax
.swing
.JButton buttonClose
;
173 private javax
.swing
.JLabel jLabel1
;
174 private javax
.swing
.JTextField txtDatabaseURL
;
175 // End of variables declaration//GEN-END:variables