KickJava   Java API By Example, From Geeks To Geeks.

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


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.awt.CardLayout JavaDoc;
23 import java.awt.event.KeyEvent JavaDoc;
24 import java.awt.event.InputEvent JavaDoc;
25 import javax.swing.DefaultListModel JavaDoc;
26 import javax.swing.event.DocumentEvent JavaDoc;
27 import javax.swing.event.DocumentListener JavaDoc;
28 import javax.swing.event.ListDataEvent JavaDoc;
29 import javax.swing.event.ListDataListener JavaDoc;
30 import javax.jmi.reflect.InvalidObjectException;
31
32 import org.openide.src.JavaDoc;
33 import org.openide.src.JavaDocTag;
34 import org.openide.src.JavaDocSupport;
35 import org.openide.src.SourceException;
36 import org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor;
37 import org.openide.util.NbBundle;
38 import org.openide.DialogDescriptor;
39 import org.openide.ErrorManager;
40 import org.openide.text.CloneableEditorSupport;
41
42 /**
43  * @author phrebejk
44  * @version
45  */

46 public class JavaDocEditorPanel extends javax.swing.JPanel JavaDoc
47     implements EnhancedCustomPropertyEditor {
48
49     private JavaDoc javaDoc;
50     private DefaultListModel JavaDoc listModel;
51     private int lastSelection = -1;
52
53
54     private EmptyTagPanel emptyTagPanel;
55     private StandardTagPanel standardTagPanel;
56     private SeeTagPanel seeTagPanel;
57     private ParamTagPanel paramTagPanel;
58     private ThrowsTagPanel throwsTagPanel;
59     private SerialFieldTagPanel serialFieldTagPanel;
60
61     private NewTagDialog newTagDialog;
62
63     private AutoCommenter.Element element;
64
65     private MnemonicsDistributor mnemonicsDistributor;
66
67     static final long serialVersionUID =7005703844831686911L;
68     /** Holds value of property dirty. */
69     private boolean dirty;
70     private boolean updatingTagList;
71     private boolean grabFocusAfterNewButton = false;
72
73     /** Creates new form JavaDocEditorPanel
74      */

75     public JavaDocEditorPanel() {
76         initComponents ();
77
78         // Buttons mnemonics
79
newButton.setMnemonic( org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.newButton_Mnemonic").charAt(0) ); //NOI18N
80
deleteButton.setMnemonic( org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.deleteButton_Mnemonic").charAt(0) ); //NOI18N
81
moveUpButton.setMnemonic( org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.moveUpButton_Mnemonic").charAt(0) ); //NOI18N
82
moveDownButton.setMnemonic( org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.moveDownButton_Mnemonic").charAt(0) ); //NOI18N
83
boldButton.setMnemonic( NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_JavaDocEditorPanel.boldButton").charAt(0));
84         italicButton.setMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_JavaDocEditorPanel.italicButton").charAt(0));
85         underlineButton.setMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_JavaDocEditorPanel.underlineButton").charAt(0));
86         codeButton.setMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_JavaDocEditorPanel.codeButton").charAt(0));
87         preButton.setMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_JavaDocEditorPanel.preButton").charAt(0));
88         linkButton.setMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_JavaDocEditorPanel.linkButton").charAt(0));
89
90         commentLabel.setDisplayedMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_JavaDocEditorPanel.textPane").charAt(0));
91         tagListLabel.setDisplayedMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_JavaDocEditorPanel.tagPanel").charAt(0));
92
93         enableButtons( false );
94
95         mnemonicsDistributor = new MnemonicsDistributor();
96
97         commentTextArea.getDocument().addDocumentListener(
98             new DocumentListener JavaDoc() {
99                 public void changedUpdate( DocumentEvent JavaDoc evt) {
100                     dirty = true;
101                 }
102                 public void insertUpdate( DocumentEvent JavaDoc evt) {
103                     dirty = true;
104                 }
105                 public void removeUpdate( DocumentEvent JavaDoc evt) {
106                     dirty = true;
107                 }
108             } );
109         mnemonicsDistributor.registerComponent( commentTextArea );
110
111
112
113         // Make the list to select only one line and listen to selections
114

115         tagList.setVisibleRowCount(4);
116         tagList.getSelectionModel().setSelectionMode( javax.swing.ListSelectionModel.SINGLE_SELECTION );
117
118         // i18n
119

120         // Add panels for different tag types
121

122         emptyTagPanel = new EmptyTagPanel( this );
123         tagParamPanel.add( emptyTagPanel, emptyTagPanel.getCardName() );
124
125         standardTagPanel = new StandardTagPanel( this );
126         tagParamPanel.add( standardTagPanel, standardTagPanel.getCardName() );
127
128         seeTagPanel = new SeeTagPanel( this );
129         tagParamPanel.add( seeTagPanel, seeTagPanel.getCardName() );
130
131
132         paramTagPanel = new ParamTagPanel( this );
133         tagParamPanel.add( paramTagPanel, paramTagPanel.getCardName() );
134
135         throwsTagPanel = new ThrowsTagPanel( this );
136         tagParamPanel.add( throwsTagPanel, throwsTagPanel.getCardName() );
137
138         serialFieldTagPanel = new SerialFieldTagPanel( this );
139         tagParamPanel.add( serialFieldTagPanel, serialFieldTagPanel.getCardName() );
140         
141         initAccessibility();
142     }
143
144     /**
145      */

146     public JavaDocEditorPanel(AutoCommenter.Element element, JavaDoc doc) {
147         this();
148         setElement(element);
149         setJavaDoc(doc);
150     }
151
152     /**
153      */

154     public void clear() {
155         commentTextArea.setText(""); //NOI18N
156
newButton.setEnabled(false);
157         setTagListModel();
158     }
159
160     public void setEnabled(boolean enable) {
161         super.setEnabled(enable);
162         tagList.setEnabled(enable);
163         commentTextArea.setEnabled(enable);
164         newButton.setEnabled(enable);
165     }
166
167     public void updateForClosing() {
168         commitTagChange();
169     }
170
171     private void setTagListModel() {
172         lastSelection = -1;
173         listModel = new DefaultListModel JavaDoc();
174         tagList.setModel( listModel );
175         deleteButton.setEnabled(false);
176         moveUpButton.setEnabled(false);
177         moveDownButton.setEnabled(false);
178         listModel.addListDataListener(
179             new ListDataListener JavaDoc() {
180                 public void intervalAdded(ListDataEvent JavaDoc e) {
181                     dirty = true;
182                 }
183                 public void intervalRemoved(ListDataEvent JavaDoc e) {
184                     dirty = true;
185                 }
186                 public void contentsChanged(ListDataEvent JavaDoc e) {
187                     dirty = true;
188                 }
189             } );
190     }
191
192     public void setJavaDoc(JavaDoc javaDoc) {
193         this.javaDoc = javaDoc;
194
195         if ( javaDoc != null ) {
196             this.javaDoc = javaDoc;
197             commentTextArea.setText( javaDoc.getText() );
198             commentTextArea.setCaretPosition(0);
199         } else {
200             commentTextArea.setText( null );
201         }
202
203         // Put the tags into listbox
204

205         setTagListModel();
206
207         if ( javaDoc != null ) {
208             JavaDocTag tags[] = javaDoc.getTags();
209             for( int i = 0; i < tags.length; i++ ) {
210                 listModel.addElement( tags[i] );
211             }
212
213             if ( listModel.getSize() < 0 ) {
214                 tagList.setSelectedIndex( 0 );
215             }
216         }
217
218         // Add panels for different tag types
219

220         try {
221             standardTagPanel.setElement(element.getSrcElement());
222             paramTagPanel.setElement(element.getSrcElement());
223             throwsTagPanel.setElement(element.getSrcElement());
224         } catch (InvalidObjectException e) {
225             // ignore since AutoCommenter will refresh the model
226
}
227
228         setDirty(false);
229
230         revalidate();
231         repaint();
232     }
233
234     public void setElement(AutoCommenter.Element element) {
235         this.element = element;
236     }
237
238     public AutoCommenter.Element getElement() {
239         return this.element;
240     }
241
242     private void initAccessibility()
243     {
244         commentTextArea.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.commentTextAreaA11yName")); // NOI18N
245
tagList.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.tagListA11yName")); // NOI18N
246
}
247
248     /** This method is called from within the constructor to
249      * initialize the form.
250      * WARNING: Do NOT modify this code. The content of this method is
251      * always regenerated by the FormEditor.
252      */

253     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
254
private void initComponents() {
255         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
256
257         textPanel = new javax.swing.JPanel JavaDoc();
258         commentScrollPane = new javax.swing.JScrollPane JavaDoc();
259         commentTextArea = new javax.swing.JEditorPane JavaDoc(); commentTextArea.setEditorKit(CloneableEditorSupport.getEditorKit("text/html"));
260         tagPanel = new javax.swing.JPanel JavaDoc();
261         newButton = new javax.swing.JButton JavaDoc();
262         deleteButton = new javax.swing.JButton JavaDoc();
263         moveUpButton = new javax.swing.JButton JavaDoc();
264         moveDownButton = new javax.swing.JButton JavaDoc();
265         tagScrollPane = new javax.swing.JScrollPane JavaDoc();
266         tagList = new javax.swing.JList JavaDoc();
267         tagParamPanel = new javax.swing.JPanel JavaDoc();
268         tagListLabel = new javax.swing.JLabel JavaDoc();
269         htmlToolBar = new javax.swing.JPanel JavaDoc();
270         boldButton = new javax.swing.JButton JavaDoc();
271         italicButton = new javax.swing.JButton JavaDoc();
272         underlineButton = new javax.swing.JButton JavaDoc();
273         codeButton = new javax.swing.JButton JavaDoc();
274         preButton = new javax.swing.JButton JavaDoc();
275         linkButton = new javax.swing.JButton JavaDoc();
276         commentLabel = new javax.swing.JLabel JavaDoc();
277
278         FormListener formListener = new FormListener();
279
280         setLayout(new java.awt.GridBagLayout JavaDoc());
281
282         setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 5, 0, 0));
283         textPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
284
285         commentScrollPane.setMinimumSize(new java.awt.Dimension JavaDoc(22, 60));
286         commentTextArea.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.commentTextAreaA11yDesc"));
287         commentTextArea.addFocusListener(formListener);
288
289         commentScrollPane.setViewportView(commentTextArea);
290
291         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
292         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
293         gridBagConstraints.weightx = 1.0;
294         gridBagConstraints.weighty = 1.0;
295         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
296         textPanel.add(commentScrollPane, gridBagConstraints);
297
298         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
299         gridBagConstraints.gridx = 0;
300         gridBagConstraints.gridy = 1;
301         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
302         gridBagConstraints.weighty = 1.0;
303         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 3, 5, 7);
304         add(textPanel, gridBagConstraints);
305
306         tagPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
307
308         newButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.newButton.text"));
309         newButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.newButton.textA11yDesc"));
310         newButton.setMargin(new java.awt.Insets JavaDoc(2, 12, 2, 12));
311         newButton.addActionListener(formListener);
312
313         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
314         gridBagConstraints.gridx = 1;
315         gridBagConstraints.gridy = 2;
316         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
317         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
318         tagPanel.add(newButton, gridBagConstraints);
319
320         deleteButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.deleteButton.text"));
321         deleteButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.deleteButton.textA11yDesc"));
322         deleteButton.setMargin(new java.awt.Insets JavaDoc(2, 12, 2, 12));
323         deleteButton.setEnabled(false);
324         deleteButton.addActionListener(formListener);
325
326         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
327         gridBagConstraints.gridx = 1;
328         gridBagConstraints.gridy = 3;
329         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
330         tagPanel.add(deleteButton, gridBagConstraints);
331
332         moveUpButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.moveUpButton.text"));
333         moveUpButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.moveUpButton.textA11yDesc"));
334         moveUpButton.setActionCommand("UP");
335         moveUpButton.setMargin(new java.awt.Insets JavaDoc(2, 12, 2, 12));
336         moveUpButton.setEnabled(false);
337         moveUpButton.addActionListener(formListener);
338
339         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
340         gridBagConstraints.gridx = 1;
341         gridBagConstraints.gridy = 4;
342         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
343         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 5, 0);
344         tagPanel.add(moveUpButton, gridBagConstraints);
345
346         moveDownButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.moveDownButton.text"));
347         moveDownButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.moveDownButton.textA11yDesc"));
348         moveDownButton.setActionCommand("DOWN");
349         moveDownButton.setMargin(new java.awt.Insets JavaDoc(2, 12, 2, 12));
350         moveDownButton.setEnabled(false);
351         moveDownButton.addActionListener(formListener);
352
353         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
354         gridBagConstraints.gridx = 1;
355         gridBagConstraints.gridy = 5;
356         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
357         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
358         tagPanel.add(moveDownButton, gridBagConstraints);
359
360         tagList.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.tagListA11yDesc"));
361         tagList.addListSelectionListener(formListener);
362
363         tagScrollPane.setViewportView(tagList);
364
365         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
366         gridBagConstraints.gridx = 0;
367         gridBagConstraints.gridy = 1;
368         gridBagConstraints.gridheight = 5;
369         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
370         gridBagConstraints.weightx = 1.0;
371         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
372         tagPanel.add(tagScrollPane, gridBagConstraints);
373
374         tagParamPanel.setLayout(new java.awt.CardLayout JavaDoc());
375
376         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
377         gridBagConstraints.gridx = 0;
378         gridBagConstraints.gridy = 6;
379         gridBagConstraints.gridwidth = 2;
380         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
381         gridBagConstraints.weightx = 1.0;
382         gridBagConstraints.weighty = 1.0;
383         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 5);
384         tagPanel.add(tagParamPanel, gridBagConstraints);
385
386         tagListLabel.setLabelFor(tagList);
387         tagListLabel.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.tagPanel.title"));
388         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
389         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
390         tagPanel.add(tagListLabel, gridBagConstraints);
391
392         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
393         gridBagConstraints.gridx = 0;
394         gridBagConstraints.gridy = 2;
395         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
396         gridBagConstraints.weighty = 1.0;
397         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 3, 11, 7);
398         add(tagPanel, gridBagConstraints);
399
400         htmlToolBar.setLayout(new java.awt.GridLayout JavaDoc(1, 6));
401
402         boldButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.boldButton.text"));
403         boldButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.boldButton.textA11yDesc"));
404         boldButton.setActionCommand("B");
405         boldButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
406         boldButton.setMinimumSize(new java.awt.Dimension JavaDoc(32, 27));
407         boldButton.setRequestFocusEnabled(false);
408         boldButton.addActionListener(formListener);
409
410         htmlToolBar.add(boldButton);
411
412         italicButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.italicButton.text"));
413         italicButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.italicButton.textA11yDesc"));
414         italicButton.setActionCommand("I");
415         italicButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
416         italicButton.setMinimumSize(new java.awt.Dimension JavaDoc(32, 27));
417         italicButton.setRequestFocusEnabled(false);
418         italicButton.addActionListener(formListener);
419
420         htmlToolBar.add(italicButton);
421
422         underlineButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.underlineButton.text"));
423         underlineButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.underlineButton.textA11yDesc"));
424         underlineButton.setActionCommand("U");
425         underlineButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
426         underlineButton.setMinimumSize(new java.awt.Dimension JavaDoc(32, 27));
427         underlineButton.setRequestFocusEnabled(false);
428         underlineButton.addActionListener(formListener);
429
430         htmlToolBar.add(underlineButton);
431
432         codeButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.codeButton.text"));
433         codeButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.codeButton.textA11yDesc"));
434         codeButton.setActionCommand("CODE");
435         codeButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
436         codeButton.setMinimumSize(new java.awt.Dimension JavaDoc(32, 27));
437         codeButton.setRequestFocusEnabled(false);
438         codeButton.addActionListener(formListener);
439
440         htmlToolBar.add(codeButton);
441
442         preButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.preButton.text"));
443         preButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.preButton.textA11yDesc"));
444         preButton.setActionCommand("PRE");
445         preButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
446         preButton.setMinimumSize(new java.awt.Dimension JavaDoc(32, 27));
447         preButton.setRequestFocusEnabled(false);
448         preButton.addActionListener(formListener);
449
450         htmlToolBar.add(preButton);
451
452         linkButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.linkButton.text"));
453         linkButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.linkButton.textA11yDesc"));
454         linkButton.setActionCommand("link");
455         linkButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
456         linkButton.setMinimumSize(new java.awt.Dimension JavaDoc(32, 27));
457         linkButton.setRequestFocusEnabled(false);
458         linkButton.addActionListener(formListener);
459
460         htmlToolBar.add(linkButton);
461
462         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
463         gridBagConstraints.gridx = 0;
464         gridBagConstraints.gridy = 3;
465         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
466         gridBagConstraints.weightx = 1.0;
467         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 7, 11, 7);
468         add(htmlToolBar, gridBagConstraints);
469
470         commentLabel.setLabelFor(commentTextArea);
471         commentLabel.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.textPanel.title"));
472         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
473         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
474         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 3, 0, 0);
475         add(commentLabel, gridBagConstraints);
476
477     }
478
479     // Code for dispatching events from components to event handlers.
480

