KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > editor > example > HTMLKit


1 package org.netbeans.editor.example;
2
3 import java.util.Map JavaDoc;
4 import java.awt.event.KeyEvent JavaDoc;
5 import java.awt.event.InputEvent JavaDoc;
6 import java.awt.event.ActionEvent JavaDoc;
7 import javax.swing.Action JavaDoc;
8 import javax.swing.KeyStroke JavaDoc;
9 import javax.swing.text.Caret JavaDoc;
10 import javax.swing.text.Document JavaDoc;
11 import javax.swing.text.TextAction JavaDoc;
12 import javax.swing.text.JTextComponent JavaDoc;
13
14 import org.netbeans.editor.*;
15 import org.netbeans.editor.ext.*;
16 import org.netbeans.editor.ext.html.*;
17 import org.netbeans.editor.ext.html.dtd.*;
18
19 /**
20 * Editor kit implementation for HTML content type
21 *
22 * @author Miloslav Metelka
23 * @version 0.01
24 */

25
26 public class HTMLKit extends ExtKit {
27
28     private static final String JavaDoc DEFAULT_DOCTYPE =
29         "-//W3C//DTD HTML 4.01 Transitional//EN"; // NOI18N
30

31     static final long serialVersionUID =-1381945567613910297L;
32
33     public static final String JavaDoc HTML_MIME_TYPE = "text/html"; // NOI18N
34

35     public static final String JavaDoc shiftInsertBreakAction = "shift-insert-break"; // NOI18N
36

37     static {
38         Settings.addInitializer( new HTMLSettingsInitializer( HTMLKit.class ) );
39         Settings.addInitializer( new SaHTMLSettingsInitializer() );
40         Settings.reset();
41       SAReaderProvider.setupReaders();
42     }
43     
44     public HTMLKit() {
45         super();
46         DTD myDTD = org.netbeans.editor.ext.html.dtd.Registry.getDTD( DEFAULT_DOCTYPE, null );
47     }
48
49     public String JavaDoc getContentType() {
50         return HTML_MIME_TYPE;
51     }
52
53     /** Create new instance of syntax coloring scanner
54     * @param doc document to operate on. It can be null in the cases the syntax
55     * creation is not related to the particular document
56     */

57     public Syntax createSyntax(Document JavaDoc doc) {
58         return new HTMLSyntax();
59     }
60
61     /** Create syntax support */
62     public SyntaxSupport createSyntaxSupport(BaseDocument doc) {
63         return new HTMLSyntaxSupport(doc);
64     }
65
66     public Completion createCompletion(ExtEditorUI extEditorUI) {
67         return new HTMLCompletion(extEditorUI);
68     }
69
70     protected Action JavaDoc[] createActions() {
71         Action JavaDoc[] HTMLActions = new Action JavaDoc[] {
72                                    new HTMLShiftBreakAction()
73                                };
74         return TextAction.augmentList(super.createActions(), HTMLActions);
75     }
76     
77
78     public static class HTMLShiftBreakAction extends BaseAction {
79
80         static final long serialVersionUID =4004043376345356061L;
81
82         public HTMLShiftBreakAction() {
83             super( shiftInsertBreakAction, ABBREV_RESET
84                   | MAGIC_POSITION_RESET | UNDO_MERGE_RESET);
85         }
86
87         public void actionPerformed(ActionEvent JavaDoc evt, JTextComponent JavaDoc target) {
88             if (target != null) {
89                 Completion completion = ExtUtilities.getCompletion(target);
90                 if (completion != null && completion.isPaneVisible()) {
91                     if (completion.substituteText( true )) {
92 // completion.setPaneVisible(false);
93
} else {
94                         completion.refresh(false);
95                     }
96                 }
97             }
98         }
99
100     }
101
102     private static class SaHTMLSettingsInitializer extends Settings.AbstractInitializer {
103         public SaHTMLSettingsInitializer() {
104             super( "sa-html-settings-initializer" ); // NOI18N
105
}
106             
107         public void updateSettingsMap(Class JavaDoc kitClass, Map JavaDoc settingsMap) {
108             if (kitClass == HTMLKit.class) {
109                 SettingsUtil.updateListSetting(settingsMap, SettingsNames.KEY_BINDING_LIST, getHTMLKeyBindings());
110             }
111         }
112
113         public MultiKeyBinding[] getHTMLKeyBindings() {
114             return new MultiKeyBinding[] {
115                 new MultiKeyBinding(
116                     KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_MASK),
117                     HTMLKit.shiftInsertBreakAction
118                 )
119             };
120         }
121     }
122
123 }
124
Popular Tags