KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javadoc > comments > AutoCommentPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.javadoc.comments;
21
22 import java.lang.reflect.Modifier JavaDoc;
23 import java.util.ResourceBundle JavaDoc;
24 import javax.swing.*;
25 import javax.swing.event.ListSelectionListener JavaDoc;
26 import javax.swing.event.ListSelectionEvent JavaDoc;
27 import java.awt.*;
28
29 import org.openide.ErrorManager;
30 import org.openide.DialogDisplayer;
31 import org.openide.NotifyDescriptor;
32
33 import org.netbeans.modules.javadoc.settings.DocumentationSettings;
34 import org.netbeans.api.javahelp.Help;
35 import org.openide.src.JavaDoc;
36 import org.openide.util.*;
37
38 /**
39  */

40 public class AutoCommentPanel
41 extends javax.swing.JPanel JavaDoc
42 implements ListSelectionListener JavaDoc, AutoCommenter.AutoCommentChangeListener {
43     
44     AutoCommenter autoCommenter;
45     
46     private JavaDocEditorPanel javaDocEditor = new JavaDocEditorPanel();
47     private boolean resetingAll = false;
48     private boolean updatingBadList = false;
49     
50     private final DefaultListModel EMPTY_MODEL = new DefaultListModel();
51     static final String JavaDoc WAIT_STRING = "WAIT.MODEL"; // NOI18N
52
private final DefaultListModel WAIT_MODEL = new DefaultListModel();
53     
54     private int modifierMask;
55     private int errorMask;
56     /** The state of the window is stored in hidden options of DocumentationSettings */
57     DocumentationSettings dss = ((DocumentationSettings)SharedClassObject.findObject(DocumentationSettings.class, true));
58     
59     static final long serialVersionUID =1845033305150331568L;
60     /** last selected items of the {@link #badList} */
61     private Object JavaDoc[] LAST_SELECTION;
62
63     /** Creates new form AutoCommentPanel
64      */

65     public AutoCommentPanel() {
66         WAIT_MODEL.addElement( WAIT_STRING );
67         initComponents ();
68         
69         // unselectable error list
70
this.errorListBox.setCellRenderer(new DefaultListCellRenderer() {
71             public Component getListCellRendererComponent(
72                     JList list,
73                     Object JavaDoc value,
74                     int index,
75                     boolean isSelected,
76                     boolean cellHasFocus) {
77                 return super.getListCellRendererComponent(list, value, index, false, false);
78             }
79             
80         });
81         
82         javaDocEditor.setEnabled(false);
83         
84         ResourceBundle JavaDoc b = org.openide.util.NbBundle.getBundle(AutoCommentPanel.class);
85         defaultButton.setMnemonic( b.getString("CTL_AutoCommentPanel.defaultButton.text_Mnemonic").charAt(0) );
86         sourceButton.setMnemonic( b.getString("CTL_AutoCommentPanel.sourceButton.text_Mnemonic").charAt(0) );
87         refreshButton.setMnemonic( b.getString("CTL_AutoCommentPanel.refreshButton.text_Mnemonic").charAt(0) );
88         helpButton.setMnemonic( b.getString("CTL_AutoCommentPanel.helpButton.text_Mnemonic").charAt(0) );
89         
90         okButton.setMnemonic(b.getString("MNEMO_AutoCommentPanel.okButton").charAt(0));
91         errButton.setMnemonic(b.getString("MNEMO_AutoCommentPanel.errButton").charAt(0));
92         missButton.setMnemonic(b.getString("MNEMO_AutoCommentPanel.missButton").charAt(0));
93         publicButton.setMnemonic(b.getString("MNEMO_AutoCommentPanel.publicButton").charAt(0));
94         packageButton.setMnemonic(b.getString("MNEMO_AutoCommentPanel.packageButton").charAt(0));
95         protectedButton.setMnemonic(b.getString("MNEMO_AutoCommentPanel.protectedButton").charAt(0));
96         privateButton.setMnemonic(b.getString("MNEMO_AutoCommentPanel.privateButton").charAt(0));
97         
98         splittedPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, classInfoPanel, javaDocEditor);
99         splittedPanel.setDividerSize(5);
100         add(splittedPanel);
101         
102         okButton.setIcon(new ImageIcon(Utilities.loadImage("org/netbeans/modules/javadoc/comments/resources/ok.gif"))); // NOI18N
103
errButton.setIcon(new ImageIcon(Utilities.loadImage("org/netbeans/modules/javadoc/comments/resources/error.gif"))); // NOI18N
104
missButton.setIcon(new ImageIcon(Utilities.loadImage("org/netbeans/modules/javadoc/comments/resources/missing.gif"))); // NOI18N
105

106         publicButton.setIcon(new ImageIcon(Utilities.loadImage("org/netbeans/modules/javadoc/comments/resources/public.gif"))); // NOI18N
107
packageButton.setIcon(new ImageIcon(Utilities.loadImage("org/netbeans/modules/javadoc/comments/resources/package.gif"))); // NOI18N
108
protectedButton.setIcon(new ImageIcon(Utilities.loadImage("org/netbeans/modules/javadoc/comments/resources/protected.gif"))); // NOI18N
109
privateButton.setIcon(new ImageIcon(Utilities.loadImage("org/netbeans/modules/javadoc/comments/resources/private.gif"))); // NOI18N
110

111         resolveButtonState();
112         
113         badList.setCellRenderer( new AutoCommentListCellRenderer() );
114         badList.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
115         
116         elementSelection( new ListSelectionEvent JavaDoc( badList.getModel(), -1, -1, false ) );
117         initAccessibility(b);
118     }
119     
120     private void initAccessibility(ResourceBundle JavaDoc b)
121     {
122         badList.getAccessibleContext().setAccessibleName(b.getString("ACS_AutoCommentPanel.methodListA11yName")); // NOI18N
123
badList.getAccessibleContext().setAccessibleDescription(b.getString("ACS_AutoCommentPanel.methodListA11yDesc")); // NOI18N
124
nameLabel.getAccessibleContext().setAccessibleDescription(b.getString("ACS_AutoCommentPanel.nameLabel.textA11yDesc")); // NOI18N
125
classTextField.getAccessibleContext().setAccessibleName(b.getString("ACS_AutoCommentPanel.nameTextField.textA11yName")); // NOI18N
126
errorListBox.getAccessibleContext().setAccessibleName(b.getString("ACS_AutoCommentPanel.commentList.textA11yName")); // NOI18N
127
errorListBox.getAccessibleContext().setAccessibleDescription(b.getString("ACS_AutoCommentPanel.commentList.textA11yDesc")); // NOI18N
128
}
129     
130     /** This method is called from within the constructor to
131      * initialize the form.
132      * WARNING: Do NOT modify this code. The content of this method is
133      * always regenerated by the FormEditor.
134      */