481     private class FormListener implements java.awt.event.ActionListener JavaDoc, java.awt.event.FocusListener JavaDoc, javax.swing.event.ListSelectionListener JavaDoc {
482         public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
483             if (evt.getSource() == newButton) {
484                 JavaDocEditorPanel.this.newTagButtonActionPerformed(evt);
485             }
486             else if (evt.getSource() == deleteButton) {
487                 JavaDocEditorPanel.this.delTagButtonActionPerformed(evt);
488             }
489             else if (evt.getSource() == moveUpButton) {
490                 JavaDocEditorPanel.this.moveTagButtonActionPerformed(evt);
491             }
492             else if (evt.getSource() == moveDownButton) {
493                 JavaDocEditorPanel.this.moveTagButtonActionPerformed(evt);
494             }
495             else if (evt.getSource() == boldButton) {
496                 JavaDocEditorPanel.this.formatButtonActionPerformed(evt);
497             }
498             else if (evt.getSource() == italicButton) {
499                 JavaDocEditorPanel.this.formatButtonActionPerformed(evt);
500             }
501             else if (evt.getSource() == underlineButton) {
502                 JavaDocEditorPanel.this.formatButtonActionPerformed(evt);
503             }
504             else if (evt.getSource() == codeButton) {
505                 JavaDocEditorPanel.this.formatButtonActionPerformed(evt);
506             }
507             else if (evt.getSource() == preButton) {
508                 JavaDocEditorPanel.this.formatButtonActionPerformed(evt);
509             }
510             else if (evt.getSource() == linkButton) {
511                 JavaDocEditorPanel.this.formatButtonActionPerformed(evt);
512             }
513         }
514
515         public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
516             if (evt.getSource() == commentTextArea) {
517                 JavaDocEditorPanel.this.commentTextAreaFocusGained(evt);
518             }
519         }
520
521         public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
522             if (evt.getSource() == commentTextArea) {
523                 JavaDocEditorPanel.this.commentTextAreaFocusLost(evt);
524             }
525         }
526
527         public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {
528             if (evt.getSource() == tagList) {
529                 JavaDocEditorPanel.this.tagListValueChanged(evt);
530             }
531         }
532     }// </editor-fold>//GEN-END:initComponents
533

