1 15 16 18 36 package ixenon.free.swing; 37 38 import java.awt.*; 39 import java.awt.event.*; 40 import java.util.*; 41 import java.io.*; import java.net.*; 44 import javax.swing.*; import javax.swing.event.*; import javax.swing.border.*; import javax.swing.text.*; 49 50 51 60 public class HTMLViewerDialog extends JDialog 61 implements ActionListener, WindowListener 62 { 63 64 public final static String DEFAULT_APPROVE_TEXT="Close"; 65 66 public final static String DEFAULT_APPROVE_TOOLTIP_TEXT="dispose dialog"; 67 68 69 70 protected JButton bt_approve; 71 72 73 protected HTMLViewerPane htmlPane; 74 75 80 public HTMLViewerDialog( Frame frame, String title) 81 { 82 super( frame, title, true ); 83 84 initialise( frame, title, DEFAULT_APPROVE_TEXT ); 85 } 86 87 93 public HTMLViewerDialog( Frame frame, String title, String url ) 94 throws IOException 95 { 96 this(frame, title, url, DEFAULT_APPROVE_TEXT ); 97 } 98 99 106 public HTMLViewerDialog( Frame frame, String title, 107 String url, String approveText ) 108 throws IOException 109 { 110 super( frame, title, true ); 111 initialise( frame, title, approveText ); 112 setPage(url); 113 } 114 115 protected void initialise( Frame frame, String title, String 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 htmlPane = new HTMLViewerPane(); 134 getContentPane().add( htmlPane, BorderLayout.CENTER ); 135 136 addWindowListener(this); 137 pack(); 138 } 139 140 141 public HTMLViewerPane getHTMLViewerPane() 142 { 143 return (htmlPane); 144 } 145 146 147 public URL getPage() 148 { 149 return htmlPane.getPage(); 150 } 151 152 153 public void setPage( URL url ) 154 throws IOException 155 { 156 htmlPane.setPage( url ); 157 } 158 159 160 public void setPage( String url ) 161 throws IOException 162 { 163 htmlPane.setPage( url ); 164 } 165 166 167 public boolean isBrowsable() 168 { 169 return htmlPane.isBrowsable(); 170 } 171 172 173 public void setBrowsable( boolean flag ) 174 { 175 htmlPane.setBrowsable(flag); 176 } 177 178 179 public String getContentType() 180 { 181 return htmlPane.getContentType(); 182 } 183 184 185 public void setContentType( String contentType ) 186 throws IOException 187 { 188 htmlPane.setContentType( contentType ); 189 } 190 191 192 public JButton getApproveButton() 193 { 194 return bt_approve; 195 } 196 197 198 public String getApproveButtonText() 199 { 200 return bt_approve.getText(); 201 } 202 203 204 public void setApproveButtonText( String text ) 205 { 206 bt_approve.setText(text); 207 } 208 209 210 public String getApproveButtonToolTipText() 211 { 212 return bt_approve.getToolTipText(); 213 } 214 215 216 public void setApproveButtonToolTipText( String tooltip_text ) 217 { 218 bt_approve.setToolTipText(tooltip_text); 219 } 220 221 222 226 public void actionPerformed( ActionEvent e ) 227 { 228 Object 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 [] 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 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 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 | Popular Tags |