-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWrApp.java
235 lines (205 loc) · 6.65 KB
/
WrApp.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import java.applet.Applet;
import java.awt.Image;
import java.awt.Graphics;
import java.awt.Frame;
import java.awt.Component;
import java.awt.Color;
import java.awt.Event;
import java.awt.event.*;
import java.net.URL;
import java.awt.image.*;
import java.util.StringTokenizer;
//import java.awt.*;
//import java.io.*;
/**
* WrApp wrapper class for all Durius applets.
*
* @author Robert Bögniel.
*/
public class WrApp extends Applet implements Runnable, MouseListener, MouseMotionListener {
Thread kicker;
DirectColorModel dcm;
MemoryImageSource mis;
Image img;
static final String strLoading = "Applet initializing.", strProtocol = "file";
String s, strBrokenImageName;
private long lngStart;
private long lngEnd;
static long lngFPS = 1000/50;
private boolean running = true;
boolean boolInitialized = false, boolImageError = false;
protected int intBackgroundColor, intAppletWidth, intAppletHeight, intAppKey;
private URL urlDurius, urlThis;
private String urlTarget[];
private StringTokenizer tokURL;
private int intButtonCount, intRegcode, intOrientation;
private String strFrame = "";
protected Graphics gfx;
public void init()
{
try { urlThis = getDocumentBase(); } catch(Exception e) {};
try { urlDurius = new URL("http://www.durius.com/"); } catch(Exception e) { };
addMouseListener(this);
addMouseMotionListener(this);
s = getParameter("bg");
if (s != null) {
intBackgroundColor = Integer.valueOf(s,16).intValue();
setBackground( new Color(intBackgroundColor) );
} else setBackground(new Color(0,0,0));
// Default settings
intRegcode = 1; intButtonCount = 0; intOrientation = 0;
s = getParameter("width"); if (s != null) intAppletWidth = Integer.parseInt(s);
s = getParameter("height"); if (s != null) intAppletHeight = Integer.parseInt(s);
s = getParameter("orientation"); if(s != null) intOrientation = (s.toLowerCase().compareTo("v")) == 0 ? 0 : 1;
/*
* URL forming
*/
s = getParameter("url");
if (s != null && s.length() > 1) {
tokURL = new StringTokenizer(s);
urlTarget = new String[tokURL.countTokens()];
}
s = getParameter("target"); if (s != null) strFrame = s;
if(tokURL != null) {
this.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
while (tokURL.hasMoreTokens()) {
s = tokURL.nextToken();
String ustring = s;
s = s.toLowerCase();
// String strPort = "";
// if(urlThis.getPort() > 1)
// strPort = ":" +strPort.valueOf(urlThis.getPort);
if (s.startsWith("/")) ustring = urlThis.getProtocol().toString() + urlThis.getHost().toString() + ustring;
else if (s.startsWith("mailto:")) {;}
else if (s.startsWith("javascript:")) {;}
else if (s.startsWith("http://")) {;}
else if (s.startsWith("https://")) {;}
else if (s.startsWith(".")) { ustring = urlThis.toString().substring(0,urlThis.toString().lastIndexOf("/")+1) + ustring;}
else if ((s.startsWith("/") == false) && (s.startsWith("javascript:") == false)) { ustring = urlThis.toString().substring(0,urlThis.toString().lastIndexOf("/")+1) + ustring;}
urlTarget[intButtonCount] = ustring;
intButtonCount++;
}
}
gfx = getGraphics();
kicker = new Thread(this);
kicker.setPriority(Thread.MAX_PRIORITY);
kicker.start();
}
public final void mouseClicked(MouseEvent e) {
int x = e.getX();
int y = e.getY();
navigate(getURL(x, y));
}
// Navigate a hyperlink
public final void navigate(String url)
{
if(url.startsWith("javascript:"))
{
executeJavascriptCommand(url);
return;
}
try
{
if(strFrame != "")
{
getAppletContext().showDocument(new URL(url), strFrame);
}
else
{
getAppletContext().showDocument(new URL(url));
}
} catch(Exception e) {}
}
// Rather than checking the browser vendor to determine what action
// to take, we test for the presence of the JSObject class.
final private void executeJavascriptCommand(String s)
{
/* Class jsObjectClass;
try {
jsObjectClass = Class.forName("netscape.javascript.JSObject");
} catch(ClassNotFoundException e) {
jsObjectClass = null;
}
if(jsObjectClass != null) {
try {
netscape.javascript.JSObject window;
window = netscape.javascript.JSObject.getWindow(this);
//window = (netscape.javascript.JSObject)window.getMember("top");
window.eval(s.substring(11,s.length()));
} catch(Exception shite) { }
}
else {
try {
getAppletContext().showDocument(new URL(s));
} catch(Exception shite2) { }
}
*/
}
public void mouseEntered(MouseEvent e) {
if(intButtonCount != 0)
showStatus(getURL(e.getX(),e.getY()));
}
public void mouseMoved(MouseEvent e) {
if(intButtonCount != 0)
showStatus(getURL(e.getX(),e.getY()));
if(boolImageError) {
String imageerror = new String(urlThis.toString());
imageerror = imageerror.substring(0, (imageerror.lastIndexOf("/")));
showStatus("Image '" + imageerror + "/" + strBrokenImageName + "' not found!");
}
}
public void render() {}
public void mouseExited(MouseEvent e) {/* showStatus("") ;*/ }
public void mousePressed(MouseEvent e) {};
public void mouseDragged(MouseEvent e) {};
public void mouseReleased(MouseEvent e) {};
public final void paint(Graphics g) { }
public final void update(Graphics g) { }
public final void run() {
while (kicker!=null && running) {
if(boolInitialized) {
lngStart = System.currentTimeMillis();
render();
lngEnd = System.currentTimeMillis();
long lngSleep = lngFPS-(lngEnd - lngStart);
try {
if(lngSleep > 1) {
kicker.sleep(lngSleep);
// showStatus(Long.toString(lngSleep));
} else {
kicker.sleep(5);
// showStatus(Long.toString(lngSleep));
}
} catch(Exception e) { ; }
} else {
try {
Thread.sleep(100);
} catch(Exception e) {}
}
}
}
public final void start() { }
public final void stop() {
if ( kicker != null ) {
running = false;
try {
kicker.join ( 1000 );
} catch ( Exception e ) { }
kicker = null;
}
}
public final String getAppletInfo() { return "(c) Durius http://www.durius.com/"; }
private final String getURL(int x,int y) {
try {
if(intButtonCount >= 1) {
if(intOrientation == 0)
return urlTarget[Math.min(intButtonCount-1,(int)((double)y/(intAppletHeight/intButtonCount)))];
else
return urlTarget[Math.min(intButtonCount-1,(int)((double)x/(intAppletWidth/intButtonCount)))];
} else return "";
} catch (Exception e) {
return "";
}
}
/* End Wrapper */
}