534     private void tagListValueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {//GEN-FIRST:event_tagListValueChanged
535
if (!updatingTagList) {
536             deleteButton.setEnabled(true);
537             moveUpButton.setEnabled(true);
538             moveDownButton.setEnabled(true);
539         }
540
541         TagPanel tagPanel;
542         int sel = tagList.getMinSelectionIndex();
543
544         if (lastSelection >= 0 && lastSelection != sel && lastSelection<listModel.getSize()) {
545             JavaDocTag tag = (JavaDocTag)listModel.get( lastSelection );
546             tagPanel = getPanelForTag( tag );
547             JavaDocTag newTag = tagPanel.getTag( tag.name() );
548             listModel.setElementAt(newTag, lastSelection);
549         }
550         lastSelection = sel;
551
552         if ( sel < 0 ) {
553             tagPanel = emptyTagPanel;
554             enableButtons( false );
555         }
556         else {
557             //JavaDocTag tag = (JavaDocTag)listModel.get( tagList.getMinSelectionIndex() ) ;
558
JavaDocTag tag = (JavaDocTag)listModel.get( sel ) ;
559
560             tagPanel = getPanelForTag( tag );
561             tagPanel.setData( tag );
562         }
563         CardLayout JavaDoc layout = (CardLayout JavaDoc)tagParamPanel.getLayout();
564         layout.show( tagParamPanel, tagPanel.getCardName() );
565         // JHK 9/29/2000 - cause focus to go to entry fields when tag selection is changed
566
// must check attributes of event since valueChanged is called so often even when the value is not really changed
567
// Called when new tag is selected
568
if ( tagPanel != emptyTagPanel && this.grabFocusAfterNewButton
569                 && evt.getFirstIndex() != evt.getLastIndex()
570                 && !evt.getValueIsAdjusting() ) {
571             this.grabFocusAfterNewButton = false;
572             tagPanel.grabFirstFocus();
573         }
574         //System.out.println("In JavaDocEditorPanel.tagSelection: " + evt.toString() );
575
}//GEN-LAST:event_tagListValueChanged
576