135     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
136
private void initComponents() {
137         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
138
139         classInfoPanel = new javax.swing.JPanel JavaDoc();
140         filterPanel = new javax.swing.JPanel JavaDoc();
141         okButton = new javax.swing.JToggleButton JavaDoc();
142         errButton = new javax.swing.JToggleButton JavaDoc();
143         missButton = new javax.swing.JToggleButton JavaDoc();
144         publicButton = new javax.swing.JToggleButton JavaDoc();
145         packageButton = new javax.swing.JToggleButton JavaDoc();
146         protectedButton = new javax.swing.JToggleButton JavaDoc();
147         privateButton = new javax.swing.JToggleButton JavaDoc();
148         jPanel2 = new javax.swing.JPanel JavaDoc();
149         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
150         badList = new javax.swing.JList JavaDoc();
151         buttonPanel = new javax.swing.JPanel JavaDoc();
152         defaultButton = new javax.swing.JButton JavaDoc();
153         sourceButton = new javax.swing.JButton JavaDoc();
154         refreshButton = new javax.swing.JButton JavaDoc();
155         helpButton = new javax.swing.JButton JavaDoc();
156         jPanel3 = new javax.swing.JPanel JavaDoc();
157         detailsPanel = new javax.swing.JPanel JavaDoc();
158         nameLabel = new javax.swing.JLabel JavaDoc();
159         classTextField = new javax.swing.JTextField JavaDoc();
160         jScrollPane2 = new javax.swing.JScrollPane JavaDoc();
161         errorListBox = new javax.swing.JList JavaDoc();
162
163         FormListener formListener = new FormListener();
164
165         setLayout(new java.awt.BorderLayout JavaDoc());
166
167         setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(0, 0, 0, 0)));
168         classInfoPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
169
170         classInfoPanel.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(6, 6, 5, 5)));
171         classInfoPanel.setName("classInfoPanel");
172         filterPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
173
174         okButton.setSelected(true);
175         okButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.okButton.toolTipText"));
176         okButton.setActionCommand("ALL");
177         okButton.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
178         okButton.addActionListener(formListener);
179
180         filterPanel.add(okButton, new java.awt.GridBagConstraints JavaDoc());
181
182         errButton.setSelected(true);
183         errButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.errButton.toolTipText"));
184         errButton.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
185         errButton.addActionListener(formListener);
186
187         filterPanel.add(errButton, new java.awt.GridBagConstraints JavaDoc());
188
189         missButton.setSelected(true);
190         missButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.missButton.toolTipText"));
191         missButton.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
192         missButton.addActionListener(formListener);
193
194         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
195         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 6);
196         filterPanel.add(missButton, gridBagConstraints);
197
198         publicButton.setSelected(true);
199         publicButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.publicButton.toolTipText"));
200         publicButton.setActionCommand("PUBLIC");
201         publicButton.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
202         publicButton.addActionListener(formListener);
203
204         filterPanel.add(publicButton, new java.awt.GridBagConstraints JavaDoc());
205
206         packageButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.packageButton.toolTipText"));
207         packageButton.setActionCommand("PACKAGE");
208         packageButton.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
209         packageButton.addActionListener(formListener);
210
211         filterPanel.add(packageButton, new java.awt.GridBagConstraints JavaDoc());
212
213         protectedButton.setSelected(true);
214         protectedButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.protectedButton.toolTipText"));
215         protectedButton.setActionCommand("PROTECTED");
216         protectedButton.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
217         protectedButton.addActionListener(formListener);
218
219         filterPanel.add(protectedButton, new java.awt.GridBagConstraints JavaDoc());
220
221         privateButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.privateButton.toolTipText"));
222         privateButton.setActionCommand("PRIVATE");
223         privateButton.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
224         privateButton.addActionListener(formListener);
225
226         filterPanel.add(privateButton, new java.awt.GridBagConstraints JavaDoc());
227
228         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
229         gridBagConstraints.weightx = 1.0;
230         filterPanel.add(jPanel2, gridBagConstraints);
231
232         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
233         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
234         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
235         gridBagConstraints.weightx = 1.0;
236         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 5, 6);
237         classInfoPanel.add(filterPanel, gridBagConstraints);
238
239         badList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
240         badList.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.methodListA11yDesc"));
241         jScrollPane1.setViewportView(badList);
242
243         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
244         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
245         gridBagConstraints.weightx = 0.6;
246         gridBagConstraints.weighty = 1.0;
247         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
248         classInfoPanel.add(jScrollPane1, gridBagConstraints);
249
250         buttonPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
251
252         buttonPanel.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(0, 5, 0, 0)));
253         defaultButton.setText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.defaultButton.text"));
254         defaultButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.defaultButton.textA11yDesc"));
255         defaultButton.setActionCommand("Default Comment");
256         defaultButton.setMargin(new java.awt.Insets JavaDoc(2, 4, 2, 4));
257         defaultButton.addActionListener(formListener);
258
259         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
260         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
261         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
262         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
263         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
264         buttonPanel.add(defaultButton, gridBagConstraints);
265
266         sourceButton.setText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.sourceButton.text"));
267         sourceButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.sourceButton.textA11yDesc"));
268         sourceButton.setMargin(new java.awt.Insets JavaDoc(2, 4, 2, 4));
269         sourceButton.addActionListener(formListener);
270
271         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
272         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
273         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
274         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
275         buttonPanel.add(sourceButton, gridBagConstraints);
276
277         refreshButton.setText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.refreshButton.text"));
278         refreshButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.refreshButton.textA11yDesc"));
279         refreshButton.setMargin(new java.awt.Insets JavaDoc(2, 4, 2, 4));
280         refreshButton.addActionListener(formListener);
281
282         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
283         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
284         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
285         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
286         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
287         buttonPanel.add(refreshButton, gridBagConstraints);
288
289         helpButton.setText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutocommentPanel.helpButton.text"));
290         helpButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutocommentPanel.helpButton.tooltipText"));
291         helpButton.addActionListener(formListener);
292
293         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
294         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
295         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
296         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 0, 0, 0);
297         buttonPanel.add(helpButton, gridBagConstraints);
298
299         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
300         gridBagConstraints.weighty = 1.0;
301         buttonPanel.add(jPanel3, gridBagConstraints);
302
303         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
304         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
305         gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
306         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
307         gridBagConstraints.weighty = 0.6;
308         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 5, 0, 6);
309         classInfoPanel.add(buttonPanel, gridBagConstraints);
310
311         detailsPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
312
313         nameLabel.setLabelFor(classTextField);
314         nameLabel.setText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("AutoCommentPanel.nameLabel.text"));
315         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
316         gridBagConstraints.gridx = 0;
317         gridBagConstraints.gridy = 0;
318         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
319         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
320         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 11, 0);
321         detailsPanel.add(nameLabel, gridBagConstraints);
322
323         classTextField.setEditable(false);
324         classTextField.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.nameTextField.textA11yDesc"));
325         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
326         gridBagConstraints.gridx = 1;
327         gridBagConstraints.gridy = 0;
328         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
329         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
330         gridBagConstraints.weightx = 1.0;
331         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 11, 0);
332         detailsPanel.add(classTextField, gridBagConstraints);
333
334         errorListBox.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.commentList.textA11yDesc"));
335         jScrollPane2.setViewportView(errorListBox);
336
337         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
338         gridBagConstraints.gridx = 0;
339         gridBagConstraints.gridy = 1;
340         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
341         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
342         gridBagConstraints.weightx = 1.0;
343         gridBagConstraints.weighty = 1.0;
344         detailsPanel.add(jScrollPane2, gridBagConstraints);
345
346         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
347         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
348         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
349         gridBagConstraints.weightx = 1.0;
350         gridBagConstraints.weighty = 0.4;
351         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 5, 5, 6);
352         classInfoPanel.add(detailsPanel, gridBagConstraints);
353
354         add(classInfoPanel, java.awt.BorderLayout.CENTER);
355
356     }
357
358     // Code for dispatching events from components to event handlers.
359

