Skip to content

Commit b163ebb

Browse files
committed
Fixed most issues
1 parent c9ac07a commit b163ebb

26 files changed

+563
-420
lines changed

CodenameOne/src/com/codename1/ui/Form.java

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -736,14 +736,7 @@ public void releaseAnimationLock() {
736736
* @see Component#isEditing()
737737
*/
738738
public Component findCurrentlyEditingComponent() {
739-
return ComponentSelector.select("*", this).filter(new Filter() {
740-
741-
742-
public boolean filter(Component c) {
743-
return c.isEditing();
744-
}
745-
746-
}).asComponent();
739+
return ComponentSelector.select("*", this).filter(new CurrentlyEditingFilter()).asComponent();
747740
}
748741

749742
/**
@@ -2954,25 +2947,8 @@ public Component getPreviousComponent(Component current) {
29542947
public TabIterator getTabIterator(Component start) {
29552948
updateTabIndices(0);
29562949
java.util.List<Component> out = new ArrayList<Component>();
2957-
out.addAll(ComponentSelector.select("*", this).filter(new Filter() {
2958-
2959-
2960-
public boolean filter(Component c) {
2961-
return c.getTabIndex() >= 0 && c.isVisible() && c.isFocusable() && c.isEnabled() && !c.isHidden(true);
2962-
}
2963-
2964-
}));
2965-
Collections.sort(out, new Comparator<Component>() {
2966-
2967-
2968-
public int compare(Component o1, Component o2) {
2969-
return o1.getTabIndex() < o2.getTabIndex() ? -1 :
2970-
o2.getTabIndex() < o1.getTabIndex() ? 1 :
2971-
0;
2972-
}
2973-
2974-
});
2975-
2950+
out.addAll(ComponentSelector.select("*", this).filter(new TabIteratorFilter()));
2951+
Collections.sort(out, new TabIteratorComparator());
29762952
return new TabIterator(out, start);
29772953
}
29782954

@@ -4831,4 +4807,23 @@ public void add(Component e) {
48314807
}
48324808

48334809

4810+
private static class CurrentlyEditingFilter implements Filter {
4811+
public boolean filter(Component c) {
4812+
return c.isEditing();
4813+
}
4814+
}
4815+
4816+
private static class TabIteratorComparator implements Comparator<Component> {
4817+
public int compare(Component o1, Component o2) {
4818+
return o1.getTabIndex() < o2.getTabIndex() ? -1 :
4819+
o2.getTabIndex() < o1.getTabIndex() ? 1 :
4820+
0;
4821+
}
4822+
}
4823+
4824+
private static class TabIteratorFilter implements Filter {
4825+
public boolean filter(Component c) {
4826+
return c.getTabIndex() >= 0 && c.isVisible() && c.isFocusable() && c.isEnabled() && !c.isHidden(true);
4827+
}
4828+
}
48344829
}

CodenameOne/src/com/codename1/ui/InputComponent.java

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,7 @@
7171
public abstract class InputComponent extends Container {
7272
static Boolean guiBuilderMode;
7373
private static boolean multiLineErrorMessage;
74-
private final Button lbl = new Button("", "Label") {
75-
@Override
76-
protected boolean shouldRenderComponentSelection() {
77-
return true;
78-
}
79-
};
74+
private final Button lbl = new LabelButton();
8075
private final Label descriptionMessage = new Label("", "DescriptionLabel");
8176
Button action;
8277
private Boolean onTopMode;
@@ -182,16 +177,7 @@ Label getLabel() {
182177
*/
183178
protected TextHolder createErrorLabel() {
184179
if (multiLineErrorMessage && isOnTopMode()) {
185-
TextArea errorLabel = new TextArea() {
186-
@Override
187-
protected Dimension calcPreferredSize() {
188-
if (getText() == null || getText().length() == 0) {
189-
return new Dimension();
190-
}
191-
return super.calcPreferredSize();
192-
}
193-
194-
};
180+
TextArea errorLabel = new ErrorLabelTextArea();
195181
errorLabel.setRows(1);
196182
errorLabel.setActAsLabel(true);
197183
errorLabel.setGrowByContent(true);
@@ -538,4 +524,26 @@ public String setPropertyValue(String name, Object value) {
538524
}
539525
return super.setPropertyValue(name, value);
540526
}
527+
528+
private static class ErrorLabelTextArea extends TextArea {
529+
@Override
530+
protected Dimension calcPreferredSize() {
531+
if (getText() == null || getText().length() == 0) {
532+
return new Dimension();
533+
}
534+
return super.calcPreferredSize();
535+
}
536+
537+
}
538+
539+
private static class LabelButton extends Button {
540+
public LabelButton() {
541+
super("", "Label");
542+
}
543+
544+
@Override
545+
protected boolean shouldRenderComponentSelection() {
546+
return true;
547+
}
548+
}
541549
}

CodenameOne/src/com/codename1/ui/Label.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -914,10 +914,8 @@ void initAutoResize() {
914914
while (currentWidth > w) {
915915
fontSize--;
916916
if (fontSize <= minSizePixel) {
917-
fontSize = minSizePixel;
918917
currentFont = currentFont.derive(minSizePixel, currentFont.getStyle());
919918
getAllStyles().setFont(currentFont);
920-
currentWidth = calcPreferredSize().getWidth();
921919
break;
922920
}
923921
currentFont = currentFont.derive(fontSize, currentFont.getStyle());
@@ -1569,8 +1567,7 @@ public String getIconUIID() {
15691567
*/
15701568
public void setIconUIID(String uiid) {
15711569
if (iconStyleComponent == null || !uiid.equals(iconStyleComponent.getUIID())) {
1572-
iconStyleComponent = new Component() {
1573-
};
1570+
iconStyleComponent = new Component();
15741571
iconStyleComponent.setUIID(uiid);
15751572
}
15761573
}

CodenameOne/src/com/codename1/ui/MenuBar.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -704,11 +704,7 @@ public void showMenu() {
704704
final Dialog d = new Dialog("Menu", "");
705705
d.setDisposeWhenPointerOutOfBounds(true);
706706
d.setMenu(true);
707-
d.addOrientationListener(new ActionListener() {
708-
public void actionPerformed(ActionEvent evt) {
709-
d.dispose();
710-
}
711-
});
707+
d.addOrientationListener(new MenuDisposerActionListener(d));
712708
d.setTransitionInAnimator(transitionIn);
713709
d.setTransitionOutAnimator(transitionOut);
714710
d.setLayout(new BorderLayout());
@@ -1761,4 +1757,16 @@ private boolean isTouchMenus() {
17611757
return t == Display.COMMAND_BEHAVIOR_TOUCH_MENU ||
17621758
(t == Display.COMMAND_BEHAVIOR_DEFAULT && Display.getInstance().isTouchScreenDevice());
17631759
}
1760+
1761+
private static class MenuDisposerActionListener implements ActionListener {
1762+
private final Dialog d;
1763+
1764+
public MenuDisposerActionListener(Dialog d) {
1765+
this.d = d;
1766+
}
1767+
1768+
public void actionPerformed(ActionEvent evt) {
1769+
d.dispose();
1770+
}
1771+
}
17641772
}

CodenameOne/src/com/codename1/ui/RunnableWrapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ public void run() {
122122
while (!done) {
123123
synchronized (Display.lock) {
124124
try {
125-
Display.lock.wait(10);
125+
if(!done) {
126+
Display.lock.wait(10);
127+
}
126128
} catch (InterruptedException ex) {
127129
ex.printStackTrace();
128130
}

CodenameOne/src/com/codename1/ui/Toolbar.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -592,15 +592,8 @@ public void actionPerformed(ActionEvent evt) {
592592
*
593593
* @param callback gets the search string callbacks
594594
*/
595-
public void showSearchBar(final ActionListener callback) {
596-
SearchBar s = new SearchBar(Toolbar.this, searchIconSize) {
597-
598-
@Override
599-
public void onSearch(String text) {
600-
callback.actionPerformed(new ActionEvent(text));
601-
}
602-
603-
};
595+
public void showSearchBar(final ActionListener<ActionEvent> callback) {
596+
SearchBar s = new CallbackSearchBar(callback);
604597
Form f = Toolbar.this.getComponentForm();
605598
setHidden(true);
606599
f.removeComponentFromForm(Toolbar.this);
@@ -1642,10 +1635,7 @@ public void run() {
16421635
// changes in code path - since it already worked correctly on
16431636
// every platform except for iOS.
16441637
// Ref https://github.com/codenameone/CodenameOne/issues/2444
1645-
f.stopEditing(new Runnable() {
1646-
public void run() {
1647-
}
1648-
});
1638+
f.stopEditing(null);
16491639
}
16501640
}
16511641
AnimationManager a = getAnimationManager();
@@ -2784,4 +2774,17 @@ void initTitleBarStatus() {
27842774
}
27852775

27862776

2777+
private class CallbackSearchBar extends SearchBar {
2778+
private final ActionListener<ActionEvent> callback;
2779+
2780+
public CallbackSearchBar(ActionListener<ActionEvent> callback) {
2781+
super(Toolbar.this, Toolbar.this.searchIconSize);
2782+
this.callback = callback;
2783+
}
2784+
2785+
@Override
2786+
public void onSearch(String text) {
2787+
callback.actionPerformed(new ActionEvent(text));
2788+
}
2789+
}
27872790
}

CodenameOne/src/com/codename1/ui/html/AsyncDocumentRequestHandlerImpl.java

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.io.InputStream;
3333
import java.io.OutputStream;
3434
import java.io.OutputStreamWriter;
35+
import java.util.Arrays;
3536

3637
/**
3738
* Implementation of the HTML components document request handler to allow simple
@@ -116,41 +117,67 @@ private InputStream resourceRequested(final DocumentInfo docInfo, final IOCallba
116117

117118
protected ConnectionRequest createConnectionRequest(final DocumentInfo docInfo,
118119
final IOCallback callback, final Object[] response) {
119-
return new ConnectionRequest() {
120+
return new AsyncDocumentConnectionRequest(docInfo, callback, response);
121+
}
120122

121-
protected void buildRequestBody(OutputStream os) throws IOException {
122-
if (isPost()) {
123-
if (docInfo.getParams() != null) {
124-
OutputStreamWriter w = new OutputStreamWriter(os, docInfo.getEncoding());
125-
w.write(docInfo.getParams());
126-
}
127-
}
128-
}
123+
private static class AsyncDocumentConnectionRequest extends ConnectionRequest {
124+
private final DocumentInfo docInfo;
125+
private final IOCallback callback;
126+
private final Object[] response;
129127

130-
protected void handleIOException(IOException err) {
131-
if (callback == null) {
132-
response[0] = err;
128+
public AsyncDocumentConnectionRequest(DocumentInfo docInfo, IOCallback callback, Object[] response) {
129+
this.docInfo = docInfo;
130+
this.callback = callback;
131+
this.response = response;
132+
}
133+
134+
protected void buildRequestBody(OutputStream os) throws IOException {
135+
if (isPost()) {
136+
if (docInfo.getParams() != null) {
137+
OutputStreamWriter w = new OutputStreamWriter(os, docInfo.getEncoding());
138+
w.write(docInfo.getParams());
133139
}
134-
super.handleIOException(err);
135140
}
141+
}
136142

137-
protected boolean shouldAutoCloseResponse() {
138-
return callback != null;
143+
protected void handleIOException(IOException err) {
144+
if (callback == null) {
145+
response[0] = err;
139146
}
147+
super.handleIOException(err);
148+
}
140149

141-
protected void readResponse(InputStream input) throws IOException {
142-
if (callback != null) {
143-
callback.streamReady(input, docInfo);
144-
} else {
145-
response[0] = input;
146-
synchronized (LOCK) {
147-
LOCK.notifyAll();
148-
}
150+
protected boolean shouldAutoCloseResponse() {
151+
return callback != null;
152+
}
153+
154+
protected void readResponse(InputStream input) throws IOException {
155+
if (callback != null) {
156+
callback.streamReady(input, docInfo);
157+
} else {
158+
response[0] = input;
159+
synchronized (LOCK) {
160+
LOCK.notifyAll();
149161
}
150162
}
163+
}
151164

152-
};
165+
@Override
166+
public final boolean equals(Object o) {
167+
if (!(o instanceof AsyncDocumentConnectionRequest)) return false;
168+
if (!super.equals(o)) return false;
153169

154-
}
170+
AsyncDocumentConnectionRequest that = (AsyncDocumentConnectionRequest) o;
171+
return (docInfo == null ? that.docInfo == null : docInfo.equals(that.docInfo)) && (callback == null ? that.callback == null : callback.equals(that.callback)) && Arrays.equals(response, that.response);
172+
}
155173

174+
@Override
175+
public int hashCode() {
176+
int result = super.hashCode();
177+
result = 31 * result + (docInfo != null ? docInfo.hashCode() : 0);
178+
result = 31 * result + (callback != null ? callback.hashCode() : 0);
179+
result = 31 * result + Arrays.hashCode(response);
180+
return result;
181+
}
182+
}
156183
}

CodenameOne/src/com/codename1/ui/html/HTMLComponent.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,11 +2719,7 @@ TextArea setInputFormat(final TextArea inputField, String inputFormat) {
27192719
if (Display.getInstance().getCurrent() != inputField.getComponentForm()) { // ((inputField.getComponentForm()==null) ||
27202720
inputField.getParent().replace(inputField, newInputField, null); // Applying the constraints may return a new instance that has to be replaced in the form
27212721
} else {
2722-
Display.getInstance().callSerially(new Runnable() {
2723-
public void run() {
2724-
inputField.getParent().replace(inputField, newInputField, null); // Applying the constraints may return a new instance that has to be replaced in the form
2725-
}
2726-
});
2722+
Display.getInstance().callSerially(new InputFormatRunnable(inputField, newInputField));
27272723
}
27282724
if (firstFocusable == inputField) {
27292725
firstFocusable = newInputField;
@@ -4351,4 +4347,17 @@ protected List createPopupList() {
43514347

43524348
}
43534349

4350+
private static class InputFormatRunnable implements Runnable {
4351+
private final TextArea inputField;
4352+
private final TextArea newInputField;
4353+
4354+
public InputFormatRunnable(TextArea inputField, TextArea newInputField) {
4355+
this.inputField = inputField;
4356+
this.newInputField = newInputField;
4357+
}
4358+
4359+
public void run() {
4360+
inputField.getParent().replace(inputField, newInputField, null); // Applying the constraints may return a new instance that has to be replaced in the form
4361+
}
4362+
}
43544363
}

CodenameOne/src/com/codename1/ui/html/HTMLInputFormat.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,7 @@ TextArea applyConstraints(TextArea ta) {
167167
if (ta instanceof TextField) {
168168
TextField tf = (TextField) ta;
169169
if (((widestConstraint & FormatConstraint.TYPE_SYMBOL) == 0) && ((widestConstraint & FormatConstraint.TYPE_ANY) == 0)) { // No symbols allowed
170-
tf = new TextField(ta.getText()) {
171-
protected void showSymbolDialog() { // Block symbols dialog
172-
}
173-
};
170+
tf = new ConstraintsTextField(ta);
174171
tf.setConstraint(ta.getConstraint());
175172
ta = tf;
176173
}
@@ -492,5 +489,13 @@ public String toString() {
492489
}
493490

494491

492+
private static class ConstraintsTextField extends TextField {
493+
public ConstraintsTextField(TextArea ta) {
494+
super(ta.getText());
495+
}
496+
497+
protected void showSymbolDialog() { // Block symbols dialog
498+
}
499+
}
495500
}
496501

0 commit comments

Comments
 (0)