577     private void commentTextAreaFocusLost (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_commentTextAreaFocusLost
578
enableButtons( false );
579     }//GEN-LAST:event_commentTextAreaFocusLost
580

581     private void commentTextAreaFocusGained (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_commentTextAreaFocusGained
582
enableButtons( true );
583     }//GEN-LAST:event_commentTextAreaFocusGained
584

585     private void newTagButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_newTagButtonActionPerformed
586
//if ( newTagDialog == null ) //what is that ? not possible, there can be different types of element
587
newTagDialog = new NewTagDialog(element.getSrcElement());
588
589         DialogDescriptor desc = new DialogDescriptor(newTagDialog,
590                 NbBundle.getMessage(JavaDocEditorPanel.class, "NewTagDialog.Form.title"),
591                 true, DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION, null);
592         Object JavaDoc result = org.openide.DialogDisplayer.getDefault().notify(desc);
593         JavaDocTag tag = null;
594
595         if (result == DialogDescriptor.OK_OPTION && (tag = newTagDialog.getResult()) != null) {
596             listModel.addElement( tag );
597             tagList.ensureIndexIsVisible( listModel.getSize() );
598             this.grabFocusAfterNewButton = true;
599             tagList.setSelectedIndex( listModel.getSize() - 1 );
600         }
601
602     }//GEN-LAST:event_newTagButtonActionPerformed
603
/** Deletes the actual row */
604     private void delTagButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_delTagButtonActionPerformed
605
int sel = tagList.getMinSelectionIndex();
606
607         if ( sel != -1 ) {
608             lastSelection = -1;
609             listModel.removeElementAt( sel );
610         }
611
612         if ( listModel.getSize() > 0 )
613             tagList.setSelectedIndex( sel == listModel.getSize() ? sel - 1 : sel );
614         else {
615             CardLayout JavaDoc layout = (CardLayout JavaDoc)tagParamPanel.getLayout();
616             layout.show( tagParamPanel, emptyTagPanel.getCardName() );
617         }
618     }//GEN-LAST:event_delTagButtonActionPerformed
619

