KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ixenon > free > swing > HTMLViewerDialog


1 /* $Id$
2  *
3  * Copyright (c) 1998 Xenonsoft Limited. All Rights Reserved.
4  *
5  * This software is protected by copyright. You are hereby notified from
6  * now by reading this message. This software is also the confidential
7  * and proprietary information of Xenonsoft Limited. ("Confidential
8  * Information").
9  *
10  * This software is distributed under the Xenonsoft Public end user
11  * License ("XPeL"), where the machine-readable source code is provided
12  * under the "Open Source" model.
13  * For more information, please read the file "LICENSE-XPL.txt"
14  */

15
16 // HTMLViewerDialog.java
17

18 // Description:
19
// HTMLViewerDialog the JFC/Swing component
20
//
21
// Author:
22
// Peter Pilgrim
23
// Sun Jan 31 21:59:52 GMT 1999
24
//
25
// RCS HEADER
26
//
27
// $Author$
28
// $Date$
29
// $Source$
30
// $Revision$ $State$ $Locker$
31
//
32
// History
33
// ================================================================================
34
// $Log$
35

36 package ixenon.free.swing;
37
38 import java.awt.*;
39 import java.awt.event.*;
40 import java.util.*;
41 import java.io.*; // for File
42
import java.net.*; // for URL, MalformedUrlException
43

44 import javax.swing.*; // for JDialog, JFrame, JOptionPane
45
import javax.swing.event.*; // HyperlinkEvent, HyperlinkLister
46
import javax.swing.border.*; // for BevelBorder
47
import javax.swing.text.*; // for Document
48

49
50
51 /**
52  *
53  * Implementation of a HTMLViewerDialog custom JFC/Swing pseudo component
54  *
55  * *INCOMPLETE*
56  *
57  * @author Peter Pilgrim Sun Jan 31 22:01:25 GMT 1999
58  * @version $Id$
59  */

