propane 3.4.0-java → 3.4.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.mvn/extensions.xml +1 -2
- data/.travis.yml +2 -2
- data/CHANGELOG.md +2 -0
- data/README.md +12 -7
- data/Rakefile +2 -2
- data/lib/propane.rb +2 -2
- data/lib/propane/app.rb +18 -9
- data/lib/propane/helper_methods.rb +1 -1
- data/lib/propane/runner.rb +1 -1
- data/lib/propane/version.rb +1 -1
- data/library/color_group/color_group.rb +26 -0
- data/library/dxf/dxf.rb +4 -0
- data/library/net/net.rb +5 -0
- data/library/video_event/video_event.rb +2 -1
- data/pom.rb +3 -3
- data/pom.xml +3 -3
- data/propane.gemspec +1 -1
- data/src/main/java/japplemenubar/JAppleMenuBar.java +3 -3
- data/src/main/java/monkstone/ColorUtil.java +14 -0
- data/src/main/java/monkstone/MathToolModule.java +243 -194
- data/src/main/java/monkstone/filechooser/Chooser.java +1 -0
- data/src/main/java/monkstone/slider/WheelHandler.java +6 -5
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +3 -2
- data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
- data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +10 -26
- data/src/main/java/processing/awt/PSurfaceAWT.java +1 -1
- data/src/main/java/processing/core/PApplet.java +1236 -599
- data/src/main/java/processing/core/PGraphics.java +59 -59
- data/src/main/java/processing/core/PImage.java +528 -129
- data/src/main/java/processing/core/PShape.java +10 -10
- data/src/main/java/processing/core/PVector.java +2 -2
- data/src/main/java/processing/core/ThinkDifferent.java +5 -7
- data/src/main/java/processing/dxf/RawDXF.java +404 -0
- data/src/main/java/processing/net/Client.java +744 -0
- data/src/main/java/processing/net/Server.java +388 -0
- data/src/main/java/processing/opengl/FontTexture.java +19 -20
- data/src/main/java/processing/opengl/FrameBuffer.java +27 -17
- data/src/main/java/processing/opengl/LinePath.java +512 -508
- data/src/main/java/processing/opengl/PGL.java +3106 -3066
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +4 -4
- data/src/main/java/processing/opengl/PShader.java +1442 -1341
- data/vendors/Rakefile +3 -27
- metadata +12 -25
- data/src/main/java/processing/core/util/image/ImageLoadFacade.java +0 -161
- data/src/main/java/processing/core/util/image/ImageSaveFacade.java +0 -169
- data/src/main/java/processing/core/util/image/constants/TifConstants.java +0 -45
- data/src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java +0 -80
- data/src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java +0 -73
- data/src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java +0 -70
- data/src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java +0 -132
- data/src/main/java/processing/core/util/image/load/ImageLoadStrategy.java +0 -48
- data/src/main/java/processing/core/util/image/load/ImageLoadUtil.java +0 -45
- data/src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java +0 -255
- data/src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java +0 -98
- data/src/main/java/processing/core/util/image/save/ImageSaveStrategy.java +0 -49
- data/src/main/java/processing/core/util/image/save/ImageSaveUtil.java +0 -48
- data/src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java +0 -179
- data/src/main/java/processing/core/util/image/save/SaveImageException.java +0 -41
- data/src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java +0 -198
- data/src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java +0 -91
- data/src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java +0 -57
- data/src/main/java/processing/core/util/io/InputFactory.java +0 -285
- data/src/main/java/processing/core/util/io/PathUtil.java +0 -109
@@ -0,0 +1,388 @@
|
|
1
|
+
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
2
|
+
|
3
|
+
/*
|
4
|
+
Server - basic network server implementation
|
5
|
+
Part of the Processing project - http://processing.org
|
6
|
+
|
7
|
+
Copyright (c) 2004-2007 Ben Fry and Casey Reas
|
8
|
+
The previous version of this code was developed by Hernando Barragan
|
9
|
+
|
10
|
+
This library is free software; you can redistribute it and/or
|
11
|
+
modify it under the terms of the GNU Lesser General Public
|
12
|
+
License as published by the Free Software Foundation; either
|
13
|
+
version 2.1 of the License, or (at your option) any later version.
|
14
|
+
|
15
|
+
This library is distributed in the hope that it will be useful,
|
16
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
18
|
+
Lesser General Public License for more details.
|
19
|
+
|
20
|
+
You should have received a copy of the GNU Lesser General
|
21
|
+
Public License along with this library; if not, write to the
|
22
|
+
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
23
|
+
Boston, MA 02111-1307 USA
|
24
|
+
*/
|
25
|
+
|
26
|
+
package processing.net;
|
27
|
+
|
28
|
+
import processing.core.*;
|
29
|
+
|
30
|
+
import java.io.*;
|
31
|
+
import java.lang.reflect.*;
|
32
|
+
import java.net.*;
|
33
|
+
|
34
|
+
|
35
|
+
/**
|
36
|
+
* ( begin auto-generated from Server.xml )
|
37
|
+
*
|
38
|
+
* A server sends and receives data to and from its associated clients
|
39
|
+
* (other programs connected to it). When a server is started, it begins
|
40
|
+
* listening for connections on the port specified by the <b>port</b>
|
41
|
+
* parameter. Computers have many ports for transferring data and some are
|
42
|
+
* commonly used so be sure to not select one of these. For example, web
|
43
|
+
* servers usually use port 80 and POP mail uses port 110.
|
44
|
+
*
|
45
|
+
* ( end auto-generated )
|
46
|
+
* @webref net
|
47
|
+
* @usage application
|
48
|
+
* @brief The server class is used to create server objects which send and receives data to and from its associated clients (other programs connected to it).
|
49
|
+
* @instanceName server any variable of type Server
|
50
|
+
*/
|
51
|
+
public class Server implements Runnable {
|
52
|
+
PApplet parent;
|
53
|
+
Method serverEventMethod;
|
54
|
+
|
55
|
+
volatile Thread thread;
|
56
|
+
ServerSocket server;
|
57
|
+
int port;
|
58
|
+
|
59
|
+
protected final Object clientsLock = new Object[0];
|
60
|
+
/** Number of clients currently connected. */
|
61
|
+
public int clientCount;
|
62
|
+
/** Array of client objects, useful length is determined by clientCount. */
|
63
|
+
public Client[] clients;
|
64
|
+
|
65
|
+
|
66
|
+
/**
|
67
|
+
* @param parent typically use "this"
|
68
|
+
* @param port port used to transfer data
|
69
|
+
*/
|
70
|
+
public Server(PApplet parent, int port) {
|
71
|
+
this(parent, port, null);
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
/**
|
76
|
+
* @param parent typically use "this"
|
77
|
+
* @param port port used to transfer data
|
78
|
+
* @param host when multiple NICs are in use, the ip (or name) to bind from
|
79
|
+
*/
|
80
|
+
public Server(PApplet parent, int port, String host) {
|
81
|
+
this.parent = parent;
|
82
|
+
this.port = port;
|
83
|
+
|
84
|
+
try {
|
85
|
+
if (host == null) {
|
86
|
+
server = new ServerSocket(this.port);
|
87
|
+
} else {
|
88
|
+
server = new ServerSocket(this.port, 10, InetAddress.getByName(host));
|
89
|
+
}
|
90
|
+
//clients = new Vector();
|
91
|
+
clients = new Client[10];
|
92
|
+
|
93
|
+
thread = new Thread(this);
|
94
|
+
thread.start();
|
95
|
+
|
96
|
+
parent.registerMethod("dispose", this);
|
97
|
+
|
98
|
+
// reflection to check whether host applet has a call for
|
99
|
+
// public void serverEvent(Server s, Client c);
|
100
|
+
// which is called when a new guy connects
|
101
|
+
try {
|
102
|
+
serverEventMethod =
|
103
|
+
parent.getClass().getMethod("serverEvent", Server.class, Client.class);
|
104
|
+
} catch (Exception e) {
|
105
|
+
// no such method, or an error.. which is fine, just ignore
|
106
|
+
}
|
107
|
+
|
108
|
+
} catch (IOException e) {
|
109
|
+
//e.printStackTrace();
|
110
|
+
thread = null;
|
111
|
+
throw new RuntimeException(e);
|
112
|
+
//errorMessage("<init>", e);
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
|
117
|
+
/**
|
118
|
+
* ( begin auto-generated from Server_disconnect.xml )
|
119
|
+
*
|
120
|
+
* Disconnect a particular client.
|
121
|
+
*
|
122
|
+
* ( end auto-generated )
|
123
|
+
* @brief Disconnect a particular client.
|
124
|
+
* @webref server:server
|
125
|
+
* @param client the client to disconnect
|
126
|
+
*/
|
127
|
+
public void disconnect(Client client) {
|
128
|
+
client.stop();
|
129
|
+
synchronized (clientsLock) {
|
130
|
+
int index = clientIndex(client);
|
131
|
+
if (index != -1) {
|
132
|
+
removeIndex(index);
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
protected void removeIndex(int index) {
|
139
|
+
synchronized (clientsLock) {
|
140
|
+
clientCount--;
|
141
|
+
// shift down the remaining clients
|
142
|
+
for (int i = index; i < clientCount; i++) {
|
143
|
+
clients[i] = clients[i + 1];
|
144
|
+
}
|
145
|
+
// mark last empty var for garbage collection
|
146
|
+
clients[clientCount] = null;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
|
151
|
+
protected void disconnectAll() {
|
152
|
+
synchronized (clientsLock) {
|
153
|
+
for (int i = 0; i < clientCount; i++) {
|
154
|
+
try {
|
155
|
+
clients[i].stop();
|
156
|
+
} catch (Exception e) {
|
157
|
+
// ignore
|
158
|
+
}
|
159
|
+
clients[i] = null;
|
160
|
+
}
|
161
|
+
clientCount = 0;
|
162
|
+
}
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
protected void addClient(Client client) {
|
167
|
+
synchronized (clientsLock) {
|
168
|
+
if (clientCount == clients.length) {
|
169
|
+
clients = (Client[]) PApplet.expand(clients);
|
170
|
+
}
|
171
|
+
clients[clientCount++] = client;
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
protected int clientIndex(Client client) {
|
177
|
+
synchronized (clientsLock) {
|
178
|
+
for (int i = 0; i < clientCount; i++) {
|
179
|
+
if (clients[i] == client) {
|
180
|
+
return i;
|
181
|
+
}
|
182
|
+
}
|
183
|
+
return -1;
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
/**
|
189
|
+
* ( begin auto-generated from Server_active.xml )
|
190
|
+
*
|
191
|
+
* Returns true if this server is still active and hasn't run
|
192
|
+
* into any trouble.
|
193
|
+
*
|
194
|
+
* ( end auto-generated )
|
195
|
+
* @webref server:server
|
196
|
+
* @brief Return true if this server is still active.
|
197
|
+
*/
|
198
|
+
public boolean active() {
|
199
|
+
return thread != null;
|
200
|
+
}
|
201
|
+
|
202
|
+
|
203
|
+
static public String ip() {
|
204
|
+
try {
|
205
|
+
return InetAddress.getLocalHost().getHostAddress();
|
206
|
+
} catch (UnknownHostException e) {
|
207
|
+
e.printStackTrace();
|
208
|
+
return null;
|
209
|
+
}
|
210
|
+
}
|
211
|
+
|
212
|
+
|
213
|
+
// the last index used for available. can't just cycle through
|
214
|
+
// the clients in order from 0 each time, because if client 0 won't
|
215
|
+
// shut up, then the rest of the clients will never be heard from.
|
216
|
+
int lastAvailable = -1;
|
217
|
+
|
218
|
+
/**
|
219
|
+
* ( begin auto-generated from Server_available.xml )
|
220
|
+
*
|
221
|
+
* Returns the next client in line with a new message.
|
222
|
+
*
|
223
|
+
* ( end auto-generated )
|
224
|
+
* @brief Returns the next client in line with a new message.
|
225
|
+
* @webref server
|
226
|
+
* @usage application
|
227
|
+
*/
|
228
|
+
public Client available() {
|
229
|
+
synchronized (clientsLock) {
|
230
|
+
int index = lastAvailable + 1;
|
231
|
+
if (index >= clientCount) index = 0;
|
232
|
+
|
233
|
+
for (int i = 0; i < clientCount; i++) {
|
234
|
+
int which = (index + i) % clientCount;
|
235
|
+
Client client = clients[which];
|
236
|
+
//Check for valid client
|
237
|
+
if (!client.active()){
|
238
|
+
removeIndex(which); //Remove dead client
|
239
|
+
i--; //Don't skip the next client
|
240
|
+
//If the client has data make sure lastAvailable
|
241
|
+
//doesn't end up skipping the next client
|
242
|
+
which--;
|
243
|
+
//fall through to allow data from dead clients
|
244
|
+
//to be retreived.
|
245
|
+
}
|
246
|
+
if (client.available() > 0) {
|
247
|
+
lastAvailable = which;
|
248
|
+
return client;
|
249
|
+
}
|
250
|
+
}
|
251
|
+
}
|
252
|
+
return null;
|
253
|
+
}
|
254
|
+
|
255
|
+
|
256
|
+
/**
|
257
|
+
* ( begin auto-generated from Server_stop.xml )
|
258
|
+
*
|
259
|
+
* Disconnects all clients and stops the server.
|
260
|
+
*
|
261
|
+
* ( end auto-generated )
|
262
|
+
* <h3>Advanced</h3>
|
263
|
+
* Use this to shut down the server if you finish using it while your applet
|
264
|
+
* is still running. Otherwise, it will be automatically be shut down by the
|
265
|
+
* host PApplet using dispose(), which is identical.
|
266
|
+
* @brief Disconnects all clients and stops the server.
|
267
|
+
* @webref server
|
268
|
+
* @usage application
|
269
|
+
*/
|
270
|
+
public void stop() {
|
271
|
+
dispose();
|
272
|
+
}
|
273
|
+
|
274
|
+
|
275
|
+
/**
|
276
|
+
* Disconnect all clients and stop the server: internal use only.
|
277
|
+
*/
|
278
|
+
public void dispose() {
|
279
|
+
thread = null;
|
280
|
+
|
281
|
+
if (clients != null) {
|
282
|
+
disconnectAll();
|
283
|
+
clientCount = 0;
|
284
|
+
clients = null;
|
285
|
+
}
|
286
|
+
|
287
|
+
try {
|
288
|
+
if (server != null) {
|
289
|
+
server.close();
|
290
|
+
server = null;
|
291
|
+
}
|
292
|
+
} catch (IOException e) {
|
293
|
+
e.printStackTrace();
|
294
|
+
}
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
@Override
|
299
|
+
public void run() {
|
300
|
+
while (Thread.currentThread() == thread) {
|
301
|
+
try {
|
302
|
+
Socket socket = server.accept();
|
303
|
+
Client client = new Client(parent, socket);
|
304
|
+
synchronized (clientsLock) {
|
305
|
+
addClient(client);
|
306
|
+
if (serverEventMethod != null) {
|
307
|
+
try {
|
308
|
+
serverEventMethod.invoke(parent, this, client);
|
309
|
+
} catch (Exception e) {
|
310
|
+
System.err.println("Disabling serverEvent() for port " + port);
|
311
|
+
Throwable cause = e;
|
312
|
+
// unwrap the exception if it came from the user code
|
313
|
+
if (e instanceof InvocationTargetException && e.getCause() != null) {
|
314
|
+
cause = e.getCause();
|
315
|
+
}
|
316
|
+
cause.printStackTrace();
|
317
|
+
serverEventMethod = null;
|
318
|
+
}
|
319
|
+
}
|
320
|
+
}
|
321
|
+
} catch (SocketException e) {
|
322
|
+
//thrown when server.close() is called and server is waiting on accept
|
323
|
+
System.err.println("Server SocketException: " + e.getMessage());
|
324
|
+
thread = null;
|
325
|
+
} catch (IOException e) {
|
326
|
+
//errorMessage("run", e);
|
327
|
+
e.printStackTrace();
|
328
|
+
thread = null;
|
329
|
+
}
|
330
|
+
}
|
331
|
+
}
|
332
|
+
|
333
|
+
|
334
|
+
/**
|
335
|
+
* ( begin auto-generated from Server_write.xml )
|
336
|
+
*
|
337
|
+
* Writes a value to all the connected clients. It sends bytes out from the
|
338
|
+
* Server object.
|
339
|
+
*
|
340
|
+
* ( end auto-generated )
|
341
|
+
* @webref server
|
342
|
+
* @brief Writes data to all connected clients
|
343
|
+
* @param data data to write
|
344
|
+
*/
|
345
|
+
public void write(int data) { // will also cover char
|
346
|
+
synchronized (clientsLock) {
|
347
|
+
int index = 0;
|
348
|
+
while (index < clientCount) {
|
349
|
+
if (clients[index].active()) {
|
350
|
+
clients[index].write(data);
|
351
|
+
index++;
|
352
|
+
} else {
|
353
|
+
removeIndex(index);
|
354
|
+
}
|
355
|
+
}
|
356
|
+
}
|
357
|
+
}
|
358
|
+
|
359
|
+
|
360
|
+
public void write(byte data[]) {
|
361
|
+
synchronized (clientsLock) {
|
362
|
+
int index = 0;
|
363
|
+
while (index < clientCount) {
|
364
|
+
if (clients[index].active()) {
|
365
|
+
clients[index].write(data);
|
366
|
+
index++;
|
367
|
+
} else {
|
368
|
+
removeIndex(index);
|
369
|
+
}
|
370
|
+
}
|
371
|
+
}
|
372
|
+
}
|
373
|
+
|
374
|
+
|
375
|
+
public void write(String data) {
|
376
|
+
synchronized (clientsLock) {
|
377
|
+
int index = 0;
|
378
|
+
while (index < clientCount) {
|
379
|
+
if (clients[index].active()) {
|
380
|
+
clients[index].write(data);
|
381
|
+
index++;
|
382
|
+
} else {
|
383
|
+
removeIndex(index);
|
384
|
+
}
|
385
|
+
}
|
386
|
+
}
|
387
|
+
}
|
388
|
+
}
|
@@ -72,9 +72,9 @@ class FontTexture implements PConstants {
|
|
72
72
|
}
|
73
73
|
|
74
74
|
protected void dispose() {
|
75
|
-
|
76
|
-
|
77
|
-
|
75
|
+
for (Texture texture : textures) {
|
76
|
+
texture.dispose();
|
77
|
+
}
|
78
78
|
}
|
79
79
|
|
80
80
|
protected void initTexture(PGraphicsOpenGL pg, PFont font) {
|
@@ -97,7 +97,7 @@ class FontTexture implements PConstants {
|
|
97
97
|
offsetY = 0;
|
98
98
|
lineHeight = 0;
|
99
99
|
|
100
|
-
texinfoMap = new HashMap
|
100
|
+
texinfoMap = new HashMap<>();
|
101
101
|
glyphTexinfos = new TextureInfo[font.getGlyphCount()];
|
102
102
|
addAllGlyphsToTexture(pg, font);
|
103
103
|
}
|
@@ -173,9 +173,9 @@ class FontTexture implements PConstants {
|
|
173
173
|
}
|
174
174
|
|
175
175
|
public void end() {
|
176
|
-
|
177
|
-
|
178
|
-
|
176
|
+
for (Texture texture : textures) {
|
177
|
+
pgl.disableTexturing(texture.glTarget);
|
178
|
+
}
|
179
179
|
}
|
180
180
|
|
181
181
|
public PImage getTexture(TextureInfo info) {
|
@@ -191,13 +191,12 @@ class FontTexture implements PConstants {
|
|
191
191
|
}
|
192
192
|
|
193
193
|
public void updateGlyphsTexCoords() {
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
tinfo.updateUV();
|
199
|
-
}
|
194
|
+
// loop over current glyphs.
|
195
|
+
for (TextureInfo tinfo : glyphTexinfos) {
|
196
|
+
if (tinfo != null && tinfo.texIndex == lastTex) {
|
197
|
+
tinfo.updateUV();
|
200
198
|
}
|
199
|
+
}
|
201
200
|
}
|
202
201
|
|
203
202
|
public TextureInfo getTexInfo(PFont.Glyph glyph) {
|
@@ -216,15 +215,15 @@ class FontTexture implements PConstants {
|
|
216
215
|
|
217
216
|
public boolean contextIsOutdated() {
|
218
217
|
boolean outdated = false;
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
}
|
218
|
+
for (Texture texture : textures) {
|
219
|
+
if (texture.contextIsOutdated()) {
|
220
|
+
outdated = true;
|
223
221
|
}
|
222
|
+
}
|
224
223
|
if (outdated) {
|
225
|
-
|
226
|
-
|
227
|
-
|
224
|
+
for (Texture texture : textures) {
|
225
|
+
texture.dispose();
|
226
|
+
}
|
228
227
|
}
|
229
228
|
return outdated;
|
230
229
|
}
|