Mercurial > hg > ltpda
view src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryPrefGroupPanel.java @ 43:bc767aaa99a8
CVS Update
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Tue, 06 Dec 2011 11:09:25 +0100 |
parents | f0afece42f48 |
children | 5a49956df427 |
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.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Observable; import java.util.Observer; import javax.swing.DefaultListModel; 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(); DefaultListModel mdl = new DefaultListModel(); hostnameList.setModel(mdl); setPreferences(); repoPrefs.addObserver(this); expirySpinner.addChangeListener(this); } public void setPreferences() { updateHostnames(); 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() { jScrollPane1 = new javax.swing.JScrollPane(); hostnameList = new javax.swing.JList(); newHostnameTextField = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); addBtn = new javax.swing.JButton(); removeBtn = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); expirySpinner = new javax.swing.JSpinner(); jScrollPane1.setViewportView(hostnameList); jLabel1.setText("New Hostname:"); addBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpipeline/icons/add_small.png"))); // NOI18N addBtn.setRolloverEnabled(true); addBtn.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/mpipeline/icons/add_small_ro.png"))); // NOI18N addBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addBtnActionPerformed(evt); } }); removeBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpipeline/icons/subtract_small.png"))); // NOI18N removeBtn.setRolloverEnabled(true); removeBtn.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/mpipeline/icons/subtract_small_ro.png"))); // NOI18N removeBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { removeBtnActionPerformed(evt); } }); jLabel2.setText("User-defined LTPDA Repository Hostnames"); jLabel3.setText("Repository Login Expiry (s):"); expirySpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 10000000, 10)); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(removeBtn) .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 372, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel2) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(layout.createSequentialGroup() .add(jLabel3) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(expirySpinner)) .add(layout.createSequentialGroup() .add(jLabel1) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(newHostnameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE))) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(addBtn))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(jLabel2) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel1) .add(newHostnameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(addBtn)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(removeBtn) .add(10, 10, 10) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER) .add(jLabel3) .add(expirySpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); }// </editor-fold>//GEN-END:initComponents private void removeBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeBtnActionPerformed // get selected index Object objs[] = hostnameList.getSelectedValues(); repoPrefs.removeHostnames(objs); }//GEN-LAST:event_removeBtnActionPerformed private void addBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addBtnActionPerformed if (newHostnameTextField.getText().length() != 0) { repoPrefs.addHostname(newHostnameTextField.getText()); } }//GEN-LAST:event_addBtnActionPerformed public void update(Observable o, Object arg) { if (arg != null) { if (arg instanceof Integer) { int identifier = ((Integer) arg).intValue(); if (identifier == RepositoryPrefGroup.REPOSITORY_EXPIRY_CHANGED) { updateExpiry(); } else if (identifier == RepositoryPrefGroup.REPOSITORY_HOSTNAMES_CHANGED) { updateHostnames(); } else { System.err.println("Unknown observation argument: " + arg.toString()); } } } } private void updateExpiry() { expirySpinner.setValue(repoPrefs.getExpiry()); } private void updateHostnames() { DefaultListModel mmdl = (DefaultListModel) hostnameList.getModel(); mmdl.removeAllElements(); Iterator it = repoPrefs.getHostnames().iterator(); while (it.hasNext()) { String path = (String) it.next(); mmdl.addElement(path); } } public void stateChanged(ChangeEvent e) { if (e.getSource() == expirySpinner) { repoPrefs.setExpiry((Integer) expirySpinner.getValue()); } } public void actionPerformed(ActionEvent e) { } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton addBtn; private javax.swing.JSpinner expirySpinner; private javax.swing.JList hostnameList; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextField newHostnameTextField; private javax.swing.JButton removeBtn; // End of variables declaration//GEN-END:variables }