/
GRApplet.java
140 lines (112 loc) · 4.03 KB
/
GRApplet.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
package com.gallery.GalleryRemote;
import com.gallery.GalleryRemote.util.DialogUtil;
import com.gallery.GalleryRemote.util.ImageUtils;
import com.gallery.GalleryRemote.model.Gallery;
import javax.swing.*;
import java.applet.Applet;
import java.io.FilePermission;
import java.net.URL;
import java.net.MalformedURLException;
import HTTPClient.CookieModule;
import HTTPClient.Cookie;
/**
* Created by IntelliJ IDEA.
* User: paour
* Date: Oct 30, 2003
*/
public class GRApplet extends JApplet {
public static final String MODULE = "GRApplet";
protected JLabel jLabel;
boolean hasStarted = false;
String coreClass = "com.gallery.GalleryRemote.GalleryRemoteMainFrame";
public void init() {
System.out.println("Applet init");
}
public void start() {
System.out.println("Applet start");
initGalleryRemote();
if (hasStarted) {
GalleryRemote._().initializeGR();
initUI();
new Thread() {
public void run() {
GalleryRemote._().runGR();
}
}.start();
} else {
initDummyUI();
}
}
protected void initUI() {
jLabel = new JLabel("<HTML><CENTER>The Gallery Remote applet is running. Please don't close this window or navigate away!</CENTER></HTML>");
getContentPane().add(jLabel);
}
protected void initDummyUI() {
jLabel = new JLabel("<HTML><CENTER>The Gallery Remote applet is not running because another is running in the same browser</CENTER></HTML>");
getContentPane().add(jLabel);
}
protected void initGalleryRemote() {
if (! GalleryRemote.createInstance(coreClass, this)) {
JOptionPane.showMessageDialog(DialogUtil.findParentWindow(this),
"Only one instance of the Gallery Remote can run at the same time...",
"Error", JOptionPane.ERROR_MESSAGE);
} else {
hasStarted = true;
}
}
public void stop() {
System.out.println("Applet stop");
// don't shutdown the applet if it didn't start...
if (hasStarted && GalleryRemote._() != null) {
GalleryRemote._().getCore().shutdown();
}
ImageUtils.purgeTemp();
Log.log(Log.LEVEL_INFO, MODULE, "Shutting down log");
Log.shutdown();
}
public void hasShutdown() {
jLabel.setText("<HTML><CENTER>The Gallery Remote applet has stopped, you can navigate away or close the window</CENTER></HTML>");
}
protected AppletInfo getGRAppletInfo() {
AppletInfo info = new AppletInfo();
info.gallery = new Gallery(GalleryRemote._().getCore().getMainStatusUpdate());
String url = getParameter("gr_url");
String cookieName = getParameter("gr_cookie_name");
String cookieValue = getParameter("gr_cookie_value");
String cookieDomain = getParameter("gr_cookie_domain");
String cookiePath = getParameter("gr_cookie_path");
info.albumName = getParameter("gr_album");
Log.log(Log.LEVEL_TRACE, MODULE, "Applet parameters:");
Log.log(Log.LEVEL_TRACE, MODULE, "gr_url:" + url);
Log.log(Log.LEVEL_TRACE, MODULE, "gr_cookie_name:" + cookieName);
Log.log(Log.LEVEL_TRACE, MODULE, "gr_cookie_domain:" + cookieDomain);
Log.log(Log.LEVEL_TRACE, MODULE, "gr_cookie_path:" + cookiePath);
Log.log(Log.LEVEL_TRACE, MODULE, "gr_album:" + info.albumName);
if (cookieDomain == null || cookieDomain.length() < 1) {
try {
cookieDomain = new URL(url).getHost();
} catch (MalformedURLException e) {
//Log.logException(Log.LEVEL_ERROR, MODULE, e);
URL documentBase = getDocumentBase();
cookieDomain = documentBase.getHost();
Log.log(Log.LEVEL_INFO, MODULE, "URL probably doesn't have a host part because the Gallery " +
"is in (unsupported) relative mode. Using the Applet documentBase: " + cookieDomain);
try {
url = new URL(documentBase.getProtocol(), documentBase.getHost(), documentBase.getPort(),
url).toString();
} catch (MalformedURLException e1) {
Log.logException(Log.LEVEL_ERROR, MODULE, e1);
}
}
}
info.gallery.setType(Gallery.TYPE_STANDALONE);
info.gallery.setStUrlString(url);
info.gallery.cookieLogin = true;
CookieModule.addCookie(new Cookie(cookieName, cookieValue, cookieDomain, cookiePath, null, false));
return info;
}
class AppletInfo {
String albumName;
Gallery gallery;
}
}