360     private class FormListener implements java.awt.event.ActionListener JavaDoc {
361         public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
362             if (evt.getSource() == okButton) {
363                 AutoCommentPanel.this.okButtonActionPerformed(evt);
364             }
365             else if (evt.getSource() == errButton) {
366                 AutoCommentPanel.this.errButtonActionPerformed(evt);
367             }
368             else if (evt.getSource() == missButton) {
369                 AutoCommentPanel.this.missButtonActionPerformed(evt);
370             }
371             else if (evt.getSource() == publicButton) {
372                 AutoCommentPanel.this.publicButtonActionPerformed(evt);
373             }
374             else if (evt.getSource() == packageButton) {
375                 AutoCommentPanel.this.packageButtonActionPerformed(evt);
376             }
377             else if (evt.getSource() == protectedButton) {
378                 AutoCommentPanel.this.protectedButtonActionPerformed(evt);
379             }
380             else if (evt.getSource() == privateButton) {
381                 AutoCommentPanel.this.privateButtonActionPerformed(evt);
382             }
383             else if (evt.getSource() == defaultButton) {
384                 AutoCommentPanel.this.defaultButtonActionPerformed(evt);
385             }
386             else if (evt.getSource() == sourceButton) {
387                 AutoCommentPanel.this.sourceButtonActionPerformed(evt);
388             }
389             else if (evt.getSource() == refreshButton) {
390                 AutoCommentPanel.this.refreshButtonActionPerformed(evt);
391             }
392             else if (evt.getSource() == helpButton) {
393                 AutoCommentPanel.this.helpButtonActionPerformed(evt);
394             }
395         }
396     }
397     // </editor-fold>//GEN-END:initComponents
398