60 public class HTMLViewerDialog extends JDialog
61 implements ActionListener, WindowListener
62 {
63     /** the default approve button text */
64     public final static String JavaDoc DEFAULT_APPROVE_TEXT="Close";
65     /** the default approve button tooltip text */
66     public final static String JavaDoc DEFAULT_APPROVE_TOOLTIP_TEXT="dispose dialog";
67
68
69     /** the approve button */
70     protected JButton bt_approve;
71
72     /** the HTML Viewer pane embedded in the dialog */
73     protected HTMLViewerPane htmlPane;
74
75     /**
76      * Create a HTMLViewerDialog with default configuration
77      * @param frame the parent frame
78      * @param title the title of the dialog
79      */

80     public HTMLViewerDialog( Frame frame, String JavaDoc title)
81     {
82     super( frame, title, true /* Modal */ );
83
84     initialise( frame, title, DEFAULT_APPROVE_TEXT );
85     }
86     
87     /**
88      * Create a HTMLViewerDialog with default configuration
89      * @param frame the parent frame
90      * @param title the title of the dialog
91      * @param url the URL to be visited
92      */

93     public HTMLViewerDialog( Frame frame, String JavaDoc title, String JavaDoc url )
94     throws IOException
95     {
96     this(frame, title, url, DEFAULT_APPROVE_TEXT );
97     }
98     
99     /**
100      * Create a HTMLViewerDialog
101      * @param frame the parent frame
102      * @param title the title of the dialog
103      * @param url the URL to be visited
104      * @param approveText the text of the approve button
105      */

106     public HTMLViewerDialog( Frame frame, String JavaDoc title,
107                  String JavaDoc url, String JavaDoc approveText )
108     throws IOException
109     {
110     super( frame, title, true /* Modal */ );
111     initialise( frame, title, approveText );
112     setPage(url);
113     }
114     
115     // creates initial GUI
116
protected void initialise( Frame frame, String JavaDoc title, String JavaDoc approveText )
117     {
118     getContentPane().setLayout( new BorderLayout( 2,2 ));
119
120     Container box = Box.createHorizontalBox();
121
122     bt_approve = new JButton( approveText );
123     bt_approve.addActionListener(this);
124     box.add( Box.createHorizontalGlue() );
125     box.add( bt_approve );
126     box.add( Box.createHorizontalStrut(8) );
127
128     getContentPane().add( box, BorderLayout.SOUTH );
129     
130     // ======================================================================
131
// Create the central HTMLViewerDialog work area panel
132
// ======================================================================
133
htmlPane = new HTMLViewerPane();
134     getContentPane().add( htmlPane, BorderLayout.CENTER );
135
136     addWindowListener(this);
137     pack();
138     }
139     
140     /** Return the HTMLViewerPane object reference */
141     public HTMLViewerPane getHTMLViewerPane()
142     {
143     return (htmlPane);
144     }
145     
146     /** Convenience method: gets the HTMLViewerDialog's page URL */
147     public URL getPage()
148     {
149     return htmlPane.getPage();
150     }
151     
152     /** Convenience method: Sets the HTMLViewerDialog's page URL */
153     public void setPage( URL url )
154     throws IOException
155     {
156     htmlPane.setPage( url );
157     }
158
159     /** Convenience method: Sets the HTMLViewerDialog's page URL */
160     public void setPage( String JavaDoc url )
161     throws IOException
162     {
163     htmlPane.setPage( url );
164     }
165
166     /** Convenience method: Return a boolean flag if the viewer is browsable */
167     public boolean isBrowsable()
168     {
169     return htmlPane.isBrowsable();
170     }
171     
172     /** Convenience method: Sets the boolean flag if the viewer is browsable */
173     public void setBrowsable( boolean flag )
174     {
175     htmlPane.setBrowsable(flag);
176     }
177
178     /** Convenience method: Gets the HTMLViewerDialog's content type */
179     public String JavaDoc getContentType()
180     {
181     return htmlPane.getContentType();
182     }
183     
184     /** Convenience method: Sets the HTMLViewerDialog's content type */
185     public void setContentType( String JavaDoc contentType )
186     throws IOException
187     {
188     htmlPane.setContentType( contentType );
189     }
190
191     /** convenience method to get a reference to approve button object */
192     public JButton getApproveButton()
193     {
194     return bt_approve;
195     }
196
197     /** convenience method to get approve button text */
198     public String JavaDoc getApproveButtonText()
199     {
200     return bt_approve.getText();
201     }
202
203     /** convenience method to set approve button text */
204     public void setApproveButtonText( String JavaDoc text )
205     {
206     bt_approve.setText(text);
207     }
208
209     /** convenience method to get approve button tool tip text */
210     public String JavaDoc getApproveButtonToolTipText()
211     {
212     return bt_approve.getToolTipText();
213     }
214
215     /** convenience method to set approve button tool tip text */
216     public void setApproveButtonToolTipText( String JavaDoc tooltip_text )
217     {
218     bt_approve.setToolTipText(tooltip_text);
219     }
220     
221
222     // ======================================================================
223
// EVENT HANDLING
224
// ======================================================================
225

226     public void actionPerformed( ActionEvent e )
227     {
228     Object JavaDoc src = e.getSource();
229     if ( src == bt_approve ) {
230         setVisible(false);
231         dispose();
232     }
233     }
234     
235     public void windowClosed(WindowEvent event) {}
236     public void windowDeiconified(WindowEvent event) {}
237     public void windowIconified(WindowEvent event) {}
238     public void windowActivated(WindowEvent event) {}
239     public void windowDeactivated(WindowEvent event) {}
240     public void windowOpened(WindowEvent event) {}
241     public void windowClosing(WindowEvent event) { setVisible(false); dispose(); }
242
243     public static void main( String JavaDoc [] args )
244     {
245     JFrame frame = new JFrame("HTMLViewerDialog Demonstration");
246     frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
247     if (args.length != 1) {
248         System.out.println("USAGE: java HTMLViewerDialog <URL>");
249         System.exit(69);
250     }
251     
252     try {
253         String JavaDoc url = args[0];
254         File file = new File(url);
255         if ( file.exists() )
256         url = "file:"+file.getAbsolutePath();
257         System.out.println("URL: `"+url+"'");
258         HTMLViewerDialog dialog =
259         new HTMLViewerDialog( frame, "HTMLViewerDialog", url );
260         HTMLViewerPane viewer = dialog.getHTMLViewerPane();
261         // viewer.setBackButtonIcon( new ImageIcon( "images/my-back.gif" ));
262
// viewer.setNextButtonIcon( new ImageIcon( "images/my-forward.gif" ));
263
dialog.show();
264     }
265     catch (IOException e) {
266         System.out.println(e);
267         System.exit(69);
268     }
269     System.exit(0);
270     }
271
272
273
274
275 }
276
277 // fini
278
Popular Tags