1 package org.netbeans.editor.example; 2 3 import java.util.Map ; 4 import java.awt.event.KeyEvent ; 5 import java.awt.event.InputEvent ; 6 import java.awt.event.ActionEvent ; 7 import javax.swing.Action ; 8 import javax.swing.KeyStroke ; 9 import javax.swing.text.Caret ; 10 import javax.swing.text.Document ; 11 import javax.swing.text.TextAction ; 12 import javax.swing.text.JTextComponent ; 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 25 26 public class HTMLKit extends ExtKit { 27 28 private static final String DEFAULT_DOCTYPE = 29 "-//W3C//DTD HTML 4.01 Transitional//EN"; 31 static final long serialVersionUID =-1381945567613910297L; 32 33 public static final String HTML_MIME_TYPE = "text/html"; 35 public static final String shiftInsertBreakAction = "shift-insert-break"; 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 getContentType() { 50 return HTML_MIME_TYPE; 51 } 52 53 57 public Syntax createSyntax(Document doc) { 58 return new HTMLSyntax(); 59 } 60 61 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 [] createActions() { 71 Action [] HTMLActions = new Action [] { 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 evt, JTextComponent target) { 88 if (target != null) { 89 Completion completion = ExtUtilities.getCompletion(target); 90 if (completion != null && completion.isPaneVisible()) { 91 if (completion.substituteText( true )) { 92 } 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" ); } 106 107 public void updateSettingsMap(Class kitClass, Map 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 |