--- a/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java Thu May 10 11:47:56 2012 -0700
@@ -372,7 +372,7 @@
}
@Override
- public void dispose() {
+ public final void dispose() {
if (disposed.compareAndSet(false, true)) {
disposeImpl();
}
--- a/jdk/src/macosx/classes/sun/lwawt/LWCursorManager.java Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/macosx/classes/sun/lwawt/LWCursorManager.java Thu May 10 11:47:56 2012 -0700
@@ -88,20 +88,20 @@
} else {
cursor = (c != null) ? c.getCursor() : null;
}
- // TODO: default cursor for modal blocked windows
setCursor(cursor);
}
/**
* Returns the first visible, enabled and showing component under cursor.
+ * Returns null for modal blocked windows.
*
* @param cursorPos Current cursor position.
- * @return Component
+ * @return Component or null.
*/
private static final Component findComponent(final Point cursorPos) {
final LWComponentPeer<?, ?> peer = LWWindowPeer.getPeerUnderCursor();
Component c = null;
- if (peer != null) {
+ if (peer != null && peer.getWindowPeerOrSelf().getBlocker() == null) {
c = peer.getTarget();
if (c instanceof Container) {
final Point p = peer.getLocationOnScreen();
--- a/jdk/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java Thu May 10 11:47:56 2012 -0700
@@ -81,6 +81,18 @@
firstChangeSkipped = true;
}
+ @Override
+ protected final void disposeImpl() {
+ synchronized (getDelegateLock()) {
+ // visible caret has a timer thread which must be stopped
+ getTextComponent().getCaret().setVisible(false);
+ }
+ super.disposeImpl();
+ }
+
+ /**
+ * This method should be called under getDelegateLock().
+ */
abstract JTextComponent getTextComponent();
public Dimension getPreferredSize(final int rows, final int columns) {
--- a/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java Thu May 10 11:47:56 2012 -0700
@@ -409,6 +409,8 @@
synchronized (getPeerTreeLock()) {
this.blocker = blocked ? (LWWindowPeer)blocker.getPeer() : null;
}
+
+ platformWindow.setModalBlocked(blocked);
}
@Override
--- a/jdk/src/macosx/classes/sun/lwawt/PlatformWindow.java Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/macosx/classes/sun/lwawt/PlatformWindow.java Thu May 10 11:47:56 2012 -0700
@@ -108,6 +108,8 @@
public void flip(int x1, int y1, int x2, int y2,
BufferCapabilities.FlipContents flipAction);
+ public void setModalBlocked(boolean blocked);
+
public void toFront();
public void toBack();
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java Thu May 10 11:47:56 2012 -0700
@@ -205,4 +205,7 @@
@Override
public void setWindowState(int windowState) {}
+
+ @Override
+ public void setModalBlocked(boolean blocked) {}
}
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Thu May 10 11:47:56 2012 -0700
@@ -61,6 +61,7 @@
private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
private static native void nativeSetNSWindowSecurityWarningPositioning(long nsWindowPtr, double x, double y, float biasX, float biasY);
+ private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
private static native void nativeSynthesizeMouseEnteredExitedEvents(long nsWindowPtr);
private static native int nativeGetScreenNSWindowIsOn_AppKitThread(long nsWindowPtr);
@@ -800,6 +801,15 @@
// value when the native notification comes to us
}
+ @Override
+ public void setModalBlocked(boolean blocked) {
+ if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
+ return;
+ }
+
+ nativeSetEnabled(getNSWindowPtr(), !blocked);
+ }
+
// ----------------------------------------------------------------------
// UTILITY METHODS
// ----------------------------------------------------------------------
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java Thu May 10 11:47:56 2012 -0700
@@ -27,9 +27,9 @@
import sun.awt.datatransfer.ToolkitThreadBlockedHandler;
-// TODO:BG this class is really a NOOP right now, but should be filled in if needed.
+final class CToolkitThreadBlockedHandler implements ToolkitThreadBlockedHandler {
+ private final LWCToolkit toolkit = (LWCToolkit)java.awt.Toolkit.getDefaultToolkit();
-final class CToolkitThreadBlockedHandler implements ToolkitThreadBlockedHandler {
public void lock() {
}
@@ -41,9 +41,10 @@
}
public void enter() {
+ toolkit.startNativeNestedEventLoop();
}
public void exit() {
+ toolkit.stopNativeNestedEventLoop();
}
-
}
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java Thu May 10 11:47:56 2012 -0700
@@ -63,6 +63,10 @@
private static native void initIDs();
+ static native void startNativeNestedEventLoop();
+
+ static native void stopNativeNestedEventLoop();
+
private static CInputMethodDescriptor sInputMethodDescriptor;
static {
--- a/jdk/src/macosx/native/sun/awt/AWTView.m Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/macosx/native/sun/awt/AWTView.m Thu May 10 11:47:56 2012 -0700
@@ -81,7 +81,7 @@
fEnablePressAndHold = shouldUsePressAndHold();
fInPressAndHold = NO;
fPAHNeedsToSelect = NO;
-
+
mouseIsOver = NO;
if (windowLayer != nil) {
@@ -302,16 +302,25 @@
*/
-(void) deliverJavaMouseEvent: (NSEvent *) event {
-
- NSEventType type = [event type];
-
+ BOOL isEnabled = YES;
+ NSWindow* window = [self window];
+ if ([window isKindOfClass: [AWTWindow class]]) {
+ isEnabled = [(AWTWindow*)window isEnabled];
+ }
+
+ if (!isEnabled) {
+ return;
+ }
+
+ NSEventType type = [event type];
+
// check synthesized mouse entered/exited events
if ((type == NSMouseEntered && mouseIsOver) || (type == NSMouseExited && !mouseIsOver)) {
return;
}else if ((type == NSMouseEntered && !mouseIsOver) || (type == NSMouseExited && mouseIsOver)) {
mouseIsOver = !mouseIsOver;
}
-
+
[AWTToolkit eventCountPlusPlus];
JNIEnv *env = [ThreadUtilities getJNIEnv];
--- a/jdk/src/macosx/native/sun/awt/AWTWindow.h Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/macosx/native/sun/awt/AWTWindow.h Thu May 10 11:47:56 2012 -0700
@@ -42,6 +42,7 @@
NSSize javaMinSize;
NSSize javaMaxSize;
jint styleBits;
+ BOOL isEnabled;
}
@property (nonatomic, retain) JNFWeakJObjectWrapper *javaPlatformWindow;
@@ -49,6 +50,7 @@
@property (nonatomic) NSSize javaMinSize;
@property (nonatomic) NSSize javaMaxSize;
@property (nonatomic) jint styleBits;
+@property (nonatomic) BOOL isEnabled;
- (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)javaPlatformWindow
styleBits:(jint)styleBits
--- a/jdk/src/macosx/native/sun/awt/AWTWindow.m Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/macosx/native/sun/awt/AWTWindow.m Thu May 10 11:47:56 2012 -0700
@@ -58,6 +58,7 @@
@synthesize javaMinSize;
@synthesize javaMaxSize;
@synthesize styleBits;
+@synthesize isEnabled;
- (void) updateMinMaxSize:(BOOL)resizable {
if (resizable) {
@@ -157,6 +158,7 @@
if (self == nil) return nil; // no hope
+ self.isEnabled = YES;
self.javaPlatformWindow = platformWindow;
self.styleBits = bits;
[self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
@@ -170,22 +172,22 @@
return self;
}
-// checks that this window is under the mouse cursor and this point is not overlapped by others windows
+// checks that this window is under the mouse cursor and this point is not overlapped by others windows
- (BOOL) isTopmostWindowUnderMouse {
-
- int currentWinID = [self windowNumber];
-
- NSRect screenRect = [[NSScreen mainScreen] frame];
+
+ int currentWinID = [self windowNumber];
+
+ NSRect screenRect = [[NSScreen mainScreen] frame];
NSPoint nsMouseLocation = [NSEvent mouseLocation];
- CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);
-
+ CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);
+
NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
-
-
+
+
for (NSDictionary *window in windows) {
int layer = [[window objectForKey:(id)kCGWindowLayer] intValue];
if (layer == 0) {
- int winID = [[window objectForKey:(id)kCGWindowNumber] intValue];
+ int winID = [[window objectForKey:(id)kCGWindowNumber] intValue];
CGRect rect;
CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:(id)kCGWindowBounds], &rect);
if (CGRectContainsPoint(rect, cgMouseLocation)) {
@@ -199,23 +201,23 @@
}
- (void) synthesizeMouseEnteredExitedEvents {
-
+
int eventType = 0;
BOOL isUnderMouse = [self isTopmostWindowUnderMouse];
BOOL mouseIsOver = [[self contentView] mouseIsOver];
-
+
if (isUnderMouse && !mouseIsOver) {
eventType = NSMouseEntered;
} else if (!isUnderMouse && mouseIsOver) {
- eventType = NSMouseExited;
+ eventType = NSMouseExited;
} else {
return;
}
-
- NSPoint screenLocation = [NSEvent mouseLocation];
- NSPoint windowLocation = [self convertScreenToBase: screenLocation];
+
+ NSPoint screenLocation = [NSEvent mouseLocation];
+ NSPoint windowLocation = [self convertScreenToBase: screenLocation];
int modifierFlags = (eventType == NSMouseEntered) ? NSMouseEnteredMask : NSMouseExitedMask;
-
+
NSEvent *mouseEvent = [NSEvent enterExitEventWithType: eventType
location: windowLocation
modifierFlags: modifierFlags
@@ -226,7 +228,7 @@
trackingNumber: 0
userData: nil
];
-
+
[[self contentView] deliverJavaMouseEvent: mouseEvent];
}
@@ -239,16 +241,15 @@
[super dealloc];
}
-
// NSWindow overrides
- (BOOL) canBecomeKeyWindow {
AWT_ASSERT_APPKIT_THREAD;
- return IS(self.styleBits, SHOULD_BECOME_KEY);
+ return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_KEY);
}
- (BOOL) canBecomeMainWindow {
AWT_ASSERT_APPKIT_THREAD;
- return IS(self.styleBits, SHOULD_BECOME_MAIN);
+ return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_MAIN);
}
- (BOOL) worksWhenModal {
@@ -562,6 +563,27 @@
size->height = MAX(size->height, minHeight);
}
+- (void) setEnabled: (BOOL)flag {
+ self.isEnabled = flag;
+
+ if (IS(self.styleBits, CLOSEABLE)) {
+ [[self standardWindowButton:NSWindowCloseButton] setEnabled: flag];
+ }
+
+ if (IS(self.styleBits, MINIMIZABLE)) {
+ [[self standardWindowButton:NSWindowMiniaturizeButton] setEnabled: flag];
+ }
+
+ if (IS(self.styleBits, ZOOMABLE)) {
+ [[self standardWindowButton:NSWindowZoomButton] setEnabled: flag];
+ }
+
+ if (IS(self.styleBits, RESIZABLE)) {
+ [self updateMinMaxSize:flag];
+ [self setShowsResizeIndicator:flag];
+ }
+}
+
@end // AWTWindow
@@ -729,7 +751,7 @@
// ensure we repaint the whole window after the resize operation
// (this will also re-enable screen updates, which were disabled above)
// TODO: send PaintEvent
-
+
[window synthesizeMouseEnteredExitedEvents];
}];
@@ -969,14 +991,14 @@
{
JNF_COCOA_ENTER(env);
AWT_ASSERT_NOT_APPKIT_THREAD;
-
+
AWTWindow *window = OBJC(windowPtr);
[JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
AWT_ASSERT_APPKIT_THREAD;
-
+
[window synthesizeMouseEnteredExitedEvents];
}];
-
+
JNF_COCOA_EXIT(env);
}
@@ -1056,3 +1078,17 @@
return underMouse;
}
+
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetEnabled
+(JNIEnv *env, jclass clazz, jlong windowPtr, jboolean isEnabled)
+{
+JNF_COCOA_ENTER(env);
+
+ AWTWindow *window = OBJC(windowPtr);
+ [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+ [window setEnabled: isEnabled];
+ }];
+
+JNF_COCOA_EXIT(env);
+}
+
--- a/jdk/src/macosx/native/sun/awt/LWCToolkit.m Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/macosx/native/sun/awt/LWCToolkit.m Thu May 10 11:47:56 2012 -0700
@@ -42,6 +42,7 @@
@implementation AWTToolkit
static long eventCount;
+static bool shouldKeepRunningNestedLoop = NO;
+ (long) getEventCount{
return eventCount;
@@ -456,3 +457,36 @@
{
}
+
+/*
+ * Class: sun_lwawt_macosx_LWCToolkit
+ * Method: startNativeNestedEventLoop
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_startNativeNestedEventLoop
+(JNIEnv *env, jclass cls)
+{
+ if(!shouldKeepRunningNestedLoop) {
+ NSRunLoop *theRL = [NSRunLoop currentRunLoop];
+ NSApplication * app = [NSApplication sharedApplication];
+ shouldKeepRunningNestedLoop = YES;
+ while (shouldKeepRunningNestedLoop && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]])
+ {
+ NSEvent * event = [app nextEventMatchingMask: 0xFFFFFFFF untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES];
+ if (event != nil) {
+ [app sendEvent: event];
+ }
+ }
+ }
+}
+
+/*
+ * Class: sun_lwawt_macosx_LWCToolkit
+ * Method: stopNativeNestedEventLoop
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_stopNativeNestedEventLoop
+(JNIEnv *env, jclass cls)
+{
+ shouldKeepRunningNestedLoop = NO;
+}
--- a/jdk/src/share/classes/java/awt/Component.java Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/share/classes/java/awt/Component.java Thu May 10 11:47:56 2012 -0700
@@ -7169,6 +7169,9 @@
* Set from its parent. If all ancestors of this Component have null
* specified for the Set, then the current KeyboardFocusManager's default
* Set is used.
+ * <p>
+ * This method may throw a {@code ClassCastException} if any {@code Object}
+ * in {@code keystrokes} is not an {@code AWTKeyStroke}.
*
* @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
@@ -7182,8 +7185,7 @@
* KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
* KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or if keystrokes
- * contains null, or if any Object in keystrokes is not an
- * AWTKeyStroke, or if any keystroke represents a KEY_TYPED event,
+ * contains null, or if any keystroke represents a KEY_TYPED event,
* or if any keystroke already maps to another focus traversal
* operation for this Component
* @since 1.4
--- a/jdk/src/share/classes/java/awt/Container.java Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/share/classes/java/awt/Container.java Thu May 10 11:47:56 2012 -0700
@@ -3093,6 +3093,9 @@
* Set from its parent. If all ancestors of this Container have null
* specified for the Set, then the current KeyboardFocusManager's default
* Set is used.
+ * <p>
+ * This method may throw a {@code ClassCastException} if any {@code Object}
+ * in {@code keystrokes} is not an {@code AWTKeyStroke}.
*
* @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
@@ -3109,8 +3112,7 @@
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
* KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
* KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS, or if keystrokes
- * contains null, or if any Object in keystrokes is not an
- * AWTKeyStroke, or if any keystroke represents a KEY_TYPED event,
+ * contains null, or if any keystroke represents a KEY_TYPED event,
* or if any keystroke already maps to another focus traversal
* operation for this Container
* @since 1.4
--- a/jdk/src/share/classes/java/awt/Dialog.java Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/share/classes/java/awt/Dialog.java Thu May 10 11:47:56 2012 -0700
@@ -1037,7 +1037,7 @@
predictedFocusOwner = getMostRecentFocusOwner();
if (conditionalShow(predictedFocusOwner, time)) {
modalFilter = ModalEventFilter.createFilterForDialog(this);
- Conditional cond = new Conditional() {
+ final Conditional cond = new Conditional() {
@Override
public boolean evaluate() {
return windowClosingException == null;
@@ -1067,7 +1067,12 @@
modalityPushed();
try {
- EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();
+ final EventQueue eventQueue = AccessController.doPrivileged(
+ new PrivilegedAction<EventQueue>() {
+ public EventQueue run() {
+ return Toolkit.getDefaultToolkit().getSystemEventQueue();
+ }
+ });
secondaryLoop = eventQueue.createSecondaryLoop(cond, modalFilter, 0);
if (!secondaryLoop.enter()) {
secondaryLoop = null;
--- a/jdk/src/share/classes/java/awt/KeyboardFocusManager.java Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/share/classes/java/awt/KeyboardFocusManager.java Thu May 10 11:47:56 2012 -0700
@@ -991,12 +991,12 @@
/**
* Sets the default focus traversal keys for a given traversal operation.
- * This traversal key <code>Set</code> will be in effect on all
- * <code>Window</code>s that have no such <code>Set</code> of
- * their own explicitly defined. This <code>Set</code> will also be
- * inherited, recursively, by any child <code>Component</code> of
- * those <code>Windows</code> that has
- * no such <code>Set</code> of its own explicitly defined.
+ * This traversal key {@code Set} will be in effect on all
+ * {@code Window}s that have no such {@code Set} of
+ * their own explicitly defined. This {@code Set} will also be
+ * inherited, recursively, by any child {@code Component} of
+ * those {@code Windows} that has
+ * no such {@code Set} of its own explicitly defined.
* <p>
* The default values for the default focus traversal keys are
* implementation-dependent. Sun recommends that all implementations for a
@@ -1011,66 +1011,67 @@
* <th>Default</th>
* </tr>
* <tr>
- * <td><code>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</code></td>
+ * <td>{@code KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS}</td>
* <td>Normal forward keyboard traversal</td>
- * <td><code>TAB</code> on <code>KEY_PRESSED</code>,
- * <code>CTRL-TAB</code> on <code>KEY_PRESSED</code></td>
+ * <td>{@code TAB} on {@code KEY_PRESSED},
+ * {@code CTRL-TAB} on {@code KEY_PRESSED}</td>
* </tr>
* <tr>
- * <td><code>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</code></td>
+ * <td>{@code KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS}</td>
* <td>Normal reverse keyboard traversal</td>
- * <td><code>SHIFT-TAB</code> on <code>KEY_PRESSED</code>,
- * <code>CTRL-SHIFT-TAB</code> on <code>KEY_PRESSED</code></td>
+ * <td>{@code SHIFT-TAB} on {@code KEY_PRESSED},
+ * {@code CTRL-SHIFT-TAB} on {@code KEY_PRESSED}</td>
* </tr>
* <tr>
- * <td><code>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</code></td>
+ * <td>{@code KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS}</td>
* <td>Go up one focus traversal cycle</td>
* <td>none</td>
* </tr>
* <tr>
- * <td><code>KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS</code></td>
+ * <td>{@code KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS}</td>
* <td>Go down one focus traversal cycle</td>
* <td>none</td>
* </tr>
* </table>
*
- * To disable a traversal key, use an empty <code>Set</code>;
- * <code>Collections.EMPTY_SET</code> is recommended.
+ * To disable a traversal key, use an empty {@code Set};
+ * {@code Collections.EMPTY_SET} is recommended.
* <p>
- * Using the <code>AWTKeyStroke</code> API, client code can
+ * Using the {@code AWTKeyStroke} API, client code can
* specify on which of two
- * specific <code>KeyEvent</code>s, <code>KEY_PRESSED</code> or
- * <code>KEY_RELEASED</code>, the focus traversal operation will
- * occur. Regardless of which <code>KeyEvent</code> is specified,
- * however, all <code>KeyEvent</code>s related to the focus
- * traversal key, including the associated <code>KEY_TYPED</code>
+ * specific {@code KeyEvent}s, {@code KEY_PRESSED} or
+ * {@code KEY_RELEASED}, the focus traversal operation will
+ * occur. Regardless of which {@code KeyEvent} is specified,
+ * however, all {@code KeyEvent}s related to the focus
+ * traversal key, including the associated {@code KEY_TYPED}
* event, will be consumed, and will not be dispatched
- * to any <code>Component</code>. It is a runtime error to
- * specify a <code>KEY_TYPED</code> event as
+ * to any {@code Component}. It is a runtime error to
+ * specify a {@code KEY_TYPED} event as
* mapping to a focus traversal operation, or to map the same event to
* multiple default focus traversal operations.
+ * <p>
+ * This method may throw a {@code ClassCastException} if any {@code Object}
+ * in {@code keystrokes} is not an {@code AWTKeyStroke}.
*
* @param id one of
- * <code>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</code>,
- * <code>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</code>,
- * <code>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</code>, or
- * <code>KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS</code>
- * @param keystrokes the Set of <code>AWTKeyStroke</code>s for the
+ * {@code KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS},
+ * {@code KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS},
+ * {@code KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS}, or
+ * {@code KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS}
+ * @param keystrokes the Set of {@code AWTKeyStroke}s for the
* specified operation
* @see #getDefaultFocusTraversalKeys
* @see Component#setFocusTraversalKeys
* @see Component#getFocusTraversalKeys
* @throws IllegalArgumentException if id is not one of
- * <code>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</code>,
- * <code>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</code>,
- * <code>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</code>, or
- * <code>KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS</code>,
- * or if keystrokes is <code>null</code>,
- * or if keystrokes contains <code>null</code>,
- * or if any <code>Object</code> in
- * keystrokes is not an <code>AWTKeyStroke</code>,
+ * {@code KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS},
+ * {@code KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS},
+ * {@code KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS}, or
+ * {@code KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS},
+ * or if keystrokes is {@code null},
+ * or if keystrokes contains {@code null},
* or if any keystroke
- * represents a <code>KEY_TYPED</code> event,
+ * represents a {@code KEY_TYPED} event,
* or if any keystroke already maps
* to another default focus traversal operation
* @beaninfo
@@ -1090,20 +1091,12 @@
Set oldKeys;
synchronized (this) {
- for (Iterator iter = keystrokes.iterator(); iter.hasNext(); ) {
- Object obj = iter.next();
+ for (AWTKeyStroke keystroke : keystrokes) {
- if (obj == null) {
+ if (keystroke == null) {
throw new IllegalArgumentException("cannot set null focus traversal key");
}
- // Fix for 6195831:
- //According to javadoc this method should throw IAE instead of ClassCastException
- if (!(obj instanceof AWTKeyStroke)) {
- throw new IllegalArgumentException("object is expected to be AWTKeyStroke");
- }
- AWTKeyStroke keystroke = (AWTKeyStroke)obj;
-
if (keystroke.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
throw new IllegalArgumentException("focus traversal keys cannot map to KEY_TYPED events");
}
--- a/jdk/src/share/classes/javax/swing/JComponent.java Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/share/classes/javax/swing/JComponent.java Thu May 10 11:47:56 2012 -0700
@@ -4148,6 +4148,9 @@
* Refer to
* {@link java.awt.Component#setFocusTraversalKeys}
* for a complete description of this method.
+ * <p>
+ * This method may throw a {@code ClassCastException} if any {@code Object}
+ * in {@code keystrokes} is not an {@code AWTKeyStroke}.
*
* @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
@@ -4160,8 +4163,7 @@
* KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
* KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or if keystrokes
- * contains null, or if any Object in keystrokes is not an
- * AWTKeyStroke, or if any keystroke represents a KEY_TYPED event,
+ * contains null, or if any keystroke represents a KEY_TYPED event,
* or if any keystroke already maps to another focus traversal
* operation for this Component
* @since 1.5
--- a/jdk/src/share/demo/jfc/Notepad/Notepad.java Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/share/demo/jfc/Notepad/Notepad.java Thu May 10 11:47:56 2012 -0700
@@ -39,71 +39,18 @@
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.Container;
-import java.awt.FileDialog;
-import java.awt.Font;
-import java.awt.Frame;
-import java.awt.Graphics;
-import java.awt.Insets;
-import java.awt.event.ActionEvent;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import java.util.StringTokenizer;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.BorderFactory;
-import javax.swing.Box;
-import javax.swing.BoxLayout;
-import javax.swing.ImageIcon;
-import javax.swing.JButton;
-import javax.swing.JComponent;
-import javax.swing.JFileChooser;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JProgressBar;
-import javax.swing.JScrollPane;
-import javax.swing.JTextArea;
-import javax.swing.JToolBar;
-import javax.swing.JViewport;
-import javax.swing.SwingUtilities;
-import javax.swing.UIManager;
+import java.awt.*;
+import java.awt.event.*;
+import java.beans.*;
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import java.util.logging.*;
+import javax.swing.*;
+import javax.swing.undo.*;
+import javax.swing.text.*;
+import javax.swing.event.*;
import javax.swing.UIManager.LookAndFeelInfo;
-import javax.swing.event.UndoableEditEvent;
-import javax.swing.event.UndoableEditListener;
-import javax.swing.text.BadLocationException;
-import javax.swing.text.Document;
-import javax.swing.text.JTextComponent;
-import javax.swing.text.PlainDocument;
-import javax.swing.text.Segment;
-import javax.swing.text.TextAction;
-import javax.swing.undo.CannotRedoException;
-import javax.swing.undo.CannotUndoException;
-import javax.swing.undo.UndoManager;
/**
@@ -115,16 +62,27 @@
@SuppressWarnings("serial")
class Notepad extends JPanel {
+ private static Properties properties;
private static ResourceBundle resources;
private final static String EXIT_AFTER_PAINT = "-exit";
private static boolean exitAfterFirstPaint;
+ private static final String[] MENUBAR_KEYS = {"file", "edit", "debug"};
+ private static final String[] TOOLBAR_KEYS = {"new", "open", "save", "-", "cut", "copy", "paste"};
+ private static final String[] FILE_KEYS = {"new", "open", "save", "-", "exit"};
+ private static final String[] EDIT_KEYS = {"cut", "copy", "paste", "-", "undo", "redo"};
+ private static final String[] DEBUG_KEYS = {"dump", "showElementTree"};
+
static {
try {
+ properties = new Properties();
+ properties.load(Notepad.class.getResourceAsStream(
+ "resources/system.properties"));
resources = ResourceBundle.getBundle("resources.Notepad",
Locale.getDefault());
- } catch (MissingResourceException mre) {
- System.err.println("resources/Notepad.properties not found");
+ } catch (MissingResourceException | IOException e) {
+ System.err.println("resources/Notepad.properties "
+ + "or resources/system.properties not found");
System.exit(1);
}
}
@@ -163,26 +121,22 @@
// install the command table
commands = new HashMap<Object, Action>();
Action[] actions = getActions();
- for (int i = 0; i < actions.length; i++) {
- Action a = actions[i];
- //commands.put(a.getText(Action.NAME), a);
+ for (Action a : actions) {
commands.put(a.getValue(Action.NAME), a);
}
JScrollPane scroller = new JScrollPane();
JViewport port = scroller.getViewport();
port.add(editor);
- try {
- String vpFlag = resources.getString("ViewportBackingStore");
+
+ String vpFlag = getProperty("ViewportBackingStore");
+ if (vpFlag != null) {
Boolean bs = Boolean.valueOf(vpFlag);
- port.setScrollMode(bs.booleanValue()
+ port.setScrollMode(bs
? JViewport.BACKINGSTORE_SCROLL_MODE
: JViewport.BLIT_SCROLL_MODE);
- } catch (MissingResourceException ignored) {
- // just use the viewport default
}
- menuItems = new HashMap<String, JMenuItem>();
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add("North", createToolbar());
@@ -191,31 +145,26 @@
add("South", createStatusbar());
}
- public static void main(String[] args) {
- try {
- if (args.length > 0 && args[0].equals(EXIT_AFTER_PAINT)) {
- exitAfterFirstPaint = true;
- }
- SwingUtilities.invokeAndWait(new Runnable() {
+ public static void main(String[] args) throws Exception {
+ if (args.length > 0 && args[0].equals(EXIT_AFTER_PAINT)) {
+ exitAfterFirstPaint = true;
+ }
+ SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- JFrame frame = new JFrame();
- frame.setTitle(resources.getString("Title"));
- frame.setBackground(Color.lightGray);
- frame.getContentPane().setLayout(new BorderLayout());
- Notepad notepad = new Notepad();
- frame.getContentPane().add("Center", notepad);
- frame.setJMenuBar(notepad.createMenubar());
- frame.addWindowListener(new AppCloser());
- frame.pack();
- frame.setSize(500, 600);
- frame.setVisible(true);
- }
- });
- } catch (Throwable t) {
- Logger.getLogger(Notepad.class.getName()).log(Level.SEVERE,
- "uncaught exception", t);
- }
+ public void run() {
+ JFrame frame = new JFrame();
+ frame.setTitle(resources.getString("Title"));
+ frame.setBackground(Color.lightGray);
+ frame.getContentPane().setLayout(new BorderLayout());
+ Notepad notepad = new Notepad();
+ frame.getContentPane().add("Center", notepad);
+ frame.setJMenuBar(notepad.createMenubar());
+ frame.addWindowListener(new AppCloser());
+ frame.pack();
+ frame.setSize(500, 600);
+ frame.setVisible(true);
+ }
+ });
}
/**
@@ -274,9 +223,7 @@
/**
* This is the hook through which all menu items are
- * created. It registers the result with the menuitem
- * hashtable so that it can be fetched with getMenuItem().
- * @see #getMenuItem
+ * created.
*/
protected JMenuItem createMenuItem(String cmd) {
JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix));
@@ -285,7 +232,7 @@
mi.setHorizontalTextPosition(JButton.RIGHT);
mi.setIcon(new ImageIcon(url));
}
- String astr = getResourceString(cmd + actionSuffix);
+ String astr = getProperty(cmd + actionSuffix);
if (astr == null) {
astr = cmd;
}
@@ -298,25 +245,17 @@
} else {
mi.setEnabled(false);
}
- menuItems.put(cmd, mi);
return mi;
}
- /**
- * Fetch the menu item that was created for the given
- * command.
- * @param cmd Name of the action.
- * @returns item created for the given command or null
- * if one wasn't created.
- */
- protected JMenuItem getMenuItem(String cmd) {
- return menuItems.get(cmd);
- }
-
protected Action getAction(String cmd) {
return commands.get(cmd);
}
+ protected String getProperty(String key) {
+ return properties.getProperty(key);
+ }
+
protected String getResourceString(String nm) {
String str;
try {
@@ -330,20 +269,11 @@
protected URL getResource(String key) {
String name = getResourceString(key);
if (name != null) {
- URL url = this.getClass().getResource(name);
- return url;
+ return this.getClass().getResource(name);
}
return null;
}
- protected Container getToolbar() {
- return toolbar;
- }
-
- protected JMenuBar getMenubar() {
- return menubar;
- }
-
/**
* Create a status bar
*/
@@ -368,12 +298,11 @@
*/
private Component createToolbar() {
toolbar = new JToolBar();
- String[] toolKeys = tokenize(getResourceString("toolbar"));
- for (int i = 0; i < toolKeys.length; i++) {
- if (toolKeys[i].equals("-")) {
+ for (String toolKey: TOOLBAR_KEYS) {
+ if (toolKey.equals("-")) {
toolbar.add(Box.createHorizontalStrut(5));
} else {
- toolbar.add(createTool(toolKeys[i]));
+ toolbar.add(createTool(toolKey));
}
}
toolbar.add(Box.createHorizontalGlue());
@@ -408,7 +337,7 @@
b.setRequestFocusEnabled(false);
b.setMargin(new Insets(1, 1, 1, 1));
- String astr = getResourceString(key + actionSuffix);
+ String astr = getProperty(key + actionSuffix);
if (astr == null) {
astr = key;
}
@@ -429,43 +358,17 @@
}
/**
- * Take the given string and chop it up into a series
- * of strings on whitespace boundaries. This is useful
- * for trying to get an array of strings out of the
- * resource file.
- */
- protected String[] tokenize(String input) {
- List<String> v = new ArrayList<String>();
- StringTokenizer t = new StringTokenizer(input);
- String cmd[];
-
- while (t.hasMoreTokens()) {
- v.add(t.nextToken());
- }
- cmd = new String[v.size()];
- for (int i = 0; i < cmd.length; i++) {
- cmd[i] = v.get(i);
- }
-
- return cmd;
- }
-
- /**
* Create the menubar for the app. By default this pulls the
* definition of the menu from the associated resource file.
*/
protected JMenuBar createMenubar() {
- JMenuItem mi;
JMenuBar mb = new JMenuBar();
-
- String[] menuKeys = tokenize(getResourceString("menubar"));
- for (int i = 0; i < menuKeys.length; i++) {
- JMenu m = createMenu(menuKeys[i]);
+ for(String menuKey: MENUBAR_KEYS){
+ JMenu m = createMenu(menuKey);
if (m != null) {
mb.add(m);
}
}
- this.menubar = mb;
return mb;
}
@@ -474,19 +377,32 @@
* definition of the menu from the associated resource file.
*/
protected JMenu createMenu(String key) {
- String[] itemKeys = tokenize(getResourceString(key));
- JMenu menu = new JMenu(getResourceString(key + "Label"));
- for (int i = 0; i < itemKeys.length; i++) {
- if (itemKeys[i].equals("-")) {
+ JMenu menu = new JMenu(getResourceString(key + labelSuffix));
+ for (String itemKey: getItemKeys(key)) {
+ if (itemKey.equals("-")) {
menu.addSeparator();
} else {
- JMenuItem mi = createMenuItem(itemKeys[i]);
+ JMenuItem mi = createMenuItem(itemKey);
menu.add(mi);
}
}
return menu;
}
+ // get keys for menus
+ private String[] getItemKeys(String key) {
+ switch (key) {
+ case "file":
+ return FILE_KEYS;
+ case "edit":
+ return EDIT_KEYS;
+ case "debug":
+ return DEBUG_KEYS;
+ default:
+ return null;
+ }
+ }
+
// Yarked from JMenu, ideally this would be public.
protected PropertyChangeListener createActionChangeListener(JMenuItem b) {
return new ActionChangedListener(b);
@@ -516,13 +432,11 @@
}
private JTextComponent editor;
private Map<Object, Action> commands;
- private Map<String, JMenuItem> menuItems;
- private JMenuBar menubar;
private JToolBar toolbar;
private JComponent status;
private JFrame elementTreeFrame;
protected ElementTreePanel elementTreePanel;
- protected FileDialog fileDialog;
+
/**
* Listener for the edits on the current document.
*/
@@ -773,10 +687,6 @@
super(showElementTreeAction);
}
- ShowElementTreeAction(String nm) {
- super(nm);
- }
-
public void actionPerformed(ActionEvent e) {
if (elementTreeFrame == null) {
// Create a frame containing an instance of
--- a/jdk/src/share/demo/jfc/Notepad/resources/Notepad.properties Wed Jul 05 18:10:27 2017 +0200
+++ b/jdk/src/share/demo/jfc/Notepad/resources/Notepad.properties Thu May 10 11:47:56 2012 -0700
@@ -3,16 +3,6 @@
Title=Notepad
ElementTreeFrameTitle=Elements
-# The following string should NOT be translated: ViewportBackingStore
-ViewportBackingStore=false
-
-# menubar definition
-#
-# Each of the strings that follow form a key to be
-# used to the actual menu definition.
-
-# The following string should NOT be translated: menubar
-menubar=file edit debug
# file Menu definition
#
@@ -24,8 +14,6 @@
# save -> Notepad.saveAction
# exit -> Notepad.exitAction
-# The following string should NOT be translated: file
-file=new open save - exit
fileLabel=File
openLabel=Open
openImage=resources/open.gif
@@ -42,38 +30,22 @@
# copy -> JTextComponent.copyAction
# paste -> JTextComponent.pasteAction
-# The following string should NOT be translated: edit
-edit=cut copy paste - undo redo
editLabel=Edit
cutLabel=Cut
-# The following string should NOT be translated: cutAction
-cutAction=cut-to-clipboard
cutImage=resources/cut.gif
copyLabel=Copy
-# The following string should NOT be translated: copyAction
-copyAction=copy-to-clipboard
copyImage=resources/copy.gif
pasteLabel=Paste
-# The following string should NOT be translated: pasteAction
-pasteAction=paste-from-clipboard
pasteImage=resources/paste.gif
undoLabel=Undo
-# The following string should NOT be translated: undoAction
-undoAction=Undo
redoLabel=Redo
-# The following string should NOT be translated: redoAction
-redoAction=Redo
#
# debug Menu definition
#
-# The following string should NOT be translated: debug
-debug=dump showElementTree
debugLabel=Debug
dumpLabel=Dump model to System.err
-# The following string should NOT be translated: dumpAction
-dumpAction=dump-model
showElementTreeLabel=Show Elements
# toolbar definition
@@ -83,8 +55,6 @@
# are of course sharable, and in this case are shared
# with the menu items.
-# The following string should NOT be translated: toolbar
-toolbar=new open save - cut copy paste
newTooltip=Create a new file
openTooltip=Open a file
saveTooltip=Save to a file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/demo/jfc/Notepad/resources/system.properties Thu May 10 11:47:56 2012 -0700
@@ -0,0 +1,12 @@
+#
+# Non-translatable properties for Notepad example
+
+ViewportBackingStore=false
+
+cutAction=cut-to-clipboard
+copyAction=copy-to-clipboard
+pasteAction=paste-from-clipboard
+undoAction=Undo
+redoAction=Redo
+dumpAction=dump-model
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Dialog/ModalDialogPermission/ModalDialogPermission.java Thu May 10 11:47:56 2012 -0700
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.Dialog;
+import java.awt.Frame;
+import java.util.Timer;
+import java.util.TimerTask;
+
+/*
+ @test
+ @bug 7080109
+ @summary Dialog.show() lacks doPrivileged() to access system event queue.
+ @author sergey.bylokhov@oracle.com: area=awt.dialog
+ @run main/othervm/policy=java.policy -Djava.security.manager ModalDialogPermission
+*/
+public final class ModalDialogPermission {
+
+ public static void main(final String[] args) {
+ Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
+ @Override
+ public void uncaughtException(final Thread t, final Throwable e) {
+ throw new RuntimeException(e);
+ }
+ });
+ final Frame frame = new Frame();
+ final Dialog dialog = new Dialog(frame, "ModalDialog", true);
+ final Timer t = new Timer();
+ t.schedule(new TimerTask() {
+
+ @Override
+ public void run() {
+ dialog.setVisible(false);
+ dialog.dispose();
+ }
+ }, 3000L);
+ dialog.show();
+ frame.dispose();
+ t.cancel();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Dialog/ModalDialogPermission/java.policy Thu May 10 11:47:56 2012 -0700
@@ -0,0 +1,3 @@
+grant {
+ permission java.lang.RuntimePermission "setDefaultUncaughtExceptionHandler";
+};