Skip to content

Commit d2e209e

Browse files
author
soheil_h_y
committed
1. NumberFormatException for Integer.parseInt for css width, height, top, ... that are empty. (Solved)
All of the strings passed to the parseInt should start with a number.
1 parent 67296c5 commit d2e209e

File tree

12 files changed

+117
-39
lines changed

12 files changed

+117
-39
lines changed

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/custom/CTabFolder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3439,7 +3439,10 @@ void updateSelection(int index) {
34393439
s.width = w +"px";
34403440
x += w + 2;
34413441
}
3442-
int ww = Integer.parseInt(handle.style.width);
3442+
int ww = 0;
3443+
if(handle.style.width.length() > 0){
3444+
ww = Integer.parseInt(handle.style.width);
3445+
}
34433446
if (ww > 0) {
34443447
//TODO : ITEM MORE
34453448
// String cssName = borderFrame.className;

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/dnd/SashDND.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package org.eclipse.swt.internal.dnd;
1515

1616
import org.eclipse.swt.graphics.Point;
17+
import org.eclipse.swt.internal.xhtml.CSSStyle;
1718
import org.eclipse.swt.internal.xhtml.Element;
1819
import org.eclipse.swt.internal.xhtml.document;
1920
import org.eclipse.swt.internal.xhtml.window;
@@ -52,8 +53,10 @@ public boolean dragBegan(DragEvent e) {
5253
} else {
5354
e.sourceElement.parentNode.appendChild (thumb);
5455
}
55-
this.sourceX = Integer.parseInt (e.sourceElement.style.left);
56-
this.sourceY = Integer.parseInt (e.sourceElement.style.top);
56+
CSSStyle style = e.sourceElement.style;
57+
58+
this.sourceX = style.left.length() > 0 ? Integer.parseInt (style.left) : 0;
59+
this.sourceY = style.top.length() > 0 ? Integer.parseInt (style.top) : 0;
5760
/* first time, set start location to current location */
5861
e.startX = e.currentX;
5962
e.startY = e.currentY;
@@ -90,15 +93,23 @@ protected void clean() {
9093
protected Point currentLocation(DragEvent e) {
9194
int xx = this.sourceX + e.deltaX ();
9295
int yy = this.sourceY + e.deltaY ();
93-
94-
int gHeight = Integer.parseInt(e.sourceElement.parentNode.style.height);
95-
int gWidth = Integer.parseInt(e.sourceElement.parentNode.style.width);
96+
int gHeight = 0;
97+
CSSStyle parentStyle = e.sourceElement.parentNode.style;
98+
if(parentStyle.height.length() > 0){
99+
gHeight = Integer.parseInt(parentStyle.height);
100+
}
101+
int gWidth = 0;
102+
if(parentStyle.width.length() > 0){
103+
gWidth = Integer.parseInt(parentStyle.width);
104+
}
96105
/*
97106
* On mozilla, the mousemove event can contain mousemove
98107
* outside the browser window, so make bound for the dragging.
99108
*/
100-
int dWidth = Integer.parseInt(e.sourceElement.style.width);
101-
int dHeight = Integer.parseInt(e.sourceElement.style.height);
109+
CSSStyle style = e.sourceElement.style;
110+
111+
int dWidth = style.width.length() > 0 ? Integer.parseInt(style.width) : 0;
112+
int dHeight = style.height.length() > 0 ? Integer.parseInt(style.height) : 0;
102113
if (xx < 0) {
103114
xx = 0;
104115
} else if (xx > gWidth - dWidth - 2) {

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/dnd/ScaleDND.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package org.eclipse.swt.internal.dnd;
1515

1616
import org.eclipse.swt.graphics.Point;
17+
import org.eclipse.swt.internal.xhtml.CSSStyle;
1718
import org.eclipse.swt.internal.xhtml.document;
1819

1920
/**
@@ -32,8 +33,9 @@ public boolean dragBegan(DragEvent e) {
3233
} else {
3334
isHorizontal = false;
3435
}
35-
this.sourceX = Integer.parseInt (e.sourceElement.style.left);
36-
this.sourceY = Integer.parseInt (e.sourceElement.style.top);
36+
CSSStyle style = e.sourceElement.style;
37+
this.sourceX = style.left.length() > 0 ? Integer.parseInt (style.left) : 0;
38+
this.sourceY = style.top.length() > 0 ? Integer.parseInt (style.top) : 0;
3739
/* first time, set start location to current location */
3840
e.startX = e.currentX;
3941
e.startY = e.currentY;
@@ -53,15 +55,17 @@ public boolean dragEnded(DragEvent e) {
5355
protected Point currentLocation(DragEvent e) {
5456
int xx = this.sourceX + e.deltaX ();
5557
int yy = this.sourceY + e.deltaY ();
58+
CSSStyle parentStyle = e.sourceElement.parentNode.style;
5659

57-
int gHeight = Integer.parseInt(e.sourceElement.parentNode.style.height);
58-
int gWidth = Integer.parseInt(e.sourceElement.parentNode.style.width);
60+
int gHeight = parentStyle.height.length() > 0 ? Integer.parseInt(parentStyle.height) : 0;
61+
int gWidth = parentStyle.width.length() > 0 ? Integer.parseInt(parentStyle.width) : 0;
5962
/*
6063
* On mozilla, the mousemove event can contain mousemove
6164
* outside the browser window, so make bound for the dragging.
6265
*/
63-
int dWidth = Integer.parseInt(e.sourceElement.style.width);
64-
int dHeight = Integer.parseInt(e.sourceElement.style.height);
66+
CSSStyle style = e.sourceElement.style;
67+
int dWidth = style.width.length() > 0 ? Integer.parseInt(style.width) : 0;
68+
int dHeight = style.height.length() > 0 ? Integer.parseInt(style.height) : 0;
6569
if (isHorizontal) {
6670
//if (dWidth == NaN) {
6771
dWidth = 10;

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/dnd/ShellFrameDND.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package org.eclipse.swt.internal.dnd;
1515

1616
import org.eclipse.swt.internal.browser.OS;
17+
import org.eclipse.swt.internal.xhtml.CSSStyle;
1718
import org.eclipse.swt.internal.xhtml.Element;
1819
import org.eclipse.swt.internal.xhtml.HTMLEvent;
1920
import org.eclipse.swt.internal.xhtml.document;
@@ -77,10 +78,12 @@ public boolean dragBegan(DragEvent e) {
7778
this.frame.style.top = this.sourceY + "px";
7879
this.frame.style.display = "block";
7980
}
80-
this.sourceX = Integer.parseInt (e.sourceElement.style.left);
81-
this.sourceY = Integer.parseInt (e.sourceElement.style.top);
82-
this.sourceWidth = Integer.parseInt (e.sourceElement.style.width);
83-
this.sourceHeight = Integer.parseInt (e.sourceElement.style.height);
81+
82+
CSSStyle style = e.sourceElement.style;
83+
this.sourceX = style.left.length() > 0 ? Integer.parseInt (style.left) : 0;
84+
this.sourceY = style.top.length() > 0 ? Integer.parseInt (style.top) : 0;
85+
this.sourceWidth = style.width.length() > 0 ? Integer.parseInt (style.width) : 0;
86+
this.sourceHeight = style.height.length() > 0 ? Integer.parseInt (style.height) : 0;
8487
/* first time, set start location to current location */
8588
e.startX = e.currentX;
8689
e.startY = e.currentY;
@@ -169,7 +172,8 @@ public boolean dragging(DragEvent e) {
169172
* On mozilla, the mousemove event can contain mousemove
170173
* outside the browser window, so make bound for the dragging.
171174
*/
172-
int dWidth = Integer.parseInt(e.sourceElement.style.width);
175+
CSSStyle style = e.sourceElement.style;
176+
int dWidth = style.width.length() > 0 ? Integer.parseInt(style.width) : 0;
173177
if (xx < -dWidth) {
174178
xx = -dWidth;
175179
} else if (xx > gWidth - 2) {
@@ -192,7 +196,8 @@ public boolean dragging(DragEvent e) {
192196
} else if (Math.abs (xx) < 10) {
193197
xx = 0;
194198
}
195-
int dHeight = Integer.parseInt(e.sourceElement.style.height);
199+
200+
int dHeight = style.height.length() > 0 ? Integer.parseInt(style.height) : 0;
196201
if (Math.abs (yy - gHeight + dHeight + 2) < 10) {
197202
yy = gHeight - dHeight - 2;
198203
} else if (Math.abs (yy - (-1)) < 10) {
@@ -213,10 +218,11 @@ public boolean dragging(DragEvent e) {
213218
return true;
214219
};
215220
public boolean dragEnded(DragEvent e) {
216-
int x = Integer.parseInt (this.frame.style.left);
217-
int y = Integer.parseInt (this.frame.style.top);
218-
int width = Integer.parseInt (this.frame.style.width);
219-
int height = Integer.parseInt (this.frame.style.height);
221+
CSSStyle style = this.frame.style;
222+
int x = Integer.parseInt (style.left);
223+
int y = Integer.parseInt (style.top);
224+
int width = Integer.parseInt (style.width);
225+
int height = Integer.parseInt (style.height);
220226
Element shell = e.sourceElement;
221227
// shell.style.left = x + "px";
222228
// shell.style.top = y + "px";
@@ -249,7 +255,8 @@ public boolean dragCanceled(DragEvent e) {
249255
return true;
250256
};
251257
public static void fixShellHeight(Object shell) {
252-
int height = Integer.parseInt (((Element) shell).style.height);
258+
CSSStyle style = ((Element) shell).style;
259+
int height = style.height.length() > 0 ? Integer.parseInt (style.height) : 0;
253260
Element[] divs = ((Element) shell).getElementsByTagName ("DIV");
254261
for (int i = 0; i < divs.length; i++) {
255262
//Element div = divs.item (i);
@@ -274,7 +281,8 @@ public static void fixShellWidth(Object shell) {
274281
// var needToFixedWidth = ("\n".split (/\n/).length != 2)
275282
// || navigator.userAgent.toLowerCase ().indexOf ("opera") != -1;
276283
boolean needToFixedWidth = true;
277-
int width = Integer.parseInt (((Element) shell).style.width) - 6;
284+
CSSStyle style = ((Element) shell).style;
285+
int width = style.width.length() > 0 ? Integer.parseInt (style.width) - 6 : 0;
278286
Element[] divs = ((Element) shell).getElementsByTagName ("DIV");
279287
for (int i = 0; i < divs.length; i++) {
280288
//Element div = divs.item (i);

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/dnd/SliderDND.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package org.eclipse.swt.internal.dnd;
1515

16+
import org.eclipse.swt.internal.xhtml.CSSStyle;
17+
1618

1719
/**
1820
* @author josson smith
@@ -30,8 +32,9 @@ public boolean dragBegan(DragEvent e) {
3032
} else {
3133
isHorizontal = false;
3234
}
33-
this.sourceX = Integer.parseInt (e.sourceElement.style.left);
34-
this.sourceY = Integer.parseInt (e.sourceElement.style.top);
35+
CSSStyle style = e.sourceElement.style;
36+
this.sourceX = style.left.length() > 0 ? Integer.parseInt (e.sourceElement.style.left) : 0;
37+
this.sourceY = style.top.length() > 0 ? Integer.parseInt (e.sourceElement.style.top) : 0;
3538
/* first time, set start location to current location */
3639
e.startX = e.currentX;
3740
e.startY = e.currentY;

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/dnd/TableColumnDND.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package org.eclipse.swt.internal.dnd;
1515

1616
import org.eclipse.swt.graphics.Point;
17+
import org.eclipse.swt.internal.xhtml.CSSStyle;
1718
import org.eclipse.swt.internal.xhtml.Element;
1819
import org.eclipse.swt.internal.xhtml.document;
1920

@@ -45,7 +46,8 @@ public boolean dragBegan(DragEvent e) {
4546
e.sourceElement.parentNode.appendChild (thumb);
4647
}
4748

48-
this.sourceX = Integer.parseInt (e.sourceElement.style.left);
49+
CSSStyle style = e.sourceElement.style;
50+
this.sourceX = style.left.length() > 0 ? Integer.parseInt (style.left) : 0;
4951
/* first time, set start location to current location */
5052
e.startX = e.currentX;
5153
return true;
@@ -68,13 +70,15 @@ protected void clean() {
6870

6971
protected Point currentLocation(DragEvent e) {
7072
int xx = this.sourceX + e.deltaX ();
73+
CSSStyle parentStyle = e.sourceElement.parentNode.style;
7174

72-
int gWidth = Integer.parseInt(e.sourceElement.parentNode.style.width);
75+
int gWidth = parentStyle.width.length() > 0 ? Integer.parseInt(parentStyle.width) : 0;
7376
/*
7477
* On mozilla, the mousemove event can contain mousemove
7578
* outside the browser window, so make bound for the dragging.
7679
*/
77-
int dWidth = Integer.parseInt(e.sourceElement.style.width);
80+
CSSStyle style = e.sourceElement.style;
81+
int dWidth = style.width.length() > 0 ? Integer.parseInt(style.width) : 0;
7882
if (xx < 0) {
7983
xx = 0;
8084
} else if (xx > gWidth - dWidth - 2) {

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/ColorDialog.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.eclipse.swt.internal.dnd.DragAndDrop;
2424
import org.eclipse.swt.internal.dnd.DragEvent;
2525
import org.eclipse.swt.internal.dnd.HTMLEventWrapper;
26+
import org.eclipse.swt.internal.xhtml.CSSStyle;
2627
import org.eclipse.swt.internal.xhtml.Element;
2728
import org.eclipse.swt.internal.xhtml.document;
2829
import org.eclipse.swt.layout.GridData;
@@ -759,7 +760,8 @@ public boolean dragging(DragEvent e) {
759760
return true;
760761
}
761762
public boolean dragBegan(DragEvent e) {
762-
originalTop = Integer.parseInt(e.sourceElement.style.top);
763+
CSSStyle style = e.sourceElement.style;
764+
originalTop = style.top.length() > 0 ? Integer.parseInt(style.top) : 0;
763765
return true;
764766
}
765767
});

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/Menu.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.eclipse.swt.SWTException;
1717
import org.eclipse.swt.events.HelpListener;
1818
import org.eclipse.swt.events.MenuListener;
19+
import org.eclipse.swt.events.SelectionEvent;
1920
import org.eclipse.swt.graphics.Image;
2021
import org.eclipse.swt.graphics.Point;
2122
import org.eclipse.swt.graphics.Rectangle;
@@ -74,6 +75,8 @@ public class Menu extends Widget {
7475

7576
long lastFocusdTime;
7677

78+
Object[] acceleratorTable;
79+
7780
/* Resource ID for SHMENUBARINFO */
7881
static final int ID_PPC = 100;
7982

@@ -84,7 +87,7 @@ public class Menu extends Widget {
8487
static final int ID_SPBB = 105;
8588
static final int ID_SPSOFTKEY0 = 106;
8689
static final int ID_SPSOFTKEY1 = 107;
87-
90+
static final int GROWTH_RATE = 5;
8891
/**
8992
* Constructs a new instance of this class given its parent,
9093
* and sets the style for the instance so that the instance
@@ -778,6 +781,38 @@ void destroyAccelerators () {
778781
parent.destroyAccelerators ();
779782
}
780783

784+
void registerAccelerator(int accelerator, MenuItem item){
785+
if(acceleratorTable == null){
786+
acceleratorTable = new Object[0];
787+
}
788+
int size = acceleratorTable.length;
789+
acceleratorTable[size] = new Integer(accelerator);
790+
acceleratorTable[size+1] = item;
791+
}
792+
793+
boolean isAccelerated(HTMLEvent keyEvent){
794+
int size = acceleratorTable.length;
795+
for(int i = 0; i < size; i+=2){
796+
int acclCode = ((Integer) acceleratorTable[i]).intValue();
797+
if(
798+
(((acclCode & SWT.CONTROL) != 0 && keyEvent.ctrlKey) || ((acclCode & SWT.CONTROL) == 0 )) &&
799+
(((acclCode & SWT.ALT) != 0 && keyEvent.altKey) || ((acclCode & SWT.ALT) == 0)) &&
800+
((acclCode & SWT.SHIFT) != 0 && keyEvent.shiftKey) || ((acclCode & SWT.SHIFT) == 0)
801+
) {
802+
acclCode &= ~(SWT.ALT | SWT.SHIFT | SWT.CONTROL);
803+
if(acclCode == keyEvent.keyCode){
804+
MenuItem item = (MenuItem) acceleratorTable[i+1];
805+
/**
806+
* @j2sNative
807+
* item.handle.onclick();
808+
*
809+
*/{}
810+
}
811+
}
812+
}
813+
return false;
814+
}
815+
781816
void destroyItem (MenuItem item) {
782817
try {
783818
handle.removeChild(item.handle);

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/Scale.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.eclipse.swt.internal.dnd.DragAndDrop;
2121
import org.eclipse.swt.internal.dnd.DragEvent;
2222
import org.eclipse.swt.internal.dnd.ScaleDND;
23+
import org.eclipse.swt.internal.xhtml.CSSStyle;
2324
import org.eclipse.swt.internal.xhtml.Element;
2425
import org.eclipse.swt.internal.xhtml.document;
2526

@@ -503,11 +504,12 @@ public int getPageIncrement () {
503504
public int getSelection () {
504505
checkWidget ();
505506
//return OS.SendMessage (handle, OS.TBM_GETPOS, 0, 0);
507+
CSSStyle thumbStyle = thumbHandle.style;
506508
if ((style & SWT.HORIZONTAL) != 0) {
507-
int left = Integer.parseInt(thumbHandle.style.left);
509+
int left = thumbStyle.left.length() > 0 ? Integer.parseInt(thumbStyle.left) : 0;
508510
selection = left * maximum / (getSize().x - 12);
509511
} else {
510-
int top = Integer.parseInt(thumbHandle.style.top);
512+
int top = thumbStyle.top.length() > 0 ? Integer.parseInt(thumbStyle.top) : 0;
511513
selection = maximum - top * maximum / (getSize().y - 12);
512514
}
513515
return selection;

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/Slider.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.eclipse.swt.internal.dnd.DragAndDrop;
2121
import org.eclipse.swt.internal.dnd.DragEvent;
2222
import org.eclipse.swt.internal.dnd.SliderDND;
23+
import org.eclipse.swt.internal.xhtml.CSSStyle;
2324
import org.eclipse.swt.internal.xhtml.Element;
2425
import org.eclipse.swt.internal.xhtml.document;
2526

@@ -320,9 +321,10 @@ public boolean dragEnded(DragEvent e) {
320321
protected Point currentLocation(DragEvent e) {
321322
int xx = this.sourceX + e.deltaX ();
322323
int yy = this.sourceY + e.deltaY ();
324+
CSSStyle parentStyle = e.sourceElement.parentNode.style;
323325

324-
int gHeight = Integer.parseInt(e.sourceElement.parentNode.style.height);
325-
int gWidth = Integer.parseInt(e.sourceElement.parentNode.style.width);
326+
int gHeight = parentStyle.height.length() > 0 ? Integer.parseInt(parentStyle.height) : 0;
327+
int gWidth = parentStyle.width.length() > 0 ? Integer.parseInt(parentStyle.width) : 0;
326328
/*
327329
* On mozilla, the mousemove event can contain mousemove
328330
* outside the browser window, so make bound for the dragging.

0 commit comments

Comments
 (0)