aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2005-01-10 18:16:37 +0000
committerMichael Koch <konqueror@gmx.de>2005-01-10 18:16:37 +0000
commite061fba4da0e07321ff95fabb00a8fe4aa9a091b (patch)
tree76823ebbd3d53a2108580a7fff7cd2721a653686
parentbb6b070f31187b4985ba2d6be06b438821e97bee (diff)
2005-01-10 Michael Koch <konqueror@gmx.de>
* javax/swing/JEditorPane.java (read): Implemented. (write): Likewise. * javax/swing/text/DefaultEditorKit.java (page): Renamed from page_url. Made private. (editorKit): Renamed from kit. Made private. (ctype): Removed. (JEditorPane): All constructors reimplemented. (getContentType): Use content type from editor kit. (getEditorKit): Return editorKit. (getEditorKitForContentType):Likewise. (getPage): Return page. (setContentType): Reimplemented. (setEditorKit): Likewise. (setEditorKitForContentType): Removed wrong implementation. (setPage): Implemented. git-svn-id: https://gcc.gnu.org/svn/gcc/branches/java-gui-branch@93148 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libjava/ChangeLog19
-rw-r--r--libjava/javax/swing/JEditorPane.java75
-rw-r--r--libjava/javax/swing/text/DefaultEditorKit.java30
3 files changed, 99 insertions, 25 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 5d9bd6ea29e..0fdf0ee11f6 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,22 @@
+2005-01-10 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/JEditorPane.java
+ (read): Implemented.
+ (write): Likewise.
+ * javax/swing/text/DefaultEditorKit.java
+ (page): Renamed from page_url. Made private.
+ (editorKit): Renamed from kit. Made private.
+ (ctype): Removed.
+ (JEditorPane): All constructors reimplemented.
+ (getContentType): Use content type from editor kit.
+ (getEditorKit): Return editorKit.
+ (getEditorKitForContentType):Likewise.
+ (getPage): Return page.
+ (setContentType): Reimplemented.
+ (setEditorKit): Likewise.
+ (setEditorKitForContentType): Removed wrong implementation.
+ (setPage): Implemented.
+
2005-01-10 Thomas Fitzsimmons <fitzsim@redhat.com>
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c
diff --git a/libjava/javax/swing/JEditorPane.java b/libjava/javax/swing/JEditorPane.java
index cc59138b4fe..f975e40331d 100644
--- a/libjava/javax/swing/JEditorPane.java
+++ b/libjava/javax/swing/JEditorPane.java
@@ -1,5 +1,5 @@
/* JEditorPane.java --
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -47,6 +47,7 @@ import java.net.URL;
import javax.accessibility.AccessibleContext;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
+import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultEditorKit;
import javax.swing.text.EditorKit;
import javax.swing.text.JTextComponent;
@@ -56,29 +57,31 @@ public class JEditorPane extends JTextComponent
{
private static final long serialVersionUID = 3140472492599046285L;
- URL page_url;
- EditorKit kit;
- String ctype = "text/plain";
+ private URL page;
+ private EditorKit editorKit;
+
boolean focus_root;
boolean manages_focus;
public JEditorPane()
{
+ setEditorKit(createDefaultEditorKit());
}
public JEditorPane(String url) throws IOException
{
- setPage(url);
+ this(new URL(url));
}
public JEditorPane(String type, String text)
{
- ctype = text;
+ setEditorKit(createEditorKitForContentType(type));
setText(text);
}
public JEditorPane(URL url) throws IOException
{
+ this();
setPage(url);
}
@@ -112,12 +115,12 @@ public class JEditorPane extends JTextComponent
public String getContentType()
{
- return ctype;
+ return getEditorKit().getContentType();
}
public EditorKit getEditorKit()
{
- return kit;
+ return editorKit;
}
public static String getEditorKitClassNameForContentType(String type)
@@ -127,7 +130,7 @@ public class JEditorPane extends JTextComponent
public EditorKit getEditorKitForContentType(String type)
{
- return kit;
+ return editorKit;
}
/**
@@ -150,7 +153,7 @@ public class JEditorPane extends JTextComponent
public URL getPage()
{
- return page_url;
+ return page;
}
protected InputStream getStream(URL page)
@@ -242,22 +245,41 @@ public class JEditorPane extends JTextComponent
public void setContentType(String type)
{
- ctype = type;
- invalidate();
- repaint();
- }
-
- public void setEditorKit(EditorKit kit)
- {
- this.kit = kit;
+ if (editorKit != null
+ && editorKit.getContentType().equals(type))
+ return;
+
+ EditorKit kit = getEditorKitForContentType(type);
+
+ if (kit != null)
+ setEditorKit(kit);
+ }
+
+ public void setEditorKit(EditorKit newValue)
+ {
+ if (editorKit == newValue)
+ return;
+
+ if (editorKit != null)
+ editorKit.deinstall(this);
+
+ EditorKit oldValue = editorKit;
+ editorKit = newValue;
+
+ if (editorKit != null)
+ {
+ editorKit.install(this);
+ setDocument(editorKit.createDefaultDocument());
+ }
+
+ firePropertyChange("editorKit", oldValue, newValue);
invalidate();
repaint();
}
public void setEditorKitForContentType(String type, EditorKit k)
{
- ctype = type;
- setEditorKit(k);
+ // FIXME: editorKitCache.put(type, kit);
}
/**
@@ -265,6 +287,7 @@ public class JEditorPane extends JTextComponent
*/
public void setPage(String url) throws IOException
{
+ setPage(new URL(url));
}
/**
@@ -272,6 +295,18 @@ public class JEditorPane extends JTextComponent
*/
public void setPage(URL page) throws IOException
{
+ if (page == null)
+ throw new IOException("invalid url");
+
+ try
+ {
+ this.page = page;
+ getEditorKit().read(page.openStream(), getDocument(), 0);
+ }
+ catch (BadLocationException e)
+ {
+ // Ignored. '0' is always a valid offset.
+ }
}
public void setText(String t)
diff --git a/libjava/javax/swing/text/DefaultEditorKit.java b/libjava/javax/swing/text/DefaultEditorKit.java
index 1fd1073dff7..6458e5b0b98 100644
--- a/libjava/javax/swing/text/DefaultEditorKit.java
+++ b/libjava/javax/swing/text/DefaultEditorKit.java
@@ -1,5 +1,5 @@
/* DefaultEditorKit.java --
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -40,9 +40,12 @@ package javax.swing.text;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
+import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
+import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
@@ -84,6 +87,7 @@ public class DefaultEditorKit extends EditorKit
{
super(cutAction);
}
+
public void actionPerformed(ActionEvent event)
{
}
@@ -96,6 +100,7 @@ public class DefaultEditorKit extends EditorKit
{
super(defaultKeyTypedAction);
}
+
public void actionPerformed(ActionEvent event)
{
JTextComponent t = getTextComponent(event);
@@ -123,6 +128,7 @@ public class DefaultEditorKit extends EditorKit
{
super(insertBreakAction);
}
+
public void actionPerformed(ActionEvent event)
{
}
@@ -147,6 +153,7 @@ public class DefaultEditorKit extends EditorKit
{
super(insertTabAction);
}
+
public void actionPerformed(ActionEvent event)
{
}
@@ -159,6 +166,7 @@ public class DefaultEditorKit extends EditorKit
{
super(pasteAction);
}
+
public void actionPerformed(ActionEvent event)
{
}
@@ -364,22 +372,34 @@ public class DefaultEditorKit extends EditorKit
return null;
}
- public void read(InputStream in, Document doc, int pos)
+ public void read(InputStream in, Document document, int offset)
throws BadLocationException, IOException
{
+ read(new InputStreamReader(in), document, offset);
}
- public void read(Reader in, Document doc, int pos)
+ public void read(Reader in, Document document, int offset)
throws BadLocationException, IOException
{
+ BufferedReader reader = new BufferedReader(in);
+
+ String line;
+ StringBuffer content = new StringBuffer();
+
+ while ((line = reader.readLine()) != null)
+ content.append(line);
+
+ document.insertString(offset, content.toString(),
+ SimpleAttributeSet.EMPTY);
}
- public void write(OutputStream out, Document doc, int pos, int len)
+ public void write(OutputStream out, Document document, int offset, int len)
throws BadLocationException, IOException
{
+ write(new OutputStreamWriter(out), document, offset, len);
}
- public void write(Writer out, Document doc, int pos, int len)
+ public void write(Writer out, Document document, int offset, int len)
throws BadLocationException, IOException
{
}