View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20  */
21  
22  
23  
24  /******************************************************************************
25  * HelpWindow.java
26  *
27  * A Generic Floating Window for displaying Help Messages
28  *****************************************************************************/
29  
30  package zeus.gui.help;
31  
32  import java.io.*;
33  import java.awt.*;
34  import java.util.Vector;
35  import java.awt.event.*;
36  import javax.swing.*;
37  import javax.swing.border.*;
38  
39  import zeus.util.SystemProps;
40  
41  
42  public class HelpWindow extends JFrame {
43    protected HtmlPanel      textPane;
44    protected JScrollPane    displayArea;
45    protected HelpToolBar    helpBar;
46    protected AbstractButton sourceBtn;
47    protected Vector         history = new Vector();
48    protected int            histpos = 0;
49  
50  
51    public HelpWindow(Component parent, Point p, String subpath, String aspect) {
52      addWindowListener(new HWHandler());
53  
54      setTitle("Help on " + aspect);
55      String sep = System.getProperty("file.separator");
56      String path = SystemProps.getProperty("gif.dir") + "help" + sep;
57      ImageIcon icon = new ImageIcon(path + "questionicon.gif");
58      setIconImage(icon.getImage());
59      Point parentpos = parent.getLocation();
60      int width = (parent.getSize()).width;
61      Point dispos = new Point(parentpos.x + width, parentpos.y + p.y);
62      setLocation(dispos.x, dispos.y);
63      setSize(new Dimension(400,300));
64  
65      getContentPane().setLayout(new BorderLayout());
66      JPanel innerPane = new JPanel();
67      innerPane.setBackground(Color.yellow.brighter());
68      BevelBorder border = new BevelBorder(BevelBorder.RAISED);
69      innerPane.setBorder(border);
70  
71      String filename = aspect + sep + "what.html";
72      String helppath = SystemProps.getProperty("zeus.dir") + "help" + sep +
73                            subpath + sep;
74      String fullpath = "file:" + helppath + filename;
75  
76      textPane = new HtmlPanel(this);
77      history.addElement(fullpath);
78      textPane.setPage(fullpath);
79  
80      GridBagLayout gridBagLayout = new GridBagLayout();
81      GridBagConstraints gbc = new GridBagConstraints();
82      innerPane.setLayout(gridBagLayout);
83  
84      helpBar = new HelpToolBar();
85      gbc.gridwidth = GridBagConstraints.REMAINDER;
86      gbc.gridheight = 1;
87      gbc.anchor = GridBagConstraints.EAST;
88      gbc.fill = GridBagConstraints.HORIZONTAL;
89      gbc.weightx = gbc.weighty = 0;
90      gbc.insets = new Insets(2,2,2,2);
91      gridBagLayout.setConstraints(helpBar,gbc);
92      innerPane.add(helpBar);
93  
94      gbc.gridwidth = GridBagConstraints.REMAINDER;
95      gbc.anchor = GridBagConstraints.NORTH;
96      gbc.fill = GridBagConstraints.BOTH;
97      gbc.weightx = gbc.weighty = 1;
98      gbc.insets = new Insets(16,16,16,16);
99      gridBagLayout.setConstraints(textPane,gbc);
100     innerPane.add(textPane);
101 
102     getContentPane().add("Center", innerPane);
103     pack();
104     show();
105   }
106 
107   public void setSource(AbstractButton button) { sourceBtn = button; }
108 
109   public void addToHistory(String doc)  {
110     history.addElement(doc);
111     histpos++;
112   }
113 
114 
115   class HWHandler extends WindowAdapter  {
116     public void windowClosing(WindowEvent event)  {
117       if ( sourceBtn != null ) sourceBtn.setSelected(false);
118       dispose();
119     }
120   }
121 
122 class HelpToolBar extends JPanel implements ActionListener {
123   protected JButton       prevBtn;
124   protected JButton       nextBtn;
125 
126   public HelpToolBar() {
127     setBorder(new BevelBorder(BevelBorder.LOWERED));
128     setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
129     setBackground(Color.yellow);
130 
131     String sep = System.getProperty("file.separator");
132     String path = SystemProps.getProperty("gif.dir") + "help" + sep;
133 
134     // Previous Button
135     prevBtn = new JButton(new ImageIcon(path + "previous.gif"));
136     add(prevBtn);
137     prevBtn.setToolTipText("Previous Entry");
138     prevBtn.setMargin(new Insets(0,0,0,0));
139     prevBtn.addActionListener(this);
140 
141     // New Button
142     nextBtn = new JButton(new ImageIcon(path + "next.gif"));
143     add(nextBtn);
144     nextBtn.setToolTipText("Next Entry");
145     nextBtn.setMargin(new Insets(0,0,0,0));
146     nextBtn.addActionListener(this);
147 
148     add(Box.createHorizontalGlue() );
149 
150     JButton hicon = new JButton(new ImageIcon(path + "questionmark.gif"));
151     hicon.setMargin(new Insets(0,0,0,0));
152     add(hicon);
153   }
154   public void actionPerformed(ActionEvent e)  {
155     Object src = e.getSource();
156     if ( src == nextBtn && histpos+1 < history.size() ){
157        histpos++;
158        textPane.setPage((String)history.elementAt(histpos));
159     }
160     else if ( src == prevBtn && histpos > 0 ) {
161       histpos--;
162       textPane.setPage((String)history.elementAt(histpos));
163     }
164     textPane.repaint();
165   }
166 }
167 }