/************************************************************************* * * * EJBCA Community: The OpenSource Certificate Authority * * * * This software is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or any later version. * * * * See terms of license at gnu.org. * * * *************************************************************************/ package org.ejbca.batchenrollmentgui; import java.io.File; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import org.apache.log4j.Logger; /** * Dialog for settings. * * @author markus * @version $Id: SettingsDialog.java 19902 2014-09-30 14:32:24Z anatom $ */ public class SettingsDialog extends javax.swing.JDialog { private static final long serialVersionUID = -1315993902451329011L; /** Logger for this class. */ private static final Logger LOG = Logger.getLogger(SettingsDialog.class); private Settings settings; private Settings okSettings; /** Creates new form SettingsDialog. */ public SettingsDialog(java.awt.Frame parent, boolean modal, Settings oldSettings) { super(parent, modal); initComponents(); LOG.debug("Settings: " + settings); if (oldSettings != null) { settings = new Settings(oldSettings); truststorePath.setText(settings.getTruststorePath()); } } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // //GEN-BEGIN:initComponents private void initComponents() { cancelButton = new javax.swing.JButton(); okButton = new javax.swing.JButton(); jTabbedPane1 = new javax.swing.JTabbedPane(); jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); truststorePath = new javax.swing.JTextField(); truststoreBrowseButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(org.ejbca.batchenrollmentgui.BatchEnrollmentGUIApp.class).getContext().getResourceMap(SettingsDialog.class); setTitle(resourceMap.getString("Form.title")); // NOI18N setLocationByPlatform(true); setName("Form"); // NOI18N cancelButton.setText(resourceMap.getString("cancelButton.text")); // NOI18N cancelButton.setName("cancelButton"); // NOI18N cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(evt); } }); okButton.setText(resourceMap.getString("okButton.text")); // NOI18N okButton.setName("okButton"); // NOI18N okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonActionPerformed(evt); } }); jTabbedPane1.setName("jTabbedPane1"); // NOI18N jPanel1.setName("jPanel1"); // NOI18N jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N jLabel1.setName("jLabel1"); // NOI18N truststorePath.setText(resourceMap.getString("truststorePath.text")); // NOI18N truststorePath.setName("truststorePath"); // NOI18N truststoreBrowseButton.setText(resourceMap.getString("truststoreBrowseButton.text")); // NOI18N truststoreBrowseButton.setName("truststoreBrowseButton"); // NOI18N truststoreBrowseButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { truststoreBrowseButtonActionPerformed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addComponent(truststorePath, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(truststoreBrowseButton))) .addContainerGap()) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(truststorePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(truststoreBrowseButton)) .addContainerGap(217, Short.MAX_VALUE)) ); jTabbedPane1.addTab(resourceMap.getString("jPanel1.TabConstraints.tabTitle"), jPanel1); // NOI18N javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(okButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(cancelButton)) .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)) .addContainerGap()) ); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton}); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 324, Short.MAX_VALUE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cancelButton) .addComponent(okButton)) .addContainerGap()) ); pack(); }// //GEN-END:initComponents private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//NOPMD //GEN-FIRST:event_cancelButtonActionPerformed dispose(); }//GEN-LAST:event_cancelButtonActionPerformed private void truststoreBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//NOPMD //GEN-FIRST:event_truststoreBrowseButtonActionPerformed final JFileChooser chooser = new JFileChooser(); chooser.setSelectedFile(new File(truststorePath.getText())); final int result = chooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { truststorePath.setText( chooser.getSelectedFile().getAbsolutePath()); } }//GEN-LAST:event_truststoreBrowseButtonActionPerformed private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//NOPMD //GEN-FIRST:event_okButtonActionPerformed settings.setTruststorePath(truststorePath.getText()); if (new File(settings.getTruststorePath()).exists()) { okSettings = settings; dispose(); } else { JOptionPane.showMessageDialog(this, "Non-existing file: " + settings.getTruststorePath(), "Settings", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_okButtonActionPerformed public Settings getSettings() { return okSettings; } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton cancelButton; private javax.swing.JLabel jLabel1; private javax.swing.JPanel jPanel1; private javax.swing.JTabbedPane jTabbedPane1; private javax.swing.JButton okButton; private javax.swing.JButton truststoreBrowseButton; private javax.swing.JTextField truststorePath; // End of variables declaration//GEN-END:variables }