Source code: dtk/gui/TKHtmlDocumentWindow.java
1 //Title: D3E ToolKit
2 //Version:
3 //Copyright: See accompanying license agreement
4 //Author: John Weatherley
5 //Company:
6 //Description: D3E Toolkit
7
8 package dtk.gui;
9
10 import dtk.core.*;
11 import javax.swing.*;
12 import javax.swing.event.*;
13 import javax.swing.text.*;
14 import javax.swing.text.html.*;
15 import javax.swing.border.*;
16 import javax.swing.colorchooser.*;
17 import javax.swing.filechooser.*;
18 import javax.accessibility.*;
19
20 import java.awt.*;
21 import java.awt.event.*;
22 import java.beans.*;
23 import java.util.*;
24 import java.io.*;
25 import java.net.*;
26
27 /**
28 This class provides a window that displays an HTML Document. Is used to
29 display the input file and output files.
30 */
31 class TKHtmlDocumentWindow extends TKHtmlWindow {
32
33 /**
34 Construct a document window to display HTML. If
35 no frame is passed in, a frame will also be created
36 to display the document in.
37
38 @param owner The frame that will hold this HTML document.
39 If null then a frame will be created.
40 @param title The title appearin on the frame's window.
41 @param w Window width.
42 @param h Window height.
43 @param resizable True = window can be resized, false = window not resizable.
44 @param fileDisplayed The HTML or TXT file to be displayed.
45 */
46 TKHtmlDocumentWindow(Frame owner, // Can be null
47 String title,
48 int w, int h,
49 boolean resizable,
50 String fileDisplayed)
51 {
52 super(owner,title,w,h,resizable,fileDisplayed);
53 }
54
55 /**
56 Get the location of the main frame on screen and show this HTML
57 window at a slight offset from that location.
58 */
59 public void show(){
60 Point p = TKToolkit.frame.getLocationOnScreen();
61 setLocation((int)(p.getX()+40),(int)(p.getY()+40));
62 super.show();
63 }
64
65 /**
66 Set the page displayed in this window.
67 */
68 public void setPage(String f){
69 String fullPath = System.getProperty("user.dir") + System.getProperty("file.separator") + f;
70
71 try {
72 // First check if the direct path is correct:
73 if(new File(fullPath).exists()) {
74 theURL = new URL("file:" + fullPath);
75 }
76 else if ( new File(f).exists() ) {
77
78 theURL = new URL("file:" + f);
79 }
80 else {
81
82 // Grab the url path inside jar file:
83 theURL = getClass().getResource(f);
84 }
85 } catch (Exception e) {
86 System.err.println("Couldn't find the following file: " + f);
87 }
88
89 try{
90 htmlPane.setPage(theURL);
91 } catch(IOException ioe) {
92 TKLog.error("Couldn't find the following file (URL): " + theURL + ". Reason: " + ioe);
93 }
94 }
95 }
96
97
98