1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46:
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54:
55:
56: public class JEditorPane extends JTextComponent
57: {
58: private static final long serialVersionUID = 3140472492599046285L;
59:
60: private URL page;
61: private EditorKit editorKit;
62:
63: boolean focus_root;
64:
65: public JEditorPane()
66: {
67: setEditorKit(createDefaultEditorKit());
68: }
69:
70: public JEditorPane(String url) throws IOException
71: {
72: this(new URL(url));
73: }
74:
75: public JEditorPane(String type, String text)
76: {
77: setEditorKit(createEditorKitForContentType(type));
78: setText(text);
79: }
80:
81: public JEditorPane(URL url) throws IOException
82: {
83: this();
84: setPage(url);
85: }
86:
87: protected EditorKit createDefaultEditorKit()
88: {
89: return new DefaultEditorKit();
90: }
91:
92: public static EditorKit createEditorKitForContentType(String type)
93: {
94: return new DefaultEditorKit();
95: }
96:
97:
102: public void fireHyperlinkUpdate(HyperlinkEvent event)
103: {
104: HyperlinkListener[] listeners = getHyperlinkListeners();
105:
106: for (int index = 0; index < listeners.length; ++index)
107: listeners[index].hyperlinkUpdate(event);
108: }
109:
110: public AccessibleContext getAccessibleContext()
111: {
112: return null;
113: }
114:
115: public final String getContentType()
116: {
117: return getEditorKit().getContentType();
118: }
119:
120:
124: public EditorKit getEditorKit()
125: {
126: if (editorKit == null)
127: setEditorKit(createDefaultEditorKit());
128: return editorKit;
129: }
130:
131: public static String getEditorKitClassNameForContentType(String type)
132: {
133: return "text/plain";
134: }
135:
136: public EditorKit getEditorKitForContentType(String type)
137: {
138: return editorKit;
139: }
140:
141:
144: public Dimension getPreferredSize()
145: {
146: return super.getPreferredSize();
147: }
148:
149: public boolean getScrollableTracksViewportHeight()
150: {
151: return false;
152: }
153:
154: public boolean getScrollableTracksViewportWidth()
155: {
156: return false;
157: }
158:
159: public URL getPage()
160: {
161: return page;
162: }
163:
164: protected InputStream getStream(URL page)
165: throws IOException
166: {
167: return page.openStream();
168: }
169:
170: public String getText()
171: {
172: return super.getText();
173: }
174:
175: public String getUIClassID()
176: {
177: return "EditorPaneUI";
178: }
179:
180: public boolean isFocusCycleRoot()
181: {
182: return focus_root;
183: }
184:
185: protected String paramString()
186: {
187: return "JEditorPane";
188: }
189:
190:
193: public void read(InputStream in, Object desc)
194: throws IOException
195: {
196: }
197:
198:
201: public static void registerEditorKitForContentType(String type,
202: String classname)
203: {
204: }
205:
206:
209: public static void registerEditorKitForContentType(String type,
210: String classname,
211: ClassLoader loader)
212: {
213: }
214:
215:
219: public void replaceSelection(String content)
220: {
221: }
222:
223:
227: public void scrollToReference(String reference)
228: {
229: }
230:
231: public final void setContentType(String type)
232: {
233: if (editorKit != null
234: && editorKit.getContentType().equals(type))
235: return;
236:
237: EditorKit kit = getEditorKitForContentType(type);
238:
239: if (kit != null)
240: setEditorKit(kit);
241: }
242:
243: public void setEditorKit(EditorKit newValue)
244: {
245: if (editorKit == newValue)
246: return;
247:
248: if (editorKit != null)
249: editorKit.deinstall(this);
250:
251: EditorKit oldValue = editorKit;
252: editorKit = newValue;
253:
254: if (editorKit != null)
255: {
256: editorKit.install(this);
257: setDocument(editorKit.createDefaultDocument());
258: }
259:
260: firePropertyChange("editorKit", oldValue, newValue);
261: invalidate();
262: repaint();
263: }
264:
265: public void setEditorKitForContentType(String type, EditorKit k)
266: {
267:
268: }
269:
270:
273: public void setPage(String url) throws IOException
274: {
275: setPage(new URL(url));
276: }
277:
278:
281: public void setPage(URL page) throws IOException
282: {
283: if (page == null)
284: throw new IOException("invalid url");
285:
286: try
287: {
288: this.page = page;
289: getEditorKit().read(page.openStream(), getDocument(), 0);
290: }
291: catch (BadLocationException e)
292: {
293:
294: }
295: }
296:
297: public void setText(String t)
298: {
299: super.setText(t);
300: }
301:
302:
307: public void addHyperlinkListener(HyperlinkListener listener)
308: {
309: listenerList.add(HyperlinkListener.class, listener);
310: }
311:
312:
317: public void removeHyperlinkListener(HyperlinkListener listener)
318: {
319: listenerList.remove(HyperlinkListener.class, listener);
320: }
321:
322:
329: public HyperlinkListener[] getHyperlinkListeners()
330: {
331: return (HyperlinkListener[]) getListeners(HyperlinkListener.class);
332: }
333: }