alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

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.cvsclient.commands;

import org.netbeans.lib.cvsclient.command.Command;
import org.netbeans.lib.cvsclient.commandLine.GetOpt;
import org.netbeans.modules.javacvs.customizers.*;
import org.netbeans.modules.javacvs.commands.FileSystemCommand;
import org.netbeans.modules.javacvs.commands.FileSystemCommandImpl;
import org.netbeans.modules.javacvs.*;
import java.util.*;
import javax.swing.event.*;
import org.openide.util.NbBundle;
import java.beans.*;
import javax.accessibility.*;

/**
 *  A CommandParamInput implementing class that parses the switches received by user
 * and sets the apropriate properties of the Command.
 * @author  mkleint
 */
public class CommandLineParamInput extends javax.swing.JPanel 
                                   implements Customizer {

    private FileSystemCommandImpl currentFSCommand;
    private List commandList;

    private CustomizerPropChangeSupport support;                                 
    /** Creates new form CommandLineParamInput */
    public CommandLineParamInput() {
        initComponents ();
        lblCommandLine.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/Bundle").getString("CommandLineParamInput.lblCommandLine.mnemonic").charAt(0)); // NOI18N
        lblCommandLine.setLabelFor(txCommandLine);
        lblCommandName.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/Bundle").getString("CommandLineParamInput.lblCommandName.mnemonic").charAt(0)); // NOI18N
        lblCommandName.setLabelFor(txCommandName);
        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();
                }
        };
        txCommandLine.getDocument().addDocumentListener(docList);
        java.awt.event.FocusAdapter focus = new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                javax.swing.SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                       txCommandLine.requestFocus();
                   }
                });
            }
        };
        this.addFocusListener(focus);                
        
    }

    /** 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;

        lblCommandName = new javax.swing.JLabel();
        txCommandName = new javax.swing.JTextField();
        lblCommandLine = new javax.swing.JLabel();
        txCommandLine = new javax.swing.JTextField();

        setLayout(new java.awt.GridBagLayout());

        lblCommandName.setLabelFor(txCommandName);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        add(lblCommandName, gridBagConstraints);

        txCommandName.setEditable(false);
        txCommandName.setPreferredSize(new java.awt.Dimension(70, 20));
        txCommandName.setMinimumSize(new java.awt.Dimension(40, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 11);
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        add(txCommandName, gridBagConstraints);

        lblCommandLine.setLabelFor(txCommandLine);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(7, 12, 11, 0);
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        add(lblCommandLine, gridBagConstraints);

        txCommandLine.setPreferredSize(new java.awt.Dimension(175, 20));
        txCommandLine.setMinimumSize(new java.awt.Dimension(50, 20));
        txCommandLine.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txCommandLineActionPerformed(evt);
            }
        });

        txCommandLine.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txCommandLineFocusLost(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(5, 12, 11, 11);
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        add(txCommandLine, gridBagConstraints);

    }//GEN-END:initComponents

    private void txCommandLineFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txCommandLineFocusLost
        // Add your handling code here:
        setData();
    }//GEN-LAST:event_txCommandLineFocusLost

    private void txCommandLineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txCommandLineActionPerformed
        // Add your handling code here:
        setData();
    }//GEN-LAST:event_txCommandLineActionPerformed

    /** fills the param input with a command.. the switches of the param input
     * act accordingly and set themselves that way
     */
    public void getData(FileSystemCommand command) {
        txCommandLine.setText(command.getCVSArguments());
        java.beans.BeanInfo info;
        String name = command.getClass().getName();
        try {
            info = java.beans.Introspector.getBeanInfo(command.getClass());
            name = info.getBeanDescriptor().getName();
        } catch (java.beans.IntrospectionException exc) {
//            System.out.println("no beaninfo for class"); // NOI18N
        }        
        txCommandName.setText(name);
    }    

  protected void setData() {
      if (commandList != null) {
          Iterator it = commandList.iterator();
          FileSystemCommandImpl fsCheck = null;
          while (it.hasNext()) {
              fsCheck = (FileSystemCommandImpl)it.next();
              setData(fsCheck.getOuterClassInstance());
          }
          if (fsCheck != null) {
              support.firePropertyChange(((CvsCommand)fsCheck));
          }
      } else {
          setData(currentFSCommand.getOuterClassInstance());
          support.firePropertyChange(((CvsCommand)currentFSCommand));
      }
  }    
    
    /** sets the comand with the params the user selected in the dialog.
     */
    public void setData(FileSystemCommand command) {
        if (command != null) {
            String text = txCommandLine.getText();
            int firstIndex = text.indexOf('"');
            int lastIndex = text.lastIndexOf('"');
            if ( firstIndex > 0 && lastIndex > 0 && firstIndex == lastIndex) {
                // don't set command when there's only one " character..
                return;
            }
            command.parseCvsArguments(text);
        }
    }
    
    public void removePropertyChangeListener(java.beans.PropertyChangeListener propertyChangeListener) {
        if (support == null) {
            support = new CustomizerPropChangeSupport(this);
        }
        support.removePropertyChangeListener(propertyChangeListener);
    }
    
    public void setObject(java.lang.Object obj) {
        if (obj instanceof List) {
            commandList = (List)obj;
            currentFSCommand = null;
            if (commandList.size() > 0) {
                FileSystemCommandImpl check = (FileSystemCommandImpl)commandList.get(0);
                getData(check.getOuterClassInstance());
            }
        }        
        if (obj instanceof FileSystemCommandImpl) {
          currentFSCommand = (FileSystemCommandImpl)obj;
          commandList = null;
          getData(currentFSCommand.getOuterClassInstance());
        }
    }
    
    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);
    }    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField txCommandName;
    private javax.swing.JLabel lblCommandName;
    private javax.swing.JTextField txCommandLine;
    private javax.swing.JLabel lblCommandLine;
    // End of variables declaration//GEN-END:variables

}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

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.