Skip to content

Commit 2665620

Browse files
committed
Updated code
1 parent da144c7 commit 2665620

19 files changed

+472
-313
lines changed

CodenameOne/src/com/codename1/impl/OpenGalleryFileTree.java

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,34 +47,46 @@ public void actionPerformed(ActionEvent evt) {
4747
});
4848
final ImageIO imageio = ImageIO.getImageIO();
4949
if (imageio != null) {
50+
Display.getInstance().scheduleBackgroundTask(
51+
new CreateNodeComponentRunnable(thumbs, node, imageio, b));
52+
}
53+
return b;
54+
}
5055

51-
Display.getInstance().scheduleBackgroundTask(new Runnable() {
56+
private static class CreateNodeComponentRunnable implements Runnable {
5257

53-
public void run() {
54-
byte[] data = (byte[]) thumbs.get(node);
55-
if (data == null) {
56-
ByteArrayOutputStream out = new ByteArrayOutputStream();
57-
try {
58-
imageio.save(FileSystemStorage.getInstance().openInputStream((String) node),
59-
out,
60-
ImageIO.FORMAT_JPEG,
61-
b.getIcon().getWidth(), b.getIcon().getHeight(), 1);
62-
data = out.toByteArray();
63-
thumbs.put(node, data);
64-
Storage.getInstance().writeObject("thumbnails", thumbs);
65-
} catch (IOException ex) {
66-
Log.e(ex);
67-
}
68-
}
69-
if (data != null) {
70-
Image im = Image.createImage(data, 0, data.length);
71-
b.setIcon(im);
72-
}
73-
}
74-
});
58+
private final Hashtable thumbs;
59+
private final Object node;
60+
private final ImageIO imageio;
61+
private final Button b;
7562

63+
public CreateNodeComponentRunnable(Hashtable thumbs, Object node, ImageIO imageio, Button b) {
64+
this.thumbs = thumbs;
65+
this.node = node;
66+
this.imageio = imageio;
67+
this.b = b;
7668
}
77-
return b;
78-
}
7969

70+
public void run() {
71+
byte[] data = (byte[]) thumbs.get(node);
72+
if (data == null) {
73+
ByteArrayOutputStream out = new ByteArrayOutputStream();
74+
try {
75+
imageio.save(FileSystemStorage.getInstance().openInputStream((String) node),
76+
out,
77+
ImageIO.FORMAT_JPEG,
78+
b.getIcon().getWidth(), b.getIcon().getHeight(), 1);
79+
data = out.toByteArray();
80+
thumbs.put(node, data);
81+
Storage.getInstance().writeObject("thumbnails", thumbs);
82+
} catch (IOException ex) {
83+
Log.e(ex);
84+
}
85+
}
86+
if (data != null) {
87+
Image im = Image.createImage(data, 0, data.length);
88+
b.setIcon(im);
89+
}
90+
}
91+
}
8092
}

