[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: swing fixes

Kaffe CVS cvs-commits at kaffe.org
Wed Jan 12 21:23:00 PST 2005


PatchSet 5840 
Date: 2005/01/13 05:18:24
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: swing fixes

2005-01-13  Dalibor Topic  <robilad at kaffe.org>

Resynced with GNU Classpath.

2005-01-10  Michael Koch  <konqueror at 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.

Members: 
	ChangeLog:1.3384->1.3385 
	libraries/javalib/javax/swing/JEditorPane.java:1.4->1.5 
	libraries/javalib/javax/swing/text/DefaultEditorKit.java:1.6->1.7 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3384 kaffe/ChangeLog:1.3385
--- kaffe/ChangeLog:1.3384	Thu Jan 13 04:54:25 2005
+++ kaffe/ChangeLog	Thu Jan 13 05:18:24 2005
@@ -2,6 +2,29 @@
 
 	Resynced with GNU Classpath.
 	
+	2005-01-10  Michael Koch  <konqueror at 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-13  Dalibor Topic  <robilad at kaffe.org>
+
+	Resynced with GNU Classpath.
+	
 	2005-01-10  Thomas Fitzsimmons  <fitzsim at redhat.com>
 
 	* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c
Index: kaffe/libraries/javalib/javax/swing/JEditorPane.java
diff -u kaffe/libraries/javalib/javax/swing/JEditorPane.java:1.4 kaffe/libraries/javalib/javax/swing/JEditorPane.java:1.5
--- kaffe/libraries/javalib/javax/swing/JEditorPane.java:1.4	Sun Oct 24 13:39:11 2004
+++ kaffe/libraries/javalib/javax/swing/JEditorPane.java	Thu Jan 13 05:18:27 2005
@@ -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 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 @@
 {
   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 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 EditorKit getEditorKitForContentType(String type)
   {
-    return kit;
+    return editorKit;
   }
 
   /**
@@ -150,7 +153,7 @@
 
   public URL getPage()
   {
-    return page_url;
+    return page;
   }
 
   protected InputStream getStream(URL page)
@@ -242,22 +245,41 @@
 
   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 void setPage(String url) throws IOException
   {
+    setPage(new URL(url));
   }
 
   /**
@@ -272,6 +295,18 @@
    */
   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)
Index: kaffe/libraries/javalib/javax/swing/text/DefaultEditorKit.java
diff -u kaffe/libraries/javalib/javax/swing/text/DefaultEditorKit.java:1.6 kaffe/libraries/javalib/javax/swing/text/DefaultEditorKit.java:1.7
--- kaffe/libraries/javalib/javax/swing/text/DefaultEditorKit.java:1.6	Sun Oct 24 13:39:22 2004
+++ kaffe/libraries/javalib/javax/swing/text/DefaultEditorKit.java	Thu Jan 13 05:18:28 2005
@@ -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 @@
 
 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 @@
     {
       super(cutAction);
     }
+
     public void actionPerformed(ActionEvent event)
     {
     }
@@ -96,6 +100,7 @@
     {
       super(defaultKeyTypedAction);
     }
+
     public void actionPerformed(ActionEvent event)
     {
       JTextComponent t = getTextComponent(event);
@@ -123,6 +128,7 @@
     {
       super(insertBreakAction);
     }
+
     public void actionPerformed(ActionEvent event)
     {
     }
@@ -147,6 +153,7 @@
     {
       super(insertTabAction);
     }
+
     public void actionPerformed(ActionEvent event)
     {
     }
@@ -159,6 +166,7 @@
     {
       super(pasteAction);
     }
+
     public void actionPerformed(ActionEvent event)
     {
     }
@@ -364,22 +372,34 @@
     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
   {
   }



More information about the kaffe mailing list