forked from cravxx/unfm2jg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DesktopContext.java
140 lines (127 loc) · 3.39 KB
/
DesktopContext.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
import java.applet.Applet;
import java.applet.AppletContext;
import java.applet.AudioClip;
import java.awt.*;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.*;
import java.util.List;
// import sun.applet.AppletAudioClip;
/**
* An implementation of <code>AppletContext</code>, optimized for desktop apps. It's not complete though, only the methods needed by Nfm2 are implemented.
*
* @author DragShot
*/
class DesktopContext implements AppletContext, Runnable {
private final List<DesktopSoundClip> clips = Collections.synchronizedList(new LinkedList<DesktopSoundClip>());
private Thread clipper;
/**
* Small procedure to close the unused audio lines.
*/
@Override
public void run() {
while (true) {
clips.forEach(DesktopSoundClip::checkopen);
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
}
}
}
@Override
/**
* @inheritdoc
*/
public AudioClip getAudioClip(URL url) {
try {
InputStream in = url.openStream();
int size = in.available();
int read;
byte[] buffer = new byte[size];
while (size > 0) {
read = in.read(buffer, 0, size);
size -= read;
}
in.close();
DesktopSoundClip clip = new DesktopSoundClip(buffer);
clips.add(clip);
if (clipper == null) {
clipper = new Thread(this, "Clip stopper service");
clipper.start();
}
return clip;
} catch (Exception ex) {
}
return new DesktopSoundClip();
// return new AppletAudioClip(url);
}
@Override
/**
* @inheritdoc
*/
public Image getImage(URL url) {
return Toolkit.getDefaultToolkit().getImage(url);
}
@Override
/**
* This method is not implemented.
*/
public Applet getApplet(String name) {
throw new UnsupportedOperationException("Not supported.");
}
@Override
/**
* This method is not implemented.
*/
public Enumeration<Applet> getApplets() {
throw new UnsupportedOperationException("Not supported.");
}
@Override
/**
* @inheritdoc
*/
public void showDocument(URL url) {
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(url.toURI());
} catch (Exception ex) {
}
}
}
@Override
/**
* @inheritdoc
*/
public void showDocument(URL url, String target) {
showDocument(url);
}
/**
* This method is not implemented.
*/
@Override
public void showStatus(String status) {
/* empty */
}
/**
* This method is not implemented.
*/
@Override
public void setStream(String key, InputStream stream) throws IOException {
throw new UnsupportedOperationException("Not supported.");
}
/**
* This method is not implemented.
*/
@Override
public InputStream getStream(String key) {
throw new UnsupportedOperationException("Not supported.");
}
/**
* This method is not implemented.
*/
@Override
public Iterator<String> getStreamKeys() {
throw new UnsupportedOperationException("Not supported.");
}
}