KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > loader > wizard > OctopusHelpToolBar


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

21
22 package org.webdocwf.util.loader.wizard;
23
24 // Java core packages
25
import java.awt.*;
26 import java.awt.event.*;
27 import java.net.*;
28
29 // Java extension packages
30
import javax.swing.*;
31 import javax.swing.event.*;
32
33 public class OctopusHelpToolBar extends JToolBar
34    implements HyperlinkListener {
35
36    private OctopusHelpPane webBrowserPane;
37    private JButton backButton;
38    private JButton forwardButton;
39    private JTextField urlTextField;
40
41    // WebToolBar constructor
42
public OctopusHelpToolBar( OctopusHelpPane browser )
43    {
44       super( "Web Navigation" );
45
46       // register for HyperlinkEvents
47
webBrowserPane = browser;
48       webBrowserPane.addHyperlinkListener( this );
49
50       // create JTextField for entering URLs
51
urlTextField = new JTextField( 25 );
52       urlTextField.setVisible(false);
53       urlTextField.addActionListener(
54          new ActionListener() {
55
56             // navigate webBrowser to user-entered URL
57
public void actionPerformed( ActionEvent event )
58             {
59                // attempt to load URL in webBrowserPane
60
try {
61                   URL url = new URL( urlTextField.getText() );
62                   webBrowserPane.goToURL( url );
63                }
64
65                // handle invalid URL
66
catch ( MalformedURLException urlException ) {
67                   urlException.printStackTrace();
68                }
69             }
70          }
71       );
72
73       // create JButton for navigating to previous history URL
74
backButton = new JButton( new ImageIcon(
75          getClass().getResource( "images/Back16.gif" ) ) );
76
77       backButton.addActionListener(
78          new ActionListener() {
79
80             public void actionPerformed( ActionEvent event )
81             {
82                // navigate to previous URL
83
URL url = webBrowserPane.back();
84
85                // display URL in urlTextField
86
urlTextField.setText( url.toString() );
87             }
88          }
89       );
90
91       // create JButton for navigating to next history URL
92
forwardButton = new JButton( new ImageIcon(
93          getClass().getResource( "images/Forward16.gif" ) ) );
94
95       forwardButton.addActionListener(
96          new ActionListener() {
97
98             public void actionPerformed( ActionEvent event )
99             {
100                // navigate to next URL
101
URL url = webBrowserPane.forward();
102
103                // display new URL in urlTextField
104
urlTextField.setText( url.toString() );
105             }
106          }
107       );
108
109       // add JButtons and JTextField to WebToolBar
110
add( backButton );
111       add( forwardButton );
112       add( urlTextField );
113
114    } // end WebToolBar constructor
115

116    // listen for HyperlinkEvents in WebBrowserPane
117
public void hyperlinkUpdate( HyperlinkEvent event )
118    {
119       // if hyperlink was activated, go to hyperlink's URL
120
if ( event.getEventType() ==
121          HyperlinkEvent.EventType.ACTIVATED ) {
122
123          // get URL from HyperlinkEvent
124
URL url = event.getURL();
125
126          // navigate to URL and display URL in urlTextField
127
webBrowserPane.goToURL( url );
128          urlTextField.setText( url.toString() );
129       }
130    }
131 }
Popular Tags