620     private void chgTagButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_chgTagButtonActionPerformed
621
commitTagChange();
622     }//GEN-LAST:event_chgTagButtonActionPerformed
623

624
625     private void moveTagButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_moveTagButtonActionPerformed
626
// Add your handling code here:
627
if ( evt.getActionCommand().equals( "UP" ) ) { // NOI18N
628
int selIndex = tagList.getMinSelectionIndex();
629             if ( selIndex > 0 ) {
630                 Object JavaDoc tag = listModel.get( selIndex );
631                 lastSelection = -1;
632                 listModel.removeElementAt( selIndex );
633                 listModel.insertElementAt( tag, selIndex - 1 );
634                 tagList.setSelectedIndex( selIndex - 1 );
635             }
636         }
637         else if ( evt.getActionCommand().equals( "DOWN" ) ) { // NOI18N
638
int selIndex = tagList.getMinSelectionIndex();
639             if ( selIndex >= 0 && selIndex < listModel.getSize() - 1 ) {
640                 Object JavaDoc tag = listModel.get( selIndex );
641                 lastSelection = -1;
642                 listModel.removeElementAt( selIndex );
643                 listModel.insertElementAt( tag, selIndex + 1 );
644                 tagList.setSelectedIndex( selIndex + 1 );
645             }
646         }
647     }//GEN-LAST:event_moveTagButtonActionPerformed
648