399     private void helpButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_helpButtonActionPerformed
400
Help help=(Help)Lookup.getDefault().lookup(Help.class);
401         
402         help.showHelp(
403             new org.openide.util.HelpCtx(AutoCommentTopComponent.AUTO_COMMENT_HELP_CTX_KEY));
404     }//GEN-LAST:event_helpButtonActionPerformed
405

406     private void missButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_missButtonActionPerformed
407
refreshState();
408     }//GEN-LAST:event_missButtonActionPerformed
409

410     private void errButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_errButtonActionPerformed
411
refreshState();
412     }//GEN-LAST:event_errButtonActionPerformed
413

414     private void okButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_okButtonActionPerformed
415
refreshState();
416     }//GEN-LAST:event_okButtonActionPerformed
417

418     private void refreshButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_refreshButtonActionPerformed
419
resetingAll = true;
420         updateForClosing();
421         resetState();
422     }//GEN-LAST:event_refreshButtonActionPerformed
423

424     
425     private void privateButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_privateButtonActionPerformed
426
refreshState();
427     }//GEN-LAST:event_privateButtonActionPerformed
428

429     private void protectedButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_protectedButtonActionPerformed
430
refreshState();
431     }//GEN-LAST:event_protectedButtonActionPerformed
432

