2 Copyright (C) 2002, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
41 import java.awt.Dimension;
42 import java.awt.event.KeyEvent;
43 import java.io.InputStream;
44 import java.io.IOException;
46 import javax.accessibility.AccessibleContext;
47 import javax.swing.text.EditorKit;
48 import javax.swing.text.JTextComponent;
49 import javax.swing.text.PlainEditorKit;
50 import javax.swing.event.HyperlinkEvent;
51 import javax.swing.event.HyperlinkListener;
53 public class JEditorPane extends JTextComponent
55 private static final long serialVersionUID = 3140472492599046285L;
59 String ctype = "text/plain";
61 boolean manages_focus;
68 public JEditorPane(String url)
75 public JEditorPane(String type, String text)
81 public JEditorPane(URL url)
87 protected EditorKit createDefaultEditorKit()
88 { return new PlainEditorKit(); }
90 static EditorKit createEditorKitForContentType(String type)
91 { return new PlainEditorKit(); }
93 void fireHyperlinkUpdate(HyperlinkEvent e)
97 public AccessibleContext getAccessibleContext()
100 String getContentType()
103 EditorKit getEditorKit()
106 static String getEditorKitClassNameForContentType(String type)
107 { return "text/plain"; }
109 EditorKit getEditorKitForContentType(String type)
112 public Dimension getPreferredSize()
114 //Returns the preferred size for the JEditorPane.
115 return super.getPreferredSize();
118 public boolean getScrollableTracksViewportHeight()
120 public boolean getScrollableTracksViewportWidth()
126 protected InputStream getStream(URL page)
129 return page.openStream();
130 } catch (Exception e) {
131 System.out.println("Hhmmm, failed to open stream: " + e);
136 public String getText()
137 { return super.getText(); }
139 public String getUIClassID()
140 { return "EditorPaneUI"; }
142 public boolean isFocusCycleRoot()
143 { return focus_root; }
145 public boolean isManagingFocus()
146 { return manages_focus; }
148 protected String paramString()
149 { return "JEditorPane"; }
151 protected void processComponentKeyEvent(KeyEvent e)
153 //Overridden to handle processing of tab/shift tab.
156 protected void processKeyEvent(KeyEvent e)
158 //Make sure that TAB and Shift-TAB events get consumed, so that awt doesn't attempt focus traversal.
161 void read(InputStream in, Object desc)
163 //This method initializes from a stream.
166 static void registerEditorKitForContentType(String type, String classname)
168 //Establishes the default bindings of type to classname.
171 static void registerEditorKitForContentType(String type, String classname, ClassLoader loader)
173 //Establishes the default bindings of type to classname.
176 void replaceSelection(String content)
178 //Replaces the currently selected content with new content represented by the given string.
181 protected void scrollToReference(String reference)
183 //Scrolls the view to the given reference location (that is, the value returned by the UL.getRef method for the URL being displayed).
186 void setContentType(String type)
193 void setEditorKit(EditorKit kit)
200 void setEditorKitForContentType(String type, EditorKit k)
206 void setPage(String url)
209 // Sets the current URL being displayed.
212 void setPage(URL page)
215 // Sets the current URL being displayed.
218 public void setText(String t)
223 public void addHyperlinkListener(HyperlinkListener listener)
225 listenerList.add (HyperlinkListener.class, listener);
228 public void removeHyperlinkListener (HyperlinkListener listener)
230 listenerList.remove (HyperlinkListener.class, listener);
236 public HyperlinkListener[] getHyperlinkListeners()
238 return (HyperlinkListener[]) getListeners (HyperlinkListener.class);
241 } // class JEditorPane