001    /*
002    // $Id: //open/mondrian/src/main/mondrian/gui/PreferencesDialog.java#10 $
003    // This software is subject to the terms of the Common Public License
004    // Agreement, available at the following URL:
005    // http://www.opensource.org/licenses/cpl.html.
006    // Copyright (C) 2002-2008 Julian Hyde and others
007    // Copyright (C) 2006-2007 Cincom Systems, Inc.
008    // Copyright (C) 2006-2007 JasperSoft
009    // All Rights Reserved.
010    // You must accept the terms of that agreement to use this software.
011    */
012    package mondrian.gui;
013    
014    import java.awt.Dimension;
015    
016    /**
017     *
018     * @author  sean
019     * @version $Id: //open/mondrian/src/main/mondrian/gui/PreferencesDialog.java#10 $
020     */
021    public class PreferencesDialog extends javax.swing.JDialog {
022        boolean accepted = false;
023    
024        /** Creates new form PreferencesDialog */
025        public PreferencesDialog(java.awt.Frame parent, boolean modal) {
026            super(parent, modal);
027            initComponents();
028        }
029    
030        public boolean accepted() {
031            return accepted;
032        }
033    
034        public void setJDBCConnectionUrl(String s) {
035            this.urlTextField.setText(s);
036        }
037    
038        public String getJDBCConnectionUrl() {
039            return urlTextField.getText();
040        }
041    
042        public void setJDBCUsername(String s) {
043            this.usernameTextField.setText(s);
044        }
045    
046        public String getJDBCUsername() {
047            return usernameTextField.getText();
048        }
049    
050        public void setJDBCPassword(String s) {
051            this.passwordTextField.setText(s);
052        }
053    
054        public String getJDBCPassword() {
055            return passwordTextField.getText();
056        }
057    
058        public void setJDBCDriverClassName(String s) {
059            this.driverClassTextField.setText(s);
060        }
061    
062        public String getJDBCDriverClassName() {
063            return driverClassTextField.getText();
064        }
065    
066        /**
067         * @return the workbench i18n converter
068         */
069        public I18n getResourceConverter() {
070            return ((Workbench) getParent()).getResourceConverter();
071        }
072    
073        /** This method is called from within the constructor to
074         * initialize the form.
075         * WARNING: Do NOT modify this code. The content of this method is
076         * always regenerated by the Form Editor.
077         */
078        private void initComponents() {//GEN-BEGIN:initComponents
079            java.awt.GridBagConstraints gridBagConstraints;
080    
081            jTabbedPane1 = new javax.swing.JTabbedPane();
082            jPanel1 = new javax.swing.JPanel();
083            jLabel1 = new javax.swing.JLabel();
084            jLabel2 = new javax.swing.JLabel();
085            jLabel3 = new javax.swing.JLabel();
086            jLabel4 = new javax.swing.JLabel();
087    
088            // Set the url text field to 50 to drive the width of the dialog
089            urlTextField = new javax.swing.JTextField(50);
090    
091            usernameTextField = new javax.swing.JTextField();
092            passwordTextField = new javax.swing.JTextField();
093            driverClassTextField = new javax.swing.JTextField();
094            acceptButton = new javax.swing.JButton();
095            cancelButton = new javax.swing.JButton();
096    
097            getContentPane().setLayout(new java.awt.GridBagLayout());
098    
099            setTitle(getResourceConverter().getString("preferences.pane.title","Workbench Preferences"));
100            addWindowListener(new java.awt.event.WindowAdapter() {
101                public void windowClosing(java.awt.event.WindowEvent evt) {
102                    closeDialog(evt);
103                }
104            });
105    
106            jPanel1.setLayout(new java.awt.GridBagLayout());
107    
108            jLabel1.setText(getResourceConverter().getString("preferences.driverClassName.title","Driver Class Name"));
109            gridBagConstraints = new java.awt.GridBagConstraints();
110            gridBagConstraints.gridx = 0;
111            gridBagConstraints.gridy = 0;
112            gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
113            gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
114            jPanel1.add(jLabel1, gridBagConstraints);
115    
116            jLabel2.setText(getResourceConverter().getString("preferences.connectionURL.title","Connection URL"));
117            gridBagConstraints = new java.awt.GridBagConstraints();
118            gridBagConstraints.gridx = 0;
119            gridBagConstraints.gridy = 1;
120            gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
121            gridBagConstraints.weighty = 1.0;
122            gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
123            jPanel1.add(jLabel2, gridBagConstraints);
124    
125            jLabel3.setText(getResourceConverter().getString("preferences.userName.title","User name"));
126            gridBagConstraints = new java.awt.GridBagConstraints();
127            gridBagConstraints.gridx = 0;
128            gridBagConstraints.gridy = 2;
129            gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
130            gridBagConstraints.weighty = 1.0;
131            gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
132            jPanel1.add(jLabel3, gridBagConstraints);
133    
134            jLabel4.setText(getResourceConverter().getString("preferences.password.title","Password"));
135            gridBagConstraints = new java.awt.GridBagConstraints();
136            gridBagConstraints.gridx = 0;
137            gridBagConstraints.gridy = 3;
138            gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
139            gridBagConstraints.weighty = 1.0;
140            gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
141            jPanel1.add(jLabel4, gridBagConstraints);
142    
143            gridBagConstraints = new java.awt.GridBagConstraints();
144            gridBagConstraints.gridx = 1;
145            gridBagConstraints.gridy = 1;
146            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
147            gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
148            gridBagConstraints.weightx = 1.0;
149            gridBagConstraints.weighty = 1.0;
150            gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
151            jPanel1.add(urlTextField, gridBagConstraints);
152    
153            usernameTextField.setText("");
154            gridBagConstraints = new java.awt.GridBagConstraints();
155            gridBagConstraints.gridx = 1;
156            gridBagConstraints.gridy = 2;
157            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
158            gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
159            gridBagConstraints.weightx = 1.0;
160            gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
161            jPanel1.add(usernameTextField, gridBagConstraints);
162    
163            passwordTextField.setText("");
164            gridBagConstraints = new java.awt.GridBagConstraints();
165            gridBagConstraints.gridx = 1;
166            gridBagConstraints.gridy = 3;
167            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
168            gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
169            gridBagConstraints.weightx = 1.0;
170            gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
171            jPanel1.add(passwordTextField, gridBagConstraints);
172    
173            driverClassTextField.setText("org.gjt.mm.mysql.Driver");
174            gridBagConstraints = new java.awt.GridBagConstraints();
175            gridBagConstraints.gridx = 1;
176            gridBagConstraints.gridy = 0;
177            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
178            gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
179            gridBagConstraints.weightx = 1.0;
180            gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
181            jPanel1.add(driverClassTextField, gridBagConstraints);
182    
183            jTabbedPane1.addTab(getResourceConverter().getString("preferences.jdbcPanel.title","JDBC"), jPanel1);
184    
185            gridBagConstraints = new java.awt.GridBagConstraints();
186            gridBagConstraints.gridwidth = 2;
187            gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
188            gridBagConstraints.weightx = 1.0;
189            gridBagConstraints.weighty = 1.0;
190            getContentPane().add(jTabbedPane1, gridBagConstraints);
191    
192            cancelButton.setText(getResourceConverter().getString("preferences.cancelButton.title","Cancel"));
193            cancelButton.addActionListener(new java.awt.event.ActionListener() {
194                public void actionPerformed(java.awt.event.ActionEvent evt) {
195                    cancelButtonActionPerformed(evt);
196                }
197            });
198    
199            gridBagConstraints = new java.awt.GridBagConstraints();
200            gridBagConstraints.gridx = 1;
201            gridBagConstraints.gridy = 1;
202            gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
203            gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
204            getContentPane().add(cancelButton, gridBagConstraints);
205    
206            acceptButton.setText(getResourceConverter().getString("preferences.acceptButton.title","Accept"));
207            acceptButton.addActionListener(new java.awt.event.ActionListener() {
208                public void actionPerformed(java.awt.event.ActionEvent evt) {
209                    acceptButtonActionPerformed(evt);
210                }
211            });
212    
213            gridBagConstraints = new java.awt.GridBagConstraints();
214            gridBagConstraints.gridx = 1;
215            gridBagConstraints.gridy = 1;
216            gridBagConstraints.weightx = 1.0;
217            gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
218            gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 80);
219            getContentPane().add(acceptButton, gridBagConstraints);
220    
221            pack();
222        } //GEN-END:initComponents
223    
224        private void acceptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptButtonActionPerformed
225            accepted = true;
226            hide();
227        } //GEN-LAST:event_acceptButtonActionPerformed
228    
229        private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
230            accepted = false;
231            hide();
232        } //GEN-LAST:event_cancelButtonActionPerformed
233    
234        /** Closes the dialog */
235        private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
236            setVisible(false);
237            dispose();
238        } //GEN-LAST:event_closeDialog
239    
240        /**
241         * @param args the command line arguments
242         */
243        public static void main(String args[]) {
244            new PreferencesDialog(new javax.swing.JFrame(), true).show();
245        }
246    
247    
248        // Variables declaration - do not modify//GEN-BEGIN:variables
249        private javax.swing.JTextField driverClassTextField;
250        private javax.swing.JPanel jPanel1;
251        private javax.swing.JTextField urlTextField;
252        private javax.swing.JTextField usernameTextField;
253        private javax.swing.JTextField passwordTextField;
254        private javax.swing.JButton acceptButton;
255        private javax.swing.JTabbedPane jTabbedPane1;
256        private javax.swing.JButton cancelButton;
257        private javax.swing.JLabel jLabel4;
258        private javax.swing.JLabel jLabel3;
259        private javax.swing.JLabel jLabel2;
260        private javax.swing.JLabel jLabel1;
261        // End of variables declaration//GEN-END:variables
262    
263    }
264    
265    // End PreferencesDialog.java