|
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-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.cvsclient.customizer; import org.openide.util.*; import org.openide.*; import javax.swing.event.*; import javax.swing.*; import javax.accessibility.*; import java.awt.event.*; import java.io.*; import java.util.*; import org.netbeans.modules.javacvs.passwd.*; import org.netbeans.modules.cvsclient.NbJavaCvsFileSystem; import org.netbeans.modules.cvsclient.JavaCvsSettings; import org.netbeans.modules.javacvs.util.*; import org.netbeans.lib.cvsclient.connection.AuthenticationException; import org.netbeans.lib.cvsclient.connection.PServerConnection; import org.openide.*; import org.netbeans.modules.javacvs.commands.ClientCreationException; import org.openide.ErrorManager; /** Panel in the JavaCvsCustomizer which takes care of CVS server settings. * After the user fills in all info needed and the type of server is pserver, looks in the .cvspass file for settings. * If not found, it attempts to connect to the pserver and prompts for password. * If successful, the current settings are written to the .cvspass file. * @author mkleint */ public class Cust2ServerPanel extends javax.swing.JPanel { NbJavaCvsFileSystem fs; CVSPasswd passFile; private boolean allowNext = false; private ArrayList listeners; /** Creates new form Cust2Server */ public Cust2ServerPanel() { initComponents (); initAccessibility(); lblServerType.setDisplayedMnemonic (NbBundle.getBundle(Cust2ServerPanel.class).getString("Cust2ServerPanel.lblServerType.mnemonic").charAt (0)); // NOI18N lblServerType.setLabelFor (cbServerType); lbServer.setDisplayedMnemonic (NbBundle.getBundle(Cust2ServerPanel.class).getString("JavaCvsCustomizer.lbServer.mnemonic").charAt (0)); // NOI18N lbServer.setLabelFor (txServer); lbRepository.setDisplayedMnemonic (NbBundle.getBundle(Cust2ServerPanel.class).getString("JavaCvsCustomizer.lbRepository.mnemonic").charAt (0)); // NOI18N lbRepository.setLabelFor (txRepository); lbUser.setDisplayedMnemonic (NbBundle.getBundle(Cust2ServerPanel.class).getString("JavaCvsCustomizer.lbUser.mnemonic").charAt (0)); // NOI18N lbUser.setLabelFor (txUser); lblCvsRoot.setDisplayedMnemonic (NbBundle.getBundle(Cust2ServerPanel.class).getString("Cust2ServerPanel.lblCvsRoot.mnemonic").charAt (0)); // NOI18N lblCvsRoot.setLabelFor (txCvsRoot); lblPort.setDisplayedMnemonic (NbBundle.getBundle(Cust2ServerPanel.class).getString("Cust2ServerPanel.lblPort.mnemonic").charAt (0)); // NOI18N lblPort.setLabelFor (txPort); btnLogin.setMnemonic (NbBundle.getBundle(Cust2ServerPanel.class).getString("Cust2ServerPanel.btnLogin.mnemonic").charAt (0)); // NOI18N JavaCvsSettings settings = (JavaCvsSettings)SharedClassObject.findObject( JavaCvsSettings.class, true); passFile = new CVSPasswd(settings.getHome().getAbsolutePath(), ".cvspass"); // should suit all OS // NOI18N try { passFile.loadPassFile(); } catch (ClientCreationException exc) { ErrorManager.getDefault().log(ErrorManager.WARNING, exc.getLocalizedMessage()); } } /** 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; lblServerType = new javax.swing.JLabel(); cbServerType = new javax.swing.JComboBox(); lbServer = new javax.swing.JLabel(); txServer = new javax.swing.JTextField(); lblPort = new javax.swing.JLabel(); txPort = new javax.swing.JTextField(); lbRepository = new javax.swing.JLabel(); txRepository = new javax.swing.JTextField(); lbUser = new javax.swing.JLabel(); txUser = new javax.swing.JTextField(); lblCvsRoot = new javax.swing.JLabel(); txCvsRoot = new javax.swing.JTextField(); jSeparator1 = new javax.swing.JSeparator(); jPanel1 = new javax.swing.JPanel(); btnLogin = new javax.swing.JButton(); txPasswd = new javax.swing.JTextField(); setLayout(new java.awt.GridBagLayout()); setMinimumSize(new java.awt.Dimension(450, 325)); setPreferredSize(new java.awt.Dimension(450, 325)); lblServerType.setLabelFor(cbServerType); lblServerType.setText(org.openide.util.NbBundle.getBundle(Cust2ServerPanel.class).getString("Cust2ServerPanel.lblServerType.text")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0); add(lblServerType, gridBagConstraints); cbServerType.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cbServerTypeActionPerformed(evt); } }); cbServerType.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { cbServerTypeFocusLost(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 11); add(cbServerType, gridBagConstraints); lbServer.setLabelFor(txServer); lbServer.setText(org.openide.util.NbBundle.getBundle(Cust2ServerPanel.class).getString("JavaCvsCustomizer.lbServer.text")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0); add(lbServer, gridBagConstraints); txServer.setColumns(20); txServer.setMinimumSize(new java.awt.Dimension(100, 20)); txServer.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { txServerFocusLost(evt); } }); txServer.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { txServerKeyReleased(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 11); add(txServer, gridBagConstraints); lblPort.setLabelFor(txPort); lblPort.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/customizer/Bundle").getString("Cust2ServerPanel.lblPort.text")); 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(lblPort, gridBagConstraints); txPort.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { txPortActionPerformed(evt); } }); txPort.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { txPortFocusLost(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 11); add(txPort, gridBagConstraints); lbRepository.setLabelFor(txRepository); lbRepository.setText(org.openide.util.NbBundle.getBundle(Cust2ServerPanel.class).getString("JavaCvsCustomizer.lbRepository.text")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 0); add(lbRepository, gridBagConstraints); txRepository.setColumns(20); txRepository.setMinimumSize(new java.awt.Dimension(100, 20)); txRepository.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { txRepositoryFocusLost(evt); } }); txRepository.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { txRepositoryKeyReleased(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 11); add(txRepository, gridBagConstraints); lbUser.setLabelFor(txUser); lbUser.setText(org.openide.util.NbBundle.getBundle(Cust2ServerPanel.class).getString("JavaCvsCustomizer.lbUser.text")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 0); add(lbUser, gridBagConstraints); txUser.setMinimumSize(new java.awt.Dimension(100, 20)); txUser.setPreferredSize(new java.awt.Dimension(160, 20)); txUser.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { txUserFocusLost(evt); } }); txUser.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { txUserKeyReleased(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 4; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 11); add(txUser, gridBagConstraints); lblCvsRoot.setLabelFor(txCvsRoot); lblCvsRoot.setText(org.openide.util.NbBundle.getBundle(Cust2ServerPanel.class).getString("Cust2ServerPanel.lblCvsRoot.text")); 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(lblCvsRoot, gridBagConstraints); txCvsRoot.setEditable(false); txCvsRoot.setDisabledTextColor(javax.swing.UIManager.getColor ("TextField.foreground")); txCvsRoot.setMinimumSize(new java.awt.Dimension(100, 20)); txCvsRoot.setPreferredSize(new java.awt.Dimension(200, 20)); txCvsRoot.setEnabled(false); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 5; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 11); add(txCvsRoot, gridBagConstraints); jSeparator1.setPreferredSize(new java.awt.Dimension(40, 5)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 6; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 11); add(jSeparator1, gridBagConstraints); jPanel1.setLayout(new java.awt.GridBagLayout()); btnLogin.setText(org.openide.util.NbBundle.getBundle(Cust2ServerPanel.class).getString("Cust2ServerPanel.btnLogin.text")); btnLogin.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnLoginActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; jPanel1.add(btnLogin, gridBagConstraints); txPasswd.setEditable(false); txPasswd.setText("jTextField1"); txPasswd.setDisabledTextColor(javax.swing.UIManager.getColor ("Label.foreground")); txPasswd.setPreferredSize(new java.awt.Dimension(150, 20)); txPasswd.setEnabled(false); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0); jPanel1.add(txPasswd, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 7; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 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(12, 12, 11, 11); add(jPanel1, gridBagConstraints); }//GEN-END:initComponents private void txPortFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txPortFocusLost try { int i = Integer.parseInt(txPort.getText()); } catch (NumberFormatException exc) { txPort.setText(""+ PServerConnection.DEFAULT_PORT); } eventCheckPassword(); fireChangeState(); }//GEN-LAST:event_txPortFocusLost private void txPortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txPortActionPerformed try { int i = Integer.parseInt(txPort.getText()); } catch (NumberFormatException exc) { txPort.setText(""+ PServerConnection.DEFAULT_PORT); } eventCheckPassword(); fireChangeState(); }//GEN-LAST:event_txPortActionPerformed private void txRepositoryKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txRepositoryKeyReleased eventCheckPassword(); fireChangeState(); // Add your handling code here: }//GEN-LAST:event_txRepositoryKeyReleased private void txUserKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txUserKeyReleased eventCheckPassword(); fireChangeState(); // Add your handling code here: }//GEN-LAST:event_txUserKeyReleased private void txServerKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txServerKeyReleased eventCheckPassword(); fireChangeState(); // Add your handling code here: }//GEN-LAST:event_txServerKeyReleased private void txUserFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txUserFocusLost // Add your handling code here: eventCheckPassword(); fireChangeState(); }//GEN-LAST:event_txUserFocusLost private void txRepositoryFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txRepositoryFocusLost // Add your handling code here: eventCheckPassword(); fireChangeState(); }//GEN-LAST:event_txRepositoryFocusLost private void txServerFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txServerFocusLost // Add your handling code here: eventCheckPassword(); fireChangeState(); }//GEN-LAST:event_txServerFocusLost private void cbServerTypeFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cbServerTypeFocusLost // Add your handling code here: eventCheckPassword(); fireChangeState(); }//GEN-LAST:event_cbServerTypeFocusLost private void cbServerTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbServerTypeActionPerformed // Add your handling code here: btnLogin.setEnabled(cbServerType.getSelectedIndex() + 1 == NbJavaCvsFileSystem.TYPE_PSERVER); // hack.. server was removed and to be backward compatible, ... eventCheckPassword(); fireChangeState(); }//GEN-LAST:event_cbServerTypeActionPerformed private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoginActionPerformed // Add your handling code here: SwingUtilities.invokeLater(new Runnable() { public void run() { int port = 2401; try { port = Integer.parseInt(txPort.getText()); } catch (NumberFormatException exc) { port = 2401; } LoginDialog login = LoginDialog.createDialog(getCvsRoot(), passFile, port); login.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent e) { eventCheckPassword(); fireChangeState(); } }); NbJavaCvsCustomizer.centerWindow(login); login.show(); } }); }//GEN-LAST:event_btnLoginActionPerformed private void eventCheckPassword() { String root = getCvsRoot(); txCvsRoot.setText(root); int selType = cbServerType.getSelectedIndex() + 1; // hack.. server was removed and to be backward compatible, ... checkPassword(root,selType); } private String getCvsRoot() { int selType = cbServerType.getSelectedIndex() + 1; // hack.. server was removed and to be backward compatible, ... String root = ":" + fs.getCvsServerTypeName(selType); // NOI18N root = root + ":" + txUser.getText().trim() + "@" + txServer.getText().trim(); // NOI18N root = root + ":"; //NOI18N if (!txPort.getText().trim().equals("2401")) { //NOI18N root = root + txPort.getText().trim(); } root = root + txRepository.getText().trim(); // NOI18N return root; } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTextField txUser; private javax.swing.JLabel lbRepository; private javax.swing.JTextField txServer; private javax.swing.JComboBox cbServerType; private javax.swing.JLabel lbServer; private javax.swing.JLabel lbUser; private javax.swing.JTextField txPort; private javax.swing.JLabel lblServerType; private javax.swing.JLabel lblPort; private javax.swing.JSeparator jSeparator1; private javax.swing.JLabel lblCvsRoot; private javax.swing.JTextField txRepository; private javax.swing.JPanel jPanel1; private javax.swing.JTextField txPasswd; private javax.swing.JButton btnLogin; private javax.swing.JTextField txCvsRoot; // End of variables declaration//GEN-END:variables private static final java.util.ResourceBundle bundle = NbBundle.getBundle(Cust2ServerPanel.class); // NOI18N private void initAccessibility() { AccessibleContext context = this.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_Cust2ServerPanel")); context = btnLogin.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_Cust2ServerPanel.btnLogin")); context = txPasswd.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_Cust2ServerPanel.txPasswd")); context.setAccessibleName(bundle.getString("ACSN_Cust2ServerPanel.txPasswd")); context = txServer.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_Cust2ServerPanel.txServer")); context = txPort.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_Cust2ServerPanel.txPort")); context = txRepository.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_Cust2ServerPanel.txRepository")); context = txUser.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_Cust2ServerPanel.txUser")); context = txCvsRoot.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_Cust2ServerPanel.txCvsRoot")); context = cbServerType.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_Cust2ServerPanel.cbServerType")); } /** name of panel * @return the name of the current panel */ public String getName() { return org.openide.util.NbBundle.getBundle(Cust2ServerPanel.class).getString("Cust2ServerPanel.serverDialogLabel"); } public void setLast(boolean last) { // isLastPanel = last; } /** last panel check. * @return true if last else false. */ public boolean isLast() { // System.out.println("server is last =" + !iter.isNewSources()); // return !iter.isNewSources(); return false; } /** If everything is ok, returns the number of the Cust3CheckoutPanel. * Otherwise returns it's onw number, so that the user has to stay here or cancel. * @return the number of next panel. */ public int getNext() { // if (iter.isNewSources()) return 2; return 3; //.. if not new sources this one is final.. // this makes the assumption that the server repository has something the user can checkout.. } private void checkPassword(String root, int serverType) { if (serverType == NbJavaCvsFileSystem.TYPE_PSERVER) { PasswdEntry entry = passFile.find(root); if (entry != null) { txPasswd.setText(NbBundle.getBundle(Cust2ServerPanel.class).getString("Cust2ServerPanel.isLogged")); allowNext = true; } else { txPasswd.setText(NbBundle.getBundle(Cust2ServerPanel.class).getString("Cust2ServerPanel.isNotLogged")); allowNext = true; } } else { txPasswd.setText(NbBundle.getBundle(Cust2ServerPanel.class).getString("Cust2ServerPanel.isNotApplicable")); allowNext = true; } } /** Add a listener to changes of the panel's validity. * @param l the listener to add * @see #isValid */ private synchronized void addChangeListener(ChangeListener l) { if (listeners == null) { listeners = new ArrayList(); } listeners.add (l); } /** Remove a listener to changes of the panel's validity. * @param l the listener to remove */ private synchronized void removeChangeListener(ChangeListener l) { if (listeners != null) { listeners.remove (l); } } private void fireChangeState() { ArrayList list; synchronized (this) { if (this.listeners == null) return; list = (ArrayList) this.listeners.clone(); } ChangeEvent event = new ChangeEvent (this); for (int i=0; i |
... 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.