77import java .awt .event .KeyEvent ;
88import java .awt .event .MouseEvent ;
99import java .beans .PropertyChangeEvent ;
10- import java .util .Enumeration ;
1110
1211import javax .swing .InputMap ;
1312import javax .swing .JComponent ;
1413import javax .swing .JEditorPane ;
1514import javax .swing .event .CaretEvent ;
1615import javax .swing .plaf .InputMapUIResource ;
1716import javax .swing .text .AbstractDocument .BranchElement ;
18- import javax .swing .text .AbstractDocument ;
1917import javax .swing .text .AttributeSet ;
2018import javax .swing .text .BadLocationException ;
2119import javax .swing .text .Caret ;
2220import javax .swing .text .Document ;
2321import javax .swing .text .Element ;
2422import javax .swing .text .JTextComponent ;
2523import javax .swing .text .Keymap ;
26- import javax .swing .text .Style ;
24+ import javax .swing .text .Position ;
2725import javax .swing .text .StyleConstants ;
28- import javax .swing .text .StyleContext ;
2926import javax .swing .text .StyledEditorKit ;
3027import javax .swing .text .View ;
31- import javax .swing .text .html .StyleSheet ;
3228
3329import javajs .util .PT ;
3430import javajs .util .SB ;
@@ -71,6 +67,8 @@ public class JSEditorPaneUI extends JSTextUI {
7167 private static final int SPACES_PER_TAB = 4 ;
7268
7369 protected boolean isTextPane = false ;
70+
71+ protected boolean isHtmlKit = false ;
7472
7573 public JSEditorPaneUI () {
7674 isEditorPane = isTextView = true ;
@@ -213,7 +211,7 @@ public DOMNode updateDOMNode() {
213211 }
214212 textListener .checkDocument ();
215213 setCssFont (domNode , c .getFont ());
216- DOMNode .setAttrs (domNode , "contentEditable" , editor .isEditable () ? TRUE : FALSE , "spellcheck" , FALSE );
214+ DOMNode .setAttrs (domNode , "contentEditable" , isHtmlKit || editor .isEditable () ? TRUE : FALSE , "spellcheck" , FALSE );
217215 if (jc .getTopLevelAncestor () != null ) {
218216 if (editor .getText () != mytext ) {
219217 setText (null );
@@ -231,6 +229,9 @@ public void propertyChange(PropertyChangeEvent e) {
231229 String prop = e .getPropertyName ();
232230 //System.out.println("JSEPUI prop " + prop);
233231 switch (prop ) {
232+ case "editorKit" :
233+ isHtmlKit = (editor .秘jsHTMLHelper != null );
234+ return ;
234235 case "text" :
235236 setCurrentText ();
236237 return ;
@@ -338,11 +339,11 @@ public void setText(String text) {
338339 String html ;
339340 if (text == null )
340341 text = editor .getText ();
341- if (editor . 秘jsHTMLHelper != null ) {
342+ if (isHtmlKit ) {
342343 mytext = html = text ;
343344 isHTML = true ;
344345 html = (String ) editor .秘jsHTMLHelper .get ("html" , getInner (text , "body" ));
345- DOMNode .setAttrs (domNode , "contentEditable" , FALSE );
346+ DOMNode .setAttrs (domNode , "contentEditable" , TRUE );
346347 styleNode = DOMNode .createElement ("div" , id + "_style" );
347348 domNode .appendChild (styleNode );
348349 String [] styles = (String []) editor .秘jsHTMLHelper .get ("styles" , "body" );
@@ -726,6 +727,8 @@ private static boolean isJSTAB(Object node) {
726727 */
727728 @ Override
728729 protected void setJSSelection (int mark , int dot , boolean andScroll ) {
730+ if (isHtmlKit )
731+ return ;
729732 super .setJSSelection (Math .min (mark , dot ), Math .max (mark , dot ), andScroll );
730733 }
731734
@@ -841,6 +844,8 @@ public void caretUpdatedByProgram(CaretEvent e) {
841844 @ SuppressWarnings ("unused" )
842845 @ Override
843846 boolean getJSMarkAndDot (Point pt , int keycode ) {
847+ if (isHtmlKit )
848+ return false ;
844849 int dot = 0 , mark = 0 , apt = 0 , fpt = 0 ;
845850 DOMNode anode = null , fnode = null , apar = null , fpar = null ;
846851 String atag = null , ftag = null ;
@@ -891,6 +896,8 @@ boolean getJSMarkAndDot(Point pt, int keycode) {
891896
892897 @ Override
893898 void setJSMarkAndDot (int mark , int dot , boolean andScroll ) {
899+ if (isHtmlKit )
900+ return ;
894901 //System.out.println("setJSMarkAndDot " + mark + " " + dot + " " + andScroll);
895902 // key up with text change -- need to refresh data-ui attributes
896903 // for all childNodes and also set the java caret, which will then
@@ -907,6 +914,8 @@ public boolean isFocusable() {
907914
908915 @ Override
909916 public void action (String what , int data ) {
917+ if (isHtmlKit )
918+ return ;
910919 int p = -1 ;
911920 switch (what ) {
912921 case "paste" :
@@ -985,6 +994,12 @@ private int[] getJavaMarkAndDot() {
985994 private String stemp ;
986995 private int [] xyTemp ;
987996
997+ @ Override
998+ public int viewToModel (JTextComponent t , Point pt ,
999+ Position .Bias [] biasReturn ) {
1000+ return (isHtmlKit ? 0 : super .viewToModel (t , pt , biasReturn ));
1001+ }
1002+
9881003 /**
9891004 * CTRL-V insertion requires knowledge of the text length at the time of keypress and
9901005 * then comparing that to the value at the time of keyup. Hopefully no repeating!
@@ -993,7 +1008,9 @@ private int[] getJavaMarkAndDot() {
9931008 @ Override
9941009 protected boolean handleCtrlV (int mode ) {
9951010 //System.out.println(getJavaMarkAndDot());
996-
1011+ if (isHtmlKit )
1012+ return false ;
1013+
9971014 getJSMarkAndDot (markDot , 0 );
9981015 //System.out.println(markDot);
9991016 String s = (String ) DOMNode .getAttr (domNode , "innerText" );
@@ -1060,33 +1077,43 @@ void setJSText() {
10601077
10611078 boolean isPressConsumed ;
10621079
1080+ protected final static boolean DO_KEY_DEFAULT = true ;
1081+ protected final static boolean STOP_KEY_DEFAULT_AND_PREVENT_PROPAGATION = false ;
1082+
1083+
1084+ /**
1085+ * This method is entered from the j2sApplet mouse listeners,
1086+ *
1087+ */
10631088 @ Override
10641089 public boolean handleJSEvent (Object target , int eventType , Object jQueryEvent ) {
10651090 Boolean b = checkAllowEvent (jQueryEvent );
10661091 if (b != null )
10671092 return b ;
1068- System .out .println ("handling event type " + eventType );
10691093 switch (eventType ) {
10701094 default :
10711095 return NOT_HANDLED ;
10721096 case MouseEvent .MOUSE_ENTERED :
1097+ case MouseEvent .MOUSE_DRAGGED :
10731098 case MouseEvent .MOUSE_EXITED :
1099+ case MouseEvent .MOUSE_PRESSED :
10741100 case MouseEvent .MOUSE_RELEASED :
1075- if (editor .秘jsHTMLHelper != null ) {
1101+ if (isHtmlKit ) {
1102+ // The idea here is to disallow mouse-driven editing
1103+ DOMNode .setAttrs (domNode , "contentEditable" , FALSE );
10761104 editor .秘jsHTMLHelper .handleJSEvent (target , eventType , jQueryEvent );
10771105 return HANDLED ;
10781106 }
1107+ return HANDLED ;
10791108 case SOME_KEY_EVENT :
1080- //System.out.println("JSEPUI dispatching " + jQueryEvent);
1081- JSKeyEvent .dispatchKeyEvent (jc , 0 , jQueryEvent , System .currentTimeMillis ());
1082- /**
1083- * @j2sNative
1084- *
1085- * jQueryEvent.preventDefault();
1086- * jQueryEvent.stopPropagation();
1087- */
10881109 setIgnoreEvent (jQueryEvent );
1089- return HANDLED ;
1110+ if (isHtmlKit ) {
1111+ // Allow CTRL-A to select just the JEditorPane, not the whole page
1112+ DOMNode .setAttrs (domNode , "contentEditable" , TRUE );
1113+ return DO_KEY_DEFAULT ;
1114+ }
1115+ JSKeyEvent .dispatchKeyEvent (jc , 0 , jQueryEvent , System .currentTimeMillis ());
1116+ return STOP_KEY_DEFAULT_AND_PREVENT_PROPAGATION ;
10901117 }
10911118 }
10921119
0 commit comments