United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4479072 HTMLEditorKit uses always default editor kit for rendering of frames
JDK-4479072 : HTMLEditorKit uses always default editor kit for rendering of frames

Details
Type:
Enhancement
Submit Date:
2001-07-12
Status:
Closed
Updated Date:
2004-10-14
Project Name:
JDK
Resolved Date:
2003-09-26
Component:
client-libs
OS:
linux
Sub-Component:
javax.swing
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.3.1
Fixed Versions:
1.4.2_04 (04)

Related Reports
Backport:

Sub Tasks

Description
When HTML pages are rendered in JEditorPane using HTMLEditorKit from JDK there are a problems with framesets. If the application sets its own kit for text/html this kit is used although it would be better to use kit from superior component. Another problem is that FrameView always fails to construct its component because insets are not initialized. This can be observed for example when generated java doc is displayed. Following exception is thrown:

Thu Jul 12 16:41:19 CEST 2001: java.lang.NullPointerException: null
java.lang.NullPointerException
        at javax.swing.text.html.FrameView.setMargin(FrameView.java:142)
        at javax.swing.text.html.FrameView.createComponent(FrameView.java:75)
        at javax.swing.text.ComponentView.setComponentParent(ComponentView.java:253)
        at javax.swing.text.ComponentView$1.run(ComponentView.java:225)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:154)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:337)
[catch] at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)
###@###.### 10/14/04 14:25 GMT

                                    

Comments
EVALUATION

This can be accomplished by creating your own View to render the frame sets. I'm moving this over to an RFE as this is really a request for additional API to make this easier.
scott.violet@eng 2001-07-12
===============================
This RFE has received little interest by the development
community since its submittal. It is being closed as "Will
Not Fix". Should there be an renewed interest in this request,
it will be considered for re-opening.

###@###.### 2001-11-13

It is not possible simply change view for frames only. It would require to rewrite all HtmlEditorKit.HtmlFactory. This is not very nice solution and maybe there is some room for any enhancement. So please fix at least problem with NPE from setMargin when FrameView is not correctly initialized.
###@###.### 2001-11-14

Agree. Thank you Radim for the fix you have sent me.  I have changed it a bit to keep backward compatibiltiy.


To turn editor kit inheritance on:
        editorPane.putClientProperty("JEditorPane.inheritEditorKit",Boolean.TRUE);

If you want to have customized editor kit for text/html in your JEditorPane here are the suggested steps:

editorPane.setEditorKitForContentType("text/html",customizedEditorKit);
editorPane.putClientProperty("JEditorPane.inheritEditorKit",Boolean.TRUE);

Will it do for you?

###@###.### 2003-07-29
---
After going back and forth with the fix. I have decided to make this
behavior the default one.  having the exceptional property for logical
behavior is irrational.

editorPane.setEditorKitForContentType("text/html",customizedEditorKit);

That is the only thing to do to have customizedEditorKit inerited by frames.

###@###.### 2003-09-03
                                     
2003-09-03
SUGGESTED FIX

