KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.ArrayList JavaDoc;
23
24 import javax.swing.JEditorPane JavaDoc;
25
26 import org.openide.src.JavaDocTag;
27
28 /** Panel with standard tags
29  *
30  * @author Petr Hrebejk
31  * @version
32  */

33
34 abstract class TagPanel extends javax.swing.JPanel JavaDoc {
35
36     protected ArrayList JavaDoc htmlComponents = new ArrayList JavaDoc();
37
38     private JavaDocEditorPanel editorPanel;
39
40     TagPanel( JavaDocEditorPanel editorPanel ) {
41         this.editorPanel = editorPanel;
42     }
43
44     abstract void setData( JavaDocTag tag );
45
46     abstract String JavaDoc getCardName();
47
48     abstract JavaDocTag getTag( String JavaDoc tagName );
49
50     void addHTMLComponent( JEditorPane JavaDoc component ) {
51         htmlComponents.add( component );
52     }
53
54     void handleFormatButton( String JavaDoc begTag, String JavaDoc endTag ) {
55         for ( int i = 0; i < htmlComponents.size(); i++ ) {
56             JEditorPane JavaDoc component = (JEditorPane JavaDoc)htmlComponents.get( i );
57             if ( component.hasFocus() ) {
58
59                 int caretPosition = component.getCaretPosition();
60                 try {
61                     component.getDocument().insertString( component.getSelectionStart(), begTag, null );
62                     component.getDocument().insertString( component.getSelectionEnd(), endTag, null );
63                     component.setCaretPosition( caretPosition + begTag.length() );
64                 }
65                 catch ( javax.swing.text.BadLocationException JavaDoc e ) {
66                     //System.out.println(e );
67
}
68                 break;
69             }
70         }
71     }
72
73     void commitTagChange() {
74         editorPanel.commitTagChange();
75     }
76
77     void enableHTMLButtons( boolean enable ) {
78         editorPanel.enableButtons( enable );
79     }
80
81     abstract void grabFirstFocus();
82 }
83
Popular Tags