433     private void packageButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_packageButtonActionPerformed
434
refreshState();
435     }//GEN-LAST:event_packageButtonActionPerformed
436

437     private void publicButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_publicButtonActionPerformed
438
refreshState();
439     }//GEN-LAST:event_publicButtonActionPerformed
440

441         
442     private void defaultButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_defaultButtonActionPerformed
443
int sel = badList.getMinSelectionIndex();
444         
445         if ( sel == -1 )
446             return;
447         
448         AutoCommenter.Element[] elements = getSelectedElements();
449         if (elements.length == 1) {
450             JavaDoc doc = null;
451             javaDocEditor.commitTagChange();
452             if (javaDocEditor.isDirty()) {
453                 doc = javaDocEditor.getUpdatedJavaDoc();
454             }
455             this.autoCommenter.autoCorrectJavadoc(elements[0], doc);
456         } else {
457             this.autoCommenter.autoCorrectJavadoc(elements);
458         }
459     }//GEN-LAST:event_defaultButtonActionPerformed
460

461     private void sourceButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_sourceButtonActionPerformed
462
int sel = badList.getMinSelectionIndex();
463         
464         if ( sel == -1 || !badList.isEnabled())
465             return;
466
467         final AutoCommenter.Element element = (AutoCommenter.Element) badList.getModel().getElementAt( sel );
468         if (element.isValid()) {
469             element.viewSource();
470         }
471
472     }//GEN-LAST:event_sourceButtonActionPerformed
473

