-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPageDisplay.java
68 lines (60 loc) · 1.37 KB
/
PageDisplay.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.io.File;
import java.io.IOException;
import javax.swing.JEditorPane;
/**
*
* @author Victoria
*
* JEditorPane that displays loaded HTML Page
*
*/
@SuppressWarnings("serial")
public class PageDisplay extends JEditorPane {
private File file;
/**
* Set and display HTML page
*
* @param file page to be loaded
*/
public PageDisplay(File file) {
updateFile(file);
setEditable(false); // so that no weird things appear on the screen (set to true to see a funny html page)
}
/**
* Sets new page to be displayed
* @param file new page to be displayed
*/
public void updateFile(File file) {
this.file = file;
displayFromFile();
}
/**
* Displays HTML page or gives error screen if file cannot be loaded
* Prompts to choose a file if file is null
*/
public void displayFromFile() {
if (file == null) {
setContentType("text/html");
setText("<html><h1>Please select a HTML file to load<h1></html>");
return;
}
try {
setPage(file.toURI().toURL());
} catch (IOException e) {
errorPage();
}
}
/**
* Displays HTML page from code in editor pane
*
* @param code code to read to display
*/
public void displayFromEditor(String code) {
setContentType("text/html");
setText(code);
}
public void errorPage() {
setContentType("text/html");
setText("<html><h1>Error!<h1><h2>Page could not load<h2></html>");
}
}