CodenameOne/src/com/codename1/io/Oauth2.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,7 @@ public void showAuthentication(final ActionListener<ActionEvent> al) {
356356
Form authenticationForm = new Form("Login");
357357
authenticationForm.setScrollable(false);
358358
if (old != null) {
359-
Command cancel = new Command("Cancel") {
360-
public void actionPerformed(ActionEvent ev) {
361-
if (Display.getInstance().getCurrent() == progress) {
362-
progress.dispose();
363-
}
364-
old.showBack();
365-
}
366-
};
359+
Command cancel = new ShowAuthenticationCommand(progress, old);
367360
if (authenticationForm.getToolbar() != null) {
368361
authenticationForm.getToolbar().addCommandToLeftBar(cancel);
369362
} else {
@@ -689,6 +682,24 @@ public void actionPerformed(ActionEvent evt) {
689682
}
690683
}
691684

685+
private static class ShowAuthenticationCommand extends Command {
686+
private final Dialog progress;
687+
private final Form old;
688+
689+
public ShowAuthenticationCommand(Dialog progress, Form old) {
690+
super("Cancel");
691+
this.progress = progress;
692+
this.old = old;
693+
}
694+
695+
public void actionPerformed(ActionEvent ev) {
696+
if (Display.getInstance().getCurrent() == progress) {
697+
progress.dispose();
698+
}
699+
old.showBack();
700+
}
701+
}
702+
692703
private class ShowAuthenticationActionListener implements ActionListener<NetworkEvent> {
693704
private final BrowserWindow win;
694705
private final ActionListener<ActionEvent> al;

CodenameOne/src/com/codename1/javascript/JSObject.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ public JSObject(JavascriptContext context, String expr) {
269269
R1 + "." + PROP_REFCOUNT + "++;" +
270270
"} id";
271271

272-
273272
String id = exec(js);
274273
this.objectId = Integer.parseInt(id);
275274
context.retain(this);

CodenameOne/src/com/codename1/javascript/JavascriptContext.java

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -420,13 +420,7 @@ public void apply(JSObject self, Object[] args) {
420420
* @param callback Callback to be called with the result of the expression.
421421
*/
422422
public void getAsync(String javascript, final SuccessCallback callback) {
423-
getAsync(javascript, new CallbackAdapter() {
424-
425-
@Override
426-
public void onSucess(Object value) {
427-
callback.onSucess(value);
428-
}
429-
});
423+
getAsync(javascript, new GetAsyncCallbackAdapter(callback));
430424
}
431425

432426
/**
@@ -841,14 +835,7 @@ public void callAsync(String jsFunc, JSObject self, Object[] params, Callback ca
841835
* object type.
842836
*/
843837
public void callAsync(String jsFunc, JSObject self, Object[] params, final SuccessCallback callback) {
844-
callAsync(jsFunc, self, params, new CallbackAdapter() {
845-
846-
@Override
847-
public void onSucess(Object value) {
848-
callback.onSucess(value);
849-
}
850-
851-
});
838+
callAsync(jsFunc, self, params, new CallAsyncCallbackAdapter(callback));
852839
}
853840

854841
/**
@@ -960,6 +947,35 @@ public void onSucess(Object value) {
960947
});
961948
}
962949

950+
private static class GetAsyncCallbackAdapter extends CallbackAdapter {
951+
952+
private final SuccessCallback callback;
953+
954+
public GetAsyncCallbackAdapter(SuccessCallback callback) {
955+
this.callback = callback;
956+
}
957+
958+
@Override
959+
public void onSucess(Object value) {
960+
callback.onSucess(value);
961+
}
962+
}
963+
964+
private static class CallAsyncCallbackAdapter extends CallbackAdapter {
965+
966+
private final SuccessCallback callback;
967+
968+
public CallAsyncCallbackAdapter(SuccessCallback callback) {
969+
this.callback = callback;
970+
}
971+
972+
@Override
973+
public void onSucess(Object value) {
974+
callback.onSucess(value);
975+
}
976+
977+
}
978+
963979
/**
964980
* A navigation callback that handles navigations to urls of the form
965981
* cn1command:...

CodenameOne/src/com/codename1/maps/MapComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public MapComponent(MapProvider provider, Coord centerPosition, int zoomLevel, b
168168
_layers = new Vector();
169169
setFocusable(false);
170170
if (Display.getInstance().isTouchScreenDevice() && getUIManager().isThemeConstant("mapZoomButtonsBool", true)) {
171-
setLayout(new BorderLayout());
171+
super.setLayout(new BorderLayout());
172172
Container buttonsbar = new Container(new FlowLayout(Component.RIGHT));
173173
Button out = new Button("-");
174174
out.setUIID("MapZoomOut");

CodenameOne/src/com/codename1/media/AbstractMedia.java

Lines changed: 64 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,8 @@ public void onSucess(Throwable value) {
185185
}
186186

187187
if (pendingPlayRequest != null && pendingPlayRequest != out) {
188-
pendingPlayRequest.ready(new SuccessCallback<AsyncMedia>() {
189-
@Override
190-
public void onSucess(AsyncMedia value) {
191-
if (!out.isDone()) {
192-
out.complete(value);
193-
}
194-
}
195-
}).except(new SuccessCallback<Throwable>() {
196-
@Override
197-
public void onSucess(Throwable value) {
198-
if (!out.isDone()) {
199-
out.error(value);
200-
}
201-
}
202-
});
188+
pendingPlayRequest.ready(new PlayAsyncSuccessCallback(out))
189+
.except(new PlayAsyncExceptSuccessCallback(out));
203190
return out;
204191
} else {
205192
pendingPlayRequest = out;
@@ -304,21 +291,8 @@ public void onSucess(Throwable value) {
304291
return out;
305292
}
306293
if (pendingPauseRequest != null && pendingPauseRequest != out) {
307-
pendingPauseRequest.ready(new SuccessCallback<AsyncMedia>() {
308-
@Override
309-
public void onSucess(AsyncMedia value) {
310-
if (!out.isDone()) {
311-
out.complete(value);
312-
}
313-
}
314-
}).except(new SuccessCallback<Throwable>() {
315-
@Override
316-
public void onSucess(Throwable value) {
317-
if (!out.isDone()) {
318-
out.error(value);
319-
}
320-
}
321-
});
294+
pendingPauseRequest.ready(new PauseAsyncSuccessCallback(out))
295+
.except(new PauseAsyncExceptSuccessCallback(out));
322296
return out;
323297
} else {
324298
pendingPauseRequest = out;
@@ -394,4 +368,64 @@ public final void play() {
394368
public final void pause() {
395369
pauseAsync();
396370
}
371+
372+
private static class PauseAsyncSuccessCallback implements SuccessCallback<AsyncMedia> {
373+
private final PauseRequest out;
374+
375+
public PauseAsyncSuccessCallback(PauseRequest out) {
376+
this.out = out;
377+
}
378+
379+
@Override
380+
public void onSucess(AsyncMedia value) {
381+
if (!out.isDone()) {
382+
out.complete(value);
383+
}
384+
}
385+
}
386+
387+
private static class PauseAsyncExceptSuccessCallback implements SuccessCallback<Throwable> {
388+
private final PauseRequest out;
389+
390+
public PauseAsyncExceptSuccessCallback(PauseRequest out) {
391+
this.out = out;
392+
}
393+
394+
@Override
395+
public void onSucess(Throwable value) {
396+
if (!out.isDone()) {
397+
out.error(value);
398+
}
399+
}
400+
}
401+
402+
private static class PlayAsyncSuccessCallback implements SuccessCallback<AsyncMedia> {
403+
private final PlayRequest out;
404+
405+
public PlayAsyncSuccessCallback(PlayRequest out) {
406+
this.out = out;
407+
}
408+
409+
@Override
410+
public void onSucess(AsyncMedia value) {
411+
if (!out.isDone()) {
412+
out.complete(value);
413+
}
414+
}
415+
}
416+
417+
private static class PlayAsyncExceptSuccessCallback implements SuccessCallback<Throwable> {
418+
private final PlayRequest out;
419+
420+
public PlayAsyncExceptSuccessCallback(PlayRequest out) {
421+
this.out = out;
422+
}
423+
424+
@Override
425+
public void onSucess(Throwable value) {
426+
if (!out.isDone()) {
427+
out.error(value);
428+
}
429+
}
430+
}
397431
}

0 commit comments

Comments
 (0)