1*1b0aaa91SAndrew Rist /**************************************************************
2*1b0aaa91SAndrew Rist  *
3*1b0aaa91SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*1b0aaa91SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*1b0aaa91SAndrew Rist  * distributed with this work for additional information
6*1b0aaa91SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*1b0aaa91SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*1b0aaa91SAndrew Rist  * "License"); you may not use this file except in compliance
9*1b0aaa91SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*1b0aaa91SAndrew Rist  *
11*1b0aaa91SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*1b0aaa91SAndrew Rist  *
13*1b0aaa91SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*1b0aaa91SAndrew Rist  * software distributed under the License is distributed on an
15*1b0aaa91SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*1b0aaa91SAndrew Rist  * KIND, either express or implied.  See the License for the
17*1b0aaa91SAndrew Rist  * specific language governing permissions and limitations
18*1b0aaa91SAndrew Rist  * under the License.
19*1b0aaa91SAndrew Rist  *
20*1b0aaa91SAndrew Rist  *************************************************************/
21*1b0aaa91SAndrew Rist 
22cdf0e10cSrcweir import javax.swing.JEditorPane;
23cdf0e10cSrcweir import javax.swing.event.HyperlinkListener;
24cdf0e10cSrcweir import javax.swing.event.HyperlinkEvent;
25cdf0e10cSrcweir import javax.swing.text.Document;
26cdf0e10cSrcweir import java.net.URL;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir class TextLogger
29cdf0e10cSrcweir     extends JEditorPane
30cdf0e10cSrcweir {
TextLogger()31cdf0e10cSrcweir     public TextLogger ()
32cdf0e10cSrcweir         throws java.io.IOException
33cdf0e10cSrcweir     {
34cdf0e10cSrcweir //        maDocument = getEditorKit().createDefaultDocument();
35cdf0e10cSrcweir             super ("http://localhost");
36cdf0e10cSrcweir         try
37cdf0e10cSrcweir         {
38cdf0e10cSrcweir             //            setPage (new URL ("http://www.spiegel.de"));
39cdf0e10cSrcweir         }
40cdf0e10cSrcweir         catch (Exception e)
41cdf0e10cSrcweir         {}
42cdf0e10cSrcweir 
43cdf0e10cSrcweir         setEditable (false);
44cdf0e10cSrcweir         final JEditorPane finalPane = this;
45cdf0e10cSrcweir         addHyperlinkListener (new HyperlinkListener()
46cdf0e10cSrcweir             {
47cdf0e10cSrcweir                 public void hyperlinkUpdate (HyperlinkEvent e)
48cdf0e10cSrcweir                 {
49cdf0e10cSrcweir                     try
50cdf0e10cSrcweir                     {
51cdf0e10cSrcweir                         if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
52cdf0e10cSrcweir                             finalPane.setPage (e.getURL());
53cdf0e10cSrcweir                     }
54cdf0e10cSrcweir                     catch (java.io.IOException ex)
55cdf0e10cSrcweir                     {
56cdf0e10cSrcweir                         ex.printStackTrace(System.err);
57cdf0e10cSrcweir                     }
58cdf0e10cSrcweir                 }
59cdf0e10cSrcweir             });
60cdf0e10cSrcweir     }
61cdf0e10cSrcweir 
appendText(String sText)62cdf0e10cSrcweir     public void appendText (String sText)
63cdf0e10cSrcweir     {
64cdf0e10cSrcweir         try
65cdf0e10cSrcweir         {
66cdf0e10cSrcweir             maDocument.insertString (maDocument.getLength(), sText, null);
67cdf0e10cSrcweir         }
68cdf0e10cSrcweir         catch (javax.swing.text.BadLocationException e)
69cdf0e10cSrcweir         {}
70cdf0e10cSrcweir     }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     private Document maDocument;
73cdf0e10cSrcweir }
74