Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/demo/share/jfc/SwingSet2/HtmlDemo.java
41152 views
1
/*
2
*
3
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
8
*
9
* - Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
*
12
* - Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in the
14
* documentation and/or other materials provided with the distribution.
15
*
16
* - Neither the name of Oracle nor the names of its
17
* contributors may be used to endorse or promote products derived
18
* from this software without specific prior written permission.
19
*
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
*/
32
33
34
import javax.swing.*;
35
import javax.swing.event.*;
36
import javax.swing.text.*;
37
import javax.swing.text.html.*;
38
import javax.swing.border.*;
39
import javax.swing.colorchooser.*;
40
import javax.swing.filechooser.*;
41
import javax.accessibility.*;
42
43
import java.awt.*;
44
import java.awt.event.*;
45
import java.beans.*;
46
import java.util.*;
47
import java.io.*;
48
import java.applet.*;
49
import java.net.*;
50
51
/**
52
* Html Demo
53
*
54
* @author Jeff Dinkins
55
*/
56
public class HtmlDemo extends DemoModule {
57
58
JEditorPane html;
59
60
/**
61
* main method allows us to run as a standalone demo.
62
*/
63
public static void main(String[] args) {
64
HtmlDemo demo = new HtmlDemo(null);
65
demo.mainImpl();
66
}
67
68
/**
69
* HtmlDemo Constructor
70
*/
71
public HtmlDemo(SwingSet2 swingset) {
72
// Set the title for this demo, and an icon used to represent this
73
// demo inside the SwingSet2 app.
74
super(swingset, "HtmlDemo", "toolbar/JEditorPane.gif");
75
76
try {
77
URL url = null;
78
// System.getProperty("user.dir") +
79
// System.getProperty("file.separator");
80
String path = null;
81
try {
82
path = "/resources/index.html";
83
url = getClass().getResource(path);
84
} catch (Exception e) {
85
System.err.println("Failed to open " + path);
86
url = null;
87
}
88
89
if(url != null) {
90
html = new JEditorPane(url);
91
html.setEditable(false);
92
html.addHyperlinkListener(createHyperLinkListener());
93
94
JScrollPane scroller = new JScrollPane();
95
JViewport vp = scroller.getViewport();
96
vp.add(html);
97
getDemoPanel().add(scroller, BorderLayout.CENTER);
98
}
99
} catch (MalformedURLException e) {
100
System.out.println("Malformed URL: " + e);
101
} catch (IOException e) {
102
System.out.println("IOException: " + e);
103
}
104
}
105
106
public HyperlinkListener createHyperLinkListener() {
107
return new HyperlinkListener() {
108
public void hyperlinkUpdate(HyperlinkEvent e) {
109
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
110
if (e instanceof HTMLFrameHyperlinkEvent) {
111
((HTMLDocument)html.getDocument()).processHTMLFrameHyperlinkEvent(
112
(HTMLFrameHyperlinkEvent)e);
113
} else {
114
try {
115
html.setPage(e.getURL());
116
} catch (IOException ioe) {
117
System.out.println("IOE: " + ioe);
118
}
119
}
120
}
121
}
122
};
123
}
124
125
void updateDragEnabled(boolean dragEnabled) {
126
html.setDragEnabled(dragEnabled);
127
}
128
129
}
130
131