Mercurial > hg > ltpda
view src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryPrefGroupPanel.java @ 5:5a49956df427 database-connection-manager
LTPDAPreferences panel for new LTPDADatabaseConnectionManager
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 16:20:06 +0100 |
parents | f0afece42f48 |
children | 5e7477b94d94 |
line wrap: on
line source
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * RepositoryPrefGroupPanel.java * * Created on Aug 15, 2010, 3:22:54 PM */ package mpipeline.ltpdapreferences; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Observable; import java.util.Observer; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; /** * * @author hewitson */ public class RepositoryPrefGroupPanel extends javax.swing.JPanel implements Observer, ChangeListener, ActionListener { private RepositoryPrefGroup repoPrefs; /** Creates new form RepositoryPrefGroupPanel */ public RepositoryPrefGroupPanel(RepositoryPrefGroup repoPrefs) { this.repoPrefs = repoPrefs; initComponents(); setPreferences(); repoPrefs.addObserver(this); maxConnectionsNumberSpinner.addChangeListener(this); cachePasswordComboBox.addActionListener(this); expirySpinner.addChangeListener(this); } public void setPreferences() { updateMaxConnectionsNumber(); updateCachePasswords(); updateExpiry(); } /** 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. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel3 = new javax.swing.JLabel(); expirySpinner = new javax.swing.JSpinner(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); maxConnectionsNumberSpinner = new javax.swing.JSpinner(); cachePasswordComboBox = new javax.swing.JComboBox(); jLabel4 = new javax.swing.JLabel(); jLabel3.setText("Cached passwords expire after:"); expirySpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 10000000, 10)); jLabel1.setText("Maximum number of simultaneous database connections:"); jLabel2.setText("Cache password:"); maxConnectionsNumberSpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(1), Integer.valueOf(1), null, Integer.valueOf(1))); cachePasswordComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "No", "Yes", "Ask" })); jLabel4.setText("[seconds]"); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(jLabel1) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(maxConnectionsNumberSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 48, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() .add(jLabel2) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(cachePasswordComboBox, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel3)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(expirySpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 59, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jLabel4))) .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel1) .add(maxConnectionsNumberSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel2) .add(cachePasswordComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel3) .add(expirySpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(jLabel4)) .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); }// </editor-fold>//GEN-END:initComponents public void update(Observable o, Object arg) { if (arg != null) { if (arg instanceof Integer) { int identifier = ((Integer) arg).intValue(); switch (identifier) { case RepositoryPrefGroup.REPOSITORY_EXPIRY_CHANGED: updateExpiry(); break; case RepositoryPrefGroup.REPOSITORY_MAX_CONNECTIONS_NUMBER_CHANGED: updateMaxConnectionsNumber(); break; case RepositoryPrefGroup.REPOSITORY_CACHE_PASSWORD_CHANGED: updateCachePasswords(); break; default: System.err.println("Unknown observation argument: " + arg.toString()); } } } } private void updateMaxConnectionsNumber() { maxConnectionsNumberSpinner.setValue(repoPrefs.getMaxConnectionsNumber()); } private void updateCachePasswords() { cachePasswordComboBox.setSelectedIndex(repoPrefs.getCachePassword().intValue()); } private void updateExpiry() { expirySpinner.setValue(repoPrefs.getExpiry()); } public void stateChanged(ChangeEvent e) { if (e.getSource() == expirySpinner) { repoPrefs.setExpiry((Integer) expirySpinner.getValue()); return; } if (e.getSource() == maxConnectionsNumberSpinner) { repoPrefs.setMaxConnectionsNumber((Integer) maxConnectionsNumberSpinner.getValue()); return; } } public void actionPerformed(ActionEvent e) { if (e.getSource() == cachePasswordComboBox) { repoPrefs.setCachePassword((Integer) cachePasswordComboBox.getSelectedIndex()); return; } } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox cachePasswordComboBox; private javax.swing.JSpinner expirySpinner; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JSpinner maxConnectionsNumberSpinner; // End of variables declaration//GEN-END:variables }