|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.javacvs.customizers; import java.util.*; import javax.swing.*; import org.openide.util.*; import java.io.File; import org.netbeans.modules.javacvs.FsExport; import org.netbeans.modules.javacvs.commands.StandardClientProvider; import org.netbeans.modules.javacvs.commands.CvsExport; import org.netbeans.lib.cvsclient.command.*; import org.netbeans.lib.cvsclient.command.export.*; import java.beans.Customizer; import javax.accessibility.*; /** * * @author mkleint * @version */ public class ExportParamInput extends javax.swing.JPanel implements Customizer { private static final String K_NONE = NbBundle.getBundle(ExportParamInput.class).getString("ImportParamInput.NoSubstitution"); //NOI18N private static final String K_BINARY = NbBundle.getBundle(ExportParamInput.class).getString("ImportParamInput.BinarySubst"); //NOI18N private static final String K_KEYWORD_VALUE = NbBundle.getBundle(ExportParamInput.class).getString("ImportParamInput.KeywordValueSubst"); //NOI18N private static final String K_KEYWORD_VALUE_LOCKER = NbBundle.getBundle(ExportParamInput.class).getString("ImportParamInput.KeywordValueLockerSubst"); //NOI18N private static final String K_KEYWORD = NbBundle.getBundle(ExportParamInput.class).getString("ImportParamInput.Keyword"); //NOI18N private static final String K_VALUE = NbBundle.getBundle(ExportParamInput.class).getString("ImportParamInput.Value"); //NOI18N private static final String K_OLD = NbBundle.getBundle(ExportParamInput.class).getString("ImportParamInput.Old"); //NOI18N private Object[] comboValues = new Object[] { K_NONE, K_BINARY, K_KEYWORD_VALUE, K_KEYWORD_VALUE_LOCKER, K_KEYWORD, K_VALUE, K_OLD} ; private KeywordSubstitutionOptions[] cvsValues = new KeywordSubstitutionOptions[] { null, KeywordSubstitutionOptions.BINARY, KeywordSubstitutionOptions.DEFAULT, KeywordSubstitutionOptions.DEFAULT_LOCKER, KeywordSubstitutionOptions.ONLY_KEYWORDS, KeywordSubstitutionOptions.ONLY_VALUES, KeywordSubstitutionOptions.OLD_VALUES }; // needed to set the setRecursive() property private FsExport exportCommand; private List commandList; private String rememberedLocalPath; private CustomizerPropChangeSupport support; /** Creates new form LogParamInput */ public ExportParamInput() { initComponents(); initAccessibility(); if (support == null) { support = new CustomizerPropChangeSupport(this); } lblKeyword.setDisplayedMnemonic(bundle.getString("ExportParamInput.lblKeyword.mnemonic").charAt(0)); //NOI18N lblKeyword.setLabelFor(cbKeyword); lblDestDir.setDisplayedMnemonic(bundle.getString("ExportParamInput.lblDestDir.mnemonic").charAt(0)); //NOI18N lblDestDir.setLabelFor(txDestDir); lblModules.setDisplayedMnemonic(bundle.getString("ExportParamInput.lblModules.mnemonic").charAt(0)); //NOI18N lblModules.setLabelFor(txModules); cbExportByDate.setMnemonic(bundle.getString("ExportParamInput.cbExportByDate.mnemonic").charAt(0)); //NOI18N cbExportByRevision.setMnemonic(bundle.getString("ExportParamInput.cbExportByRevision.mnemonic").charAt(0)); //NOI18N cbPruneEmpty.setMnemonic(bundle.getString("ExportParamInput.cbPruneEmpty.mnemonic").charAt(0)); //NOI18N cbRecursive.setMnemonic(bundle.getString("ExportParamInput.cbRecursive.mnemonic").charAt(0)); //NOI18N cbUseHead.setMnemonic(bundle.getString("ExportParamInput.cbUseHead.mnemonic").charAt(0)); //NOI18N cbKeyword.setModel(new DefaultComboBoxModel(comboValues)); cbKeyword.setSelectedIndex(0); //TODO if all files in command are dirs, disable message + keyword subst. java.awt.event.ActionListener actionList = new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { setData(); } }; cbExportByDate.addActionListener(actionList); cbExportByRevision.addActionListener(actionList); cbPruneEmpty.addActionListener(actionList); cbRecursive.addActionListener(actionList); cbUseHead.addActionListener(actionList); cbKeyword.addActionListener(actionList); txExportByDate.addActionListener(actionList); txExportByRevision.addActionListener(actionList); txModules.addActionListener(actionList); txDestDir.addActionListener(actionList); java.awt.event.FocusAdapter focusList = new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { setData(); } }; javax.swing.event.DocumentListener docList = new javax.swing.event.DocumentListener() { public void insertUpdate(javax.swing.event.DocumentEvent e) { setData(); } public void removeUpdate(javax.swing.event.DocumentEvent e) { setData(); } public void changedUpdate(javax.swing.event.DocumentEvent e) { setData(); } }; txDestDir.addFocusListener(focusList); txModules.addFocusListener(focusList); txExportByDate.addFocusListener(focusList); txExportByRevision.addFocusListener(focusList); txDestDir.getDocument().addDocumentListener(docList); txModules.getDocument().addDocumentListener(docList); txExportByDate.getDocument().addDocumentListener(docList); txExportByRevision.getDocument().addDocumentListener(docList); } /** 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 FormEditor. */ private void initComponents() {//GEN-BEGIN:initComponents java.awt.GridBagConstraints gridBagConstraints; lblModules = new javax.swing.JLabel(); txModules = new javax.swing.JTextField(); lblDestDir = new javax.swing.JLabel(); txDestDir = new javax.swing.JTextField(); lblKeyword = new javax.swing.JLabel(); cbKeyword = new javax.swing.JComboBox(); cbRecursive = new javax.swing.JCheckBox(); cbPruneEmpty = new javax.swing.JCheckBox(); cbExportByDate = new javax.swing.JCheckBox(); txExportByDate = new javax.swing.JTextField(); cbExportByRevision = new javax.swing.JCheckBox(); txExportByRevision = new javax.swing.JTextField(); cbUseHead = new javax.swing.JCheckBox(); setLayout(new java.awt.GridBagLayout()); lblModules.setText(org.openide.util.NbBundle.getBundle(ExportParamInput.class).getString("ExportParamInput.lblModules")); lblModules.setLabelFor(txModules); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0); add(lblModules, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 11); add(txModules, gridBagConstraints); lblDestDir.setText(org.openide.util.NbBundle.getBundle(ExportParamInput.class).getString("ExportParamInput.lblDestDir.text")); lblDestDir.setLabelFor(txDestDir); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 0); add(lblDestDir, gridBagConstraints); txDestDir.setPreferredSize(new java.awt.Dimension(70, 21)); txDestDir.setMinimumSize(new java.awt.Dimension(30, 21)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 11); add(txDestDir, gridBagConstraints); lblKeyword.setText(org.openide.util.NbBundle.getBundle(ExportParamInput.class).getString("ExportParamInput.lblKeyword.text")); lblKeyword.setLabelFor(cbKeyword); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 0); add(lblKeyword, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 11); add(cbKeyword, gridBagConstraints); cbRecursive.setText(org.openide.util.NbBundle.getBundle(ExportParamInput.class).getString("ExportParamInput.cbRecursive")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 0); add(cbRecursive, gridBagConstraints); cbPruneEmpty.setText(org.openide.util.NbBundle.getBundle(ExportParamInput.class).getString("ExportParamInput.cbPruneEmpty")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0); add(cbPruneEmpty, gridBagConstraints); cbExportByDate.setText(org.openide.util.NbBundle.getBundle(ExportParamInput.class).getString("ExportParamInput.cbExportByDate")); cbExportByDate.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cbExportByDateActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 5; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 0); add(cbExportByDate, gridBagConstraints); txExportByDate.setColumns(10); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 5; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 0); add(txExportByDate, gridBagConstraints); cbExportByRevision.setText(org.openide.util.NbBundle.getBundle(ExportParamInput.class).getString("ExportParamInput.cbExportByRevision")); cbExportByRevision.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cbExportByRevisionActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 6; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 12, 11, 0); add(cbExportByRevision, gridBagConstraints); txExportByRevision.setColumns(10); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 6; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(7, 12, 11, 0); add(txExportByRevision, gridBagConstraints); cbUseHead.setText(org.openide.util.NbBundle.getBundle(ExportParamInput.class).getString("ExportParamInput.cbUseHead")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 6; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 5, 11, 11); add(cbUseHead, gridBagConstraints); }//GEN-END:initComponents private void cbExportByRevisionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbExportByRevisionActionPerformed // Add your handling code here: enableFieldsAndBox(); }//GEN-LAST:event_cbExportByRevisionActionPerformed private void cbExportByDateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbExportByDateActionPerformed // Add your handling code here: enableFieldsAndBox(); }//GEN-LAST:event_cbExportByDateActionPerformed private void enableFieldsAndBox() { txExportByRevision.setEnabled(cbExportByRevision.isSelected()); txExportByDate.setEnabled(cbExportByDate.isSelected()); if (cbExportByDate.isSelected() || cbExportByRevision.isSelected()) { cbUseHead.setEnabled(true); } else { cbUseHead.setSelected(false); cbUseHead.setEnabled(false); } } protected void setData() { if (commandList != null) { Iterator it = commandList.iterator(); FsExport fsCheck = null; while (it.hasNext()) { fsCheck = (FsExport)it.next(); setData(fsCheck); } if (fsCheck != null) { support.firePropertyChange(fsCheck); } } else { setData(exportCommand); support.firePropertyChange(exportCommand); } } protected void setData(FsExport exportCom) { if (exportCom == null) return; exportCom.setPruneDirectories(cbPruneEmpty.isSelected()); exportCom.setUseHeadIfNotFound(cbUseHead.isSelected()); exportCom.setRecursive(!cbRecursive.isSelected()); if (cbExportByDate.isSelected()) { exportCom.setExportByDate(txExportByDate.getText().trim()); } else { exportCom.setExportByDate(null); } if (cbExportByRevision.isSelected()) { exportCom.setExportByRevision(txExportByRevision.getText().trim()); } else { exportCom.setExportByRevision(null); } if (txDestDir.getText().trim().length() > 0) { setExportPath(txDestDir.getText().trim(), exportCom); } else { StandardClientProvider prov = getClientProvider(exportCom); if (prov != null) { prov.setLocalPath(rememberedLocalPath); } exportCom.setExportDirectory(null); } exportCom.setModules(getModArray()); exportCom.setKeywordSubstitutionOptions(cvsValues[cbKeyword.getSelectedIndex()]); } private void setExportPath(String directory, FsExport exportCom) { File fil = new File(directory); String residuum = ""; boolean found = true; while (!fil.exists()) { residuum = fil.getName() + File.separator + residuum; if (fil.getParentFile() != null) { fil = fil.getParentFile(); } else { found = false; break; } } StandardClientProvider prov = getClientProvider(exportCom); if (found) { if (prov != null) { prov.setLocalPath(fil.getAbsolutePath()); if (residuum.length() > 0) { if (residuum.endsWith(File.separator)) { residuum = residuum.substring(0, residuum.length() -1); } exportCom.setExportDirectory(residuum); } else { exportCom.setExportDirectory(null); } } } else { exportCom.setExportDirectory(directory); if (prov != null) { prov.setLocalPath(rememberedLocalPath); } } } private StandardClientProvider getClientProvider(FsExport exportCom) { if (exportCom instanceof CvsExport.ExportImpl) { CvsExport.ExportImpl impl = (CvsExport.ExportImpl)exportCom; CvsExport export = (CvsExport)impl.getOuterClassInstance(); StandardClientProvider prov = (StandardClientProvider)export.getClientProvider(); return prov; } return null; } public void getData(FsExport exportCom) { if (exportCom == null) return; cbRecursive.setSelected(!exportCom.isRecursive()); cbPruneEmpty.setSelected(exportCom.isPruneDirectories()); cbUseHead.setSelected(exportCom.isUseHeadIfNotFound()); if (exportCom.getExportByDate() != null) { cbExportByDate.setSelected(true); txExportByDate.setText(exportCom.getExportByDate()); } else { cbExportByDate.setSelected(false); txExportByDate.setText(""); //NOI18N } if (exportCom.getExportByRevision() != null) { cbExportByRevision.setSelected(true); txExportByRevision.setText(exportCom.getExportByRevision()); } else { cbExportByRevision.setSelected(false); txExportByRevision.setText(""); //NOI18N } if (exportCom.getExportDirectory() != null) { txDestDir.setText(exportCom.getExportDirectory()); } else { txDestDir.setText(""); //NOI18N } if (exportCom.getModules() != null) { txModules.setText(fromArrayToCommas(exportCom.getModules(), " ")); } else { txModules.setText(""); } enableFieldsAndBox(); for (int index = 0; index < cvsValues.length; index++) { if (cvsValues[index] == null) { if (exportCom.getKeywordSubstitutionOptions() == null) { cbKeyword.setSelectedIndex(index); return; } } else { if (cvsValues[index].equals(exportCom.getKeywordSubstitutionOptions())) { cbKeyword.setSelectedIndex(index); return; } } } support.firePropertyChange(exportCom); } private String fromArrayToCommas(String[] arr, String separator) { if (arr != null) { StringBuffer buff = new StringBuffer(); for (int i = 0; i < arr.length; i++) { buff.append(arr[i]); if (i != arr.length - 1) { buff.append(separator); } } return buff.toString(); } else { return ""; } } private String[] fromCommasToArray(String commas, String separator) { StringTokenizer tok = new StringTokenizer(commas, separator, false); LinkedList list = new LinkedList(); while (tok.hasMoreTokens()) { String item = tok.nextToken(); list.add(item); } if (list.size() > 0) { String[] arr = new String[list.size()]; arr = (String[])list.toArray(arr); return arr; } return null; } /** * The Customizer's setObject method. However the customizer accepts both the * FsDiff instance and a list of FsDiff instances. In case of a list, * it loads switches from the first comand in row, however sets all the instances. */ public void setObject(java.lang.Object obj) { if (obj instanceof FsExport) { exportCommand = (FsExport)obj; StandardClientProvider prov = getClientProvider(exportCommand); if (prov != null) { rememberedLocalPath = prov.getLocalPath(); } getData(exportCommand); commandList = null; } if (obj instanceof List) { commandList = (List)obj; exportCommand = null; if (commandList.size() > 0) { FsExport check = (FsExport)commandList.get(0); StandardClientProvider prov = getClientProvider(check); if (prov != null) { rememberedLocalPath = prov.getLocalPath(); } getData(check); } } } public void removePropertyChangeListener(java.beans.PropertyChangeListener propertyChangeListener) { if (support == null) { support = new CustomizerPropChangeSupport(this); } support.removePropertyChangeListener(propertyChangeListener); } public void addPropertyChangeListener(java.beans.PropertyChangeListener propertyChangeListener) { if (support == null) { support = new CustomizerPropChangeSupport(this); } support.addPropertyChangeListener(propertyChangeListener); } protected void firePropertyChange(java.lang.String str, java.lang.Object obj, java.lang.Object obj2) { if (support == null) { support = new CustomizerPropChangeSupport(this); } support.firePropertyChange(str, obj, obj2); } private String[] getModArray() { String modules = txModules.getText(); StringTokenizer tok = new StringTokenizer(modules, " ", false); //NOI18N String[] modArray = new String[tok.countTokens()]; int index = 0; while (tok.hasMoreTokens()) { modArray[index] = tok.nextToken(); index = index + 1; } return modArray; } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JCheckBox cbUseHead; private javax.swing.JTextField txDestDir; private javax.swing.JTextField txModules; private javax.swing.JTextField txExportByDate; private javax.swing.JCheckBox cbRecursive; private javax.swing.JLabel lblKeyword; private javax.swing.JCheckBox cbExportByDate; private javax.swing.JCheckBox cbExportByRevision; private javax.swing.JTextField txExportByRevision; private javax.swing.JCheckBox cbPruneEmpty; private javax.swing.JLabel lblDestDir; private javax.swing.JLabel lblModules; private javax.swing.JComboBox cbKeyword; // End of variables declaration//GEN-END:variables private static final java.util.ResourceBundle bundle = NbBundle.getBundle(ExportParamInput.class); //NOI18N private void initAccessibility() { AccessibleContext context = this.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_ExportParamInput")); context = cbRecursive.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_ExportParamInput.cbRecursive")); context = cbPruneEmpty.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_ExportParamInput.cbPruneEmpty")); context = cbExportByDate.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_ExportParamInput.cbExportByDate")); context = txExportByDate.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_ExportParamInput.txExportByDate")); context = cbExportByRevision.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_ExportParamInput.cbExportByRevision")); context = txExportByRevision.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_ExportParamInput.txExportByRevision")); context = cbUseHead.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_ExportParamInput.cbUseHead")); context = cbKeyword.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_ExportParamInput.cbKeyword")); context = txDestDir.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_ExportParamInput.txDestDir")); context = txModules.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_ExportParamInput.txModules")); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.