KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > helpbrowser > LinkListener


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2002 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.helpbrowser;
20
21 import javax.swing.*;
22 import javax.swing.event.*;
23
24 /**
25  * HelpBrowser's link listener
26  */

27 public class LinkListener
28 implements HyperlinkListener
29 {
30     private JEditorPane big;
31     private JTextArea mini;
32     private HelpBrowser parent;
33     
34     /**
35      * Constructor
36      *
37      * @param parent the help browser
38      * @param big the help container
39      * @param mini the tooltip container
40      */

41     public LinkListener(HelpBrowser parent, JEditorPane big, JTextArea mini)
42     {
43         this.big = big;
44         this.mini = mini;
45         this.parent = parent;
46     }
47     
48     /**
49      * A link was hovered or clicked
50      */

51     public void hyperlinkUpdate(HyperlinkEvent he)
52     {
53         String JavaDoc url = he.getDescription();
54         boolean tooltip = false;
55         boolean section = false;
56         
57         if(url.startsWith("#tooltip:"))
58         {
59             tooltip = true;
60             url = url.substring(9); //#tooltip:
61
}
62         else if(url.startsWith("#section:"))
63         {
64             section = true;
65             url = url.substring(9); //#section:
66
}
67         
68         //-- click
69
if(he.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
70         {
71             if(section)
72                 this.parent.gotoSection(url);
73         }
74         
75         //-- hover
76
else if(he.getEventType() == HyperlinkEvent.EventType.ENTERED)
77         {
78             if(tooltip)
79                 this.mini.setText(url);
80             else if(section)
81                 this.mini.setText(parent.tr("gotoSection1") + url + parent.tr("gotoSection2"));
82         }
83         
84         //-- end of hover
85
else if(he.getEventType() == HyperlinkEvent.EventType.EXITED)
86         {
87             if(tooltip || section)
88                 this.mini.setText("");
89         }
90     }
91 }
Popular Tags