649     private void formatButtonActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_formatButtonActionPerformed
650
String JavaDoc begTag;
651         String JavaDoc endTag;
652         String JavaDoc command = evt.getActionCommand();
653
654         if ( command.equals( "link" ) ) { // NOI18N
655
begTag = "{@link "; // NOI18N
656
endTag = "}"; // NOI18N
657
}
658         else {
659             begTag = "<" + command + ">"; // NOI18N
660
endTag = "</" + command + ">"; // NOI18N
661
}
662
663         if ( commentTextArea.hasFocus() ) {
664             int caretPosition = commentTextArea.getCaretPosition();
665             /*
666             StringBuffer sb = new StringBuffer( commentTextArea.getText() );
667             sb.insert( commentTextArea.getSelectionStart(), begTag );
668             sb.insert( commentTextArea.getSelectionEnd(), endTag );
669             commentTextArea.setText( sb.toString() );
670             */

671             try {
672                 commentTextArea.getDocument().insertString( commentTextArea.getSelectionStart(), begTag, null );
673                 commentTextArea.getDocument().insertString( commentTextArea.getSelectionEnd(), endTag, null );
674                 commentTextArea.setCaretPosition( caretPosition + 2 + evt.getActionCommand().length() );
675             }
676             catch ( javax.swing.text.BadLocationException JavaDoc e ) {
677                 //System.out.println(e );
678
}
679         }
680         else {
681             JavaDocTag tag = (JavaDocTag)listModel.get( tagList.getMinSelectionIndex() ) ;
682             TagPanel tagPanel = getPanelForTag( tag );
683             tagPanel.handleFormatButton( begTag, endTag );
684         }
685     }//GEN-LAST:event_formatButtonActionPerformed
686

