MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / CallBack

Class CallBack

CodenameOne/src/com/codename1/capture/Capture.java:372–429  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

370 }
371
372 static class CallBack implements ActionListener<ActionEvent>, Runnable {
373 String url;
374 // We need volatile due to the usage of double locking optimization
375 @SuppressWarnings("PMD.AvoidUsingVolatile")
376 private volatile boolean completed;
377 private int targetWidth = -1;
378 private int targetHeight = -1;
379
380 @Override
381 public void actionPerformed(ActionEvent evt) {
382 if (evt == null) {
383 url = null;
384 } else {
385 url = (String) evt.getSource();
386 }
387 synchronized (this) {
388 completed = true;
389 this.notifyAll();
390 }
391 }
392
393 @Override
394 public void run() {
395 while (!completed) {
396 synchronized (this) {
397 try {
398 // we need to recheck the condition within the synchronized block (double locking)
399 if (!completed) {
400 this.wait();
401 }
402 } catch (InterruptedException ex) {
403 }
404 }
405 }
406 if (url == null) {
407 return;
408 }
409 if (targetWidth > 0 || targetHeight > 0) {
410 ImageIO scale = Display.getInstance().getImageIO();
411 if (scale != null) {
412 OutputStream os = null; //NOPMD CloseResource
413 try {
414
415 String path = url.substring(0, url.lastIndexOf(".")) + "s" + url.substring(url.lastIndexOf("."));
416 os = FileSystemStorage.getInstance().openOutputStream(path);
417 scale.save(url, os, ImageIO.FORMAT_JPEG, targetWidth, targetHeight, 1);
418 FileSystemStorage.getInstance().delete(url);
419 url = path;
420 } catch (IOException ex) {
421 Log.e(ex);
422 } finally {
423 Util.cleanup(os);
424 }
425 }
426 }
427 }
428
429 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected