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-2004 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.javadoc.comments;

import java.lang.reflect.Modifier;
import javax.swing.*;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import java.awt.*;

import org.openide.ErrorManager;

import org.netbeans.modules.javadoc.settings.DocumentationSettings;
import org.netbeans.api.javahelp.Help;
import org.openide.src.JavaDoc;
import org.openide.util.*;

/**
 */
public class AutoCommentPanel
extends javax.swing.JPanel
implements ListSelectionListener, AutoCommenter.AutoCommentChangeListener {
    
    AutoCommenter autoCommenter;
    
    private JavaDocEditorPanel javaDocEditor = new JavaDocEditorPanel();
    /** Holds the value of the last selected index in badList to be able to
     * call modifyJavaDoc method for that method. */
    private int badListLastSelectedIndex = -1;
    private boolean resetingAll = false;
    private boolean updatingBadList = false;
    
    private static final DefaultListModel EMPTY_MODEL = new DefaultListModel();
    static final String WAIT_STRING = "WAIT.MODEL"; // NOI18N
    private static final DefaultListModel WAIT_MODEL = new DefaultListModel();
    
    static {
        WAIT_MODEL.addElement( WAIT_STRING );
    }
    
    private static final ImageIcon publicIcon = new ImageIcon (AutoCommentPanel.class.getResource ("/org/netbeans/modules/javadoc/comments/resources/public.gif")); // NOI18N
    private static final ImageIcon protectedIcon = new ImageIcon (AutoCommentPanel.class.getResource ("/org/netbeans/modules/javadoc/comments/resources/protected.gif")); // NOI18N
    private static final ImageIcon packageIcon = new ImageIcon (AutoCommentPanel.class.getResource ("/org/netbeans/modules/javadoc/comments/resources/package.gif")); // NOI18N
    private static final ImageIcon privateIcon = new ImageIcon (AutoCommentPanel.class.getResource ("/org/netbeans/modules/javadoc/comments/resources/private.gif")); // NOI18N
    private static final ImageIcon okIcon = new ImageIcon (AutoCommentPanel.class.getResource ("/org/netbeans/modules/javadoc/comments/resources/ok.gif")); // NOI18N
    private static final ImageIcon errorIcon = new ImageIcon (AutoCommentPanel.class.getResource ("/org/netbeans/modules/javadoc/comments/resources/error.gif")); // NOI18N
    private static final ImageIcon missIcon = new ImageIcon (AutoCommentPanel.class.getResource ("/org/netbeans/modules/javadoc/comments/resources/missing.gif")); // NOI18N
    
    private int modifierMask;
    private int errorMask;
    /** The state of the window is stored in hidden options of DocumentationSettings */
    DocumentationSettings dss = ((DocumentationSettings)SharedClassObject.findObject(DocumentationSettings.class, true));
    
    static final long serialVersionUID =1845033305150331568L;
    /** Creates new form AutoCommentPanel
     */
    public AutoCommentPanel() {
        initComponents ();
        javaDocEditor.setEnabled(false);
        
        defaultButton.setMnemonic( org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.defaultButton.text_Mnemonic").charAt(0) );
        sourceButton.setMnemonic( org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.sourceButton.text_Mnemonic").charAt(0) );
        refreshButton.setMnemonic( org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.refreshButton.text_Mnemonic").charAt(0) );
        helpButton.setMnemonic( org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.helpButton.text_Mnemonic").charAt(0) );
        
        okButton.setMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_AutoCommentPanel.okButton").charAt(0));
        errButton.setMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_AutoCommentPanel.errButton").charAt(0));
        missButton.setMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_AutoCommentPanel.missButton").charAt(0));
        publicButton.setMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_AutoCommentPanel.publicButton").charAt(0));
        packageButton.setMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_AutoCommentPanel.packageButton").charAt(0));
        protectedButton.setMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_AutoCommentPanel.protectedButton").charAt(0));
        privateButton.setMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_AutoCommentPanel.privateButton").charAt(0));
        
        splittedPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, classInfoPanel, javaDocEditor);
        splittedPanel.setDividerSize(5);
        add(splittedPanel);
        
        okButton.setIcon( okIcon );
        errButton.setIcon( errorIcon );
        missButton.setIcon( missIcon );
        
        publicButton.setIcon( publicIcon );
        packageButton.setIcon( packageIcon );
        protectedButton.setIcon( protectedIcon );
        privateButton.setIcon( privateIcon );
        
        resolveButtonState();
        
        badList.setCellRenderer( new AutoCommentListCellRenderer() );
        
        elementSelection( new ListSelectionEvent( badList.getModel(), -1, -1, false ) );
        initAccessibility();
    }
    
    private void initAccessibility()
    {
        badList.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.methodListA11yName"));  // NOI18N
        badList.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.methodListA11yDesc"));  // NOI18N
        nameLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.nameLabel.textA11yDesc"));  // NOI18N
        classTextField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.nameTextField.textA11yName"));  // NOI18N
        errorListBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.commentList.textA11yName"));  // NOI18N
        errorListBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.commentList.textA11yDesc"));  // NOI18N
    }
    
    /** 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;

        classInfoPanel = new javax.swing.JPanel();
        filterPanel = new javax.swing.JPanel();
        okButton = new javax.swing.JToggleButton();
        errButton = new javax.swing.JToggleButton();
        missButton = new javax.swing.JToggleButton();
        publicButton = new javax.swing.JToggleButton();
        packageButton = new javax.swing.JToggleButton();
        protectedButton = new javax.swing.JToggleButton();
        privateButton = new javax.swing.JToggleButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        badList = new javax.swing.JList();
        buttonPanel = new javax.swing.JPanel();
        defaultButton = new javax.swing.JButton();
        sourceButton = new javax.swing.JButton();
        refreshButton = new javax.swing.JButton();
        helpButton = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        detailsPanel = new javax.swing.JPanel();
        nameLabel = new javax.swing.JLabel();
        classTextField = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        errorListBox = new javax.swing.JList();

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

        setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(0, 0, 0, 0)));
        classInfoPanel.setLayout(new java.awt.GridBagLayout());

        classInfoPanel.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(6, 6, 5, 5)));
        classInfoPanel.setName("classInfoPanel");
        filterPanel.setLayout(new java.awt.GridBagLayout());

        okButton.setSelected(true);
        okButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.okButton.toolTipText"));
        okButton.setActionCommand("ALL");
        okButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        filterPanel.add(okButton, new java.awt.GridBagConstraints());

        errButton.setSelected(true);
        errButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.errButton.toolTipText"));
        errButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        errButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                errButtonActionPerformed(evt);
            }
        });

        filterPanel.add(errButton, new java.awt.GridBagConstraints());

        missButton.setSelected(true);
        missButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.missButton.toolTipText"));
        missButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        missButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                missButtonActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
        filterPanel.add(missButton, gridBagConstraints);

        publicButton.setSelected(true);
        publicButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.publicButton.toolTipText"));
        publicButton.setActionCommand("PUBLIC");
        publicButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        publicButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                publicButtonActionPerformed(evt);
            }
        });

        filterPanel.add(publicButton, new java.awt.GridBagConstraints());

        packageButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.packageButton.toolTipText"));
        packageButton.setActionCommand("PACKAGE");
        packageButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        packageButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                packageButtonActionPerformed(evt);
            }
        });

        filterPanel.add(packageButton, new java.awt.GridBagConstraints());

        protectedButton.setSelected(true);
        protectedButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.protectedButton.toolTipText"));
        protectedButton.setActionCommand("PROTECTED");
        protectedButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        protectedButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                protectedButtonActionPerformed(evt);
            }
        });

        filterPanel.add(protectedButton, new java.awt.GridBagConstraints());

        privateButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.privateButton.toolTipText"));
        privateButton.setActionCommand("PRIVATE");
        privateButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        privateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                privateButtonActionPerformed(evt);
            }
        });

        filterPanel.add(privateButton, new java.awt.GridBagConstraints());

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.weightx = 1.0;
        filterPanel.add(jPanel2, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(6, 6, 5, 6);
        classInfoPanel.add(filterPanel, gridBagConstraints);

        badList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        badList.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.methodListA11yDesc"));
        jScrollPane1.setViewportView(badList);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.6;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
        classInfoPanel.add(jScrollPane1, gridBagConstraints);

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

        buttonPanel.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(0, 5, 0, 0)));
        defaultButton.setText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.defaultButton.text"));
        defaultButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.defaultButton.textA11yDesc"));
        defaultButton.setActionCommand("Default Comment");
        defaultButton.setMargin(new java.awt.Insets(2, 4, 2, 4));
        defaultButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                defaultButtonActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
        buttonPanel.add(defaultButton, gridBagConstraints);

        sourceButton.setText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.sourceButton.text"));
        sourceButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.sourceButton.textA11yDesc"));
        sourceButton.setMargin(new java.awt.Insets(2, 4, 2, 4));
        sourceButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sourceButtonActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
        buttonPanel.add(sourceButton, gridBagConstraints);

        refreshButton.setText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.refreshButton.text"));
        refreshButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.refreshButton.textA11yDesc"));
        refreshButton.setMargin(new java.awt.Insets(2, 4, 2, 4));
        refreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                refreshButtonActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
        buttonPanel.add(refreshButton, gridBagConstraints);

        helpButton.setText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutocommentPanel.helpButton.text"));
        helpButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutocommentPanel.helpButton.tooltipText"));
        helpButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpButtonActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(11, 0, 0, 0);
        buttonPanel.add(helpButton, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.weighty = 1.0;
        buttonPanel.add(jPanel3, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.weighty = 0.6;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 6);
        classInfoPanel.add(buttonPanel, gridBagConstraints);

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

        nameLabel.setLabelFor(classTextField);
        nameLabel.setText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("AutoCommentPanel.nameLabel.text"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 11, 0);
        detailsPanel.add(nameLabel, gridBagConstraints);

        classTextField.setEditable(false);
        classTextField.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.nameTextField.textA11yDesc"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 11, 0);
        detailsPanel.add(classTextField, gridBagConstraints);

        errorListBox.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.commentList.textA11yDesc"));
        jScrollPane2.setViewportView(errorListBox);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        detailsPanel.add(jScrollPane2, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 0.4;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 6);
        classInfoPanel.add(detailsPanel, gridBagConstraints);

        add(classInfoPanel, java.awt.BorderLayout.CENTER);

    }//GEN-END:initComponents

    private void helpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpButtonActionPerformed
        Help help=(Help)Lookup.getDefault().lookup(Help.class);
        
        help.showHelp(
            new org.openide.util.HelpCtx(AutoCommentTopComponent.AUTO_COMMENT_HELP_CTX_KEY));
    }//GEN-LAST:event_helpButtonActionPerformed
        
    private void missButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_missButtonActionPerformed
        refreshState();
    }//GEN-LAST:event_missButtonActionPerformed
    
    private void errButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_errButtonActionPerformed
        refreshState();
    }//GEN-LAST:event_errButtonActionPerformed
    
    private void okButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        refreshState();
    }//GEN-LAST:event_okButtonActionPerformed
    
    private void refreshButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshButtonActionPerformed
        resetingAll = true;
        updateForClosing();
        resetState();
    }//GEN-LAST:event_refreshButtonActionPerformed
    
    
    private void privateButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_privateButtonActionPerformed
        refreshState();
    }//GEN-LAST:event_privateButtonActionPerformed
    
    private void protectedButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_protectedButtonActionPerformed
        refreshState();
    }//GEN-LAST:event_protectedButtonActionPerformed
    
    private void packageButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_packageButtonActionPerformed
        refreshState();
    }//GEN-LAST:event_packageButtonActionPerformed
    
    private void publicButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_publicButtonActionPerformed
        refreshState();
    }//GEN-LAST:event_publicButtonActionPerformed
    
        
    private void defaultButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_defaultButtonActionPerformed
        int sel = badList.getMinSelectionIndex();
        
        if ( sel == -1 )
            return;
        
        AutoCommenter.Element element = (AutoCommenter.Element)badList.getModel().getElementAt( sel );
        javaDocEditor.commitTagChange();
        JavaDoc doc = null;
        if (javaDocEditor.isDirty()) {
            doc = javaDocEditor.getUpdatedJavaDoc();
        }
        this.autoCommenter.autoCorrectJavadoc(element, doc);
    }//GEN-LAST:event_defaultButtonActionPerformed
    
    private void sourceButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sourceButtonActionPerformed
        int sel = badList.getMinSelectionIndex();
        
        if ( sel == -1 )
            return;
        
        ((AutoCommenter.Element)badList.getModel().getElementAt( sel )).viewSource();
        
    }//GEN-LAST:event_sourceButtonActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList badList;
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JPanel classInfoPanel;
    private javax.swing.JTextField classTextField;
    private javax.swing.JButton defaultButton;
    private javax.swing.JPanel detailsPanel;
    private javax.swing.JToggleButton errButton;
    private javax.swing.JList errorListBox;
    private javax.swing.JPanel filterPanel;
    private javax.swing.JButton helpButton;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JToggleButton missButton;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JToggleButton okButton;
    private javax.swing.JToggleButton packageButton;
    private javax.swing.JToggleButton privateButton;
    private javax.swing.JToggleButton protectedButton;
    private javax.swing.JToggleButton publicButton;
    private javax.swing.JButton refreshButton;
    private javax.swing.JButton sourceButton;
    // End of variables declaration//GEN-END:variables
    private JSplitPane splittedPanel;
       
    public void updateForClosing() {
        javaDocEditor.updateForClosing();
        int sel = badList.getMinSelectionIndex();
        if (sel != -1) {
            if( !(badList.getModel().getElementAt( 0 ) instanceof AutoCommenter.Element) )
                  return;
            AutoCommenter.Element el = (AutoCommenter.Element) badList.getModel().getElementAt(sel);
            modifyJavaDoc(el);
        }
    }
    
    private void showCommentEditor( final AutoCommenter.Element el ) {
        javaDocEditor.setElement(el);
        javaDocEditor.setJavaDoc(el.getJavaDoc());
    }
    
    private void modifyJavaDoc(final AutoCommenter.Element el) {
        javaDocEditor.commitTagChange();
        if (! javaDocEditor.isDirty()) {
            return;
        }
        this.autoCommenter.modifyJavadoc(el, javaDocEditor.getUpdatedJavaDoc());
        javaDocEditor.setDirty(false);
    }
    
    private void elementSelection( ListSelectionEvent evt ) {
        // This is to prevente an infinite loop when performing an update to
        // the list
        if (updatingBadList || (evt != null && evt.getValueIsAdjusting())) {
            return;
        }
        
        int sel = badList.getMinSelectionIndex();
        ListModel badModel = badList.getModel();
        
        // If there was an item selected before changing, check to see if we
        // have to update the current javadoc.
        if (badListLastSelectedIndex != -1) {
            // System.out.println("run modifyJavaDoc for element " + badListLastSelectedIndex);
            //check for no resolved
            if(!(badModel.getElementAt(0) instanceof AutoCommenter.Element))
                return;

            AutoCommenter.Element element = (AutoCommenter.Element) badModel.getElementAt(badListLastSelectedIndex);
            modifyJavaDoc(element);
        }
          
        badListLastSelectedIndex = sel;
        
        if ( sel < 0 ) {
            errorListBox.setModel(EMPTY_MODEL);
            defaultButton.setEnabled( false );
            sourceButton.setEnabled( false );
            classTextField.setText( "" ); // NOI18N
            javaDocEditor.clear();
            javaDocEditor.setEnabled(false);
        } else {
            //check for no resolved
            if( !(badModel.getElementAt(0) instanceof AutoCommenter.Element) )
                  return;

            AutoCommenter.Element element = (AutoCommenter.Element) badModel.getElementAt(sel);
            String dcName = element.getDescriptor().getDeclaringClassName();
            if (dcName == null) {
                dcName = element.getDescriptor().getName();
            }
            classTextField.setText(dcName);
            
            defaultButton.setEnabled( element.isCorrectable() );
            sourceButton.setEnabled( true );
            javaDocEditor.setEnabled( true );
            
            errorListBox.setModel( element.getErrorList() );
            showCommentEditor(element);
        }
    }
    
    void setAutoCommenter( AutoCommenter autoCommenter ) {
        if (this.autoCommenter != null) {
            this.autoCommenter.removeAutoCommentChangeListener(this);
        }
        this.autoCommenter = autoCommenter;
        if (this.autoCommenter != null) {
            resolveMask();
            activate();
        }
    }
    
    /**
     * initialize auto commenter
     */ 
    public void activate() {
        if (this.autoCommenter == null) return;
        try{
            this.autoCommenter.addAutoCommentChangeListener(this);
            resetState();
        } catch(java.util.TooManyListenersException tooEx){
            ErrorManager.getDefault().notify(tooEx);
        }
    }
    
    /**
     * deactivate auto commenter
     */ 
    public void deactivate() {
        if (this.autoCommenter == null) return;
        this.autoCommenter.removeAutoCommentChangeListener(this);
        updateForClosing();
    }
    
    private void resetState() {
        if (this.autoCommenter == null) return;
        resetingAll = true;
        badListLastSelectedIndex = -1;
        badList.setModel( WAIT_MODEL );
        autoCommenter.refreshFromSource();
    }
    
    private void resolveMask() {
        modifierMask = 0;
        errorMask = 0;
        
        if ( publicButton.isSelected() )
            modifierMask |= Modifier.PUBLIC;
        if ( protectedButton.isSelected() )
            modifierMask |= Modifier.PROTECTED;
        if ( privateButton.isSelected() )
            modifierMask |= Modifier.PRIVATE;
        
        if ( okButton.isSelected() )
            errorMask |= AutoCommenter.JDC_OK;
        if ( errButton.isSelected() )
            errorMask |= AutoCommenter.JDC_ERROR;
        if ( missButton.isSelected() )
            errorMask |= AutoCommenter.JDC_MISSING;
        
        DocumentationSettings ds = ((DocumentationSettings)SharedClassObject.findObject(DocumentationSettings.class, true));
        
        ds.setAutocommentModifierMask( modifierMask );
        ds.setAutocommentPackage( packageButton.isSelected() );
        ds.setAutocommentErrorMask( errorMask );
        
        
    }

    private void refreshState(){
        resolveMask();
        resetState();
    }    

    private void replaceModel(ListModel lm) {
        updatingBadList = true;
        resetingAll = false;
        ListSelectionModel lsm = badList.getSelectionModel();
        lsm.removeListSelectionListener(this);
        badList.setModel(lm);
        lsm.addListSelectionListener(this);

        errorListBox.setModel( EMPTY_MODEL );
        badList.setSelectedIndex(-1);
        badListLastSelectedIndex = -1;
        updatingBadList = false;
        javaDocEditor.enableButtons( false );
    }

    // Impelmentation of externalizable
    
    /**
     */
    public void resolveButtonState() {
        
        DocumentationSettings ds = ((DocumentationSettings)SharedClassObject.findObject(DocumentationSettings.class, true));
        
        final int modifierMask = ds.getAutocommentModifierMask();
        final boolean pckg = ds.getAutocommentPackage();
        final int errorMask = ds.getAutocommentErrorMask();
        
        javax.swing.SwingUtilities.invokeLater( new Runnable() {
            public void run() {
                publicButton.setSelected( (modifierMask & Modifier.PUBLIC) != 0 );
                protectedButton.setSelected( (modifierMask & Modifier.PROTECTED) != 0 );
                privateButton.setSelected( (modifierMask & Modifier.PRIVATE) != 0 );
                packageButton.setSelected( pckg );
                
                okButton.setSelected( ( errorMask & AutoCommenter.JDC_OK ) != 0 );
                errButton.setSelected( ( errorMask & AutoCommenter.JDC_ERROR ) != 0 );
                missButton.setSelected( ( errorMask & AutoCommenter.JDC_MISSING) != 0 );
            }
        } );
    }
    
    
    // Implementation of ListSelectionListener
    /**
     */
    public void valueChanged(final ListSelectionEvent evt) {
        elementSelection( evt );
    }
    
    // implementation of AutoCommenter.AutoCommentChangeListener
    public void listChanged() {
        final ListModel lm = autoCommenter.prepareListModel(modifierMask, packageButton.isSelected(), errorMask);
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                replaceModel(lm);
            }
        });
    }

    public void elementUpdated(final AutoCommenter.Element el) {
        if (resetingAll) return;
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                DefaultListModel badModel = (DefaultListModel) badList.getModel();
                int index = badModel.indexOf(el);
                if (index < 0) return;
                
                boolean reselect = false;
                int sel = badList.getSelectedIndex();
                try {
                    updatingBadList = true;
                    if (AutoCommenter.acceptElement(el, modifierMask, packageButton.isSelected(), errorMask)) {
                        badModel.setElementAt(el, index);
                    } else {
                        reselect = true;
                        badModel.removeElement(el);
                    }
                } finally {
                    updatingBadList = false;
                }
                if (reselect && sel == index) {
                    // updated element was filtered out of the list so we need to select the next element
                    int size = badModel.getSize();
                    badListLastSelectedIndex = -1; // do not modify javadoc
                    if (size == 0) {
                        elementSelection(new ListSelectionEvent(badModel, -1, -1, false));
                    } else {
                        sel = (sel >= size)? size - 1: sel;
                        badList.setSelectedIndex(sel);
                    }
                } else if (!reselect && sel == index) {
                    // in case auto correct is called; do not store javadoc but refresch ui components
                    badListLastSelectedIndex = -1;  // do not modify javadoc
                    elementSelection(new ListSelectionEvent(badModel, sel, sel, false));
                }
            }
        });
    }


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

#1 New Release!

FP Best Seller

 

new blog posts

 

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.