Skip to content

Commit da144c7

Browse files
committed
Additional round of fixes
1 parent f5ee076 commit da144c7

File tree

13 files changed

+592
-390
lines changed

13 files changed

+592
-390
lines changed

CodenameOne/src/com/codename1/components/SignatureComponent.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,13 @@ public SignatureDialogBody() {
338338
super.addComponent(BorderLayout.CENTER, signaturePanel);
339339
Button doneButton = new Button(
340340
localize("SignatureComponent.SaveButtonLabel", "Save"),
341-
getUIManager().getThemeConstant("sigButtonOKUIID", "Button"));
341+
super.getUIManager().getThemeConstant("sigButtonOKUIID", "Button"));
342342
Button resetButton = new Button(
343343
localize("SignatureComponent.ResetButtonLabel", "Reset"),
344-
getUIManager().getThemeConstant("sigButtonResetUIID", "Button"));
344+
super.getUIManager().getThemeConstant("sigButtonResetUIID", "Button"));
345345
Button cancelButton = new Button(
346346
localize("SignatureComponent.CancelButtonLabel", "Cancel"),
347-
getUIManager().getThemeConstant("sigButtonCancelUIID", "Button"));
347+
super.getUIManager().getThemeConstant("sigButtonCancelUIID", "Button"));
348348

