Mercurial > hg > ltpda
view src/MPipeline2/src/mpipeline/ltpdapreferences/ExtensionsPrefGroupPanel.java @ 13:e05504b18072 database-connection-manager
Move more functions to utils.repository
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 16:20:06 +0100 |
parents | f0afece42f48 |
children |
line wrap: on
line source
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * ModelsPrefGroupPanel.java * * Created on Aug 15, 2010, 12:53:49 PM */ package mpipeline.ltpdapreferences; import java.io.File; import java.util.Iterator; import java.util.Observable; import java.util.Observer; import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JList; import javax.swing.JTextField; import mpipeline.utils.Utils; /** * * @author hewitson */ public class ExtensionsPrefGroupPanel extends javax.swing.JPanel implements Observer { private ExtensionsPrefGroup extensionsPrefs; private Object removePaths[]; // Backup for MATLAB because java deletes the path before MATLAB is called. /** Creates new form ExtensionsPrefGroupPanel */ public ExtensionsPrefGroupPanel(ExtensionsPrefGroup prefs) { this.extensionsPrefs = prefs; initComponents(); DefaultListModel mdl = new DefaultListModel(); searchPathList.setModel(mdl); setPreferences(); extensionsPrefs.addObserver(this); } public void setPreferences() { updateExtensions(); } /** 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(); searchPathList = new javax.swing.JList(); newPathTextField = new javax.swing.JTextField(); addPathBtn = new javax.swing.JButton(); browseBtn = new javax.swing.JButton(); removePathBtn = new javax.swing.JButton(); jScrollPane1.setViewportView(searchPathList); addPathBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpipeline/icons/add_small.png"))); // NOI18N addPathBtn.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/mpipeline/icons/add_small_ro.png"))); // NOI18N addPathBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addPathBtnActionPerformed(evt); } }); browseBtn.setText("Browse"); browseBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { browseBtnActionPerformed(evt); } }); removePathBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpipeline/icons/subtract_small.png"))); // NOI18N removePathBtn.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/mpipeline/icons/subtract_small_ro.png"))); // NOI18N removePathBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { removePathBtnActionPerformed(evt); } }); 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(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(addPathBtn) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(removePathBtn)) .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 386, Short.MAX_VALUE)) .addContainerGap()) .add(layout.createSequentialGroup() .add(newPathTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 314, Short.MAX_VALUE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(browseBtn) .add(20, 20, 20)))) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .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.UNRELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(addPathBtn) .add(removePathBtn)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER) .add(newPathTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(browseBtn)) .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); }// </editor-fold>//GEN-END:initComponents private void addPathBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPathBtnActionPerformed if (newPathTextField.getText().length() != 0) { extensionsPrefs.addSearchPath(newPathTextField.getText()); } }//GEN-LAST:event_addPathBtnActionPerformed private void removePathBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removePathBtnActionPerformed // get selected values removePaths = searchPathList.getSelectedValues(); extensionsPrefs.removePaths(removePaths); }//GEN-LAST:event_removePathBtnActionPerformed private void browseBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseBtnActionPerformed File newPath = Utils.getDirectory(this, ""); if (newPath != null) { newPathTextField.setText(newPath.getPath()); } }//GEN-LAST:event_browseBtnActionPerformed public void update(Observable o, Object arg) { if (arg != null) { if (arg instanceof Integer) { int identifier = ((Integer) arg).intValue(); if (identifier == ExtensionsPrefGroup.EXTENSION_SEARCH_PATHS_CHANGED) { updateExtensions(); } else { System.err.println("Unknown observation argument: " + arg.toString()); } } } } private void updateExtensions() { DefaultListModel mmdl = (DefaultListModel) searchPathList.getModel(); mmdl.removeAllElements(); Iterator it = extensionsPrefs.getSearchPaths().iterator(); while (it.hasNext()) { String path = (String) it.next(); mmdl.addElement(path); } } public JButton getAddPathBtn() { return addPathBtn; } public JButton getRemovePathBtn() { return removePathBtn; } public JTextField getNewPathTextField() { return newPathTextField; } public JList getSearchPathList() { return searchPathList; } public Object[] getRemovePaths() { return removePaths; } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton addPathBtn; private javax.swing.JButton browseBtn; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextField newPathTextField; private javax.swing.JButton removePathBtn; private javax.swing.JList searchPathList; // End of variables declaration//GEN-END:variables }