1   package gate.gui;
2   
3   import java.awt.BorderLayout;
4   import java.beans.PropertyChangeEvent;
5   import java.beans.PropertyChangeListener;
6   import java.io.IOException;
7   import java.net.URL;
8   
9   import javax.swing.*;
10  import javax.swing.text.Document;
11  
12  import gate.event.StatusListener;
13  import gate.swing.XJEditorPane;
14  
15  /**
16   * A frame used by Gate to display Help information.
17   * It is a basic HTML browser.
18   */
19  public class HelpFrame extends JFrame implements StatusListener {
20  
21    public HelpFrame(){
22      super();
23      initLocalData();
24      initGuiComponents();
25      initListeners();
26    }
27  
28    protected void initLocalData(){
29    }
30  
31    protected void initGuiComponents(){
32      getContentPane().setLayout(new BorderLayout());
33      textPane = new XJEditorPane();
34      textPane.setEditable(false);
35      getContentPane().add(new JScrollPane(textPane), BorderLayout.CENTER);
36  
37      toolBar = new JToolBar();
38      toolBar.add(textPane.getBackAction());
39      toolBar.add(textPane.getForwardAction());
40  
41      getContentPane().add(toolBar, BorderLayout.NORTH);
42  
43      Box southBox = Box.createHorizontalBox();
44      southBox.add(new JLabel(" "));
45      status = new JLabel();
46      southBox.add(status);
47      getContentPane().add(southBox, BorderLayout.SOUTH);
48  
49    }
50  
51    protected void initListeners(){
52      textPane.addPropertyChangeListener(new PropertyChangeListener(){
53        public void propertyChange(PropertyChangeEvent e) {
54          if(e.getPropertyName().equals("document")){
55            String title = (String)textPane.getDocument().
56                                            getProperty("title");
57            setTitle((title == null) ?
58                     "GATE help browser" :
59                     title + " - GATE help browser");
60          }
61        }
62      });
63  
64      textPane.addStatusListener(this);
65    }
66  
67    public void setPage(URL newPage) throws IOException{
68      textPane.setPage(newPage);
69      String title = (String)textPane.getDocument().
70                                      getProperty(Document.TitleProperty);
71      setTitle((title == null) ?
72               "GATE help browser" :
73               title + " - GATE help browser");
74    }
75  
76    XJEditorPane textPane;
77    JToolBar toolBar;
78    JLabel status;
79    public void statusChanged(String e) {
80      status.setText(e);
81    }
82  }