349349
doneButton.addActionListener(new ActionListener<ActionEvent>() {
350350
public void actionPerformed(ActionEvent evt) {
@@ -449,8 +449,8 @@ private static class SignaturePanel extends Component {
449449

450450
SignaturePanel() {
451451
setUIIDFinal("SignaturePanel");
452-
signatureBoxStyle = getUIManager().getComponentStyle("SignaturePanelBox");
453-
signatureStyle = getUIManager().getComponentStyle("SignaturePanelSignature");
452+
signatureBoxStyle = super.getUIManager().getComponentStyle("SignaturePanelBox");
453+
signatureStyle = super.getUIManager().getComponentStyle("SignaturePanelSignature");
454454
stroke.setLineWidth(Math.max(1, Display.getInstance().convertToPixels(1, true) / 2));
455455
}
456456

CodenameOne/src/com/codename1/components/SpanLabel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public SpanLabel(String txt, String textUiid) {
8282
public SpanLabel(String txt) {
8383
setUIIDFinal("Container");
8484
super.setLayout(new BorderLayout());
85-
text = new TextArea(getUIManager().localize(txt, txt));
85+
text = new TextArea(super.getUIManager().localize(txt, txt));
8686
text.setActAsLabel(true);
8787
text.setColumns(text.getText().length() + 1);
8888
text.setGrowByContent(true);

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

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3783,7 +3783,7 @@ public InputStream getResourceAsStream(Class cls, String resource) {
37833783
if (cls != null) {
37843784
return cls.getResourceAsStream(resource);
37853785
}
3786-
return getClass().getResourceAsStream(resource);
3786+
return CodenameOneImplementation.class.getResourceAsStream(resource);
37873787
}
37883788

37893789
/**
@@ -5898,58 +5898,7 @@ public void openGallery(final ActionListener response, int type) {
58985898
model.addExtensionFilter("mov");
58995899
}
59005900

5901-
FileTree t = new FileTree(model) {
5902-
5903-
protected Button createNodeComponent(final Object node, int depth) {
5904-
if (node == null || !getModel().isLeaf(node)) {
5905-
return super.createNodeComponent(node, depth);
5906-
}
5907-
Hashtable t = (Hashtable) Storage.getInstance().readObject("thumbnails");
5908-
if (t == null) {
5909-
t = new Hashtable();
5910-
}
5911-
final Hashtable thumbs = t;
5912-
final Button b = super.createNodeComponent(node, depth);
5913-
b.addActionListener(new ActionListener() {
5914-
5915-
public void actionPerformed(ActionEvent evt) {
5916-
response.actionPerformed(new ActionEvent(node, ActionEvent.Type.Other));
5917-
d.dispose();
5918-
}
5919-
});
5920-
final ImageIO imageio = ImageIO.getImageIO();
5921-
if (imageio != null) {
5922-
5923-
Display.getInstance().scheduleBackgroundTask(new Runnable() {
5924-
5925-
public void run() {
5926-
byte[] data = (byte[]) thumbs.get(node);
5927-
if (data == null) {
5928-
ByteArrayOutputStream out = new ByteArrayOutputStream();
5929-
try {
5930-
imageio.save(FileSystemStorage.getInstance().openInputStream((String) node),
5931-
out,
5932-
ImageIO.FORMAT_JPEG,
5933-
b.getIcon().getWidth(), b.getIcon().getHeight(), 1);
5934-
data = out.toByteArray();
5935-
thumbs.put(node, data);
5936-
Storage.getInstance().writeObject("thumbnails", thumbs);
5937-
} catch (IOException ex) {
5938-
Log.e(ex);
5939-
}
5940-
}
5941-
if (data != null) {
5942-
Image im = Image.createImage(data, 0, data.length);
5943-
b.setIcon(im);
5944-
}
5945-
}
5946-
});
5947-
5948-
}
5949-
return b;
5950-
}
5951-
5952-
};
5901+
FileTree t = new OpenGalleryFileTree(model, response, d);
59535902

59545903
d.addComponent(BorderLayout.CENTER, t);
59555904

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.codename1.impl;
2+
3+
import com.codename1.components.FileTree;
4+
import com.codename1.components.FileTreeModel;
5+
import com.codename1.io.FileSystemStorage;
6+
import com.codename1.io.Log;
7+
import com.codename1.io.Storage;
8+
import com.codename1.ui.Button;
9+
import com.codename1.ui.Dialog;
10+
import com.codename1.ui.Display;
11+
import com.codename1.ui.Image;
12+
import com.codename1.ui.events.ActionEvent;
13+
import com.codename1.ui.events.ActionListener;
14+
import com.codename1.ui.util.ImageIO;
15+
16+
import java.io.ByteArrayOutputStream;
17+
import java.io.IOException;
18+
import java.util.Hashtable;
19+
20+
class OpenGalleryFileTree extends FileTree {
21+
22+
private final ActionListener response;
23+
private final Dialog d;
24+
25+
public OpenGalleryFileTree(FileTreeModel model, ActionListener response, Dialog d) {
26+
super(model);
27+
this.response = response;
28+
this.d = d;
29+
}
30+
31+
protected Button createNodeComponent(final Object node, int depth) {
32+
if (node == null || !getModel().isLeaf(node)) {
33+
return super.createNodeComponent(node, depth);
34+
}
35+
Hashtable t = (Hashtable) Storage.getInstance().readObject("thumbnails");
36+
if (t == null) {
37+
t = new Hashtable();
38+
}
39+
final Hashtable thumbs = t;
40+
final Button b = super.createNodeComponent(node, depth);
41+
b.addActionListener(new ActionListener() {
42+
43+
public void actionPerformed(ActionEvent evt) {
44+
response.actionPerformed(new ActionEvent(node, ActionEvent.Type.Other));
45+
d.dispose();
46+
}
47+
});
48+
final ImageIO imageio = ImageIO.getImageIO();
49+
if (imageio != null) {
50+
51+
Display.getInstance().scheduleBackgroundTask(new Runnable() {
52+
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+
});
75+
76+
}
77+
return b;
78+
}
79+
80+
}

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

Lines changed: 67 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,21 +2580,8 @@ public AsyncResource<Image> downloadImageToStorage(String storageFile) {
25802580
*/
25812581
public AsyncResource<Image> downloadImageToStorage(String storageFile, boolean useCache) {
25822582
final AsyncResource<Image> out = new AsyncResource<Image>();
2583-
downloadImageToStorage(storageFile, new SuccessCallback<Image>() {
2584-
@Override
2585-
public void onSucess(Image value) {
2586-
if (!out.isDone()) {
2587-
out.complete(value);
2588-
}
2589-
}
2590-
}, new FailureCallback<Image>() {
2591-
@Override
2592-
public void onError(Object sender, Throwable err, int errorCode, String errorMessage) {
2593-
if (!out.isDone()) {
2594-
out.error(err);
2595-
}
2596-
}
2597-
}, useCache);
2583+
downloadImageToStorage(storageFile, new ImageStorageSuccessCallback(out),
2584+
new ImageStorageFailureCallback(out), useCache);
25982585
return out;
25992586
}
26002587

@@ -2646,28 +2633,13 @@ public void downloadImageToStorage(String storageFile, SuccessCallback<Image> on
26462633
*/
26472634
public AsyncResource<Image> downloadImageToFileSystem(String file, boolean useCache) {
26482635
final AsyncResource<Image> out = new AsyncResource<Image>();
2649-
downloadImageToFileSystem(file, new SuccessCallback<Image>() {
2650-
@Override
2651-
public void onSucess(Image value) {
2652-
if (out.isDone()) {
2653-
return;
2654-
}
2655-
out.complete(value);
2656-
}
2657-
}, new FailureCallback<Image>() {
2658-
@Override
2659-
public void onError(Object sender, Throwable err, int errorCode, String errorMessage) {
2660-
if (out.isDone()) {
2661-
return;
2662-
}
2663-
out.error(err);
2664-
}
2665-
}, useCache);
2636+
downloadImageToFileSystem(file, new ImageFileSystemSuccessCallback(out),
2637+
new ImageFileSystemFailureCallback(out), useCache);
26662638
return out;
26672639
}
26682640

26692641
/**
2670-
* Downloads an image to a the file system asynchronously returning an AsyncResource object that resolves to the loaded image..
2642+
* Downloads an image to the file system asynchronously returning an AsyncResource object that resolves to the loaded image..
26712643
* If useCache is true, then this will first try to load the image from Storage if it exists. This is a wrapper around {@link #downloadImageToFileSystem(java.lang.String, boolean) }
26722644
* with {@literal true} as the 2nd parameter.
26732645
*
@@ -2962,4 +2934,66 @@ public String getCertificteAlgorithm() {
29622934
return certificateAlgorithm;
29632935
}
29642936
}
2937+
2938+
private static class ImageStorageSuccessCallback implements SuccessCallback<Image> {
2939+
private final AsyncResource<Image> out;
2940+
2941+
public ImageStorageSuccessCallback(AsyncResource<Image> out) {
2942+
this.out = out;
2943+
}
2944+
2945+
@Override
2946+
public void onSucess(Image value) {
2947+
if (!out.isDone()) {
2948+
out.complete(value);
2949+
}
2950+
}
2951+
}
2952+
2953+
private static class ImageStorageFailureCallback implements FailureCallback<Image> {
2954+
private final AsyncResource<Image> out;
2955+
2956+
public ImageStorageFailureCallback(AsyncResource<Image> out) {
2957+
this.out = out;
2958+
}
2959+
2960+
@Override
2961+
public void onError(Object sender, Throwable err, int errorCode, String errorMessage) {
2962+
if (!out.isDone()) {
2963+
out.error(err);
2964+
}
2965+
}
2966+
}
2967+
2968+
private static class ImageFileSystemSuccessCallback implements SuccessCallback<Image> {
2969+
private final AsyncResource<Image> out;
2970+
2971+
public ImageFileSystemSuccessCallback(AsyncResource<Image> out) {
2972+
this.out = out;
2973+
}
2974+
2975+
@Override
2976+
public void onSucess(Image value) {
2977+
if (out.isDone()) {
2978+
return;
2979+
}
2980+
out.complete(value);
2981+
}
2982+
}
2983+
2984+
private static class ImageFileSystemFailureCallback implements FailureCallback<Image> {
2985+
private final AsyncResource<Image> out;
2986+
2987+
public ImageFileSystemFailureCallback(AsyncResource<Image> out) {
2988+
this.out = out;
2989+
}
2990+
2991+
@Override
2992+
public void onError(Object sender, Throwable err, int errorCode, String errorMessage) {
2993+
if (out.isDone()) {
2994+
return;
2995+
}
2996+
out.error(err);
2997+
}
2998+
}
29652999
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ void addToQueue(@Async.Schedule ConnectionRequest request, boolean retry) {
602602
addSortedToQueue(request, i);
603603
break;
604604
}
605-
LOCK.notify();
605+
LOCK.notifyAll();
606606
}
607607
}
608608

@@ -836,7 +836,7 @@ private boolean runCurrentRequest(@Async.Execute ConnectionRequest req) {
836836
return false;
837837
}
838838
pending.addElement(currentRequest);
839-
LOCK.notify();
839+
LOCK.notifyAll();
840840
long end = System.currentTimeMillis() + 30;
841841
while (true) {
842842
long remaining = end - System.currentTimeMillis();

0 commit comments

Comments
 (0)