1   /**
2    * Distribution License:
3    * BibleDesktop is free software; you can redistribute it and/or modify it under
4    * the terms of the GNU General Public License, version 2 as published by
5    * the Free Software Foundation. This program is distributed in the hope
6    * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8    * See the GNU General Public License for more details.
9    *
10   * The License is available on the internet at:
11   *       http://www.gnu.org/copyleft/gpl.html
12   * or by writing to:
13   *      Free Software Foundation, Inc.
14   *      59 Temple Place - Suite 330
15   *      Boston, MA 02111-1307, USA
16   *
17   * Copyright: 2007
18   *     The copyright to this program is held by it's authors.
19   *
20   * ID: $Id: org.eclipse.jdt.ui.prefs 1178 2006-11-06 12:48:02Z lanyjie $
21   */
22  
23  package org.crosswire.bibledesktop.display.basic;
24  
25  import java.awt.event.MouseListener;
26  
27  import javax.swing.JEditorPane;
28  import javax.swing.text.html.HTMLEditorKit;
29  
30  /**
31   *
32   *
33   * @see gnu.gpl.License for license details.
34   *      The copyright to this program is held by it's authors.
35   * @author Yingjie Lan [lanyjie at yahoo dot com]
36   */
37  public class LazyHTMLEditorKit extends HTMLEditorKit {
38       /**
39        * Called when the kit is being installed into the
40        * a JEditorPane.
41        *
42        * @param c the JEditorPane
43        */
44       @Override
45      public void install(JEditorPane c) {
46          super.install(c);
47          MouseListener[] mls = c.getMouseListeners();
48          for (int i = 0; i < mls.length; i++) {
49              if (mls[i] instanceof HTMLEditorKit.LinkController) {
50                  if (linkCtrl == null) {
51                      linkCtrl = (HTMLEditorKit.LinkController) mls[i];
52                  } else {
53                      throw new RuntimeException("Multiple Link Controllers!");
54                  }
55              }
56          }
57          c.removeMouseMotionListener(linkCtrl);
58        }
59  
60         /**
61          * Called when the kit is being removed from the
62          * JEditorPane. This is used to unregister any
63          * listeners that were attached.
64          *
65          * @param c the JEditorPane
66          */
67          @Override
68          public void deinstall(JEditorPane c) {
69              c.addMouseMotionListener(linkCtrl);
70              super.deinstall(c);
71              linkCtrl = null;
72          }
73  
74          public HTMLEditorKit.LinkController getLinkCtrl() {
75              return  linkCtrl;
76          }
77  
78          /**
79           * Auto generated.
80           */
81          private static final long serialVersionUID = 4673477549981614993L;
82          private HTMLEditorKit.LinkController linkCtrl;
83  }
84