提交 fd4fced5 编写于 作者: L lana

Merge

...@@ -158,12 +158,12 @@ public final class CGraphicsDevice extends GraphicsDevice ...@@ -158,12 +158,12 @@ public final class CGraphicsDevice extends GraphicsDevice
boolean fsSupported = isFullScreenSupported(); boolean fsSupported = isFullScreenSupported();
if (fsSupported && old != null) { if (fsSupported && old != null) {
// restore original display mode and enter windowed mode. // enter windowed mode and restore original display mode
exitFullScreenExclusive(old);
if (originalMode != null) { if (originalMode != null) {
setDisplayMode(originalMode); setDisplayMode(originalMode);
originalMode = null; originalMode = null;
} }
exitFullScreenExclusive(old);
} }
super.setFullScreenWindow(w); super.setFullScreenWindow(w);
...@@ -227,14 +227,10 @@ public final class CGraphicsDevice extends GraphicsDevice ...@@ -227,14 +227,10 @@ public final class CGraphicsDevice extends GraphicsDevice
throw new IllegalArgumentException("Invalid display mode"); throw new IllegalArgumentException("Invalid display mode");
} }
if (!Objects.equals(dm, getDisplayMode())) { if (!Objects.equals(dm, getDisplayMode())) {
final Window w = getFullScreenWindow();
if (w != null) {
exitFullScreenExclusive(w);
}
nativeSetDisplayMode(displayID, dm.getWidth(), dm.getHeight(), nativeSetDisplayMode(displayID, dm.getWidth(), dm.getHeight(),
dm.getBitDepth(), dm.getRefreshRate()); dm.getBitDepth(), dm.getRefreshRate());
if (isFullScreenSupported() && w != null) { if (isFullScreenSupported() && getFullScreenWindow() != null) {
enterFullScreenExclusive(w); getFullScreenWindow().setSize(dm.getWidth(), dm.getHeight());
} }
} }
} }
......
...@@ -379,10 +379,6 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -379,10 +379,6 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
return windowPeer.getPlatformWindow(); return windowPeer.getPlatformWindow();
} }
protected AppContext getAppContext() {
return SunToolkit.targetToAppContext(getTarget());
}
// ---- PEER METHODS ---- // // ---- PEER METHODS ---- //
// Just a helper method // Just a helper method
...@@ -1162,8 +1158,8 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -1162,8 +1158,8 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
/** /**
* Post an event to the proper Java EDT. * Post an event to the proper Java EDT.
*/ */
public void postEvent(AWTEvent event) { public void postEvent(final AWTEvent event) {
SunToolkit.postEvent(getAppContext(), event); LWToolkit.postEvent(event);
} }
protected void postPaintEvent(int x, int y, int w, int h) { protected void postPaintEvent(int x, int y, int w, int h) {
......
...@@ -949,7 +949,8 @@ public class LWWindowPeer ...@@ -949,7 +949,8 @@ public class LWWindowPeer
KeyEvent keyEvent = new KeyEvent(focusOwner, id, when, modifiers, KeyEvent keyEvent = new KeyEvent(focusOwner, id, when, modifiers,
keyCode, keyChar, keyLocation); keyCode, keyChar, keyLocation);
AWTAccessor.getKeyEventAccessor().setExtendedKeyCode(keyEvent, AWTAccessor.getKeyEventAccessor().setExtendedKeyCode(keyEvent,
ExtendedKeyCodes.getExtendedKeyCodeForChar(keyChar)); (keyChar == KeyEvent.CHAR_UNDEFINED) ? keyCode
: ExtendedKeyCodes.getExtendedKeyCodeForChar(keyChar));
postEvent(keyEvent); postEvent(keyEvent);
} }
......
...@@ -25,8 +25,10 @@ ...@@ -25,8 +25,10 @@
package sun.lwawt.macosx; package sun.lwawt.macosx;
import java.awt.*;
import java.awt.datatransfer.*; import java.awt.datatransfer.*;
import java.io.IOException; import java.io.IOException;
import java.io.NotSerializableException;
import java.util.*; import java.util.*;
import sun.awt.datatransfer.*; import sun.awt.datatransfer.*;
...@@ -65,12 +67,10 @@ public class CClipboard extends SunClipboard { ...@@ -65,12 +67,10 @@ public class CClipboard extends SunClipboard {
long[] formatArray = dataTransferer.getFormatsForTransferableAsArray(contents, flavorMap); long[] formatArray = dataTransferer.getFormatsForTransferableAsArray(contents, flavorMap);
declareTypes(formatArray, this); declareTypes(formatArray, this);
Map<Long, DataFlavor> formatMap = DataTransferer.getInstance().getFormatsForTransferable(contents, flavorMap); Map<Long, DataFlavor> formatMap = dataTransferer.getFormatsForTransferable(contents, flavorMap);
for (Map.Entry<Long, DataFlavor> entry : formatMap.entrySet()) {
for (Iterator<Long> iter = formatMap.keySet().iterator(); iter.hasNext(); ) { long format = entry.getKey();
Long lFormat = iter.next(); DataFlavor flavor = entry.getValue();
long format = lFormat.longValue();
DataFlavor flavor = formatMap.get(lFormat);
try { try {
byte[] bytes = DataTransferer.getInstance().translateTransferable(contents, flavor, format); byte[] bytes = DataTransferer.getInstance().translateTransferable(contents, flavor, format);
...@@ -80,17 +80,27 @@ public class CClipboard extends SunClipboard { ...@@ -80,17 +80,27 @@ public class CClipboard extends SunClipboard {
// javaJVMLocalObjectMimeType failed to serialize. // javaJVMLocalObjectMimeType failed to serialize.
// May remove this if-check when 5078787 is fixed. // May remove this if-check when 5078787 is fixed.
if (!(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType) && if (!(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType) &&
e instanceof java.io.NotSerializableException)) { e instanceof NotSerializableException)) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
notifyChanged();
} }
private void lostSelectionOwnershipImpl() { private void notifyLostOwnership() {
lostOwnershipImpl(); lostOwnershipImpl();
} }
private static void notifyChanged() {
CClipboard clipboard = (CClipboard) Toolkit.getDefaultToolkit().getSystemClipboard();
if (!clipboard.areFlavorListenersRegistered()) {
return;
}
clipboard.checkChange(clipboard.getClipboardFormats());
}
protected native long[] getClipboardFormats(); protected native long[] getClipboardFormats();
protected native byte[] getClipboardData(long format) throws IOException; protected native byte[] getClipboardData(long format) throws IOException;
......
...@@ -468,8 +468,6 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -468,8 +468,6 @@ AWT_ASSERT_APPKIT_THREAD;
// TODO: create generic AWT assert // TODO: create generic AWT assert
} }
[AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows];
NSRect frame = ConvertNSScreenRect(env, [self.nsWindow frame]); NSRect frame = ConvertNSScreenRect(env, [self.nsWindow frame]);
static JNF_MEMBER_CACHE(jm_deliverMoveResizeEvent, jc_CPlatformWindow, "deliverMoveResizeEvent", "(IIIIZ)V"); static JNF_MEMBER_CACHE(jm_deliverMoveResizeEvent, jc_CPlatformWindow, "deliverMoveResizeEvent", "(IIIIZ)V");
...@@ -480,6 +478,8 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -480,6 +478,8 @@ AWT_ASSERT_APPKIT_THREAD;
(jint)frame.size.height, (jint)frame.size.height,
(jboolean)[self.nsWindow inLiveResize]); (jboolean)[self.nsWindow inLiveResize]);
(*env)->DeleteLocalRef(env, platformWindow); (*env)->DeleteLocalRef(env, platformWindow);
[AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows];
} }
- (void)windowDidMove:(NSNotification *)notification { - (void)windowDidMove:(NSNotification *)notification {
...@@ -1236,7 +1236,9 @@ JNF_COCOA_ENTER(env); ...@@ -1236,7 +1236,9 @@ JNF_COCOA_ENTER(env);
NSRect screenRect = [[nsWindow screen] frame]; NSRect screenRect = [[nsWindow screen] frame];
[nsWindow setFrame:screenRect display:YES]; [nsWindow setFrame:screenRect display:YES];
} else { } else {
[JNFException raise:env as:kRuntimeException reason:"Failed to enter full screen."]; [JNFException raise:[ThreadUtilities getJNIEnv]
as:kRuntimeException
reason:"Failed to enter full screen."];
} }
}]; }];
...@@ -1261,7 +1263,9 @@ JNF_COCOA_ENTER(env); ...@@ -1261,7 +1263,9 @@ JNF_COCOA_ENTER(env);
// GraphicsDevice takes care of restoring pre full screen bounds // GraphicsDevice takes care of restoring pre full screen bounds
} else { } else {
[JNFException raise:env as:kRuntimeException reason:"Failed to exit full screen."]; [JNFException raise:[ThreadUtilities getJNIEnv]
as:kRuntimeException
reason:"Failed to exit full screen."];
} }
}]; }];
......
...@@ -43,6 +43,4 @@ ...@@ -43,6 +43,4 @@
- (NSArray *) javaGetTypes; - (NSArray *) javaGetTypes;
- (NSData *) javaGetDataForType:(NSString *)inFormat; - (NSData *) javaGetDataForType:(NSString *)inFormat;
- (void) pasteboardChangedOwner:(NSPasteboard *)sender;
@end @end
...@@ -91,7 +91,9 @@ static CClipboard *sClipboard = nil; ...@@ -91,7 +91,9 @@ static CClipboard *sClipboard = nil;
{ {
if (sClipboard == nil) { if (sClipboard == nil) {
sClipboard = [[CClipboard alloc] init]; sClipboard = [[CClipboard alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:sClipboard selector: @selector(checkPasteboard:) name: NSApplicationDidBecomeActiveNotification object: nil]; [[NSNotificationCenter defaultCenter] addObserver:sClipboard selector: @selector(checkPasteboard:)
name: NSApplicationDidBecomeActiveNotification
object: nil];
} }
return sClipboard; return sClipboard;
...@@ -110,8 +112,6 @@ static CClipboard *sClipboard = nil; ...@@ -110,8 +112,6 @@ static CClipboard *sClipboard = nil;
- (void) javaDeclareTypes:(NSArray *)inTypes withOwner:(jobject)inClipboard jniEnv:(JNIEnv *)inEnv { - (void) javaDeclareTypes:(NSArray *)inTypes withOwner:(jobject)inClipboard jniEnv:(JNIEnv *)inEnv {
//NSLog(@"CClipboard javaDeclareTypes %@ withOwner", inTypes);
@synchronized(self) { @synchronized(self) {
if (inClipboard != NULL) { if (inClipboard != NULL) {
if (fClipboardOwner != NULL) { if (fClipboardOwner != NULL) {
...@@ -126,8 +126,6 @@ static CClipboard *sClipboard = nil; ...@@ -126,8 +126,6 @@ static CClipboard *sClipboard = nil;
- (void) _nativeDeclareTypes:(NSArray *)inTypes { - (void) _nativeDeclareTypes:(NSArray *)inTypes {
AWT_ASSERT_APPKIT_THREAD; AWT_ASSERT_APPKIT_THREAD;
//NSLog(@"CClipboard _nativeDeclareTypes %@ withOwner", inTypes);
fChangeCount = [[NSPasteboard generalPasteboard] declareTypes:inTypes owner:self]; fChangeCount = [[NSPasteboard generalPasteboard] declareTypes:inTypes owner:self];
} }
...@@ -136,8 +134,6 @@ static CClipboard *sClipboard = nil; ...@@ -136,8 +134,6 @@ static CClipboard *sClipboard = nil;
NSMutableArray *args = [NSMutableArray arrayWithCapacity:1]; NSMutableArray *args = [NSMutableArray arrayWithCapacity:1];
[ThreadUtilities performOnMainThread:@selector(_nativeGetTypes:) on:self withObject:args waitUntilDone:YES]; [ThreadUtilities performOnMainThread:@selector(_nativeGetTypes:) on:self withObject:args waitUntilDone:YES];
//NSLog(@"CClipboard getTypes returns %@", [args lastObject]);
return [args lastObject]; return [args lastObject];
} }
...@@ -145,8 +141,6 @@ static CClipboard *sClipboard = nil; ...@@ -145,8 +141,6 @@ static CClipboard *sClipboard = nil;
AWT_ASSERT_APPKIT_THREAD; AWT_ASSERT_APPKIT_THREAD;
[args addObject:[[NSPasteboard generalPasteboard] types]]; [args addObject:[[NSPasteboard generalPasteboard] types]];
//NSLog(@"CClipboard getTypes returns %@", [args lastObject]);
} }
- (void) javaSetData:(NSData *)inData forType:(NSString *) inFormat { - (void) javaSetData:(NSData *)inData forType:(NSString *) inFormat {
...@@ -154,25 +148,18 @@ static CClipboard *sClipboard = nil; ...@@ -154,25 +148,18 @@ static CClipboard *sClipboard = nil;
CClipboardUpdate *newUpdate = [[CClipboardUpdate alloc] initWithData:inData withFormat:inFormat]; CClipboardUpdate *newUpdate = [[CClipboardUpdate alloc] initWithData:inData withFormat:inFormat];
[ThreadUtilities performOnMainThread:@selector(_nativeSetData:) on:self withObject:newUpdate waitUntilDone:YES]; [ThreadUtilities performOnMainThread:@selector(_nativeSetData:) on:self withObject:newUpdate waitUntilDone:YES];
[newUpdate release]; [newUpdate release];
//NSLog(@"CClipboard javaSetData forType %@", inFormat);
} }
- (void) _nativeSetData:(CClipboardUpdate *)newUpdate { - (void) _nativeSetData:(CClipboardUpdate *)newUpdate {
AWT_ASSERT_APPKIT_THREAD; AWT_ASSERT_APPKIT_THREAD;
[[NSPasteboard generalPasteboard] setData:[newUpdate data] forType:[newUpdate format]]; [[NSPasteboard generalPasteboard] setData:[newUpdate data] forType:[newUpdate format]];
//NSLog(@"CClipboard _nativeSetData setData %@", [newUpdate data]);
//NSLog(@"CClipboard _nativeSetData forType %@", [newUpdate format]);
} }
- (NSData *) javaGetDataForType:(NSString *) inFormat { - (NSData *) javaGetDataForType:(NSString *) inFormat {
NSMutableArray *args = [NSMutableArray arrayWithObject:inFormat]; NSMutableArray *args = [NSMutableArray arrayWithObject:inFormat];
[ThreadUtilities performOnMainThread:@selector(_nativeGetDataForType:) on:self withObject:args waitUntilDone:YES]; [ThreadUtilities performOnMainThread:@selector(_nativeGetDataForType:) on:self withObject:args waitUntilDone:YES];
//NSLog(@"CClipboard javaGetDataForType %@ returns an NSData", inFormat);
return [args lastObject]; return [args lastObject];
} }
...@@ -183,15 +170,11 @@ static CClipboard *sClipboard = nil; ...@@ -183,15 +170,11 @@ static CClipboard *sClipboard = nil;
if (returnValue) [args replaceObjectAtIndex:0 withObject:returnValue]; if (returnValue) [args replaceObjectAtIndex:0 withObject:returnValue];
else [args removeLastObject]; else [args removeLastObject];
//NSLog(@"CClipboard _nativeGetDataForType");
} }
- (void) checkPasteboard:(id)application { - (void) checkPasteboard:(id)application {
AWT_ASSERT_APPKIT_THREAD; AWT_ASSERT_APPKIT_THREAD;
//NSLog(@"CClipboard checkPasteboard oldCount %d newCount %d newTypes %@", fChangeCount, [[NSPasteboard generalPasteboard] changeCount], [[NSPasteboard generalPasteboard] types]);
// This is called via NSApplicationDidBecomeActiveNotification. // This is called via NSApplicationDidBecomeActiveNotification.
// If the change count on the general pasteboard is different than when we set it // If the change count on the general pasteboard is different than when we set it
...@@ -201,19 +184,14 @@ static CClipboard *sClipboard = nil; ...@@ -201,19 +184,14 @@ static CClipboard *sClipboard = nil;
if (fChangeCount != newChangeCount) { if (fChangeCount != newChangeCount) {
fChangeCount = newChangeCount; fChangeCount = newChangeCount;
[self pasteboardChangedOwner:[NSPasteboard generalPasteboard]]; // Notify that the content might be changed
}
}
- (void)pasteboardChangedOwner:(NSPasteboard *)sender; {
AWT_ASSERT_APPKIT_THREAD;
static JNF_CLASS_CACHE(jc_CClipboard, "sun/lwawt/macosx/CClipboard"); static JNF_CLASS_CACHE(jc_CClipboard, "sun/lwawt/macosx/CClipboard");
static JNF_MEMBER_CACHE(jm_lostOwnership, jc_CClipboard, "lostSelectionOwnershipImpl", "()V"); static JNF_STATIC_MEMBER_CACHE(jm_contentChanged, jc_CClipboard, "notifyChanged", "()V");
JNIEnv *env = [ThreadUtilities getJNIEnv];
//NSLog(@"CClipboard pasteboardChangedOwner"); JNFCallStaticVoidMethod(env, jm_contentChanged);
// If we have a Java pasteboard owner, tell it that it doesn't own the pasteboard anymore. // If we have a Java pasteboard owner, tell it that it doesn't own the pasteboard anymore.
static JNF_MEMBER_CACHE(jm_lostOwnership, jc_CClipboard, "notifyLostOwnership", "()V");
@synchronized(self) { @synchronized(self) {
if (fClipboardOwner) { if (fClipboardOwner) {
JNIEnv *env = [ThreadUtilities getJNIEnv]; JNIEnv *env = [ThreadUtilities getJNIEnv];
...@@ -222,6 +200,7 @@ static CClipboard *sClipboard = nil; ...@@ -222,6 +200,7 @@ static CClipboard *sClipboard = nil;
fClipboardOwner = NULL; fClipboardOwner = NULL;
} }
} }
}
} }
@end @end
...@@ -265,9 +244,6 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CClipboard_setData ...@@ -265,9 +244,6 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CClipboard_setData
} }
JNF_COCOA_ENTER(env); JNF_COCOA_ENTER(env);
//NSLog(@"Java_sun_lwawt_macosx_CClipboard_setData");
jint nBytes = (*env)->GetArrayLength(env, inBytes); jint nBytes = (*env)->GetArrayLength(env, inBytes);
jbyte *rawBytes = (*env)->GetPrimitiveArrayCritical(env, inBytes, NULL); jbyte *rawBytes = (*env)->GetPrimitiveArrayCritical(env, inBytes, NULL);
NSData *bytesAsData = [NSData dataWithBytes:rawBytes length:nBytes]; NSData *bytesAsData = [NSData dataWithBytes:rawBytes length:nBytes];
...@@ -288,8 +264,6 @@ JNIEXPORT jlongArray JNICALL Java_sun_lwawt_macosx_CClipboard_getClipboardFormat ...@@ -288,8 +264,6 @@ JNIEXPORT jlongArray JNICALL Java_sun_lwawt_macosx_CClipboard_getClipboardFormat
jlongArray returnValue = NULL; jlongArray returnValue = NULL;
JNF_COCOA_ENTER(env); JNF_COCOA_ENTER(env);
//NSLog(@"Java_sun_lwawt_macosx_CClipboard_getClipboardFormats");
NSArray *dataTypes = [[CClipboard sharedClipboard] javaGetTypes]; NSArray *dataTypes = [[CClipboard sharedClipboard] javaGetTypes];
NSUInteger nFormats = [dataTypes count]; NSUInteger nFormats = [dataTypes count];
NSUInteger knownFormats = 0; NSUInteger knownFormats = 0;
...@@ -346,8 +320,6 @@ JNIEXPORT jbyteArray JNICALL Java_sun_lwawt_macosx_CClipboard_getClipboardData ...@@ -346,8 +320,6 @@ JNIEXPORT jbyteArray JNICALL Java_sun_lwawt_macosx_CClipboard_getClipboardData
// a byte array back to Java. CDataTransferer will do that if necessary. // a byte array back to Java. CDataTransferer will do that if necessary.
JNF_COCOA_ENTER(env); JNF_COCOA_ENTER(env);
//NSLog(@"Java_sun_lwawt_macosx_CClipboard_getClipboardData");
NSString *formatAsString = formatForIndex(format); NSString *formatAsString = formatForIndex(format);
NSData *clipData = [[CClipboard sharedClipboard] javaGetDataForType:formatAsString]; NSData *clipData = [[CClipboard sharedClipboard] javaGetDataForType:formatAsString];
......
...@@ -24,11 +24,12 @@ ...@@ -24,11 +24,12 @@
*/ */
package com.sun.beans.finder; package com.sun.beans.finder;
import com.sun.beans.WeakCache; import com.sun.beans.util.Cache;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import static com.sun.beans.util.Cache.Kind.SOFT;
import static sun.reflect.misc.ReflectUtil.isPackageAccessible; import static sun.reflect.misc.ReflectUtil.isPackageAccessible;
/** /**
...@@ -41,7 +42,18 @@ import static sun.reflect.misc.ReflectUtil.isPackageAccessible; ...@@ -41,7 +42,18 @@ import static sun.reflect.misc.ReflectUtil.isPackageAccessible;
* @author Sergey A. Malenkov * @author Sergey A. Malenkov
*/ */
public final class ConstructorFinder extends AbstractFinder<Constructor<?>> { public final class ConstructorFinder extends AbstractFinder<Constructor<?>> {
private static final WeakCache<Signature, Constructor<?>> CACHE = new WeakCache<Signature, Constructor<?>>(); private static final Cache<Signature, Constructor<?>> CACHE = new Cache<Signature, Constructor<?>>(SOFT, SOFT) {
@Override
public Constructor create(Signature signature) {
try {
ConstructorFinder finder = new ConstructorFinder(signature.getArgs());
return finder.find(signature.getType().getConstructors());
}
catch (Exception exception) {
throw new SignatureException(exception);
}
}
};
/** /**
* Finds public constructor * Finds public constructor
...@@ -69,13 +81,12 @@ public final class ConstructorFinder extends AbstractFinder<Constructor<?>> { ...@@ -69,13 +81,12 @@ public final class ConstructorFinder extends AbstractFinder<Constructor<?>> {
PrimitiveWrapperMap.replacePrimitivesWithWrappers(args); PrimitiveWrapperMap.replacePrimitivesWithWrappers(args);
Signature signature = new Signature(type, args); Signature signature = new Signature(type, args);
Constructor<?> constructor = CACHE.get(signature); try {
if (constructor != null) { return CACHE.get(signature);
return constructor; }
catch (SignatureException exception) {
throw exception.toNoSuchMethodException("Constructor is not found");
} }
constructor = new ConstructorFinder(args).find(type.getConstructors());
CACHE.put(signature, constructor);
return constructor;
} }
/** /**
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
package com.sun.beans.finder; package com.sun.beans.finder;
import com.sun.beans.TypeResolver; import com.sun.beans.TypeResolver;
import com.sun.beans.WeakCache; import com.sun.beans.util.Cache;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
...@@ -33,6 +33,7 @@ import java.lang.reflect.ParameterizedType; ...@@ -33,6 +33,7 @@ import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.Arrays; import java.util.Arrays;
import static com.sun.beans.util.Cache.Kind.SOFT;
import static sun.reflect.misc.ReflectUtil.isPackageAccessible; import static sun.reflect.misc.ReflectUtil.isPackageAccessible;
/** /**
...@@ -45,7 +46,18 @@ import static sun.reflect.misc.ReflectUtil.isPackageAccessible; ...@@ -45,7 +46,18 @@ import static sun.reflect.misc.ReflectUtil.isPackageAccessible;
* @author Sergey A. Malenkov * @author Sergey A. Malenkov
*/ */
public final class MethodFinder extends AbstractFinder<Method> { public final class MethodFinder extends AbstractFinder<Method> {
private static final WeakCache<Signature, Method> CACHE = new WeakCache<Signature, Method>(); private static final Cache<Signature, Method> CACHE = new Cache<Signature, Method>(SOFT, SOFT) {
@Override
public Method create(Signature signature) {
try {
MethodFinder finder = new MethodFinder(signature.getName(), signature.getArgs());
return findAccessibleMethod(finder.find(signature.getType().getMethods()));
}
catch (Exception exception) {
throw new SignatureException(exception);
}
}
};
/** /**
* Finds public method (static or non-static) * Finds public method (static or non-static)
...@@ -65,16 +77,13 @@ public final class MethodFinder extends AbstractFinder<Method> { ...@@ -65,16 +77,13 @@ public final class MethodFinder extends AbstractFinder<Method> {
PrimitiveWrapperMap.replacePrimitivesWithWrappers(args); PrimitiveWrapperMap.replacePrimitivesWithWrappers(args);
Signature signature = new Signature(type, name, args); Signature signature = new Signature(type, name, args);
try {
Method method = CACHE.get(signature); Method method = CACHE.get(signature);
boolean cached = method != null; return (method == null) || isPackageAccessible(method.getDeclaringClass()) ? method : CACHE.create(signature);
if (cached && isPackageAccessible(method.getDeclaringClass())) {
return method;
} }
method = findAccessibleMethod(new MethodFinder(name, args).find(type.getMethods())); catch (SignatureException exception) {
if (!cached) { throw exception.toNoSuchMethodException("Method '" + name + "' is not found");
CACHE.put(signature, method);
} }
return method;
} }
/** /**
......
...@@ -62,6 +62,18 @@ final class Signature { ...@@ -62,6 +62,18 @@ final class Signature {
this.args = args; this.args = args;
} }
Class<?> getType() {
return this.type;
}
String getName() {
return this.name;
}
Class<?>[] getArgs() {
return this.args;
}
/** /**
* Indicates whether some other object is "equal to" this one. * Indicates whether some other object is "equal to" this one.
* *
......
/*
* Copyright (c) 2013, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
package com.sun.beans.finder;
final class SignatureException extends RuntimeException {
SignatureException(Throwable cause) {
super(cause);
}
NoSuchMethodException toNoSuchMethodException(String message) {
Throwable throwable = getCause();
if (throwable instanceof NoSuchMethodException) {
return (NoSuchMethodException) throwable;
}
NoSuchMethodException exception = new NoSuchMethodException(message);
exception.initCause(throwable);
return exception;
}
}
此差异已折叠。
...@@ -43,7 +43,6 @@ import java.io.PrintWriter; ...@@ -43,7 +43,6 @@ import java.io.PrintWriter;
import java.security.AccessController; import java.security.AccessController;
import java.util.Arrays;
import java.util.EventListener; import java.util.EventListener;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
...@@ -4427,6 +4426,7 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener { ...@@ -4427,6 +4426,7 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener {
stopListeningForOtherDrags(); stopListeningForOtherDrags();
mouseEventTarget = null; mouseEventTarget = null;
targetLastEntered = null; targetLastEntered = null;
targetLastEnteredDT = null;
} }
/** /**
...@@ -4617,44 +4617,65 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener { ...@@ -4617,44 +4617,65 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener {
} }
/* /*
* Generates enter/exit events as mouse moves over lw components * Generates dnd enter/exit events as mouse moves over lw components
* @param targetOver Target mouse is over (including native container) * @param targetOver Target mouse is over (including native container)
* @param e Mouse event in native container * @param e SunDropTarget mouse event in native container
*/ */
private void trackMouseEnterExit(Component targetOver, MouseEvent e) { private void trackDropTargetEnterExit(Component targetOver, MouseEvent e) {
Component targetEnter = null;
int id = e.getID(); int id = e.getID();
if (id == MouseEvent.MOUSE_ENTERED && isMouseDTInNativeContainer) {
if (e instanceof SunDropTargetEvent &&
id == MouseEvent.MOUSE_ENTERED &&
isMouseInNativeContainer == true) {
// This can happen if a lightweight component which initiated the // This can happen if a lightweight component which initiated the
// drag has an associated drop target. MOUSE_ENTERED comes when the // drag has an associated drop target. MOUSE_ENTERED comes when the
// mouse is in the native container already. To propagate this event // mouse is in the native container already. To propagate this event
// properly we should null out targetLastEntered. // properly we should null out targetLastEntered.
targetLastEntered = null; targetLastEnteredDT = null;
} else if ( id != MouseEvent.MOUSE_EXITED && } else if (id == MouseEvent.MOUSE_ENTERED) {
isMouseDTInNativeContainer = true;
} else if (id == MouseEvent.MOUSE_EXITED) {
isMouseDTInNativeContainer = false;
}
targetLastEnteredDT = retargetMouseEnterExit(targetOver, e,
targetLastEnteredDT,
isMouseDTInNativeContainer);
}
/*
* Generates enter/exit events as mouse moves over lw components
* @param targetOver Target mouse is over (including native container)
* @param e Mouse event in native container
*/
private void trackMouseEnterExit(Component targetOver, MouseEvent e) {
if (e instanceof SunDropTargetEvent) {
trackDropTargetEnterExit(targetOver, e);
return;
}
int id = e.getID();
if ( id != MouseEvent.MOUSE_EXITED &&
id != MouseEvent.MOUSE_DRAGGED && id != MouseEvent.MOUSE_DRAGGED &&
id != LWD_MOUSE_DRAGGED_OVER && id != LWD_MOUSE_DRAGGED_OVER &&
isMouseInNativeContainer == false ) { !isMouseInNativeContainer) {
// any event but an exit or drag means we're in the native container // any event but an exit or drag means we're in the native container
isMouseInNativeContainer = true; isMouseInNativeContainer = true;
startListeningForOtherDrags(); startListeningForOtherDrags();
} else if ( id == MouseEvent.MOUSE_EXITED ) { } else if (id == MouseEvent.MOUSE_EXITED) {
isMouseInNativeContainer = false; isMouseInNativeContainer = false;
stopListeningForOtherDrags(); stopListeningForOtherDrags();
} }
targetLastEntered = retargetMouseEnterExit(targetOver, e,
if (isMouseInNativeContainer) { targetLastEntered,
targetEnter = targetOver; isMouseInNativeContainer);
} }
if (targetLastEntered == targetEnter) { private Component retargetMouseEnterExit(Component targetOver, MouseEvent e,
return; Component lastEntered,
} boolean inNativeContainer) {
int id = e.getID();
Component targetEnter = inNativeContainer ? targetOver : null;
if (targetLastEntered != null) { if (lastEntered != targetEnter) {
retargetMouseEvent(targetLastEntered, MouseEvent.MOUSE_EXITED, e); if (lastEntered != null) {
retargetMouseEvent(lastEntered, MouseEvent.MOUSE_EXITED, e);
} }
if (id == MouseEvent.MOUSE_EXITED) { if (id == MouseEvent.MOUSE_EXITED) {
// consume native exit event if we generate one // consume native exit event if we generate one
...@@ -4668,8 +4689,8 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener { ...@@ -4668,8 +4689,8 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener {
// consume native enter event if we generate one // consume native enter event if we generate one
e.consume(); e.consume();
} }
}
targetLastEntered = targetEnter; return targetEnter;
} }
/* /*
...@@ -4908,20 +4929,30 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener { ...@@ -4908,20 +4929,30 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener {
private transient Component mouseEventTarget; private transient Component mouseEventTarget;
/** /**
* The last component entered * The last component entered by the {@code MouseEvent}.
*/ */
private transient Component targetLastEntered; private transient Component targetLastEntered;
/**
* The last component entered by the {@code SunDropTargetEvent}.
*/
private transient Component targetLastEnteredDT;
/** /**
* Indicates whether {@code mouseEventTarget} was removed and nulled * Indicates whether {@code mouseEventTarget} was removed and nulled
*/ */
private transient boolean isCleaned; private transient boolean isCleaned;
/** /**
* Is the mouse over the native container * Is the mouse over the native container.
*/ */
private transient boolean isMouseInNativeContainer = false; private transient boolean isMouseInNativeContainer = false;
/**
* Is DnD over the native container.
*/
private transient boolean isMouseDTInNativeContainer = false;
/** /**
* This variable is not used, but kept for serialization compatibility * This variable is not used, but kept for serialization compatibility
*/ */
...@@ -4960,5 +4991,8 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener { ...@@ -4960,5 +4991,8 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener {
if (targetLastEntered == removedComponent) { if (targetLastEntered == removedComponent) {
targetLastEntered = null; targetLastEntered = null;
} }
if (targetLastEnteredDT == removedComponent) {
targetLastEnteredDT = null;
}
} }
} }
/* /*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -736,7 +736,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { ...@@ -736,7 +736,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
if (pref == null || pref.width != getWidth() || if (pref == null || pref.width != getWidth() ||
pref.height != getHeight()) { pref.height != getHeight()) {
popup = getPopup(); showPopup();
} else { } else {
validate(); validate();
} }
...@@ -787,7 +787,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { ...@@ -787,7 +787,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
if(b) { if(b) {
firePopupMenuWillBecomeVisible(); firePopupMenuWillBecomeVisible();
popup = getPopup(); showPopup();
firePropertyChange("visible", Boolean.FALSE, Boolean.TRUE); firePropertyChange("visible", Boolean.FALSE, Boolean.TRUE);
...@@ -805,7 +805,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { ...@@ -805,7 +805,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
} }
/** /**
* Returns a <code>Popup</code> instance from the * Retrieves <code>Popup</code> instance from the
* <code>PopupMenuUI</code> that has had <code>show</code> invoked on * <code>PopupMenuUI</code> that has had <code>show</code> invoked on
* it. If the current <code>popup</code> is non-null, * it. If the current <code>popup</code> is non-null,
* this will invoke <code>dispose</code> of it, and then * this will invoke <code>dispose</code> of it, and then
...@@ -814,7 +814,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { ...@@ -814,7 +814,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
* This does NOT fire any events, it is up the caller to dispatch * This does NOT fire any events, it is up the caller to dispatch
* the necessary events. * the necessary events.
*/ */
private Popup getPopup() { private void showPopup() {
Popup oldPopup = popup; Popup oldPopup = popup;
if (oldPopup != null) { if (oldPopup != null) {
...@@ -838,8 +838,8 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { ...@@ -838,8 +838,8 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
desiredLocationY); desiredLocationY);
popupFactory.setPopupType(PopupFactory.LIGHT_WEIGHT_POPUP); popupFactory.setPopupType(PopupFactory.LIGHT_WEIGHT_POPUP);
popup = newPopup;
newPopup.show(); newPopup.show();
return newPopup;
} }
/** /**
...@@ -873,7 +873,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { ...@@ -873,7 +873,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
desiredLocationX = x; desiredLocationX = x;
desiredLocationY = y; desiredLocationY = y;
if(popup != null && (x != oldX || y != oldY)) { if(popup != null && (x != oldX || y != oldY)) {
popup = getPopup(); showPopup();
} }
} }
...@@ -1030,7 +1030,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { ...@@ -1030,7 +1030,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
Dimension newSize = getPreferredSize(); Dimension newSize = getPreferredSize();
if (!oldSize.equals(newSize)) { if (!oldSize.equals(newSize)) {
popup = getPopup(); showPopup();
} }
} }
} }
......
...@@ -794,19 +794,14 @@ abstract class AppletPanel extends Panel implements AppletStub, Runnable { ...@@ -794,19 +794,14 @@ abstract class AppletPanel extends Panel implements AppletStub, Runnable {
doInit = true; doInit = true;
} else { } else {
// serName is not null; // serName is not null;
InputStream is = (InputStream) try (InputStream is = AccessController.doPrivileged(
java.security.AccessController.doPrivileged( (PrivilegedAction<InputStream>)() -> loader.getResourceAsStream(serName));
new java.security.PrivilegedAction() { ObjectInputStream ois = new AppletObjectInputStream(is, loader)) {
public Object run() {
return loader.getResourceAsStream(serName); applet = (Applet) ois.readObject();
}
});
ObjectInputStream ois =
new AppletObjectInputStream(is, loader);
Object serObject = ois.readObject();
applet = (Applet) serObject;
doInit = false; // skip over the first init doInit = false; // skip over the first init
} }
}
// Determine the JDK level that the applet targets. // Determine the JDK level that the applet targets.
// This is critical for enabling certain backward // This is critical for enabling certain backward
...@@ -1239,20 +1234,13 @@ abstract class AppletPanel extends Panel implements AppletStub, Runnable { ...@@ -1239,20 +1234,13 @@ abstract class AppletPanel extends Panel implements AppletStub, Runnable {
// append .class // append .class
final String resourceName = name + ".class"; final String resourceName = name + ".class";
InputStream is = null;
byte[] classHeader = new byte[8]; byte[] classHeader = new byte[8];
try { try (InputStream is = AccessController.doPrivileged(
is = (InputStream) java.security.AccessController.doPrivileged( (PrivilegedAction<InputStream>) () -> loader.getResourceAsStream(resourceName))) {
new java.security.PrivilegedAction() {
public Object run() {
return loader.getResourceAsStream(resourceName);
}
});
// Read the first 8 bytes of the class file // Read the first 8 bytes of the class file
int byteRead = is.read(classHeader, 0, 8); int byteRead = is.read(classHeader, 0, 8);
is.close();
// return if the header is not read in entirely // return if the header is not read in entirely
// for some reasons. // for some reasons.
......
...@@ -668,11 +668,11 @@ public class AppletViewer extends Frame implements AppletContext, ...@@ -668,11 +668,11 @@ public class AppletViewer extends Frame implements AppletContext,
String dname = fd.getDirectory(); String dname = fd.getDirectory();
File file = new File(dname, fname); File file = new File(dname, fname);
try { try (FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream s = new BufferedOutputStream(new FileOutputStream(file)); BufferedOutputStream bos = new BufferedOutputStream(fos);
ObjectOutputStream os = new ObjectOutputStream(s); ObjectOutputStream os = new ObjectOutputStream(bos)) {
showStatus(amh.getMessage("appletsave.err1",
panel.applet.toString(), file.toString())); showStatus(amh.getMessage("appletsave.err1", panel.applet.toString(), file.toString()));
os.writeObject(panel.applet); os.writeObject(panel.applet);
} catch (IOException ex) { } catch (IOException ex) {
System.err.println(amh.getMessage("appletsave.err2", ex)); System.err.println(amh.getMessage("appletsave.err2", ex));
......
...@@ -432,10 +432,8 @@ public class Main { ...@@ -432,10 +432,8 @@ public class Main {
} }
// SAVE THE FILE // SAVE THE FILE
try { try (FileOutputStream out = new FileOutputStream(dotAV)) {
FileOutputStream out = new FileOutputStream(dotAV);
avProps.store(out, lookup("main.prop.store")); avProps.store(out, lookup("main.prop.store"));
out.close();
} catch (IOException e) { } catch (IOException e) {
System.err.println(lookup("main.err.prop.cantsave", System.err.println(lookup("main.err.prop.cantsave",
dotAV.toString())); dotAV.toString()));
...@@ -472,13 +470,10 @@ public class Main { ...@@ -472,13 +470,10 @@ public class Main {
// read the file // read the file
Properties tmpProps = new Properties(); Properties tmpProps = new Properties();
try { try (FileInputStream in = new FileInputStream(inFile)) {
FileInputStream in = new FileInputStream(inFile);
tmpProps.load(new BufferedInputStream(in)); tmpProps.load(new BufferedInputStream(in));
in.close();
} catch (IOException e) { } catch (IOException e) {
System.err.println(lookup("main.err.prop.cantread", System.err.println(lookup("main.err.prop.cantread", inFile.toString()));
inFile.toString()));
} }
// pick off the properties we care about // pick off the properties we care about
......
...@@ -740,37 +740,7 @@ abstract class XDecoratedPeer extends XWindowPeer { ...@@ -740,37 +740,7 @@ abstract class XDecoratedPeer extends XWindowPeer {
// Bounds of the window // Bounds of the window
Rectangle targetBounds = AWTAccessor.getComponentAccessor().getBounds((Component)target); Rectangle targetBounds = AWTAccessor.getComponentAccessor().getBounds((Component)target);
Point newLocation = targetBounds.getLocation(); Point newLocation = getNewLocation(xe, currentInsets.left, currentInsets.top);
if (xe.get_send_event() || runningWM == XWM.NO_WM || XWM.isNonReparentingWM()) {
// Location, Client size + insets
newLocation = new Point(xe.get_x() - currentInsets.left, xe.get_y() - currentInsets.top);
} else {
// ICCCM 4.1.5 states that a real ConfigureNotify will be sent when
// a window is resized but the client can not tell if the window was
// moved or not. The client should consider the position as unkown
// and use TranslateCoordinates to find the actual position.
//
// TODO this should be the default for every case.
switch (XWM.getWMID()) {
case XWM.CDE_WM:
case XWM.MOTIF_WM:
case XWM.METACITY_WM:
case XWM.MUTTER_WM:
case XWM.SAWFISH_WM:
{
Point xlocation = queryXLocation();
if (log.isLoggable(PlatformLogger.Level.FINE)) {
log.fine("New X location: {0}", xlocation);
}
if (xlocation != null) {
newLocation = xlocation;
}
break;
}
default:
break;
}
}
WindowDimensions newDimensions = WindowDimensions newDimensions =
new WindowDimensions(newLocation, new WindowDimensions(newLocation,
...@@ -1261,12 +1231,4 @@ abstract class XDecoratedPeer extends XWindowPeer { ...@@ -1261,12 +1231,4 @@ abstract class XDecoratedPeer extends XWindowPeer {
} }
super.handleWindowFocusOut(oppositeWindow, serial); super.handleWindowFocusOut(oppositeWindow, serial);
} }
private Point queryXLocation()
{
return XlibUtil.translateCoordinates(
getContentWindow(),
XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber()),
new Point(0, 0));
}
} }
...@@ -740,15 +740,67 @@ class XWindowPeer extends XPanelPeer implements WindowPeer, ...@@ -740,15 +740,67 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
public void paletteChanged() { public void paletteChanged() {
} }
private Point queryXLocation()
{
return XlibUtil.translateCoordinates(
getContentWindow(),
XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber()),
new Point(0, 0));
}
protected Point getNewLocation(XConfigureEvent xe, int leftInset, int topInset) {
// Bounds of the window
Rectangle targetBounds = AWTAccessor.getComponentAccessor().getBounds((Component)target);
int runningWM = XWM.getWMID();
Point newLocation = targetBounds.getLocation();
if (xe.get_send_event() || runningWM == XWM.NO_WM || XWM.isNonReparentingWM()) {
// Location, Client size + insets
newLocation = new Point(xe.get_x() - leftInset, xe.get_y() - topInset);
} else {
// ICCCM 4.1.5 states that a real ConfigureNotify will be sent when
// a window is resized but the client can not tell if the window was
// moved or not. The client should consider the position as unkown
// and use TranslateCoordinates to find the actual position.
//
// TODO this should be the default for every case.
switch (runningWM) {
case XWM.CDE_WM:
case XWM.MOTIF_WM:
case XWM.METACITY_WM:
case XWM.MUTTER_WM:
case XWM.SAWFISH_WM:
{
Point xlocation = queryXLocation();
if (log.isLoggable(PlatformLogger.Level.FINE)) {
log.fine("New X location: {0}", xlocation);
}
if (xlocation != null) {
newLocation = xlocation;
}
break;
}
default:
break;
}
}
return newLocation;
}
/* /*
* Overridden to check if we need to update our GraphicsDevice/Config * Overridden to check if we need to update our GraphicsDevice/Config
* Added for 4934052. * Added for 4934052.
*/ */
@Override @Override
public void handleConfigureNotifyEvent(XEvent xev) { public void handleConfigureNotifyEvent(XEvent xev) {
// TODO: We create an XConfigureEvent every time we override
// handleConfigureNotify() - too many!
XConfigureEvent xe = xev.get_xconfigure(); XConfigureEvent xe = xev.get_xconfigure();
/*
* Correct window location which could be wrong in some cases.
* See getNewLocation() for the details.
*/
Point newLocation = getNewLocation(xe, 0, 0);
xe.set_x(newLocation.x);
xe.set_y(newLocation.y);
checkIfOnNewScreen(new Rectangle(xe.get_x(), checkIfOnNewScreen(new Rectangle(xe.get_x(),
xe.get_y(), xe.get_y(),
xe.get_width(), xe.get_width(),
......
/* /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011,2013 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -23,9 +23,9 @@ ...@@ -23,9 +23,9 @@
/* /*
* @test * @test
* @bug 7122796 * @bug 8004584
* @summary Tests 7122796 * @summary Tests 8004584
* @author anthony.petrov@oracle.com * @author anthony.petrov@oracle.com, petr.pchelko@oracle.com
*/ */
import java.awt.*; import java.awt.*;
...@@ -37,11 +37,9 @@ public class MainAppContext { ...@@ -37,11 +37,9 @@ public class MainAppContext {
public static void main(String[] args) { public static void main(String[] args) {
ThreadGroup secondGroup = new ThreadGroup("test"); ThreadGroup secondGroup = new ThreadGroup("test");
new Thread(secondGroup, new Runnable() { new Thread(secondGroup, () -> {
public void run() {
SunToolkit.createNewAppContext(); SunToolkit.createNewAppContext();
test(true); test(true);
}
}).start(); }).start();
// Sleep on the main thread so that the AWT Toolkit is initialized // Sleep on the main thread so that the AWT Toolkit is initialized
...@@ -51,9 +49,11 @@ public class MainAppContext { ...@@ -51,9 +49,11 @@ public class MainAppContext {
test(false); test(false);
} }
private static void test(boolean userAppContext) { private static void test(boolean expectAppContext) {
if (Toolkit.getDefaultToolkit().getSystemEventQueue() == null) { boolean appContextIsCreated = AppContext.getAppContext() != null;
throw new RuntimeException("No EventQueue for the current app context! userAppContext: " + userAppContext); if (expectAppContext != appContextIsCreated) {
throw new RuntimeException("AppContext is created: " + appContextIsCreated
+ " expected: " + expectAppContext);
} }
} }
} }
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import sun.awt.OSInfo;
import test.java.awt.regtesthelpers.Util; import test.java.awt.regtesthelpers.Util;
public class OpensWithNoGrab public class OpensWithNoGrab
...@@ -49,8 +51,8 @@ public class OpensWithNoGrab ...@@ -49,8 +51,8 @@ public class OpensWithNoGrab
Sysout.createDialog( ); Sysout.createDialog( );
Sysout.printInstructions( instructions ); Sysout.printInstructions( instructions );
String toolkit = Toolkit.getDefaultToolkit().getClass().getName(); if (!(OSInfo.getOSType().equals(OSInfo.OSType.LINUX)
if (toolkit.equals("sun.awt.windows.WToolkit")){ || OSInfo.getOSType().equals(OSInfo.OSType.SOLARIS))) {
System.out.println("This test is for XAWT/Motif only"); System.out.println("This test is for XAWT/Motif only");
OpensWithNoGrab.pass(); OpensWithNoGrab.pass();
} }
......
/* /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -28,15 +28,16 @@ import java.awt.Rectangle; ...@@ -28,15 +28,16 @@ import java.awt.Rectangle;
import java.awt.Robot; import java.awt.Robot;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.event.InputEvent; import java.awt.event.InputEvent;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
/*
/**
* @test * @test
* @bug 8008728 * @bug 8008728
* @summary [macosx] Swing. JDialog. Modal dialog goes to background * @summary [macosx] Swing. JDialog. Modal dialog goes to background
* @author Alexandr Scherbatiy * @author Alexandr Scherbatiy
* @run main ModalDialogOrderingTest * @run main ModalDialogOrderingTest
*/ */
public class ModalDialogOrderingTest { public class ModalDialogOrderingTest {
private static final Color DIALOG_COLOR = Color.GREEN; private static final Color DIALOG_COLOR = Color.GREEN;
...@@ -45,13 +46,13 @@ public class ModalDialogOrderingTest { ...@@ -45,13 +46,13 @@ public class ModalDialogOrderingTest {
public static void main(String[] args) { public static void main(String[] args) {
final Frame frame = new Frame("Test"); final Frame frame = new Frame("Test");
frame.setSize(100, 100); frame.setSize(400, 400);
frame.setBackground(FRAME_COLOR); frame.setBackground(FRAME_COLOR);
frame.setVisible(true); frame.setVisible(true);
final Dialog modalDialog = new Dialog((Frame) null, true); final Dialog modalDialog = new Dialog(null, true);
modalDialog.setTitle("Modal Dialog"); modalDialog.setTitle("Modal Dialog");
modalDialog.setSize(50, 50); modalDialog.setSize(400, 200);
modalDialog.setBackground(DIALOG_COLOR); modalDialog.setBackground(DIALOG_COLOR);
modalDialog.setModal(true); modalDialog.setModal(true);
...@@ -68,40 +69,35 @@ public class ModalDialogOrderingTest { ...@@ -68,40 +69,35 @@ public class ModalDialogOrderingTest {
private static void runTest(Dialog dialog, Frame frame) { private static void runTest(Dialog dialog, Frame frame) {
try { try {
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
Robot robot = new Robot(); Robot robot = new Robot();
robot.setAutoDelay(15); robot.setAutoDelay(50);
robot.mouseMove(300, 300); robot.mouseMove(300, 300);
while (!dialog.isVisible()) { while (!dialog.isVisible()) {
toolkit.realSync(); sleep();
} }
Rectangle dialogBounds = dialog.getBounds(); Rectangle dialogBounds = dialog.getBounds();
Rectangle frameBounds = frame.getBounds(); Rectangle frameBounds = frame.getBounds();
double x0 = dialogBounds.getX(); int y1 = dialogBounds.y + dialogBounds.height;
double y0 = dialogBounds.getY(); int y2 = frameBounds.y + frameBounds.height;
double x1 = dialogBounds.getX() + dialogBounds.getWidth();
double y1 = dialogBounds.getY() + dialogBounds.getHeight();
double x2 = frameBounds.getX() + frameBounds.getWidth();
double y2 = frameBounds.getY() + frameBounds.getHeight();
int clickX = (int) ((x2 + x1) / 2); int clickX = frameBounds.x + frameBounds.width / 2;
int clickY = (int) ((y2 + y1) / 2); int clickY = y1 + (y2 - y1) / 2;
robot.mouseMove(clickX, clickY); robot.mouseMove(clickX, clickY);
robot.mousePress(InputEvent.BUTTON1_MASK); robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK);
toolkit.realSync(); sleep();
int colorX = (int) ((x0 + x1) / 2); int colorX = dialogBounds.x + dialogBounds.width / 2;
int colorY = (int) ((y0 + y1) / 2); int colorY = dialogBounds.y + dialogBounds.height / 2;
Color color = robot.getPixelColor(colorX, colorY); Color color = robot.getPixelColor(colorX, colorY);
dialog.setVisible(false); dialog.dispose();
frame.setVisible(false); frame.dispose();
if (!DIALOG_COLOR.equals(color)) { if (!DIALOG_COLOR.equals(color)) {
throw new RuntimeException("The frame is on top" throw new RuntimeException("The frame is on top"
...@@ -111,4 +107,12 @@ public class ModalDialogOrderingTest { ...@@ -111,4 +107,12 @@ public class ModalDialogOrderingTest {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
} }
private static void sleep() {
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
}
((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
}
} }
...@@ -61,6 +61,12 @@ public class FullscreenEnterEventTest { ...@@ -61,6 +61,12 @@ public class FullscreenEnterEventTest {
return; return;
} }
//Move the mouse out, because it could interfere with the test.
Robot r = Util.createRobot();
Util.waitForIdle(r);
r.mouseMove(0, 0);
Util.waitForIdle(r);
SwingUtilities.invokeAndWait(new Runnable() { SwingUtilities.invokeAndWait(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -69,7 +75,6 @@ public class FullscreenEnterEventTest { ...@@ -69,7 +75,6 @@ public class FullscreenEnterEventTest {
}); });
//Move the mouse away from the frame and check the View-base full screen mode //Move the mouse away from the frame and check the View-base full screen mode
Robot r = Util.createRobot();
Util.waitForIdle(r); Util.waitForIdle(r);
r.mouseMove(500, 500); r.mouseMove(500, 500);
Util.waitForIdle(r); Util.waitForIdle(r);
...@@ -92,6 +97,7 @@ public class FullscreenEnterEventTest { ...@@ -92,6 +97,7 @@ public class FullscreenEnterEventTest {
}); });
//Test native full screen support //Test native full screen support
Util.waitForIdle(r);
Point fullScreenButtonPos = frame.getLocation(); Point fullScreenButtonPos = frame.getLocation();
fullScreenButtonPos.translate(frame.getWidth() - 10, 10); fullScreenButtonPos.translate(frame.getWidth() - 10, 10);
r.mouseMove(fullScreenButtonPos.x, fullScreenButtonPos.y); r.mouseMove(fullScreenButtonPos.x, fullScreenButtonPos.y);
......
/*
* Copyright (c) 2013, 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.
*/
/**
* @test
* @bug 8027628
* @author Oleg Pekhovskiy
* @summary JWindow jumps to (0, 0) after mouse clicked
* @run main TopLevelLocation
*/
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Point;
import java.awt.Robot;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JWindow;
public class TopLevelLocation {
private static JFrame frame;
private static JWindow window;
private static boolean passed = true;
public static void main(String[] args) throws Exception {
EventQueue.invokeAndWait(() -> {
frame = new JFrame();
frame.getContentPane().setBackground(Color.PINK);
frame.setBounds(100, 100, 500, 400);
frame.setUndecorated(true);
frame.setVisible(true);
window = new JWindow(frame);
window.setBackground(Color.BLUE);
window.setAlwaysOnTop(true);
window.setBounds(200, 200, 200, 200);
window.addMouseListener(new MouseAdapter() {
private Point dragOrigin = null;
private Dimension origSize = null;
private Point origLoc = null;
private Point lastLoc = null;
private boolean left = false;
private boolean top = false;
private boolean bottom = false;
private boolean right = false;
@Override
public void mousePressed(MouseEvent e) {
System.out.println("mousePressed");
dragOrigin = e.getLocationOnScreen();
origSize = window.getSize();
origLoc = window.getLocationOnScreen();
if (lastLoc != null) {
System.out.println("SET LOCATION: " + lastLoc);
System.out.println("CURRENT LOCATION: " + origLoc);
if (lastLoc.x != origLoc.x || lastLoc.y != origLoc.y) {
passed = false;
}
}
right = (origLoc.x + window.getWidth() - dragOrigin.x) < 5;
left = !right && dragOrigin.x - origLoc.x < 5;
bottom = (origLoc.y + window.getHeight() - dragOrigin.y) < 5;
top = !bottom && dragOrigin.y - origLoc.y < 5;
}
@Override
public void mouseDragged(MouseEvent e) {
System.out.println("mouseDragged");
resize(e);
}
@Override
public void mouseReleased(MouseEvent e) {
System.out.println("mouseReleased");
resize(e);
}
void resize(MouseEvent e) {
Point dragDelta = e.getLocationOnScreen();
dragDelta.translate(-dragOrigin.x, -dragOrigin.y);
Point newLoc = new Point(origLoc);
newLoc.translate(dragDelta.x, dragDelta.y);
Dimension newSize = new Dimension(origSize);
if (left || right) {
newSize.width += right ? dragDelta.x : -dragDelta.x;
}
if (top || bottom) {
newSize.height += bottom ? dragDelta.y : -dragDelta.y;
}
if (right || (top || bottom) && !left) {
newLoc.x = origLoc.x;
}
if (bottom || (left || right) && !top) {
newLoc.y = origLoc.y;
}
window.setBounds(newLoc.x, newLoc.y, newSize.width, newSize.height);
lastLoc = newLoc;
}
});
window.setVisible(true);
});
Thread.sleep(500);
Dimension size = window.getSize();
Point location = window.getLocation();
Robot robot = new Robot();
robot.setAutoDelay(200);
robot.setAutoWaitForIdle(true);
robot.waitForIdle();
robot.mouseMove(location.x + size.height - 2, location.y + size.width - 2);
robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
robot.mouseMove(location.x + size.height, location.y + size.width);
robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
robot.mouseMove(location.x + size.height + 2, location.y + size.width + 2);
robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
Thread.sleep(500);
frame.dispose();
if (!passed) {
throw new RuntimeException("TEST FAILED: Location doesn't match!");
}
System.out.println("TEST PASSED!");
}
}
/*
* Copyright (c) 2013, 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.
*/
/**
* @test
* @bug 8027913
* @library ../../regtesthelpers
* @build Util
* @compile MissingDragExitEventTest.java
* @run main/othervm MissingDragExitEventTest
* @author Sergey Bylokhov
*/
import java.awt.Color;
import java.awt.Point;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetAdapter;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import sun.awt.SunToolkit;
import test.java.awt.regtesthelpers.Util;
public class MissingDragExitEventTest {
private static volatile JFrame frame;
private static boolean FAILED;
private static boolean MOUSE_ENTERED_DT;
private static boolean MOUSE_ENTERED;
private static boolean MOUSE_EXIT_TD;
private static boolean MOUSE_EXIT;
private static int SIZE = 300;
private static void initAndShowUI() {
frame = new JFrame("Test frame");
frame.setSize(SIZE, SIZE);
frame.setLocationRelativeTo(null);
final JTextArea jta = new JTextArea();
jta.setBackground(Color.RED);
frame.add(jta);
jta.setText("1234567890");
jta.setFont(jta.getFont().deriveFont(150f));
jta.setDragEnabled(true);
jta.selectAll();
jta.setDropTarget(new DropTarget(jta, DnDConstants.ACTION_COPY,
new TestdropTargetListener()));
jta.addMouseListener(new TestMouseAdapter());
frame.setVisible(true);
}
public static void main(final String[] args) throws Exception {
try {
final Robot r = new Robot();
r.setAutoDelay(50);
r.mouseMove(100, 100);
Util.waitForIdle(r);
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
initAndShowUI();
}
});
final Point inside = new Point(frame.getLocationOnScreen());
inside.translate(20, SIZE / 2);
final Point outer = new Point(inside);
outer.translate(-40, 0);
r.mouseMove(inside.x, inside.y);
r.mousePress(InputEvent.BUTTON1_MASK);
try {
for (int i = 0; i < 3; ++i) {
Util.mouseMove(r, inside, outer);
Util.mouseMove(r, outer, inside);
}
} finally {
r.mouseRelease(InputEvent.BUTTON1_MASK);
}
sleep();
if (FAILED || !MOUSE_ENTERED || !MOUSE_ENTERED_DT || !MOUSE_EXIT
|| !MOUSE_EXIT_TD) {
throw new RuntimeException("Failed");
}
} finally {
if (frame != null) {
frame.dispose();
}
}
}
private static void sleep() {
try {
Thread.sleep(10000);
} catch (InterruptedException ignored) {
}
((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
}
static class TestdropTargetListener extends DropTargetAdapter {
private volatile boolean inside;
@Override
public void dragEnter(final DropTargetDragEvent dtde) {
if (inside) {
FAILED = true;
Thread.dumpStack();
}
inside = true;
MOUSE_ENTERED_DT = true;
try {
Thread.sleep(10000); // we should have time to leave a component
} catch (InterruptedException ignored) {
}
}
@Override
public void dragOver(final DropTargetDragEvent dtde) {
if (!inside) {
FAILED = true;
Thread.dumpStack();
}
}
@Override
public void dragExit(final DropTargetEvent dte) {
if (!inside) {
FAILED = true;
Thread.dumpStack();
}
inside = false;
MOUSE_EXIT_TD = true;
}
@Override
public void drop(final DropTargetDropEvent dtde) {
if (!inside) {
FAILED = true;
Thread.dumpStack();
}
inside = false;
}
}
static class TestMouseAdapter extends MouseAdapter {
private volatile boolean inside;
@Override
public void mouseEntered(final MouseEvent e) {
if (inside) {
FAILED = true;
Thread.dumpStack();
}
inside = true;
MOUSE_ENTERED = true;
}
@Override
public void mouseExited(final MouseEvent e) {
if (!inside) {
FAILED = true;
Thread.dumpStack();
}
inside = false;
MOUSE_EXIT = true;
}
}
}
...@@ -31,7 +31,7 @@ import sun.awt.SunToolkit; ...@@ -31,7 +31,7 @@ import sun.awt.SunToolkit;
/* /*
* @test * @test
* @bug 8007156 * @bug 8007156 8025126
* @summary Extended key code is not set for a key event * @summary Extended key code is not set for a key event
* @author Alexandr Scherbatiy * @author Alexandr Scherbatiy
* @run main ExtendedKeyCodeTest * @run main ExtendedKeyCodeTest
...@@ -44,6 +44,7 @@ public class ExtendedKeyCodeTest { ...@@ -44,6 +44,7 @@ public class ExtendedKeyCodeTest {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
Robot robot = new Robot(); Robot robot = new Robot();
robot.setAutoDelay(50);
Frame frame = new Frame(); Frame frame = new Frame();
frame.setSize(300, 300); frame.setSize(300, 300);
...@@ -77,5 +78,29 @@ public class ExtendedKeyCodeTest { ...@@ -77,5 +78,29 @@ public class ExtendedKeyCodeTest {
if (eventsCount != 2 || !setExtendedKeyCode) { if (eventsCount != 2 || !setExtendedKeyCode) {
throw new RuntimeException("Wrong extended key code"); throw new RuntimeException("Wrong extended key code");
} }
frame = new Frame();
frame.setSize(300, 300);
setExtendedKeyCode = false;
frame.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
setExtendedKeyCode = e.getExtendedKeyCode() == KeyEvent.VK_LEFT;
}
});
frame.setVisible(true);
toolkit.realSync();
robot.keyPress(KeyEvent.VK_LEFT);
robot.keyRelease(KeyEvent.VK_LEFT);
toolkit.realSync();
frame.dispose();
if (!setExtendedKeyCode) {
throw new RuntimeException("Wrong extended key code!");
}
} }
} }
/*
* Copyright (c) 2013, 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.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
abstract class Task<T> implements Runnable {
private transient boolean working = true;
private final List<T> methods;
private final Thread thread;
Task(List<T> methods) {
this.methods = methods;
this.thread = new Thread(this);
this.thread.start();
}
boolean isAlive() {
return this.thread.isAlive();
}
boolean isWorking() {
boolean working = this.working && this.thread.isAlive();
this.working = false;
return working;
}
@Override
public void run() {
long time = -System.currentTimeMillis();
for (T method : this.methods) {
this.working = true;
try {
for (int i = 0; i < 100; i++) {
process(method);
}
} catch (NoSuchMethodException ignore) {
}
}
time += System.currentTimeMillis();
print("thread done in " + time / 1000 + " seconds");
}
protected abstract void process(T method) throws NoSuchMethodException;
static synchronized void print(Object message) {
System.out.println(message);
System.out.flush();
}
static List<Class<?>> getClasses(int count) throws Exception {
String resource = ClassLoader.getSystemClassLoader().getResource("java/lang/Object.class").toString();
Pattern pattern = Pattern.compile("jar:file:(.*)!.*");
Matcher matcher = pattern.matcher(resource);
matcher.matches();
resource = matcher.group(1);
List<Class<?>> classes = new ArrayList<>();
try (JarFile jarFile = new JarFile(resource)) {
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
String name = entries.nextElement().getName();
if (name.startsWith("java") && name.endsWith(".class")) {
classes.add(Class.forName(name.substring(0, name.indexOf(".")).replace('/', '.')));
if (count == classes.size()) {
break;
}
}
}
}
return classes;
}
}
/*
* Copyright (c) 2013, 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 com.sun.beans.finder.ConstructorFinder;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/*
* @test
* @bug 8028054
* @summary Tests that cached constructors have synchronized access
* @author Sergey Malenkov
* @compile -XDignore.symbol.file TestConstructorFinder.java
* @run main TestConstructorFinder
*/
public class TestConstructorFinder {
public static void main(String[] args) throws Exception {
List<Class<?>> classes = Task.getClasses(Integer.MAX_VALUE);
List<Constructor> constructors = new ArrayList<>();
for (Class<?> type : classes) {
Collections.addAll(constructors, type.getConstructors());
}
Task.print("found " + constructors.size() + " constructors in " + classes.size() + " classes");
List<Task> tasks = new ArrayList<>();
for (int i = 0; i < 50; i++) {
tasks.add(new Task<Constructor>(constructors) {
@Override
protected void process(Constructor constructor) throws NoSuchMethodException {
ConstructorFinder.findConstructor(constructor.getDeclaringClass(), constructor.getParameterTypes());
}
});
}
int alarm = 0;
while (true) {
int alive = 0;
int working = 0;
for (Task task : tasks) {
if (task.isWorking()) {
working++;
alive++;
} else if (task.isAlive()) {
alive++;
}
}
if (alive == 0) {
break;
}
Task.print(working + " out of " + alive + " threads are working");
if ((working == 0) && (++alarm == 10)) {
Task.print("DEADLOCK DETECTED");
System.exit(100);
}
Thread.sleep(1000);
}
}
}
/*
* Copyright (c) 2013, 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 com.sun.beans.finder.MethodFinder;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/*
* @test
* @bug 8028054
* @summary Tests that cached methods have synchronized access
* @author Sergey Malenkov
* @compile -XDignore.symbol.file TestMethodFinder.java
* @run main TestMethodFinder
*/
public class TestMethodFinder {
public static void main(String[] args) throws Exception {
List<Class<?>> classes = Task.getClasses(4000);
List<Method> methods = new ArrayList<>();
for (Class<?> type : classes) {
Collections.addAll(methods, type.getMethods());
}
Task.print("found " + methods.size() + " methods in " + classes.size() + " classes");
List<Task> tasks = new ArrayList<>();
for (int i = 0; i < 50; i++) {
tasks.add(new Task<Method>(methods) {
@Override
protected void process(Method method) throws NoSuchMethodException {
MethodFinder.findMethod(method.getDeclaringClass(), method.getName(), method.getParameterTypes());
}
});
}
int alarm = 0;
while (true) {
int alive = 0;
int working = 0;
for (Task task : tasks) {
if (task.isWorking()) {
working++;
alive++;
} else if (task.isAlive()) {
alive++;
}
}
if (alive == 0) {
break;
}
Task.print(working + " out of " + alive + " threads are working");
if ((working == 0) && (++alarm == 10)) {
Task.print("DEADLOCK DETECTED");
System.exit(100);
}
Thread.sleep(1000);
}
}
}
/*
* Copyright (c) 2013, 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.
*/
/* @test
@bug 8016356
@summary Any swing frame resizes ugly.
@run main bug8016356
@author Oleg Pekhovskiy
*/
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.InputEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import sun.awt.OSInfo;
public class bug8016356 {
private static JFrame frame;
private static Color color;
private static int scrTop;
private static Point frLoc;
private static Dimension frSize;
public static void main(String[] args) throws Exception {
// Windows only test
if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
// Retrieving top edge of Desktop
GraphicsConfiguration grConf = GraphicsEnvironment
.getLocalGraphicsEnvironment().getDefaultScreenDevice()
.getDefaultConfiguration();
Rectangle scrRect = grConf.getBounds();
Insets scrInsets = Toolkit.getDefaultToolkit().getScreenInsets(grConf);
scrTop = scrRect.y + scrInsets.top;
color = new Color(0, 255, 0);
SwingUtilities.invokeAndWait(() -> {
createAndShowUI();
});
try {
Robot robot = new Robot();
robot.setAutoDelay(500);
robot.setAutoWaitForIdle(true);
robot.delay(1000);
// Resizing a window to invoke Windows Snap feature
readFrameInfo();
robot.mouseMove(frLoc.x + frSize.width / 2, frLoc.y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseMove(frLoc.x + frSize.width / 2, scrTop);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
// Retrieving the color of window expanded area
readFrameInfo();
Insets insets = frame.getInsets();
Color bgColor = robot.getPixelColor(frLoc.x + frSize.width / 2,
frLoc.y + frSize.height - insets.bottom - 1);
frame.dispose();
if (!bgColor.equals(color)) {
throw new RuntimeException("TEST FAILED: got "
+ bgColor + " instead of " + color);
}
System.out.println("TEST PASSED!");
} catch (AWTException ex) {
throw new RuntimeException("TEST FAILED!");
}
}
}
private static void createAndShowUI() {
frame = new JFrame();
frame.setBounds(10, scrTop + 10, 300, 100);
JPanel panel = new JPanel();
panel.setBackground(color);
frame.getContentPane().add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
private static void readFrameInfo() throws Exception {
SwingUtilities.invokeAndWait(() -> {
frLoc = frame.getLocationOnScreen();
frSize = frame.getSize();
});
}
}
<!--
Copyright (c) 2013, 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.
-->
<html>
<body>
<applet code="bug7160604.class" width=400 height=100></applet>
Click on the top-bar and combo-box more than once.
Make sure popup menu and drop-down list have a border and their items are drawn properly.
</body>
</html>
/*
* Copyright (c) 2013, 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.
*/
/* @test
@bug 7160604
@summary Using non-opaque windows - popups are initially not painted correctly
@author Oleg Pekhovskiy
@run applet/manual=yesno bug7160604.html
*/
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JApplet;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class bug7160604 extends JApplet {
public void init() {
SwingUtilities.invokeLater(() -> {
final JWindow window = new JWindow();
window.setLocation(200, 200);
window.setSize(300, 300);
final JLabel label = new JLabel("...click to invoke JPopupMenu");
label.setOpaque(true);
final JPanel contentPane = new JPanel(new BorderLayout());
contentPane.setBorder(BorderFactory.createLineBorder(Color.RED));
window.setContentPane(contentPane);
contentPane.add(label, BorderLayout.NORTH);
final JComboBox comboBox = new JComboBox(new Object[]{"1", "2", "3", "4"});
contentPane.add(comboBox, BorderLayout.SOUTH);
final JPopupMenu jPopupMenu = new JPopupMenu();
jPopupMenu.add("string");
jPopupMenu.add(new AbstractAction("action") {
@Override
public void actionPerformed(final ActionEvent e) {
}
});
jPopupMenu.add(new JLabel("label"));
jPopupMenu.add(new JMenuItem("MenuItem"));
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(final MouseEvent e) {
jPopupMenu.show(label, 0, 0);
}
});
window.setBackground(new Color(0, 0, 0, 0));
window.setVisible(true);
});
}
}
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
*/ */
/* @test /* @test
@bug 8001633 @bug 8001633 8028271
@summary Wrong alt processing during switching between windows @summary Wrong alt processing during switching between windows
@author mikhail.cherkasov@oracle.com @author mikhail.cherkasov@oracle.com
@run main WrongAltProcessing @run main WrongAltProcessing
...@@ -44,17 +44,28 @@ public class WrongAltProcessing { ...@@ -44,17 +44,28 @@ public class WrongAltProcessing {
private static JTextField mainFrameTf2; private static JTextField mainFrameTf2;
private static JTextField secondFrameTf; private static JTextField secondFrameTf;
public static void main(String[] args) throws AWTException { public static void main(String[] args) throws Exception {
try { try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception e) { } catch (Exception e) {
return;// miss unsupported platforms. return;// miss unsupported platforms.
} }
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
createWindows(); createWindows();
}
});
sync();
initRobot(); initRobot();
runScript(); runScript();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
verify(); verify();
} }
});
}
private static void verify() { private static void verify() {
Component c = DefaultKeyboardFocusManager Component c = DefaultKeyboardFocusManager
...@@ -76,7 +87,7 @@ public class WrongAltProcessing { ...@@ -76,7 +87,7 @@ public class WrongAltProcessing {
private static void clickWindowsTitle(JFrame frame) { private static void clickWindowsTitle(JFrame frame) {
Point point = frame.getLocationOnScreen(); Point point = frame.getLocationOnScreen();
robot.mouseMove(point.x + (frame.getWidth() / 2), point.y + 5); robot.mouseMove(point.x + (frame.getWidth() / 2), point.y + frame.getInsets().top / 2);
robot.mousePress(InputEvent.BUTTON1_MASK); robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK);
} }
...@@ -112,6 +123,7 @@ public class WrongAltProcessing { ...@@ -112,6 +123,7 @@ public class WrongAltProcessing {
public static void createWindows() { public static void createWindows() {
firstFrame = new JFrame("Frame"); firstFrame = new JFrame("Frame");
firstFrame.setLayout(new FlowLayout()); firstFrame.setLayout(new FlowLayout());
firstFrame.setPreferredSize(new Dimension(600,100));
JMenuBar bar = new JMenuBar(); JMenuBar bar = new JMenuBar();
JMenu menu = new JMenu("File"); JMenu menu = new JMenu("File");
...@@ -146,24 +158,16 @@ public class WrongAltProcessing { ...@@ -146,24 +158,16 @@ public class WrongAltProcessing {
firstFrame.pack(); firstFrame.pack();
secondFrame = new JFrame("Frame 2"); secondFrame = new JFrame("Frame 2");
secondFrame.setPreferredSize(new Dimension(600,100));
secondFrame.setLocation(0, 150); secondFrame.setLocation(0, 150);
secondFrameTf = new JTextField(20); secondFrameTf = new JTextField(20);
secondFrame.add(secondFrameTf); secondFrame.add(secondFrameTf);
secondFrame.pack(); secondFrame.pack();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
secondFrame.setVisible(true); secondFrame.setVisible(true);
}
});
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
firstFrame.setVisible(true); firstFrame.setVisible(true);
}
});
mainFrameTf1.requestFocus(); mainFrameTf1.requestFocus();
sync();
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册