Skip to content

Commit bc47990

Browse files
hansonrhansonr
authored andcommitted
SwingJS-site.zip and test files
1 parent bdc67b1 commit bc47990

File tree

9 files changed

+882
-831
lines changed

9 files changed

+882
-831
lines changed
1.41 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190225071046
1+
20190228144323
1.41 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190225071046
1+
20190228144323
1.41 KB
Binary file not shown.

sources/net.sf.j2s.java.core/src/javax/swing/SwingUtilities.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public static Rectangle getLocalBounds(Component aComponent) {
145145
*/
146146
public static Window getWindowAncestor(Component c) {
147147
for(Container p = c.getParent(); p != null; p = p.getParent()) {
148-
if (p instanceof Window) {
148+
if (p.isWindowOrJSApplet()) {
149149
return (Window)p;
150150
}
151151
}
@@ -158,7 +158,7 @@ public static Window getWindowAncestor(Component c) {
158158
*/
159159
static Point convertScreenLocationToParent(Container parent,int x, int y) {
160160
for (Container p = parent; p != null; p = p.getParent()) {
161-
if (p instanceof Window) {
161+
if (p != null && p.isWindowOrJSApplet()) {
162162
Point point = new Point(x, y);
163163

164164
SwingUtilities.convertPointFromScreen(point, parent);
@@ -380,13 +380,12 @@ else if (sourceEvent instanceof MenuDragMouseEvent) {
380380
public static void convertPointToScreen(Point p,Component c) {
381381
// Rectangle b;
382382
int x,y;
383-
383+
boolean done = false;
384384
do {
385385
if(c instanceof JComponent) {
386386
x = ((JComponent)c).getX();
387387
y = ((JComponent)c).getY();
388-
} else if(c instanceof JSApplet ||
389-
c instanceof Window) {
388+
} else if((done = c.isWindowOrJSApplet())) {
390389
try {
391390
Point pp = c.getLocationOnScreen();
392391
x = pp.x;
@@ -402,11 +401,8 @@ public static void convertPointToScreen(Point p,Component c) {
402401

403402
p.x += x;
404403
p.y += y;
405-
406-
if(c instanceof Window || c instanceof JSApplet)
407-
break;
408404
c = c.getParent();
409-
} while(c != null);
405+
} while(c != null && !done);
410406
}
411407

412408
/**
@@ -424,8 +420,7 @@ public static void convertPointFromScreen(Point p,Component c) {
424420
if(c instanceof JComponent) {
425421
x = ((JComponent)c).getX();
426422
y = ((JComponent)c).getY();
427-
} else if(c instanceof JSApplet ||
428-
c instanceof Window) {
423+
} else if(c.isWindowOrJSApplet()) {
429424
try {
430425
Point pp = c.getLocationOnScreen();
431426
x = pp.x;
@@ -442,7 +437,7 @@ public static void convertPointFromScreen(Point p,Component c) {
442437
p.x -= x;
443438
p.y -= y;
444439

445-
if(c instanceof Window || c instanceof JSApplet)
440+
if(c.isWindowOrJSApplet())
446441
break;
447442
c = c.getParent();
448443
} while(c != null);
@@ -1530,7 +1525,7 @@ public static Component findFocusOwner(Component c) {
15301525

15311526
// verify focusOwner is a descendant of c
15321527
for (Component temp = focusOwner; temp != null;
1533-
temp = (temp instanceof Window) ? null : temp.getParent())
1528+
temp = (temp.isWindowOrJSApplet() ? null : temp.getParent()))
15341529
{
15351530
if (temp == c) {
15361531
return focusOwner;
@@ -1563,16 +1558,12 @@ public static JRootPane getRootPane(Component c) {
15631558
* @return the first ancestor of c that's a Window or the last Applet ancestor
15641559
*/
15651560
public static Component getRoot(Component c) {
1566-
Component applet = null;
15671561
for(Component p = c; p != null; p = p.getParent()) {
1568-
if (p instanceof Window) {
1562+
if (p.isWindowOrJSApplet()) {
15691563
return p;
15701564
}
1571-
if (p instanceof JSApplet) {
1572-
applet = p;
1573-
}
15741565
}
1575-
return applet;
1566+
return null;
15761567
}
15771568

15781569
// SwingJS never used - see JComponent

sources/net.sf.j2s.java.core/src/test/TApp2.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import java.awt.TextField;
1515
import java.awt.event.AdjustmentEvent;
1616
import java.awt.event.AdjustmentListener;
17+
import java.awt.event.FocusEvent;
18+
import java.awt.event.FocusListener;
1719
import java.awt.event.MouseEvent;
1820
import java.awt.event.MouseListener;
1921

@@ -38,6 +40,19 @@ public void init() {
3840
TextField tf = new TextField("Text");
3941
tf.setBounds(5, 5, 50, 24);
4042
tf.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 20));
43+
tf.addFocusListener(new FocusListener() {
44+
45+
@Override
46+
public void focusGained(FocusEvent e) {
47+
System.out.println("tf " + e.paramString());
48+
}
49+
50+
@Override
51+
public void focusLost(FocusEvent e) {
52+
System.out.println("tf " + e.paramString());
53+
}
54+
55+
});
4156
panel.add(tf);
4257
// Label label = new Label("blue", Label.RIGHT);
4358
// label.setBounds(10, 10, 50, 60);
@@ -55,9 +70,22 @@ public void init() {
5570
// and then only if the append is AFTER the add
5671
ta = new TextArea("A text\nwith some\nlines and\n no content.");
5772
add(ta);
58-
ta.setBounds(200, 70, 150, 150);
73+
ta.setBounds(200, 70, 200,200);
5974
ta.setFont(new Font(Font.DIALOG, Font.BOLD, 20));
6075
ta.appendText("A text\nwith some\nlines and\n no content.");
76+
ta.addFocusListener(new FocusListener() {
77+
78+
@Override
79+
public void focusGained(FocusEvent e) {
80+
System.out.println("ta " + e.paramString());
81+
}
82+
83+
@Override
84+
public void focusLost(FocusEvent e) {
85+
System.out.println("ta " + e.paramString());
86+
}
87+
88+
});
6189

6290

6391
// TextArea ta = new TextArea("A text\nwith some\nlines and\n no content.");

0 commit comments

Comments
 (0)