474     
475     // Variables declaration - do not modify//GEN-BEGIN:variables
476
private javax.swing.JList JavaDoc badList;
477     private javax.swing.JPanel JavaDoc buttonPanel;
478     private javax.swing.JPanel JavaDoc classInfoPanel;
479     private javax.swing.JTextField JavaDoc classTextField;
480     private javax.swing.JButton JavaDoc defaultButton;
481     private javax.swing.JPanel JavaDoc detailsPanel;
482     private javax.swing.JToggleButton JavaDoc errButton;
483     private javax.swing.JList JavaDoc errorListBox;
484     private javax.swing.JPanel JavaDoc filterPanel;
485     private javax.swing.JButton JavaDoc helpButton;
486     private javax.swing.JPanel JavaDoc jPanel2;
487     private javax.swing.JPanel JavaDoc jPanel3;
488     private javax.swing.JScrollPane JavaDoc jScrollPane1;
489     private javax.swing.JScrollPane JavaDoc jScrollPane2;
490     private javax.swing.JToggleButton JavaDoc missButton;
491     private javax.swing.JLabel JavaDoc nameLabel;
492     private javax.swing.JToggleButton JavaDoc okButton;
493     private javax.swing.JToggleButton JavaDoc packageButton;
494     private javax.swing.JToggleButton JavaDoc privateButton;
495     private javax.swing.JToggleButton JavaDoc protectedButton;
496     private javax.swing.JToggleButton JavaDoc publicButton;
497     private javax.swing.JButton JavaDoc refreshButton;
498     private javax.swing.JButton JavaDoc sourceButton;
499     // End of variables declaration//GEN-END:variables
500
private JSplitPane splittedPanel;
501        
502     public void updateForClosing() {
503         int sel = badList.getMinSelectionIndex();
504         boolean isNotMultiselect = sel == badList.getMaxSelectionIndex();
505         if (sel >= 0 && isNotMultiselect) {
506             if( !(badList.getModel().getElementAt( 0 ) instanceof AutoCommenter.Element) )
507                   return;
508             javaDocEditor.updateForClosing();
509             AutoCommenter.Element el = (AutoCommenter.Element) badList.getModel().getElementAt(sel);
510             if (el.isValid() && badList.isEnabled()) {
511                 modifyJavaDoc(el);
512             }
513         }
514     }
515     
516     private void showCommentEditor( final AutoCommenter.Element el ) {
517         javaDocEditor.setElement(el);
518         javaDocEditor.setJavaDoc(el.getJavaDoc());
519     }
520     
521     private void modifyJavaDoc(final AutoCommenter.Element el) {
522         javaDocEditor.commitTagChange();
523         if (! javaDocEditor.isDirty()) {
524             return;
525         }
526         this.autoCommenter.modifyJavadoc(el, javaDocEditor.getUpdatedJavaDoc());
527         javaDocEditor.setDirty(false);
528     }
529     
530     private void elementSelection( ListSelectionEvent JavaDoc evt ) {
531         // This is to prevente an infinite loop when performing an update to
532
// the list
533
if (updatingBadList || (evt != null && evt.getValueIsAdjusting())) {
534             return;
535         }
536         
537         int sel = badList.getMinSelectionIndex();
538         boolean isMultiselect = sel != badList.getMaxSelectionIndex();
539         ListModel badModel = badList.getModel();
540         
541         // If there was an item selected before changing, check to see if we
542
// have to update the current javadoc.
543
if (LAST_SELECTION != null && LAST_SELECTION.length == 1) {
544             // System.out.println("run modifyJavaDoc for element " + badListLastSelectedIndex);
545
//check for no resolved
546
if(!(badModel.getElementAt(0) instanceof AutoCommenter.Element))
547                 return;
548
549             AutoCommenter.Element element = (AutoCommenter.Element) findLastObject();
550             if (element != null && element.isValid() && badList.isEnabled()) {
551                 modifyJavaDoc(element);
552             } else {
553                 badList.setEnabled(false);
554                 DialogDisplayer.getDefault().notify(
555                         new NotifyDescriptor.Message(
556                                 NbBundle.getMessage(AutoCommentPanel.class, "MSG_IvalidSource"),
557                                 NotifyDescriptor.WARNING_MESSAGE));
558                 return;
559             }
560         }
561           
562         if ( sel < 0 ) {
563             LAST_SELECTION = null;
564             errorListBox.setModel(EMPTY_MODEL);
565             defaultButton.setEnabled( false );
566             sourceButton.setEnabled( false );
567             classTextField.setText( "" ); // NOI18N
568
javaDocEditor.clear();
569             javaDocEditor.setEnabled(false);
570         } else if (isMultiselect) {
571             LAST_SELECTION = badList.getSelectedValues();
572             errorListBox.setModel(EMPTY_MODEL);
573             sourceButton.setEnabled(false);
574             classTextField.setText(""); // NOI18N
575
javaDocEditor.clear();
576             javaDocEditor.setEnabled(false);
577             boolean canCorrect = isCorrectable(getSelectedElements());
578             defaultButton.setEnabled(canCorrect);
579         } else {
580             //check for no resolved
581
if( !(badModel.getElementAt(0) instanceof AutoCommenter.Element) ) {
582                 LAST_SELECTION = null;
583                 return;
584             }
585             LAST_SELECTION = badList.getSelectedValues();
586
587             AutoCommenter.Element element = (AutoCommenter.Element) LAST_SELECTION[0];
588             String JavaDoc dcName = element.getDescriptor().getDeclaringClassName();
589             if (dcName == null) {
590                 dcName = element.getDescriptor().getName();
591             }
592             classTextField.setText(dcName);
593             
594             defaultButton.setEnabled( element.isCorrectable() );
595             sourceButton.setEnabled( true );
596             javaDocEditor.setEnabled( true );
597             
598             errorListBox.setModel( element.getErrorList() );
599             showCommentEditor(element);
600         }
601     }
602     
603     /** gets array of selected elements from the list model or empty array;
604      * it should be called from EDT only.
605      */

