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);
44 jLabel1
.setText("Path to Database");
46 buttonChooseFile
.setText("Choose...");
47 buttonChooseFile
.addActionListener(new java
.awt
.event
.ActionListener() {
48 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
49 buttonChooseFileActionPerformed(evt
);
53 buttonClose
.setText("Close");
54 buttonClose
.addActionListener(new java
.awt
.event
.ActionListener() {
55 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
56 buttonCloseActionPerformed(evt
);
60 buttonApply
.setText("Apply");
61 buttonApply
.addActionListener(new java
.awt
.event
.ActionListener() {
62 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
63 buttonApplyActionPerformed(evt
);
67 javax
.swing
.GroupLayout layout
= new javax
.swing
.GroupLayout(getContentPane());
68 getContentPane().setLayout(layout
);
69 layout
.setHorizontalGroup(
70 layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
71 .addGroup(layout
.createSequentialGroup()
73 .addGroup(layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
74 .addGroup(layout
.createSequentialGroup()
75 .addComponent(jLabel1
, javax
.swing
.GroupLayout
.PREFERRED_SIZE
, 139, javax
.swing
.GroupLayout
.PREFERRED_SIZE
)
76 .addGap(0, 0, Short
.MAX_VALUE
))
77 .addGroup(layout
.createSequentialGroup()
78 .addGroup(layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.TRAILING
)
79 .addComponent(txtDatabaseURL
, javax
.swing
.GroupLayout
.PREFERRED_SIZE
, 231, javax
.swing
.GroupLayout
.PREFERRED_SIZE
)
80 .addComponent(buttonApply
, javax
.swing
.GroupLayout
.PREFERRED_SIZE
, 92, javax
.swing
.GroupLayout
.PREFERRED_SIZE
))
81 .addPreferredGap(javax
.swing
.LayoutStyle
.ComponentPlacement
.RELATED
)
82 .addGroup(layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
83 .addComponent(buttonClose
, javax
.swing
.GroupLayout
.DEFAULT_SIZE
, javax
.swing
.GroupLayout
.DEFAULT_SIZE
, Short
.MAX_VALUE
)
84 .addComponent(buttonChooseFile
, javax
.swing
.GroupLayout
.DEFAULT_SIZE
, 93, Short
.MAX_VALUE
))))
87 layout
.setVerticalGroup(
88 layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
89 .addGroup(layout
.createSequentialGroup()
91 .addComponent(jLabel1
)
92 .addPreferredGap(javax
.swing
.LayoutStyle
.ComponentPlacement
.RELATED
)
93 .addGroup(layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.BASELINE
)
94 .addComponent(txtDatabaseURL
, javax
.swing
.GroupLayout
.PREFERRED_SIZE
, javax
.swing
.GroupLayout
.DEFAULT_SIZE
, javax
.swing
.GroupLayout
.PREFERRED_SIZE
)
95 .addComponent(buttonChooseFile
))
96 .addPreferredGap(javax
.swing
.LayoutStyle
.ComponentPlacement
.RELATED
, 29, Short
.MAX_VALUE
)
97 .addGroup(layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.BASELINE
)
98 .addComponent(buttonClose
)
99 .addComponent(buttonApply
))
104 }// </editor-fold>//GEN-END:initComponents
106 private void buttonApplyActionPerformed(java
.awt
.event
.ActionEvent evt
) {//GEN-FIRST:event_buttonApplyActionPerformed
107 // TODO add your handling code here
108 Utility
.setConnectionURL (txtDatabaseURL
.getText());
109 }//GEN-LAST:event_buttonApplyActionPerformed
111 private void buttonCloseActionPerformed(java
.awt
.event
.ActionEvent evt
) {//GEN-FIRST:event_buttonCloseActionPerformed
112 // TODO add your handling code here:
114 }//GEN-LAST:event_buttonCloseActionPerformed
116 private void buttonChooseFileActionPerformed(java
.awt
.event
.ActionEvent evt
) {//GEN-FIRST:event_buttonChooseFileActionPerformed
117 // TODO add your handling code here:
118 JFileChooser chooser
= new JFileChooser ();
119 int i
= chooser
.showOpenDialog(this);
120 if (i
== JFileChooser
.APPROVE_OPTION
) {
121 txtDatabaseURL
.setText(chooser
.getSelectedFile().getAbsolutePath());
123 }//GEN-LAST:event_buttonChooseFileActionPerformed
126 * @param args the command line arguments
128 public static void main(String args
[]) {
129 /* Set the Nimbus look and feel */
130 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
131 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
132 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
135 for (javax
.swing
.UIManager
.LookAndFeelInfo info
: javax
.swing
.UIManager
.getInstalledLookAndFeels()) {
136 if ("Nimbus".equals(info
.getName())) {
137 javax
.swing
.UIManager
.setLookAndFeel(info
.getClassName());
141 } catch (ClassNotFoundException ex
) {
142 java
.util
.logging
.Logger
.getLogger(DatabaseSettingsDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
143 } catch (InstantiationException ex
) {
144 java
.util
.logging
.Logger
.getLogger(DatabaseSettingsDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
145 } catch (IllegalAccessException ex
) {
146 java
.util
.logging
.Logger
.getLogger(DatabaseSettingsDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
147 } catch (javax
.swing
.UnsupportedLookAndFeelException ex
) {
148 java
.util
.logging
.Logger
.getLogger(DatabaseSettingsDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
153 /* Create and display the dialog */
154 java
.awt
.EventQueue
.invokeLater(new Runnable() {
156 DatabaseSettingsDialog dialog
= new DatabaseSettingsDialog(new javax
.swing
.JFrame(), true);
157 dialog
.addWindowListener(new java
.awt
.event
.WindowAdapter() {
159 public void windowClosing(java
.awt
.event
.WindowEvent e
) {
163 dialog
.setVisible(true);
168 // Variables declaration - do not modify//GEN-BEGIN:variables
169 private javax
.swing
.JButton buttonApply
;
170 private javax
.swing
.JButton buttonChooseFile
;
171 private javax
.swing
.JButton buttonClose
;
172 private javax
.swing
.JLabel jLabel1
;
173 private javax
.swing
.JTextField txtDatabaseURL
;
174 // End of variables declaration//GEN-END:variables