/[classpath]/classpath/javax/swing/JEditorPane.java
ViewVC logotype

Diff of /classpath/javax/swing/JEditorPane.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14 by mkoch, Fri Oct 22 18:16:00 2004 UTC revision 1.15 by mkoch, Mon Jan 10 18:16:15 2005 UTC
# Line 1  Line 1 
1  /* JEditorPane.java --  /* JEditorPane.java --
2     Copyright (C) 2002, 2004  Free Software Foundation, Inc.     Copyright (C) 2002, 2004, 2005  Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 47  import java.net.URL; Line 47  import java.net.URL;
47  import javax.accessibility.AccessibleContext;  import javax.accessibility.AccessibleContext;
48  import javax.swing.event.HyperlinkEvent;  import javax.swing.event.HyperlinkEvent;
49  import javax.swing.event.HyperlinkListener;  import javax.swing.event.HyperlinkListener;
50    import javax.swing.text.BadLocationException;
51  import javax.swing.text.DefaultEditorKit;  import javax.swing.text.DefaultEditorKit;
52  import javax.swing.text.EditorKit;  import javax.swing.text.EditorKit;
53  import javax.swing.text.JTextComponent;  import javax.swing.text.JTextComponent;
# Line 56  public class JEditorPane extends JTextCo Line 57  public class JEditorPane extends JTextCo
57  {  {
58    private static final long serialVersionUID = 3140472492599046285L;    private static final long serialVersionUID = 3140472492599046285L;
59        
60    URL page_url;    private URL page;
61    EditorKit kit;    private EditorKit editorKit;
62    String ctype = "text/plain";    
63    boolean focus_root;    boolean focus_root;
64    boolean manages_focus;    boolean manages_focus;
65    
66    public JEditorPane()    public JEditorPane()
67    {    {
68        setEditorKit(createDefaultEditorKit());
69    }    }
70    
71    public JEditorPane(String url) throws IOException    public JEditorPane(String url) throws IOException
72    {    {
73      setPage(url);      this(new URL(url));
74    }    }
75    
76    public JEditorPane(String type, String text)    public JEditorPane(String type, String text)
77    {    {
78      ctype = text;      setEditorKit(createEditorKitForContentType(type));
79      setText(text);      setText(text);
80    }    }
81    
82    public JEditorPane(URL url) throws IOException    public JEditorPane(URL url) throws IOException
83    {    {
84        this();
85      setPage(url);      setPage(url);
86    }    }
87    
# Line 112  public class JEditorPane extends JTextCo Line 115  public class JEditorPane extends JTextCo
115    
116    public String getContentType()    public String getContentType()
117    {    {
118      return ctype;      return getEditorKit().getContentType();
119    }    }
120    
121    public EditorKit getEditorKit()    public EditorKit getEditorKit()
122    {    {
123      return kit;      return editorKit;
124    }    }
125    
126    public static String getEditorKitClassNameForContentType(String type)    public static String getEditorKitClassNameForContentType(String type)
# Line 127  public class JEditorPane extends JTextCo Line 130  public class JEditorPane extends JTextCo
130    
131    public EditorKit getEditorKitForContentType(String type)    public EditorKit getEditorKitForContentType(String type)
132    {    {
133      return kit;      return editorKit;
134    }    }
135    
136    /**    /**
# Line 150  public class JEditorPane extends JTextCo Line 153  public class JEditorPane extends JTextCo
153    
154    public URL getPage()    public URL getPage()
155    {    {
156      return page_url;      return page;
157    }    }
158    
159    protected InputStream getStream(URL page)    protected InputStream getStream(URL page)
# Line 242  public class JEditorPane extends JTextCo Line 245  public class JEditorPane extends JTextCo
245    
246    public void setContentType(String type)    public void setContentType(String type)
247    {    {
248      ctype = type;      if (editorKit != null
249      invalidate();          && editorKit.getContentType().equals(type))
250      repaint();        return;
251    }                
252        EditorKit kit = getEditorKitForContentType(type);
253    public void setEditorKit(EditorKit kit)                  
254    {      if (kit != null)
255      this.kit = kit;        setEditorKit(kit);
256      }
257    
258      public void setEditorKit(EditorKit newValue)
259      {
260        if (editorKit == newValue)
261          return;
262            
263        if (editorKit != null)
264          editorKit.deinstall(this);
265                        
266        EditorKit oldValue = editorKit;
267        editorKit = newValue;
268                                    
269        if (editorKit != null)
270          {
271            editorKit.install(this);
272            setDocument(editorKit.createDefaultDocument());
273          }
274                                                
275        firePropertyChange("editorKit", oldValue, newValue);
276      invalidate();      invalidate();
277      repaint();      repaint();
278    }    }
279    
280    public void setEditorKitForContentType(String type, EditorKit k)    public void setEditorKitForContentType(String type, EditorKit k)
281    {    {
282      ctype = type;      // FIXME: editorKitCache.put(type, kit);
     setEditorKit(k);  
283    }    }
284    
285    /**    /**
# Line 265  public class JEditorPane extends JTextCo Line 287  public class JEditorPane extends JTextCo
287     */     */
288    public void setPage(String url) throws IOException    public void setPage(String url) throws IOException
289    {    {
290        setPage(new URL(url));
291    }    }
292    
293    /**    /**
# Line 272  public class JEditorPane extends JTextCo Line 295  public class JEditorPane extends JTextCo
295     */     */
296    public void setPage(URL page) throws IOException    public void setPage(URL page) throws IOException
297    {    {
298        if (page == null)
299          throw new IOException("invalid url");
300    
301        try
302          {
303            this.page = page;
304            getEditorKit().read(page.openStream(), getDocument(), 0);
305          }
306        catch (BadLocationException e)
307          {
308            // Ignored. '0' is always a valid offset.
309          }
310    }    }
311    
312    public void setText(String t)    public void setText(String t)

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26