Skip to content

Commit 189416b

Browse files
hansonrhansonr
authored andcommitted
Keyboard accessors out; proper layout management;
Does not include new focus management in core yet
1 parent bd69ec0 commit 189416b

Some content is hidden

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

69 files changed

+2633
-831
lines changed
5.8 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190618062841
1+
20190627113444
5.8 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190618062841
1+
20190627113444
5.8 KB
Binary file not shown.

sources/net.sf.j2s.java.core/src/java/awt/AWTEvent.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public abstract class AWTEvent extends EventObject {
131131
//
132132
transient boolean focusManagerIsDispatching = false;
133133
transient boolean isPosted;
134+
134135

135136
// /**
136137
// * Indicates whether this AWTEvent was generated by the system as
@@ -281,6 +282,12 @@ public abstract class AWTEvent extends EventObject {
281282
// public void setPosted(AWTEvent ev) {
282283
// ev.isPosted = true;
283284
// }
285+
286+
public void setPosted() {
287+
// swingJS
288+
isPosted = true;
289+
}
290+
284291
//
285292
// public AccessControlContext getAccessControlContext(AWTEvent ev) {
286293
// return ev.getAccessControlContext();

sources/net.sf.j2s.java.core/src/java/awt/Component.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
import java.util.Set;
6969
import java.util.Vector;
7070

71+
import javax.swing.JComponent;
72+
7173
import sun.awt.AppContext;
7274
import sun.awt.CausedFocusEvent;
7375
import sun.awt.RequestFocusController;
@@ -388,7 +390,7 @@ public AppContext getAppContext() {
388390
* @see #getFocusTraversalKeysEnabled
389391
* @since 1.4
390392
*/
391-
private boolean focusTraversalKeysEnabled = false;// true;
393+
private boolean focusTraversalKeysEnabled = true;
392394

393395
/**
394396
* The locking object for AWT component-tree and layout operations.
@@ -738,6 +740,8 @@ void setBoundsOp(int op) {
738740
// return comp.getAccessControlContext();
739741
// }
740742
//
743+
744+
741745
// public void setBackgroundEraseDisabled(Component comp, boolean disabled)
742746
// {
743747
// comp.backgroundEraseDisabled = disabled;
@@ -747,10 +751,16 @@ void setBoundsOp(int op) {
747751
// return comp.backgroundEraseDisabled;
748752
// }
749753
//
750-
public Rectangle getBounds(Component comp) {
751-
return new Rectangle(comp.x, comp.y, comp.width, comp.height);
754+
755+
public void setBackgroundEraseDisabled(boolean disabled) {
756+
backgroundEraseDisabled = disabled;
752757
}
753758

759+
public boolean getBackgroundEraseDisabled() {
760+
return backgroundEraseDisabled;
761+
}
762+
763+
754764
public boolean requestFocusInWindow(Component comp, CausedFocusEvent.Cause cause) {
755765
return comp.requestFocusInWindow(cause);
756766
}
@@ -1121,7 +1131,7 @@ public boolean isVisible() {
11211131
return isVisible_NoClientCode();
11221132
}
11231133

1124-
protected final boolean isVisible_NoClientCode() {
1134+
public final boolean isVisible_NoClientCode() {
11251135
return visible;
11261136
}
11271137

@@ -3048,6 +3058,10 @@ public void repaint(int x, int y, int width, int height) {
30483058
* @since JDK1.0
30493059
*/
30503060
public void repaint(long tm, int x, int y, int width, int height) {
3061+
秘repaintCmp(tm, x, y, width, height);
3062+
}
3063+
3064+
protected void 秘repaintCmp(long tm, int x, int y, int width, int height) {
30513065
// System.out.println("C repaint " + this.name);
30523066
if (canPaint()) {
30533067
// System.out.println("C firing Paint event on " + this.name);
@@ -6345,7 +6359,7 @@ public void requestFocus() {
63456359
requestFocusHelper(false, true);
63466360
}
63476361

6348-
void requestFocus(CausedFocusEvent.Cause cause) {
6362+
public void requestFocus(CausedFocusEvent.Cause cause) {
63496363
requestFocusHelper(false, true, cause);
63506364
}
63516365

@@ -6623,17 +6637,20 @@ private boolean isRequestFocusAccepted(boolean temporary, boolean focusedWindowC
66236637
return true;
66246638
}
66256639

6640+
if (requestFocusController == null)
6641+
requestFocusController = JComponent.focusController;
66266642
boolean ret = requestFocusController.acceptRequestFocus(focusOwner, this, temporary, focusedWindowChangeAllowed,
66276643
cause);
66286644
return ret;
66296645
}
66306646

6631-
private static RequestFocusController requestFocusController = new DummyRequestFocusController();
6647+
private static RequestFocusController requestFocusController;// = new DummyRequestFocusController();
66326648

66336649
// Swing access this method through reflection to implement
66346650
// InputVerifier's functionality.
66356651
// Perhaps, we should make this method public (later ;)
66366652
private static class DummyRequestFocusController implements RequestFocusController {
6653+
@Override
66376654
public boolean acceptRequestFocus(Component from, Component to, boolean temporary,
66386655
boolean focusedWindowChangeAllowed, CausedFocusEvent.Cause cause) {
66396656
return true;

sources/net.sf.j2s.java.core/src/java/awt/Container.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,16 +1567,18 @@ public void invalidate() {
15671567
@Override
15681568
public void validate() {
15691569
/* Avoid grabbing lock unless really necessary. */
1570-
if (!isValid()) {
1570+
if (!isValid() && peer != null) {
15711571
synchronized (getTreeLock()) {
15721572

1573+
// validation in AWT prior to addNotify will cause NPE for TextArea without font
1574+
15731575
// for SwingJS ALL components must have peers. might as well do that
15741576
// now.
15751577
// I think there was a notification threading issue that the root pane
15761578
// was not
15771579
// getting its peer in time for validation.
1578-
if (peer == null)
1579-
peer = getToolkit().createComponent(this);
1580+
// if (peer == null)
1581+
// peer = getToolkit().createComponent(this);
15801582
int n = component.size();
15811583
if (!isValid() && peer != null && n > 0) {
15821584
ContainerPeer p = null;
@@ -3298,23 +3300,22 @@ void clearMostRecentFocusOwnerOnHide() {
32983300

32993301
@Override
33003302
protected void clearCurrentFocusCycleRootOnHide() {
3301-
// KeyboardFocusManager kfm =
3302-
// KeyboardFocusManager.getCurrentKeyboardFocusManager();
3303-
// Container cont = kfm.getCurrentFocusCycleRoot();
3304-
//
3305-
// if (cont == this || isParentOf(cont)) {
3306-
// kfm.setGlobalCurrentFocusCycleRoot(null);
3307-
// }
3303+
KeyboardFocusManager kfm =
3304+
KeyboardFocusManager.getCurrentKeyboardFocusManager();
3305+
Container cont = kfm.getCurrentFocusCycleRoot();
3306+
3307+
if (cont == this || isParentOf(cont)) {
3308+
kfm.setGlobalCurrentFocusCycleRoot(null);
3309+
}
33083310
}
33093311

33103312
@Override
33113313
final Container getTraversalRoot() {
3312-
// if (isFocusCycleRoot()) {
3313-
// return findTraversalRoot();
3314-
// }
3315-
//
3316-
// return super.getTraversalRoot();
3317-
return null;
3314+
if (isFocusCycleRoot()) {
3315+
return findTraversalRoot();
3316+
}
3317+
3318+
return super.getTraversalRoot();
33183319
}
33193320

33203321
/**
@@ -3374,6 +3375,9 @@ public FocusTraversalPolicy getFocusTraversalPolicy() {
33743375
Container rootAncestor = getFocusCycleRootAncestor();
33753376
if (rootAncestor != null) {
33763377
return rootAncestor.getFocusTraversalPolicy();
3378+
} else if (秘isAWT()) {
3379+
return KeyboardFocusManager.getCurrentKeyboardFocusManager().
3380+
getDefaultAWTFocusTraversalPolicy();
33773381
} else {
33783382
return KeyboardFocusManager.getCurrentKeyboardFocusManager().
33793383
getDefaultFocusTraversalPolicy();

sources/net.sf.j2s.java.core/src/java/awt/ContainerOrderFocusTraversalPolicy.java

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@
2424
*/
2525
package java.awt;
2626

27-
import java.util.List;
2827
import java.util.ArrayList;
29-
import sun.util.logging.PlatformLogger;
28+
import java.util.List;
3029

3130
/**
3231
* A FocusTraversalPolicy that determines traversal order based on the order
@@ -102,12 +101,14 @@ public class ContainerOrderFocusTraversalPolicy extends FocusTraversalPolicy
102101
* the 2nd point but just override the implementation of the 1st one.
103102
* A striking example of such a descendant is the javax.swing.SortingFocusTraversalPolicy.
104103
*/
105-
/*protected*/ private List<Component> getFocusTraversalCycle(Container aContainer) {
104+
/* protected*/ private List<Component> getFocusTraversalCycle(Container aContainer) {
105+
// change from protected was Java, not SwingJS
106106
List<Component> cycle = new ArrayList<Component>();
107107
enumerateCycle(aContainer, cycle);
108108
return cycle;
109109
}
110110
/*protected*/ private int getComponentIndex(List<Component> cycle, Component aComponent) {
111+
// change from protected was Java, not SwingJS
111112
return cycle.indexOf(aComponent);
112113
}
113114

@@ -120,7 +121,10 @@ private void enumerateCycle(Container container, List<Component> cycle) {
120121

121122
Component[] components = container.getChildArray();
122123
for (int i = 0, n = container.getComponentCount(); i < n; i++) {
123-
Component comp = components[i];
124+
// SwingJS adding check for JTextArea and JEditorPane, which
125+
// cannot accept tab focus in HTML5 because they cannot
126+
// break out of it.
127+
JSComponent comp = (JSComponent) components[i];
124128
if (comp instanceof Container) {
125129
Container cont = (Container)comp;
126130

@@ -207,7 +211,8 @@ private Component getComponentDownCycle(Component comp, int traversalDirection)
207211
* root of aComponent or focus traversal policy provider, or if either aContainer or
208212
* aComponent is null
209213
*/
210-
public Component getComponentAfter(Container aContainer, Component aComponent) {
214+
@Override
215+
public Component getComponentAfter(Container aContainer, Component aComponent) {
211216
// if (log.isLoggable(PlatformLogger.Level.FINE)) {
212217
// log.fine("### Searching in " + aContainer + " for component after " + aComponent);
213218
// }
@@ -222,7 +227,7 @@ public Component getComponentAfter(Container aContainer, Component aComponent) {
222227
throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
223228
}
224229

225-
synchronized(aContainer.getTreeLock()) {
230+
// synchronized(aContainer.getTreeLock()) {
226231

227232
if (!(aContainer.isVisible() && aContainer.isDisplayable())) {
228233
return null;
@@ -292,7 +297,7 @@ public Component getComponentAfter(Container aContainer, Component aComponent) {
292297

293298
return comp;
294299
}
295-
}
300+
// }
296301
return null;
297302
}
298303

@@ -311,7 +316,8 @@ public Component getComponentAfter(Container aContainer, Component aComponent) {
311316
* root of aComponent or focus traversal policy provider, or if either aContainer or
312317
* aComponent is null
313318
*/
314-
public Component getComponentBefore(Container aContainer, Component aComponent) {
319+
@Override
320+
public Component getComponentBefore(Container aContainer, Component aComponent) {
315321
if (aContainer == null || aComponent == null) {
316322
throw new IllegalArgumentException("aContainer and aComponent cannot be null");
317323
}
@@ -408,7 +414,8 @@ public Component getComponentBefore(Container aContainer, Component aComponent)
408414
* or null if no suitable Component can be found
409415
* @throws IllegalArgumentException if aContainer is null
410416
*/
411-
public Component getFirstComponent(Container aContainer) {
417+
@Override
418+
public Component getFirstComponent(Container aContainer) {
412419
List<Component> cycle;
413420

414421
// if (log.isLoggable(PlatformLogger.Level.FINE)) {
@@ -419,7 +426,7 @@ public Component getFirstComponent(Container aContainer) {
419426

420427
}
421428

422-
synchronized(aContainer.getTreeLock()) {
429+
// synchronized(aContainer.getTreeLock()) {
423430

424431
if (!(aContainer.isVisible() && aContainer.isDisplayable())) {
425432
return null;
@@ -442,6 +449,10 @@ public Component getFirstComponent(Container aContainer) {
442449
// }
443450

444451
for (Component comp : cycle) {
452+
453+
if (comp == aContainer)
454+
continue; // BH -- SwingJS HACK -- presuming that comp itself should somehow define first component implicitly?
455+
445456
if (accept(comp)) {
446457
return comp;
447458
} else if (comp != aContainer &&
@@ -450,7 +461,7 @@ public Component getFirstComponent(Container aContainer) {
450461
return comp;
451462
}
452463
}
453-
}
464+
// }
454465
return null;
455466
}
456467

@@ -465,7 +476,8 @@ public Component getFirstComponent(Container aContainer) {
465476
* or null if no suitable Component can be found
466477
* @throws IllegalArgumentException if aContainer is null
467478
*/
468-
public Component getLastComponent(Container aContainer) {
479+
@Override
480+
public Component getLastComponent(Container aContainer) {
469481
List<Component> cycle;
470482
// if (log.isLoggable(PlatformLogger.Level.FINE)) {
471483
// log.fine("### Getting last component in " + aContainer);
@@ -525,7 +537,8 @@ public Component getLastComponent(Container aContainer) {
525537
* @see #getFirstComponent
526538
* @throws IllegalArgumentException if aContainer is null
527539
*/
528-
public Component getDefaultComponent(Container aContainer) {
540+
@Override
541+
public Component getDefaultComponent(Container aContainer) {
529542
return getFirstComponent(aContainer);
530543
}
531544

sources/net.sf.j2s.java.core/src/java/awt/DefaultFocusTraversalPolicy.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public class DefaultFocusTraversalPolicy
9393
* @return <code>true</code> if aComponent meets the above requirements;
9494
* <code>false</code> otherwise
9595
*/
96-
protected boolean accept(Component aComponent) {
96+
@Override
97+
protected boolean accept(Component aComponent) {
9798
if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
9899
aComponent.isEnabled()))
99100
{
@@ -117,6 +118,9 @@ protected boolean accept(Component aComponent) {
117118
}
118119
}
119120

121+
// if (((JSComponent) aComponent).秘isNotTabFocusable())
122+
// return false; // SwingJS JLabel, JTextArea, JEditorPane
123+
//
120124
boolean focusable = aComponent.isFocusable();
121125
if (aComponent.isFocusTraversableOverridden()) {
122126
return focusable;

0 commit comments

Comments
 (0)