It is almost the same fix Radim Kubacki has suggested.
--
*** /tmp/geta29971	Tue Jul 29 17:00:27 2003
--- FrameView.java	Tue Jul 29 16:55:41 2003
***************
*** 54,69 ****
  	    try {
  		URL base = ((HTMLDocument)elem.getDocument()).getBase();
  		src = new URL(base, srcAtt);
-                 htmlPane = new JEditorPane();
-                 htmlPane.addHyperlinkListener(this);
                  JEditorPane host = getHostPane();
                  if (host != null) {
-                     htmlPane.setEditable(host.isEditable());
  		    String charset = (String) host.getClientProperty("charset");
  		    if (charset != null) {
  			htmlPane.putClientProperty("charset", charset);
  		    }
                  }
                  htmlPane.setPage(src);
  		Document doc = htmlPane.getDocument();
  		if (doc instanceof HTMLDocument) {
--- 54,79 ----
  	    try {
  		URL base = ((HTMLDocument)elem.getDocument()).getBase();
  		src = new URL(base, srcAtt);
                  JEditorPane host = getHostPane();
                  if (host != null) {
  		    String charset = (String) host.getClientProperty("charset");
+                     Boolean inheritEditorKit = (Boolean) host.getClientProperty("JEditorPane.inheritEditorKit");
+                     if (inheritEditorKit != null 
+                         && inheritEditorKit == Boolean.TRUE) {
+                         htmlPane = new FrameEditorPane();
+                         htmlPane.putClientProperty("JEditorPane.inheritEditorKit", Boolean.TRUE);
+                         System.out.println("FrameView putClientProperty");
+                     } else {
+                         htmlPane = new JEditorPane();
+                     }
  		    if (charset != null) {
  			htmlPane.putClientProperty("charset", charset);
  		    }
+                     htmlPane.setEditable(host.isEditable());
+                 } else {
+                     htmlPane = new JEditorPane();
                  }
+                 htmlPane.addHyperlinkListener(this);
                  htmlPane.setPage(src);
  		Document doc = htmlPane.getDocument();
  		if (doc instanceof HTMLDocument) {
***************
*** 375,379 ****
--- 385,404 ----
  	return Integer.MAX_VALUE;
      }
  
+     /** Editor pane rendering frame of HTML document
+      *  It uses the same kit as outermost JEditorPane
+      */
+     private class FrameEditorPane extends JEditorPane {
+         public EditorKit getEditorKitForContentType(String type) {
+             JEditorPane outerMostJeditorPane;
+             if (htmlPane.getClientProperty("JEditorPane.inheritEditorKit") != null
+                 && (outerMostJeditorPane = getOutermostJEditorPane()) != null) {
+                 return outerMostJeditorPane.getEditorKitForContentType(type);
+             } else {
+                 return super.getEditorKitForContentType(type);
+             }
+         }
+     }
+ 
  }
---

see evaluation for more details
###@###.### 2003-07-29
----
After going back and forth with the fix. I have decided to make this
behavior the default one.  having the exceptional property for logical
behavior is irrational

---
*** /home/kid/work/tests/4479072/webrev/src/share/classes/javax/swing/text/html/FrameView.java-	Tue Sep  2 22:06:57 2003
--- FrameView.java	Tue Sep  2 20:26:46 2003
***************
*** 52,62 ****
  
  	if ((srcAtt != null) && (!srcAtt.equals(""))) {
  	    try {
  		URL base = ((HTMLDocument)elem.getDocument()).getBase();
  		src = new URL(base, srcAtt);
!                 htmlPane = new JEditorPane();
                  htmlPane.addHyperlinkListener(this);
                  JEditorPane host = getHostPane();
                  if (host != null) {
                      htmlPane.setEditable(host.isEditable());
  		    String charset = (String) host.getClientProperty("charset");
--- 52,62 ----
  
  	if ((srcAtt != null) && (!srcAtt.equals(""))) {
  	    try {
  		URL base = ((HTMLDocument)elem.getDocument()).getBase();
  		src = new URL(base, srcAtt);
!                 htmlPane = new FrameEditorPane();
                  htmlPane.addHyperlinkListener(this);
                  JEditorPane host = getHostPane();
                  if (host != null) {
                      htmlPane.setEditable(host.isEditable());
  		    String charset = (String) host.getClientProperty("charset");
***************
*** 373,379 ****
--- 373,396 ----
       */
      public float getMaximumSpan(int axis) {
  	return Integer.MAX_VALUE;
      }
  
+     /** Editor pane rendering frame of HTML document
+      *  It uses the same editor kits classes as outermost JEditorPane
+      */
+     private class FrameEditorPane extends JEditorPane {
+         public EditorKit getEditorKitForContentType(String type) {
+             EditorKit editorKit = super.getEditorKitForContentType(type); 
+             JEditorPane outerMostJEditorPane = null;
+             if ((outerMostJEditorPane = getOutermostJEditorPane()) != null) {
+                 EditorKit inheritedEditorKit = outerMostJEditorPane.getEditorKitForContentType(type);
+                 if (! editorKit.getClass().equals(inheritedEditorKit.getClass())) {
+                     editorKit = (EditorKit) inheritedEditorKit.clone();
+                     setEditorKitForContentType(type, editorKit);
+                 }
+             } 
+             return editorKit;
+         }
+     }
  }
  

---


###@###.### 2003-09-03
                                     
2003-09-03
WORK AROUND

 
                                     
2004-06-11
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
1.4.2_04
generic

FIXED IN:
1.4.2_04
tiger

INTEGRATED IN:
1.4.2_04
tiger
tiger-b22

VERIFIED IN:
1.4.2_04


                                     
2004-06-14



Hardware and Software, Engineered to Work Together