Skip to content

Commit 8ae54ac

Browse files
committed
Major fixes for calls from constructors
1 parent da30271 commit 8ae54ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+188
-131
lines changed

.github/scripts/generate-quality-report.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,6 @@ def main() -> None:
806806
"NM_CONFUSING",
807807
"NO_NOTIFY_NOT_NOTIFYALL",
808808
"NP_BOOLEAN_RETURN_NULL",
809-
"PZLA_PREFER_ZERO_LENGTH_ARRAYS",
810809
"REFLC_REFLECTION_MAY_INCREASE_ACCESSIBILITY_OF_CLASS",
811810
"UI_INHERITANCE_UNSAFE_GETRESOURCE",
812811
"URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD",

CodenameOne/src/com/codename1/charts/ChartComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public class ChartComponent extends Component {
208208
* @param chart The chart to be displayed in this component.
209209
*/
210210
public ChartComponent(AbstractChart chart) {
211-
setUIID("ChartComponent");
211+
setUIIDFinal("ChartComponent");
212212
this.chart = chart;
213213
if (chart != null && chart instanceof XYChart) {
214214
XYChart xyChart = (XYChart) chart;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ class AccordionContent extends Container {
420420
private String topUiid = uiidHeader;
421421

422422
public AccordionContent(Component header, final Component body) {
423-
setUIID(uiidBackGroundItem);
423+
setUIIDFinal(uiidBackGroundItem);
424424
setLayout(new BorderLayout());
425425
this.body = body;
426426
this.header = header;

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import com.codename1.ads.AdsService;
2626
import com.codename1.io.ConnectionRequest;
27+
import com.codename1.io.NetworkEvent;
2728
import com.codename1.ui.Component;
2829
import com.codename1.ui.Container;
2930
import com.codename1.ui.Display;
@@ -76,7 +77,7 @@ public class Ads extends Container implements HTMLCallback {
7677
* Default constructor for GUI builder
7778
*/
7879
public Ads() {
79-
setUIID("Ads");
80+
setUIIDFinal("Ads");
8081
setLayout(new BorderLayout());
8182

8283
// special case for iOS. It seems the ad component can inadvertedly steal focus from
@@ -218,20 +219,7 @@ public String getAd() {
218219
*/
219220
public void setAd(String ad) {
220221
this.ad = ad;
221-
HTMLComponent html = new HTMLComponent(new AsyncDocumentRequestHandlerImpl() {
222-
223-
protected ConnectionRequest createConnectionRequest(DocumentInfo docInfo, IOCallback callback, Object[] response) {
224-
ConnectionRequest req = super.createConnectionRequest(docInfo, callback, response);
225-
req.setFailSilently(true);
226-
req.addResponseCodeListener(new ActionListener() {
227-
228-
public void actionPerformed(ActionEvent evt) {
229-
//do nothing, just make sure the html won't throw an error
230-
}
231-
});
232-
return req;
233-
}
234-
});
222+
HTMLComponent html = new HTMLComponent(new MyAsyncDocumentRequestHandlerImpl());
235223
html.setSupressExceptions(true);
236224
html.setHTMLCallback(this);
237225
html.setBodyText("<html><body><div align='center'>" + ad + "</div></body></html>");
@@ -585,4 +573,21 @@ public String setPropertyValue(String name, Object value) {
585573
}
586574
return super.setPropertyValue(name, value);
587575
}
576+
577+
private static class MyAsyncDocumentRequestHandlerImpl extends AsyncDocumentRequestHandlerImpl {
578+
579+
protected ConnectionRequest createConnectionRequest(DocumentInfo docInfo, IOCallback callback, Object[] response) {
580+
ConnectionRequest req = super.createConnectionRequest(docInfo, callback, response);
581+
req.setFailSilently(true);
582+
req.addResponseCodeListener(new NetworkEventActionListener());
583+
return req;
584+
}
585+
586+
private static class NetworkEventActionListener implements ActionListener<NetworkEvent> {
587+
588+
public void actionPerformed(NetworkEvent evt) {
589+
//do nothing, just make sure the html won't throw an error
590+
}
591+
}
592+
}
588593
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ public ButtonList(ListModel model) {
110110
((DefaultListModel) model).setMultiSelectionMode(true);
111111
}
112112
setModel(model);
113-
114113
}
115114

116115
/**
@@ -130,7 +129,7 @@ protected void onReady(Runnable r) {
130129
* This should be called by the concrete implementation once it is ready to generate the
131130
* buttons.
132131
*/
133-
protected void fireReady() {
132+
protected final void fireReady() {
134133
ready = true;
135134
for (Runnable r : onReady) {
136135
r.run();
@@ -160,7 +159,7 @@ public ListModel getModel() {
160159
return model;
161160
}
162161

163-
public void setModel(ListModel model) {
162+
public final void setModel(ListModel model) {
164163
if (model != this.model) {
165164
if (this.model != null) {
166165
this.model.removeDataChangedListener(this);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public class FileTree extends Tree {
3838
*/
3939
public FileTree() {
4040
super(new FileTreeModel(true));
41-
setUIID("FileTree");
41+
setUIIDFinal("FileTree");
4242
}
4343

4444
/**
4545
* Constructor with a model
4646
*/
4747
public FileTree(FileTreeModel model) {
4848
super(model);
49-
setUIID("FileTree");
49+
setUIIDFinal("FileTree");
5050
}
5151

5252
protected String childToDisplayLabel(Object child) {

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

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ protected FloatingActionButton(char icon, String text, String uiid, float size)
112112
setIcon(image);
113113
setText("");
114114
this.text = text;
115-
setUIID(uiid);
115+
setUIIDFinal(uiid);
116116
Style all = getAllStyles();
117117
all.setAlignment(CENTER);
118118
updateBorder();
@@ -125,7 +125,7 @@ private FloatingActionButton(String text) {
125125
super.setText(text);
126126
rectangle = true;
127127
shadowOpacity = 0;
128-
setUIID("Badge");
128+
setUIIDFinal("Badge");
129129
updateBorder();
130130
isBadge = true;
131131
}
@@ -370,15 +370,7 @@ public void released(int x, int y) {
370370
int oldTint = f.getTintColor();
371371
f.setTintColor(0);
372372
d.setBlurBackgroundRadius(-1);
373-
d.addShowListener(new ActionListener() {
374-
public void actionPerformed(ActionEvent evt) {
375-
for (Component c : con) {
376-
c.setY(con.getHeight());
377-
c.setVisible(true);
378-
}
379-
con.animateLayout(200);
380-
}
381-
});
373+
d.addShowListener(new ReleaseActionListener(con));
382374
showPopupDialog(d);
383375
f.setTintColor(oldTint);
384376
for (FloatingActionButton next : subMenu) {
@@ -404,12 +396,7 @@ protected Container createPopupContent(List<FloatingActionButton> fabs) {
404396
c.add(BorderLayout.CENTER, FlowLayout.encloseRight(txt));
405397
c.add(BorderLayout.EAST, next);
406398
con.add(c);
407-
txt.addActionListener(new ActionListener() {
408-
public void actionPerformed(ActionEvent evt) {
409-
next.pressed();
410-
next.released();
411-
}
412-
});
399+
txt.addActionListener(new CreatePopupContentActionListener(next));
413400
}
414401
return con;
415402
}
@@ -438,4 +425,32 @@ public void setFloatingActionTextUIID(String floatingActionTextUIID) {
438425
this.floatingActionTextUIID = floatingActionTextUIID;
439426
}
440427

428+
private static class ReleaseActionListener implements ActionListener<ActionEvent> {
429+
private final Container con;
430+
431+
public ReleaseActionListener(Container con) {
432+
this.con = con;
433+
}
434+
435+
public void actionPerformed(ActionEvent evt) {
436+
for (Component c : con) {
437+
c.setY(con.getHeight());
438+
c.setVisible(true);
439+
}
440+
con.animateLayout(200);
441+
}
442+
}
443+
444+
private static class CreatePopupContentActionListener implements ActionListener<ActionEvent> {
445+
private final FloatingActionButton next;
446+
447+
public CreatePopupContentActionListener(FloatingActionButton next) {
448+
this.next = next;
449+
}
450+
451+
public void actionPerformed(ActionEvent evt) {
452+
next.pressed();
453+
next.released();
454+
}
455+
}
441456
}

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

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,7 @@ public FloatingHint(final TextArea tf) {
6565
this.tf = tf;
6666
Container content = new Container(new BorderLayout());
6767
add(content);
68-
hintButton = new Button(tf.getHint()) {
69-
@Override
70-
protected boolean shouldRenderComponentSelection() {
71-
return true;
72-
}
73-
};
68+
hintButton = new HintButtonImpl(tf);
7469
hintLabel = new Label(tf.getHint());
7570
tf.setHint("");
7671
hintButton.setFocusable(false);
@@ -87,11 +82,7 @@ protected boolean shouldRenderComponentSelection() {
8782
add(BorderLayout.north(hintButton).
8883
add(BorderLayout.CENTER, hintLabel));
8984

90-
hintButton.addActionListener(new ActionListener() {
91-
public void actionPerformed(ActionEvent evt) {
92-
tf.startEditingAsync();
93-
}
94-
});
85+
hintButton.addActionListener(new HintButtonActionListener(tf));
9586
if (tf.getText() == null || tf.getText().length() == 0) {
9687
hintButton.setVisible(false);
9788
} else {
@@ -170,4 +161,26 @@ protected void initComponent() {
170161
}
171162

172163

164+
private static class HintButtonImpl extends Button {
165+
public HintButtonImpl(TextArea tf) {
166+
super(tf.getHint());
167+
}
168+
169+
@Override
170+
protected boolean shouldRenderComponentSelection() {
171+
return true;
172+
}
173+
}
174+
175+
private static class HintButtonActionListener implements ActionListener<ActionEvent> {
176+
private final TextArea tf;
177+
178+
public HintButtonActionListener(TextArea tf) {
179+
this.tf = tf;
180+
}
181+
182+
public void actionPerformed(ActionEvent evt) {
183+
tf.startEditingAsync();
184+
}
185+
}
173186
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public class ImageViewer extends Component {
117117
*/
118118
public ImageViewer() {
119119
setFocusable(true);
120-
setUIID("ImageViewer");
120+
setUIIDFinal("ImageViewer");
121121
$(this).selectAllStyles().setBgTransparency(0x0);
122122
}
123123

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public class InfiniteProgress extends Component {
101101
* Default constructor to define the UIID
102102
*/
103103
public InfiniteProgress() {
104-
setUIID("InfiniteProgress");
104+
setUIIDFinal("InfiniteProgress");
105105
}
106106

107107
/**

0 commit comments

Comments
 (0)