687
688     // Variables declaration - do not modify//GEN-BEGIN:variables
689
private javax.swing.JButton JavaDoc boldButton;
690     private javax.swing.JButton JavaDoc codeButton;
691     private javax.swing.JLabel JavaDoc commentLabel;
692     private javax.swing.JScrollPane JavaDoc commentScrollPane;
693     private javax.swing.JEditorPane JavaDoc commentTextArea;
694     private javax.swing.JButton JavaDoc deleteButton;
695     private javax.swing.JPanel JavaDoc htmlToolBar;
696     private javax.swing.JButton JavaDoc italicButton;
697     private javax.swing.JButton JavaDoc linkButton;
698     private javax.swing.JButton JavaDoc moveDownButton;
699     private javax.swing.JButton JavaDoc moveUpButton;
700     private javax.swing.JButton JavaDoc newButton;
701     private javax.swing.JButton JavaDoc preButton;
702     private javax.swing.JList JavaDoc tagList;
703     private javax.swing.JLabel JavaDoc tagListLabel;
704     private javax.swing.JPanel JavaDoc tagPanel;
705     private javax.swing.JPanel JavaDoc tagParamPanel;
706     private javax.swing.JScrollPane JavaDoc tagScrollPane;
707     private javax.swing.JPanel JavaDoc textPanel;
708     private javax.swing.JButton JavaDoc underlineButton;
709     // End of variables declaration//GEN-END:variables
710

711     /** gets the text of comment */
712     String JavaDoc getRawText() {
713         JavaDoc jd = getUpdatedJavaDoc();
714         return jd.getRawText();
715     }
716     
717     JavaDoc getUpdatedJavaDoc() {
718         JavaDoc jd = JavaDocSupport.createJavaDoc("");
719         JavaDocTag tags[];
720
721         try {
722             jd.setText(commentTextArea.getDocument().getText( 0, commentTextArea.getDocument().getLength()));
723             tags = new JavaDocTag[listModel.getSize()];
724             listModel.copyInto(tags);
725             jd.changeTags(tags,JavaDoc.SET);
726         } catch (Exception JavaDoc e) {
727             ErrorManager.getDefault().notify(e);
728         }
729         return jd;
730     }
731
732
733     /**
734     * @return Returns the property value that is result of the CustomPropertyEditor.
735     * @exception IllegalStateException when the custom property editor does not represent valid property value
736     * (and thus it should not be set)
737     */

