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