Skip to content

Commit 8572494

Browse files
hansonrhansonr
authored andcommitted
working on focus management
1 parent 3c93e5b commit 8572494

21 files changed

+3182
-3444
lines changed

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

Lines changed: 69 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
import java.util.Map;
6868
import java.util.Set;
6969
import java.util.Vector;
70-
import java.util.logging.Level;
7170

7271
import javax.swing.JInternalFrame;
7372

@@ -748,18 +747,17 @@ void setBoundsOp(int op) {
748747
// return comp.backgroundEraseDisabled;
749748
// }
750749
//
751-
// public Rectangle getBounds(Component comp) {
752-
// return new Rectangle(comp.x, comp.y, comp.width, comp.height);
753-
// }
754-
//
755-
// public boolean requestFocusInWindow(Component comp,
756-
// CausedFocusEvent.Cause cause) {
757-
// return comp.requestFocusInWindow(cause);
758-
// }
759-
//
760-
// public void requestFocus(Component comp, CausedFocusEvent.Cause cause) {
761-
// comp.requestFocus(cause);
762-
// }
750+
public Rectangle getBounds(Component comp) {
751+
return new Rectangle(comp.x, comp.y, comp.width, comp.height);
752+
}
753+
754+
public boolean requestFocusInWindow(Component comp, CausedFocusEvent.Cause cause) {
755+
return comp.requestFocusInWindow(cause);
756+
}
757+
758+
public void requestFocus(Component comp, CausedFocusEvent.Cause cause) {
759+
comp.requestFocus(cause);
760+
}
763761
//
764762
// public void setMixingCutoutShape(Component comp, Shape shape) {
765763
// Region region = shape == null ? null :
@@ -1356,7 +1354,7 @@ public void enable(boolean b) {
13561354
@Deprecated
13571355
public void disable() {
13581356
if (enabled) {
1359-
// KeyboardFocusManager.clearMostRecentFocusOwner(this);
1357+
KeyboardFocusManager.clearMostRecentFocusOwner(this);
13601358
// synchronized (getTreeLock()) {
13611359
enabled = false;
13621360
// A disabled lw container is allowed to contain a focus owner.
@@ -1397,47 +1395,45 @@ public boolean isDoubleBuffered() {
13971395
return false;
13981396
}
13991397

1400-
// /**
1401-
// * Enables or disables input method support for this component. If input
1402-
// * method support is enabled and the component also processes key events,
1403-
// * incoming events are offered to
1404-
// * the current input method and will only be processed by the component or
1405-
// * dispatched to its listeners if the input method does not consume them.
1406-
// * By default, input method support is enabled.
1407-
// *
1408-
// * @param enable true to enable, false to disable
1409-
// * @see #processKeyEvent
1410-
// * @since 1.2
1411-
// */
1412-
// public void enableInputMethods(boolean enable) {
1413-
// if (enable) {
1414-
// if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0)
1415-
// return;
1416-
//
1417-
// // If this component already has focus, then activate the
1418-
// // input method by dispatching a synthesized focus gained
1419-
// // event.
1420-
// if (isFocusOwner()) {
1421-
// InputContext inputContext = getInputContext();
1422-
// if (inputContext != null) {
1423-
// FocusEvent focusGainedEvent =
1424-
// new FocusEvent(this, FocusEvent.FOCUS_GAINED);
1425-
// inputContext.dispatchEvent(focusGainedEvent);
1426-
// }
1427-
// }
1428-
//
1429-
// eventMask |= AWTEvent.INPUT_METHODS_ENABLED_MASK;
1430-
// } else {
1431-
// if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) {
1432-
// InputContext inputContext = getInputContext();
1433-
// if (inputContext != null) {
1434-
// inputContext.endComposition();
1435-
// inputContext.removeNotify(this);
1436-
// }
1437-
// }
1438-
// eventMask &= ~AWTEvent.INPUT_METHODS_ENABLED_MASK;
1439-
// }
1440-
// }
1398+
/**
1399+
* Enables or disables input method support for this component. If input method
1400+
* support is enabled and the component also processes key events, incoming
1401+
* events are offered to the current input method and will only be processed by
1402+
* the component or dispatched to its listeners if the input method does not
1403+
* consume them. By default, input method support is enabled.
1404+
*
1405+
* @param enable true to enable, false to disable
1406+
* @see #processKeyEvent
1407+
* @since 1.2
1408+
*/
1409+
public void enableInputMethods(boolean enable) {
1410+
if (enable) {
1411+
if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0)
1412+
return;
1413+
1414+
// If this component already has focus, then activate the
1415+
// input method by dispatching a synthesized focus gained
1416+
// event.
1417+
if (isFocusOwner()) {
1418+
// InputContext inputContext = getInputContext();
1419+
// if (inputContext != null) {
1420+
// FocusEvent focusGainedEvent = new FocusEvent(this, FocusEvent.FOCUS_GAINED);
1421+
// inputContext.dispatchEvent(focusGainedEvent);
1422+
// }
1423+
}
1424+
1425+
eventMask |= AWTEvent.INPUT_METHODS_ENABLED_MASK;
1426+
} else {
1427+
if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) {
1428+
// InputContext inputContext = getInputContext();
1429+
// if (inputContext != null) {
1430+
// inputContext.endComposition();
1431+
// inputContext.removeNotify(this);
1432+
// }
1433+
}
1434+
eventMask &= ~AWTEvent.INPUT_METHODS_ENABLED_MASK;
1435+
}
1436+
}
14411437

14421438
/**
14431439
* Shows or hides this component depending on the value of parameter
@@ -3762,11 +3758,11 @@ protected void dispatchEventImplComp(AWTEvent e) {
37623758
/*
37633759
* 2. Allow the Toolkit to pass this to AWTEventListeners.
37643760
*/
3765-
3761+
37663762
// SwingJS: This allows a developer to watch any events they wish to follow.
3767-
3768-
Toolkit toolkit = Toolkit.getDefaultToolkit();
3769-
toolkit.notifyAWTEventListeners(e);
3763+
3764+
Toolkit toolkit = Toolkit.getDefaultToolkit();
3765+
toolkit.notifyAWTEventListeners(e);
37703766

37713767
/*
37723768
* 3. If no one has consumed a key event, allow the KeyboardFocusManager to
@@ -3777,9 +3773,9 @@ protected void dispatchEventImplComp(AWTEvent e) {
37773773
// check for tab navigation:
37783774
// KeyboardFocusManager.getCurrentKeyboardFocusManager().
37793775
// processKeyEvent(this, (KeyEvent)e);
3780-
//if (e.isConsumed()) {
3781-
// return;
3782-
//}
3776+
// if (e.isConsumed()) {
3777+
// return;
3778+
// }
37833779
}
37843780
}
37853781

@@ -4543,8 +4539,8 @@ public synchronized void addKeyListener(KeyListener l) {
45434539
keyListener = AWTEventMulticaster.add(keyListener, l);
45444540
newEventsOnly = true;
45454541

4546-
// if this is a lightweight component, enable key events
4547-
// in the native container.
4542+
// if this is a lightweight component, enable key events
4543+
// in the native container.
45484544
// if (peer instanceof LightweightPeer) {
45494545
// parent.proxyEnableEvents(AWTEvent.KEY_EVENT_MASK);
45504546
// }
@@ -5210,7 +5206,8 @@ protected void processEvent(AWTEvent e) {
52105206
}
52115207

52125208
protected void processEventComp(AWTEvent e) {
5213-
boolean isActiveRetarget = /**@j2sNative !!e.dispatch$ ||*/false;
5209+
boolean isActiveRetarget = /** @j2sNative !!e.dispatch$ || */
5210+
false;
52145211
if (isActiveRetarget || e instanceof ActiveEvent) {
52155212
// SwingJS added because we are bypassing the standard queue
52165213
((ActiveEvent) e).dispatch();
@@ -5841,9 +5838,9 @@ protected void addNotifyComp() {
58415838
//
58425839
peerFont = getFont();
58435840

5844-
if (getContainer() != null && !isAddNotifyComplete) {
5845-
getContainer().increaseComponentCount(this);
5846-
}
5841+
// if (getContainer() != null && !isAddNotifyComplete) {
5842+
// getContainer().increaseComponentCount(this);
5843+
// }
58475844

58485845
// Update stacking order
58495846
if (parent != null && parent.peer != null) {
@@ -5926,9 +5923,9 @@ protected void removeNotifyComp() {
59265923
// transferFocus(true);
59275924
// }
59285925

5929-
if (getContainer() != null && isAddNotifyComplete) {
5930-
getContainer().decreaseComponentCount(this);
5931-
}
5926+
// if (getContainer() != null && isAddNotifyComplete) {
5927+
// getContainer().decreaseComponentCount(this);
5928+
// }
59325929

59335930
// int npopups = (popups != null? popups.size() : 0);
59345931
// SwingJS TODO for (int i = 0 ; i < npopups ; i++) {
@@ -6564,8 +6561,7 @@ final boolean requestFocusHelper(boolean temporary, boolean focusedWindowChangeA
65646561
if (!success) {
65656562
KeyboardFocusManager.getCurrentKeyboardFocusManager(appContext).dequeueKeyEvents(time, this);
65666563
} else {
6567-
6568-
6564+
65696565
}
65706566
return success;
65716567
}
@@ -6852,7 +6848,6 @@ public void transferFocusUpCycle() {
68526848
* @since 1.2
68536849
*/
68546850
public boolean hasFocus() {
6855-
// return JSToolkit.hasFocus(this);
68566851
return (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == this);
68576852
}
68586853

0 commit comments

Comments
 (0)