606     private AutoCommenter.Element[] getSelectedElements() {
607         if(!(badList.getModel().getElementAt(0) instanceof AutoCommenter.Element)) {
608             return new AutoCommenter.Element[0];
609         }
610         Object JavaDoc[] objs = badList.getSelectedValues();
611         AutoCommenter.Element[] els = new AutoCommenter.Element[objs.length];
612         for (int i = 0; i < objs.length; i++) {
613             els[i] = (AutoCommenter.Element) objs[i];
614         }
615         return els;
616     }
617     
618     /** returns true in case all elements are correctable */
619     private static boolean isCorrectable(AutoCommenter.Element[] els) {
620         assert els != null;
621         for (int i = 0; i < els.length; i++) {
622             if (!els[i].isCorrectable() || !els[i].isValid()) {
623                 return false;
624             }
625         }
626         return els.length > 0;
627     }
628     
629     void setAutoCommenter( AutoCommenter autoCommenter ) {
630         if (this.autoCommenter != null) {
631             this.autoCommenter.removeAutoCommentChangeListener(this);
632         }
633         this.autoCommenter = autoCommenter;
634         if (this.autoCommenter != null) {
635             resolveMask();
636             activate();
637         } else {
638             this.LAST_SELECTION = null;
639         }
640     }
641     
642     /**
643      * initialize auto commenter
644      */

645     public void activate() {
646         if (this.autoCommenter == null) return;
647         try{
648             this.autoCommenter.addAutoCommentChangeListener(this);
649             resetState();
650         } catch(java.util.TooManyListenersException JavaDoc tooEx){
651             ErrorManager.getDefault().notify(tooEx);
652         }
653     }
654     
655     /**
656      * deactivate auto commenter
657      */

658     public void deactivate() {
659         if (this.autoCommenter == null) return;
660         this.autoCommenter.removeAutoCommentChangeListener(this);
661         updateForClosing();
662     }
663     
664     private void resetState() {
665         if (this.autoCommenter == null) return;
666         resetingAll = true;
667         badList.getSelectionModel().removeListSelectionListener(this);
668         badList.setModel( WAIT_MODEL );
669         autoCommenter.refreshFromSource();
670     }
671     
672     private void resolveMask() {
673         modifierMask = 0;
674         errorMask = 0;
675         
676         if ( publicButton.isSelected() )
677             modifierMask |= Modifier.PUBLIC;
678         if ( protectedButton.isSelected() )
679             modifierMask |= Modifier.PROTECTED;
680         if ( privateButton.isSelected() )
681             modifierMask |= Modifier.PRIVATE;
682         
683         if ( okButton.isSelected() )
684             errorMask |= AutoCommenter.JDC_OK;
685         if ( errButton.isSelected() )
686             errorMask |= AutoCommenter.JDC_ERROR;
687         if ( missButton.isSelected() )
688             errorMask |= AutoCommenter.JDC_MISSING;
689         
690         DocumentationSettings ds = ((DocumentationSettings)SharedClassObject.findObject(DocumentationSettings.class, true));
691         
692         ds.setAutocommentModifierMask( modifierMask );
693         ds.setAutocommentPackage( packageButton.isSelected() );
694         ds.setAutocommentErrorMask( errorMask );
695         
696         
697     }
698
699     private void refreshState(){
700         resolveMask();
701         resetState();
702     }
703
704     private void replaceModel(ListModel lm) {
705         updatingBadList = true;
706         resetingAll = false;
707         ListSelectionModel lsm = badList.getSelectionModel();
708         lsm.removeListSelectionListener(this);
709         badList.setEnabled(true);
710         badList.setModel(lm);
711         lsm.addListSelectionListener(this);
712
713         errorListBox.setModel( EMPTY_MODEL );
714         updatingBadList = false;
715
716         int[] lasts = findIndicies(lm, LAST_SELECTION);
717         LAST_SELECTION = null;
718         if (lasts != null && lasts.length > 0) {
719             badList.setSelectedIndices(lasts);
720         } else {
721             elementSelection(new ListSelectionEvent JavaDoc(lm, -1, -1, false));
722         }
723     }
724
725     /**
726      * finds indicies of items in the listmodel
727      * @param lm model where to search
728      * @param items what search
729      * @return indicies of items in the listmodel
730      */