738     public Object JavaDoc getPropertyValue () throws IllegalStateException JavaDoc {
739
740         try {
741             javaDoc.setRawText( getRawText() );
742         }
743         catch ( SourceException ex ) {
744             throw new IllegalStateException JavaDoc();
745
746         }
747
748         return javaDoc;
749     }
750
751     TagPanel getPanelForTag( JavaDocTag tag ) {
752
753         if ( tag instanceof JavaDocTag.Param )
754             return paramTagPanel;
755         else if ( tag instanceof JavaDocTag.Throws )
756             return throwsTagPanel;
757         else if ( tag instanceof JavaDocTag.SerialField )
758             return serialFieldTagPanel;
759         else if ( tag instanceof JavaDocTag.See )
760             return seeTagPanel;
761         else
762             return standardTagPanel;
763
764     }
765
766     /** Changes the tag in the tag list */
767     void commitTagChange() {
768         updatingTagList = true;
769         TagPanel tagPanel;
770         int sel = tagList.getMinSelectionIndex();
771         if ( sel >= 0 ) {
772             JavaDocTag tag = (JavaDocTag)listModel.get( sel );
773             tagPanel = getPanelForTag( tag );
774             JavaDocTag newTag = tagPanel.getTag( tag.name() );
775             listModel.setElementAt( newTag, sel );
776             dirty = true;
777         }
778         updatingTagList = false;
779     }
780
781     void enableButtons( boolean enable ) {
782         boldButton.setEnabled( enable );
783         italicButton.setEnabled( enable );
784         underlineButton.setEnabled( enable );
785         codeButton.setEnabled( enable );
786         preButton.setEnabled( enable );
787         linkButton.setEnabled( enable );
788     }
789
790     void registerComponent( java.awt.Component JavaDoc component) {
791         mnemonicsDistributor.registerComponent( component );
792     }
793
794
795     /** Getter for property dirty.
796      * @return Value of property dirty.
797      */

798     public boolean isDirty() {
799         return dirty;
800     }
801
802     /** Setter for property dirty.
803      * @param dirty Value of property dirty.
804      */

805     public void setDirty(boolean dirty) {
806         this.dirty = dirty;
807     }
808
809     /** This innerclass serves as workaround for handling alt key mnemonics
810      */

811     class MnemonicsDistributor extends java.awt.event.KeyAdapter JavaDoc {
812
813         MnemonicsDistributor() {
814         }
815
816         private static final int ALT_LESS_MASK = InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_GRAPH_DOWN_MASK |
817                 InputEvent.SHIFT_DOWN_MASK | InputEvent.META_DOWN_MASK;
818         
819         public void keyPressed( java.awt.event.KeyEvent JavaDoc e ) {
820
821             javax.swing.KeyStroke JavaDoc ks = javax.swing.KeyStroke.getKeyStrokeForEvent( e );
822
823             final int modifiers = ks.getModifiers();
824             if ( ( modifiers & InputEvent.ALT_MASK ) != 0 && (modifiers & ALT_LESS_MASK) == 0) {
825
826                 switch ( ks.getKeyCode() ) {
827                 case KeyEvent.VK_B:
828                     boldButton.doClick();
829                     e.consume();
830                     break;
831                 case KeyEvent.VK_I:
832                     italicButton.doClick();
833                     e.consume();
834                     break;
835                 case KeyEvent.VK_U:
836                     underlineButton.doClick();
837                     e.consume();
838                     break;
839                 case KeyEvent.VK_C:
840                     codeButton.doClick();
841                     e.consume();
842                     break;
843                 case KeyEvent.VK_P:
844                     preButton.doClick();
845                     e.consume();
846                     break;
847                 case KeyEvent.VK_L:
848                     linkButton.doClick();
849                     e.consume();
850                     break;
851                 }
852             }
853         }
854
855         void registerComponent( java.awt.Component JavaDoc component ) {
856             component.addKeyListener(this);
857         }
858
859     }
860
861 }
862
Popular Tags