You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ap...@apache.org on 2007/02/19 16:32:25 UTC
svn commit: r509220 - in /harmony/enhanced/classlib/trunk/modules/swing:
make/exclude.common src/main/java/common/javax/swing/JEditorPane.java
Author: apetrenko
Date: Mon Feb 19 07:32:21 2007
New Revision: 509220
URL: http://svn.apache.org/viewvc?view=rev&rev=509220
Log:
Patch for HARMONY-3192 "[classlib][swing] j.s.JEditorPane does not support HTML"
JEditorPaneTest is excluded. See HARMONY-3202 for details.
Modified:
harmony/enhanced/classlib/trunk/modules/swing/make/exclude.common
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JEditorPane.java
Modified: harmony/enhanced/classlib/trunk/modules/swing/make/exclude.common
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/make/exclude.common?view=diff&rev=509220&r1=509219&r2=509220
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/make/exclude.common (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/make/exclude.common Mon Feb 19 07:32:21 2007
@@ -8,6 +8,7 @@
javax/swing/JComponent_AddRemoveNotifyTest.java
javax/swing/JComponent_MultithreadedTest.java
javax/swing/JDialogTest.java
+javax/swing/JEditorPaneTest.java
javax/swing/JEditorPane_AccessibleJEditorPaneHTMLTest.java
javax/swing/JEditorPane_AccessibleJEditorPaneTest.java
javax/swing/JEditorPane_MultithreadedTest.java
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JEditorPane.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JEditorPane.java?view=diff&rev=509220&r1=509219&r2=509220
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JEditorPane.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JEditorPane.java Mon Feb 19 07:32:21 2007
@@ -18,6 +18,7 @@
import java.awt.Container;
import java.awt.Dimension;
+import java.awt.Rectangle;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -27,6 +28,7 @@
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
+
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleHyperlink;
import javax.accessibility.AccessibleHypertext;
@@ -35,6 +37,7 @@
import javax.accessibility.AccessibleText;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
+import javax.swing.text.AbstractDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.ChangedCharSetException;
@@ -47,6 +50,10 @@
import javax.swing.text.View;
import javax.swing.text.ViewFactory;
import javax.swing.text.WrappedPlainView;
+import javax.swing.text.html.HTML;
+import javax.swing.text.html.HTMLDocument;
+import javax.swing.text.html.HTMLEditorKit;
+
import org.apache.harmony.luni.util.NotImplementedException;
import org.apache.harmony.x.swing.StringConstants;
@@ -517,65 +524,52 @@
}
public void scrollToReference(final String ref) {
- // temporarily commented-out: HTMLDocument not implemented
- /*
Document doc = getDocument();
- if (ref == null || !(doc instanceof HTMLDocument)) {
- return;
- }
- HTMLDocument.Iterator it = ((HTMLDocument)doc).getIterator(HTML.Tag.A);
- int offset = 0;
- while (it.isValid()) {
- AttributeSet set = it.getAttributes();
- Object name = set.getAttribute(HTML.Attribute.NAME);
- if (ref.equals(name)) {
- offset = it.getStartOffset();
- break;
- }
- it.next();
- }
- Rectangle rect = null;
- try {
- rect = modelToView(offset);
- } catch (BadLocationException e) {
- }
- Rectangle visibleRect = getVisibleRect();
- if (visibleRect != null) {
- rect.height = visibleRect.height;
- }
- scrollRectToVisible(rect);
- */
- }
-
- /*
- private boolean changeEditoKit(final String contentType) {
- return !((RTF_CONTENT_TYPE.equals(contentType)
- && editorKit instanceof RTFEditorKit)
- || (HTML_CONTENT_TYPE.equals(contentType)
- && editorKit instanceof HTMLEditorKit)
- || (PLAIN_CONTENT_TYPE.equals(contentType)
- && editorKit instanceof PlainEditorKit));
- }
- */
+ if (ref == null || !(doc instanceof HTMLDocument)) {
+ return;
+ }
+ HTMLDocument.Iterator it = ((HTMLDocument)doc).getIterator(HTML.Tag.A);
+ int offset = 0;
+ while (it.isValid()) {
+ AttributeSet set = it.getAttributes();
+ Object name = set.getAttribute(HTML.Attribute.NAME);
+ if (ref.equals(name)) {
+ offset = it.getStartOffset();
+ break;
+ }
+ it.next();
+ }
+ Rectangle rect = null;
+ try {
+ rect = modelToView(offset);
+ } catch (BadLocationException e) {
+ }
+ Rectangle visibleRect = getVisibleRect();
+ if (visibleRect != null) {
+ rect.height = visibleRect.height;
+ }
+ scrollRectToVisible(rect);
+ }
+
+ private boolean changeEditoKit(final String contentType) {
+ return !(/*(RTF_CONTENT_TYPE.equals(contentType) && editorKit instanceof RTFEditorKit)
+ ||*/ (HTML_CONTENT_TYPE.equals(contentType) && editorKit instanceof HTMLEditorKit)
+ || (PLAIN_CONTENT_TYPE.equals(contentType) && editorKit instanceof PlainEditorKit));
+ }
+
public final void setContentType(final String type) {
if (type == null) {
throw new NullPointerException("Content type is null");
}
- if (type == "text/html" || type == "text/rtf") {
- System.err
- .println("WARNING: HTML/RTF is not supported yet. Plain text will be shown");
- }
- /*
- int index = contentTypes.indexOf(type);
- contentType = (index >= 0) ? (String)contentTypes.get(index)
- : PLAIN_CONTENT_TYPE;
- if (changeEditoKit(contentType)) {
- EditorKit kit = getEditorKitForContentType(contentType);
- updateEditorKit((kit != null) ? kit : new PlainEditorKit());
- updateDocument(editorKit);
- }
- */
+ int index = contentTypes.indexOf(type);
+ contentType = (index >= 0) ? (String)contentTypes.get(index)
+ : PLAIN_CONTENT_TYPE;
+ if (changeEditoKit(contentType)) {
+ EditorKit kit = getEditorKitForContentType(contentType);
+ updateEditorKit((kit != null) ? kit : new PlainEditorKit());
+ updateDocument(editorKit);
+ }
}
private String getContentTypeByEditorKit(final EditorKit kit) {
@@ -613,19 +607,9 @@
public void setEditorKit(final EditorKit kit) {
String newContentType = getContentTypeByEditorKit(kit);
- if (newContentType == "text/html" || newContentType == "text/rtf") {
- System.err
- .println("WARNING: HTML/RTF is not supported yet. Plain text will be shown");
- } else {
- updateEditorKit(kit);
- updateDocument(kit);
- }
- /*
- String newContentType = getContentTypeByEditorKit(kit);
- updateEditorKit(kit);
- updateDocument(kit);
- contentType = newContentType;
- */
+ updateEditorKit(kit);
+ updateDocument(kit);
+ contentType = newContentType;
}
public void setEditorKitForContentType(final String type, final EditorKit kit) {
@@ -668,78 +652,97 @@
}
}
+ private class AsynchLoad extends Thread {
+ InputStream inputStream;
+ boolean successfulLoading = true;
+ URL url;
+
+ public AsynchLoad(final int priority, final InputStream stream,
+ final URL url) {
+ super();
+ setPriority(priority);
+ inputStream = stream;
+ this.url = url;
+ }
+
+ @Override
+ public void run() {
+ try {
+ documentLoading(inputStream, getDocument(), url);
+ } catch (IOException e) {
+ successfulLoading = false;
+ }
+ }
+ }
+
public void setPage(final URL page) throws IOException {
if (page == null) {
throw new IOException("Page is null");
}
- //temporarily commented-out: HTMLDocument not implemented
- /*
- String url = page.toString();
- String baseUrl = getBaseURL(url);
- Document oldDoc = getDocument();
- if (baseUrl != null
- && oldDoc != null
- && baseUrl.equals(oldDoc
- .getProperty(Document.StreamDescriptionProperty))) {
-
- scrollToReference(page.getRef());
- return;
- }
- InputStream stream = getStream(page);
- if (stream == null) {
- return;
- }
- Document newDoc = editorKit.createDefaultDocument();
- //Perhaps, it is reasonable only for HTMLDocument...
- if (newDoc instanceof HTMLDocument) {
- newDoc.putProperty(Document.StreamDescriptionProperty, baseUrl);
- newDoc.putProperty(StringConstants.IGNORE_CHARSET_DIRECTIVE,
- new Boolean(false));
- try {
- ((HTMLDocument)newDoc).setBase(new URL(baseUrl));
- } catch (IOException e) {
- }
- }
- //TODO Asynch loading doesn't work with completely.
- //Also page property change event is written incorrectly now
- //(at the asynchrounous loading), because loading may not be
- //completed.
- //int asynchronousLoadPriority = getAsynchronousLoadPriority(newDoc);
- int asynchronousLoadPriority = -1;
- if (asynchronousLoadPriority >= 0) {
- setDocument(newDoc);
- AsynchLoad newThread = new AsynchLoad(asynchronousLoadPriority,
- stream, page);
- newThread.start();
- if (newThread.successfulLoading) {
- changePage(page);
- }
- } else {
- try {
- documentLoading(stream, newDoc, page);
- stream.close();
- setDocument(newDoc);
- changePage(page);
- } catch (IOException e) {
- }
- }
- */
- }
-
- //TODO uncomment when the above method is uncommented
- // private void changePage(final URL newPage) {
- // URL oldPage = currentPage;
- // currentPage = newPage;
- // firePropertyChange("page", oldPage, currentPage);
- // }
- //
- // private int getAsynchronousLoadPriority(final Document doc) {
- // if (doc instanceof AbstractDocument) {
- // return ((AbstractDocument)doc).getAsynchronousLoadPriority();
- // }
- // return -1;
- // }
+ String url = page.toString();
+ String baseUrl = getBaseURL(url);
+ Document oldDoc = getDocument();
+ if (baseUrl != null
+ && oldDoc != null
+ && baseUrl.equals(oldDoc
+ .getProperty(Document.StreamDescriptionProperty))) {
+
+ scrollToReference(page.getRef());
+ return;
+ }
+ InputStream stream = getStream(page);
+ if (stream == null) {
+ return;
+ }
+ Document newDoc = editorKit.createDefaultDocument();
+ // Perhaps, it is reasonable only for HTMLDocument...
+ if (newDoc instanceof HTMLDocument) {
+ newDoc.putProperty(Document.StreamDescriptionProperty, baseUrl);
+ newDoc.putProperty(StringConstants.IGNORE_CHARSET_DIRECTIVE,
+ new Boolean(false));
+ try {
+ ((HTMLDocument)newDoc).setBase(new URL(baseUrl));
+ } catch (IOException e) {
+ }
+ }
+ // TODO Asynch loading doesn't work with completely.
+ // Also page property change event is written incorrectly now
+ // (at the asynchrounous loading), because loading may not be
+ // completed.
+ // int asynchronousLoadPriority = getAsynchronousLoadPriority(newDoc);
+ int asynchronousLoadPriority = -1;
+ if (asynchronousLoadPriority >= 0) {
+ setDocument(newDoc);
+ AsynchLoad newThread = new AsynchLoad(asynchronousLoadPriority,
+ stream, page);
+ newThread.start();
+ if (newThread.successfulLoading) {
+ changePage(page);
+ }
+ } else {
+ try {
+ documentLoading(stream, newDoc, page);
+ stream.close();
+ setDocument(newDoc);
+ changePage(page);
+ } catch (IOException e) {
+ }
+ }
+ }
+
+ private void changePage(final URL newPage) {
+ URL oldPage = currentPage;
+ currentPage = newPage;
+ firePropertyChange("page", oldPage, currentPage);
+ }
+
+ private int getAsynchronousLoadPriority(final Document doc) {
+ if (doc instanceof AbstractDocument) {
+ return ((AbstractDocument)doc).getAsynchronousLoadPriority();
+ }
+ return -1;
+ }
@Override
public synchronized void setText(final String content) {