731     private static int[] findIndicies(ListModel lm, Object JavaDoc[] items) {
732         int[] indecies = null;
733         if (items != null) {
734             indecies = new int[items.length];
735             int count = 0;
736             for (int i = 0; i < lm.getSize(); i++) {
737                 Object JavaDoc el = lm.getElementAt(i);
738                 for (int j = 0; j < items.length; j++) {
739                     Object JavaDoc last = items[j];
740                     if (last.equals(el)) {
741                         indecies[count++] = i;
742                         break;
743                     }
744                 }
745             }
746
747             if (count != items.length) {
748                 int[] temp = indecies;
749                 indecies = new int[count];
750                 for (int i = 0; i < indecies.length; i++) {
751                     indecies[i] = temp[i];
752                 }
753             }
754         }
755         return indecies;
756     }
757
758     private Object JavaDoc findLastObject() {
759         ListModel lm = badList.getModel();
760         if (LAST_SELECTION != null && LAST_SELECTION.length == 1) {
761             for (int i = 0; i < lm.getSize(); i++) {
762                 Object JavaDoc el = lm.getElementAt(i);
763                     if (LAST_SELECTION[0].equals(el)) {
764                         return el;
765                     }
766             }
767         }
768         return null;
769     }
770
771     /** customize ui according to stored settings
772      */

773     public void resolveButtonState() {
774         
775         DocumentationSettings ds = ((DocumentationSettings)SharedClassObject.findObject(DocumentationSettings.class, true));
776         
777         final int modifierMask = ds.getAutocommentModifierMask();
778         final boolean pckg = ds.getAutocommentPackage();
779         final int errorMask = ds.getAutocommentErrorMask();
780         
781         publicButton.setSelected( (modifierMask & Modifier.PUBLIC) != 0 );
782         protectedButton.setSelected( (modifierMask & Modifier.PROTECTED) != 0 );
783         privateButton.setSelected( (modifierMask & Modifier.PRIVATE) != 0 );
784         packageButton.setSelected( pckg );
785         
786         okButton.setSelected( ( errorMask & AutoCommenter.JDC_OK ) != 0 );
787         errButton.setSelected( ( errorMask & AutoCommenter.JDC_ERROR ) != 0 );
788         missButton.setSelected( ( errorMask & AutoCommenter.JDC_MISSING) != 0 );
789     }
790     
791     
792     // Implementation of ListSelectionListener
793
/**
794      */

795     public void valueChanged(final ListSelectionEvent JavaDoc evt) {
796         elementSelection( evt );
797     }
798     
799     // implementation of AutoCommenter.AutoCommentChangeListener
800
public void listChanged() {
801         final ListModel lm = autoCommenter.prepareListModel(modifierMask, packageButton.isSelected(), errorMask);
802         EventQueue.invokeLater(new Runnable JavaDoc() {
803             public void run() {
804                 replaceModel(lm);
805             }
806         });
807     }
808
809     public void elementUpdated(final AutoCommenter.Element el) {
810         if (resetingAll) return;
811         EventQueue.invokeLater(new Runnable JavaDoc() {
812             public void run() {
813                 DefaultListModel badModel = (DefaultListModel) badList.getModel();
814                 int index = badModel.indexOf(el);
815                 if (index < 0) return;
816                 
817                 boolean reselect = false;
818                 int sel = badList.getSelectedIndex();
819                 try {
820                     updatingBadList = true;
821                     if (AutoCommenter.acceptElement(el, modifierMask, packageButton.isSelected(), errorMask)) {
822                         badModel.setElementAt(el, index);
823                     } else {
824                         reselect = true;
825                         badModel.removeElement(el);
826                     }
827                 } finally {
828                     updatingBadList = false;
829                 }
830                 if (reselect && sel == index) {
831                     // updated element was filtered out of the list so we need to select the next element
832
int size = badModel.getSize();
833                     LAST_SELECTION = null;
834                     if (size == 0) {
835                         elementSelection(new ListSelectionEvent JavaDoc(badModel, -1, -1, false));
836                     } else {
837                         sel = (sel >= size)? size - 1: sel;
838                         badList.setSelectedIndex(sel);
839                     }
840                 } else if (!reselect && sel == index) {
841                     // in case auto correct is called; do not store javadoc but refresch ui components
842
LAST_SELECTION = null;
843                     elementSelection(new ListSelectionEvent JavaDoc(badModel, sel, sel, false));
844                 }
845             }
846         });
847     }
848
849
850 }
851
Popular Tags