001: package org.netbeans.editor.example;
002:
003: import java.util.Map;
004: import java.awt.event.KeyEvent;
005: import java.awt.event.InputEvent;
006: import java.awt.event.ActionEvent;
007: import javax.swing.Action;
008: import javax.swing.KeyStroke;
009: import javax.swing.text.Caret;
010: import javax.swing.text.Document;
011: import javax.swing.text.TextAction;
012: import javax.swing.text.JTextComponent;
013:
014: import org.netbeans.editor.*;
015: import org.netbeans.editor.ext.*;
016: import org.netbeans.editor.ext.html.*;
017: import org.netbeans.editor.ext.html.dtd.*;
018:
019: /**
020: * Editor kit implementation for HTML content type
021: *
022: * @author Miloslav Metelka
023: * @version 0.01
024: */
025:
026: public class HTMLKit extends ExtKit {
027:
028: private static final String DEFAULT_DOCTYPE = "-//W3C//DTD HTML 4.01 Transitional//EN"; // NOI18N
029:
030: static final long serialVersionUID = -1381945567613910297L;
031:
032: public static final String HTML_MIME_TYPE = "text/html"; // NOI18N
033:
034: public static final String shiftInsertBreakAction = "shift-insert-break"; // NOI18N
035:
036: static {
037: Settings.addInitializer(new HTMLSettingsInitializer(
038: HTMLKit.class));
039: Settings.addInitializer(new SaHTMLSettingsInitializer());
040: Settings.reset();
041: SAReaderProvider.setupReaders();
042: }
043:
044: public HTMLKit() {
045: super ();
046: DTD myDTD = org.netbeans.editor.ext.html.dtd.Registry.getDTD(
047: DEFAULT_DOCTYPE, null);
048: }
049:
050: public String getContentType() {
051: return HTML_MIME_TYPE;
052: }
053:
054: /** Create new instance of syntax coloring scanner
055: * @param doc document to operate on. It can be null in the cases the syntax
056: * creation is not related to the particular document
057: */
058: public Syntax createSyntax(Document doc) {
059: return new HTMLSyntax();
060: }
061:
062: /** Create syntax support */
063: public SyntaxSupport createSyntaxSupport(BaseDocument doc) {
064: return new HTMLSyntaxSupport(doc);
065: }
066:
067: public Completion createCompletion(ExtEditorUI extEditorUI) {
068: return new HTMLCompletion(extEditorUI);
069: }
070:
071: protected Action[] createActions() {
072: Action[] HTMLActions = new Action[] { new HTMLShiftBreakAction() };
073: return TextAction.augmentList(super .createActions(),
074: HTMLActions);
075: }
076:
077: public static class HTMLShiftBreakAction extends BaseAction {
078:
079: static final long serialVersionUID = 4004043376345356061L;
080:
081: public HTMLShiftBreakAction() {
082: super (shiftInsertBreakAction, ABBREV_RESET
083: | MAGIC_POSITION_RESET | UNDO_MERGE_RESET);
084: }
085:
086: public void actionPerformed(ActionEvent evt,
087: JTextComponent target) {
088: if (target != null) {
089: Completion completion = ExtUtilities
090: .getCompletion(target);
091: if (completion != null && completion.isPaneVisible()) {
092: if (completion.substituteText(true)) {
093: // completion.setPaneVisible(false);
094: } else {
095: completion.refresh(false);
096: }
097: }
098: }
099: }
100:
101: }
102:
103: private static class SaHTMLSettingsInitializer extends
104: Settings.AbstractInitializer {
105: public SaHTMLSettingsInitializer() {
106: super ("sa-html-settings-initializer"); // NOI18N
107: }
108:
109: public void updateSettingsMap(Class kitClass, Map settingsMap) {
110: if (kitClass == HTMLKit.class) {
111: SettingsUtil.updateListSetting(settingsMap,
112: SettingsNames.KEY_BINDING_LIST,
113: getHTMLKeyBindings());
114: }
115: }
116:
117: public MultiKeyBinding[] getHTMLKeyBindings() {
118: return new MultiKeyBinding[] { new MultiKeyBinding(
119: KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
120: InputEvent.SHIFT_MASK),
121: HTMLKit.shiftInsertBreakAction) };
122: }
123: }
124:
125: }
|