|
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 org.netbeans.modules.javacvs.FsGlobalOptions; import org.netbeans.modules.javacvs.CvsCommand; import javax.accessibility.*; import org.openide.util.*; import java.io.File; import java.util.*; import javax.swing.*; import org.netbeans.modules.javacvs.passwd.*; import org.netbeans.modules.javacvs.commands.ClientCreationException; /** * A customizer for the global options of a cvs command. * @author Milos Kleint */ public class GlobalOptionsCustomizer extends javax.swing.JPanel implements java.beans.Customizer { private CustomizerPropChangeSupport support; private FsGlobalOptions globals; private List globalsList; /** Creates new form GlobalOptionsCustomizer */ public GlobalOptionsCustomizer() { initComponents(); initAccessibility(); if (support == null) { support = new CustomizerPropChangeSupport(this); } cbNoChanges.setMnemonic(bundle.getString("GlobalOptionsCustomizer.cbNoChanges.mnemonic").charAt(0)); //NOI18N cbNoHistoryChange.setMnemonic(bundle.getString("GlobalOptionsCustomizer.cbNoHistoryChange.mnemonic").charAt(0)); //NOI18N cbUseGzip.setMnemonic(bundle.getString("GlobalOptionsCustomizer.cbUseGzip.mnemonic").charAt(0)); //NOI18N cbCvsRoot.setMnemonic(bundle.getString("GlobalOptionsCustomizer.lblCvsRoot.mnemonic").charAt(0)); //NOI18N java.awt.event.ActionListener actionList = new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { setData(); } }; cbNoChanges.addActionListener(actionList); cbNoHistoryChange.addActionListener(actionList); cbUseGzip.addActionListener(actionList); comCvsRoot.addActionListener(actionList); cbCvsRoot.addActionListener(actionList); /* java.awt.event.FocusAdapter focusList = new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { setData(globals); } }; txCvsRoot.addFocusListener(focusList); */ } /** 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. */ private void initComponents() {//GEN-BEGIN:initComponents java.awt.GridBagConstraints gridBagConstraints; cbUseGzip = new javax.swing.JCheckBox(); cbNoChanges = new javax.swing.JCheckBox(); cbNoHistoryChange = new javax.swing.JCheckBox(); cbCvsRoot = new javax.swing.JCheckBox(); comCvsRoot = new javax.swing.JComboBox(); setLayout(new java.awt.GridBagLayout()); cbUseGzip.setText(org.openide.util.NbBundle.getBundle(GlobalOptionsCustomizer.class).getString("GlobalOptionsCustomizer.cbUseGzip.text")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 11); add(cbUseGzip, gridBagConstraints); cbNoChanges.setText(org.openide.util.NbBundle.getBundle(GlobalOptionsCustomizer.class).getString("GlobalOptionsCustomizer.cbNoChanges.text")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 11); add(cbNoChanges, gridBagConstraints); cbNoHistoryChange.setText(org.openide.util.NbBundle.getBundle(GlobalOptionsCustomizer.class).getString("GlobalOptionsCustomizer.cbNoHistoryChange.text")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 11); add(cbNoHistoryChange, gridBagConstraints); cbCvsRoot.setText(org.openide.util.NbBundle.getBundle(GlobalOptionsCustomizer.class).getString("GlobalOptionsCustomizer.lblCvsRoot.text")); cbCvsRoot.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cbCvsRootActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(0, 12, 11, 0); add(cbCvsRoot, gridBagConstraints); comCvsRoot.setEditable(true); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(2, 5, 11, 11); gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; add(comCvsRoot, gridBagConstraints); }//GEN-END:initComponents private void cbCvsRootActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbCvsRootActionPerformed // Add your handling code here: comCvsRoot.setEnabled(cbCvsRoot.isSelected()); }//GEN-LAST:event_cbCvsRootActionPerformed private static final java.util.ResourceBundle bundle = NbBundle.getBundle(GlobalOptionsCustomizer.class); //NOI18N /** * sets the customizer with data. * @param obj can be instance of FsGlobalOptions, CvsCommand or a List of * CvsCommands/FsGlobalOptions.. */ public void setObject(java.lang.Object obj) { if (obj instanceof FsGlobalOptions) { globals = (FsGlobalOptions)obj; globalsList = null; getData(); } else if (obj instanceof CvsCommand) { globals = ((CvsCommand)obj).getGlobalOptions(); globalsList = null; getData(); } else if (obj instanceof List) { globals = null; globalsList = new LinkedList(); Iterator it = ((List)obj).iterator(); while (it.hasNext()) { Object innerObj = it.next(); if (innerObj instanceof FsGlobalOptions) { globalsList.add(innerObj); } else if (innerObj instanceof CvsCommand) { CvsCommand com = (CvsCommand)innerObj; globalsList.add(com.getGlobalOptions()); } } getData(); } } protected void setData() { if (globalsList != null) { Iterator it = globalsList.iterator(); FsGlobalOptions fsGlobal = null; while (it.hasNext()) { fsGlobal = (FsGlobalOptions)it.next(); setGlobalData(fsGlobal); // System.out.println("setting gllist=" + fsGlobal.getCVSRoot()); } if (fsGlobal != null) { support.firePropertyChange(fsGlobal); } } else { setGlobalData(globals); // System.out.println("setting globals=" + globals.getCVSRoot()); support.firePropertyChange(globals); } } /* private void setData(FsGlobalOptions glob) { setGlobalData(glob); support.firePropertyChange(glob); } */ private void getData() { if (globalsList == null && globals == null) return; FsGlobalOptions glob = null; if (globalsList == null) { glob = globals; } if (globals == null) { Iterator it = globalsList.iterator(); while (it.hasNext()) { FsGlobalOptions gl = (FsGlobalOptions)it.next(); if (glob == null) { glob = gl; } if (!gl.getCVSRoot().equals(glob.getCVSRoot())) { gl.setCVSRoot(""); glob.setCVSRoot(""); } } } cbNoChanges.setSelected(glob.isDoNoChanges()); cbNoHistoryChange.setSelected(glob.isNoHistoryLogging()); cbUseGzip.setSelected(glob.isUseGzip()); cbCvsRoot.setSelected(false); comCvsRoot.setEnabled(false); CVSPasswd pswd = new CVSPasswd(getHome().getAbsolutePath(), ".cvspass"); // NOI18N String[] arr; int selectedIndex = -1; try { pswd.loadPassFile(); Collection col = pswd.getAllEntries(); arr = new String[col.size()]; Iterator it = col.iterator(); for (int i = 0; i < col.size(); i++) { if (it.hasNext()) { PasswdEntry entry = (PasswdEntry)it.next(); arr[i] = entry.getEntry(false); if (glob.getCVSRoot() != null && glob.getCVSRoot().equals(arr[i])) { selectedIndex = i; } } } } catch (ClientCreationException exc) { if (glob.getCVSRoot() != null) { arr = new String[] {glob.getCVSRoot()}; selectedIndex = 0; } else { arr = new String[0]; selectedIndex = -1; } } comCvsRoot.setModel(new DefaultComboBoxModel(arr)); comCvsRoot.setSelectedIndex(selectedIndex); support.firePropertyChange(glob); } public void setGlobalData(FsGlobalOptions glob) { if (glob == null) return; glob.setDoNoChanges(cbNoChanges.isSelected()); glob.setNoHistoryLogging(cbNoHistoryChange.isSelected()); glob.setUseGzip(cbUseGzip.isSelected()); if (cbCvsRoot.isSelected()) { if (comCvsRoot.getSelectedItem() != null) { glob.setCVSRoot(comCvsRoot.getSelectedItem().toString()); } } else { glob.setCVSRoot(""); //NOI18N } } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JCheckBox cbUseGzip; private javax.swing.JCheckBox cbCvsRoot; private javax.swing.JCheckBox cbNoChanges; private javax.swing.JComboBox comCvsRoot; private javax.swing.JCheckBox cbNoHistoryChange; // End of variables declaration//GEN-END:variables private void initAccessibility() { AccessibleContext context = this.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_GlobalOptionsCustomizer")); context = cbUseGzip.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_GlobalOptionsCustomizer.cbUserGzip")); context = cbNoChanges.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_GlobalOptionsCustomizer.cbNoChanges")); context = cbNoHistoryChange.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_GlobalOptionsCustomizer.cbNoHistoryChange")); context = cbCvsRoot.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_GlobalOptionsCustomizer.cbCvsRoot")); context = comCvsRoot.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_GlobalOptionsCustomizer.txCvsRoot")); } 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 File getHome() { String home = System.getProperty("Env-HOME"); //NOI18N if (home == null && org.openide.util.Utilities.isWindows()) { String homeDrive = System.getProperty("Env-HOMEDRIVE"); //NOI18N String homeDir = System.getProperty("Env-HOMEPATH"); //NOI18N if (homeDrive != null && homeDir != null) { home = homeDrive + homeDir; } } if (home == null) { home = System.getProperty("user.home"); //NOI18N } return new File(home); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 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.