--- a/jdk/src/macosx/classes/apple/laf/JRSUIConstants.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/macosx/classes/apple/laf/JRSUIConstants.java Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2014, 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
@@ -31,6 +31,13 @@
import java.lang.annotation.Native;
public final class JRSUIConstants {
+
+ /**
+ * There is no way to get width of focus border, so it is hardcoded here.
+ * All components, which can be focused should take care about it.
+ */
+ public static final int FOCUS_SIZE = 4;
+
private static native long getPtrForConstant(final int constant);
static class Key {
--- a/jdk/src/macosx/classes/com/apple/laf/AquaButtonExtendedTypes.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaButtonExtendedTypes.java Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2014, 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
@@ -36,6 +36,8 @@
import com.apple.laf.AquaUtilControlSize.*;
import com.apple.laf.AquaUtils.RecyclableSingleton;
+import static apple.laf.JRSUIConstants.FOCUS_SIZE;
+
/**
* All the "magic numbers" in this class should go away once
* <rdar://problem/4613866> "default font" and sizes for controls in Java Aqua Look and Feel
@@ -145,7 +147,8 @@
protected static Map<String, TypeSpecifier> getAllTypes() {
final Map<String, TypeSpecifier> specifiersByName = new HashMap<String, TypeSpecifier>();
- final Insets focusInsets = new Insets(4, 4, 4, 4);
+ final Insets focusInsets = new Insets(FOCUS_SIZE, FOCUS_SIZE,
+ FOCUS_SIZE, FOCUS_SIZE);
final TypeSpecifier[] specifiers = {
new TypeSpecifier("toolbar", true) {
--- a/jdk/src/macosx/classes/com/apple/laf/AquaIcon.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaIcon.java Wed Apr 16 12:42:40 2014 -0700
@@ -44,7 +44,8 @@
}
static UIResource getIconFor(final JRSUIControlSpec spec, final int width, final int height) {
- return new CachableJRSUIIcon(width, height) {
+ return new ScalingJRSUIIcon(width, height) {
+ @Override
public void initIconPainter(final AquaPainter<JRSUIState> painter) {
spec.initIconPainter(painter);
}
@@ -128,35 +129,12 @@
if (image != null) return image;
if (!GraphicsEnvironment.isHeadless()) {
- image = getOptimizedImage();
+ image = createImage();
}
return image;
}
- private Image getOptimizedImage() {
- final Image img = createImage();
- // TODO: no RuntimeOptions for now
- //if (RuntimeOptions.getRenderer(null) != RuntimeOptions.Sun) return img;
- return getProgressiveOptimizedImage(img, getIconWidth(), getIconHeight());
- }
-
- static Image getProgressiveOptimizedImage(final Image img, final int w, final int h) {
- if (img == null) return null;
-
- final int halfImgW = img.getWidth(null) / 2;
- final int halfImgH = img.getHeight(null) / 2;
- if (w * 2 > halfImgW && h * 2 > halfImgH) return img;
-
- final BufferedImage halfImage = new BufferedImage(halfImgW, halfImgH, BufferedImage.TYPE_INT_ARGB);
- final Graphics g = halfImage.getGraphics();
- ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
- g.drawImage(img, 0, 0, halfImgW, halfImgH, null);
- g.dispose();
-
- return getProgressiveOptimizedImage(halfImage, w, h);
- }
-
abstract Image createImage();
public boolean hasIconRef() {
@@ -189,24 +167,50 @@
}
- static abstract class CachableJRSUIIcon extends CachingScalingIcon implements UIResource {
- public CachableJRSUIIcon(final int width, final int height) {
- super(width, height);
+ static abstract class ScalingJRSUIIcon implements Icon, UIResource {
+ final int width;
+ final int height;
+
+ public ScalingJRSUIIcon(final int width, final int height) {
+ this.width = width;
+ this.height = height;
}
- Image createImage() {
- final AquaPainter<JRSUIState> painter = AquaPainter.create(JRSUIState.getInstance());
+ @Override
+ public void paintIcon(final Component c, Graphics g,
+ final int x, final int y) {
+ if (GraphicsEnvironment.isHeadless()) {
+ return;
+ }
+
+ g = g.create();
+
+ if (g instanceof Graphics2D) {
+ // improves icon rendering quality in Quartz
+ ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_RENDERING,
+ RenderingHints.VALUE_RENDER_QUALITY);
+ }
+
+ final AquaPainter<JRSUIState> painter =
+ AquaPainter.create(JRSUIState.getInstance());
initIconPainter(painter);
- final BufferedImage img = new BufferedImage(getIconWidth(), getIconHeight(), BufferedImage.TYPE_INT_ARGB_PRE);
- final Graphics g = img.getGraphics();
- g.setClip(new Rectangle(0, 0, getIconWidth(), getIconHeight()));
- painter.paint(g, null, 0, 0, getIconWidth(), getIconHeight());
+ g.setClip(new Rectangle(x, y, width, height));
+ painter.paint(g, c, x, y, width, height);
g.dispose();
- return img;
}
public abstract void initIconPainter(final AquaPainter<JRSUIState> painter);
+
+ @Override
+ public int getIconWidth() {
+ return width;
+ }
+
+ @Override
+ public int getIconHeight() {
+ return height;
+ }
}
static class FileIcon extends CachingScalingIcon {
--- a/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameUI.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameUI.java Wed Apr 16 12:42:40 2014 -0700
@@ -787,8 +787,9 @@
}
static final RecyclableSingleton<Icon> RESIZE_ICON = new RecyclableSingleton<Icon>() {
+ @Override
protected Icon getInstance() {
- return new AquaIcon.CachableJRSUIIcon(11, 11) {
+ return new AquaIcon.ScalingJRSUIIcon(11, 11) {
public void initIconPainter(final AquaPainter<JRSUIState> iconState) {
iconState.state.set(Widget.GROW_BOX_TEXTURED);
iconState.state.set(WindowType.UTILITY);
--- a/jdk/src/macosx/classes/com/apple/laf/AquaPainter.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/macosx/classes/com/apple/laf/AquaPainter.java Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2014, 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
@@ -141,40 +141,71 @@
paintFromSingleCachedImage(g, control, stateToPaint, boundsRect);
}
+ /**
+ * Paints a native control, which identified by its size and a set of
+ * additional arguments using a cached image.
+ *
+ * @param g Graphics to draw the control
+ * @param control the reference to the native control
+ * @param controlState the state of the native control
+ * @param bounds the rectangle where the native part should be drawn.
+ * Note: the focus can/will be drawn outside of this bounds.
+ */
static void paintFromSingleCachedImage(final Graphics2D g,
- final JRSUIControl control, final JRSUIState controlState,
- final Rectangle bounds) {
+ final JRSUIControl control,
+ final JRSUIState controlState,
+ final Rectangle bounds) {
if (bounds.width <= 0 || bounds.height <= 0) {
return;
}
- int scale = 1;
- if (g instanceof SunGraphics2D) {
- scale = ((SunGraphics2D) g).surfaceData.getDefaultScale();
+ int focus = 0;
+ if (controlState.is(JRSUIConstants.Focused.YES)) {
+ focus = JRSUIConstants.FOCUS_SIZE;
}
+
+ final int imgX = bounds.x - focus;
+ final int imgY = bounds.y - focus;
+ final int imgW = bounds.width + (focus << 1);
+ final int imgH = bounds.height + (focus << 1);
final GraphicsConfiguration config = g.getDeviceConfiguration();
final ImageCache cache = ImageCache.getInstance();
- final int imgW = bounds.width * scale;
- final int imgH = bounds.height * scale;
- AquaPixelsKey key = new AquaPixelsKey(config,
- imgW, imgH, scale, controlState);
- BufferedImage img = (BufferedImage) cache.getImage(key);
+ final AquaPixelsKey key = new AquaPixelsKey(config, imgW, imgH,
+ bounds, controlState);
+ Image img = cache.getImage(key);
if (img == null) {
- img = new BufferedImage(imgW, imgH, BufferedImage.TYPE_INT_ARGB_PRE);
+
+ Image baseImage = createImage(imgX, imgY, imgW, imgH, bounds,
+ control, controlState);
+
+ img = new MultiResolutionBufferedImage(baseImage,
+ (rvWidth, rvHeight) -> createImage(imgX, imgY,
+ rvWidth, rvHeight, bounds, control, controlState));
+
if (!controlState.is(JRSUIConstants.Animating.YES)) {
cache.setImage(key, img);
}
-
- final WritableRaster raster = img.getRaster();
- final DataBufferInt buffer = (DataBufferInt) raster.getDataBuffer();
-
- control.set(controlState);
- control.paint(SunWritableRaster.stealData(buffer, 0),
- imgW, imgH, 0, 0, bounds.width, bounds.height);
- SunWritableRaster.markDirty(buffer);
}
- g.drawImage(img, bounds.x, bounds.y, bounds.width, bounds.height, null);
+ g.drawImage(img, imgX, imgY, imgW, imgH, null);
+ }
+
+ private static Image createImage(int imgX, int imgY, int imgW, int imgH,
+ final Rectangle bounds,
+ final JRSUIControl control,
+ JRSUIState controlState) {
+ BufferedImage img = new BufferedImage(imgW, imgH,
+ BufferedImage.TYPE_INT_ARGB_PRE);
+
+ final WritableRaster raster = img.getRaster();
+ final DataBufferInt buffer = (DataBufferInt) raster.getDataBuffer();
+
+ control.set(controlState);
+ control.paint(SunWritableRaster.stealData(buffer, 0), imgW, imgH,
+ bounds.x - imgX, bounds.y - imgY, bounds.width,
+ bounds.height);
+ SunWritableRaster.markDirty(buffer);
+ return img;
}
}
@@ -187,21 +218,22 @@
private final GraphicsConfiguration config;
private final int w;
private final int h;
- private final int scale;
+ private final Rectangle bounds;
private final JRSUIState state;
AquaPixelsKey(final GraphicsConfiguration config,
- final int w, final int h, final int scale,
+ final int w, final int h, final Rectangle bounds,
final JRSUIState state) {
this.pixelCount = w * h;
this.config = config;
this.w = w;
this.h = h;
- this.scale = scale;
+ this.bounds = bounds;
this.state = state;
this.hash = hash();
}
+ @Override
public int getPixelCount() {
return pixelCount;
}
@@ -210,7 +242,7 @@
int hash = config != null ? config.hashCode() : 0;
hash = 31 * hash + w;
hash = 31 * hash + h;
- hash = 31 * hash + scale;
+ hash = 31 * hash + bounds.hashCode();
hash = 31 * hash + state.hashCode();
return hash;
}
@@ -225,7 +257,7 @@
if (obj instanceof AquaPixelsKey) {
AquaPixelsKey key = (AquaPixelsKey) obj;
return config == key.config && w == key.w && h == key.h
- && scale == key.scale && state.equals(key.state);
+ && bounds.equals(key.bounds) && state.equals(key.state);
}
return false;
}
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java Wed Apr 16 12:42:40 2014 -0700
@@ -44,6 +44,7 @@
import sun.awt.*;
import sun.awt.datatransfer.DataTransferer;
+import sun.java2d.opengl.OGLRenderQueue;
import sun.lwawt.*;
import sun.lwawt.LWWindowPeer.PeerType;
import sun.security.action.GetBooleanAction;
@@ -410,7 +411,11 @@
@Override
public void sync() {
- // TODO Auto-generated method stub
+ // flush the OGL pipeline (this is a no-op if OGL is not enabled)
+ OGLRenderQueue.sync();
+ // setNeedsDisplay() selector was sent to the appropriate CALayer so now
+ // we have to flush the native selectors queue.
+ flushNativeSelectors();
}
@Override
@@ -813,6 +818,11 @@
private native boolean nativeSyncQueue(long timeout);
+ /**
+ * Just spin a single empty block synchronously.
+ */
+ private static native void flushNativeSelectors();
+
@Override
public Clipboard createPlatformClipboard() {
return new CClipboard("System");
--- a/jdk/src/macosx/native/com/apple/laf/JRSUIController.m Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/macosx/native/com/apple/laf/JRSUIController.m Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2014, 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
@@ -199,7 +199,7 @@
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGContextRef cgRef = CGBitmapContextCreate(rawPixelData, imgW, imgH, 8, imgW * 4, colorspace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host);
CGColorSpaceRelease(colorspace);
- CGContextScaleCTM(cgRef, imgW/w , imgH/h);
+ CGContextScaleCTM(cgRef, imgW/(w + x + x) , imgH/(h + y + y));
jint status = doPaintCGContext(cgRef, controlPtr, oldProperties, newProperties, x, y, w, h);
CGContextRelease(cgRef);
--- a/jdk/src/macosx/native/sun/awt/AWTWindow.m Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/macosx/native/sun/awt/AWTWindow.m Wed Apr 16 12:42:40 2014 -0700
@@ -762,6 +762,10 @@
return lastKeyWindow;
}
+- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame {
+ return !NSEqualSizes(self.nsWindow.frame.size, newFrame.size);
+}
+
@end // AWTWindow
--- a/jdk/src/macosx/native/sun/awt/CClipboard.h Wed Apr 16 11:56:58 2014 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2011, 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.
- */
-
-#import <AppKit/AppKit.h>
-#import "jni.h"
-
-@interface CClipboard : NSObject {
- jobject fClipboardOwner;
-
- // Track pasteboard changes. Initialized once at the start, and then updated
- // on an application resume event. If it's different than the last time we claimed
- // the clipboard that means we lost the clipboard to someone else.
- NSInteger fChangeCount;
-}
-
-+ (CClipboard *) sharedClipboard;
-
-- (void) javaDeclareTypes:(NSArray *)inTypes withOwner:(jobject)inClipboard jniEnv:(JNIEnv *)inEnv;
-- (void) javaSetData:(NSData *)inData forType:(NSString *) inFormat;
-
-- (NSArray *) javaGetTypes;
-- (NSData *) javaGetDataForType:(NSString *)inFormat;
-
-@end
--- a/jdk/src/macosx/native/sun/awt/CClipboard.m Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/macosx/native/sun/awt/CClipboard.m Wed Apr 16 12:42:40 2014 -0700
@@ -23,70 +23,28 @@
* questions.
*/
-#import "CClipboard.h"
#import "CDataTransferer.h"
#import "ThreadUtilities.h"
#import "jni_util.h"
#import <Cocoa/Cocoa.h>
#import <JavaNativeFoundation/JavaNativeFoundation.h>
-static CClipboard *sClipboard = nil;
-
-//
-// CClipboardUpdate is used for mulitple calls to setData that happen before
-// the model and AppKit can get back in sync.
-//
-
-@interface CClipboardUpdate : NSObject {
- NSData *fData;
- NSString *fFormat;
-}
-
-- (id)initWithData:(NSData *)inData withFormat:(NSString *)inFormat;
-- (NSData *)data;
-- (NSString *)format;
-
-@end
-
-@implementation CClipboardUpdate
-
-- (id)initWithData:(NSData *)inData withFormat:(NSString *)inFormat
-{
- self = [super init];
+@interface CClipboard : NSObject { }
+@property NSInteger changeCount;
+@property jobject clipboardOwner;
- if (self != nil) {
- fData = [inData retain];
- fFormat = [inFormat retain];
- }
-
- return self;
-}
-
-- (void)dealloc
-{
- [fData release];
- fData = nil;
-
- [fFormat release];
- fFormat = nil;
-
- [super dealloc];
-}
-
-- (NSData *)data {
- return fData;
-}
-
-- (NSString *)format {
- return fFormat;
-}
++ (CClipboard*)sharedClipboard;
+- (void)declareTypes:(NSArray *)types withOwner:(jobject)owner jniEnv:(JNIEnv*)env;
+- (void)checkPasteboard:(id)sender;
@end
@implementation CClipboard
+@synthesize changeCount = _changeCount;
+@synthesize clipboardOwner = _clipboardOwner;
-// Clipboard creation is synchronized at the Java level.
-+ (CClipboard *) sharedClipboard
-{
+// Clipboard creation is synchronized at the Java level
++ (CClipboard*)sharedClipboard {
+ static CClipboard* sClipboard = nil;
if (sClipboard == nil) {
sClipboard = [[CClipboard alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:sClipboard selector: @selector(checkPasteboard:)
@@ -97,90 +55,38 @@
return sClipboard;
}
-- (id) init
-{
- self = [super init];
-
- if (self != nil) {
- fChangeCount = [[NSPasteboard generalPasteboard] changeCount];
+- (id)init {
+ if (self = [super init]) {
+ self.changeCount = [[NSPasteboard generalPasteboard] changeCount];
}
-
return self;
}
-- (void) javaDeclareTypes:(NSArray *)inTypes withOwner:(jobject)inClipboard jniEnv:(JNIEnv *)inEnv {
-
+- (void)declareTypes:(NSArray*)types withOwner:(jobject)owner jniEnv:(JNIEnv*)env {
@synchronized(self) {
- if (inClipboard != NULL) {
- if (fClipboardOwner != NULL) {
- JNFDeleteGlobalRef(inEnv, fClipboardOwner);
+ if (owner != NULL) {
+ if (self.clipboardOwner != NULL) {
+ JNFDeleteGlobalRef(env, self.clipboardOwner);
}
- fClipboardOwner = JNFNewGlobalRef(inEnv, inClipboard);
+ self.clipboardOwner = JNFNewGlobalRef(env, owner);
}
}
- [ThreadUtilities performOnMainThread:@selector(_nativeDeclareTypes:) on:self withObject:inTypes waitUntilDone:YES];
-}
-
-- (void) _nativeDeclareTypes:(NSArray *)inTypes {
- AWT_ASSERT_APPKIT_THREAD;
-
- fChangeCount = [[NSPasteboard generalPasteboard] declareTypes:inTypes owner:self];
-}
-
-
-- (NSArray *) javaGetTypes {
-
- NSMutableArray *args = [NSMutableArray arrayWithCapacity:1];
- [ThreadUtilities performOnMainThread:@selector(_nativeGetTypes:) on:self withObject:args waitUntilDone:YES];
- return [args lastObject];
-}
-
-- (void) _nativeGetTypes:(NSMutableArray *)args {
- AWT_ASSERT_APPKIT_THREAD;
-
- [args addObject:[[NSPasteboard generalPasteboard] types]];
+ [ThreadUtilities performOnMainThreadWaiting:YES block:^() {
+ self.changeCount = [[NSPasteboard generalPasteboard] declareTypes:types owner:self];
+ }];
}
-- (void) javaSetData:(NSData *)inData forType:(NSString *) inFormat {
-
- CClipboardUpdate *newUpdate = [[CClipboardUpdate alloc] initWithData:inData withFormat:inFormat];
- [ThreadUtilities performOnMainThread:@selector(_nativeSetData:) on:self withObject:newUpdate waitUntilDone:YES];
- [newUpdate release];
-}
-
-- (void) _nativeSetData:(CClipboardUpdate *)newUpdate {
- AWT_ASSERT_APPKIT_THREAD;
-
- [[NSPasteboard generalPasteboard] setData:[newUpdate data] forType:[newUpdate format]];
-}
-
-- (NSData *) javaGetDataForType:(NSString *) inFormat {
+- (void)checkPasteboard:(id)sender {
- NSMutableArray *args = [NSMutableArray arrayWithObject:inFormat];
- [ThreadUtilities performOnMainThread:@selector(_nativeGetDataForType:) on:self withObject:args waitUntilDone:YES];
- return [args lastObject];
-}
-
-- (void) _nativeGetDataForType:(NSMutableArray *) args {
- AWT_ASSERT_APPKIT_THREAD;
-
- NSData *returnValue = [[NSPasteboard generalPasteboard] dataForType:[args objectAtIndex:0]];
-
- if (returnValue) [args replaceObjectAtIndex:0 withObject:returnValue];
- else [args removeLastObject];
-}
-
-- (void) checkPasteboard:(id)application {
- AWT_ASSERT_APPKIT_THREAD;
-
// This is called via NSApplicationDidBecomeActiveNotification.
// If the change count on the general pasteboard is different than when we set it
// someone else put data on the clipboard. That means the current owner lost ownership.
+
NSInteger newChangeCount = [[NSPasteboard generalPasteboard] changeCount];
-
- if (fChangeCount != newChangeCount) {
- fChangeCount = newChangeCount;
+
+ if (self.changeCount != newChangeCount) {
+ self.changeCount = newChangeCount;
// Notify that the content might be changed
static JNF_CLASS_CACHE(jc_CClipboard, "sun/lwawt/macosx/CClipboard");
@@ -191,11 +97,11 @@
// 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) {
- if (fClipboardOwner) {
+ if (self.clipboardOwner) {
JNIEnv *env = [ThreadUtilities getJNIEnv];
- JNFCallVoidMethod(env, fClipboardOwner, jm_lostOwnership); // AWT_THREADING Safe (event)
- JNFDeleteGlobalRef(env, fClipboardOwner);
- fClipboardOwner = NULL;
+ JNFCallVoidMethod(env, self.clipboardOwner, jm_lostOwnership); // AWT_THREADING Safe (event)
+ JNFDeleteGlobalRef(env, self.clipboardOwner);
+ self.clipboardOwner = NULL;
}
}
}
@@ -225,7 +131,7 @@
}
(*env)->ReleasePrimitiveArrayCritical(env, inTypes, elements, JNI_ABORT);
- [[CClipboard sharedClipboard] javaDeclareTypes:formatArray withOwner:inJavaClip jniEnv:env];
+ [[CClipboard sharedClipboard] declareTypes:formatArray withOwner:inJavaClip jniEnv:env];
JNF_COCOA_EXIT(env);
}
@@ -248,7 +154,9 @@
NSData *bytesAsData = [NSData dataWithBytes:rawBytes length:nBytes];
(*env)->ReleasePrimitiveArrayCritical(env, inBytes, rawBytes, JNI_ABORT);
NSString *format = formatForIndex(inFormat);
- [[CClipboard sharedClipboard] javaSetData:bytesAsData forType:format];
+ [ThreadUtilities performOnMainThreadWaiting:YES block:^() {
+ [[NSPasteboard generalPasteboard] setData:bytesAsData forType:format];
+ }];
JNF_COCOA_EXIT(env);
}
@@ -263,7 +171,12 @@
jlongArray returnValue = NULL;
JNF_COCOA_ENTER(env);
- NSArray *dataTypes = [[CClipboard sharedClipboard] javaGetTypes];
+ __block NSArray* dataTypes;
+ [ThreadUtilities performOnMainThreadWaiting:YES block:^() {
+ dataTypes = [[[NSPasteboard generalPasteboard] types] retain];
+ }];
+ [dataTypes autorelease];
+
NSUInteger nFormats = [dataTypes count];
NSUInteger knownFormats = 0;
NSUInteger i;
@@ -320,11 +233,16 @@
JNF_COCOA_ENTER(env);
NSString *formatAsString = formatForIndex(format);
- NSData *clipData = [[CClipboard sharedClipboard] javaGetDataForType:formatAsString];
-
+ __block NSData* clipData;
+ [ThreadUtilities performOnMainThreadWaiting:YES block:^() {
+ clipData = [[[NSPasteboard generalPasteboard] dataForType:formatAsString] retain];
+ }];
+
if (clipData == NULL) {
[JNFException raise:env as:"java/io/IOException" reason:"Font transform has NaN position"];
return NULL;
+ } else {
+ [clipData autorelease];
}
NSUInteger dataSize = [clipData length];
@@ -350,13 +268,13 @@
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CClipboard_checkPasteboard
(JNIEnv *env, jobject inObject )
{
- JNF_COCOA_ENTER(env);
+JNF_COCOA_ENTER(env);
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
[[CClipboard sharedClipboard] checkPasteboard:nil];
}];
- JNF_COCOA_EXIT(env);
+JNF_COCOA_EXIT(env);
}
--- a/jdk/src/macosx/native/sun/awt/CImage.m Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/macosx/native/sun/awt/CImage.m Wed Apr 16 12:42:40 2014 -0700
@@ -379,7 +379,7 @@
return getOrder(size1.width <= size2.width && size1.height <= size2.height);
}];
- NSMutableArray *sortedPixelSizes = [[NSMutableArray alloc] init];
+ NSMutableArray *sortedPixelSizes = [[[NSMutableArray alloc] init] autorelease];
NSSize lastSize = [[sortedImageRepresentations lastObject] size];
NSUInteger i = [sortedImageRepresentations indexOfObjectPassingTest:
--- a/jdk/src/macosx/native/sun/awt/CTextPipe.m Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/macosx/native/sun/awt/CTextPipe.m Wed Apr 16 12:42:40 2014 -0700
@@ -147,7 +147,7 @@
CGAffineTransform invTx = CGAffineTransformInvert(strike->fTx);
- NSUInteger i;
+ NSInteger i;
for (i = 0; i < length; i++)
{
CGGlyph glyph = glyphs[i];
@@ -355,19 +355,31 @@
static JNF_CLASS_CACHE(jc_StandardGlyphVector_GlyphTransformInfo, "sun/font/StandardGlyphVector$GlyphTransformInfo");
static JNF_MEMBER_CACHE(jm_StandardGlyphVector_GlyphTransformInfo_transforms, jc_StandardGlyphVector_GlyphTransformInfo, "transforms", "[D");
jdoubleArray g_gtiTransformsArray = JNFGetObjectField(env, gti, jm_StandardGlyphVector_GlyphTransformInfo_transforms); //(*env)->GetObjectField(env, gti, g_gtiTransforms);
+ if (g_gtiTransformsArray == NULL) {
+ return;
+ }
jdouble *g_gvTransformsAsDoubles = (*env)->GetPrimitiveArrayCritical(env, g_gtiTransformsArray, NULL);
+ if (g_gvTransformsAsDoubles == NULL) {
+ (*env)->DeleteLocalRef(env, g_gtiTransformsArray);
+ return;
+ }
static JNF_MEMBER_CACHE(jm_StandardGlyphVector_GlyphTransformInfo_indices, jc_StandardGlyphVector_GlyphTransformInfo, "indices", "[I");
jintArray g_gtiTXIndicesArray = JNFGetObjectField(env, gti, jm_StandardGlyphVector_GlyphTransformInfo_indices);
jint *g_gvTXIndicesAsInts = (*env)->GetPrimitiveArrayCritical(env, g_gtiTXIndicesArray, NULL);
-
+ if (g_gvTXIndicesAsInts == NULL) {
+ (*env)->ReleasePrimitiveArrayCritical(env, g_gtiTransformsArray, g_gvTransformsAsDoubles, JNI_ABORT);
+ (*env)->DeleteLocalRef(env, g_gtiTransformsArray);
+ (*env)->DeleteLocalRef(env, g_gtiTXIndicesArray);
+ return;
+ }
// slowest case, we have per-glyph transforms, and possibly glyph substitution as well
JavaCT_DrawGlyphVector(qsdo, strike, useSubstituion, uniChars, glyphs, advances, g_gvTXIndicesAsInts, g_gvTransformsAsDoubles, length);
(*env)->ReleasePrimitiveArrayCritical(env, g_gtiTransformsArray, g_gvTransformsAsDoubles, JNI_ABORT);
- (*env)->DeleteLocalRef(env, g_gtiTransformsArray);
+ (*env)->ReleasePrimitiveArrayCritical(env, g_gtiTXIndicesArray, g_gvTXIndicesAsInts, JNI_ABORT);
- (*env)->ReleasePrimitiveArrayCritical(env, g_gtiTXIndicesArray, g_gvTXIndicesAsInts, JNI_ABORT);
+ (*env)->DeleteLocalRef(env, g_gtiTransformsArray);
(*env)->DeleteLocalRef(env, g_gtiTXIndicesArray);
}
@@ -403,6 +415,9 @@
{
// fill the glyph buffer
jint *glyphsAsInts = (*env)->GetPrimitiveArrayCritical(env, glyphsArray, NULL);
+ if (glyphsAsInts == NULL) {
+ return;
+ }
// if a glyph code from Java is negative, that means it is really a unicode value
// which we can use in CoreText to strike the character in another font
@@ -429,11 +444,15 @@
// fill the advance buffer
static JNF_MEMBER_CACHE(jm_StandardGlyphVector_positions, jc_StandardGlyphVector, "positions", "[F");
jfloatArray posArray = JNFGetObjectField(env, gVector, jm_StandardGlyphVector_positions);
- if (posArray != NULL)
- {
+ jfloat *positions = NULL;
+ if (posArray != NULL) {
// in this case, the positions have already been pre-calculated for us on the Java side
-
- jfloat *positions = (*env)->GetPrimitiveArrayCritical(env, posArray, NULL);
+ positions = (*env)->GetPrimitiveArrayCritical(env, posArray, NULL);
+ if (positions == NULL) {
+ (*env)->DeleteLocalRef(env, posArray);
+ }
+ }
+ if (positions != NULL) {
CGPoint prev;
prev.x = positions[0];
prev.y = positions[1];
--- a/jdk/src/macosx/native/sun/awt/JavaComponentAccessibility.m Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/macosx/native/sun/awt/JavaComponentAccessibility.m Wed Apr 16 12:42:40 2014 -0700
@@ -242,11 +242,15 @@
jsize count = [ignoredKeys count];
JNIEnv *env = [ThreadUtilities getJNIEnv];
- jclass clazz = (*env)->FindClass(env, "java/lang/String");
- result = (*env)->NewObjectArray(env, count, clazz, NULL); // AWT_THREADING Safe (known object)
- (*env)->DeleteLocalRef(env, clazz);
- NSUInteger i;
+ static JNF_CLASS_CACHE(jc_String, "java/lang/String");
+ result = JNFNewObjectArray(env, &jc_String, count);
+ if (!result) {
+ NSLog(@"In %s, can't create Java array of String objects", __FUNCTION__);
+ return;
+ }
+
+ NSInteger i;
for (i = 0; i < count; i++) {
jstring jString = JNFNSToJavaString(env, [ignoredKeys objectAtIndex:i]);
(*env)->SetObjectArrayElement(env, result, i, jString);
@@ -281,7 +285,7 @@
jsize arrayLen = (*env)->GetArrayLength(env, jchildrenAndRoles);
NSMutableArray *children = [NSMutableArray arrayWithCapacity:arrayLen/2]; //childrenAndRoles array contains two elements (child, role) for each child
- NSUInteger i;
+ NSInteger i;
NSUInteger childIndex = (whichChildren >= 0) ? whichChildren : 0; // if we're getting one particular child, make sure to set its index correctly
for(i = 0; i < arrayLen; i+=2)
{
@@ -377,8 +381,13 @@
// Get all the other accessibility attributes states we need in one swell foop.
// javaRole isn't pulled in because we need protected access to AccessibleRole.key
jbooleanArray attributeStates = JNFCallStaticObjectMethod(env, jm_getInitialAttributeStates, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
- if (attributeStates == NULL) return NULL;
+ if (attributeStates == NULL) return nil;
jboolean *attributeStatesArray = (*env)->GetBooleanArrayElements(env, attributeStates, 0);
+ if (attributeStatesArray == NULL) {
+ // Note: Java will not be on the stack here so a java exception can't happen and no need to call ExceptionCheck.
+ NSLog(@"%s failed calling GetBooleanArrayElements", __FUNCTION__);
+ return nil;
+ }
// if there's a component, it can be enabled and it has a size/position
if (attributeStatesArray[0]) {
@@ -1206,7 +1215,7 @@
// Go through the tabs and find selAccessible
_numTabs = [tabs count];
JavaComponentAccessibility *aTab;
- NSUInteger i;
+ NSInteger i;
for (i = 0; i < _numTabs; i++) {
aTab = (JavaComponentAccessibility *)[tabs objectAtIndex:i];
if ([aTab isAccessibleWithEnv:env forAccessible:selAccessible]) {
@@ -1233,7 +1242,7 @@
NSString *tabJavaRole = JNFJavaToNSString(env, JNFGetObjectField(env, jtabJavaRole, sjf_key));
- NSUInteger i;
+ NSInteger i;
NSUInteger tabIndex = (whichTabs >= 0) ? whichTabs : 0; // if we're getting one particular child, make sure to set its index correctly
for(i = 0; i < arrayLen; i+=2) {
jobject jtab = (*env)->GetObjectArrayElement(env, jtabsAndRoles, i);
--- a/jdk/src/macosx/native/sun/awt/JavaTextAccessibility.m Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/macosx/native/sun/awt/JavaTextAccessibility.m Wed Apr 16 12:42:40 2014 -0700
@@ -40,6 +40,11 @@
*/
NSValue *javaIntArrayToNSRangeValue(JNIEnv* env, jintArray array) {
jint *values = (*env)->GetIntArrayElements(env, array, 0);
+ if (values == NULL) {
+ // Note: Java will not be on the stack here so a java exception can't happen and no need to call ExceptionCheck.
+ NSLog(@"%s failed calling GetIntArrayElements", __FUNCTION__);
+ return nil;
+ };
NSValue *value = [NSValue valueWithRange:NSMakeRange(values[0], values[1] - values[0])];
(*env)->ReleaseIntArrayElements(env, array, values, 0);
return value;
@@ -285,6 +290,11 @@
// We cheat because we know that the array is 4 elements long (x, y, width, height)
jdouble *values = (*env)->GetDoubleArrayElements(env, axBounds, 0);
+ if (values == NULL) {
+ // Note: Java will not be on the stack here so a java exception can't happen and no need to call ExceptionCheck.
+ NSLog(@"%s failed calling GetDoubleArrayElements", __FUNCTION__);
+ return nil;
+ };
NSRect bounds;
bounds.origin.x = values[0];
bounds.origin.y = [[[[self view] window] screen] frame].size.height - values[1] - values[3]; //values[1] is y-coord from top-left of screen. Flip. Account for the height (values[3]) when flipping
--- a/jdk/src/macosx/native/sun/awt/LWCToolkit.m Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/macosx/native/sun/awt/LWCToolkit.m Wed Apr 16 12:42:40 2014 -0700
@@ -144,6 +144,18 @@
return JNI_FALSE;
}
+/*
+ * Class: sun_lwawt_macosx_LWCToolkit
+ * Method: flushNativeSelectors
+ * Signature: ()J
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_flushNativeSelectors
+(JNIEnv *env, jclass clz)
+{
+JNF_COCOA_ENTER(env);
+ [ThreadUtilities performOnMainThreadWaiting:YES block:^(){}];
+JNF_COCOA_EXIT(env);
+}
static JNF_CLASS_CACHE(jc_Component, "java/awt/Component");
static JNF_MEMBER_CACHE(jf_Component_appContext, jc_Component, "appContext", "Lsun/awt/AppContext;");
--- a/jdk/src/share/classes/com/sun/beans/util/Cache.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/com/sun/beans/util/Cache.java Wed Apr 16 12:42:40 2014 -0700
@@ -119,13 +119,13 @@
synchronized (this.queue) {
// synchronized search improves stability
// we must create and add new value if there are no needed entry
- int index = index(hash, this.table);
- current = getEntryValue(key, hash, this.table[index]);
+ current = getEntryValue(key, hash, this.table[index(hash, this.table)]);
if (current != null) {
return current;
}
V value = create(key);
Objects.requireNonNull(value, "value");
+ int index = index(hash, this.table);
this.table[index] = new CacheEntry<>(hash, key, value, this.table[index]);
if (++this.size >= this.threshold) {
if (this.table.length == MAXIMUM_CAPACITY) {
--- a/jdk/src/share/classes/com/sun/java/swing/plaf/motif/MotifScrollBarUI.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/com/sun/java/swing/plaf/motif/MotifScrollBarUI.java Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, 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
@@ -24,17 +24,19 @@
*/
package com.sun.java.swing.plaf.motif;
-import javax.swing.*;
-import javax.swing.event.*;
-import javax.swing.plaf.*;
-import javax.swing.border.*;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.Rectangle;
+
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JScrollBar;
+import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicScrollBarUI;
-import java.awt.Dimension;
-import java.awt.Insets;
-import java.awt.Rectangle;
-import java.awt.Graphics;
-import java.awt.Color;
+import static sun.swing.SwingUtilities2.drawHLine;
+import static sun.swing.SwingUtilities2.drawVLine;
/**
@@ -74,17 +76,13 @@
return new MotifScrollBarButton(orientation);
}
-
public void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
g.setColor(trackColor);
g.fillRect(trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height);
}
-
- public void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
- {
-
- if(thumbBounds.isEmpty() || !scrollbar.isEnabled()) {
+ public void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
+ if (thumbBounds.isEmpty() || !scrollbar.isEnabled()) {
return;
}
@@ -93,15 +91,15 @@
g.translate(thumbBounds.x, thumbBounds.y);
g.setColor(thumbColor);
- g.fillRect(0, 0, w-1, h-1);
+ g.fillRect(0, 0, w - 1, h - 1);
g.setColor(thumbHighlightColor);
- g.drawLine(0, 0, 0, h-1);
- g.drawLine(1, 0, w-1, 0);
+ drawVLine(g, 0, 0, h - 1);
+ drawHLine(g, 1, w - 1, 0);
g.setColor(thumbLightShadowColor);
- g.drawLine(1, h-1, w-1, h-1);
- g.drawLine(w-1, 1, w-1, h-2);
+ drawHLine(g, 1, w - 1, h - 1);
+ drawVLine(g, w - 1, 1, h - 2);
g.translate(-thumbBounds.x, -thumbBounds.y);
}
--- a/jdk/src/share/classes/com/sun/java/swing/plaf/motif/MotifSliderUI.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/com/sun/java/swing/plaf/motif/MotifSliderUI.java Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, 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
@@ -25,14 +25,17 @@
package com.sun.java.swing.plaf.motif;
-import java.awt.*;
-import java.awt.event.*;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Rectangle;
-import javax.swing.*;
-import javax.swing.event.*;
-import javax.swing.plaf.*;
+import javax.swing.JComponent;
+import javax.swing.JSlider;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicSliderUI;
-import javax.swing.plaf.basic.BasicSliderUI;
+import static sun.swing.SwingUtilities2.drawHLine;
+import static sun.swing.SwingUtilities2.drawVLine;
/**
* Motif Slider
@@ -123,15 +126,15 @@
// highlight
g.setColor(getHighlightColor());
- g.drawLine(0, 1, w - 1, 1); // top
- g.drawLine(0, 1, 0, h); // left
- g.drawLine(w/2, 2, w/2, h-1); // center
+ drawHLine(g, 0, w - 1, 1); // top
+ drawVLine(g, 0, 1, h); // left
+ drawVLine(g, w / 2, 2, h - 1); // center
// shadow
g.setColor(getShadowColor());
- g.drawLine(0, h, w - 1, h); // bottom
- g.drawLine(w - 1, 1, w - 1, h); // right
- g.drawLine(w/2 - 1, 2, w/2 - 1, h); // center
+ drawHLine(g, 0, w - 1, h); // bottom
+ drawVLine(g, w - 1, 1, h); // right
+ drawVLine(g, w / 2 - 1, 2, h); // center
g.translate(-x, -(knobBounds.y-1));
}
@@ -143,15 +146,15 @@
// highlight
g.setColor(getHighlightColor());
- g.drawLine(1, y, w, y); // top
- g.drawLine(1, y+1, 1, y+h-1); // left
- g.drawLine(2, y+h/2, w-1, y+h/2); // center
+ drawHLine(g, 1, w, y); // top
+ drawVLine(g, 1, y + 1, y + h - 1); // left
+ drawHLine(g, 2, w - 1, y + h / 2); // center
// shadow
g.setColor(getShadowColor());
- g.drawLine(2, y+h-1, w, y+h-1); // bottom
- g.drawLine(w, y+h-1, w, y); // right
- g.drawLine(2, y+h/2-1, w-1, y+h/2-1); // center
+ drawHLine(g, 2, w, y + h - 1); // bottom
+ drawVLine(g, w, y + h - 1, y); // right
+ drawHLine(g, 2, w - 1, y + h / 2 - 1);// center
g.translate(-(knobBounds.x-1), 0);
}
--- a/jdk/src/share/classes/com/sun/media/sound/SoftEnvelopeGenerator.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/com/sun/media/sound/SoftEnvelopeGenerator.java Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2014, 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
@@ -118,6 +118,7 @@
return null;
}
+ @SuppressWarnings("fallthrough")
public void processControlLogic() {
for (int i = 0; i < used_count; i++) {
@@ -170,6 +171,7 @@
this.delay[i][0] / 1200.0) / control_time);
if (stage_ix[i] < 0)
stage_ix[i] = 0;
+ // Fallthrough
case EG_DELAY:
if (stage_ix[i] == 0) {
double attack = this.attack[i][0];
--- a/jdk/src/share/classes/java/awt/Container.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/java/awt/Container.java Wed Apr 16 12:42:40 2014 -0700
@@ -263,6 +263,16 @@
boolean ignoreEnabled) {
return cont.findComponentAt(x, y, ignoreEnabled);
}
+
+ @Override
+ public void startLWModal(Container cont) {
+ cont.startLWModal();
+ }
+
+ @Override
+ public void stopLWModal(Container cont) {
+ cont.stopLWModal();
+ }
});
}
--- a/jdk/src/share/classes/java/awt/datatransfer/Clipboard.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/java/awt/datatransfer/Clipboard.java Wed Apr 16 12:42:40 2014 -0700
@@ -27,14 +27,13 @@
import java.awt.EventQueue;
+import java.util.Objects;
import java.util.Set;
import java.util.HashSet;
import java.util.Arrays;
import java.io.IOException;
-import sun.awt.EventListenerAggregate;
-
/**
* A class that implements a mechanism to transfer data using
* cut/copy/paste operations.
@@ -68,7 +67,7 @@
*
* @since 1.5
*/
- private EventListenerAggregate flavorListeners;
+ private Set<FlavorListener> flavorListeners;
/**
* A set of <code>DataFlavor</code>s that is available on
@@ -131,11 +130,7 @@
this.contents = contents;
if (oldOwner != null && oldOwner != owner) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- oldOwner.lostOwnership(Clipboard.this, oldContents);
- }
- });
+ EventQueue.invokeLater(() -> oldOwner.lostOwnership(Clipboard.this, oldContents));
}
fireFlavorsChanged();
}
@@ -261,10 +256,12 @@
if (listener == null) {
return;
}
+
if (flavorListeners == null) {
+ flavorListeners = new HashSet<>();
currentDataFlavors = getAvailableDataFlavorSet();
- flavorListeners = new EventListenerAggregate(FlavorListener.class);
}
+
flavorListeners.add(listener);
}
@@ -306,7 +303,7 @@
*/
public synchronized FlavorListener[] getFlavorListeners() {
return flavorListeners == null ? new FlavorListener[0] :
- (FlavorListener[])flavorListeners.getListenersCopy();
+ flavorListeners.toArray(new FlavorListener[flavorListeners.size()]);
}
/**
@@ -320,21 +317,15 @@
if (flavorListeners == null) {
return;
}
+
Set<DataFlavor> prevDataFlavors = currentDataFlavors;
currentDataFlavors = getAvailableDataFlavorSet();
- if (prevDataFlavors.equals(currentDataFlavors)) {
+ if (Objects.equals(prevDataFlavors, currentDataFlavors)) {
return;
}
- FlavorListener[] flavorListenerArray =
- (FlavorListener[])flavorListeners.getListenersInternal();
- for (int i = 0; i < flavorListenerArray.length; i++) {
- final FlavorListener listener = flavorListenerArray[i];
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- listener.flavorsChanged(new FlavorEvent(Clipboard.this));
- }
- });
- }
+ flavorListeners.forEach(listener ->
+ EventQueue.invokeLater(() ->
+ listener.flavorsChanged(new FlavorEvent(Clipboard.this))));
}
/**
--- a/jdk/src/share/classes/java/awt/datatransfer/DataFlavor.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/java/awt/datatransfer/DataFlavor.java Wed Apr 16 12:42:40 2014 -0700
@@ -25,13 +25,28 @@
package java.awt.datatransfer;
-import java.io.*;
-import java.nio.*;
-import java.util.*;
-
import sun.awt.datatransfer.DataTransferer;
import sun.reflect.misc.ReflectUtil;
+import java.io.ByteArrayInputStream;
+import java.io.CharArrayReader;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.OptionalDataException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Objects;
+
import static sun.security.util.SecurityConstants.GET_CLASSLOADER_PERMISSION;
/**
@@ -92,7 +107,7 @@
* As such, asking a {@code Transferable} for either {@code DataFlavor} returns
* the same results.
* <p>
- * For more information on the using data transfer with Swing see
+ * For more information on using data transfer with Swing see
* the <a href="http://docs.oracle.com/javase/tutorial/uiswing/dnd/index.html">
* How to Use Drag and Drop and Data Transfer</a>,
* section in <em>Java Tutorial</em>.
@@ -390,7 +405,7 @@
* If the <code>mimeType</code> is
* "application/x-java-serialized-object; class=<representation class>",
* the result is the same as calling
- * <code>new DataFlavor(Class:forName(<representation class>)</code>.
+ * <code>new DataFlavor(Class.forName(<representation class>)</code>.
* <p>
* Otherwise:
* <pre>
@@ -398,7 +413,7 @@
* mimeType = mimeType
* </pre>
* @param mimeType the string used to identify the MIME type for this flavor;
- * if the the <code>mimeType</code> does not specify a
+ * if the <code>mimeType</code> does not specify a
* "class=" parameter, or if the class is not successfully
* loaded, then an <code>IllegalArgumentException</code>
* is thrown
@@ -433,7 +448,7 @@
* If the mimeType is
* "application/x-java-serialized-object; class=<representation class>",
* the result is the same as calling
- * <code>new DataFlavor(Class:forName(<representation class>)</code>.
+ * <code>new DataFlavor(Class.forName(<representation class>)</code>.
* <p>
* Otherwise:
* <pre>
@@ -501,7 +516,7 @@
* @throws ClassNotFoundException
* @throws NullPointerException if <code>mimeType</code> is null
*
- * @see tryToLoadClass
+ * @see #tryToLoadClass
*/
private void initialize(String mimeType, String humanPresentableName, ClassLoader classLoader) throws MimeTypeParseException, ClassNotFoundException {
if (mimeType == null) {
@@ -986,14 +1001,8 @@
return true;
}
- if (representationClass == null) {
- if (that.getRepresentationClass() != null) {
- return false;
- }
- } else {
- if (!representationClass.equals(that.getRepresentationClass())) {
- return false;
- }
+ if (!Objects.equals(this.getRepresentationClass(), that.getRepresentationClass())) {
+ return false;
}
if (mimeType == null) {
@@ -1006,34 +1015,22 @@
}
if ("text".equals(getPrimaryType())) {
- if (DataTransferer.doesSubtypeSupportCharset(this) &&
- representationClass != null &&
- !(isRepresentationClassReader() ||
- String.class.equals(representationClass) ||
- isRepresentationClassCharBuffer() ||
- char[].class.equals(representationClass)))
- {
+ if (DataTransferer.doesSubtypeSupportCharset(this)
+ && representationClass != null
+ && !isStandardTextRepresentationClass()) {
String thisCharset =
- DataTransferer.canonicalName(getParameter("charset"));
+ DataTransferer.canonicalName(this.getParameter("charset"));
String thatCharset =
- DataTransferer.canonicalName(that.getParameter("charset"));
- if (thisCharset == null) {
- if (thatCharset != null) {
- return false;
- }
- } else {
- if (!thisCharset.equals(thatCharset)) {
- return false;
- }
+ DataTransferer.canonicalName(that.getParameter("charset"));
+ if (!Objects.equals(thisCharset, thatCharset)) {
+ return false;
}
}
- if ("html".equals(getSubType()) &&
- this.getParameter("document") != null )
- {
- if (!this.getParameter("document").
- equals(that.getParameter("document")))
- {
+ if ("html".equals(getSubType())) {
+ String thisDocument = this.getParameter("document");
+ String thatDocument = that.getParameter("document");
+ if (!Objects.equals(thisDocument, thatDocument)) {
return false;
}
}
@@ -1090,18 +1087,21 @@
// MimeType.match which reports a match if one or both of the
// subTypes is '*', regardless of the other subType.
- if ("text".equals(primaryType) &&
- DataTransferer.doesSubtypeSupportCharset(this) &&
- representationClass != null &&
- !(isRepresentationClassReader() ||
- String.class.equals(representationClass) ||
- isRepresentationClassCharBuffer() ||
- char[].class.equals(representationClass)))
- {
- String charset =
- DataTransferer.canonicalName(getParameter("charset"));
- if (charset != null) {
- total += charset.hashCode();
+ if ("text".equals(primaryType)) {
+ if (DataTransferer.doesSubtypeSupportCharset(this)
+ && representationClass != null
+ && !isStandardTextRepresentationClass()) {
+ String charset = DataTransferer.canonicalName(getParameter("charset"));
+ if (charset != null) {
+ total += charset.hashCode();
+ }
+ }
+
+ if ("html".equals(getSubType())) {
+ String document = this.getParameter("document");
+ if (document != null) {
+ total += document.hashCode();
+ }
}
}
}
@@ -1177,6 +1177,20 @@
return mimeType.match(mtype);
}
+ /**
+ * Checks if the representation class is one of the standard text
+ * representation classes.
+ *
+ * @return true if the representation class is one of the standard text
+ * representation classes, otherwise false
+ */
+ private boolean isStandardTextRepresentationClass() {
+ return isRepresentationClassReader()
+ || String.class.equals(representationClass)
+ || isRepresentationClassCharBuffer()
+ || char[].class.equals(representationClass);
+ }
+
/**
* Does the <code>DataFlavor</code> represent a serialized object?
* @return whether or not a serialized object is represented
--- a/jdk/src/share/classes/java/awt/dnd/DragSourceContext.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/java/awt/dnd/DragSourceContext.java Wed Apr 16 12:42:40 2014 -0700
@@ -576,9 +576,9 @@
throw new InvalidObjectException("Null trigger component");
}
- int DGRActions = newTrigger.getSourceAsDragGestureRecognizer().getSourceActions()
+ int newSourceActions = f.get("sourceActions", 0)
& (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK);
- if (DGRActions == DnDConstants.ACTION_NONE) {
+ if (newSourceActions == DnDConstants.ACTION_NONE) {
throw new InvalidObjectException("Invalid source actions");
}
int triggerActions = newTrigger.getDragAction();
@@ -591,8 +591,7 @@
cursor = (Cursor)f.get("cursor", null);
useCustomCursor = f.get("useCustomCursor", false);
- sourceActions = f.get("sourceActions", 0)
- & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK);
+ sourceActions = newSourceActions;
transferable = (Transferable)s.readObject();
listener = (DragSourceListener)s.readObject();
--- a/jdk/src/share/classes/java/awt/geom/Line2D.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/java/awt/geom/Line2D.java Wed Apr 16 12:42:40 2014 -0700
@@ -35,7 +35,7 @@
* default coordinate system called <i>user space</i> in which the y-axis
* values increase downward and x-axis values increase to the right. For
* more information on the user space coordinate system, see the
- * <a href="http://docs.oracle.com/javase/1.3/docs/guide/2d/spec/j2d-intro.fm2.html#61857">
+ * <a href="{@docRoot}/../technotes/guides/2d/spec/j2d-intro.html">
* Coordinate Systems</a> section of the Java 2D Programmer's Guide.
* <p>
* This class is only the abstract superclass for all objects that
--- a/jdk/src/share/classes/java/beans/Introspector.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/java/beans/Introspector.java Wed Apr 16 12:42:40 2014 -0700
@@ -848,7 +848,7 @@
}
private static boolean isAssignable(Class<?> current, Class<?> candidate) {
- return current == null ? candidate == null : current.isAssignableFrom(candidate);
+ return ((current == null) || (candidate == null)) ? current == candidate : current.isAssignableFrom(candidate);
}
private PropertyDescriptor mergePropertyWithIndexedProperty(PropertyDescriptor pd, IndexedPropertyDescriptor ipd) {
--- a/jdk/src/share/classes/javax/swing/BufferStrategyPaintManager.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/javax/swing/BufferStrategyPaintManager.java Wed Apr 16 12:42:40 2014 -0700
@@ -27,13 +27,10 @@
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
-import java.lang.reflect.*;
import java.lang.ref.WeakReference;
import java.util.*;
import com.sun.java.swing.SwingUtilities3;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import sun.awt.AWTAccessor;
import sun.awt.SubRegionShowable;
--- a/jdk/src/share/classes/javax/swing/JOptionPane.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/javax/swing/JOptionPane.java Wed Apr 16 12:42:40 2014 -0700
@@ -56,6 +56,7 @@
import javax.swing.event.InternalFrameAdapter;
import javax.accessibility.*;
import static javax.swing.ClientPropertyKey.PopupFactory_FORCE_HEAVYWEIGHT_POPUP;
+import sun.awt.AWTAccessor;
/**
* <code>JOptionPane</code> makes it easy to pop up a standard dialog box that
@@ -1306,17 +1307,7 @@
}
}
- // Use reflection to get Container.startLWModal.
- try {
- Method method = AccessController.doPrivileged(new ModalPrivilegedAction(
- Container.class, "startLWModal"));
- if (method != null) {
- method.invoke(dialog, (Object[])null);
- }
- } catch (IllegalAccessException ex) {
- } catch (IllegalArgumentException ex) {
- } catch (InvocationTargetException ex) {
- }
+ AWTAccessor.getContainerAccessor().startLWModal(dialog);
if (parentComponent instanceof JInternalFrame) {
try {
@@ -1451,17 +1442,7 @@
}
}
- // Use reflection to get Container.startLWModal.
- try {
- Method method = AccessController.doPrivileged(new ModalPrivilegedAction(
- Container.class, "startLWModal"));
- if (method != null) {
- method.invoke(dialog, (Object[])null);
- }
- } catch (IllegalAccessException ex) {
- } catch (IllegalArgumentException ex) {
- } catch (InvocationTargetException ex) {
- }
+ AWTAccessor.getContainerAccessor().startLWModal(dialog);
if (parentComponent instanceof JInternalFrame) {
try {
@@ -1535,18 +1516,7 @@
if (iFrame.isVisible() &&
event.getSource() == JOptionPane.this &&
event.getPropertyName().equals(VALUE_PROPERTY)) {
- // Use reflection to get Container.stopLWModal().
- try {
- Method method = AccessController.doPrivileged(
- new ModalPrivilegedAction(
- Container.class, "stopLWModal"));
- if (method != null) {
- method.invoke(iFrame, (Object[])null);
- }
- } catch (IllegalAccessException ex) {
- } catch (IllegalArgumentException ex) {
- } catch (InvocationTargetException ex) {
- }
+ AWTAccessor.getContainerAccessor().stopLWModal(iFrame);
try {
iFrame.setClosed(true);
@@ -2512,33 +2482,6 @@
",wantsInput=" + wantsInputString;
}
- /**
- * Retrieves a method from the provided class and makes it accessible.
- */
- private static class ModalPrivilegedAction implements PrivilegedAction<Method> {
- private Class<?> clazz;
- private String methodName;
-
- public ModalPrivilegedAction(Class<?> clazz, String methodName) {
- this.clazz = clazz;
- this.methodName = methodName;
- }
-
- public Method run() {
- Method method = null;
- try {
- method = clazz.getDeclaredMethod(methodName, (Class[])null);
- } catch (NoSuchMethodException ex) {
- }
- if (method != null) {
- method.setAccessible(true);
- }
- return method;
- }
- }
-
-
-
///////////////////
// Accessibility support
///////////////////
--- a/jdk/src/share/classes/javax/swing/JTable.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/javax/swing/JTable.java Wed Apr 16 12:42:40 2014 -0700
@@ -34,7 +34,6 @@
import java.beans.*;
-import java.io.Serializable;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
@@ -4043,7 +4042,7 @@
}
// Restore the lead
int viewLeadIndex = modelSelection.getLeadSelectionIndex();
- if (viewLeadIndex != -1) {
+ if (viewLeadIndex != -1 && !modelSelection.isSelectionEmpty()) {
viewLeadIndex = convertRowIndexToView(viewLeadIndex);
}
SwingUtilities2.setLeadAnchorWithoutSelection(
@@ -5307,14 +5306,6 @@
return retValue;
}
- private void setLazyValue(Hashtable h, Class c, LazyClass lazyClass) {
- h.put(c, new TableLazyValue(lazyClass));
- }
-
- private void setLazyRenderer(Class c, LazyClass lazyClass) {
- setLazyValue(defaultRenderersByColumnClass, c, lazyClass);
- }
-
/**
* Creates default cell renderers for objects, numbers, doubles, dates,
* booleans, and icons.
@@ -5325,24 +5316,32 @@
defaultRenderersByColumnClass = new UIDefaults(8, 0.75f);
// Objects
- setLazyRenderer(Object.class, LazyClass.UIResource);
+ defaultRenderersByColumnClass.put(Object.class, (UIDefaults.LazyValue)
+ t -> new DefaultTableCellRenderer.UIResource());
// Numbers
- setLazyRenderer(Number.class, LazyClass.NumberRenderer);
+ defaultRenderersByColumnClass.put(Number.class, (UIDefaults.LazyValue)
+ t -> new NumberRenderer());
// Doubles and Floats
- setLazyRenderer(Float.class, LazyClass.DoubleRenderer);
- setLazyRenderer(Double.class, LazyClass.DoubleRenderer);
+ defaultRenderersByColumnClass.put(Float.class, (UIDefaults.LazyValue)
+ t -> new DoubleRenderer());
+ defaultRenderersByColumnClass.put(Double.class, (UIDefaults.LazyValue)
+ t -> new DoubleRenderer());
// Dates
- setLazyRenderer(Date.class, LazyClass.DateRenderer);
+ defaultRenderersByColumnClass.put(Date.class, (UIDefaults.LazyValue)
+ t -> new DateRenderer());
// Icons and ImageIcons
- setLazyRenderer(Icon.class, LazyClass.IconRenderer);
- setLazyRenderer(ImageIcon.class, LazyClass.IconRenderer);
+ defaultRenderersByColumnClass.put(Icon.class, (UIDefaults.LazyValue)
+ t -> new IconRenderer());
+ defaultRenderersByColumnClass.put(ImageIcon.class, (UIDefaults.LazyValue)
+ t -> new IconRenderer());
// Booleans
- setLazyRenderer(Boolean.class, LazyClass.BooleanRenderer);
+ defaultRenderersByColumnClass.put(Boolean.class, (UIDefaults.LazyValue)
+ t -> new BooleanRenderer());
}
/**
@@ -5420,10 +5419,6 @@
}
}
- private void setLazyEditor(Class c, LazyClass lazyClass) {
- setLazyValue(defaultEditorsByColumnClass, c, lazyClass);
- }
-
/**
* Creates default cell editors for objects, numbers, and boolean values.
* @see DefaultCellEditor
@@ -5432,13 +5427,16 @@
defaultEditorsByColumnClass = new UIDefaults(3, 0.75f);
// Objects
- setLazyEditor(Object.class, LazyClass.GenericEditor);
+ defaultEditorsByColumnClass.put(Object.class, (UIDefaults.LazyValue)
+ t -> new GenericEditor());
// Numbers
- setLazyEditor(Number.class, LazyClass.NumberEditor);
+ defaultEditorsByColumnClass.put(Number.class, (UIDefaults.LazyValue)
+ t -> new NumberEditor());
// Booleans
- setLazyEditor(Boolean.class, LazyClass.BooleanEditor);
+ defaultEditorsByColumnClass.put(Boolean.class, (UIDefaults.LazyValue)
+ t -> new BooleanEditor());
}
/**
@@ -6544,54 +6542,6 @@
}
}
- private enum LazyClass {
-
- UIResource,
- NumberRenderer,
- DoubleRenderer,
- DateRenderer,
- IconRenderer,
- BooleanRenderer,
- GenericEditor,
- NumberEditor,
- BooleanEditor,
- }
-
- private static class TableLazyValue implements UIDefaults.LazyValue {
-
- private LazyClass type;
-
- public TableLazyValue(LazyClass type) {
- this.type = type;
- }
-
- @Override
- public Object createValue(UIDefaults table) {
- switch (type) {
- case UIResource:
- return new DefaultTableCellRenderer.UIResource();
- case NumberRenderer:
- return new NumberRenderer();
- case DoubleRenderer:
- return new DoubleRenderer();
- case DateRenderer:
- return new DateRenderer();
- case IconRenderer:
- return new IconRenderer();
- case BooleanRenderer:
- return new BooleanRenderer();
- case GenericEditor:
- return new GenericEditor();
- case NumberEditor:
- return new NumberEditor();
- case BooleanEditor:
- return new BooleanEditor();
- default:
- return null;
- }
- }
- }
-
/////////////////
// Accessibility support
////////////////
@@ -6636,8 +6586,8 @@
TableColumnModelListener, CellEditorListener, PropertyChangeListener,
AccessibleExtendedTable {
- int lastSelectedRow;
- int lastSelectedCol;
+ int previousFocusedRow;
+ int previousFocusedCol;
/**
* AccessibleJTable constructor
@@ -6652,8 +6602,10 @@
tcm.addColumnModelListener(this);
tcm.getSelectionModel().addListSelectionListener(this);
JTable.this.getModel().addTableModelListener(this);
- lastSelectedRow = JTable.this.getSelectedRow();
- lastSelectedCol = JTable.this.getSelectedColumn();
+ previousFocusedRow = JTable.this.getSelectionModel().
+ getLeadSelectionIndex();
+ previousFocusedCol = JTable.this.getColumnModel().
+ getSelectionModel().getLeadSelectionIndex();
}
// Listeners to track model, etc. changes to as to re-place the other
@@ -6979,20 +6931,23 @@
*/
public void valueChanged(ListSelectionEvent e) {
firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
- Boolean.valueOf(false), Boolean.valueOf(true));
-
- int selectedRow = JTable.this.getSelectedRow();
- int selectedCol = JTable.this.getSelectedColumn();
- if (selectedRow != lastSelectedRow ||
- selectedCol != lastSelectedCol) {
- Accessible oldA = getAccessibleAt(lastSelectedRow,
- lastSelectedCol);
- Accessible newA = getAccessibleAt(selectedRow, selectedCol);
+ Boolean.valueOf(false), Boolean.valueOf(true));
+
+ // Using lead selection index to cover both cases: node selected and node
+ // is focused but not selected (Ctrl+up/down)
+ int focusedRow = JTable.this.getSelectionModel().getLeadSelectionIndex();
+ int focusedCol = JTable.this.getColumnModel().getSelectionModel().
+ getLeadSelectionIndex();
+
+ if (focusedRow != previousFocusedRow ||
+ focusedCol != previousFocusedCol) {
+ Accessible oldA = getAccessibleAt(previousFocusedRow, previousFocusedCol);
+ Accessible newA = getAccessibleAt(focusedRow, focusedCol);
firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY,
- oldA, newA);
- lastSelectedRow = selectedRow;
- lastSelectedCol = selectedCol;
- }
+ oldA, newA);
+ previousFocusedRow = focusedRow;
+ previousFocusedCol = focusedCol;
+ }
}
--- a/jdk/src/share/classes/javax/swing/JTree.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/javax/swing/JTree.java Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, 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
@@ -1664,6 +1664,14 @@
leadPath = newPath;
firePropertyChange(LEAD_SELECTION_PATH_PROPERTY, oldValue, newPath);
+
+ // Fire the active descendant property change here since the
+ // leadPath got set, this is triggered both in case node
+ // selection changed and node focus changed
+ if (accessibleContext != null){
+ ((AccessibleJTree)accessibleContext).
+ fireActiveDescendantPropertyChange(oldValue, newPath);
+ }
}
/**
@@ -4129,26 +4137,9 @@
*
*/
public void valueChanged(TreeSelectionEvent e) {
- // Fixes 4546503 - JTree is sending incorrect active
- // descendant events
- TreePath oldLeadSelectionPath = e.getOldLeadSelectionPath();
- leadSelectionPath = e.getNewLeadSelectionPath();
-
- if (oldLeadSelectionPath != leadSelectionPath) {
- // Set parent to null so AccessibleJTreeNode computes
- // its parent.
- Accessible oldLSA = leadSelectionAccessible;
- leadSelectionAccessible = (leadSelectionPath != null)
- ? new AccessibleJTreeNode(JTree.this,
- leadSelectionPath,
- null) // parent
- : null;
- firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY,
- oldLSA, leadSelectionAccessible);
- }
- firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
- Boolean.valueOf(false), Boolean.valueOf(true));
- }
+ firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
+ Boolean.valueOf(false), Boolean.valueOf(true));
+ }
/**
* Fire a visible data property change notification.
@@ -4249,6 +4240,34 @@
}
}
+ /**
+ * Fire an active descendant property change notification.
+ * The active descendant is used for objects such as list,
+ * tree, and table, which may have transient children.
+ * It notifies screen readers the active child of the component
+ * has been changed so user can be notified from there.
+ *
+ * @param oldPath - lead path of previous active child
+ * @param newPath - lead path of current active child
+ *
+ */
+ void fireActiveDescendantPropertyChange(TreePath oldPath, TreePath newPath){
+ if(oldPath != newPath){
+ Accessible oldLSA = (oldPath != null)
+ ? new AccessibleJTreeNode(JTree.this,
+ oldPath,
+ null)
+ : null;
+
+ Accessible newLSA = (newPath != null)
+ ? new AccessibleJTreeNode(JTree.this,
+ newPath,
+ null)
+ : null;
+ firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY,
+ oldLSA, newLSA);
+ }
+ }
private AccessibleContext getCurrentAccessibleContext() {
Component c = getCurrentComponent();
--- a/jdk/src/share/classes/javax/swing/plaf/ComponentUI.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/javax/swing/plaf/ComponentUI.java Wed Apr 16 12:42:40 2014 -0700
@@ -297,7 +297,7 @@
}
/**
- * Returns an enum indicating how the baseline of he component
+ * Returns an enum indicating how the baseline of the component
* changes as the size changes. This method is primarily meant for
* layout managers and GUI builders.
* <p>
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, 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
@@ -37,6 +37,10 @@
import javax.swing.event.*;
import javax.swing.plaf.*;
+import static sun.swing.SwingUtilities2.drawHLine;
+import static sun.swing.SwingUtilities2.drawRect;
+import static sun.swing.SwingUtilities2.drawVLine;
+
/**
* Implementation of ScrollBarUI for the Basic Look and Feel
@@ -572,17 +576,17 @@
g.translate(thumbBounds.x, thumbBounds.y);
g.setColor(thumbDarkShadowColor);
- g.drawRect(0, 0, w-1, h-1);
+ drawRect(g, 0, 0, w - 1, h - 1);
g.setColor(thumbColor);
- g.fillRect(0, 0, w-1, h-1);
+ g.fillRect(0, 0, w - 1, h - 1);
g.setColor(thumbHighlightColor);
- g.drawLine(1, 1, 1, h-2);
- g.drawLine(2, 1, w-3, 1);
+ drawVLine(g, 1, 1, h - 2);
+ drawHLine(g, 2, w - 3, 1);
g.setColor(thumbLightShadowColor);
- g.drawLine(2, h-2, w-2, h-2);
- g.drawLine(w-2, 1, w-2, h-3);
+ drawHLine(g, 2, w - 2, h - 2);
+ drawVLine(g, w - 2, 1, h - 3);
g.translate(-thumbBounds.x, -thumbBounds.y);
}
--- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java Wed Apr 16 12:42:40 2014 -0700
@@ -34,13 +34,10 @@
import javax.swing.text.DefaultEditorKit;
import java.awt.Color;
-import java.awt.event.KeyEvent;
-import java.lang.reflect.*;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.security.AccessController;
-import java.security.PrivilegedAction;
import sun.awt.*;
import sun.security.action.GetPropertyAction;
@@ -460,11 +457,9 @@
LazyValue textFieldBorder =
t -> MetalBorders.getTextFieldBorder();
- Object dialogBorder = new MetalLazyValue(
- "javax.swing.plaf.metal.MetalBorders$DialogBorder");
+ LazyValue dialogBorder = t -> new MetalBorders.DialogBorder();
- Object questionDialogBorder = new MetalLazyValue(
- "javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
+ LazyValue questionDialogBorder = t -> new MetalBorders.QuestionDialogBorder();
Object fieldInputMap = new UIDefaults.LazyInputMap(new Object[] {
"ctrl C", DefaultEditorKit.copyAction,
@@ -1470,12 +1465,8 @@
"ToolBar.floatingBackground", menuBackground,
"ToolBar.dockingForeground", primaryControlDarkShadow,
"ToolBar.floatingForeground", primaryControl,
- "ToolBar.rolloverBorder", new MetalLazyValue(
- "javax.swing.plaf.metal.MetalBorders",
- "getToolBarRolloverBorder"),
- "ToolBar.nonrolloverBorder", new MetalLazyValue(
- "javax.swing.plaf.metal.MetalBorders",
- "getToolBarNonrolloverBorder"),
+ "ToolBar.rolloverBorder", (LazyValue) t -> MetalBorders.getToolBarRolloverBorder(),
+ "ToolBar.nonrolloverBorder", (LazyValue) t -> MetalBorders.getToolBarNonrolloverBorder(),
"ToolBar.ancestorInputMap",
new UIDefaults.LazyInputMap(new Object[] {
"UP", "navigateUp",
@@ -1489,17 +1480,14 @@
}),
// RootPane
- "RootPane.frameBorder", new MetalLazyValue(
- "javax.swing.plaf.metal.MetalBorders$FrameBorder"),
+ "RootPane.frameBorder", (LazyValue) t -> new MetalBorders.FrameBorder(),
"RootPane.plainDialogBorder", dialogBorder,
"RootPane.informationDialogBorder", dialogBorder,
- "RootPane.errorDialogBorder", new MetalLazyValue(
- "javax.swing.plaf.metal.MetalBorders$ErrorDialogBorder"),
+ "RootPane.errorDialogBorder", (LazyValue) t -> new MetalBorders.ErrorDialogBorder(),
"RootPane.colorChooserDialogBorder", questionDialogBorder,
"RootPane.fileChooserDialogBorder", questionDialogBorder,
"RootPane.questionDialogBorder", questionDialogBorder,
- "RootPane.warningDialogBorder", new MetalLazyValue(
- "javax.swing.plaf.metal.MetalBorders$WarningDialogBorder"),
+ "RootPane.warningDialogBorder", (LazyValue) t -> new MetalBorders.WarningDialogBorder(),
// These bindings are only enabled when there is a default
// button set on the rootpane.
"RootPane.defaultButtonWindowKeyBindings", new Object[] {
@@ -2151,61 +2139,6 @@
/**
- * MetalLazyValue is a slimmed down version of <code>ProxyLaxyValue</code>.
- * The code is duplicate so that it can get at the package private
- * classes in metal.
- */
- private static class MetalLazyValue implements UIDefaults.LazyValue {
- /**
- * Name of the class to create.
- */
- private String className;
- private String methodName;
-
- MetalLazyValue(String name) {
- this.className = name;
- }
-
- MetalLazyValue(String name, String methodName) {
- this(name);
- this.methodName = methodName;
- }
-
- public Object createValue(UIDefaults table) {
- try {
- final Class c = Class.forName(className);
-
- if (methodName == null) {
- return c.newInstance();
- }
- Method method = AccessController.doPrivileged(
- new PrivilegedAction<Method>() {
- public Method run() {
- Method[] methods = c.getDeclaredMethods();
- for (int counter = methods.length - 1; counter >= 0;
- counter--) {
- if (methods[counter].getName().equals(methodName)){
- methods[counter].setAccessible(true);
- return methods[counter];
- }
- }
- return null;
- }
- });
- if (method != null) {
- return method.invoke(null, (Object[])null);
- }
- } catch (ClassNotFoundException cnfe) {
- } catch (InstantiationException ie) {
- } catch (IllegalAccessException iae) {
- } catch (InvocationTargetException ite) {
- }
- return null;
- }
- }
-
-
- /**
* FontActiveValue redirects to the appropriate metal theme method.
*/
private static class FontActiveValue implements UIDefaults.ActiveValue {
--- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalScrollBarUI.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalScrollBarUI.java Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2014, 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
@@ -25,33 +25,23 @@
package javax.swing.plaf.metal;
-import java.awt.Component;
-import java.awt.Container;
-import java.awt.LayoutManager;
-import java.awt.Adjustable;
-import java.awt.event.AdjustmentListener;
-import java.awt.event.AdjustmentEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.ActionEvent;
-import java.awt.event.MouseListener;
-import java.awt.event.MouseMotionListener;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.Graphics;
+import java.awt.Color;
import java.awt.Dimension;
+import java.awt.Graphics;
import java.awt.Rectangle;
-import java.awt.Point;
-import java.awt.Insets;
-import java.awt.Color;
-import java.awt.IllegalComponentStateException;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
-import java.beans.*;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JScrollBar;
+import javax.swing.UIManager;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicScrollBarUI;
-import javax.swing.*;
-import javax.swing.event.*;
-
-import javax.swing.plaf.*;
-import javax.swing.plaf.basic.BasicScrollBarUI;
+import static sun.swing.SwingUtilities2.drawHLine;
+import static sun.swing.SwingUtilities2.drawRect;
+import static sun.swing.SwingUtilities2.drawVLine;
/**
@@ -158,21 +148,21 @@
if ( c.isEnabled() ) {
g.setColor( darkShadowColor );
- g.drawLine( 0, 0, 0, trackBounds.height - 1 );
- g.drawLine( trackBounds.width - 2, 0, trackBounds.width - 2, trackBounds.height - 1 );
- g.drawLine( 2, trackBounds.height - 1, trackBounds.width - 1, trackBounds.height - 1);
- g.drawLine( 2, 0, trackBounds.width - 2, 0 );
+ drawVLine(g, 0, 0, trackBounds.height - 1);
+ drawVLine(g, trackBounds.width - 2, 0, trackBounds.height - 1);
+ drawHLine(g, 2, trackBounds.width - 1, trackBounds.height - 1);
+ drawHLine(g, 2, trackBounds.width - 2, 0);
g.setColor( shadowColor );
// g.setColor( Color.red);
- g.drawLine( 1, 1, 1, trackBounds.height - 2 );
- g.drawLine( 1, 1, trackBounds.width - 3, 1 );
+ drawVLine(g, 1, 1, trackBounds.height - 2);
+ drawHLine(g, 1, trackBounds.width - 3, 1);
if (scrollbar.getValue() != scrollbar.getMaximum()) { // thumb shadow
int y = thumbRect.y + thumbRect.height - trackBounds.y;
- g.drawLine( 1, y, trackBounds.width-1, y);
+ drawHLine(g, 1, trackBounds.width - 1, y);
}
g.setColor(highlightColor);
- g.drawLine( trackBounds.width - 1, 0, trackBounds.width - 1, trackBounds.height - 1 );
+ drawVLine(g, trackBounds.width - 1, 0, trackBounds.height - 1);
} else {
MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height );
}
@@ -192,19 +182,19 @@
if ( c.isEnabled() ) {
g.setColor( darkShadowColor );
- g.drawLine( 0, 0, trackBounds.width - 1, 0 ); // top
- g.drawLine( 0, 2, 0, trackBounds.height - 2 ); // left
- g.drawLine( 0, trackBounds.height - 2, trackBounds.width - 1, trackBounds.height - 2 ); // bottom
- g.drawLine( trackBounds.width - 1, 2, trackBounds.width - 1, trackBounds.height - 1 ); // right
+ drawHLine(g, 0, trackBounds.width - 1, 0); // top
+ drawVLine(g, 0, 2, trackBounds.height - 2); // left
+ drawHLine(g, 0, trackBounds.width - 1, trackBounds.height - 2 ); // bottom
+ drawVLine(g, trackBounds.width - 1, 2, trackBounds.height - 1 ); // right
g.setColor( shadowColor );
// g.setColor( Color.red);
- g.drawLine( 1, 1, trackBounds.width - 2, 1 ); // top
- g.drawLine( 1, 1, 1, trackBounds.height - 3 ); // left
- g.drawLine( 0, trackBounds.height - 1, trackBounds.width - 1, trackBounds.height - 1 ); // bottom
+ drawHLine(g, 1, trackBounds.width - 2, 1 ); // top
+ drawVLine(g, 1, 1, trackBounds.height - 3 ); // left
+ drawHLine(g, 0, trackBounds.width - 1, trackBounds.height - 1 ); // bottom
if (scrollbar.getValue() != scrollbar.getMaximum()) { // thumb shadow
int x = thumbRect.x + thumbRect.width - trackBounds.x;
- g.drawLine( x, 1, x, trackBounds.height-1);
+ drawVLine(g, x, 1, trackBounds.height-1);
}
} else {
MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height );
@@ -246,11 +236,11 @@
g.fillRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1 );
g.setColor( thumbShadow );
- g.drawRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1 );
+ drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
g.setColor( thumbHighlightColor );
- g.drawLine( 1, 1, thumbBounds.width - 3, 1 );
- g.drawLine( 1, 1, 1, thumbBounds.height - 2 );
+ drawHLine(g, 1, thumbBounds.width - 3, 1);
+ drawVLine(g, 1, 1, thumbBounds.height - 2);
bumps.setBumpArea( thumbBounds.width - 6, thumbBounds.height - 7 );
bumps.paintIcon( c, g, 3, 4 );
@@ -272,11 +262,11 @@
g.fillRect( 0, 0, thumbBounds.width - 1, thumbBounds.height - 2 );
g.setColor( thumbShadow );
- g.drawRect( 0, 0, thumbBounds.width - 1, thumbBounds.height - 2 );
+ drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
g.setColor( thumbHighlightColor );
- g.drawLine( 1, 1, thumbBounds.width - 3, 1 );
- g.drawLine( 1, 1, 1, thumbBounds.height - 3 );
+ drawHLine(g, 1, thumbBounds.width - 3, 1);
+ drawVLine(g, 1, 1, thumbBounds.height - 3);
bumps.setBumpArea( thumbBounds.width - 7, thumbBounds.height - 6 );
bumps.paintIcon( c, g, 4, 3 );
@@ -309,11 +299,11 @@
}
g.setColor(thumbShadow);
- g.drawRect(0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
+ drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
g.setColor(thumbHighlightColor);
- g.drawLine(1, 1, thumbBounds.width - 3, 1);
- g.drawLine(1, 1, 1, thumbBounds.height - 2);
+ drawHLine(g, 1, thumbBounds.width - 3, 1);
+ drawVLine(g, 1, 1, thumbBounds.height - 2);
MetalUtils.drawGradient(c, g, "ScrollBar.gradient", 2, 2,
thumbBounds.width - 4,
@@ -351,11 +341,11 @@
}
g.setColor(thumbShadow);
- g.drawRect(0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
+ drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
g.setColor(thumbHighlightColor);
- g.drawLine(1, 1, thumbBounds.width - 2, 1);
- g.drawLine(1, 1, 1, thumbBounds.height - 3);
+ drawHLine(g, 1, thumbBounds.width - 2, 1);
+ drawVLine(g, 1, 1, thumbBounds.height - 3);
MetalUtils.drawGradient(c, g, "ScrollBar.gradient", 2, 2,
thumbBounds.width - 3,
--- a/jdk/src/share/classes/javax/swing/text/EditorKit.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/javax/swing/text/EditorKit.java Wed Apr 16 12:42:40 2014 -0700
@@ -39,9 +39,9 @@
* A kit can safely store editing state as an instance
* of the kit will be dedicated to a text component.
* New kits will normally be created by cloning a
- * prototype kit. The kit will have it's
+ * prototype kit. The kit will have its
* <code>setComponent</code> method called to establish
- * it's relationship with a JTextComponent.
+ * its relationship with a JTextComponent.
*
* @author Timothy Prinzing
*/
--- a/jdk/src/share/classes/javax/swing/text/JTextComponent.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/javax/swing/text/JTextComponent.java Wed Apr 16 12:42:40 2014 -0700
@@ -24,18 +24,16 @@
*/
package javax.swing.text;
-import java.lang.reflect.Method;
+import com.sun.beans.util.Cache;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.beans.Transient;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.Vector;
-import java.util.Map;
import java.util.concurrent.*;
@@ -1194,47 +1192,6 @@
}
/**
- * Returns true if <code>klass</code> is NOT a JTextComponent and it or
- * one of its superclasses (stoping at JTextComponent) overrides
- * <code>processInputMethodEvent</code>. It is assumed this will be
- * invoked from within a <code>doPrivileged</code>, and it is also
- * assumed <code>klass</code> extends <code>JTextComponent</code>.
- */
- private static Boolean isProcessInputMethodEventOverridden(Class<?> klass) {
- if (klass == JTextComponent.class) {
- return Boolean.FALSE;
- }
- Boolean retValue = overrideMap.get(klass.getName());
-
- if (retValue != null) {
- return retValue;
- }
- Boolean sOverriden = isProcessInputMethodEventOverridden(
- klass.getSuperclass());
-
- if (sOverriden.booleanValue()) {
- // If our superclass has overriden it, then by definition klass
- // overrides it.
- overrideMap.put(klass.getName(), sOverriden);
- return sOverriden;
- }
- // klass's superclass didn't override it, check for an override in
- // klass.
- try {
- Class[] classes = new Class[1];
- classes[0] = InputMethodEvent.class;
-
- Method m = klass.getDeclaredMethod("processInputMethodEvent",
- classes);
- retValue = Boolean.TRUE;
- } catch (NoSuchMethodException nsme) {
- retValue = Boolean.FALSE;
- }
- overrideMap.put(klass.getName(), retValue);
- return retValue;
- }
-
- /**
* Fetches the current color used to render the
* caret.
*
@@ -3916,7 +3873,33 @@
* Maps from class name to Boolean indicating if
* <code>processInputMethodEvent</code> has been overriden.
*/
- private static Map<String, Boolean> overrideMap;
+ private static Cache<Class<?>,Boolean> METHOD_OVERRIDDEN
+ = new Cache<Class<?>,Boolean>(Cache.Kind.WEAK, Cache.Kind.STRONG) {
+ /**
+ * Returns {@code true} if the specified {@code type} extends {@link JTextComponent}
+ * and the {@link JTextComponent#processInputMethodEvent} method is overridden.
+ */
+ @Override
+ public Boolean create(final Class<?> type) {
+ if (JTextComponent.class == type) {
+ return Boolean.FALSE;
+ }
+ if (get(type.getSuperclass())) {
+ return Boolean.TRUE;
+ }
+ return AccessController.doPrivileged(
+ new PrivilegedAction<Boolean>() {
+ public Boolean run() {
+ try {
+ type.getDeclaredMethod("processInputMethodEvent", InputMethodEvent.class);
+ return Boolean.TRUE;
+ } catch (NoSuchMethodException exception) {
+ return Boolean.FALSE;
+ }
+ }
+ });
+ }
+ };
/**
* Returns a string representation of this <code>JTextComponent</code>.
@@ -4941,39 +4924,16 @@
*/
private boolean shouldSynthensizeKeyEvents() {
if (!checkedInputOverride) {
+ // Checks whether the client code overrides processInputMethodEvent.
+ // If it is overridden, need not to generate KeyTyped events for committed text.
+ // If it's not, behave as an passive input method client.
+ needToSendKeyTypedEvent = !METHOD_OVERRIDDEN.get(getClass());
checkedInputOverride = true;
- needToSendKeyTypedEvent =
- !isProcessInputMethodEventOverridden();
}
return needToSendKeyTypedEvent;
}
//
- // Checks whether the client code overrides processInputMethodEvent. If it is overridden,
- // need not to generate KeyTyped events for committed text. If it's not, behave as an
- // passive input method client.
- //
- private boolean isProcessInputMethodEventOverridden() {
- if (overrideMap == null) {
- overrideMap = Collections.synchronizedMap(new HashMap<String, Boolean>());
- }
- Boolean retValue = overrideMap.get(getClass().getName());
-
- if (retValue != null) {
- return retValue.booleanValue();
- }
- Boolean ret = AccessController.doPrivileged(new
- PrivilegedAction<Boolean>() {
- public Boolean run() {
- return isProcessInputMethodEventOverridden(
- JTextComponent.this.getClass());
- }
- });
-
- return ret.booleanValue();
- }
-
- //
// Checks whether a composed text in this text component
//
boolean composedTextExists() {
--- a/jdk/src/share/classes/javax/swing/text/html/HTMLEditorKit.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/javax/swing/text/html/HTMLEditorKit.java Wed Apr 16 12:42:40 2014 -0700
@@ -26,7 +26,6 @@
import sun.awt.AppContext;
-import java.lang.reflect.Method;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
@@ -34,12 +33,13 @@
import java.net.URL;
import javax.swing.text.*;
import javax.swing.*;
-import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.plaf.TextUI;
import java.util.*;
import javax.accessibility.*;
import java.lang.ref.*;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
/**
* The Swing JEditorPane text component supports different kinds
@@ -415,14 +415,13 @@
* HTMLEditorKit class
* @return a stream representing the resource
*/
- static InputStream getResourceAsStream(String name) {
- try {
- return ResourceLoader.getResourceAsStream(name);
- } catch (Throwable e) {
- // If the class doesn't exist or we have some other
- // problem we just try to call getResourceAsStream directly.
- return HTMLEditorKit.class.getResourceAsStream(name);
- }
+ static InputStream getResourceAsStream(final String name) {
+ return AccessController.doPrivileged(
+ new PrivilegedAction<InputStream>() {
+ public InputStream run() {
+ return HTMLEditorKit.class.getResourceAsStream(name);
+ }
+ });
}
/**
--- a/jdk/src/share/classes/javax/swing/text/html/ResourceLoader.java Wed Apr 16 11:56:58 2014 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 1999, 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 javax.swing.text.html;
-
-import java.io.InputStream;
-
-/**
- * Simple class to load resources using the 1.2
- * security model. Since the html support is loaded
- * lazily, it's resources are potentially fetched with
- * applet code in the call stack. By providing this
- * functionality in a class that is only built on 1.2,
- * reflection can be used from the code that is also
- * built on 1.1 to call this functionality (and avoid
- * the evils of preprocessing). This functionality
- * is called from HTMLEditorKit.getResourceAsStream.
- *
- * @author Timothy Prinzing
- */
-class ResourceLoader implements java.security.PrivilegedAction {
-
- ResourceLoader(String name) {
- this.name = name;
- }
-
- public Object run() {
- Object o = HTMLEditorKit.class.getResourceAsStream(name);
- return o;
- }
-
- public static InputStream getResourceAsStream(String name) {
- java.security.PrivilegedAction a = new ResourceLoader(name);
- return (InputStream) java.security.AccessController.doPrivileged(a);
- }
-
- private String name;
-}
--- a/jdk/src/share/classes/javax/swing/text/html/parser/ParserDelegator.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/javax/swing/text/html/parser/ParserDelegator.java Wed Apr 16 12:42:40 2014 -0700
@@ -22,7 +22,6 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
-
package javax.swing.text.html.parser;
import sun.awt.AppContext;
@@ -35,6 +34,8 @@
import java.io.ObjectInputStream;
import java.io.Reader;
import java.io.Serializable;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
/**
* Responsible for starting up a new DocumentParser
@@ -110,14 +111,13 @@
* ParserDelegator class.
* @returns a stream representing the resource
*/
- static InputStream getResourceAsStream(String name) {
- try {
- return ResourceLoader.getResourceAsStream(name);
- } catch (Throwable e) {
- // If the class doesn't exist or we have some other
- // problem we just try to call getResourceAsStream directly.
- return ParserDelegator.class.getResourceAsStream(name);
- }
+ static InputStream getResourceAsStream(final String name) {
+ return AccessController.doPrivileged(
+ new PrivilegedAction<InputStream>() {
+ public InputStream run() {
+ return ParserDelegator.class.getResourceAsStream(name);
+ }
+ });
}
private void readObject(ObjectInputStream s)
--- a/jdk/src/share/classes/javax/swing/text/html/parser/ResourceLoader.java Wed Apr 16 11:56:58 2014 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 1999, 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 javax.swing.text.html.parser;
-
-import java.io.InputStream;
-
-/**
- * Simple class to load resources using the 1.2
- * security model. Since the html support is loaded
- * lazily, it's resources are potentially fetched with
- * applet code in the call stack. By providing this
- * functionality in a class that is only built on 1.2,
- * reflection can be used from the code that is also
- * built on 1.1 to call this functionality (and avoid
- * the evils of preprocessing). This functionality
- * is called from ParserDelegator.getResourceAsStream.
- *
- * @author Timothy Prinzing
- */
-class ResourceLoader implements java.security.PrivilegedAction {
-
- ResourceLoader(String name) {
- this.name = name;
- }
-
- public Object run() {
- Object o = ParserDelegator.class.getResourceAsStream(name);
- return o;
- }
-
- public static InputStream getResourceAsStream(String name) {
- java.security.PrivilegedAction a = new ResourceLoader(name);
- return (InputStream) java.security.AccessController.doPrivileged(a);
- }
-
- private String name;
-}
--- a/jdk/src/share/classes/javax/swing/text/rtf/RTFReader.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/javax/swing/text/rtf/RTFReader.java Wed Apr 16 12:42:40 2014 -0700
@@ -27,9 +27,9 @@
import java.lang.*;
import java.util.*;
import java.io.*;
-import java.awt.Font;
import java.awt.Color;
-
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import javax.swing.text.*;
/**
@@ -558,16 +558,14 @@
{
char[] set = characterSets.get(name);
if (set == null) {
- InputStream charsetStream;
- charsetStream = java.security.AccessController.
- doPrivileged(new java.security.PrivilegedAction<InputStream>() {
- public InputStream run() {
- return RTFReader.class.getResourceAsStream
- ("charsets/" + name + ".txt");
- }
- });
- set = readCharset(charsetStream);
- defineCharacterSet(name, set);
+ InputStream charsetStream = AccessController.doPrivileged(
+ new PrivilegedAction<InputStream>() {
+ public InputStream run() {
+ return RTFReader.class.getResourceAsStream("charsets/" + name + ".txt");
+ }
+ });
+ set = readCharset(charsetStream);
+ defineCharacterSet(name, set);
}
return set;
}
--- a/jdk/src/share/classes/javax/swing/tree/DefaultTreeCellRenderer.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/javax/swing/tree/DefaultTreeCellRenderer.java Wed Apr 16 12:42:40 2014 -0700
@@ -191,7 +191,7 @@
if (!inited || (getClosedIcon() instanceof UIResource)) {
setClosedIcon(DefaultLookup.getIcon(this, ui, "Tree.closedIcon"));
}
- if (!inited || (getOpenIcon() instanceof UIManager)) {
+ if (!inited || (getOpenIcon() instanceof UIResource)) {
setOpenIcon(DefaultLookup.getIcon(this, ui, "Tree.openIcon"));
}
if (!inited || (getTextSelectionColor() instanceof UIResource)) {
--- a/jdk/src/share/classes/sun/awt/AWTAccessor.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/sun/awt/AWTAccessor.java Wed Apr 16 12:42:40 2014 -0700
@@ -272,6 +272,16 @@
* bypasses disabled Components during the search.
*/
Component findComponentAt(Container cont, int x, int y, boolean ignoreEnabled);
+
+ /**
+ * Starts LW Modal.
+ */
+ void startLWModal(Container cont);
+
+ /**
+ * Starts LW Modal.
+ */
+ void stopLWModal(Container cont);
}
/*
--- a/jdk/src/share/classes/sun/awt/EventListenerAggregate.java Wed Apr 16 11:56:58 2014 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,175 +0,0 @@
-/*
- * Copyright (c) 2003, 2011, 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 sun.awt;
-
-import java.lang.reflect.Array;
-import java.util.EventListener;
-
-
-/**
- * A class that assists in managing {@link java.util.EventListener}s of
- * the specified type. Its instance holds an array of listeners of the same
- * type and allows to perform the typical operations on the listeners.
- * This class is thread-safe.
- *
- * @author Alexander Gerasimov
- *
- * @since 1.5
- */
-public class EventListenerAggregate {
-
- private EventListener[] listenerList;
-
- /**
- * Constructs an <code>EventListenerAggregate</code> object.
- *
- * @param listenerClass the type of the listeners to be managed by this object
- *
- * @throws NullPointerException if <code>listenerClass</code> is
- * <code>null</code>
- * @throws ClassCastException if <code>listenerClass</code> is not
- * assignable to <code>java.util.EventListener</code>
- */
- public EventListenerAggregate(Class<? extends EventListener> listenerClass) {
- if (listenerClass == null) {
- throw new NullPointerException("listener class is null");
- }
-
- listenerList = (EventListener[])Array.newInstance(listenerClass, 0);
- }
-
- private Class<?> getListenerClass() {
- return listenerList.getClass().getComponentType();
- }
-
- /**
- * Adds the listener to this aggregate.
- *
- * @param listener the listener to be added
- *
- * @throws ClassCastException if <code>listener</code> is not
- * an instatce of <code>listenerClass</code> specified
- * in the constructor
- */
- public synchronized void add(EventListener listener) {
- Class<?> listenerClass = getListenerClass();
-
- if (!listenerClass.isInstance(listener)) { // null is not an instance of any class
- throw new ClassCastException("listener " + listener + " is not " +
- "an instance of listener class " + listenerClass);
- }
-
- EventListener[] tmp = (EventListener[])Array.newInstance(listenerClass, listenerList.length + 1);
- System.arraycopy(listenerList, 0, tmp, 0, listenerList.length);
- tmp[listenerList.length] = listener;
- listenerList = tmp;
- }
-
- /**
- * Removes a listener that is equal to the given one from this aggregate.
- * <code>equals()</code> method is used to compare listeners.
- *
- * @param listener the listener to be removed
- *
- * @return <code>true</code> if this aggregate contained the specified
- * <code>listener</code>; <code>false</code> otherwise
- *
- * @throws ClassCastException if <code>listener</code> is not
- * an instatce of <code>listenerClass</code> specified
- * in the constructor
- */
- public synchronized boolean remove(EventListener listener) {
- Class<?> listenerClass = getListenerClass();
-
- if (!listenerClass.isInstance(listener)) { // null is not an instance of any class
- throw new ClassCastException("listener " + listener + " is not " +
- "an instance of listener class " + listenerClass);
- }
-
- for (int i = 0; i < listenerList.length; i++) {
- if (listenerList[i].equals(listener)) {
- EventListener[] tmp = (EventListener[])Array.newInstance(listenerClass,
- listenerList.length - 1);
- System.arraycopy(listenerList, 0, tmp, 0, i);
- System.arraycopy(listenerList, i + 1, tmp, i, listenerList.length - i - 1);
- listenerList = tmp;
-
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Returns an array of all the listeners contained in this aggregate.
- * The array is the data structure in which listeners are stored internally.
- * The runtime type of the returned array is "array of <code>listenerClass</code>"
- * (<code>listenerClass</code> has been specified as a parameter to
- * the constructor of this class).
- *
- * @return all the listeners contained in this aggregate (an empty
- * array if there are no listeners)
- */
- public synchronized EventListener[] getListenersInternal() {
- return listenerList;
- }
-
- /**
- * Returns an array of all the listeners contained in this aggregate.
- * The array is a copy of the data structure in which listeners are stored
- * internally.
- * The runtime type of the returned array is "array of <code>listenerClass</code>"
- * (<code>listenerClass</code> has been specified as a parameter to
- * the constructor of this class).
- *
- * @return a copy of all the listeners contained in this aggregate (an empty
- * array if there are no listeners)
- */
- public synchronized EventListener[] getListenersCopy() {
- return (listenerList.length == 0) ? listenerList : listenerList.clone();
- }
-
- /**
- * Returns the number of lisetners in this aggregate.
- *
- * @return the number of lisetners in this aggregate
- */
- public synchronized int size() {
- return listenerList.length;
- }
-
- /**
- * Returns <code>true</code> if this aggregate contains no listeners,
- * <code>false</code> otherwise.
- *
- * @return <code>true</code> if this aggregate contains no listeners,
- * <code>false</code> otherwise
- */
- public synchronized boolean isEmpty() {
- return listenerList.length == 0;
- }
-}
--- a/jdk/src/share/classes/sun/awt/datatransfer/SunClipboard.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/sun/awt/datatransfer/SunClipboard.java Wed Apr 16 12:42:40 2014 -0700
@@ -40,7 +40,7 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
-import java.util.Iterator;
+import java.util.Objects;
import java.util.Set;
import java.util.HashSet;
@@ -49,7 +49,6 @@
import sun.awt.AppContext;
import sun.awt.PeerEvent;
import sun.awt.SunToolkit;
-import sun.awt.EventListenerAggregate;
/**
@@ -107,11 +106,7 @@
setContentsNative(contents);
} finally {
if (oldOwner != null && oldOwner != owner) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- oldOwner.lostOwnership(SunClipboard.this, oldContents);
- }
- });
+ EventQueue.invokeLater(() -> oldOwner.lostOwnership(SunClipboard.this, oldContents));
}
}
}
@@ -355,13 +350,12 @@
return;
}
AppContext appContext = AppContext.getAppContext();
- EventListenerAggregate contextFlavorListeners = (EventListenerAggregate)
- appContext.get(CLIPBOARD_FLAVOR_LISTENER_KEY);
- if (contextFlavorListeners == null) {
- contextFlavorListeners = new EventListenerAggregate(FlavorListener.class);
- appContext.put(CLIPBOARD_FLAVOR_LISTENER_KEY, contextFlavorListeners);
+ Set<FlavorListener> flavorListeners = getFlavorListeners(appContext);
+ if (flavorListeners == null) {
+ flavorListeners = new HashSet<>();
+ appContext.put(CLIPBOARD_FLAVOR_LISTENER_KEY, flavorListeners);
}
- contextFlavorListeners.add(listener);
+ flavorListeners.add(listener);
if (numberOfFlavorListeners++ == 0) {
long[] currentFormats = null;
@@ -382,25 +376,26 @@
if (listener == null) {
return;
}
- AppContext appContext = AppContext.getAppContext();
- EventListenerAggregate contextFlavorListeners = (EventListenerAggregate)
- appContext.get(CLIPBOARD_FLAVOR_LISTENER_KEY);
- if (contextFlavorListeners == null){
+ Set<FlavorListener> flavorListeners = getFlavorListeners(AppContext.getAppContext());
+ if (flavorListeners == null){
//else we throw NullPointerException, but it is forbidden
return;
}
- if (contextFlavorListeners.remove(listener) &&
- --numberOfFlavorListeners == 0) {
+ if (flavorListeners.remove(listener) && --numberOfFlavorListeners == 0) {
unregisterClipboardViewerChecked();
currentDataFlavors = null;
}
}
+ @SuppressWarnings("unchecked")
+ private Set<FlavorListener> getFlavorListeners(AppContext appContext) {
+ return (Set<FlavorListener>)appContext.get(CLIPBOARD_FLAVOR_LISTENER_KEY);
+ }
+
public synchronized FlavorListener[] getFlavorListeners() {
- EventListenerAggregate contextFlavorListeners = (EventListenerAggregate)
- AppContext.getAppContext().get(CLIPBOARD_FLAVOR_LISTENER_KEY);
- return contextFlavorListeners == null ? new FlavorListener[0] :
- (FlavorListener[])contextFlavorListeners.getListenersCopy();
+ Set<FlavorListener> flavorListeners = getFlavorListeners(AppContext.getAppContext());
+ return flavorListeners == null ? new FlavorListener[0]
+ : flavorListeners.toArray(new FlavorListener[flavorListeners.size()]);
}
public boolean areFlavorListenersRegistered() {
@@ -425,42 +420,26 @@
Set prevDataFlavors = currentDataFlavors;
currentDataFlavors = formatArrayAsDataFlavorSet(formats);
- if ((prevDataFlavors != null) && (currentDataFlavors != null) &&
- prevDataFlavors.equals(currentDataFlavors)) {
+ if (Objects.equals(prevDataFlavors, currentDataFlavors)) {
// we've been able to successfully get available on the clipboard
// DataFlavors this and previous time and they are coincident;
// don't notify
return;
}
- class SunFlavorChangeNotifier implements Runnable {
- private final FlavorListener flavorListener;
-
- SunFlavorChangeNotifier(FlavorListener flavorListener) {
- this.flavorListener = flavorListener;
- }
-
- public void run() {
- if (flavorListener != null) {
- flavorListener.flavorsChanged(new FlavorEvent(SunClipboard.this));
- }
- }
- };
-
- for (Iterator it = AppContext.getAppContexts().iterator(); it.hasNext();) {
- AppContext appContext = (AppContext)it.next();
+ for (AppContext appContext : AppContext.getAppContexts()) {
if (appContext == null || appContext.isDisposed()) {
continue;
}
- EventListenerAggregate flavorListeners = (EventListenerAggregate)
- appContext.get(CLIPBOARD_FLAVOR_LISTENER_KEY);
+ Set<FlavorListener> flavorListeners = getFlavorListeners(appContext);
if (flavorListeners != null) {
- FlavorListener[] flavorListenerArray =
- (FlavorListener[])flavorListeners.getListenersInternal();
- for (int i = 0; i < flavorListenerArray.length; i++) {
- SunToolkit.postEvent(appContext, new PeerEvent(this,
- new SunFlavorChangeNotifier(flavorListenerArray[i]),
- PeerEvent.PRIORITY_EVENT));
+ for (FlavorListener listener : flavorListeners) {
+ if (listener != null) {
+ PeerEvent peerEvent = new PeerEvent(this,
+ () -> listener.flavorsChanged(new FlavorEvent(SunClipboard.this)),
+ PeerEvent.PRIORITY_EVENT);
+ SunToolkit.postEvent(appContext, peerEvent);
+ }
}
}
}
--- a/jdk/src/share/classes/sun/awt/image/MultiResolutionBufferedImage.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/sun/awt/image/MultiResolutionBufferedImage.java Wed Apr 16 12:42:40 2014 -0700
@@ -24,6 +24,7 @@
*/
package sun.awt.image;
+import java.awt.Dimension;
import java.awt.Image;
import java.awt.Graphics;
import java.awt.geom.Dimension2D;
@@ -43,6 +44,13 @@
private int availableInfo;
public MultiResolutionBufferedImage(Image baseImage,
+ BiFunction<Integer, Integer, Image> mapper) {
+ this(baseImage, new Dimension[]{new Dimension(
+ baseImage.getWidth(null), baseImage.getHeight(null))
+ }, mapper);
+ }
+
+ public MultiResolutionBufferedImage(Image baseImage,
Dimension2D[] sizes, BiFunction<Integer, Integer, Image> mapper) {
super(baseImage.getWidth(null), baseImage.getHeight(null),
BufferedImage.TYPE_INT_ARGB_PRE);
@@ -115,7 +123,7 @@
}
private static void preload(Image image, int availableInfo) {
- if (image instanceof ToolkitImage) {
+ if (availableInfo != 0 && image instanceof ToolkitImage) {
((ToolkitImage) image).preload(new ImageObserver() {
int flags = availableInfo;
--- a/jdk/src/share/classes/sun/java2d/pipe/DrawImage.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/sun/java2d/pipe/DrawImage.java Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2014, 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
@@ -310,11 +310,19 @@
return false;
}
- /*
- * Return a BufferedImage of the requested type with the indicated
- * subimage of the original image located at 0,0 in the new image.
- * If a bgColor is supplied, composite the original image over that
- * color with a SrcOver operation, otherwise make a SrcNoEa copy.
+ /**
+ * Return a non-accelerated BufferedImage of the requested type with the
+ * indicated subimage of the original image located at 0,0 in the new image.
+ * If a bgColor is supplied, composite the original image over that color
+ * with a SrcOver operation, otherwise make a SrcNoEa copy.
+ * <p>
+ * Returned BufferedImage is not accelerated for two reasons:
+ * <ul>
+ * <li> Types of the image and surface are predefined, because these types
+ * correspond to the TransformHelpers, which we know we have. And
+ * acceleration can change the type of the surface
+ * <li> Image will be used only once and acceleration caching wouldn't help
+ * </ul>
*/
BufferedImage makeBufferedImage(Image img, Color bgColor, int type,
int sx1, int sy1, int sx2, int sy2)
@@ -324,6 +332,7 @@
final BufferedImage bimg = new BufferedImage(width, height, type);
final SunGraphics2D g2d = (SunGraphics2D) bimg.createGraphics();
g2d.setComposite(AlphaComposite.Src);
+ bimg.setAccelerationPriority(0);
if (bgColor != null) {
g2d.setColor(bgColor);
g2d.fillRect(0, 0, width, height);
--- a/jdk/src/share/classes/sun/net/www/protocol/http/NegotiateAuthentication.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/sun/net/www/protocol/http/NegotiateAuthentication.java Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2014, 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
@@ -31,6 +31,7 @@
import java.util.Base64;
import java.util.HashMap;
import sun.net.www.HeaderParser;
+import sun.util.logging.PlatformLogger;
import static sun.net.www.protocol.http.AuthScheme.NEGOTIATE;
import static sun.net.www.protocol.http.AuthScheme.KERBEROS;
@@ -44,6 +45,7 @@
class NegotiateAuthentication extends AuthenticationInfo {
private static final long serialVersionUID = 100L;
+ private static final PlatformLogger logger = HttpURLConnection.getHttpLogger();
final private HttpCallerInfo hci;
@@ -79,6 +81,31 @@
}
/**
+ * Find out if the HttpCallerInfo supports Negotiate protocol.
+ * @return true if supported
+ */
+ public static boolean isSupported(HttpCallerInfo hci) {
+ ClassLoader loader = null;
+ try {
+ loader = Thread.currentThread().getContextClassLoader();
+ } catch (SecurityException se) {
+ if (logger.isLoggable(PlatformLogger.Level.FINER)) {
+ logger.finer("NegotiateAuthentication: " +
+ "Attempt to get the context class loader failed - " + se);
+ }
+ }
+
+ if (loader != null) {
+ // Lock on the class loader instance to avoid the deadlock engaging
+ // the lock in "ClassLoader.loadClass(String, boolean)" method.
+ synchronized (loader) {
+ return isSupportedImpl(hci);
+ }
+ }
+ return isSupportedImpl(hci);
+ }
+
+ /**
* Find out if the HttpCallerInfo supports Negotiate protocol. In order to
* find out yes or no, an initialization of a Negotiator object against it
* is tried. The generated object will be cached under the name of ths
@@ -89,7 +116,7 @@
*
* @return true if supported
*/
- synchronized public static boolean isSupported(HttpCallerInfo hci) {
+ private static synchronized boolean isSupportedImpl(HttpCallerInfo hci) {
if (supported == null) {
supported = new HashMap <String, Boolean>();
cache = new HashMap <String, Negotiator>();
--- a/jdk/src/share/classes/sun/swing/SwingUtilities2.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/classes/sun/swing/SwingUtilities2.java Wed Apr 16 12:42:40 2014 -0700
@@ -25,13 +25,11 @@
package sun.swing;
-import java.security.*;
import java.lang.reflect.*;
import java.awt.*;
import static java.awt.RenderingHints.*;
import java.awt.event.*;
import java.awt.font.*;
-import java.awt.geom.*;
import java.awt.print.PrinterGraphics;
import java.text.CharacterIterator;
import java.text.AttributedCharacterIterator;
@@ -48,11 +46,8 @@
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
-import sun.swing.PrintColorUIResource;
-import sun.swing.ImageIconUIResource;
import sun.print.ProxyPrintGraphics;
import sun.awt.*;
-import sun.security.action.GetPropertyAction;
import java.io.*;
import java.util.*;
import sun.font.FontDesignMetrics;
@@ -924,6 +919,77 @@
return retVal;
}
+ /**
+ * This method should be used for drawing a borders over a filled rectangle.
+ * Draws vertical line, using the current color, between the points {@code
+ * (x, y1)} and {@code (x, y2)} in graphics context's coordinate system.
+ * Note: it use {@code Graphics.fillRect()} internally.
+ *
+ * @param g Graphics to draw the line to.
+ * @param x the <i>x</i> coordinate.
+ * @param y1 the first point's <i>y</i> coordinate.
+ * @param y2 the second point's <i>y</i> coordinate.
+ */
+ public static void drawVLine(Graphics g, int x, int y1, int y2) {
+ if (y2 < y1) {
+ final int temp = y2;
+ y2 = y1;
+ y1 = temp;
+ }
+ g.fillRect(x, y1, 1, y2 - y1 + 1);
+ }
+
+ /**
+ * This method should be used for drawing a borders over a filled rectangle.
+ * Draws horizontal line, using the current color, between the points {@code
+ * (x1, y)} and {@code (x2, y)} in graphics context's coordinate system.
+ * Note: it use {@code Graphics.fillRect()} internally.
+ *
+ * @param g Graphics to draw the line to.
+ * @param x1 the first point's <i>x</i> coordinate.
+ * @param x2 the second point's <i>x</i> coordinate.
+ * @param y the <i>y</i> coordinate.
+ */
+ public static void drawHLine(Graphics g, int x1, int x2, int y) {
+ if (x2 < x1) {
+ final int temp = x2;
+ x2 = x1;
+ x1 = temp;
+ }
+ g.fillRect(x1, y, x2 - x1 + 1, 1);
+ }
+
+ /**
+ * This method should be used for drawing a borders over a filled rectangle.
+ * Draws the outline of the specified rectangle. The left and right edges of
+ * the rectangle are at {@code x} and {@code x + w}. The top and bottom
+ * edges are at {@code y} and {@code y + h}. The rectangle is drawn using
+ * the graphics context's current color. Note: it use {@code
+ * Graphics.fillRect()} internally.
+ *
+ * @param g Graphics to draw the rectangle to.
+ * @param x the <i>x</i> coordinate of the rectangle to be drawn.
+ * @param y the <i>y</i> coordinate of the rectangle to be drawn.
+ * @param w the w of the rectangle to be drawn.
+ * @param h the h of the rectangle to be drawn.
+ * @see SwingUtilities2#drawVLine(java.awt.Graphics, int, int, int)
+ * @see SwingUtilities2#drawHLine(java.awt.Graphics, int, int, int)
+ */
+ public static void drawRect(Graphics g, int x, int y, int w, int h) {
+ if (w < 0 || h < 0) {
+ return;
+ }
+
+ if (h == 0 || w == 0) {
+ g.fillRect(x, y, w + 1, h + 1);
+ } else {
+ g.fillRect(x, y, w, 1);
+ g.fillRect(x + w, y, 1, h);
+ g.fillRect(x + 1, y + h, w, 1);
+ g.fillRect(x, y + 1, 1, h);
+ }
+ }
+
private static TextLayout createTextLayout(JComponent c, String s,
Font f, FontRenderContext frc) {
Object shaper = (c == null ?
--- a/jdk/src/share/native/sun/java2d/loops/TransformHelper.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/native/sun/java2d/loops/TransformHelper.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2014, 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
@@ -384,6 +384,7 @@
return;
}
Region_IntersectBounds(&clipInfo, &dstInfo.bounds);
+ Transform_GetInfo(env, itxform, &itxInfo);
numedges = (((jlong) dstInfo.bounds.y2) - ((jlong) dstInfo.bounds.y1));
if (numedges <= 0) {
@@ -423,7 +424,6 @@
return;
}
- Transform_GetInfo(env, itxform, &itxInfo);
if (!Region_IsEmpty(&clipInfo)) {
srcOps->GetRasInfo(env, srcOps, &srcInfo);
--- a/jdk/src/share/native/sun/java2d/opengl/OGLSurfaceData.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/share/native/sun/java2d/opengl/OGLSurfaceData.c Wed Apr 16 12:42:40 2014 -0700
@@ -543,7 +543,9 @@
}
JNU_SetFieldByName(env, NULL, sdObject, "nativeWidth", "I", width);
- JNU_SetFieldByName(env, NULL, sdObject, "nativeHeight", "I", height);
+ if (!((*env)->ExceptionOccurred(env))) {
+ JNU_SetFieldByName(env, NULL, sdObject, "nativeHeight", "I", height);
+ }
(*env)->DeleteLocalRef(env, sdObject);
}
--- a/jdk/src/solaris/native/sun/awt/CUPSfuncs.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/CUPSfuncs.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2014, 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
@@ -213,6 +213,8 @@
name = (*env)->GetStringUTFChars(env, printer, NULL);
if (name == NULL) {
+ (*env)->ExceptionClear(env);
+ JNU_ThrowOutOfMemoryError(env, "Could not create printer name");
return NULL;
}
@@ -220,12 +222,10 @@
// unlink() must be caled to remove the file when finished using it.
filename = j2d_cupsGetPPD(name);
(*env)->ReleaseStringUTFChars(env, printer, name);
+ CHECK_NULL_RETURN(filename, NULL);
cls = (*env)->FindClass(env, "java/lang/String");
-
- if (filename == NULL) {
- return NULL;
- }
+ CHECK_NULL_RETURN(cls, NULL);
if ((ppd = j2d_ppdOpenFile(filename)) == NULL) {
unlink(filename);
@@ -249,6 +249,7 @@
unlink(filename);
j2d_ppdClose(ppd);
DPRINTF("CUPSfuncs::bad alloc new array\n", "")
+ (*env)->ExceptionClear(env);
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
return NULL;
}
@@ -323,6 +324,11 @@
ppd_size_t *size;
const char *name = (*env)->GetStringUTFChars(env, printer, NULL);
+ if (name == NULL) {
+ (*env)->ExceptionClear(env);
+ JNU_ThrowOutOfMemoryError(env, "Could not create printer name");
+ return NULL;
+ }
const char *filename;
int i;
jobjectArray sizeArray = NULL;
@@ -332,9 +338,7 @@
// unlink() must be called to remove the file after using it.
filename = j2d_cupsGetPPD(name);
(*env)->ReleaseStringUTFChars(env, printer, name);
- if (filename == NULL) {
- return NULL;
- }
+ CHECK_NULL_RETURN(filename, NULL);
if ((ppd = j2d_ppdOpenFile(filename)) == NULL) {
unlink(filename);
DPRINTF("unable to open PPD %s\n", filename)
@@ -350,11 +354,19 @@
unlink(filename);
j2d_ppdClose(ppd);
DPRINTF("CUPSfuncs::bad alloc new float array\n", "")
+ (*env)->ExceptionClear(env);
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
return NULL;
}
dims = (*env)->GetFloatArrayElements(env, sizeArray, NULL);
+ if (dims == NULL) {
+ unlink(filename);
+ j2d_ppdClose(ppd);
+ (*env)->ExceptionClear(env);
+ JNU_ThrowOutOfMemoryError(env, "Could not create printer name");
+ return NULL;
+ }
for (i = 0; i<option->num_choices; i++) {
choice = (option->choices)+i;
size = j2d_ppdPageSize(ppd, choice->choice);
--- a/jdk/src/solaris/native/sun/awt/X11Color.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/X11Color.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2014, 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
@@ -892,11 +892,10 @@
jmethodID mid;
clazz = (*env)->FindClass(env,"java/awt/color/ColorSpace");
+ CHECK_NULL_RETURN(clazz, NULL);
mid = (*env)->GetStaticMethodID(env, clazz, "getInstance",
"(I)Ljava/awt/color/ColorSpace;");
- if (mid == NULL) {
- return NULL;
- }
+ CHECK_NULL_RETURN(mid, NULL);
/* SECURITY: This is safe, because static methods cannot
* be overridden, and this method does not invoke
@@ -919,6 +918,11 @@
(aData->awt_depth >= 15))
{
clazz = (*env)->FindClass(env,"java/awt/image/DirectColorModel");
+ if (clazz == NULL) {
+ (*env)->PopLocalFrame(env, 0);
+ return NULL;
+ }
+
if (!aData->isTranslucencySupported) {
mid = (*env)->GetMethodID(env,clazz,"<init>","(IIIII)V");
@@ -1005,6 +1009,10 @@
}
clazz = (*env)->FindClass(env,"java/awt/image/ComponentColorModel");
+ if (clazz == NULL) {
+ (*env)->PopLocalFrame(env, 0);
+ return NULL;
+ }
mid = (*env)->GetMethodID(env,clazz,"<init>",
"(Ljava/awt/color/ColorSpace;[IZZII)V");
@@ -1253,6 +1261,7 @@
if (!JNU_IsNull(env,this))
{
SYSCLR_class = (*env)->FindClass(env, "java/awt/SystemColor");
+ CHECK_NULL_RETURN(SYSCLR_class, 0);
if ((*env)->IsInstanceOf(env, this, SYSCLR_class)) {
/* SECURITY: This is safe, because there is no way
@@ -1264,6 +1273,7 @@
,this
,"getRGB"
,"()I").i;
+ JNU_CHECK_EXCEPTION_RETURN(env, 0);
} else {
col = (int)(*env)->GetIntField(env,this,colorValueID);
}
@@ -1370,6 +1380,8 @@
AWT_UNLOCK ();
}
sysColors = (*env)->FindClass (env, "java/awt/SystemColor");
+ CHECK_NULL(sysColors);
+
if (lock) {
AWT_LOCK ();
}
@@ -1377,6 +1389,13 @@
"systemColors",
"[I");
+ if (colorID == NULL) {
+ if (lock) {
+ AWT_UNLOCK();
+ }
+ return;
+ }
+
colors = (jintArray) (*env)->GetStaticObjectField
(env, sysColors, colorID);
--- a/jdk/src/solaris/native/sun/awt/awt.h Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/awt.h Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2014, 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
@@ -77,8 +77,22 @@
#define AWT_LOCK_IMPL() \
(*env)->CallStaticVoidMethod(env, tkClass, awtLockMID)
+
#define AWT_NOFLUSH_UNLOCK_IMPL() \
- (*env)->CallStaticVoidMethod(env, tkClass, awtUnlockMID)
+ do { \
+ jthrowable pendingException; \
+ if ((pendingException = (*env)->ExceptionOccurred(env)) != NULL) { \
+ (*env)->ExceptionClear(env); \
+ } \
+ (*env)->CallStaticVoidMethod(env, tkClass, awtUnlockMID); \
+ if (pendingException) { \
+ if ((*env)->ExceptionCheck(env)) { \
+ (*env)->ExceptionDescribe(env); \
+ (*env)->ExceptionClear(env); \
+ } \
+ (*env)->Throw(env, pendingException); \
+ } \
+ } while (0)
#define AWT_WAIT_IMPL(tm) \
(*env)->CallStaticVoidMethod(env, tkClass, awtWaitMID, (jlong)(tm))
#define AWT_NOTIFY_IMPL() \
--- a/jdk/src/solaris/native/sun/awt/awt_AWTEvent.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/awt_AWTEvent.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2014, 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
@@ -49,22 +49,22 @@
JNIEXPORT void JNICALL
Java_java_awt_AWTEvent_initIDs(JNIEnv *env, jclass cls)
{
- awtEventIDs.bdata = (*env)->GetFieldID(env, cls, "bdata", "[B");
- awtEventIDs.consumed = (*env)->GetFieldID(env, cls, "consumed", "Z");
- awtEventIDs.id = (*env)->GetFieldID(env, cls, "id", "I");
+ CHECK_NULL(awtEventIDs.bdata = (*env)->GetFieldID(env, cls, "bdata", "[B"));
+ CHECK_NULL(awtEventIDs.consumed = (*env)->GetFieldID(env, cls, "consumed", "Z"));
+ CHECK_NULL(awtEventIDs.id = (*env)->GetFieldID(env, cls, "id", "I"));
}
JNIEXPORT void JNICALL
Java_java_awt_event_InputEvent_initIDs(JNIEnv *env, jclass cls)
{
- inputEventIDs.modifiers = (*env)->GetFieldID(env, cls, "modifiers", "I");
+ CHECK_NULL(inputEventIDs.modifiers = (*env)->GetFieldID(env, cls, "modifiers", "I"));
}
JNIEXPORT void JNICALL
Java_java_awt_event_KeyEvent_initIDs(JNIEnv *env, jclass cls)
{
- keyEventIDs.keyCode = (*env)->GetFieldID(env, cls, "keyCode", "I");
- keyEventIDs.keyChar = (*env)->GetFieldID(env, cls, "keyChar", "C");
+ CHECK_NULL(keyEventIDs.keyCode = (*env)->GetFieldID(env, cls, "keyCode", "I"));
+ CHECK_NULL(keyEventIDs.keyChar = (*env)->GetFieldID(env, cls, "keyChar", "C"));
}
JNIEXPORT void JNICALL
--- a/jdk/src/solaris/native/sun/awt/awt_DrawingSurface.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/awt_DrawingSurface.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2014, 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
@@ -78,6 +78,8 @@
/* Make sure the target is a java.awt.Component */
componentClass = (*env)->FindClass(env, "java/awt/Component");
+ CHECK_NULL_RETURN(componentClass, (jint)JAWT_LOCK_ERROR);
+
if (!(*env)->IsInstanceOf(env, target, componentClass)) {
#ifdef DEBUG
fprintf(stderr, "Target is not a component\n");
@@ -126,6 +128,8 @@
/* Make sure the target is a java.awt.Component */
componentClass = (*env)->FindClass(env, "java/awt/Component");
+ CHECK_NULL_RETURN(componentClass, (int32_t) 0);
+
if (!(*env)->IsInstanceOf(env, target, componentClass)) {
#ifdef DEBUG
fprintf(stderr, "DrawingSurface target must be a component\n");
@@ -195,6 +199,8 @@
/* Make sure the target is a java.awt.Component */
componentClass = (*env)->FindClass(env, "java/awt/Component");
+ CHECK_NULL_RETURN(componentClass, NULL);
+
if (!(*env)->IsInstanceOf(env, target, componentClass)) {
#ifdef DEBUG
fprintf(stderr, "DrawingSurface target must be a component\n");
@@ -292,6 +298,8 @@
/* Make sure the target component is a java.awt.Component */
componentClass = (*env)->FindClass(env, "java/awt/Component");
+ CHECK_NULL_RETURN(componentClass, NULL);
+
if (!(*env)->IsInstanceOf(env, target, componentClass)) {
#ifdef DEBUG
fprintf(stderr,
@@ -354,6 +362,10 @@
if (window != None) {
peer = JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XToolkit",
"windowToXWindow", "(J)Lsun/awt/X11/XBaseWindow;", (jlong)window).l;
+ if ((*env)->ExceptionCheck(env)) {
+ AWT_UNLOCK();
+ return (jobject)NULL;
+ }
}
if ((peer != NULL) &&
(JNU_IsInstanceOfByName(env, peer, "sun/awt/X11/XWindow") == 1)) {
@@ -361,6 +373,7 @@
}
if (target == NULL) {
+ (*env)->ExceptionClear(env);
JNU_ThrowNullPointerException(env, "NullPointerException");
AWT_UNLOCK();
return (jobject)NULL;
--- a/jdk/src/solaris/native/sun/awt/awt_Font.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/awt_Font.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2014, 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
@@ -86,14 +86,13 @@
#ifndef HEADLESS
/** We call "NoClientCode" methods because they won't invoke client
code on the privileged toolkit thread **/
- fontIDs.pData = (*env)->GetFieldID(env, cls, "pData", "J");
- fontIDs.style = (*env)->GetFieldID(env, cls, "style", "I");
- fontIDs.size = (*env)->GetFieldID(env, cls, "size", "I");
- fontIDs.getPeer = (*env)->GetMethodID(env, cls, "getPeer_NoClientCode",
- "()Ljava/awt/peer/FontPeer;");
- fontIDs.getFamily =
- (*env)->GetMethodID(env, cls, "getFamily_NoClientCode",
- "()Ljava/lang/String;");
+ CHECK_NULL(fontIDs.pData = (*env)->GetFieldID(env, cls, "pData", "J"));
+ CHECK_NULL(fontIDs.style = (*env)->GetFieldID(env, cls, "style", "I"));
+ CHECK_NULL(fontIDs.size = (*env)->GetFieldID(env, cls, "size", "I"));
+ CHECK_NULL(fontIDs.getPeer = (*env)->GetMethodID(env, cls, "getPeer_NoClientCode",
+ "()Ljava/awt/peer/FontPeer;"));
+ CHECK_NULL(fontIDs.getFamily = (*env)->GetMethodID(env, cls, "getFamily_NoClientCode",
+ "()Ljava/lang/String;"));
#endif /* !HEADLESS */
}
@@ -120,12 +119,10 @@
(JNIEnv *env, jclass cls)
{
#ifndef HEADLESS
- fontDescriptorIDs.nativeName =
- (*env)->GetFieldID(env, cls, "nativeName",
- "Ljava/lang/String;");
- fontDescriptorIDs.charsetName =
- (*env)->GetFieldID(env, cls, "charsetName",
- "Ljava/lang/String;");
+ CHECK_NULL(fontDescriptorIDs.nativeName =
+ (*env)->GetFieldID(env, cls, "nativeName", "Ljava/lang/String;"));
+ CHECK_NULL(fontDescriptorIDs.charsetName =
+ (*env)->GetFieldID(env, cls, "charsetName", "Ljava/lang/String;"));
#endif /* !HEADLESS */
}
@@ -144,20 +141,18 @@
(JNIEnv *env, jclass cls)
{
#ifndef HEADLESS
- platformFontIDs.componentFonts =
- (*env)->GetFieldID(env, cls, "componentFonts",
- "[Lsun/awt/FontDescriptor;");
- platformFontIDs.fontConfig =
- (*env)->GetFieldID(env,cls, "fontConfig",
- "Lsun/awt/FontConfiguration;");
-
- platformFontIDs.makeConvertedMultiFontString =
- (*env)->GetMethodID(env, cls, "makeConvertedMultiFontString",
- "(Ljava/lang/String;)[Ljava/lang/Object;");
-
- platformFontIDs.makeConvertedMultiFontChars =
- (*env)->GetMethodID(env, cls, "makeConvertedMultiFontChars",
- "([CII)[Ljava/lang/Object;");
+ CHECK_NULL(platformFontIDs.componentFonts =
+ (*env)->GetFieldID(env, cls, "componentFonts",
+ "[Lsun/awt/FontDescriptor;"));
+ CHECK_NULL(platformFontIDs.fontConfig =
+ (*env)->GetFieldID(env,cls, "fontConfig",
+ "Lsun/awt/FontConfiguration;"));
+ CHECK_NULL(platformFontIDs.makeConvertedMultiFontString =
+ (*env)->GetMethodID(env, cls, "makeConvertedMultiFontString",
+ "(Ljava/lang/String;)[Ljava/lang/Object;"));
+ CHECK_NULL(platformFontIDs.makeConvertedMultiFontChars =
+ (*env)->GetMethodID(env, cls, "makeConvertedMultiFontChars",
+ "([CII)[Ljava/lang/Object;"));
#endif /* !HEADLESS */
}
@@ -385,6 +380,11 @@
return 0;
}
cname = (char *) JNU_GetStringPlatformChars(env, name, NULL);
+ if (cname == NULL) {
+ (*env)->ExceptionClear(env);
+ JNU_ThrowOutOfMemoryError(env, "Could not create font name");
+ return 0;
+ }
/* additional default font names */
if (strcmp(cname, "serif") == 0) {
@@ -448,6 +448,8 @@
}
if (!JNU_IsNull(env, font) && awtJNI_IsMultiFont(env, font)) {
+ JNU_CHECK_EXCEPTION_RETURN(env, NULL);
+
struct FontData *fdata = NULL;
int32_t i, size;
char *fontsetname = NULL;
@@ -492,7 +494,12 @@
if (!JNU_IsNull(env, fontDescriptorName)) {
nativename = (char *) JNU_GetStringPlatformChars(env, fontDescriptorName, NULL);
- doFree = TRUE;
+ if (nativename == NULL) {
+ nativename = "";
+ doFree = FALSE;
+ } else {
+ doFree = TRUE;
+ }
} else {
nativename = "";
doFree = FALSE;
@@ -516,6 +523,11 @@
fdata->flist[i].charset_name = (char *)
JNU_GetStringPlatformChars(env, charsetName, NULL);
+ if (fdata->flist[i].charset_name == NULL) {
+ (*env)->ExceptionClear(env);
+ JNU_ThrowOutOfMemoryError(env, "Could not create charset name");
+ return NULL;
+ }
/* We are done with the objects. */
(*env)->DeleteLocalRef(env, fontDescriptor);
@@ -543,6 +555,19 @@
fdata->xfont = fdata->flist[i].xfont;
fdata->flist[i].index_length = 1;
} else {
+ /* Free any already allocated storage and fonts */
+ int j = i;
+ for (j = 0; j <= i; j++) {
+ free((void *)fdata->flist[j].xlfd);
+ JNU_ReleaseStringPlatformChars(env, NULL,
+ fdata->flist[j].charset_name);
+ if (fdata->flist[j].load) {
+ XFreeFont(awt_display, fdata->flist[j].xfont);
+ }
+ }
+ free((void *)fdata->flist);
+ free((void *)fdata);
+
if (errmsg != NULL) {
*errmsg = "java/lang" "NullPointerException";
}
--- a/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, 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
@@ -152,8 +152,11 @@
x11GraphicsConfigIDs.screen = NULL;
x11GraphicsConfigIDs.aData = (*env)->GetFieldID (env, cls, "aData", "J");
+ CHECK_NULL(x11GraphicsConfigIDs.aData);
x11GraphicsConfigIDs.bitsPerPixel = (*env)->GetFieldID (env, cls, "bitsPerPixel", "I");
+ CHECK_NULL(x11GraphicsConfigIDs.bitsPerPixel);
x11GraphicsConfigIDs.screen = (*env)->GetFieldID (env, cls, "screen", "Lsun/awt/X11GraphicsDevice;");
+ CHECK_NULL(x11GraphicsConfigIDs.screen);
if (x11GraphicsConfigIDs.aData == NULL ||
x11GraphicsConfigIDs.bitsPerPixel == NULL ||
@@ -1346,7 +1349,6 @@
/* Make Color Model object for this GraphicsConfiguration */
colorModel = awtJNI_GetColorModel (env, adata);
-
AWT_UNLOCK ();
return colorModel;
@@ -1374,6 +1376,7 @@
JNU_GetLongFieldAsPtr(env, this, x11GraphicsConfigIDs.aData);
clazz = (*env)->FindClass(env, "java/awt/Rectangle");
+ CHECK_NULL_RETURN(clazz, NULL);
mid = (*env)->GetMethodID(env, clazz, "<init>", "(IIII)V");
if (mid != NULL) {
if (usingXinerama) {
@@ -1543,7 +1546,7 @@
clazz = (*env)->GetObjectClass(env, this);
midAddVisual = (*env)->GetMethodID(env, clazz, "addDoubleBufferVisual",
"(I)V");
-
+ CHECK_NULL(midAddVisual);
AWT_LOCK();
rootWindow = RootWindow(awt_display, xinawareScreen);
visScreenInfo = XdbeGetVisualInfo(awt_display, &rootWindow, &n);
@@ -1739,6 +1742,7 @@
jint validRefreshRate = refreshRate;
displayModeClass = (*env)->FindClass(env, "java/awt/DisplayMode");
+ CHECK_NULL_RETURN(displayModeClass, NULL);
if (JNU_IsNull(env, displayModeClass)) {
JNU_ThrowInternalError(env,
"Could not get display mode class");
@@ -1746,6 +1750,7 @@
}
cid = (*env)->GetMethodID(env, displayModeClass, "<init>", "(IIII)V");
+ CHECK_NULL_RETURN(cid, NULL);
if (cid == NULL) {
JNU_ThrowInternalError(env,
"Could not get display mode constructor");
@@ -1779,6 +1784,7 @@
}
mid = (*env)->GetMethodID(env, arrayListClass, "add",
"(Ljava/lang/Object;)Z");
+ CHECK_NULL(mid);
if (mid == NULL) {
JNU_ThrowInternalError(env,
"Could not get method java.util.ArrayList.add()");
@@ -1955,6 +1961,9 @@
size.height,
BIT_DEPTH_MULTI,
rates[j]);
+ if ((*env)->ExceptionCheck(env)) {
+ break;
+ }
}
}
}
--- a/jdk/src/solaris/native/sun/awt/awt_InputMethod.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/awt_InputMethod.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, 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
@@ -319,6 +319,7 @@
JNU_CallMethodByName(env, NULL, pX11IMData->x11inputmethod,
"flushText",
"()V");
+ JNU_CHECK_EXCEPTION_RETURN(env, NULL);
/* IMPORTANT:
The order of the following calls is critical since "imInstance" may
point to the global reference itself, if "freeX11InputMethodData" is called
@@ -1120,6 +1121,9 @@
if (text->string.multi_byte != NULL) {
if (pre_draw->text->encoding_is_wchar == False) {
javastr = JNU_NewStringPlatform(env, (const char *)text->string.multi_byte);
+ if (javastr == NULL) {
+ goto finally;
+ }
} else {
char *mbstr = wcstombsdmp(text->string.wide_char, text->length);
if (mbstr == NULL) {
@@ -1127,6 +1131,9 @@
}
javastr = JNU_NewStringPlatform(env, (const char *)mbstr);
free(mbstr);
+ if (javastr == NULL) {
+ goto finally;
+ }
}
}
if (text->feedback != NULL) {
@@ -1135,6 +1142,7 @@
style = (*env)->NewIntArray(env, text->length);
if (JNU_IsNull(env, style)) {
+ (*env)->ExceptionClear(env);
THROW_OUT_OF_MEMORY_ERROR();
goto finally;
}
@@ -1395,14 +1403,17 @@
pX11IMData->lookup_buf = 0;
pX11IMData->lookup_buf_len = 0;
- if (createXIC(env, pX11IMData, (Window)window)
- == False) {
+ if (createXIC(env, pX11IMData, (Window)window) == False) {
destroyX11InputMethodData((JNIEnv *) NULL, pX11IMData);
pX11IMData = (X11InputMethodData *) NULL;
+ if ((*env)->ExceptionCheck(env)) {
+ goto finally;
+ }
}
setX11InputMethodData(env, this, pX11IMData);
+finally:
AWT_UNLOCK();
return (pX11IMData != NULL);
}
--- a/jdk/src/solaris/native/sun/awt/awt_Insets.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/awt_Insets.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2014, 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
@@ -34,8 +34,8 @@
JNIEXPORT void JNICALL
Java_java_awt_Insets_initIDs(JNIEnv *env, jclass cls)
{
- insetsIDs.top = (*env)->GetFieldID(env, cls, "top", "I");
- insetsIDs.bottom = (*env)->GetFieldID(env, cls, "bottom", "I");
- insetsIDs.left = (*env)->GetFieldID(env, cls, "left", "I");
- insetsIDs.right = (*env)->GetFieldID(env, cls, "right", "I");
+ CHECK_NULL(insetsIDs.top = (*env)->GetFieldID(env, cls, "top", "I"));
+ CHECK_NULL(insetsIDs.bottom = (*env)->GetFieldID(env, cls, "bottom", "I"));
+ CHECK_NULL(insetsIDs.left = (*env)->GetFieldID(env, cls, "left", "I"));
+ CHECK_NULL(insetsIDs.right = (*env)->GetFieldID(env, cls, "right", "I"));
}
--- a/jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2014, 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
@@ -77,11 +77,16 @@
return isHeadless;
}
+#define CHECK_EXCEPTION_FATAL(env, message) \
+ if ((*env)->ExceptionCheck(env)) { \
+ (*env)->ExceptionClear(env); \
+ (*env)->FatalError(env, message); \
+ }
+
/*
* Pathnames to the various awt toolkits
*/
-
#ifdef MACOSX
#define LWAWT_PATH "/libawt_lwawt.dylib"
#define DEFAULT_PATH LWAWT_PATH
@@ -125,6 +130,8 @@
*/
fmProp = (*env)->NewStringUTF(env, "sun.font.fontmanager");
+ CHECK_EXCEPTION_FATAL(env, "Could not allocate font manager property");
+
#ifdef MACOSX
fmanager = (*env)->NewStringUTF(env, "sun.font.CFontManager");
tk = LWAWT_PATH;
@@ -132,10 +139,13 @@
fmanager = (*env)->NewStringUTF(env, "sun.awt.X11FontManager");
tk = XAWT_PATH;
#endif
+ CHECK_EXCEPTION_FATAL(env, "Could not allocate font manager name");
+
if (fmanager && fmProp) {
JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "setProperty",
"(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
fmProp, fmanager);
+ CHECK_EXCEPTION_FATAL(env, "Could not allocate set properties");
}
#ifndef MACOSX
@@ -154,9 +164,11 @@
(*env)->DeleteLocalRef(env, fmanager);
}
+ jstring jbuf = JNU_NewStringPlatform(env, buf);
+ CHECK_EXCEPTION_FATAL(env, "Could not allocate library name");
JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "load",
"(Ljava/lang/String;)V",
- JNU_NewStringPlatform(env, buf));
+ jbuf);
awtHandle = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL);
--- a/jdk/src/solaris/native/sun/awt/awt_Robot.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/awt_Robot.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2014, 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
@@ -175,10 +175,13 @@
num_buttons = numberOfButtons;
tmp = (*env)->GetIntArrayElements(env, buttonDownMasks, JNI_FALSE);
+ CHECK_NULL(tmp);
+
masks = (jint *)SAFE_SIZE_ARRAY_ALLOC(malloc, sizeof(jint), num_buttons);
if (masks == (jint *) NULL) {
+ (*env)->ExceptionClear(env);
+ (*env)->ReleaseIntArrayElements(env, buttonDownMasks, tmp, 0);
JNU_ThrowOutOfMemoryError((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), NULL);
- (*env)->ReleaseIntArrayElements(env, buttonDownMasks, tmp, 0);
return;
}
for (i = 0; i < num_buttons; i++) {
--- a/jdk/src/solaris/native/sun/awt/awt_UNIXToolkit.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/awt_UNIXToolkit.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2014, 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
@@ -98,6 +98,7 @@
(*env)->GetObjectClass(env, this));
icon_upcall_method = (*env)->GetMethodID(env, this_class,
"loadIconCallback", "([BIIIIIZ)V");
+ CHECK_NULL_RETURN(icon_upcall_method, JNI_FALSE);
}
if (pixbuf != NULL)
@@ -112,6 +113,8 @@
/* Copy the data array into a Java structure so we can pass it back. */
jbyteArray data = (*env)->NewByteArray(env, (row_stride * height));
+ JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
+
(*env)->SetByteArrayRegion(env, data, 0, (row_stride * height),
(jbyte *)pixbuf_data);
--- a/jdk/src/solaris/native/sun/awt/awt_util.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/awt_util.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2014, 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
@@ -62,7 +62,7 @@
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
-void
+jboolean
awtJNI_ThreadYield(JNIEnv *env) {
static jclass threadClass = NULL;
@@ -76,6 +76,7 @@
Boolean err = FALSE;
if (threadClass == NULL) {
jclass tc = (*env)->FindClass(env, "java/lang/Thread");
+ CHECK_NULL_RETURN(tc, JNI_FALSE);
threadClass = (*env)->NewGlobalRef(env, tc);
(*env)->DeleteLocalRef(env, tc);
if (threadClass != NULL) {
@@ -91,10 +92,11 @@
err = TRUE;
}
if (err) {
- return;
+ return JNI_FALSE;
}
} /* threadClass == NULL*/
(*env)->CallStaticVoidMethod(env, threadClass, yieldMethodID);
DASSERT(!((*env)->ExceptionOccurred(env)));
+ return JNI_TRUE;
} /* awtJNI_ThreadYield() */
--- a/jdk/src/solaris/native/sun/awt/awt_util.h Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/awt_util.h Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2014, 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
@@ -78,7 +78,7 @@
int32_t echoC;
};
-extern void awtJNI_ThreadYield(JNIEnv *env);
+extern jboolean awtJNI_ThreadYield(JNIEnv *env);
/*
* Functions for accessing fields by name and signature
--- a/jdk/src/solaris/native/sun/awt/fontpath.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/fontpath.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2014, 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
@@ -161,17 +161,22 @@
if (! isLocalSet) {
jclass geCls = (*env)->FindClass(env, "java/awt/GraphicsEnvironment");
+ CHECK_NULL_RETURN(geCls, JNI_FALSE);
jmethodID getLocalGE = (*env)->GetStaticMethodID(env, geCls,
"getLocalGraphicsEnvironment",
"()Ljava/awt/GraphicsEnvironment;");
+ CHECK_NULL_RETURN(getLocalGE, JNI_FALSE);
jobject ge = (*env)->CallStaticObjectMethod(env, geCls, getLocalGE);
+ JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
jclass sgeCls = (*env)->FindClass(env,
"sun/java2d/SunGraphicsEnvironment");
+ CHECK_NULL_RETURN(sgeCls, JNI_FALSE);
if ((*env)->IsInstanceOf(env, ge, sgeCls)) {
jmethodID isDisplayLocal = (*env)->GetMethodID(env, sgeCls,
"isDisplayLocal",
"()Z");
+ JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
isLocal = (*env)->CallBooleanMethod(env, ge, isDisplayLocal);
} else {
isLocal = True;
@@ -1005,50 +1010,38 @@
jmethodID fcFontCons;
char* debugMinGlyphsStr = getenv("J2D_DEBUG_MIN_GLYPHS");
+ CHECK_NULL(fcInfoObj);
+ CHECK_NULL(fcCompFontArray);
+
jclass fcInfoClass =
(*env)->FindClass(env, "sun/font/FontConfigManager$FontConfigInfo");
+ CHECK_NULL(fcInfoClass);
jclass fcCompFontClass =
(*env)->FindClass(env, "sun/font/FontConfigManager$FcCompFont");
+ CHECK_NULL(fcCompFontClass);
jclass fcFontClass =
(*env)->FindClass(env, "sun/font/FontConfigManager$FontConfigFont");
-
- if (fcInfoObj == NULL || fcCompFontArray == NULL || fcInfoClass == NULL ||
- fcCompFontClass == NULL || fcFontClass == NULL) {
- return;
- }
-
- fcVersionID = (*env)->GetFieldID(env, fcInfoClass, "fcVersion", "I");
+ CHECK_NULL(fcFontClass);
- fcCacheDirsID = (*env)->GetFieldID(env, fcInfoClass, "cacheDirs",
- "[Ljava/lang/String;");
-
- fcNameID = (*env)->GetFieldID(env, fcCompFontClass,
- "fcName", "Ljava/lang/String;");
- fcFirstFontID =
- (*env)->GetFieldID(env, fcCompFontClass, "firstFont",
- "Lsun/font/FontConfigManager$FontConfigFont;");
- fcAllFontsID =
- (*env)->GetFieldID(env, fcCompFontClass, "allFonts",
- "[Lsun/font/FontConfigManager$FontConfigFont;");
-
- fcFontCons = (*env)->GetMethodID(env, fcFontClass, "<init>", "()V");
-
- familyNameID = (*env)->GetFieldID(env, fcFontClass,
- "familyName", "Ljava/lang/String;");
- styleNameID = (*env)->GetFieldID(env, fcFontClass,
- "styleStr", "Ljava/lang/String;");
- fullNameID = (*env)->GetFieldID(env, fcFontClass,
- "fullName", "Ljava/lang/String;");
- fontFileID = (*env)->GetFieldID(env, fcFontClass,
- "fontFile", "Ljava/lang/String;");
-
- if (fcVersionID == NULL || fcCacheDirsID == NULL || fcNameID == NULL ||
- fcFirstFontID == NULL || fcAllFontsID == NULL || fcFontCons == NULL ||
- familyNameID == NULL || styleNameID == NULL || fullNameID == NULL ||
- fontFileID == NULL) {
- return;
- }
+ CHECK_NULL(fcVersionID = (*env)->GetFieldID(env, fcInfoClass, "fcVersion", "I"));
+ CHECK_NULL(fcCacheDirsID = (*env)->GetFieldID(env, fcInfoClass, "cacheDirs",
+ "[Ljava/lang/String;"));
+ CHECK_NULL(fcNameID = (*env)->GetFieldID(env, fcCompFontClass,
+ "fcName", "Ljava/lang/String;"));
+ CHECK_NULL(fcFirstFontID = (*env)->GetFieldID(env, fcCompFontClass, "firstFont",
+ "Lsun/font/FontConfigManager$FontConfigFont;"));
+ CHECK_NULL(fcAllFontsID = (*env)->GetFieldID(env, fcCompFontClass, "allFonts",
+ "[Lsun/font/FontConfigManager$FontConfigFont;"));
+ CHECK_NULL(fcFontCons = (*env)->GetMethodID(env, fcFontClass, "<init>", "()V"));
+ CHECK_NULL(familyNameID = (*env)->GetFieldID(env, fcFontClass,
+ "familyName", "Ljava/lang/String;"));
+ CHECK_NULL(styleNameID = (*env)->GetFieldID(env, fcFontClass,
+ "styleStr", "Ljava/lang/String;"));
+ CHECK_NULL(fullNameID = (*env)->GetFieldID(env, fcFontClass,
+ "fullName", "Ljava/lang/String;"));
+ CHECK_NULL(fontFileID = (*env)->GetFieldID(env, fcFontClass,
+ "fontFile", "Ljava/lang/String;"));
if ((libfontconfig = openFontConfig()) == NULL) {
return;
@@ -1129,6 +1122,8 @@
if (cacheDirs != NULL) {
while ((cnt < max) && (cacheDir = (*FcStrListNext)(cacheDirs))) {
jstr = (*env)->NewStringUTF(env, (const char*)cacheDir);
+ JNU_CHECK_EXCEPTION(env);
+
(*env)->SetObjectArrayElement(env, cacheDirArray, cnt++, jstr);
}
(*FcStrListDone)(cacheDirs);
@@ -1136,6 +1131,11 @@
}
locale = (*env)->GetStringUTFChars(env, localeStr, 0);
+ if (locale == NULL) {
+ (*env)->ExceptionClear(env);
+ JNU_ThrowOutOfMemoryError(env, "Could not create locale");
+ return;
+ }
arrlen = (*env)->GetArrayLength(env, fcCompFontArray);
for (i=0; i<arrlen; i++) {
--- a/jdk/src/solaris/native/sun/awt/gtk2_interface.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/gtk2_interface.c Wed Apr 16 12:42:40 2014 -0700
@@ -538,9 +538,7 @@
fprintf(stderr, "dlsym(gtk_show_uri) returned NULL\n");
#endif /* INTERNAL_BUILD */
} else {
-#ifdef __solaris__
update_supported_actions(env);
-#endif
success = TRUE;
}
}
--- a/jdk/src/solaris/native/sun/awt/initIDs.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/initIDs.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, 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
@@ -47,9 +47,6 @@
(JNIEnv *env, jclass clazz)
{
colorValueID = (*env)->GetFieldID(env, clazz, "value", "I");
-
- if(colorValueID == NULL)
- JNU_ThrowNullPointerException (env, "Can't get java/awt/Color.value fieldID");
}
JNIEXPORT void JNICALL
--- a/jdk/src/solaris/native/sun/awt/multi_font.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/multi_font.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2014, 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
@@ -74,7 +74,7 @@
jobject temp = NULL;
jboolean validRet = JNI_FALSE;
- if ((*env)->EnsureLocalCapacity(env, 2) < 0)
+ if ((*env)->EnsureLocalCapacity(env, 2) < 0 || (*env)->ExceptionCheck(env))
goto done;
peer = (*env)->CallObjectMethod(env,font,fontIDs.getPeer);
@@ -162,7 +162,7 @@
font = JNU_CallMethodByName(env, NULL, this, "getFont_NoClientCode",
"()Ljava/awt/Font;").l;
- if (JNU_IsNull(env, font)) {
+ if (JNU_IsNull(env, font) || (*env)->ExceptionCheck(env)) {
return JNI_FALSE;
}
@@ -318,6 +318,10 @@
}
fdata = awtJNI_GetFontData(env, font, &err);
+ if ((*env)->ExceptionCheck(env)) {
+ (*env)->DeleteLocalRef(env, dataArray);
+ return 0;
+ }
stringCount = (*env)->GetArrayLength(env, dataArray);
@@ -336,6 +340,11 @@
}
j = awtJNI_GetFontDescriptorNumber(env, font, fontDescriptor);
+ if ((*env)->ExceptionCheck(env)) {
+ (*env)->DeleteLocalRef(env, fontDescriptor);
+ (*env)->DeleteLocalRef(env, data);
+ break;
+ }
if (fdata->flist[j].load == 0) {
xf = loadFont(awt_display,
@@ -356,6 +365,14 @@
stringData =
(unsigned char *)(*env)->GetPrimitiveArrayCritical(env, data,NULL);
+ if (stringData == NULL) {
+ (*env)->DeleteLocalRef(env, fontDescriptor);
+ (*env)->DeleteLocalRef(env, data);
+ (*env)->ExceptionClear(env);
+ JNU_ThrowOutOfMemoryError(env, "Could not get string data");
+ break;
+ }
+
length = (stringData[0] << 24) | (stringData[1] << 16) |
(stringData[2] << 8) | stringData[3];
offsetStringData = (char *)(stringData + (4 * sizeof(char)));
--- a/jdk/src/solaris/native/sun/awt/sun_awt_X11_GtkFileDialogPeer.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/awt/sun_awt_X11_GtkFileDialogPeer.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2014, 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
@@ -45,10 +45,12 @@
filenameFilterCallbackMethodID = (*env)->GetMethodID(env, cx,
"filenameFilterCallback", "(Ljava/lang/String;)Z");
DASSERT(filenameFilterCallbackMethodID != NULL);
+ CHECK_NULL(filenameFilterCallbackMethodID);
setFileInternalMethodID = (*env)->GetMethodID(env, cx,
"setFileInternal", "(Ljava/lang/String;[Ljava/lang/String;)V");
DASSERT(setFileInternalMethodID != NULL);
+ CHECK_NULL(setFileInternalMethodID);
widgetFieldID = (*env)->GetFieldID(env, cx, "widget", "J");
DASSERT(widgetFieldID != NULL);
@@ -63,6 +65,7 @@
env = (JNIEnv *) JNU_GetEnv(jvm, JNI_VERSION_1_2);
filename = (*env)->NewStringUTF(env, filter_info->filename);
+ JNU_CHECK_EXCEPTION_RETURN(env, FALSE);
return (*env)->CallBooleanMethod(env, obj, filenameFilterCallbackMethodID,
filename);
@@ -173,13 +176,14 @@
stringCls = (*env)->FindClass(env, "java/lang/String");
if (stringCls == NULL) {
+ (*env)->ExceptionClear(env);
JNU_ThrowInternalError(env, "Could not get java.lang.String class");
return NULL;
}
- array = (*env)->NewObjectArray(env, fp_gtk_g_slist_length(list), stringCls,
- NULL);
+ array = (*env)->NewObjectArray(env, fp_gtk_g_slist_length(list), stringCls, NULL);
if (array == NULL) {
+ (*env)->ExceptionClear(env);
JNU_ThrowInternalError(env, "Could not instantiate array files array");
return NULL;
}
@@ -189,7 +193,9 @@
entry = (char*) iterator->data;
entry = strrchr(entry, '/') + 1;
str = (*env)->NewStringUTF(env, entry);
- (*env)->SetObjectArrayElement(env, array, i, str);
+ if (str && !(*env)->ExceptionCheck(env)) {
+ (*env)->SetObjectArrayElement(env, array, i, str);
+ }
i++;
}
@@ -215,13 +221,14 @@
stringCls = (*env)->FindClass(env, "java/lang/String");
if (stringCls == NULL) {
+ (*env)->ExceptionClear(env);
JNU_ThrowInternalError(env, "Could not get java.lang.String class");
return NULL;
}
- array = (*env)->NewObjectArray(env, fp_gtk_g_slist_length(list), stringCls,
- NULL);
+ array = (*env)->NewObjectArray(env, fp_gtk_g_slist_length(list), stringCls, NULL);
if (array == NULL) {
+ (*env)->ExceptionClear(env);
JNU_ThrowInternalError(env, "Could not instantiate array files array");
return NULL;
}
@@ -236,7 +243,9 @@
}
str = (*env)->NewStringUTF(env, entry);
- (*env)->SetObjectArrayElement(env, array, i, str);
+ if (str && !(*env)->ExceptionCheck(env)) {
+ (*env)->SetObjectArrayElement(env, array, i, str);
+ }
i++;
}
@@ -268,16 +277,17 @@
if (full_path_names) {
//This is a hack for use with "Recent Folders" in gtk where each
//file could have its own directory.
+ jfilenames = toPathAndFilenamesArray(env, filenames);
jcurrent_folder = (*env)->NewStringUTF(env, "/");
- jfilenames = toPathAndFilenamesArray(env, filenames);
} else {
- jcurrent_folder = (*env)->NewStringUTF(env, current_folder);
jfilenames = toFilenamesArray(env, filenames);
+ jcurrent_folder = (*env)->NewStringUTF(env, current_folder);
}
- (*env)->CallVoidMethod(env, obj, setFileInternalMethodID, jcurrent_folder,
- jfilenames);
+ if (!(*env)->ExceptionCheck(env)) {
+ (*env)->CallVoidMethod(env, obj, setFileInternalMethodID,
+ jcurrent_folder, jfilenames);
+ }
fp_g_free(current_folder);
-
quit(env, (jobject)obj, TRUE);
}
@@ -296,11 +306,17 @@
if (jvm == NULL) {
(*env)->GetJavaVM(env, &jvm);
+ JNU_CHECK_EXCEPTION(env);
}
fp_gdk_threads_enter();
const char *title = jtitle == NULL? "": (*env)->GetStringUTFChars(env, jtitle, 0);
+ if (title == NULL) {
+ (*env)->ExceptionClear(env);
+ JNU_ThrowOutOfMemoryError(env, "Could not get title");
+ return;
+ }
if (mode == java_awt_FileDialog_SAVE) {
/* Save action */
@@ -328,6 +344,11 @@
/* Set the directory */
if (jdir != NULL) {
const char *dir = (*env)->GetStringUTFChars(env, jdir, 0);
+ if (dir == NULL) {
+ (*env)->ExceptionClear(env);
+ JNU_ThrowOutOfMemoryError(env, "Could not get dir");
+ return;
+ }
fp_gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), dir);
(*env)->ReleaseStringUTFChars(env, jdir, dir);
}
@@ -335,6 +356,11 @@
/* Set the filename */
if (jfile != NULL) {
const char *filename = (*env)->GetStringUTFChars(env, jfile, 0);
+ if (filename == NULL) {
+ (*env)->ExceptionClear(env);
+ JNU_ThrowOutOfMemoryError(env, "Could not get filename");
+ return;
+ }
if (mode == java_awt_FileDialog_SAVE) {
fp_gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename);
} else {
--- a/jdk/src/solaris/native/sun/xawt/XToolkit.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/xawt/XToolkit.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2014, 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
@@ -40,6 +40,7 @@
#include "awt_Component.h"
#include "awt_MenuComponent.h"
#include "awt_Font.h"
+#include "awt_util.h"
#include "sun_awt_X11_XToolkit.h"
#include "java_awt_SystemColor.h"
@@ -76,6 +77,8 @@
#ifndef HEADLESS
extern Display* awt_init_Display(JNIEnv *env, jobject this);
+extern void freeNativeStringArray(char **array, long length);
+extern char** stringArrayToNative(JNIEnv *env, jobjectArray array, jsize * ret_length);
struct XFontPeerIDs xFontPeerIDs;
@@ -103,9 +106,11 @@
(JNIEnv *env, jclass clazz)
{
jfieldID fid = (*env)->GetStaticFieldID(env, clazz, "numLockMask", "I");
+ CHECK_NULL(fid);
awt_NumLockMask = (*env)->GetStaticIntField(env, clazz, fid);
DTRACE_PRINTLN1("awt_NumLockMask = %u", awt_NumLockMask);
fid = (*env)->GetStaticFieldID(env, clazz, "modLockIsShiftLock", "I");
+ CHECK_NULL(fid);
awt_ModLockIsShiftLock = (*env)->GetStaticIntField(env, clazz, fid) != 0 ? True : False;
}
@@ -173,21 +178,31 @@
componentIDs.x = (*env)->GetFieldID(env, cls, "x", "I");
+ CHECK_NULL(componentIDs.x);
componentIDs.y = (*env)->GetFieldID(env, cls, "y", "I");
+ CHECK_NULL(componentIDs.y);
componentIDs.width = (*env)->GetFieldID(env, cls, "width", "I");
+ CHECK_NULL(componentIDs.width);
componentIDs.height = (*env)->GetFieldID(env, cls, "height", "I");
+ CHECK_NULL(componentIDs.height);
componentIDs.isPacked = (*env)->GetFieldID(env, cls, "isPacked", "Z");
+ CHECK_NULL(componentIDs.isPacked);
componentIDs.peer =
(*env)->GetFieldID(env, cls, "peer", "Ljava/awt/peer/ComponentPeer;");
+ CHECK_NULL(componentIDs.peer);
componentIDs.background =
(*env)->GetFieldID(env, cls, "background", "Ljava/awt/Color;");
+ CHECK_NULL(componentIDs.background);
componentIDs.foreground =
(*env)->GetFieldID(env, cls, "foreground", "Ljava/awt/Color;");
+ CHECK_NULL(componentIDs.foreground);
componentIDs.graphicsConfig =
(*env)->GetFieldID(env, cls, "graphicsConfig",
"Ljava/awt/GraphicsConfiguration;");
+ CHECK_NULL(componentIDs.graphicsConfig);
componentIDs.name =
(*env)->GetFieldID(env, cls, "name", "Ljava/lang/String;");
+ CHECK_NULL(componentIDs.name);
/* Use _NoClientCode() methods for trusted methods, so that we
* know that we are not invoking client code on trusted threads
@@ -195,19 +210,20 @@
componentIDs.getParent =
(*env)->GetMethodID(env, cls, "getParent_NoClientCode",
"()Ljava/awt/Container;");
+ CHECK_NULL(componentIDs.getParent);
componentIDs.getLocationOnScreen =
(*env)->GetMethodID(env, cls, "getLocationOnScreen_NoTreeLock",
"()Ljava/awt/Point;");
+ CHECK_NULL(componentIDs.getLocationOnScreen);
keyclass = (*env)->FindClass(env, "java/awt/event/KeyEvent");
- if (JNU_IsNull(env, keyclass)) {
- return;
- }
+ CHECK_NULL(keyclass);
componentIDs.isProxyActive =
(*env)->GetFieldID(env, keyclass, "isProxyActive",
"Z");
+ CHECK_NULL(componentIDs.isProxyActive);
componentIDs.appContext =
(*env)->GetFieldID(env, cls, "appContext",
@@ -339,7 +355,7 @@
static void waitForEvents(JNIEnv *, jlong);
static void awt_pipe_init();
static void processOneEvent(XtInputMask iMask);
-static void performPoll(JNIEnv *, jlong);
+static Boolean performPoll(JNIEnv *, jlong);
static void wakeUp();
static void update_poll_timeout(int timeout_control);
static uint32_t get_poll_timeout(jlong nextTaskTime);
@@ -608,11 +624,13 @@
*/
void
waitForEvents(JNIEnv *env, jlong nextTaskTime) {
- performPoll(env, nextTaskTime);
- if ((awt_next_flush_time > 0) && (awtJNI_TimeMillis() >= awt_next_flush_time)) {
- XFlush(awt_display);
- awt_last_flush_time = awt_next_flush_time;
- awt_next_flush_time = 0LL;
+ if (performPoll(env, nextTaskTime)
+ && (awt_next_flush_time > 0)
+ && (awtJNI_TimeMillis() >= awt_next_flush_time)) {
+
+ XFlush(awt_display);
+ awt_last_flush_time = awt_next_flush_time;
+ awt_next_flush_time = 0LL;
}
} /* waitForEvents() */
@@ -646,7 +664,7 @@
*
* The fdAWTPipe will be empty when this returns.
*/
-static void
+static Boolean
performPoll(JNIEnv *env, jlong nextTaskTime) {
static Bool pollFdsInited = False;
static char read_buf[AWT_POLL_BUFSIZE + 1]; /* dummy buf to empty pipe */
@@ -673,7 +691,9 @@
/* ACTUALLY DO THE POLL() */
if (timeout == 0) {
// be sure other threads get a chance
- awtJNI_ThreadYield(env);
+ if (!awtJNI_ThreadYield(env)) {
+ return FALSE;
+ }
}
if (tracing) poll_sleep_time = awtJNI_TimeMillis();
@@ -701,7 +721,7 @@
update_poll_timeout(TIMEOUT_EVENTS);
PRINT2("performPoll(): TIMEOUT_EVENTS curPollTimeout = %d \n", curPollTimeout);
}
- return;
+ return TRUE;
} /* performPoll() */
@@ -856,23 +876,25 @@
xawt_root_window = get_xawt_root_shell(env);
if ( xawt_root_window == None ) {
+ AWT_UNLOCK();
JNU_ThrowNullPointerException(env, "AWT root shell is unrealized");
- AWT_UNLOCK();
return;
}
command = (char *) JNU_GetStringPlatformChars(env, jcommand, NULL);
- c[0] = (char *)command;
- status = XmbTextListToTextProperty(awt_display, c, 1,
- XStdICCTextStyle, &text_prop);
+ if (command != NULL) {
+ c[0] = (char *)command;
+ status = XmbTextListToTextProperty(awt_display, c, 1,
+ XStdICCTextStyle, &text_prop);
- if (status == Success || status > 0) {
- XSetTextProperty(awt_display, xawt_root_window,
- &text_prop, XA_WM_COMMAND);
- if (text_prop.value != NULL)
- XFree(text_prop.value);
+ if (status == Success || status > 0) {
+ XSetTextProperty(awt_display, xawt_root_window,
+ &text_prop, XA_WM_COMMAND);
+ if (text_prop.value != NULL)
+ XFree(text_prop.value);
+ }
+ JNU_ReleaseStringPlatformChars(env, jcommand, command);
}
- JNU_ReleaseStringPlatformChars(env, jcommand, command);
AWT_UNLOCK();
}
@@ -886,96 +908,56 @@
* name. It's not! It's just a plain function.
*/
JNIEXPORT void JNICALL
-Java_sun_awt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jargv)
+Java_sun_awt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jarray)
{
- static const char empty[] = "";
-
- int argc;
- const char **cargv;
+ jsize length;
+ char ** array;
XTextProperty text_prop;
int status;
- int i;
Window xawt_root_window;
AWT_LOCK();
xawt_root_window = get_xawt_root_shell(env);
if (xawt_root_window == None) {
+ AWT_UNLOCK();
JNU_ThrowNullPointerException(env, "AWT root shell is unrealized");
- AWT_UNLOCK();
return;
}
- argc = (int)(*env)->GetArrayLength(env, jargv);
- if (argc == 0) {
- AWT_UNLOCK();
- return;
- }
-
- /* array of C strings */
- cargv = (const char **)calloc(argc, sizeof(char *));
- if (cargv == NULL) {
- JNU_ThrowOutOfMemoryError(env, "Unable to allocate cargv");
- AWT_UNLOCK();
- return;
- }
-
- /* fill C array with platform chars of java strings */
- for (i = 0; i < argc; ++i) {
- jstring js;
- const char *cs;
-
- cs = NULL;
- js = (*env)->GetObjectArrayElement(env, jargv, i);
- if (js != NULL) {
- cs = JNU_GetStringPlatformChars(env, js, NULL);
- }
- if (cs == NULL) {
- cs = empty;
- }
- cargv[i] = cs;
- (*env)->DeleteLocalRef(env, js);
- }
+ array = stringArrayToNative(env, jarray, &length);
- /* grr, X prototype doesn't declare cargv as const, thought it really is */
- status = XmbTextListToTextProperty(awt_display, (char **)cargv, argc,
- XStdICCTextStyle, &text_prop);
- if (status < 0) {
- switch (status) {
- case XNoMemory:
- JNU_ThrowOutOfMemoryError(env,
- "XmbTextListToTextProperty: XNoMemory");
- break;
- case XLocaleNotSupported:
- JNU_ThrowInternalError(env,
- "XmbTextListToTextProperty: XLocaleNotSupported");
- break;
- case XConverterNotFound:
- JNU_ThrowNullPointerException(env,
- "XmbTextListToTextProperty: XConverterNotFound");
- break;
- default:
- JNU_ThrowInternalError(env,
- "XmbTextListToTextProperty: unknown error");
+ if (array != NULL) {
+ status = XmbTextListToTextProperty(awt_display, array, length,
+ XStdICCTextStyle, &text_prop);
+ if (status < 0) {
+ switch (status) {
+ case XNoMemory:
+ JNU_ThrowOutOfMemoryError(env,
+ "XmbTextListToTextProperty: XNoMemory");
+ break;
+ case XLocaleNotSupported:
+ JNU_ThrowInternalError(env,
+ "XmbTextListToTextProperty: XLocaleNotSupported");
+ break;
+ case XConverterNotFound:
+ JNU_ThrowNullPointerException(env,
+ "XmbTextListToTextProperty: XConverterNotFound");
+ break;
+ default:
+ JNU_ThrowInternalError(env,
+ "XmbTextListToTextProperty: unknown error");
+ }
+ } else {
+ XSetTextProperty(awt_display, xawt_root_window,
+ &text_prop, XA_WM_COMMAND);
}
- } else {
-
- XSetTextProperty(awt_display, xawt_root_window,
- &text_prop, XA_WM_COMMAND);
- }
-
- for (i = 0; i < argc; ++i) {
- jstring js;
- if (cargv[i] == empty)
- continue;
+ if (text_prop.value != NULL)
+ XFree(text_prop.value);
- js = (*env)->GetObjectArrayElement(env, jargv, i);
- JNU_ReleaseStringPlatformChars(env, js, cargv[i]);
- (*env)->DeleteLocalRef(env, js);
+ freeNativeStringArray(array, length);
}
- if (text_prop.value != NULL)
- XFree(text_prop.value);
AWT_UNLOCK();
}
--- a/jdk/src/solaris/native/sun/xawt/XWindow.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/xawt/XWindow.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2014, 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
@@ -1242,9 +1242,13 @@
{
char *ptr = NULL;
windowID = (*env)->GetFieldID(env, clazz, "window", "J");
+ CHECK_NULL(windowID);
targetID = (*env)->GetFieldID(env, clazz, "target", "Ljava/awt/Component;");
+ CHECK_NULL(targetID);
graphicsConfigID = (*env)->GetFieldID(env, clazz, "graphicsConfig", "Lsun/awt/X11GraphicsConfig;");
+ CHECK_NULL(graphicsConfigID);
drawStateID = (*env)->GetFieldID(env, clazz, "drawState", "I");
+ CHECK_NULL(drawStateID);
ptr = getenv("_AWT_USE_TYPE4_PATCH");
if( ptr != NULL && ptr[0] != 0 ) {
if( strncmp("true", ptr, 4) == 0 ) {
--- a/jdk/src/solaris/native/sun/xawt/XlibWrapper.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/xawt/XlibWrapper.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2014, 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
@@ -48,6 +48,7 @@
#include "utility/rect.h"
#include <X11/XKBlib.h>
+
#if defined(DEBUG) || defined(INTERNAL_BUILD)
static jmethodID lockIsHeldMID = NULL;
@@ -59,17 +60,94 @@
lockIsHeldMID =
(*env)->GetStaticMethodID(env, tkClass,
"isAWTLockHeldByCurrentThread", "()Z");
+ if (lockIsHeldMID == NULL) return;
}
if (!(*env)->CallStaticBooleanMethod(env, tkClass, lockIsHeldMID)) {
JNU_ThrowInternalError(env, "Current thread does not hold AWT_LOCK!");
}
}
-#define AWT_CHECK_HAVE_LOCK() CheckHaveAWTLock(env)
+#define AWT_CHECK_HAVE_LOCK() \
+ do { \
+ CheckHaveAWTLock(env); \
+ if ((*env)->ExceptionCheck(env)) { \
+ return; \
+ } \
+ } while (0); \
+
+#define AWT_CHECK_HAVE_LOCK_RETURN(ret) \
+ do { \
+ CheckHaveAWTLock(env); \
+ if ((*env)->ExceptionCheck(env)) { \
+ return (ret); \
+ } \
+ } while (0); \
+
#else
#define AWT_CHECK_HAVE_LOCK()
+#define AWT_CHECK_HAVE_LOCK_RETURN(ret)
#endif
+void freeNativeStringArray(char **array, jsize length) {
+ int i;
+ if (array == NULL) {
+ return;
+ }
+ for (i = 0; i < length; i++) {
+ free(array[i]);
+ }
+ free(array);
+}
+
+char** stringArrayToNative(JNIEnv *env, jobjectArray array, jsize * ret_length) {
+ Bool err = FALSE;
+ char ** strings;
+ int index, str_index = 0;
+ jsize length = (*env)->GetArrayLength(env, array);
+
+ if (length == 0) {
+ return NULL;
+ }
+
+ strings = (char**) calloc(length, sizeof (char*));
+
+ if (strings == NULL) {
+ JNU_ThrowOutOfMemoryError(env, "");
+ return NULL;
+ }
+
+ for (index = 0; index < length; index++) {
+ jstring str = (*env)->GetObjectArrayElement(env, array, index);
+ if (str != NULL) {
+ const char * str_char = JNU_GetStringPlatformChars(env, str, NULL);
+ if (str_char != NULL) {
+ char * dup_str = strdup(str_char);
+ if (dup_str != NULL) {
+ strings[str_index++] = dup_str;
+ } else {
+ JNU_ThrowOutOfMemoryError(env, "");
+ err = TRUE;
+ }
+ JNU_ReleaseStringPlatformChars(env, str, str_char);
+ } else {
+ err = TRUE;
+ }
+ (*env)->DeleteLocalRef(env, str);
+ if (err) {
+ break;
+ }
+ }
+ }
+
+ if (err) {
+ freeNativeStringArray(strings, str_index);
+ strings = NULL;
+ str_index = -1;
+ }
+ *ret_length = str_index;
+
+ return strings;
+}
/*
* Class: XlibWrapper
@@ -81,7 +159,7 @@
(JNIEnv *env, jclass clazz, jlong display_name)
{
Display *dp;
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
dp = XOpenDisplay((char *) jlong_to_ptr(display_name));
return ptr_to_jlong(dp);
@@ -97,7 +175,7 @@
JNIEXPORT jlong JNICALL
Java_sun_awt_X11_XlibWrapper_XDisplayString(JNIEnv *env, jclass clazz,
jlong display) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return ptr_to_jlong(XDisplayString((Display*) jlong_to_ptr(display)));
}
@@ -115,7 +193,7 @@
*/
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DefaultScreen (JNIEnv *env, jclass clazz, jlong display) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return (jlong) DefaultScreen((Display *) jlong_to_ptr(display));
}
@@ -125,7 +203,7 @@
* Signature: (JJ)J
*/
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_ScreenOfDisplay(JNIEnv *env, jclass clazz, jlong display, jlong screen_number) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return ptr_to_jlong(ScreenOfDisplay((Display *) jlong_to_ptr(display),
screen_number));
}
@@ -136,7 +214,7 @@
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_DoesBackingStore(JNIEnv *env, jclass clazz, jlong screen) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return (jint) DoesBackingStore((Screen*) jlong_to_ptr(screen));
}
@@ -148,7 +226,7 @@
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DisplayWidth
(JNIEnv *env, jclass clazz, jlong display, jlong screen) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return (jlong) DisplayWidth((Display *) jlong_to_ptr(display),screen);
}
@@ -160,7 +238,7 @@
*/
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DisplayWidthMM
(JNIEnv *env, jclass clazz, jlong display, jlong screen) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return (jlong) DisplayWidthMM((Display *) jlong_to_ptr(display),screen);
}
@@ -172,7 +250,7 @@
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DisplayHeight
(JNIEnv *env, jclass clazz, jlong display, jlong screen) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return (jlong) DisplayHeight((Display *) jlong_to_ptr(display),screen);
}
/*
@@ -182,7 +260,7 @@
*/
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DisplayHeightMM
(JNIEnv *env, jclass clazz, jlong display, jlong screen) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return (jlong) DisplayHeightMM((Display *) jlong_to_ptr(display),screen);
}
@@ -193,7 +271,7 @@
*/
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_RootWindow
(JNIEnv *env , jclass clazz, jlong display, jlong screen_number) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return (jlong) RootWindow((Display *) jlong_to_ptr(display), screen_number);
}
@@ -203,7 +281,7 @@
*/
JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_ScreenCount
(JNIEnv *env , jclass clazz, jlong display) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return ScreenCount((Display *) jlong_to_ptr(display));
}
@@ -218,7 +296,7 @@
jint x, jint y, jint w, jint h , jint border_width, jint depth,
jlong wclass, jlong visual, jlong valuemask, jlong attributes)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XCreateWindow((Display *) jlong_to_ptr(display),(Window) window, x, y, w, h,
border_width, depth, wclass, (Visual *) jlong_to_ptr(visual),
valuemask, (XSetWindowAttributes *) jlong_to_ptr(attributes));
@@ -360,7 +438,7 @@
Window focusOwner;
int revert_to;
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
XGetInputFocus( (Display *)jlong_to_ptr(display), &focusOwner, &revert_to);
return focusOwner;
}
@@ -383,7 +461,7 @@
jint owner_events, jint event_mask, jint pointer_mode,
jint keyboard_mode, jlong confine_to, jlong cursor, jlong time)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XGrabPointer( (Display *)jlong_to_ptr(display), (Window) window,
(Bool) owner_events, (unsigned int) event_mask, (int) pointer_mode,
(int) keyboard_mode, (Window) confine_to, (Cursor) cursor, (Time) time);
@@ -401,7 +479,7 @@
jint owner_events, jint pointer_mode,
jint keyboard_mode, jlong time)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XGrabKeyboard( (Display *)jlong_to_ptr(display), (Window) window,
(Bool) owner_events, (int) pointer_mode,
(int) keyboard_mode, (Time) time);
@@ -474,7 +552,7 @@
(JNIEnv *env, jclass clazz, jlong display, jlong opcode_rtrn, jlong event_rtrn,
jlong error_rtrn, jlong major_in_out, jlong minor_in_out)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
return XkbQueryExtension( (Display *) jlong_to_ptr(display),
(int *) jlong_to_ptr(opcode_rtrn),
(int *) jlong_to_ptr(event_rtrn),
@@ -485,7 +563,7 @@
JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XkbLibraryVersion
(JNIEnv *env, jclass clazz, jlong lib_major_in_out, jlong lib_minor_in_out)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
*((int *)jlong_to_ptr(lib_major_in_out)) = XkbMajorVersion;
*((int *)jlong_to_ptr(lib_minor_in_out)) = XkbMinorVersion;
return XkbLibraryVersion((int *)jlong_to_ptr(lib_major_in_out), (int *)jlong_to_ptr(lib_minor_in_out));
@@ -494,7 +572,7 @@
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XkbGetMap
(JNIEnv *env, jclass clazz, jlong display, jlong which, jlong device_spec)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return (jlong) XkbGetMap( (Display *) jlong_to_ptr(display),
(unsigned int) which,
(unsigned int) device_spec);
@@ -502,7 +580,7 @@
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XkbGetUpdatedMap
(JNIEnv *env, jclass clazz, jlong display, jlong which, jlong xkb)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return (jlong) XkbGetUpdatedMap( (Display *) jlong_to_ptr(display),
(unsigned int) which,
(XkbDescPtr) jlong_to_ptr(xkb));
@@ -516,6 +594,7 @@
JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XkbTranslateKeyCode
(JNIEnv *env, jclass clazz, jlong xkb, jint keycode, jlong mods, jlong mods_rtrn, jlong keysym_rtrn)
{
+ AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
Bool b;
b = XkbTranslateKeyCode((XkbDescPtr)xkb, (unsigned int)keycode, (unsigned int)mods,
(unsigned int *)jlong_to_ptr(mods_rtrn),
@@ -578,7 +657,7 @@
JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XFilterEvent
(JNIEnv *env, jclass clazz, jlong ptr, jlong window)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
return (jboolean) XFilterEvent((XEvent *) jlong_to_ptr(ptr), (Window) window);
}
@@ -590,7 +669,7 @@
JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XSupportsLocale
(JNIEnv *env, jclass clazz)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
return (jboolean)XSupportsLocale();
}
@@ -607,9 +686,10 @@
if (!JNU_IsNull(env, jstr)) {
modifier_list = (char *)JNU_GetStringPlatformChars(env, jstr, NULL);
+ CHECK_NULL_RETURN(modifier_list, NULL);
}
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(NULL);
if (modifier_list) {
ret = XSetLocaleModifiers(modifier_list);
JNU_ReleaseStringPlatformChars(env, jstr, (const char *) modifier_list);
@@ -722,7 +802,7 @@
jlong src_x, jlong src_y, jlong dest_x_return, jlong dest_y_return,
jlong child_return)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XTranslateCoordinates( (Display *) jlong_to_ptr(display), src_w, dest_w,
src_x, src_y,
(int *) jlong_to_ptr(dest_x_return),
@@ -733,7 +813,7 @@
JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XEventsQueued
(JNIEnv *env, jclass clazz, jlong display, jint mode) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XEventsQueued((Display *) jlong_to_ptr(display), mode);
}
@@ -758,6 +838,7 @@
#else
cname = (char *) JNU_GetStringPlatformChars(env, jstr, NULL);
#endif
+ CHECK_NULL(cname);
} else {
cname = "";
}
@@ -814,8 +895,9 @@
jlong type, jint format, jint mode, jstring value)
{
jboolean iscopy;
+ AWT_CHECK_HAVE_LOCK();
const char * chars = JNU_GetStringPlatformChars(env, value, &iscopy);
- AWT_CHECK_HAVE_LOCK();
+ CHECK_NULL(chars);
XChangeProperty((Display*)jlong_to_ptr(display), window, (Atom)property,
(Atom)type, format, mode, (unsigned char*)chars, strlen(chars));
if (iscopy) {
@@ -833,7 +915,7 @@
jlong long_length, jlong delete, jlong req_type, jlong actual_type,
jlong actual_format, jlong nitems_ptr, jlong bytes_after, jlong data_ptr)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XGetWindowProperty((Display*) jlong_to_ptr(display), window, property, long_offset, long_length,
delete, (Atom) req_type, (Atom*) jlong_to_ptr(actual_type),
(int *) jlong_to_ptr(actual_format), (unsigned long *) jlong_to_ptr(nitems_ptr),
@@ -857,23 +939,22 @@
unsigned long nitems;
unsigned long bytes_after;
unsigned char * string;
- jstring res;
- AWT_CHECK_HAVE_LOCK();
+ jstring res = NULL;
+ AWT_CHECK_HAVE_LOCK_RETURN(NULL);
status = XGetWindowProperty((Display*)jlong_to_ptr(display), window,
atom, 0, 0xFFFF, False, XA_STRING,
&actual_type, &actual_format, &nitems, &bytes_after,
&string);
+
if (status != Success || string == NULL) {
- return NULL;
+ return NULL;
}
- if (actual_type != XA_STRING || actual_format != 8) {
- XFree(string);
- return NULL;
+ if (actual_type == XA_STRING && actual_format == 8) {
+ res = JNU_NewStringPlatform(env,(char*) string);
}
-
- // Memory leak???
- return JNU_NewStringPlatform(env,(char*) string);
+ XFree(string);
+ return res;
}
/*
@@ -887,13 +968,15 @@
char *cname;
unsigned long atom;
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
+
if (!JNU_IsNull(env, jstr)) {
cname = (char *)JNU_GetStringPlatformChars(env, jstr, NULL);
+ CHECK_NULL_RETURN(cname, 0);
} else {
cname = "";
}
- AWT_CHECK_HAVE_LOCK();
atom = XInternAtom((Display *) jlong_to_ptr(display), cname, ife);
if (!JNU_IsNull(env, jstr)) {
@@ -906,7 +989,7 @@
JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XCreateFontCursor
(JNIEnv *env, jclass clazz, jlong display, jint shape) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XCreateFontCursor((Display *) jlong_to_ptr(display), (int) shape);
}
@@ -919,7 +1002,7 @@
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XCreatePixmapCursor
(JNIEnv *env , jclass clazz, jlong display, jlong source, jlong mask, jlong fore, jlong back, jint x , jint y) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return (jlong) XCreatePixmapCursor((Display *) jlong_to_ptr(display), (Pixmap) source, (Pixmap) mask,
(XColor *) jlong_to_ptr(fore), (XColor *) jlong_to_ptr(back), x, y);
}
@@ -935,7 +1018,7 @@
Status status;
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
status = XQueryBestCursor((Display *) jlong_to_ptr(display), (Drawable) drawable, width,height,
(unsigned int *) jlong_to_ptr(width_return), (unsigned int *) jlong_to_ptr(height_return));
@@ -966,15 +1049,14 @@
Bool b;
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
b = XQueryPointer((Display *) jlong_to_ptr(display),
(Window) w, (Window *) jlong_to_ptr(root_return), (Window *) jlong_to_ptr(child_return),
(int *) jlong_to_ptr(root_x_return), (int *) jlong_to_ptr(root_y_return),
(int *) jlong_to_ptr(win_x_return), (int *) jlong_to_ptr(win_y_return),
(unsigned int *) jlong_to_ptr(mask_return));
- if (b == True) return JNI_TRUE;
- else return JNI_FALSE;
+ return b ? JNI_TRUE : JNI_FALSE;
}
/*
@@ -1042,7 +1124,7 @@
JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetPointerMapping
(JNIEnv *env, jclass clazz, jlong display, jlong map, jint buttonNumber)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XGetPointerMapping((Display*)jlong_to_ptr(display), (unsigned char*) jlong_to_ptr(map), buttonNumber);
}
@@ -1061,31 +1143,26 @@
if (!JNU_IsNull(env, program)) {
c_program = (char *)JNU_GetStringPlatformChars(env, program, NULL);
}
+ CHECK_NULL_RETURN(c_program, NULL);
+
if (!JNU_IsNull(env, option)) {
c_option = (char *)JNU_GetStringPlatformChars(env, option, NULL);
}
- if (c_program == NULL || c_option == NULL) {
- if (!JNU_IsNull(env, program)) {
- JNU_ReleaseStringPlatformChars(env, program, (const char *) c_program);
- }
- if (!JNU_IsNull(env, option)) {
- JNU_ReleaseStringPlatformChars(env, option, (const char *) c_option);
- }
+ if (c_option == NULL) {
+ JNU_ReleaseStringPlatformChars(env, program, (const char *) c_program);
return NULL;
}
- AWT_CHECK_HAVE_LOCK();
- c_res = XGetDefault((Display*)jlong_to_ptr(display), c_program, c_option);
- if (!JNU_IsNull(env, program)) {
- JNU_ReleaseStringPlatformChars(env, program, (const char *) c_program);
- }
- if (!JNU_IsNull(env, option)) {
- JNU_ReleaseStringPlatformChars(env, option, (const char *) c_option);
- }
+ AWT_CHECK_HAVE_LOCK_RETURN(NULL);
+ c_res = XGetDefault((Display*)jlong_to_ptr(display), c_program, c_option);
+ // The strings returned by XGetDefault() are owned by Xlib and
+ // should not be modified or freed by the client.
+
+ JNU_ReleaseStringPlatformChars(env, program, (const char *) c_program);
+ JNU_ReleaseStringPlatformChars(env, option, (const char *) c_option);
if (c_res != NULL) {
- // Memory leak???
return JNU_NewStringPlatform(env, c_res);
} else {
return NULL;
@@ -1103,7 +1180,7 @@
{
XWindowAttributes attrs;
memset(&attrs, 0, sizeof(attrs));
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
XGetWindowAttributes((Display *) jlong_to_ptr(display), window, &attrs);
return ptr_to_jlong(attrs.screen);
}
@@ -1116,7 +1193,7 @@
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XScreenNumberOfScreen
(JNIEnv *env, jclass clazz, jlong screen)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(-1);
if(jlong_to_ptr(screen) == NULL) {
return -1;
}
@@ -1131,7 +1208,7 @@
JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XIconifyWindow
(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong screenNumber)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XIconifyWindow((Display*) jlong_to_ptr(display), window, screenNumber);
}
@@ -1158,10 +1235,9 @@
unsigned char * str = (unsigned char*) jlong_to_ptr(str_ptr);
long length = strlen((char*)str);
jbyteArray res = (*env)->NewByteArray(env, length);
- void * storage = malloc(length+1);
- memcpy(storage, str, length+1);
+ CHECK_NULL_RETURN(res, NULL);
(*env)->SetByteArrayRegion(env, res, 0, length,
- (const signed char*) storage);
+ (const signed char*) str);
return res;
}
@@ -1174,7 +1250,7 @@
JNIEXPORT jstring JNICALL Java_sun_awt_X11_XlibWrapper_ServerVendor
(JNIEnv *env, jclass clazz, jlong display)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(NULL);
return JNU_NewStringPlatform(env, ServerVendor((Display*)jlong_to_ptr(display)));
}
/*
@@ -1185,7 +1261,7 @@
JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_VendorRelease
(JNIEnv *env, jclass clazz, jlong display)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return VendorRelease((Display*)jlong_to_ptr(display));
}
/*
@@ -1203,7 +1279,7 @@
// second, in which place in the keysymarray is XK_KP_7
// using XKeycodeToKeysym.
int kc7;
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
kc7 = XKeysymToKeycode((Display*)jlong_to_ptr(display), XK_KP_7);
if( !kc7 ) {
// keycode is not defined. Why, it's a reduced keyboard perhaps:
@@ -1226,7 +1302,7 @@
(JNIEnv *env, jclass clazz, jlong display)
{
int xx;
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
xx = XKeysymToKeycode((Display*)jlong_to_ptr(display), SunXK_F37);
return (!xx) ? JNI_FALSE : JNI_TRUE;
}
@@ -1242,7 +1318,7 @@
int32_t i;
int32_t kanaCount = 0;
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
// There's no direct way to determine whether the keyboard has
// a kana lock key. From available keyboard mapping tables, it looks
@@ -1289,8 +1365,10 @@
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_SetToolkitErrorHandler
(JNIEnv *env, jclass clazz)
{
- (*env)->GetJavaVM(env, &jvm);
- AWT_CHECK_HAVE_LOCK();
+ if ((*env)->GetJavaVM(env, &jvm) < 0) {
+ return 0;
+ }
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return ptr_to_jlong(XSetErrorHandler(ToolkitErrorHandler));
}
@@ -1350,28 +1428,14 @@
JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XInternAtoms
(JNIEnv *env, jclass clazz, jlong display, jobjectArray names_arr, jboolean only_if_exists, jlong atoms)
{
- int length = (*env)->GetArrayLength(env, names_arr);
- char ** names = (char**)malloc(length*sizeof(char*));
- jboolean copy;
- int index, name_index = 0;
- int status;
-
- AWT_CHECK_HAVE_LOCK();
-
- for (index = 0; index < length; index++) {
- jstring str = (*env)->GetObjectArrayElement(env, names_arr, index);
- if (!JNU_IsNull(env, str)) {
- const char * str_char = JNU_GetStringPlatformChars(env, str, NULL);
- names[name_index++] = strdup(str_char);
- JNU_ReleaseStringPlatformChars(env, str, str_char);
- (*env)->DeleteLocalRef(env, str);
- }
+ int status = 0;
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
+ jsize length;
+ char** names = stringArrayToNative(env, names_arr, &length);
+ if (names) {
+ status = XInternAtoms((Display*)jlong_to_ptr(display), names, length, only_if_exists, (Atom*) jlong_to_ptr(atoms));
+ freeNativeStringArray(names, length);
}
- status = XInternAtoms((Display*)jlong_to_ptr(display), names, name_index, only_if_exists, (Atom*) jlong_to_ptr(atoms));
- for (index = 0; index < length; index++) {
- free(names[index]);
- }
- free(names);
return status;
}
@@ -1386,7 +1450,7 @@
(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong attr_ptr)
{
jint status;
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
memset((XWindowAttributes*) jlong_to_ptr(attr_ptr), 0, sizeof(XWindowAttributes));
status = XGetWindowAttributes((Display*)jlong_to_ptr(display), window, (XWindowAttributes*) jlong_to_ptr(attr_ptr));
return status;
@@ -1404,7 +1468,7 @@
jlong border_width_return, jlong depth_return)
{
jint status;
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
status = XGetGeometry((Display *)jlong_to_ptr(display),
(Drawable)drawable, (Window *)jlong_to_ptr(root_return),
(int *)jlong_to_ptr(x_return), (int *)jlong_to_ptr(y_return),
@@ -1423,7 +1487,7 @@
JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetWMNormalHints
(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong hints, jlong supplied_return)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XGetWMNormalHints((Display*) jlong_to_ptr(display),
window,
(XSizeHints*) jlong_to_ptr(hints),
@@ -1462,7 +1526,7 @@
JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XSendEvent
(JNIEnv *env, jclass clazz, jlong display, jlong window, jboolean propagate, jlong event_mask, jlong event)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XSendEvent((Display*) jlong_to_ptr(display),
window,
propagate==JNI_TRUE?True:False,
@@ -1479,7 +1543,7 @@
JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XQueryTree
(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong root_return, jlong parent_return, jlong children_return, jlong nchildren_return)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XQueryTree((Display*) jlong_to_ptr(display),
window,
(Window *) jlong_to_ptr(root_return),
@@ -1524,7 +1588,7 @@
(JNIEnv *env, jclass clazz, jlong display, jlong vinfo_mask, jlong vinfo_template,
jlong nitems_return)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return ptr_to_jlong(XGetVisualInfo((Display*) jlong_to_ptr(display),
(long) vinfo_mask,
(XVisualInfo*) jlong_to_ptr(vinfo_template),
@@ -1534,7 +1598,7 @@
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XAllocSizeHints
(JNIEnv *env, jclass clazz)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return ptr_to_jlong(XAllocSizeHints());
}
@@ -1560,7 +1624,7 @@
(JNIEnv *env, jclass clazz, jlong display , jlong colormap, jlong xcolor) {
Status status;
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
status = XAllocColor((Display *) jlong_to_ptr(display), (Colormap) colormap, (XColor *) jlong_to_ptr(xcolor));
if (status == 0) return JNI_FALSE;
@@ -1575,7 +1639,7 @@
*/
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XCreateBitmapFromData
(JNIEnv *env, jclass clazz, jlong display, jlong drawable, jlong data, jint width, jint height) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return (jlong) XCreateBitmapFromData((Display *) jlong_to_ptr(display), (Drawable) drawable,
(char *) jlong_to_ptr(data), width, height);
@@ -1640,7 +1704,7 @@
JNIEXPORT jlong JNICALL
Java_sun_awt_X11_XlibWrapper_XGetSelectionOwner(JNIEnv *env, jclass clazz,
jlong display, jlong selection) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return (jlong)XGetSelectionOwner((Display*)jlong_to_ptr(display), selection);
}
@@ -1655,7 +1719,7 @@
{
jstring string = NULL;
char* name;
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(NULL);
name = (char*) XGetAtomName((Display*)jlong_to_ptr(display), atom);
if (name == NULL) {
@@ -1679,21 +1743,21 @@
JNIEXPORT jlong JNICALL
Java_sun_awt_X11_XlibWrapper_XMaxRequestSize(JNIEnv *env, jclass clazz,
jlong display) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XMaxRequestSize((Display*) jlong_to_ptr(display));
}
JNIEXPORT jlong JNICALL
Java_sun_awt_X11_XlibWrapper_XAllocWMHints(JNIEnv *env, jclass clazz)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return ptr_to_jlong(XAllocWMHints());
}
JNIEXPORT jlong JNICALL
Java_sun_awt_X11_XlibWrapper_XCreatePixmap(JNIEnv *env, jclass clazz, jlong display, jlong drawable, jint width, jint height, jint depth)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XCreatePixmap((Display*)jlong_to_ptr(display), (Drawable)drawable, width, height, depth);
}
JNIEXPORT jlong JNICALL
@@ -1702,7 +1766,7 @@
jint depth, jint format, jint offset, jlong data, jint width,
jint height, jint bitmap_pad, jint bytes_per_line)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return ptr_to_jlong(XCreateImage((Display*) jlong_to_ptr(display), (Visual*) jlong_to_ptr(visual_ptr),
depth, format, offset, (char*) jlong_to_ptr(data),
width, height, bitmap_pad, bytes_per_line));
@@ -1712,7 +1776,7 @@
(JNIEnv *env, jclass clazz, jlong display, jlong drawable,
jlong valuemask, jlong values)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return ptr_to_jlong(XCreateGC((Display*) jlong_to_ptr(display), (Drawable)drawable, valuemask, (XGCValues*) jlong_to_ptr(values)));
}
@@ -1762,7 +1826,7 @@
XIconSize** psize = (XIconSize**) jlong_to_ptr(ret_sizes);
int * pcount = (int *) jlong_to_ptr(ret_count);
Status res;
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
res = XGetIconSizes((Display*) jlong_to_ptr(display), (Window)window, psize, pcount);
return res;
}
@@ -1771,7 +1835,7 @@
(JNIEnv *env, jclass clazz, jlong display, jlong major_version_return,
jlong minor_version_return)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XdbeQueryExtension((Display*) jlong_to_ptr(display), (int *) jlong_to_ptr(major_version_return),
(int *) jlong_to_ptr(minor_version_return));
}
@@ -1784,11 +1848,12 @@
Boolean bu;
if (!JNU_IsNull(env, jstr)) {
cname = (char *)JNU_GetStringPlatformChars(env, jstr, NULL);
+ CHECK_NULL_RETURN(cname, JNI_FALSE);
} else {
cname = "";
}
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
bu = XQueryExtension((Display*) jlong_to_ptr(display), cname, (int *) jlong_to_ptr(mop_return),
(int *) jlong_to_ptr(feve_return), (int *) jlong_to_ptr(err_return));
if (!JNU_IsNull(env, jstr)) {
@@ -1800,7 +1865,7 @@
JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_IsKeypadKey
(JNIEnv *env, jclass clazz, jlong keysym)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
if(IsKeypadKey(keysym)) {
return JNI_TRUE;
}
@@ -1810,7 +1875,7 @@
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XdbeAllocateBackBufferName
(JNIEnv *env, jclass clazz, jlong display, jlong window, jint swap_action)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XdbeAllocateBackBufferName((Display*) jlong_to_ptr(display), (Window) window,
(XdbeSwapAction) swap_action);
}
@@ -1818,28 +1883,28 @@
JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeDeallocateBackBufferName
(JNIEnv *env, jclass clazz, jlong display, jlong buffer)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XdbeDeallocateBackBufferName((Display*) jlong_to_ptr(display), (XdbeBackBuffer) buffer);
}
JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeBeginIdiom
(JNIEnv *env, jclass clazz, jlong display)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XdbeBeginIdiom((Display*) jlong_to_ptr(display));
}
JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeEndIdiom
(JNIEnv *env, jclass clazz, jlong display)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XdbeEndIdiom((Display*) jlong_to_ptr(display));
}
JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeSwapBuffers
(JNIEnv *env, jclass clazz, jlong display, jlong swap_info, jint num_windows)
{
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XdbeSwapBuffers((Display*) jlong_to_ptr(display), (XdbeSwapInfo *) jlong_to_ptr(swap_info), num_windows);
}
JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XQueryKeymap
@@ -1854,7 +1919,7 @@
Java_sun_awt_X11_XlibWrapper_XKeycodeToKeysym(JNIEnv *env, jclass clazz,
jlong display, jint keycode,
jint index) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XKeycodeToKeysym((Display*) jlong_to_ptr(display), (unsigned int)keycode, (int)index);
}
@@ -1862,7 +1927,7 @@
Java_sun_awt_X11_XlibWrapper_XkbGetEffectiveGroup(JNIEnv *env, jclass clazz,
jlong display) {
XkbStateRec sr;
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
memset(&sr, 0, sizeof(XkbStateRec));
XkbGetState((Display*) jlong_to_ptr(display), XkbUseCoreKbd, &sr);
// printf("-------------------------------------VVVV\n");
@@ -1887,21 +1952,21 @@
Java_sun_awt_X11_XlibWrapper_XkbKeycodeToKeysym(JNIEnv *env, jclass clazz,
jlong display, jint keycode,
jint group, jint level) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XkbKeycodeToKeysym((Display*) jlong_to_ptr(display), (unsigned int)keycode, (unsigned int)group, (unsigned int)level);
}
JNIEXPORT jint JNICALL
Java_sun_awt_X11_XlibWrapper_XKeysymToKeycode(JNIEnv *env, jclass clazz,
jlong display, jlong keysym) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return XKeysymToKeycode((Display*) jlong_to_ptr(display), (KeySym)keysym);
}
JNIEXPORT jlong JNICALL
Java_sun_awt_X11_XlibWrapper_XGetModifierMapping(JNIEnv *env, jclass clazz,
jlong display) {
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(0);
return ptr_to_jlong(XGetModifierMapping((Display*) jlong_to_ptr(display)));
}
@@ -1958,7 +2023,7 @@
jlong display, jlong ptr) {
uint32_t timeout = 1;
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
exitSecondaryLoop = False;
while (!exitSecondaryLoop) {
if (XCheckIfEvent((Display*) jlong_to_ptr(display), (XEvent*) jlong_to_ptr(ptr), secondary_loop_event, NULL)) {
@@ -1996,7 +2061,7 @@
static jclass stringClass = NULL;
jclass stringClassLocal = NULL;
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(NULL);
if (JNU_IsNull(env, stringClass)) {
stringClassLocal = (*env)->FindClass(env, "java/lang/String");
@@ -2148,7 +2213,7 @@
{
jboolean status;
- AWT_CHECK_HAVE_LOCK();
+ AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
status = XShapeQueryExtension((Display *)jlong_to_ptr(display),
(int *)jlong_to_ptr(event_base_return), (int *)jlong_to_ptr(error_base_return));
--- a/jdk/src/solaris/native/sun/xawt/awt_Desktop.c Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/solaris/native/sun/xawt/awt_Desktop.c Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2014, 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
@@ -23,6 +23,7 @@
* questions.
*/
+#include "jni_util.h"
#include "gtk2_interface.h"
#include "gnome_interface.h"
@@ -65,6 +66,12 @@
const gchar* url_c;
url_c = (char*)(*env)->GetByteArrayElements(env, url_j, NULL);
+ if (url_c == NULL) {
+ if (!(*env)->ExceptionCheck(env)) {
+ JNU_ThrowOutOfMemoryError(env, 0);
+ }
+ return JNI_FALSE;
+ }
if (gtk_has_been_loaded) {
fp_gdk_threads_enter();
--- a/jdk/src/windows/native/sun/java2d/d3d/D3DBadHardware.h Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/windows/native/sun/java2d/d3d/D3DBadHardware.h Wed Apr 16 12:42:40 2014 -0700
@@ -53,27 +53,18 @@
// Intel HD
// Clarkdale (Desktop) GMA HD Lines
- { 0x8086, 0x0042, D_VERSION(6,14,10,5394), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x0042, D_VERSION(8,15,10,2993), OS_VISTA | OS_WINDOWS7 },
+ { 0x8086, 0x0042, NO_VERSION, OS_ALL },
// Arrandale (Mobile) GMA HD Lines
- { 0x8086, 0x0046, D_VERSION(6,14,10,5394), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x0046, D_VERSION(8,15,10,2993), OS_VISTA | OS_WINDOWS7 },
+ { 0x8086, 0x0046, NO_VERSION, OS_ALL },
// Sandy Bridge HD Graphics 3000/2000
- { 0x8086, 0x0102, D_VERSION(6,14,10,5437), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x0102, D_VERSION(9,17,10,3223), OS_VISTA | OS_WINDOWS7 },
- { 0x8086, 0x0106, D_VERSION(6,14,10,5437), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x0106, D_VERSION(9,17,10,3223), OS_VISTA | OS_WINDOWS7 },
- { 0x8086, 0x0112, D_VERSION(6,14,10,5437), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x0112, D_VERSION(9,17,10,3223), OS_VISTA | OS_WINDOWS7 },
- { 0x8086, 0x0116, D_VERSION(6,14,10,5437), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x0116, D_VERSION(9,17,10,3223), OS_VISTA | OS_WINDOWS7 },
- { 0x8086, 0x0122, D_VERSION(6,14,10,5437), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x0122, D_VERSION(9,17,10,3223), OS_VISTA | OS_WINDOWS7 },
- { 0x8086, 0x0126, D_VERSION(6,14,10,5437), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x0126, D_VERSION(9,17,10,3223), OS_VISTA | OS_WINDOWS7 },
- { 0x8086, 0x010A, D_VERSION(6,14,10,5437), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x010A, D_VERSION(9,17,10,3223), OS_VISTA | OS_WINDOWS7 },
+ { 0x8086, 0x0102, NO_VERSION, OS_ALL },
+ { 0x8086, 0x0106, NO_VERSION, OS_ALL },
+ { 0x8086, 0x0112, NO_VERSION, OS_ALL },
+ { 0x8086, 0x0116, NO_VERSION, OS_ALL },
+ { 0x8086, 0x0122, NO_VERSION, OS_ALL },
+ { 0x8086, 0x0126, NO_VERSION, OS_ALL },
+ { 0x8086, 0x010A, NO_VERSION, OS_ALL },
// Ivy Bridge
{ 0x8086, 0x0162, D_VERSION(6,14,10,5437), OS_WINXP | OS_WINXP_64 },
@@ -170,33 +161,21 @@
{ 0x8086, 0x2A13, NO_VERSION, OS_ALL },
// Eaglelake (Desktop) GMA 4500 Lines
- { 0x8086, 0x2E42, D_VERSION(6,14,10,5420), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x2E42, D_VERSION(8,15,10,2869), OS_VISTA | OS_WINDOWS7 },
- { 0x8086, 0x2E43, D_VERSION(6,14,10,5420), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x2E43, D_VERSION(8,15,10,2869), OS_VISTA | OS_WINDOWS7 },
- { 0x8086, 0x2E92, D_VERSION(6,14,10,5420), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x2E92, D_VERSION(8,15,10,2869), OS_VISTA | OS_WINDOWS7 },
- { 0x8086, 0x2E93, D_VERSION(6,14,10,5420), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x2E93, D_VERSION(8,15,10,2869), OS_VISTA | OS_WINDOWS7 },
- { 0x8086, 0x2E12, D_VERSION(6,14,10,5420), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x2E12, D_VERSION(8,15,10,2869), OS_VISTA | OS_WINDOWS7 },
- { 0x8086, 0x2E13, D_VERSION(6,14,10,5420), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x2E13, D_VERSION(8,15,10,2869), OS_VISTA | OS_WINDOWS7 },
+ { 0x8086, 0x2E42, NO_VERSION, OS_ALL },
+ { 0x8086, 0x2E43, NO_VERSION, OS_ALL },
+ { 0x8086, 0x2E92, NO_VERSION, OS_ALL },
+ { 0x8086, 0x2E93, NO_VERSION, OS_ALL },
+ { 0x8086, 0x2E12, NO_VERSION, OS_ALL },
+ { 0x8086, 0x2E13, NO_VERSION, OS_ALL },
// Eaglelake (Desktop) GMA X4500 Lines
- { 0x8086, 0x2E32, D_VERSION(6,14,10,5420), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x2E32, D_VERSION(8,15,10,2869), OS_VISTA | OS_WINDOWS7 },
- { 0x8086, 0x2E33, D_VERSION(6,14,10,5420), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x2E33, D_VERSION(8,15,10,2869), OS_VISTA | OS_WINDOWS7 },
- { 0x8086, 0x2E22, D_VERSION(6,14,10,5420), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x2E22, D_VERSION(8,15,10,2869), OS_VISTA | OS_WINDOWS7 },
+ { 0x8086, 0x2E32, NO_VERSION, OS_ALL },
+ { 0x8086, 0x2E33, NO_VERSION, OS_ALL },
+ { 0x8086, 0x2E22, NO_VERSION, OS_ALL },
// Eaglelake (Desktop) GMA X4500HD Lines
- { 0x8086, 0x2E23, D_VERSION(6,14,10,5420), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x2E23, D_VERSION(8,15,10,2869), OS_VISTA | OS_WINDOWS7 },
+ { 0x8086, 0x2E23, NO_VERSION, OS_ALL },
// Cantiga (Mobile) GMA 4500MHD Lines
- { 0x8086, 0x2A42, D_VERSION(6,14,10,5420), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x2A42, D_VERSION(8,15,10,2869), OS_VISTA | OS_WINDOWS7 },
- { 0x8086, 0x2A43, D_VERSION(6,14,10,5420), OS_WINXP | OS_WINXP_64 },
- { 0x8086, 0x2A43, D_VERSION(8,15,10,2869), OS_VISTA | OS_WINDOWS7 },
+ { 0x8086, 0x2A42, NO_VERSION, OS_ALL },
+ { 0x8086, 0x2A43, NO_VERSION, OS_ALL },
// ATI Mobility Radeon X1600, X1400, X1450, X1300, X1350
// Reason: workaround for 6613066, 6687166
--- a/jdk/src/windows/native/sun/java2d/d3d/D3DSurfaceData.cpp Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/windows/native/sun/java2d/d3d/D3DSurfaceData.cpp Wed Apr 16 12:42:40 2014 -0700
@@ -33,9 +33,16 @@
#include "awt_BitmapUtil.h"
#include "D3DRenderQueue.h"
+
// REMIND: move to awt_Component.h
extern "C" HWND AwtComponent_GetHWnd(JNIEnv *env, jlong pData);
+/* This looks weird. but since some AWT headers need to be included,
+ * we end up with AWT's alloc.h macro definition of ExceptionOccurred.
+ * The reasons for that re-defintion do not apply to this code, so undef it.
+ */
+#undef ExceptionOccurred
+
/**
* Initializes nativeWidth/Height fields of the SurfaceData object with
* dimensions on the native surface.
@@ -55,7 +62,9 @@
}
JNU_SetFieldByName(env, NULL, sdObject, "nativeWidth", "I", width);
- JNU_SetFieldByName(env, NULL, sdObject, "nativeHeight", "I", height);
+ if (!(env->ExceptionOccurred())) {
+ JNU_SetFieldByName(env, NULL, sdObject, "nativeHeight", "I", height);
+ }
env->DeleteLocalRef(sdObject);
}
--- a/jdk/src/windows/native/sun/java2d/windows/GDIWindowSurfaceData.cpp Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/windows/native/sun/java2d/windows/GDIWindowSurfaceData.cpp Wed Apr 16 12:42:40 2014 -0700
@@ -354,17 +354,26 @@
initThreadInfoIndex();
xorCompClass = (jclass)env->NewGlobalRef(XORComp);
+ if (env->ExceptionCheck()) {
+ return;
+ }
tc = env->FindClass("java/lang/Thread");
DASSERT(tc != NULL);
+ CHECK_NULL(tc);
+
threadClass = (jclass)env->NewGlobalRef(tc);
DASSERT(threadClass != NULL);
+ CHECK_NULL(threadClass);
+
currentThreadMethodID =
env->GetStaticMethodID(threadClass,
"currentThread", "()Ljava/lang/Thread;");
DASSERT(currentThreadMethodID != NULL);
}
+#undef ExceptionOccurred
+
/*
* Class: sun_java2d_windows_GDIWindowSurfaceData
* Method: initOps
@@ -394,6 +403,9 @@
wsdo->invalid = JNI_FALSE;
wsdo->lockType = WIN32SD_LOCK_UNLOCKED;
wsdo->peer = env->NewWeakGlobalRef(peer);
+ if (env->ExceptionOccurred()) {
+ return;
+ }
wsdo->depth = depth;
wsdo->pixelMasks[0] = redMask;
wsdo->pixelMasks[1] = greenMask;
@@ -997,7 +1009,7 @@
ThreadGraphicsInfo *info = GetThreadGraphicsInfo(env, wsdo);
GDIWinSD_InitDC(env, wsdo, info, type, patrop, clip, comp, color);
- return info->hDC;
+ return env->ExceptionCheck() ? (HDC)NULL : info->hDC;
}
JNIEXPORT void JNICALL
@@ -1056,8 +1068,14 @@
int topInset = wsdo->insets.top;
Region_StartIteration(env, &clipInfo);
jint numrects = Region_CountIterationRects(&clipInfo);
- RGNDATA *lpRgnData = (RGNDATA *) SAFE_SIZE_STRUCT_ALLOC(safe_Malloc,
+ RGNDATA *lpRgnData;
+ try {
+ lpRgnData = (RGNDATA *) SAFE_SIZE_STRUCT_ALLOC(safe_Malloc,
sizeof(RGNDATAHEADER), numrects, sizeof(RECT));
+ } catch (std::bad_alloc&) {
+ JNU_ThrowOutOfMemoryError(env, "Initialization of surface region data failed.");
+ return;
+ }
const DWORD nCount = sizeof(RGNDATAHEADER) + numrects * sizeof(RECT);
lpRgnData->rdh.dwSize = sizeof(RGNDATAHEADER);
lpRgnData->rdh.iType = RDH_RECTANGLES;
@@ -1086,6 +1104,9 @@
env->DeleteWeakGlobalRef(info->clip);
}
info->clip = env->NewWeakGlobalRef(clip);
+ if (env->ExceptionCheck()) {
+ return;
+ }
}
// init composite
--- a/jdk/src/windows/native/sun/windows/ThemeReader.cpp Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/windows/native/sun/windows/ThemeReader.cpp Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2014, 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
@@ -233,7 +233,7 @@
Themed = InitThemes();
TryLoadingThemeLib = TRUE;
}
- return Themed;
+ return JNI_IS_TRUE(Themed);
}
@@ -271,6 +271,10 @@
(JNIEnv *env, jclass klass, jstring widget) {
LPCTSTR str = (LPCTSTR) JNU_GetStringPlatformChars(env, widget, NULL);
+ if (str == NULL) {
+ JNU_ThrowOutOfMemoryError(env, 0);
+ return 0;
+ }
// We need to open the Theme on a Window that will stick around.
// The best one for that purpose is the Toolkit window.
HTHEME htheme = OpenThemeData(AwtToolkit::GetInstance().GetHWnd(), str);
@@ -485,6 +489,7 @@
if (insetsClassID == NULL) {
jclass insetsClassIDLocal = env->FindClass("java/awt/Insets");
+ CHECK_NULL_RETURN(insetsClassIDLocal, NULL);
insetsClassID = (jclass)env->NewGlobalRef(insetsClassIDLocal);
env->DeleteLocalRef(insetsClassIDLocal);
}
@@ -533,7 +538,7 @@
JNIEXPORT jboolean JNICALL Java_sun_awt_windows_ThemeReader_isThemePartDefined
(JNIEnv *env, jclass klass, jlong theme, jint part, jint state) {
HTHEME hTheme = (HTHEME) theme;
- return IsThemePartDefined(hTheme, part, state);
+ return JNI_IS_TRUE(IsThemePartDefined(hTheme, part, state));
}
/*
@@ -562,12 +567,14 @@
if (colorClassID == NULL) {
jclass colorClassIDLocal = env->FindClass("java/awt/Color");
+ CHECK_NULL_RETURN(colorClassIDLocal, NULL);
colorClassID = (jclass)env->NewGlobalRef(colorClassIDLocal);
env->DeleteLocalRef(colorClassIDLocal);
}
if (colorMID == NULL) {
colorMID = env->GetMethodID(colorClassID, "<init>", "(III)V");
+ CHECK_NULL_RETURN(colorMID, NULL);
}
jobject colorObj = env->NewObject(colorClassID,
colorMID, GetRValue(color), GetGValue(color),GetBValue(color));
@@ -628,7 +635,7 @@
HRESULT hres = GetThemeBool(hTheme, part, state, prop, &retVal);
assert_result(hres, env);
}
- return retVal;
+ return JNI_IS_TRUE(retVal);
}
/*
@@ -640,15 +647,11 @@
(JNIEnv *env, jclass klass, jlong theme, jint prop) {
HTHEME hTheme = (HTHEME)theme;
if (hTheme != NULL) {
- return GetThemeSysBool(hTheme, prop);
+ return JNI_IS_TRUE(GetThemeSysBool(hTheme, prop));
}
- return FALSE;
+ return JNI_FALSE;
}
-
-
-
-
/*
* Class: sun_awt_windows_ThemeReader
* Method: getPoint
@@ -673,12 +676,14 @@
if (pointClassID == NULL) {
jclass pointClassIDLocal = env->FindClass("java/awt/Point");
+ CHECK_NULL_RETURN(pointClassIDLocal, NULL);
pointClassID = (jclass)env->NewGlobalRef(pointClassIDLocal);
env->DeleteLocalRef(pointClassIDLocal);
}
if (pointMID == NULL) {
pointMID = env->GetMethodID(pointClassID, "<init>", "(II)V");
+ CHECK_NULL_RETURN(pointMID, NULL);
}
jobject pointObj = env->NewObject(pointClassID, pointMID, point.x, point.y);
@@ -720,11 +725,13 @@
static jclass dimClassID = NULL;
if (dimClassID == NULL) {
jclass dimClassIDLocal = env->FindClass("java/awt/Dimension");
+ CHECK_NULL_RETURN(dimClassIDLocal, NULL);
dimClassID = (jclass)env->NewGlobalRef(dimClassIDLocal);
env->DeleteLocalRef(dimClassIDLocal);
}
if (dimMID == NULL) {
dimMID = env->GetMethodID(dimClassID, "<init>", "(II)V");
+ CHECK_NULL_RETURN(dimMID, NULL);
}
jobject dimObj = env->NewObject(dimClassID, dimMID, point.x, point.y);
@@ -755,11 +762,13 @@
static jclass dimClassID = NULL;
if (dimClassID == NULL) {
jclass dimClassIDLocal = env->FindClass("java/awt/Dimension");
+ CHECK_NULL_RETURN(dimClassIDLocal, NULL);
dimClassID = (jclass)env->NewGlobalRef(dimClassIDLocal);
env->DeleteLocalRef(dimClassIDLocal);
}
if (dimMID == NULL) {
dimMID = env->GetMethodID(dimClassID, "<init>", "(II)V");
+ CHECK_NULL_RETURN(dimMID, NULL);
}
jobject dimObj = env->NewObject(dimClassID, dimMID, size.cx, size.cy);
if (safe_ExceptionOccurred(env)) {
--- a/jdk/src/windows/native/sun/windows/WPrinterJob.cpp Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/windows/native/sun/windows/WPrinterJob.cpp Wed Apr 16 12:42:40 2014 -0700
@@ -130,6 +130,9 @@
jstring utf_str;
jclass clazz = env->FindClass("java/lang/String");
+ if (clazz == NULL) {
+ return NULL;
+ }
jobjectArray nameArray;
try {
@@ -240,6 +243,9 @@
LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
printer, NULL);
+ if (printerName == NULL) {
+ return NULL;
+ }
jfloatArray printableArray = NULL;
@@ -262,7 +268,7 @@
if (pDevMode != NULL) {
::GlobalFree(pDevMode);
}
-
+ DeleteDC(pdc);
::ClosePrinter(hPrinter);
JNU_ReleaseStringPlatformChars(env, printer, printerName);
return printableArray;
@@ -283,25 +289,21 @@
int resy = GetDeviceCaps(pdc, LOGPIXELSY);
printableArray=env->NewFloatArray(4);
- if (printableArray == NULL) {
- throw std::bad_alloc();
+ if (printableArray != NULL) {
+ jfloat *iPrintables =
+ env->GetFloatArrayElements(printableArray, NULL);
+ if (iPrintables != NULL) {
+ iPrintables[0] = (float)left/resx;
+ iPrintables[1] = (float)top/resy;
+ iPrintables[2] = (float)width/resx;
+ iPrintables[3] = (float)height/resy;
+ env->ReleaseFloatArrayElements(printableArray, iPrintables, 0);
+ }
}
- jboolean isCopy;
- jfloat *iPrintables = env->GetFloatArrayElements(printableArray,
- &isCopy),
- *savePrintables = iPrintables;
-
- iPrintables[0] = (float)left/resx;
- iPrintables[1] = (float)top/resy;
- iPrintables[2] = (float)width/resx;
- iPrintables[3] = (float)height/resy;
-
- env->ReleaseFloatArrayElements(printableArray, savePrintables, 0);
-
GlobalFree(pDevMode);
+ DeleteDC(pdc);
}
- DeleteDC(pdc);
JNU_ReleaseStringPlatformChars(env, printer, printerName);
return printableArray;
@@ -309,6 +311,60 @@
CATCH_BAD_ALLOC_RET(NULL);
}
+jintArray getIDs(JNIEnv *env, jstring printer, jstring port, int dm_id)
+{
+
+ LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
+ LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
+
+ if (printerName == NULL || printerPort == NULL) {
+ if (printerName != NULL) {
+ JNU_ReleaseStringPlatformChars(env, printer, printerName);
+ }
+ if (printerPort != NULL) {
+ JNU_ReleaseStringPlatformChars(env, port, printerPort);
+ }
+ return NULL;
+ }
+
+ SAVE_CONTROLWORD
+ int numIDs = ::DeviceCapabilities(printerName, printerPort, dm_id,
+ NULL, NULL);
+ RESTORE_CONTROLWORD
+
+ jintArray idArray = NULL;
+ if (numIDs > 0) {
+ idArray = env->NewIntArray(numIDs);
+ if (idArray != NULL) {
+ jint *jpcIndices = env->GetIntArrayElements(idArray, NULL);
+ if (jpcIndices != NULL) {
+ jint *saveFormats = jpcIndices;
+ LPTSTR buf = NULL;
+ try {
+ buf = (LPTSTR)new char[numIDs * sizeof(WORD)];
+ } catch (std::bad_alloc&) {
+ buf = NULL;
+ }
+ if (buf != NULL) {
+ if (::DeviceCapabilities(printerName, printerPort,
+ dm_id, buf, NULL) != -1) {
+ WORD *id = (WORD *)buf;
+ for (int i = 0; i < numIDs; i++, id++) {
+ jpcIndices[i] = *id;
+ }
+ }
+ RESTORE_CONTROLWORD
+ delete[] buf;
+ }
+ env->ReleaseIntArrayElements(idArray, saveFormats, 0);
+ }
+ }
+ }
+
+ JNU_ReleaseStringPlatformChars(env, printer, printerName);
+ JNU_ReleaseStringPlatformChars(env, port, printerPort);
+ return idArray;
+}
JNIEXPORT jintArray JNICALL
Java_sun_print_Win32PrintService_getAllMediaIDs(JNIEnv *env,
@@ -316,45 +372,7 @@
jstring printer,
jstring port)
{
- TRY;
-
- LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
- LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
- jintArray mediasizeArray = NULL;
-
- SAVE_CONTROLWORD
- int numSizes = ::DeviceCapabilities(printerName, printerPort,
- DC_PAPERS, NULL, NULL);
- RESTORE_CONTROLWORD
-
- if (numSizes > 0) {
-
- mediasizeArray = env->NewIntArray(numSizes);
- if (mediasizeArray == NULL) {
- throw std::bad_alloc();
- }
-
- jboolean isCopy;
- jint *jpcIndices = env->GetIntArrayElements(mediasizeArray,
- &isCopy), *saveFormats = jpcIndices;
- LPTSTR papersBuf = (LPTSTR)new char[numSizes * sizeof(WORD)];
- if (::DeviceCapabilities(printerName, printerPort,
- DC_PAPERS, papersBuf, NULL) != -1) {
- RESTORE_CONTROLWORD
- WORD *pDmPaperSize = (WORD *)papersBuf;
- for (int i = 0; i < numSizes; i++, pDmPaperSize++) {
- jpcIndices[i] = *pDmPaperSize;
- }
- }
- delete[] papersBuf;
- env->ReleaseIntArrayElements(mediasizeArray, saveFormats, 0);
- }
-
- JNU_ReleaseStringPlatformChars(env, printer, printerName);
- JNU_ReleaseStringPlatformChars(env, port, printerPort);
- return mediasizeArray;
-
- CATCH_BAD_ALLOC_RET(NULL);
+ return getIDs(env, printer, port, DC_PAPERS);
}
@@ -364,47 +382,7 @@
jstring printer,
jstring port)
{
- TRY;
-
- LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
- printer, NULL);
- LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
-
- jintArray mediaTrayArray = NULL;
-
- SAVE_CONTROLWORD
- int nBins = ::DeviceCapabilities(printerName, printerPort,
- DC_BINS, NULL, NULL) ;
- RESTORE_CONTROLWORD
- if (nBins > 0) {
- mediaTrayArray = env->NewIntArray(nBins);
- if (mediaTrayArray == NULL) {
- throw std::bad_alloc();
- }
-
- jboolean isCopy;
- jint *jpcIndices = env->GetIntArrayElements(mediaTrayArray,
- &isCopy), *saveFormats = jpcIndices;
-
- LPTSTR buf = (LPTSTR)new char[nBins * sizeof(WORD)];
-
- if (::DeviceCapabilities(printerName, printerPort,
- DC_BINS, buf, NULL) != -1) {
- RESTORE_CONTROLWORD
- WORD *pBins = (WORD *)buf;
- for (int i = 0; i < nBins; i++) {
- jpcIndices[i] = *(pBins+i);
- }
- }
- delete[] buf;
- env->ReleaseIntArrayElements(mediaTrayArray, saveFormats, 0);
- }
-
- JNU_ReleaseStringPlatformChars(env, printer, printerName);
- JNU_ReleaseStringPlatformChars(env, port, printerPort);
- return mediaTrayArray;
-
- CATCH_BAD_ALLOC_RET(NULL);
+ return getIDs(env, printer, port, DC_BINS);
}
@@ -414,100 +392,139 @@
jstring printer,
jstring port)
{
- TRY;
-
- LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
- printer, NULL);
+ LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
- jintArray mediaArray = NULL;
+ if (printerName == NULL || printerPort == NULL) {
+ if (printerName != NULL) {
+ JNU_ReleaseStringPlatformChars(env, printer, printerName);
+ }
+ if (printerPort != NULL) {
+ JNU_ReleaseStringPlatformChars(env, port, printerPort);
+ }
+ return NULL;
+ }
SAVE_CONTROLWORD
- int nPapers = ::DeviceCapabilities(printerName, printerPort,
- DC_PAPERSIZE, NULL, NULL) ;
+ int nPapers = ::DeviceCapabilities(printerName, printerPort, DC_PAPERSIZE,
+ NULL, NULL) ;
RESTORE_CONTROLWORD
- if (nPapers > 0) {
- mediaArray = env->NewIntArray(nPapers*2);
- if (mediaArray == NULL) {
- throw std::bad_alloc();
- }
- jboolean isCopy;
- jint *jpcIndices = env->GetIntArrayElements(mediaArray,
- &isCopy), *saveFormats = jpcIndices;
+ jintArray mediaArray = NULL;
+ jint *saveFormats = NULL;
- LPTSTR buf = (LPTSTR)new char[nPapers * sizeof(POINT)]; // array of POINTs
-
- if (::DeviceCapabilities(printerName, printerPort,
- DC_PAPERSIZE, buf, NULL) != -1) {
-
- POINT *pDim = (POINT *)buf;
- for (int i = 0; i < nPapers; i++) {
- jpcIndices[i*2] = (pDim+i)->x;
- jpcIndices[i*2+1] = (pDim+i)->y;
+ if (nPapers > 0) {
+ mediaArray = env->NewIntArray(nPapers*2);
+ if (mediaArray != NULL) {
+ jint *jpcIndices = env->GetIntArrayElements(mediaArray, NULL);
+ if (jpcIndices != NULL) {
+ saveFormats = jpcIndices;
+ LPTSTR buf = NULL;
+ try {
+ buf = (LPTSTR)new char[nPapers * sizeof(POINT)];
+ } catch (std::bad_alloc&) {
+ buf = NULL;
+ }
+ if (buf != NULL) {
+ if (::DeviceCapabilities(printerName, printerPort,
+ DC_PAPERSIZE, buf, NULL) != -1) {
+ POINT *pDim = (POINT *)buf;
+ for (int i = 0; i < nPapers; i++) {
+ jpcIndices[i*2] = (pDim+i)->x;
+ jpcIndices[i*2+1] = (pDim+i)->y;
+ }
+ }
+ RESTORE_CONTROLWORD
+ delete[] buf;
+ }
+ env->ReleaseIntArrayElements(mediaArray, saveFormats, 0);
+ saveFormats = NULL;
+ }
}
- }
- RESTORE_CONTROLWORD
- delete[] buf;
- env->ReleaseIntArrayElements(mediaArray, saveFormats, 0);
}
JNU_ReleaseStringPlatformChars(env, printer, printerName);
JNU_ReleaseStringPlatformChars(env, port, printerPort);
+ if (mediaArray != NULL && saveFormats != NULL) {
+ env->ReleaseIntArrayElements(mediaArray, saveFormats, 0);
+ }
return mediaArray;
- CATCH_BAD_ALLOC_RET(NULL);
}
jobjectArray getAllDCNames(JNIEnv *env, jobject peer, jstring printer,
jstring port, unsigned int dc_id, unsigned int buf_len)
{
- TRY;
- LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
- printer, NULL);
+ LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
+ if (printerName == NULL || printerPort == NULL) {
+ if (printerName != NULL) {
+ JNU_ReleaseStringPlatformChars(env, printer, printerName);
+ }
+ if (printerPort != NULL) {
+ JNU_ReleaseStringPlatformChars(env, port, printerPort);
+ }
+ return NULL;
+ }
+
jstring utf_str;
- jclass cls = env->FindClass("java/lang/String");
- jobjectArray names= NULL;
+ jobjectArray names = NULL;
LPTSTR buf = NULL;
SAVE_CONTROLWORD
int cReturned = ::DeviceCapabilities(printerName, printerPort,
dc_id, NULL, NULL);
RESTORE_CONTROLWORD
- if (cReturned > 0) {
-
- buf = (LPTSTR)new char[cReturned * buf_len * sizeof(TCHAR)];
- if (buf == NULL) {
- throw std::bad_alloc();
- }
+ if (cReturned <= 0) {
+ JNU_ReleaseStringPlatformChars(env, printer, printerName);
+ JNU_ReleaseStringPlatformChars(env, port, printerPort);
+ return NULL;
+ }
- cReturned = ::DeviceCapabilities(printerName, printerPort,
- dc_id, buf, NULL);
- RESTORE_CONTROLWORD
+ try {
+ buf = (LPTSTR)new char[cReturned * buf_len * sizeof(TCHAR)];
+ } catch (std::bad_alloc&) {
+ buf = NULL;
+ }
+ if (buf == NULL) {
+ JNU_ReleaseStringPlatformChars(env, printer, printerName);
+ JNU_ReleaseStringPlatformChars(env, port, printerPort);
+ JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
+ return NULL;
+ }
- if (cReturned > 0) {
- names = env->NewObjectArray(cReturned, cls, NULL);
- if (names == NULL) {
- throw std::bad_alloc();
+ cReturned = ::DeviceCapabilities(printerName, printerPort,
+ dc_id, buf, NULL);
+ RESTORE_CONTROLWORD
+
+ JNU_ReleaseStringPlatformChars(env, printer, printerName);
+ JNU_ReleaseStringPlatformChars(env, port, printerPort);
+
+ if (cReturned > 0) {
+ jclass cls = env->FindClass("java/lang/String");
+ if (cls != NULL) {
+ names = env->NewObjectArray(cReturned, cls, NULL);
+ }
+ if (names == NULL || cls == NULL) {
+ delete buf;
+ return names;
}
for (int i = 0; i < cReturned; i++) {
- utf_str = JNU_NewStringPlatform(env, buf+(buf_len*i));
- if (utf_str == NULL) {
- throw std::bad_alloc();
+ utf_str = JNU_NewStringPlatform(env, buf+(buf_len*i));
+ if (utf_str == NULL) {
+ delete buf;
+ return names;
+ }
+ env->SetObjectArrayElement(names, i, utf_str);
+ env->DeleteLocalRef(utf_str);
}
- env->SetObjectArrayElement(names, i, utf_str);
- env->DeleteLocalRef(utf_str);
- }
}
delete[] buf;
- }
- return names;
+ return names;
- CATCH_BAD_ALLOC_RET(NULL);
}
@@ -540,6 +557,16 @@
LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
+ if (printerName == NULL || printerPort == NULL) {
+ if (printerName != NULL) {
+ JNU_ReleaseStringPlatformChars(env, printer, printerName);
+ }
+ if (printerPort != NULL) {
+ JNU_ReleaseStringPlatformChars(env, port, printerPort);
+ }
+ return 1;
+ }
+
SAVE_CONTROLWORD
int numCopies = ::DeviceCapabilities(printerName, printerPort,
DC_COPIES, NULL, NULL);
@@ -573,48 +600,58 @@
jstring printer,
jstring port)
{
- TRY;
-
LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
- jintArray resolutionArray = NULL;
+ if (printerName == NULL || printerPort == NULL) {
+ if (printerName != NULL) {
+ JNU_ReleaseStringPlatformChars(env, printer, printerName);
+ }
+ if (printerPort != NULL) {
+ JNU_ReleaseStringPlatformChars(env, port, printerPort);
+ }
+ return NULL;
+ }
SAVE_CONTROLWORD
int nResolutions = ::DeviceCapabilities(printerName, printerPort,
DC_ENUMRESOLUTIONS, NULL, NULL);
RESTORE_CONTROLWORD
+
+ jintArray resolutionArray = NULL;
if (nResolutions > 0) {
resolutionArray = env->NewIntArray(nResolutions*2);
- if (resolutionArray == NULL) {
- throw std::bad_alloc();
+ if (resolutionArray != NULL) {
+ jint *jpcIndices = env->GetIntArrayElements(resolutionArray, NULL);
+ if (jpcIndices != NULL) {
+ jint *saveFormats = jpcIndices;
+ LPTSTR resBuf = NULL;
+ try {
+ resBuf = (LPTSTR)new char[nResolutions * sizeof(LONG) * 2];
+ } catch (std::bad_alloc&) {
+ resBuf = NULL;
+ }
+ if (resBuf != NULL) {
+ if (::DeviceCapabilities(printerName, printerPort,
+ DC_ENUMRESOLUTIONS, resBuf,
+ NULL) != -1) {
+ LONG *pResolution = (LONG *)resBuf;
+ for (int i = 0; i < nResolutions; i++) {
+ jpcIndices[i*2] = *pResolution++;
+ jpcIndices[i*2+1] = *pResolution++;
+ }
+ }
+ RESTORE_CONTROLWORD
+ delete[] resBuf;
+ }
+ env->ReleaseIntArrayElements(resolutionArray, saveFormats, 0);
+ }
}
-
- jboolean isCopy;
- jint *jpcIndices = env->GetIntArrayElements(resolutionArray,
- &isCopy), *saveFormats = jpcIndices;
-
- LPTSTR resBuf = (LPTSTR)new char[nResolutions * sizeof(LONG) * 2]; // pairs of long
-
- if (::DeviceCapabilities(printerName, printerPort,
- DC_ENUMRESOLUTIONS, resBuf, NULL) != -1) {
-
- LONG *pResolution = (LONG *)resBuf;
- for (int i = 0; i < nResolutions; i++) {
- jpcIndices[i*2] = *pResolution++;
- jpcIndices[i*2+1] = *pResolution++;
- }
- }
- RESTORE_CONTROLWORD
- delete[] resBuf;
- env->ReleaseIntArrayElements(resolutionArray, saveFormats, 0);
}
JNU_ReleaseStringPlatformChars(env, printer, printerName);
JNU_ReleaseStringPlatformChars(env, printer, printerPort);
return resolutionArray;
-
- CATCH_BAD_ALLOC_RET(NULL);
}
@@ -672,6 +709,7 @@
} catch (std::bad_alloc&) {
delete [] buffer;
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
+ return NULL;
}
if (printerPort == NULL) {
@@ -692,6 +730,17 @@
{
LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
+
+ if (printerName == NULL || printerPort == NULL) {
+ if (printerName != NULL) {
+ JNU_ReleaseStringPlatformChars(env, printer, printerName);
+ }
+ if (printerPort != NULL) {
+ JNU_ReleaseStringPlatformChars(env, port, printerPort);
+ }
+ return NULL;
+ }
+
// 0x1000 is a flag to indicate that getCapabilities has already been called.
// 0x0001 is a flag for color support and supported is the default.
jint ret = 0x1001;
@@ -761,28 +810,41 @@
HANDLE hPrinter;
LPDEVMODE pDevMode = NULL;
- TRY;
-
LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
- jintArray defaultArray = env->NewIntArray(NDEFAULT);
- if (defaultArray == NULL) {
- throw std::bad_alloc();
+ if (printerName == NULL || printerPort == NULL) {
+ if (printerName != NULL) {
+ JNU_ReleaseStringPlatformChars(env, printer, printerName);
+ }
+ if (printerPort != NULL) {
+ JNU_ReleaseStringPlatformChars(env, port, printerPort);
+ }
+ return NULL;
}
- jboolean isCopy;
- jint *defIndices = env->GetIntArrayElements(defaultArray,
- &isCopy), *saveFormats = defIndices;
+ jint* defIndices = NULL;
+ jintArray defaultArray = env->NewIntArray(NDEFAULT);
+ if (defaultArray != NULL) {
+ defIndices = env->GetIntArrayElements(defaultArray, NULL);
+ }
+ if (defIndices == NULL) {
+ JNU_ReleaseStringPlatformChars(env, printer, printerName);
+ JNU_ReleaseStringPlatformChars(env, port, printerPort);
+ return NULL;
+ }
- for (int i=0; i<NDEFAULT; i++) {
- defIndices[i]=GETDEFAULT_ERROR;
+ jint *saveFormats = defIndices;
+
+ for (int i=0; i < NDEFAULT; i++) {
+ defIndices[i] = GETDEFAULT_ERROR;
}
/* Start by opening the printer */
if (!::OpenPrinter(printerName, &hPrinter, NULL)) {
env->ReleaseIntArrayElements(defaultArray, saveFormats, 0);
JNU_ReleaseStringPlatformChars(env, printer, printerName);
+ JNU_ReleaseStringPlatformChars(env, port, printerPort);
return defaultArray;
}
@@ -794,6 +856,7 @@
::ClosePrinter(hPrinter);
env->ReleaseIntArrayElements(defaultArray, saveFormats, 0);
JNU_ReleaseStringPlatformChars(env, printer, printerName);
+ JNU_ReleaseStringPlatformChars(env, port, printerPort);
return defaultArray;
}
@@ -863,7 +926,6 @@
defIndices[8] = pDevMode->dmColor;
}
-
GlobalFree(pDevMode);
::ClosePrinter(hPrinter);
@@ -873,8 +935,6 @@
JNU_ReleaseStringPlatformChars(env, port, printerPort);
return defaultArray;
-
- CATCH_BAD_ALLOC_RET(NULL);
}
@@ -891,6 +951,9 @@
int ret=0;
LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
+ if (printerName == NULL) {
+ return -1;
+ }
// Start by opening the printer
if (!::OpenPrinter(printerName, &hPrinter, NULL)) {
@@ -959,13 +1022,15 @@
jclass myClass = env->GetObjectClass(self);
jfieldID fieldId = env->GetFieldID(myClass, fieldName, "J");
DASSERT(fieldId != 0);
-
return fieldId;
}
static inline HANDLE getHPrinter(JNIEnv *env, jobject self) {
jfieldID fieldId = getIdOfLongField(env, self, HPRINTER_STR);
+ if (fieldId == (jfieldID)0) {
+ return (HANDLE)NULL;
+ }
return (HANDLE)(env->GetLongField(self, fieldId));
}
@@ -979,6 +1044,9 @@
HANDLE hPrinter;
DOC_INFO_1 DocInfo;
LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
+ if (printerName == NULL) {
+ return false;
+ }
DASSERT(jobname != NULL);
LPTSTR lpJobName = (LPTSTR)JNU_GetStringPlatformChars(env, jobname, NULL);
LPTSTR jname = _tcsdup(lpJobName);
@@ -1016,8 +1084,12 @@
// store handle
jfieldID fieldId = getIdOfLongField(env, peer, HPRINTER_STR);
- env->SetLongField(peer, fieldId, reinterpret_cast<jlong>(hPrinter));
- return true;
+ if (fieldId == (jfieldID)0) {
+ return false;
+ } else {
+ env->SetLongField(peer, fieldId, reinterpret_cast<jlong>(hPrinter));
+ return true;
+ }
}
@@ -1039,6 +1111,9 @@
try {
data=(jbyte *)env->GetPrimitiveArrayCritical(dataArray, 0);
+ if (data == NULL) {
+ return false;
+ }
// Send the data to the printer.
if( ! ::WritePrinter(hPrinter, data, count,(LPDWORD)&dwBytesWritten)) {
--- a/jdk/src/windows/native/sun/windows/awt.h Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/windows/native/sun/windows/awt.h Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2014, 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
@@ -47,6 +47,8 @@
class AwtObject;
typedef AwtObject* PDATA;
+#define JNI_IS_TRUE(obj) ((obj) ? JNI_TRUE : JNI_FALSE)
+
#define JNI_CHECK_NULL_GOTO(obj, msg, where) { \
if (obj == NULL) { \
env->ExceptionClear(); \
--- a/jdk/src/windows/native/sun/windows/awt_Choice.cpp Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/windows/native/sun/windows/awt_Choice.cpp Wed Apr 16 12:42:40 2014 -0700
@@ -157,6 +157,7 @@
"preferredSize",
"()Ljava/awt/Dimension;").l;
DASSERT(!safe_ExceptionOccurred(env));
+ if (env->ExceptionCheck()) goto done;
if (dimension != NULL && width == 0) {
width = env->GetIntField(dimension, AwtDimension::widthID);
@@ -337,9 +338,8 @@
"preferredSize",
"()Ljava/awt/Dimension;").l;
DASSERT(!safe_ExceptionOccurred(env));
- if (dimension == NULL) {
- return NULL;
- }
+ CHECK_NULL_RETURN(dimension, NULL);
+
/* This size is window size of choice and it's too big for each
* drop down item height.
*/
@@ -605,7 +605,8 @@
for (i = 0; i < itemCount; i++)
{
jstring item = (jstring)env->GetObjectArrayElement(items, i);
- JNI_CHECK_NULL_GOTO(item, "null item", next_elem);
+ if (env->ExceptionCheck()) goto done;
+ if (item == NULL) goto next_elem;
c->SendMessage(CB_INSERTSTRING, index + i, JavaStringBuffer(env, item));
env->DeleteLocalRef(item);
next_elem:
--- a/jdk/src/windows/native/sun/windows/awt_Component.cpp Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/windows/native/sun/windows/awt_Component.cpp Wed Apr 16 12:42:40 2014 -0700
@@ -1729,9 +1729,11 @@
case WM_IME_SETCONTEXT:
// lParam is passed as pointer and it can be modified.
mr = WmImeSetContext(static_cast<BOOL>(wParam), &lParam);
+ CallProxyDefWindowProc(message, wParam, lParam, retValue, mr);
break;
case WM_IME_NOTIFY:
mr = WmImeNotify(wParam, lParam);
+ CallProxyDefWindowProc(message, wParam, lParam, retValue, mr);
break;
case WM_IME_STARTCOMPOSITION:
mr = WmImeStartComposition();
@@ -4085,7 +4087,7 @@
{
if (mr != mrConsume) {
HWND proxy = GetProxyFocusOwner();
- if (proxy != NULL) {
+ if (proxy != NULL && ::IsWindowEnabled(proxy)) {
retVal = ComCtl32Util::GetInstance().DefWindowProc(NULL, proxy, message, wParam, lParam);
mr = mrConsume;
}
@@ -6112,7 +6114,7 @@
c = (AwtComponent *)pData;
if (::IsWindow(c->GetHWnd()))
{
- result = (jboolean)c->InheritsNativeMouseWheelBehavior();
+ result = JNI_IS_TRUE(c->InheritsNativeMouseWheelBehavior());
}
ret:
env->DeleteGlobalRef(self);
@@ -6928,9 +6930,9 @@
{
TRY;
- return (jboolean)AwtToolkit::GetInstance().SyncCall(
+ return JNI_IS_TRUE(AwtToolkit::GetInstance().SyncCall(
(void *(*)(void *))AwtComponent::_NativeHandlesWheelScrolling,
- env->NewGlobalRef(self));
+ env->NewGlobalRef(self)));
// global ref is deleted in _NativeHandlesWheelScrolling
CATCH_BAD_ALLOC_RET(NULL);
@@ -6949,9 +6951,9 @@
jobject selfGlobalRef = env->NewGlobalRef(self);
- return (jboolean)AwtToolkit::GetInstance().SyncCall(
+ return JNI_IS_TRUE(AwtToolkit::GetInstance().SyncCall(
(void*(*)(void*))AwtComponent::_IsObscured,
- (void *)selfGlobalRef);
+ (void *)selfGlobalRef));
// selfGlobalRef is deleted in _IsObscured
CATCH_BAD_ALLOC_RET(NULL);
--- a/jdk/src/windows/native/sun/windows/awt_Font.cpp Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/windows/native/sun/windows/awt_Font.cpp Wed Apr 16 12:42:40 2014 -0700
@@ -49,9 +49,12 @@
if (obj == NULL) {
return JNI_FALSE;
}
- if (env->EnsureLocalCapacity(2))
+ if (env->EnsureLocalCapacity(2)) {
+ env->ExceptionClear();
return JNI_FALSE;
+ }
jobject peer = env->CallObjectMethod(obj, AwtFont::peerMID);
+ env->ExceptionClear();
if (peer == NULL) {
return JNI_FALSE;
}
@@ -66,10 +69,12 @@
{
DASSERT(font != NULL);
if (env->EnsureLocalCapacity(2)) {
+ env->ExceptionClear();
return NULL;
}
jobject peer = env->CallObjectMethod(font, AwtFont::peerMID);
DASSERT(peer != NULL);
+ if (peer == NULL) return NULL;
jstring textComponentFontName =
(jstring) env->GetObjectField(peer, AwtFont::textComponentFontNameID);
env->DeleteLocalRef(peer);
@@ -191,6 +196,9 @@
}
awtFont = Create(env, font, angle, awScale);
+ if (awtFont == NULL) {
+ return NULL;
+ }
env->SetLongField(font, AwtFont::pDataID,
reinterpret_cast<jlong>(awtFont));
@@ -272,6 +280,9 @@
if (cfnum > 0) {
// Ask peer class for the text component font name
jstring jTextComponentFontName = GetTextComponentFontName(env, font);
+ if (jTextComponentFontName == NULL) {
+ return NULL;
+ }
LPCWSTR textComponentFontName = JNU_GetStringPlatformChars(env, jTextComponentFontName, NULL);
awtFont->m_textInput = -1;
@@ -285,6 +296,9 @@
AwtFont::nativeNameID);
wName = JNU_GetStringPlatformChars(env, nativeName, NULL);
DASSERT(wName);
+ if (wName == NULL) {
+ wName = L"Arial";
+ }
//On NT platforms, if the font is not Symbol or Dingbats
//use "W" version of Win32 APIs directly, info the FontDescription
@@ -321,7 +335,12 @@
// Instantiation for English version.
jstring fontName = (jstring)env->GetObjectField(font,
AwtFont::nameID);
- wName = JNU_GetStringPlatformChars(env, fontName, NULL);
+ if (fontName != NULL) {
+ wName = JNU_GetStringPlatformChars(env, fontName, NULL);
+ }
+ if (wName == NULL) {
+ wName = L"Arial";
+ }
WCHAR* wEName;
if (!wcscmp(wName, L"Helvetica") || !wcscmp(wName, L"SansSerif")) {
@@ -647,6 +666,9 @@
//"useUnicode" field might not be initialized correctly (font in Menu Component,
//for example").
AwtFont* awtFont = AwtFont::GetFont(env, font);
+ if (awtFont == NULL) {
+ return size;
+ }
if (IsMultiFont(env, font)) {
jobject peer = env->CallObjectMethod(font, AwtFont::peerMID);
@@ -668,6 +690,9 @@
if (arrayLength == 0) {
int length = env->GetStringLength(str);
LPCWSTR strW = JNU_GetStringPlatformChars(env, str, NULL);
+ if (strW == NULL) {
+ return size;
+ }
VERIFY(::SelectObject(hDC, awtFont->GetHFont()));
if (AwtComponent::GetRTLReadingOrder()){
VERIFY(!draw || ::ExtTextOut(hDC, x, y, ETO_RTLREADING, NULL,
@@ -692,6 +717,9 @@
}
int fdIndex = getFontDescriptorNumber(env, font, fontDescriptor);
+ if (env->ExceptionCheck()) {
+ return size; //fdIndex==0 return could be exception or not.
+ }
VERIFY(::SelectObject(hDC, awtFont->GetHFont(fdIndex)));
/*
@@ -705,10 +733,14 @@
* extend buflen and bad things will happen.
*/
unsigned char* buffer = NULL;
- jboolean unicodeUsed = env->GetBooleanField(fontDescriptor, AwtFont::useUnicodeID);
+ jboolean unicodeUsed =
+ env->GetBooleanField(fontDescriptor, AwtFont::useUnicodeID);
try {
buffer = (unsigned char *)
env->GetPrimitiveArrayCritical(convertedBytes, 0);
+ if (buffer == NULL) {
+ return size;
+ }
int buflen = (buffer[0] << 24) | (buffer[1] << 16) |
(buffer[2] << 8) | buffer[3];
@@ -816,8 +848,11 @@
jchar *strp = new jchar[len];
env->GetCharArrayRegion(str, off, len, strp);
jstring jstr = env->NewString(strp, len);
- jint result = Java_sun_awt_windows_WFontMetrics_stringWidth(env, self,
- jstr);
+ jint result = 0;
+ if (jstr != NULL) {
+ result = Java_sun_awt_windows_WFontMetrics_stringWidth(env, self,
+ jstr);
+ }
delete [] strp;
return result;
@@ -850,13 +885,25 @@
try {
jintArray array = (jintArray)env->GetObjectField(self,
AwtFont::widthsID);
+ if (array == NULL) {
+ JNU_ThrowNullPointerException(env, "Can't access widths array.");
+ return NULL;
+ }
pStrBody = (char *)env->GetPrimitiveArrayCritical(str, 0);
+ if (pStrBody == NULL) {
+ JNU_ThrowNullPointerException(env, "Can't access str bytes.");
+ return NULL;
+ }
char *pStr = pStrBody + off;
jint *widths = NULL;
try {
widths = (jint *)env->GetPrimitiveArrayCritical(array, 0);
-
+ if (widths == NULL) {
+ env->ReleasePrimitiveArrayCritical(str, pStrBody, 0);
+ JNU_ThrowNullPointerException(env, "Can't access widths.");
+ return NULL;
+ }
for (; len; len--) {
result += widths[*pStr++];
}
@@ -915,29 +962,15 @@
JNIEXPORT void JNICALL
Java_sun_awt_windows_WFontMetrics_initIDs(JNIEnv *env, jclass cls)
{
- TRY;
-
- AwtFont::widthsID = env->GetFieldID(cls, "widths", "[I");
- AwtFont::ascentID = env->GetFieldID(cls, "ascent", "I");
- AwtFont::descentID = env->GetFieldID(cls, "descent", "I");
- AwtFont::leadingID = env->GetFieldID(cls, "leading", "I");
- AwtFont::heightID = env->GetFieldID(cls, "height", "I");
- AwtFont::maxAscentID = env->GetFieldID(cls, "maxAscent", "I");
- AwtFont::maxDescentID = env->GetFieldID(cls, "maxDescent", "I");
- AwtFont::maxHeightID = env->GetFieldID(cls, "maxHeight", "I");
- AwtFont::maxAdvanceID = env->GetFieldID(cls, "maxAdvance", "I");
-
- DASSERT(AwtFont::widthsID != NULL);
- DASSERT(AwtFont::ascentID != NULL);
- DASSERT(AwtFont::descentID != NULL);
- DASSERT(AwtFont::leadingID != NULL);
- DASSERT(AwtFont::heightID != NULL);
- DASSERT(AwtFont::maxAscentID != NULL);
- DASSERT(AwtFont::maxDescentID != NULL);
- DASSERT(AwtFont::maxHeightID != NULL);
- DASSERT(AwtFont::maxAdvanceID != NULL);
-
- CATCH_BAD_ALLOC;
+ CHECK_NULL(AwtFont::widthsID = env->GetFieldID(cls, "widths", "[I"));
+ CHECK_NULL(AwtFont::ascentID = env->GetFieldID(cls, "ascent", "I"));
+ CHECK_NULL(AwtFont::descentID = env->GetFieldID(cls, "descent", "I"));
+ CHECK_NULL(AwtFont::leadingID = env->GetFieldID(cls, "leading", "I"));
+ CHECK_NULL(AwtFont::heightID = env->GetFieldID(cls, "height", "I"));
+ CHECK_NULL(AwtFont::maxAscentID = env->GetFieldID(cls, "maxAscent", "I"));
+ CHECK_NULL(AwtFont::maxDescentID = env->GetFieldID(cls, "maxDescent", "I"));
+ CHECK_NULL(AwtFont::maxHeightID = env->GetFieldID(cls, "maxHeight", "I"));
+ AwtFont::maxAdvanceID = env->GetFieldID(cls, "maxAdvance", "I");
}
} /* extern "C" */
@@ -952,28 +985,16 @@
JNIEXPORT void JNICALL
Java_java_awt_Font_initIDs(JNIEnv *env, jclass cls)
{
- TRY;
-
- AwtFont::peerMID = env->GetMethodID(cls, "getPeer",
- "()Ljava/awt/peer/FontPeer;");
- AwtFont::pDataID = env->GetFieldID(cls, "pData", "J");
- AwtFont::nameID = env->GetFieldID(cls, "name", "Ljava/lang/String;");
- AwtFont::sizeID = env->GetFieldID(cls, "size", "I");
- AwtFont::styleID = env->GetFieldID(cls, "style", "I");
-
+ CHECK_NULL(AwtFont::peerMID = env->GetMethodID(cls, "getPeer",
+ "()Ljava/awt/peer/FontPeer;"));
+ CHECK_NULL(AwtFont::pDataID = env->GetFieldID(cls, "pData", "J"));
+ CHECK_NULL(AwtFont::nameID =
+ env->GetFieldID(cls, "name", "Ljava/lang/String;"));
+ CHECK_NULL(AwtFont::sizeID = env->GetFieldID(cls, "size", "I"));
+ CHECK_NULL(AwtFont::styleID = env->GetFieldID(cls, "style", "I"));
AwtFont::getFontMID =
env->GetStaticMethodID(cls, "getFont",
"(Ljava/lang/String;)Ljava/awt/Font;");
-
- DASSERT(AwtFont::peerMID != NULL);
- DASSERT(AwtFont::pDataID != NULL);
- DASSERT(AwtFont::nameID != NULL);
- DASSERT(AwtFont::sizeID != NULL);
- DASSERT(AwtFont::styleID != NULL);
-
- DASSERT(AwtFont::getFontMID != NULL);
-
- CATCH_BAD_ALLOC;
}
} /* extern "C" */
@@ -988,15 +1009,9 @@
JNIEXPORT void JNICALL
Java_java_awt_FontMetrics_initIDs(JNIEnv *env, jclass cls)
{
- TRY;
-
- AwtFont::fontID = env->GetFieldID(cls, "font", "Ljava/awt/Font;");
+ CHECK_NULL(AwtFont::fontID =
+ env->GetFieldID(cls, "font", "Ljava/awt/Font;"));
AwtFont::getHeightMID = env->GetMethodID(cls, "getHeight", "()I");
-
- DASSERT(AwtFont::fontID);
- DASSERT(AwtFont::getHeightMID);
-
- CATCH_BAD_ALLOC;
}
} /* extern "C" */
@@ -1010,16 +1025,10 @@
JNIEXPORT void JNICALL
Java_sun_awt_FontDescriptor_initIDs(JNIEnv *env, jclass cls)
{
- TRY;
-
- AwtFont::nativeNameID = env->GetFieldID(cls, "nativeName",
- "Ljava/lang/String;");
+ CHECK_NULL(AwtFont::nativeNameID =
+ env->GetFieldID(cls, "nativeName", "Ljava/lang/String;"));
AwtFont::useUnicodeID = env->GetFieldID(cls, "useUnicode", "Z");
- DASSERT(AwtFont::nativeNameID != NULL);
- DASSERT(AwtFont::useUnicodeID != NULL);
-
- CATCH_BAD_ALLOC;
}
} /* extern "C" */
@@ -1034,20 +1043,13 @@
JNIEXPORT void JNICALL
Java_sun_awt_PlatformFont_initIDs(JNIEnv *env, jclass cls)
{
- TRY;
-
- AwtFont::fontConfigID = env->GetFieldID(cls, "fontConfig", "Lsun/awt/FontConfiguration;");
- AwtFont::componentFontsID =
- env->GetFieldID(cls, "componentFonts", "[Lsun/awt/FontDescriptor;");
+ CHECK_NULL(AwtFont::fontConfigID =
+ env->GetFieldID(cls, "fontConfig", "Lsun/awt/FontConfiguration;"));
+ CHECK_NULL(AwtFont::componentFontsID =
+ env->GetFieldID(cls, "componentFonts", "[Lsun/awt/FontDescriptor;"));
AwtFont::makeConvertedMultiFontStringMID =
env->GetMethodID(cls, "makeConvertedMultiFontString",
"(Ljava/lang/String;)[Ljava/lang/Object;");
-
- DASSERT(AwtFont::makeConvertedMultiFontStringMID != NULL);
- DASSERT(AwtFont::componentFontsID != NULL);
- DASSERT(AwtFont::fontConfigID != NULL);
-
- CATCH_BAD_ALLOC;
}
} /* extern "C" */
@@ -1862,8 +1864,10 @@
static CCombinedSegTableManager tableManager;
jstring fontName = (jstring)env->GetObjectField(self, AwtFont::fontNameID);
- DASSERT(fontName != NULL);
+ DASSERT(fontName != NULL); // leave in for debug mode.
+ CHECK_NULL_RETURN(fontName, FALSE); // in production, just return
LPCWSTR fontNameW = JNU_GetStringPlatformChars(env, fontName, NULL);
+ CHECK_NULL_RETURN(fontNameW, FALSE);
CCombinedSegTable* pTable = tableManager.GetTable(fontNameW);
JNU_ReleaseStringPlatformChars(env, fontName, fontNameW);
return (pTable->In((USHORT) ch) ? JNI_TRUE : JNI_FALSE);
--- a/jdk/src/windows/native/sun/windows/awt_Frame.cpp Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/windows/native/sun/windows/awt_Frame.cpp Wed Apr 16 12:42:40 2014 -0700
@@ -351,6 +351,8 @@
case WM_IME_STARTCOMPOSITION:
case WM_IME_ENDCOMPOSITION:
case WM_IME_COMPOSITION:
+ case WM_IME_SETCONTEXT:
+ case WM_IME_NOTIFY:
case WM_IME_CONTROL:
case WM_IME_COMPOSITIONFULL:
case WM_IME_SELECT:
--- a/jdk/src/windows/native/sun/windows/awt_InputMethod.cpp Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/windows/native/sun/windows/awt_InputMethod.cpp Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, 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
@@ -320,13 +320,18 @@
// current language ID (returned from 'getJavaIDFromLangID') is in
// ASCII encoding, so we use 'GetStringUTFChars' to retrieve requested
// language ID from the 'localeString' object.
- const char * current = getJavaIDFromLangID(AwtComponent::GetInputLanguage());
jboolean isCopy;
const char * requested = env->GetStringUTFChars(localeString, &isCopy);
- if ((current != NULL) && (strcmp(current, requested) == 0)) {
- env->ReleaseStringUTFChars(localeString, requested);
+ CHECK_NULL_RETURN(requested, JNI_FALSE);
+
+ const char * current = getJavaIDFromLangID(AwtComponent::GetInputLanguage());
+ if (current != NULL) {
+ if (strcmp(current, requested) == 0) {
+ env->ReleaseStringUTFChars(localeString, requested);
+ free((void *)current);
+ return JNI_TRUE;
+ }
free((void *)current);
- return JNI_TRUE;
}
// get list of available HKLs. Adding the user's preferred layout on top of the layout
@@ -334,7 +339,10 @@
// looking up suitable layout.
int layoutCount = ::GetKeyboardLayoutList(0, NULL) + 1; // +1 for user's preferred HKL
HKL FAR * hKLList = (HKL FAR *)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, sizeof(HKL), layoutCount);
- DASSERT(!safe_ExceptionOccurred(env));
+ if (hKLList == NULL) {
+ env->ReleaseStringUTFChars(localeString, requested);
+ return JNI_FALSE;
+ }
::GetKeyboardLayoutList(layoutCount - 1, &(hKLList[1]));
hKLList[0] = getDefaultKeyboardLayout(); // put user's preferred layout on top of the list
@@ -342,20 +350,23 @@
jboolean retValue = JNI_FALSE;
for (int i = 0; i < layoutCount; i++) {
const char * supported = getJavaIDFromLangID(LOWORD(hKLList[i]));
- if ((supported != NULL) && (strcmp(supported, requested) == 0)) {
- // use special message to call ActivateKeyboardLayout() in main thread.
- if (AwtToolkit::GetInstance().SendMessage(WM_AWT_ACTIVATEKEYBOARDLAYOUT, (WPARAM)onActivate, (LPARAM)hKLList[i])) {
- //also need to change the same keyboard layout for the Java AWT-EventQueue thread
- AwtToolkit::activateKeyboardLayout(hKLList[i]);
- retValue = JNI_TRUE;
+ if (supported != NULL) {
+ if (strcmp(supported, requested) == 0) {
+ // use special message to call ActivateKeyboardLayout() in main thread.
+ if (AwtToolkit::GetInstance().SendMessage(WM_AWT_ACTIVATEKEYBOARDLAYOUT, (WPARAM)onActivate, (LPARAM)hKLList[i])) {
+ //also need to change the same keyboard layout for the Java AWT-EventQueue thread
+ AwtToolkit::activateKeyboardLayout(hKLList[i]);
+ retValue = JNI_TRUE;
+ }
+ free((void *)supported);
+ break;
}
- break;
+ free((void *)supported);
}
}
env->ReleaseStringUTFChars(localeString, requested);
free(hKLList);
- free((void *)current);
return retValue;
CATCH_BAD_ALLOC_RET(JNI_FALSE);
@@ -445,7 +456,7 @@
// get list of available HKLs
int layoutCount = ::GetKeyboardLayoutList(0, NULL);
HKL FAR * hKLList = (HKL FAR *)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, sizeof(HKL), layoutCount);
- DASSERT(!safe_ExceptionOccurred(env));
+ CHECK_NULL_RETURN(hKLList, NULL);
::GetKeyboardLayoutList(layoutCount, hKLList);
// get list of Java locale names while getting rid of duplicates
@@ -453,8 +464,13 @@
int destIndex = 0;
int javaLocaleNameCount = 0;
int current = 0;
+
const char ** javaLocaleNames = (const char **)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, sizeof(char *), layoutCount);
- DASSERT(!safe_ExceptionOccurred(env));
+ if (javaLocaleNames == NULL) {
+ free(hKLList);
+ return NULL;
+ }
+
for (; srcIndex < layoutCount; srcIndex++) {
const char * srcLocaleName = getJavaIDFromLangID(LOWORD(hKLList[srcIndex]));
@@ -477,18 +493,33 @@
}
}
+ jobjectArray locales = NULL;
// convert it to an array of Java locale objects
jclass localeClass = env->FindClass("java/util/Locale");
- jobjectArray locales = env->NewObjectArray(javaLocaleNameCount, localeClass, NULL);
+ if (localeClass != NULL) {
+ locales = env->NewObjectArray(javaLocaleNameCount, localeClass, NULL);
+ if (locales != NULL) {
+
+ for (current = 0; current < javaLocaleNameCount; current++) {
+ jobject obj = CreateLocaleObject(env, javaLocaleNames[current]);
+ if (env->ExceptionCheck()) {
+ env->DeleteLocalRef(locales);
+ locales = NULL;
+ break;
+ }
+ env->SetObjectArrayElement(locales,
+ current,
+ obj);
+ }
+
+ }
+ env->DeleteLocalRef(localeClass);
+ }
+
for (current = 0; current < javaLocaleNameCount; current++) {
- env->SetObjectArrayElement(locales,
- current,
- CreateLocaleObject(env, javaLocaleNames[current]));
free((void *)javaLocaleNames[current]);
}
- DASSERT(!safe_ExceptionOccurred(env));
- env->DeleteLocalRef(localeClass);
free(hKLList);
free(javaLocaleNames);
return locales;
@@ -542,6 +573,7 @@
// create Locale object
jobject langtagObj = env->NewStringUTF(name);
+ CHECK_NULL_RETURN(langtagObj, NULL);
jobject localeObj = JNU_CallStaticMethodByName(env,
NULL,
"java/util/Locale",
--- a/jdk/src/windows/native/sun/windows/awt_List.cpp Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/windows/native/sun/windows/awt_List.cpp Wed Apr 16 12:42:40 2014 -0700
@@ -614,7 +614,8 @@
{
LPTSTR itemPtr = NULL;
jstring item = (jstring)env->GetObjectArrayElement(items, i);
- JNI_CHECK_NULL_GOTO(item, "null item", next_item);
+ if (env->ExceptionCheck()) goto ret;
+ if (item == NULL) goto next_item;
itemPtr = (LPTSTR)JNU_GetStringPlatformChars(env, item, 0);
if (itemPtr == NULL)
{
@@ -1017,8 +1018,8 @@
ses->list = env->NewGlobalRef(self);
ses->index = index;
- return (jboolean)AwtToolkit::GetInstance().SyncCall(
- (void *(*)(void *))AwtList::_IsSelected, ses);
+ return JNI_IS_TRUE(AwtToolkit::GetInstance().SyncCall(
+ (void *(*)(void *))AwtList::_IsSelected, ses));
// global ref and ses are deleted in _IsSelected
CATCH_BAD_ALLOC_RET(FALSE);
--- a/jdk/src/windows/native/sun/windows/awt_MenuItem.cpp Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/windows/native/sun/windows/awt_MenuItem.cpp Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2014, 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
@@ -152,6 +152,9 @@
if (dw == ERROR_OUTOFMEMORY)
{
jstring errorMsg = JNU_NewStringPlatform(env, L"too many menu handles");
+ if (errorMsg == NULL) {
+ throw std::bad_alloc();
+ }
createError = JNU_NewObjectByName(env, "java/lang/OutOfMemoryError",
"(Ljava/lang/String;)V",
errorMsg);
@@ -164,16 +167,19 @@
NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&buf, 0, NULL);
jstring s = JNU_NewStringPlatform(env, buf);
+ if (s == NULL) {
+ throw std::bad_alloc();
+ }
createError = JNU_NewObjectByName(env, "java/lang/InternalError",
"(Ljava/lang/String;)V", s);
LocalFree(buf);
env->DeleteLocalRef(s);
}
+ if (createError == NULL) {
+ throw std::bad_alloc();
+ }
env->SetObjectField(self, AwtObject::createErrorID, createError);
- if (createError != NULL)
- {
- env->DeleteLocalRef(createError);
- }
+ env->DeleteLocalRef(createError);
return FALSE;
}
return TRUE;
@@ -238,12 +244,18 @@
jobject self = GetPeer(env);
jobject target = env->GetObjectField(self, AwtObject::targetID);
jobject font = JNU_CallMethodByName(env, 0, target, "getFont_NoClientCode", "()Ljava/awt/Font;").l;
+ env->DeleteLocalRef(target);
+ if (env->ExceptionCheck()) {
+ throw std::bad_alloc();
+ }
if (font == NULL) {
font = env->NewLocalRef(GetDefaultFont(env));
+ if (env->ExceptionCheck()) {
+ throw std::bad_alloc();
+ }
}
- env->DeleteLocalRef(target);
return font;
}
@@ -251,13 +263,22 @@
AwtMenuItem::GetDefaultFont(JNIEnv *env) {
if (AwtMenuItem::systemFont == NULL) {
jclass cls = env->FindClass("sun/awt/windows/WMenuItemPeer");
- DASSERT(cls != NULL);
+ if (cls == NULL) {
+ throw std::bad_alloc();
+ }
AwtMenuItem::systemFont =
env->CallStaticObjectMethod(cls, AwtMenuItem::getDefaultFontMID);
- DASSERT(AwtMenuItem::systemFont);
+ if (env->ExceptionCheck()) {
+ env->DeleteLocalRef(cls);
+ throw std::bad_alloc();
+ }
AwtMenuItem::systemFont = env->NewGlobalRef(AwtMenuItem::systemFont);
+ if (systemFont == NULL) {
+ env->DeleteLocalRef(cls);
+ throw std::bad_alloc();
+ }
}
return AwtMenuItem::systemFont;
}
@@ -284,8 +305,19 @@
DWORD crBack,crText;
HBRUSH hbrBack;
- jobject font = GetFont(env);
+ jobject font;
+ try {
+ font = GetFont(env);
+ } catch (std::bad_alloc&) {
+ env->DeleteLocalRef(target);
+ throw;
+ }
+
jstring text = GetJavaString(env);
+ if (env->ExceptionCheck()) {
+ env->DeleteLocalRef(target);
+ throw std::bad_alloc();
+ }
size = AwtFont::getMFStringSize(hDC, font, text);
/* 4700350: If the font size is taller than the menubar, change to the
@@ -294,7 +326,13 @@
*/
if (IsTopMenu() && size.cy > ::GetSystemMetrics(SM_CYMENU)) {
env->DeleteLocalRef(font);
- font = env->NewLocalRef(GetDefaultFont(env));
+ try {
+ font = env->NewLocalRef(GetDefaultFont(env));
+ } catch (std::bad_alloc&) {
+ env->DeleteLocalRef(target);
+ env->DeleteLocalRef(text);
+ throw;
+ }
size = AwtFont::getMFStringSize(hDC, font, text);
}
@@ -452,6 +490,10 @@
/* font is a java.awt.Font */
jobject font = GetFont(env);
jstring text = GetJavaString(env);
+ if (env->ExceptionCheck()) {
+ env->DeleteLocalRef(font);
+ throw std::bad_alloc();
+ }
SIZE size = AwtFont::getMFStringSize(hDC, font, text);
/* 4700350: If the font size is taller than the menubar, change to the
@@ -459,7 +501,14 @@
* client area. -bchristi
*/
if (IsTopMenu() && size.cy > ::GetSystemMetrics(SM_CYMENU)) {
- jobject defFont = GetDefaultFont(env);
+ jobject defFont;
+ try {
+ defFont = GetDefaultFont(env);
+ } catch (std::bad_alloc&) {
+ env->DeleteLocalRef(text);
+ env->DeleteLocalRef(font);
+ throw;
+ }
env->DeleteLocalRef(font);
font = env->NewLocalRef(defFont);
size = AwtFont::getMFStringSize(hDC, font, text);
@@ -468,13 +517,31 @@
jstring fontName =
(jstring)JNU_CallMethodByName(env, 0,font, "getName",
"()Ljava/lang/String;").l;
+ if (env->ExceptionCheck()) {
+ env->DeleteLocalRef(text);
+ env->DeleteLocalRef(font);
+ throw std::bad_alloc();
+ }
+
/* fontMetrics is a Hsun_awt_windows_WFontMetrics */
jobject fontMetrics = GetFontMetrics(env, font);
-
+ if (env->ExceptionCheck()) {
+ env->DeleteLocalRef(text);
+ env->DeleteLocalRef(font);
+ env->DeleteLocalRef(fontName);
+ throw std::bad_alloc();
+ }
// int height = env->GetIntField(fontMetrics, AwtFont::heightID);
int height = (jint)JNU_CallMethodByName(env, 0, fontMetrics, "getHeight",
"()I").i;
+ if (env->ExceptionCheck()) {
+ env->DeleteLocalRef(text);
+ env->DeleteLocalRef(font);
+ env->DeleteLocalRef(fontName);
+ env->DeleteLocalRef(fontMetrics);
+ throw std::bad_alloc();
+ }
measureInfo.itemHeight = height;
measureInfo.itemHeight += measureInfo.itemHeight/3;
@@ -520,10 +587,14 @@
if (env->PushLocalFrame(2) < 0)
return NULL;
jclass cls = env->FindClass("java/awt/Toolkit");
+ CHECK_NULL_RETURN(cls, NULL);
jobject toolkitLocal =
env->CallStaticObjectMethod(cls, AwtToolkit::getDefaultToolkitMID);
+ env->DeleteLocalRef(cls);
+ CHECK_NULL_RETURN(toolkitLocal, NULL);
toolkit = env->NewGlobalRef(toolkitLocal);
- DASSERT(!safe_ExceptionOccurred(env));
+ env->DeleteLocalRef(toolkitLocal);
+ CHECK_NULL_RETURN(toolkit, NULL);
env->PopLocalFrame(0);
}
/*
@@ -739,6 +810,10 @@
{
empty = JNU_NewStringPlatform(env, TEXT(""));
}
+ if (env->ExceptionCheck()) {
+ badAlloc = 1;
+ goto ret;
+ }
LPCTSTR labelPtr;
if (empty != NULL)
{
@@ -846,10 +921,9 @@
TRY;
AwtMenuItem::fontID = env->GetFieldID(cls, "font", "Ljava/awt/Font;");
+ CHECK_NULL(AwtMenuItem::fontID);
AwtMenuItem::appContextID = env->GetFieldID(cls, "appContext", "Lsun/awt/AppContext;");
- DASSERT(AwtMenuItem::fontID != NULL);
-
CATCH_BAD_ALLOC;
}
@@ -868,11 +942,9 @@
TRY;
AwtMenuItem::labelID = env->GetFieldID(cls, "label", "Ljava/lang/String;");
+ CHECK_NULL(AwtMenuItem::labelID);
AwtMenuItem::enabledID = env->GetFieldID(cls, "enabled", "Z");
- DASSERT(AwtMenuItem::labelID != NULL);
- DASSERT(AwtMenuItem::enabledID != NULL);
-
CATCH_BAD_ALLOC;
}
@@ -892,8 +964,6 @@
AwtMenuItem::stateID = env->GetFieldID(cls, "state", "Z");
- DASSERT(AwtMenuItem::stateID != NULL);
-
CATCH_BAD_ALLOC;
}
@@ -917,15 +987,13 @@
TRY;
AwtMenuItem::isCheckboxID = env->GetFieldID(cls, "isCheckbox", "Z");
+ CHECK_NULL(AwtMenuItem::isCheckboxID);
AwtMenuItem::shortcutLabelID = env->GetFieldID(cls, "shortcutLabel",
"Ljava/lang/String;");
+ CHECK_NULL(AwtMenuItem::shortcutLabelID);
AwtMenuItem::getDefaultFontMID =
env->GetStaticMethodID(cls, "getDefaultFont", "()Ljava/awt/Font;");
- DASSERT(AwtMenuItem::isCheckboxID != NULL);
- DASSERT(AwtMenuItem::shortcutLabelID != NULL);
- DASSERT(AwtMenuItem::getDefaultFontMID != NULL);
-
CATCH_BAD_ALLOC;
}
--- a/jdk/src/windows/native/sun/windows/awt_PrintControl.cpp Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/windows/native/sun/windows/awt_PrintControl.cpp Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2014, 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
@@ -233,107 +233,166 @@
TRY;
jclass cls = env->FindClass("sun/awt/windows/WPrinterJob");
+ CHECK_NULL(cls);
AwtPrintControl::dialogOwnerPeerID =
env->GetFieldID(cls, "dialogOwnerPeer", "Ljava/awt/peer/ComponentPeer;");
+ DASSERT(AwtPrintControl::dialogOwnerPeerID != NULL);
+ CHECK_NULL(AwtPrintControl::dialogOwnerPeerID);
+
AwtPrintControl::getPrintDCID = env->GetMethodID(cls, "getPrintDC", "()J");
+ DASSERT(AwtPrintControl::getPrintDCID != NULL);
+ CHECK_NULL(AwtPrintControl::getPrintDCID);
+
AwtPrintControl::setPrintDCID =
env->GetMethodID(cls, "setPrintDC", "(J)V");
+ DASSERT(AwtPrintControl::setPrintDCID != NULL);
+ CHECK_NULL(AwtPrintControl::setPrintDCID);
+
AwtPrintControl::getDevmodeID = env->GetMethodID(cls, "getDevMode", "()J");
+ DASSERT(AwtPrintControl::getDevmodeID != NULL);
+ CHECK_NULL(AwtPrintControl::getDevmodeID);
+
AwtPrintControl::setDevmodeID =
env->GetMethodID(cls, "setDevMode", "(J)V");
+ DASSERT(AwtPrintControl::setDevmodeID != NULL);
+ CHECK_NULL(AwtPrintControl::setDevmodeID);
+
AwtPrintControl::getDevnamesID =
env->GetMethodID(cls, "getDevNames", "()J");
+ DASSERT(AwtPrintControl::getDevnamesID != NULL);
+ CHECK_NULL(AwtPrintControl::getDevnamesID);
+
AwtPrintControl::setDevnamesID =
env->GetMethodID(cls, "setDevNames", "(J)V");
+ DASSERT(AwtPrintControl::setDevnamesID != NULL);
+ CHECK_NULL(AwtPrintControl::setDevnamesID);
+
AwtPrintControl::driverDoesMultipleCopiesID =
env->GetFieldID(cls, "driverDoesMultipleCopies", "Z");
+ DASSERT(AwtPrintControl::driverDoesMultipleCopiesID != NULL);
+ CHECK_NULL(AwtPrintControl::driverDoesMultipleCopiesID);
+
AwtPrintControl::driverDoesCollationID =
env->GetFieldID(cls, "driverDoesCollation", "Z");
+ DASSERT(AwtPrintControl::driverDoesCollationID != NULL);
+ CHECK_NULL(AwtPrintControl::driverDoesCollationID);
+
AwtPrintControl::getCopiesID =
env->GetMethodID(cls, "getCopiesAttrib", "()I");
+ DASSERT(AwtPrintControl::getCopiesID != NULL);
+ CHECK_NULL(AwtPrintControl::getCopiesID);
+
AwtPrintControl::getCollateID =
env->GetMethodID(cls, "getCollateAttrib","()I");
+ DASSERT(AwtPrintControl::getCollateID != NULL);
+ CHECK_NULL(AwtPrintControl::getCollateID);
+
AwtPrintControl::getOrientID =
env->GetMethodID(cls, "getOrientAttrib", "()I");
+ DASSERT(AwtPrintControl::getOrientID != NULL);
+ CHECK_NULL(AwtPrintControl::getOrientID);
+
AwtPrintControl::getFromPageID =
env->GetMethodID(cls, "getFromPageAttrib", "()I");
+ DASSERT(AwtPrintControl::getFromPageID != NULL);
+ CHECK_NULL(AwtPrintControl::getFromPageID);
+
AwtPrintControl::getToPageID =
env->GetMethodID(cls, "getToPageAttrib", "()I");
+ DASSERT(AwtPrintControl::getToPageID != NULL);
+ CHECK_NULL(AwtPrintControl::getToPageID);
+
AwtPrintControl::getMinPageID =
env->GetMethodID(cls, "getMinPageAttrib", "()I");
+ DASSERT(AwtPrintControl::getMinPageID != NULL);
+ CHECK_NULL(AwtPrintControl::getMinPageID);
+
AwtPrintControl::getMaxPageID =
env->GetMethodID(cls, "getMaxPageAttrib", "()I");
+ DASSERT(AwtPrintControl::getMaxPageID != NULL);
+ CHECK_NULL(AwtPrintControl::getMaxPageID);
+
AwtPrintControl::getDestID =
env->GetMethodID(cls, "getDestAttrib", "()Z");
+ DASSERT(AwtPrintControl::getDestID != NULL);
+ CHECK_NULL(AwtPrintControl::getDestID);
+
AwtPrintControl::getQualityID =
env->GetMethodID(cls, "getQualityAttrib", "()I");
+ DASSERT(AwtPrintControl::getQualityID != NULL);
+ CHECK_NULL(AwtPrintControl::getQualityID);
+
AwtPrintControl::getColorID =
env->GetMethodID(cls, "getColorAttrib", "()I");
+ DASSERT(AwtPrintControl::getColorID != NULL);
+ CHECK_NULL(AwtPrintControl::getColorID);
+
AwtPrintControl::getSidesID =
env->GetMethodID(cls, "getSidesAttrib", "()I");
+ DASSERT(AwtPrintControl::getSidesID != NULL);
+ CHECK_NULL(AwtPrintControl::getSidesID);
+
AwtPrintControl::getPrinterID =
env->GetMethodID(cls, "getPrinterAttrib", "()Ljava/lang/String;");
+ DASSERT(AwtPrintControl::getPrinterID != NULL);
+ CHECK_NULL(AwtPrintControl::getPrinterID);
+
AwtPrintControl::getWin32MediaID =
env->GetMethodID(cls, "getWin32MediaAttrib", "()[I");
+ DASSERT(AwtPrintControl::getWin32MediaID != NULL);
+ CHECK_NULL(AwtPrintControl::getWin32MediaID);
+
AwtPrintControl::setWin32MediaID =
env->GetMethodID(cls, "setWin32MediaAttrib", "(III)V");
+ DASSERT(AwtPrintControl::setWin32MediaID != NULL);
+ CHECK_NULL(AwtPrintControl::setWin32MediaID);
+
AwtPrintControl::getWin32MediaTrayID =
env->GetMethodID(cls, "getMediaTrayAttrib", "()I");
+ DASSERT(AwtPrintControl::getWin32MediaTrayID != NULL);
+ CHECK_NULL(AwtPrintControl::getWin32MediaTrayID);
+
AwtPrintControl::setWin32MediaTrayID =
env->GetMethodID(cls, "setMediaTrayAttrib", "(I)V");
+ DASSERT(AwtPrintControl::setWin32MediaTrayID != NULL);
+ CHECK_NULL(AwtPrintControl::setWin32MediaTrayID);
+
AwtPrintControl::getSelectID =
env->GetMethodID(cls, "getSelectAttrib", "()I");
+ DASSERT(AwtPrintControl::getSelectID != NULL);
+ CHECK_NULL(AwtPrintControl::getSelectID);
+
AwtPrintControl::getPrintToFileEnabledID =
env->GetMethodID(cls, "getPrintToFileEnabled", "()Z");
+ DASSERT(AwtPrintControl::getPrintToFileEnabledID != NULL);
+ CHECK_NULL(AwtPrintControl::getPrintToFileEnabledID);
AwtPrintControl::setNativeAttID =
env->GetMethodID(cls, "setNativeAttributes", "(III)V");
+ DASSERT(AwtPrintControl::setNativeAttID != NULL);
+ CHECK_NULL(AwtPrintControl::setNativeAttID);
AwtPrintControl::setRangeCopiesID =
env->GetMethodID(cls, "setRangeCopiesAttribute", "(IIZI)V");
+ DASSERT(AwtPrintControl::setRangeCopiesID != NULL);
+ CHECK_NULL(AwtPrintControl::setRangeCopiesID);
+
AwtPrintControl::setResID =
env->GetMethodID(cls, "setResolutionDPI", "(II)V");
+ DASSERT(AwtPrintControl::setResID != NULL);
+ CHECK_NULL(AwtPrintControl::setResID);
AwtPrintControl::setPrinterID =
env->GetMethodID(cls, "setPrinterNameAttrib", "(Ljava/lang/String;)V");
+ DASSERT(AwtPrintControl::setPrinterID != NULL);
+ CHECK_NULL(AwtPrintControl::setPrinterID);
AwtPrintControl::setJobAttributesID =
env->GetMethodID(cls, "setJobAttributes",
"(Ljavax/print/attribute/PrintRequestAttributeSet;IISSSSSSS)V");
-
- DASSERT(AwtPrintControl::driverDoesMultipleCopiesID != NULL);
- DASSERT(AwtPrintControl::getPrintDCID != NULL);
- DASSERT(AwtPrintControl::setPrintDCID != NULL);
- DASSERT(AwtPrintControl::getDevmodeID != NULL);
- DASSERT(AwtPrintControl::setDevmodeID != NULL);
- DASSERT(AwtPrintControl::getDevnamesID != NULL);
- DASSERT(AwtPrintControl::setDevnamesID != NULL);
- DASSERT(AwtPrintControl::driverDoesCollationID != NULL);
- DASSERT(AwtPrintControl::getWin32MediaID != NULL);
- DASSERT(AwtPrintControl::setWin32MediaID != NULL);
- DASSERT(AwtPrintControl::getWin32MediaTrayID != NULL);
- DASSERT(AwtPrintControl::setWin32MediaTrayID != NULL);
- DASSERT(AwtPrintControl::setRangeCopiesID != NULL);
- DASSERT(AwtPrintControl::setResID != NULL);
- DASSERT(AwtPrintControl::setNativeAttID != NULL);
- DASSERT(AwtPrintControl::dialogOwnerPeerID != NULL);
- DASSERT(AwtPrintControl::getCopiesID != NULL);
- DASSERT(AwtPrintControl::getOrientID != NULL);
- DASSERT(AwtPrintControl::getPrinterID != NULL);
- DASSERT(AwtPrintControl::getCollateID != NULL);
- DASSERT(AwtPrintControl::getFromPageID != NULL);
- DASSERT(AwtPrintControl::getToPageID != NULL);
- DASSERT(AwtPrintControl::getMinPageID != NULL);
- DASSERT(AwtPrintControl::getMaxPageID != NULL);
- DASSERT(AwtPrintControl::getDestID != NULL);
- DASSERT(AwtPrintControl::getQualityID != NULL);
- DASSERT(AwtPrintControl::getColorID != NULL);
- DASSERT(AwtPrintControl::getSidesID != NULL);
- DASSERT(AwtPrintControl::getSelectID != NULL);
- DASSERT(AwtPrintControl::getPrintToFileEnabledID != NULL);
DASSERT(AwtPrintControl::setJobAttributesID != NULL);
-
+ CHECK_NULL(AwtPrintControl::setJobAttributesID);
CATCH_BAD_ALLOC;
}
@@ -606,6 +665,10 @@
LPTSTR getName = (LPTSTR)JNU_GetStringPlatformChars(env,
printerName, NULL);
+ if (getName == NULL) {
+ env->DeleteLocalRef(printerName);
+ throw std::bad_alloc();
+ }
BOOL samePrinter = FALSE;
@@ -652,6 +715,7 @@
if (portName != NULL) {
free(portName);
}
+ env->DeleteLocalRef(printerName);
return FALSE;
}
@@ -664,11 +728,13 @@
if (portName != NULL) {
free(portName);
}
+ env->DeleteLocalRef(printerName);
return FALSE;
}
delete [] buffer;
}
+ env->DeleteLocalRef(printerName);
// PrintDlg may change the values of hDevMode and hDevNames so we
// re-initialize our saved handles.
AwtPrintControl::setPrintHDMode(env, printCtrl, NULL);
--- a/jdk/src/windows/native/sun/windows/awt_PrintDialog.cpp Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/windows/native/sun/windows/awt_PrintDialog.cpp Wed Apr 16 12:42:40 2014 -0700
@@ -193,11 +193,24 @@
// as peer object is used later on another thread, create a global ref
jobject peerGlobalRef = env->NewGlobalRef(peer);
DASSERT(peerGlobalRef != NULL);
+ CHECK_NULL_RETURN(peerGlobalRef, 0);
jobject target = env->GetObjectField(peerGlobalRef, AwtObject::targetID);
DASSERT(target != NULL);
+ if (target == NULL) {
+ env->DeleteGlobalRef(peerGlobalRef);
+ return 0;
+ }
jobject parent = env->GetObjectField(peerGlobalRef, AwtPrintDialog::parentID);
jobject control = env->GetObjectField(target, AwtPrintDialog::controlID);
DASSERT(control != NULL);
+ if (control == NULL) {
+ env->DeleteGlobalRef(peerGlobalRef);
+ env->DeleteLocalRef(target);
+ if (parent != NULL) {
+ env->DeleteLocalRef(parent);
+ }
+ return 0;
+ }
AwtComponent *awtParent = (parent != NULL) ? (AwtComponent *)JNI_GET_PDATA(parent) : NULL;
HWND hwndOwner = awtParent ? awtParent->GetHWnd() : NULL;
@@ -206,7 +219,18 @@
memset(&pd, 0, sizeof(PRINTDLG));
pd.lStructSize = sizeof(PRINTDLG);
pd.lCustData = (LPARAM)peerGlobalRef;
- BOOL ret = AwtPrintControl::InitPrintDialog(env, control, pd);
+ BOOL ret;
+ try {
+ ret = AwtPrintControl::InitPrintDialog(env, control, pd);
+ } catch (std::bad_alloc&) {
+ env->DeleteGlobalRef(peerGlobalRef);
+ env->DeleteLocalRef(target);
+ if (parent != NULL) {
+ env->DeleteLocalRef(parent);
+ }
+ env->DeleteLocalRef(control);
+ throw;
+ }
if (!ret) {
/* Couldn't use the printer, or spooler isn't running
* Call Page dialog with ' PD_RETURNDEFAULT' so it doesn't try
--- a/jdk/src/windows/native/sun/windows/awt_new.cpp Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/src/windows/native/sun/windows/awt_new.cpp Wed Apr 16 12:42:40 2014 -0700
@@ -149,7 +149,7 @@
handle_bad_alloc(void) {
if (jvm != NULL) {
JNIEnv* env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
- if (env != NULL) {
+ if (env != NULL && !env->ExceptionCheck()) {
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
}
}
--- a/jdk/test/java/awt/Frame/7024749/bug7024749.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/test/java/awt/Frame/7024749/bug7024749.java Wed Apr 16 12:42:40 2014 -0700
@@ -23,7 +23,7 @@
/*
* @test
- * @bug 7024749
+ * @bug 7024749 8019990
* @summary JDK7 b131---a crash in: Java_sun_awt_windows_ThemeReader_isGetThemeTransitionDurationDefined+0x75
* @library ../../regtesthelpers
* @build Util
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Frame/SlideNotResizableTest/SlideNotResizableTest.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2014, 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 sun.awt.SunToolkit;
+
+import java.awt.*;
+import java.awt.Dimension;
+import java.awt.Point;
+import java.awt.event.InputEvent;
+
+/**
+ * @test
+ * @bug 8032595
+ * @summary setResizable(false) makes a frame slide down
+ * @author Petr Pchelko
+ */
+
+public class SlideNotResizableTest {
+
+ private static volatile boolean passed = false;
+ private static final Dimension FRAME_SIZE = new Dimension(100, 100);
+ private static final Point FRAME_LOCATION = new Point(200, 200);
+
+ public static void main(String[] args) throws Throwable {
+ Frame aFrame = null;
+ try {
+ aFrame = new Frame();
+ aFrame.setSize(FRAME_SIZE);
+ aFrame.setLocation(FRAME_LOCATION);
+ aFrame.setResizable(false);
+ aFrame.setVisible(true);
+
+ sync();
+
+ if (!aFrame.getLocation().equals(FRAME_LOCATION)) {
+ throw new RuntimeException("FAILED: Wrong frame position");
+ }
+ } finally {
+ if (aFrame != null) {
+ aFrame.dispose();
+ }
+ }
+ }
+
+ private static void sync() throws InterruptedException {
+ ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
+ Thread.sleep(1000);
+ }
+}
--- a/jdk/test/java/awt/Paint/bug8024864.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/test/java/awt/Paint/bug8024864.java Wed Apr 16 12:42:40 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 8024864
+ * @bug 8024864 8031422
* @summary [macosx] Problems with rendering of controls
* @author Petr Pchelko
* @library ../regtesthelpers
@@ -65,7 +65,7 @@
Util.waitForIdle(r);
Dimension frameSize = frame.getSize();
- Point loc = new Point(frameSize.width - 5, frameSize.height - 5);
+ Point loc = new Point(frameSize.width - 15, frameSize.height - 15);
SwingUtilities.convertPointToScreen(loc, frame);
Color c = r.getPixelColor(loc.x, loc.y);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/datatransfer/DataFlavor/EqualsHashCodeSymmetryTest/EqualsHashCodeSymmetryTest.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2014, 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.datatransfer.DataFlavor;
+
+/**
+ * @test
+ * @bug 8038999
+ * @summary DataFlavor.equals is not symmetric
+ * @author Petr Pchelko <petr.pchelko@oracle.com>
+ */
+public class EqualsHashCodeSymmetryTest {
+
+ private static final DataFlavor[] dataFlavors = {
+ DataFlavor.stringFlavor,
+ DataFlavor.imageFlavor,
+ DataFlavor.javaFileListFlavor,
+ DataFlavor.allHtmlFlavor,
+ DataFlavor.selectionHtmlFlavor,
+ DataFlavor.fragmentHtmlFlavor,
+ createFlavor("text/html; class=java.lang.String"),
+ new DataFlavor(String.class, "My test flavor number 1"),
+ new DataFlavor(String.class, "My test flavor number 2"),
+ new DataFlavor(StringBuilder.class, "My test flavor number 1")
+ };
+
+ public static void main(String[] args) {
+ testEqualsSymmetry();
+ testEqualsHashCodeConsistency();
+ testSimpleCollision();
+ }
+
+ private static void testEqualsSymmetry() {
+ for (DataFlavor flavor1 : dataFlavors) {
+ for (DataFlavor flavor2 : dataFlavors) {
+ if (flavor1.equals(flavor2) != flavor2.equals(flavor1)) {
+ throw new RuntimeException(
+ String.format("Equals is not symmetric for %s and %s", flavor1, flavor2));
+ }
+ }
+ }
+ }
+
+ private static void testEqualsHashCodeConsistency() {
+ for (DataFlavor flavor1 : dataFlavors) {
+ for (DataFlavor flavor2 : dataFlavors) {
+ if ((flavor1.equals(flavor2) && flavor1.hashCode() != flavor2.hashCode())) {
+ throw new RuntimeException(
+ String.format("Equals and hash code not consistent for %s and %s", flavor1, flavor2));
+ }
+ }
+ }
+ }
+
+ private static void testSimpleCollision() {
+ if (createFlavor("text/html; class=java.lang.String").hashCode() == DataFlavor.allHtmlFlavor.hashCode()) {
+ throw new RuntimeException("HashCode collision because the document parameter is not used");
+ }
+ }
+
+ private static DataFlavor createFlavor(String mime) {
+ try {
+ return new DataFlavor(mime);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/dnd/DragSourceListenerSerializationTest/DragSourceListenerSerializationTest.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2014, 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 4422345 8039083
+ @summary tests serialization of DragSourceListeners
+ @author das@sparc.spb.su area=dnd
+ @library ../../../../lib/testlibrary
+ @build jdk.testlibrary.Asserts
+ @run main/othervm DragSourceListenerSerializationTest
+*/
+
+import java.awt.Button;
+import java.awt.Component;
+import java.awt.Cursor;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.datatransfer.StringSelection;
+import java.awt.dnd.DnDConstants;
+import java.awt.dnd.DragGestureEvent;
+import java.awt.dnd.DragGestureRecognizer;
+import java.awt.dnd.DragSource;
+import java.awt.dnd.DragSourceAdapter;
+import java.awt.dnd.DragSourceContext;
+import java.awt.dnd.DragSourceListener;
+import java.awt.dnd.DragSourceMotionListener;
+import java.awt.event.InputEvent;
+import java.awt.event.MouseEvent;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.TooManyListenersException;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static jdk.testlibrary.Asserts.assertEquals;
+
+public class DragSourceListenerSerializationTest {
+ public static void main(String[] args) throws Exception {
+ DragSource ds = new DragSource();
+ TestDragSourceAdapter dsa1 = new TestDragSourceAdapter(1);
+ TestDragSourceAdapter dsa2 = new TestDragSourceAdapter(2);
+ Component c = new Button();
+ DragGestureRecognizer dgr = ds.createDefaultDragGestureRecognizer(c,
+ DnDConstants.ACTION_COPY,
+ e -> e.startDrag(null, null));
+ MouseEvent me = new MouseEvent(c, MouseEvent.MOUSE_PRESSED, 0,
+ InputEvent.CTRL_MASK, 100, 100, 0, false);
+ DragGestureEvent dge = new DragGestureEvent(dgr, DnDConstants.ACTION_COPY,
+ new Point(100, 100),
+ Arrays.asList(me));
+ DragSourceContext dsc = new DragSourceContext(
+ Toolkit.getDefaultToolkit().createDragSourceContextPeer(dge),
+ dge,
+ new Cursor(Cursor.HAND_CURSOR),
+ null, null, new StringSelection("TEXT"), null);
+
+ ds.addDragSourceListener(dsa1);
+ ds.addDragSourceListener(dsa2);
+ ds.addDragSourceListener(dsa2);
+ ds.addDragSourceMotionListener(dsa1);
+ ds.addDragSourceMotionListener(dsa1);
+ ds.addDragSourceMotionListener(dsa2);
+ dsc.addDragSourceListener(dsa2);
+
+ byte[] serialized;
+ try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(bos)) {
+ oos.writeObject(dsc);
+ serialized = bos.toByteArray();
+ }
+
+ DragSourceContext dsc_copy;
+ try (ByteArrayInputStream bis = new ByteArrayInputStream(serialized);
+ ObjectInputStream ois = new ObjectInputStream(bis)) {
+ dsc_copy = (DragSourceContext) ois.readObject();
+ }
+
+ try {
+ dsc_copy.addDragSourceListener(dsa1);
+ throw new RuntimeException("Test failed. Listener addition succeeded");
+ } catch (TooManyListenersException ignored) {
+ }
+
+ try {
+ dsc_copy.addDragSourceListener(dsa2);
+ throw new RuntimeException("Test failed. Listener addition succeeded");
+ } catch (TooManyListenersException ignored) {
+ }
+
+ try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(bos)) {
+ oos.writeObject(ds);
+ serialized = bos.toByteArray();
+ }
+
+ DragSource ds_copy;
+ try (ByteArrayInputStream bis = new ByteArrayInputStream(serialized);
+ ObjectInputStream ois = new ObjectInputStream(bis)) {
+ ds_copy = (DragSource) ois.readObject();
+ }
+
+ DragSourceListener[] dsls = ds_copy.getDragSourceListeners();
+ assertEquals(3, dsls.length, "DragSourceListeners number");
+ assertEquals(1, Stream.of(dsls).filter(dsa1::equals).collect(Collectors.counting()).intValue());
+ assertEquals(2, Stream.of(dsls).filter(dsa2::equals).collect(Collectors.counting()).intValue());
+
+ DragSourceMotionListener[] dsmls = ds_copy.getDragSourceMotionListeners();
+ assertEquals(3, dsmls.length, "DragSourceMotionListeners number");
+ assertEquals(2, Stream.of(dsmls).filter(dsa1::equals).collect(Collectors.counting()).intValue());
+ assertEquals(1, Stream.of(dsmls).filter(dsa2::equals).collect(Collectors.counting()).intValue());
+ }
+}
+
+class TestDragSourceAdapter extends DragSourceAdapter implements Serializable {
+ final int id;
+
+ TestDragSourceAdapter(int id) {
+ this.id = id;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof TestDragSourceAdapter) {
+ TestDragSourceAdapter tdsa = (TestDragSourceAdapter) obj;
+ return tdsa.getId() == getId();
+ }
+ return false;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/Dialog/DestinationTest.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2007, 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 4846344 4851365 4851321 4851316 4863656 5046198 6293139
+ * @summary Confirm that cancelling the dialog will not prompt for file.
+ * @run main/manual DestinationTest
+ */
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+import java.io.*;
+
+public class DestinationTest extends Frame implements ActionListener {
+ //Declare things used in the test, like buttons and labels here
+
+ DisplayImages images;
+ Button nativeDlg, nativeDlg2, commonSelectionDlg, commonRangeDlg, fileDlg;
+
+ public DestinationTest() {
+
+ images = new DisplayImages();
+ images.setSize(530, 480);
+ add(images, "Center");
+
+ Panel printpanel = new Panel();
+
+ nativeDlg = new Button("Native");
+ nativeDlg.addActionListener(this);
+ printpanel.add(nativeDlg);
+
+ nativeDlg2 = new Button("Native 2");
+ nativeDlg2.addActionListener(this);
+ printpanel.add(nativeDlg2);
+
+ commonSelectionDlg = new Button("Common Selection");
+ commonSelectionDlg.addActionListener(this);
+ printpanel.add(commonSelectionDlg);
+
+ commonRangeDlg = new Button("Common Range");
+ commonRangeDlg.addActionListener(this);
+ printpanel.add(commonRangeDlg);
+
+ fileDlg = new Button("Print To File - Common Dialog");
+ fileDlg.addActionListener(this);
+ printpanel.add(fileDlg);
+
+ add(printpanel, "South");
+ setSize(900, 300);
+ setVisible(true);
+ }
+
+ public static void main (String args[]) {
+ DestinationTest test = new DestinationTest();
+ }
+
+
+ public void actionPerformed(ActionEvent e) {
+
+ JobAttributes ja = new JobAttributes();
+ PageAttributes pa = new PageAttributes();
+ ja.setDestination(JobAttributes.DestinationType.FILE);
+ ja.setFileName("test_file_name.prn");
+
+ if(e.getSource()== nativeDlg) {
+ ja.setDefaultSelection(JobAttributes.DefaultSelectionType.SELECTION);
+ ja.setPageRanges(new int[][] {new int[] {2,3}, new int[] {5,6}});
+ ja.setDialog(JobAttributes.DialogType.NATIVE);
+ }
+
+ if(e.getSource()== nativeDlg2) {
+ ja.setFileName("");
+ ja.setDialog(JobAttributes.DialogType.NATIVE);
+ }
+
+ if(e.getSource()== commonRangeDlg) {
+ ja = new JobAttributes();
+ ja.setDefaultSelection(JobAttributes.DefaultSelectionType.RANGE);
+ ja.setPageRanges(new int[][] {new int[] {1,3}, new int[] {5,6}});
+ ja.setDialog(JobAttributes.DialogType.COMMON);
+ }
+
+ if (e.getSource() == fileDlg) {
+ ja = new JobAttributes();
+ ja.setDestination(JobAttributes.DestinationType.FILE);
+ ja.setDialog(JobAttributes.DialogType.COMMON);
+ }
+
+ if(e.getSource()== commonSelectionDlg) {
+ ja.setDefaultSelection(JobAttributes.DefaultSelectionType.SELECTION);
+ ja.setDialog(JobAttributes.DialogType.COMMON);
+ }
+
+ PrintJob pjob = getToolkit().getPrintJob(this,"Printing Test",ja,pa);
+ System.out.println("6293139: Chosen printer is: "+ja.getPrinter());
+ if(pjob != null) {
+
+ Graphics pg = pjob.getGraphics();
+
+ if(pg != null) {
+ //images.printAll(pg);
+ this.printAll(pg);
+ pg.dispose();
+ }
+ pjob.end();
+ }
+ }
+}
+
+class DisplayImages extends Canvas {
+
+ public void paint(Graphics g) {
+
+ g.setFont(new Font("Helvetica", Font.BOLD, 12));
+ g.drawString("PRINTING TEST", 1, 10);
+ g.drawString(" 4846344: Confirm that cancelling the native dialog will not prompt for file.", 1, 25);
+ g.drawString(" 4851365: Confirm that printing in native dialog shows test_file_name.prn as default.", 1, 40);
+ g.drawString(" 4851321: Confirm that in the Common Range dialog, page ranges is set to 1-6.", 1, 55);
+ g.drawString(" 4851316: Confirm that NPE is not thrown upon selecting Common Selection dialog.", 1, 70);
+ g.drawString(" 4863656: Confirm that no IAE is thrown when printing in native dialog.", 1, 85);
+ g.drawString(" 4864444: Confirm that the default directory in Native 2 is same as current one with no filename set.", 1, 100);
+ g.drawString(" 5046198: Confirm that the default filename in Common Range dialog when printing to a file is same as that of PrintToFile dialog.", 1, 115);
+ g.drawString(" 6293139: In Common Range dialog, change printer before printing then confirm the chosen printer.", 1, 130);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/Dialog/MediaInPrintable.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2007, 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 4869575 6361766
+ * @summary Setting orientation in the page format does not have any effect on the printout. To test 6361766, the application must exit.
+ * @run main/manual MediaInPrintable
+ */
+import java.awt.*;
+import java.awt.print.*;
+import javax.print.attribute.HashPrintRequestAttributeSet;
+import javax.print.attribute.PrintRequestAttributeSet;
+
+public class MediaInPrintable implements Printable {
+ private static Font fnt = new Font("Helvetica",Font.PLAIN,24);
+ public static void main(String[] args) {
+
+ System.out.println("arguments : native1 | native2\nExpected output :\n\tnative1 - Landscape orientation.\n\tnative2 - Legal paper is selected.");
+ if (args.length == 0) {
+ return;
+ }
+
+
+ // Get a PrinterJob
+ PrinterJob job = PrinterJob.getPrinterJob();
+ PageFormat pf = new PageFormat();
+
+ if (args[0].equals("native1")) {
+ pf.setOrientation(PageFormat.LANDSCAPE);
+ job.setPrintable(new MediaInPrintable(), pf);
+ if (job.printDialog()) {
+ // Print the job if the user didn't cancel printing
+ try {
+ job.print();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ } else if (args[0].equals("native2")) {
+ Paper p = new Paper();
+ p.setSize(612.0, 1008.0);
+ p.setImageableArea(72.0, 72.0, 468.0, 864.0);
+ pf.setPaper(p);
+
+ job.setPrintable(new MediaInPrintable(), pf);
+ if (job.printDialog()) {
+ // Print the job if the user didn't cancel printing
+ try {
+ job.print();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ //System.exit(0);
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException {
+ if (pageIndex > 0) {
+ return Printable.NO_SUCH_PAGE;
+ }
+ g.setFont(fnt);
+ g.setColor(Color.green);
+ g.drawString("Page " + (pageIndex+1), 100, 100);
+ return Printable.PAGE_EXISTS;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/Dialog/PrintApplet.html Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,29 @@
+!--
+ Copyright (c) 2007, 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.
+-->
+
+<title>PrintApplet</title>
+<h1>PrintApplet</h1>
+
+
+<applet code="PrintApplet.class" width=300 height=300>
+</applet><p>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/Dialog/PrintApplet.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2007, 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 5024549
+ @summary Pass if dialogs are modal.
+ @run applet/manual PrintApplet.html
+*/
+import java.awt.*;
+import java.awt.event.*;
+import java.applet.*;
+import java.awt.print.*;
+import javax.swing.*;
+
+public class PrintApplet extends JApplet implements Printable {
+ private JButton jButton1 = new JButton();
+
+
+ public PrintApplet() {
+ }
+
+ public void init() {
+ try {
+ jbInit();
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void jbInit() throws Exception {
+ jButton1.setText("PRINT");
+ jButton1.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ jButton1_actionPerformed(e);
+ }
+ });
+ jButton1.setBounds(new Rectangle(165, 248, 80, 30));
+ this.setSize(new Dimension(400,300));
+ this.getContentPane().setLayout(null);
+ this.getContentPane().setBackground(Color.pink);
+ this.getContentPane().add(jButton1, BorderLayout.SOUTH);
+ }
+
+ public void start() {
+ }
+
+ public void stop() {
+ }
+
+ public void destroy() {
+ }
+
+ public String getAppletInfo() {
+ return "Applet inf";
+ }
+
+ public String[][] getParameterInfo() {
+ return null;
+ }
+
+
+ public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
+ System.out.println("Calling print");
+ if (page == 0) {
+ Graphics2D g2 = (Graphics2D)g;
+ g2.translate(pf.getImageableX(), pf.getImageableY());
+ g2.setColor(Color.black);
+ g2.drawString("Hello World", 20, 100);
+
+ return Printable.PAGE_EXISTS;
+ }
+ return Printable.NO_SUCH_PAGE;
+ }
+
+
+
+ void jButton1_actionPerformed(ActionEvent e) {
+ PrinterJob printJob = null;
+ PageFormat pageFormat = null;
+ Paper prtPaper = null;
+ boolean bPrintFlg = true;
+
+
+ try{
+ printJob = PrinterJob.getPrinterJob();
+
+ }
+ catch(SecurityException se){
+
+ bPrintFlg = false;
+ }
+
+ if (bPrintFlg) {
+
+ pageFormat = printJob.pageDialog(printJob.defaultPage());
+ System.out.println("PrintApplet: pageFormat = "+pageFormat.getWidth()/72.0+" x "+pageFormat.getHeight()/72.0);
+ if (pageFormat != null) {
+
+ prtPaper = pageFormat.getPaper();
+ pageFormat.setPaper(prtPaper);
+
+
+ printJob.setPrintable(this, pageFormat);
+ }
+
+ if (printJob.printDialog()) {
+
+ try {
+ printJob.print();
+ }
+ catch (java.awt.print.PrinterException ex) {
+ ex.printStackTrace();
+ }
+
+ }
+
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/Dialog/PrintDialog.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2007, 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 6342748
+ @summary Pass if dialogs display correctly
+ @run main/manual PrintDialog
+*/
+import java.awt.print.*;
+import javax.print.attribute.*;
+
+public class PrintDialog {
+
+ public static void main(java.lang.String[] args) {
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet();
+ System.out.println("Verify page setup dialog appears correctly then cancel or OK");
+ pj.pageDialog(pSet);
+ System.out.println("Verify all tabs of print dialog appear correctly then cancel or OK");
+ pj.printDialog(pSet);
+ return;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/Dialog/PrintDlgApp.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2007, 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 4865976 7158366
+ @summary Pass if it program exits.
+ @run main/manual PrintDlgApp
+*/
+import java.awt.*;
+import java.awt.print.*;
+import javax.print.attribute.*;
+import javax.print.attribute.standard.Copies;
+import javax.print.attribute.standard.Destination;
+import java.util.Locale;
+
+import javax.print.*;
+
+class PrintDlgApp implements Printable {
+ /**
+ * Constructor
+ */
+ public PrintDlgApp() {
+ super();
+ }
+ /**
+ * Starts the application.
+ */
+ public static void main(java.lang.String[] args) {
+ PrintDlgApp pd = new PrintDlgApp();
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ System.out.println(pj);
+ PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet();
+ pSet.add(new Copies(1));
+ //PageFormat pf = pj.pageDialog(pSet);
+ PageFormat pf = new PageFormat();
+ System.out.println("Setting Printable...pf = "+pf);
+ if (pf == null) {
+ return;
+ }
+ pj.setPrintable(pd,pf);
+
+ //try { pj.setPrintService(services[0]); } catch(Exception e) { e.printStackTrace(); }
+ pSet.add(new Destination(new java.io.File("./out.prn").toURI()));
+ System.out.println("open PrintDialog..");
+ for (int i=0; i<2; i++) {
+ if (pj.printDialog(pSet)) {
+ try {
+ System.out.println("About to print the data ...");
+ pj.print(pSet);
+ System.out.println("Printed");
+ }
+ catch (PrinterException pe) {
+ pe.printStackTrace();
+ }
+ }
+ }
+
+ }
+
+ //printable interface
+ public int print(Graphics g, PageFormat pf, int pi) throws
+PrinterException {
+
+ if (pi > 0) {
+ System.out.println("pi is greater than 0");
+ return Printable.NO_SUCH_PAGE;
+ }
+ // Simply draw two rectangles
+ Graphics2D g2 = (Graphics2D)g;
+ g2.setColor(Color.black);
+ g2.translate(pf.getImageableX(), pf.getImageableY());
+ g2.drawRect(1,1,200,300);
+ g2.drawRect(1,1,25,25);
+ System.out.println("print method called "+pi);
+ return Printable.PAGE_EXISTS;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/Dialog/PrintDlgPageable.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2007, 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 4869502 4869539
+ * @summary Confirm that ToPage is populated for argument =2. Range is disabled for argument = 0.
+ * @run main/manual PrintDlgPageable
+ */
+import java.awt.*;
+import java.awt.print.*;
+import java.util.Locale;
+
+import javax.print.*;
+
+class PrintDlgPageable implements Printable {
+ public static int arg;
+ /**
+ * Constructor
+ */
+ public PrintDlgPageable() {
+ super();
+ }
+ /**
+ * Starts the application.
+ */
+ public static void main(java.lang.String[] args) {
+ if (args.length < 1) {
+ System.out.println("usage: java PrintDlgPageable { 0 | 2}");
+ return;
+ }
+ arg = Integer.parseInt(args[0]);
+ PrintDlgPageable pd = new PrintDlgPageable();
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ PageableHandler handler = new PageableHandler();
+ pj.setPageable(handler);
+
+ System.out.println("open PrintDialog..");
+ if (pj.printDialog()) {
+ try {
+ System.out.println("About to print the data ...");
+ pj.print();
+ System.out.println("Printed");
+ }
+ catch (PrinterException pe) {
+ pe.printStackTrace();
+ }
+ }
+
+ }
+
+ //printable interface
+ public int print(Graphics g, PageFormat pf, int pi) throws
+PrinterException {
+
+ /*if (pi > 0) {
+ System.out.println("pi is greater than 0");
+ return Printable.NO_SUCH_PAGE;
+ }*/
+ // Simply draw two rectangles
+ Graphics2D g2 = (Graphics2D)g;
+ g2.setColor(Color.black);
+ g2.translate(pf.getImageableX(), pf.getImageableY());
+ g2.drawRect(1,1,200,300);
+ g2.drawRect(1,1,25,25);
+ System.out.println("print method called "+pi + " Orientation "+pf.getOrientation());
+ return Printable.PAGE_EXISTS;
+ }
+}
+
+class PageableHandler implements Pageable {
+
+ PageFormat pf = new PageFormat();
+
+ public int getNumberOfPages() {
+ return PrintDlgPageable.arg;
+ //return 0;
+ }
+
+ public Printable getPrintable(int pageIndex) {
+ return new PrintDlgPageable();
+ }
+
+ public PageFormat getPageFormat(int pageIndex) {
+ System.out.println("getPageFormat called "+pageIndex);
+ if (pageIndex == 0) {
+ pf.setOrientation(PageFormat.PORTRAIT);
+ System.out.println("Orientation returned from Pageable "+findOrientation(pf.getOrientation()));
+ return pf;
+ } else {
+ pf.setOrientation(PageFormat.LANDSCAPE);
+ System.out.println("Orientation returned from Pageable "+findOrientation(pf.getOrientation()));
+ return pf;
+ }
+ }
+
+ public String findOrientation(int orient) {
+ if (orient == PageFormat.LANDSCAPE) {
+ return "LANDSCAPE";
+ }else if (orient == PageFormat.PORTRAIT) {
+ return "PORTRAIT";
+ } else if (orient == PageFormat.REVERSE_LANDSCAPE) {
+ return "REVERSE LANDSCAPE";
+ } else {
+ return null;
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/Dialog/RestoreActiveWindowTest/RestoreActiveWindowTest.html Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,43 @@
+<!--
+ Copyright (c) 2007, 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>
+<!--
+ @test
+ @bug 6365992 6379599
+ @summary REG: Showing and disposing a native print dialog makes the main frame inactive, Win32
+ @author Dmitry.Cherepanov@SUN.COM area=awt.printdialog
+ @run applet/manual=yesno RestoreActiveWindowTest.html
+ -->
+<head>
+<title>RestoreActiveWindowTest</title>
+</head>
+<body>
+
+<h1>RestoreActiveWindowTest<br>Bug ID: 6365992</h1>
+
+<p> See the dialog box (usually in upper left corner) for instructions</p>
+
+<APPLET CODE="RestoreActiveWindowTest.class" WIDTH=200 HEIGHT=200></APPLET>
+</body>
+</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/Dialog/RestoreActiveWindowTest/RestoreActiveWindowTest.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,231 @@
+/*
+ * Copyright (c) 2007, 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 6365992 6379599
+ @summary REG: Showing and disposing a native print dialog makes the main frame inactive, Win32
+ @author Dmitry.Cherepanov@SUN.COM area=awt.printdialog
+ @run applet/manual=yesno RestoreActiveWindowTest.html
+*/
+
+import java.applet.Applet;
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+import javax.print.attribute.*;
+
+public class RestoreActiveWindowTest extends Applet
+{
+ Button showBtn1 = new Button("show a native print dialog");
+ Button showBtn2 = new Button("show a native page dialog");
+
+ public void init()
+ {
+ showBtn1.addActionListener(new ActionListener(){
+ public void actionPerformed(ActionEvent ae) {
+ PrinterJob.getPrinterJob().printDialog();
+ }
+ });
+ showBtn2.addActionListener(new ActionListener(){
+ public void actionPerformed(ActionEvent ae){
+ PrinterJob.getPrinterJob().pageDialog(new PageFormat());
+ }
+ });
+
+ add(showBtn1);
+ add(showBtn2);
+
+ String[] instructions = {
+ "1.1) Click on 'show a native print dialog'. A native print dialog will come up.",
+ "1.2) Click on the 'close'(X) button. The dialog will be closed.",
+ "1.3) After the dialog closing another window should become the active window.",
+ "1.4) If there no any active window then the test failed.",
+ "2.1) Click on 'show a native page dialog'. A native page dialog will come up.",
+ "2.2) Click on the 'close'(X) button. The dialog will be closed.",
+ "2.3) After the dialog closing another window should become the active window.",
+ "2.4) If there no any active window then the test failed.",
+ "3) Test Passed."
+ };
+
+ Sysout.createDialogWithInstructions( instructions );
+
+ }//End init()
+
+ public void start ()
+ {
+ //Get things going. Request focus, set size, et cetera
+ setSize (200,200);
+ show();
+
+ }// start()
+
+ //The rest of this class is the actions which perform the test...
+
+ //Use Sysout.println to communicate with the user NOT System.out!!
+ //Sysout.println ("Something Happened!");
+
+}// class ManualYesNoTest
+
+/* Place other classes related to the test after this line */
+
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+{
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.setVisible(true);
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.setVisible(true);
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog
+{
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ setVisible(true);
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ System.out.println(messageIn);
+ }
+
+}// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/CustomPaper.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,244 @@
+/*
+ * Copyright (c) 2007, 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 4355514
+ * @bug 4385157
+ * @author Jennifer Godinez
+ * @summary Prints a rectangle to show the imageable area of a
+ * 12in x 14in custom paper size.
+ * @run main/manual CustomPaper
+ */
+
+import java.awt.*;
+import java.awt.print.*;
+import java.awt.geom.*;
+
+public class CustomPaper implements Pageable, Printable{
+
+ private static double PIXELS_PER_INCH = 72.0;
+
+ private PrinterJob printerJob;
+ private PageFormat pageFormat;
+
+ CustomPaper(){
+ printerJob = PrinterJob.getPrinterJob();
+ createPageFormat();
+ }
+
+ private void createPageFormat(){
+ pageFormat = new PageFormat();
+ Paper p = new Paper();
+ double width = 12.0*PIXELS_PER_INCH;
+ double height = 14.0*PIXELS_PER_INCH;
+ double ix = PIXELS_PER_INCH;
+ double iy = PIXELS_PER_INCH;
+ double iwidth = width - 2.0*PIXELS_PER_INCH;
+ double iheight = height - 2.0*PIXELS_PER_INCH;
+ p.setSize(width, height);
+ p.setImageableArea(ix, iy, iwidth, iheight);
+ pageFormat.setPaper(p);
+ }
+
+ public Printable getPrintable(int index){
+ return this;
+ }
+
+ public PageFormat getPageFormat(int index){
+ return pageFormat;
+ }
+
+ public int getNumberOfPages(){
+ return 1;
+ }
+
+ public void print(){
+ if(printerJob.printDialog())
+ {
+ try{
+ printerJob.setPageable(this);
+ printerJob.print();
+ }catch(Exception e){e.printStackTrace();}
+ }
+
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex){
+ if(pageIndex == 0){
+ Graphics2D g2 = (Graphics2D)g;
+ Rectangle2D r = new Rectangle2D.Double(pf.getImageableX(),
+ pf.getImageableY(),
+ pf.getImageableWidth(),
+ pf.getImageableHeight());
+ g2.setStroke(new BasicStroke(3.0f));
+ g2.draw(r);
+ return PAGE_EXISTS;
+ }else{
+ return NO_SUCH_PAGE;
+ }
+ }
+
+ public static void main(String[] args){
+
+ String[] instructions =
+ {
+ "You must have a printer that supports custom paper size of ",
+ "at least 12 x 14 inches to perform this test. It requires",
+ "user interaction and you must have a 12 x 14 inch paper available.",
+ " ",
+ "To test bug ID 4385157, click OK on print dialog box to print.",
+ " ",
+ "To test bug ID 4355514, select the printer in the Print Setup dialog and add a ",
+ "custom paper size under Printer properties' Paper selection menu. ",
+ "Set the dimension to width=12 inches and height=14 inches.",
+ "Select this custom paper size before proceeding to print.",
+ " ",
+ "Visual inspection of the one-page printout is needed. A passing",
+ "test will print a rectangle of the imageable area which is approximately",
+ "10 x 12 inches.",
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ CustomPaper pt = new CustomPaper();
+ pt.print();
+ //System.exit (0);
+ }
+
+}
+
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/NullPaper.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,423 @@
+/*
+ * Copyright (c) 2007, 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 4199506
+ @summary java.awt.print.PageFormat.setpaper(Paper paper)
+ assertion test fails by not throwing
+ NullPointerException when a null paper instance is
+ passed as argument and this is specified in the doc.
+ @author rbi: area=PageFormat
+ @run main NullPaper
+*/
+
+
+//*** global search and replace NullPaper with name of the test ***
+
+/**
+ * NullPaper.java
+ *
+ * summary: java.awt.print.PageFormat.setpaper(Paper paper)
+ assertion test fails by not throwing
+ NullPointerException when a null paper instance is
+ passed as argument and this is specified in the doc.
+
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+
+// This test is a "main" test as applets would need Runtime permission
+// "queuePrintJob".
+
+public class NullPaper {
+
+ private static void init()
+ {
+ //*** Create instructions for the user here ***
+
+ String[] instructions =
+ {
+ "This test should throw a NullPointerException. ",
+ "If the NullPointerException is correctly thrown ",
+ "by the call to setPaper() then the test succeeds. ",
+ "If no exception is thrown by setPaper() or if an ",
+ "exception other than NullPointerException is thrown ",
+ "then the test fails."
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ boolean settingNullWorked = false;
+
+ try {
+ /* Setting the paper to null should throw an exception.
+ * The bug was the exception was not being thrown.
+ */
+ new PageFormat().setPaper(null);
+ settingNullWorked = true;
+
+ /* If the test succeeds we'll end up here, so write
+ * to standard out.
+ */
+ } catch (NullPointerException e) {
+ pass();
+
+ /* The test failed if we end up here because an exception
+ * other than the one we were expecting was thrown.
+ */
+ } catch (Exception e) {
+ fail("Instead of the expected NullPointerException, '" + e + "' was thrown.");
+ }
+
+ if (settingNullWorked) {
+ fail("The expected NullPointerException was not thrown");
+ }
+
+ }//End init()
+
+
+ /*****************************************************
+ Standard Test Machinery Section
+ DO NOT modify anything in this section -- it's a
+ standard chunk of code which has all of the
+ synchronisation necessary for the test harness.
+ By keeping it the same in all tests, it is easier
+ to read and understand someone else's test, as
+ well as insuring that all tests behave correctly
+ with the test harness.
+ There is a section following this for test-defined
+ classes
+ ******************************************************/
+ private static boolean theTestPassed = false;
+ private static boolean testGeneratedInterrupt = false;
+ private static String failureMessage = "";
+
+ private static Thread mainThread = null;
+
+ private static int sleepTime = 300000;
+
+ public static void main( String args[] ) throws InterruptedException
+ {
+ mainThread = Thread.currentThread();
+ try
+ {
+ init();
+ }
+ catch( TestPassedException e )
+ {
+ //The test passed, so just return from main and harness will
+ // interepret this return as a pass
+ return;
+ }
+ //At this point, neither test passed nor test failed has been
+ // called -- either would have thrown an exception and ended the
+ // test, so we know we have multiple threads.
+
+ //Test involves other threads, so sleep and wait for them to
+ // called pass() or fail()
+ try
+ {
+ Thread.sleep( sleepTime );
+ //Timed out, so fail the test
+ throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
+ }
+ catch (InterruptedException e)
+ {
+ if( ! testGeneratedInterrupt ) throw e;
+
+ //reset flag in case hit this code more than once for some reason (just safety)
+ testGeneratedInterrupt = false;
+ if ( theTestPassed == false )
+ {
+ throw new RuntimeException( failureMessage );
+ }
+ }
+
+ }//main
+
+ public static synchronized void setTimeoutTo( int seconds )
+ {
+ sleepTime = seconds * 1000;
+ }
+
+ public static synchronized void pass()
+ {
+ Sysout.println( "The test passed." );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //first check if this is executing in main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //Still in the main thread, so set the flag just for kicks,
+ // and throw a test passed exception which will be caught
+ // and end the test.
+ theTestPassed = true;
+ throw new TestPassedException();
+ }
+ //pass was called from a different thread, so set the flag and interrupt
+ // the main thead.
+ theTestPassed = true;
+ testGeneratedInterrupt = true;
+ mainThread.interrupt();
+ }//pass()
+
+ public static synchronized void fail()
+ {
+ //test writer didn't specify why test failed, so give generic
+ fail( "it just plain failed! :-)" );
+ }
+
+ public static synchronized void fail( String whyFailed )
+ {
+ Sysout.println( "The test failed: " + whyFailed );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //check if this called from main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //If main thread, fail now 'cause not sleeping
+ throw new RuntimeException( whyFailed );
+ }
+ theTestPassed = false;
+ testGeneratedInterrupt = true;
+ failureMessage = whyFailed;
+ mainThread.interrupt();
+ }//fail()
+
+ }// class NullPaper
+
+//This exception is used to exit from any level of call nesting
+// when it's determined that the test has passed, and immediately
+// end the test.
+class TestPassedException extends RuntimeException
+ {
+ }
+
+//*********** End Standard Test Machinery Section **********
+
+
+//************ Begin classes defined for the test ****************
+
+// make listeners in a class defined here, and instantiate them in init()
+
+/* Example of a class which may be written as part of a test
+class NewClass implements anInterface
+ {
+ static int newVar = 0;
+
+ public void eventDispatched(AWTEvent e)
+ {
+ //Counting events to see if we get enough
+ eventCount++;
+
+ if( eventCount == 20 )
+ {
+ //got enough events, so pass
+
+ NullPaper.pass();
+ }
+ else if( tries == 20 )
+ {
+ //tried too many times without getting enough events so fail
+
+ NullPaper.fail();
+ }
+
+ }// eventDispatched()
+
+ }// NewClass class
+
+*/
+
+
+//************** End classes defined for the test *******************
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog implements ActionListener
+ {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+ Panel buttonP = new Panel();
+ Button passB = new Button( "pass" );
+ Button failB = new Button( "fail" );
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ passB = new Button( "pass" );
+ passB.setActionCommand( "pass" );
+ passB.addActionListener( this );
+ buttonP.add( "East", passB );
+
+ failB = new Button( "fail" );
+ failB.setActionCommand( "fail" );
+ failB.addActionListener( this );
+ buttonP.add( "West", failB );
+
+ add( "South", buttonP );
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ //catch presses of the passed and failed buttons.
+ //simply call the standard pass() or fail() static methods of
+ //NullPaper
+ public void actionPerformed( ActionEvent e )
+ {
+ if( e.getActionCommand() == "pass" )
+ {
+ NullPaper.pass();
+ }
+ else
+ {
+ NullPaper.fail();
+ }
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/Orient.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,460 @@
+/*
+ * Copyright (c) 2007, 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 4236095
+ @summary Confirm that the you get three pages of output, one
+ each in portrait, landscape, and reverse landscape
+ orientations.
+ @author rbi: area=PageFormat
+ @run main/manual Orient
+*/
+
+
+//*** global search and replace Orient with name of the test ***
+
+/**
+ * Orient.java
+ *
+ * summary:
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+
+// This test is a "main" test as applets would need Runtime permission
+// "queuePrintJob".
+
+public class Orient implements Printable {
+
+ private static void init()
+ {
+ //*** Create instructions for the user here ***
+
+ String[] instructions =
+ {
+ "On-screen inspection is not possible for this printing-specific",
+ "test therefore its only output is three printed pages.",
+ "To be able to run this test it is required to have a default",
+ "printer configured in your user environment.",
+ "",
+ "Visual inspection of the printed page is needed. A passing",
+ "test will print three pages each containing a large oval ",
+ "with the text describing the orientation: PORTRAIT, LANDSCAPE",
+ "or REVERSE_LANDSCAPE, inside of it. The first page will ",
+ "be emitted in portait orientation, the second page in landscape ",
+ "orientation and the third page in reverse-landscape orientation. ",
+ "On each page the oval will be wholly within the imageable area ",
+ "of the page. In a failing test the oval on the third page ",
+ "will be clipped against the imageable area.",
+ "Axes will indicate the direction of increasing X and Y"
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+
+ Book book = new Book();
+
+ // Page 1
+ PageFormat portrait = pjob.defaultPage();
+ portrait.setOrientation(PageFormat.PORTRAIT);
+ book.append(new Orient(), portrait);
+
+ // Page 2
+ PageFormat landscape = pjob.defaultPage();
+ landscape.setOrientation(PageFormat.LANDSCAPE);
+ book.append(new Orient(), landscape);
+
+ // Page 3
+ PageFormat reverseLandscape = pjob.defaultPage();
+ reverseLandscape.setOrientation(PageFormat.REVERSE_LANDSCAPE);
+ book.append(new Orient(), reverseLandscape);
+
+ pjob.setPageable(book);
+ try {
+ pjob.print();
+ } catch (PrinterException e) {
+ e.printStackTrace();
+ }
+
+ }//End init()
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pf.getImageableX(), pf.getImageableY());
+ drawGraphics(g2d, pf);
+ return Printable.PAGE_EXISTS;
+ }
+
+ void drawGraphics(Graphics2D g, PageFormat pf) {
+ double iw = pf.getImageableWidth();
+ double ih = pf.getImageableHeight();
+
+ g.setColor(Color.black);
+ String orientation;
+ switch (pf.getOrientation()) {
+ case PageFormat.PORTRAIT : orientation = "PORTRAIT";
+ break;
+ case PageFormat.LANDSCAPE : orientation = "LANDSCAPE";
+ break;
+ case PageFormat.REVERSE_LANDSCAPE :
+ orientation = "REVERSE_LANDSCAPE";
+ break;
+ default : orientation = "INVALID";
+ }
+ g.drawString(orientation, 100, 300);
+ g.draw(new Ellipse2D.Double(0, 0, iw, ih));
+ g.drawString("(0,0)", 5,15);
+ g.drawLine(0,0,300,0);
+ g.drawString("X", 300,15);
+ g.drawLine(0,0,0,300);
+ g.drawString("Y",5,300);
+ }
+
+
+ /*****************************************************
+ Standard Test Machinery Section
+ DO NOT modify anything in this section -- it's a
+ standard chunk of code which has all of the
+ synchronisation necessary for the test harness.
+ By keeping it the same in all tests, it is easier
+ to read and understand someone else's test, as
+ well as insuring that all tests behave correctly
+ with the test harness.
+ There is a section following this for test-defined
+ classes
+ ******************************************************/
+ private static boolean theTestPassed = false;
+ private static boolean testGeneratedInterrupt = false;
+ private static String failureMessage = "";
+
+ private static Thread mainThread = null;
+
+ private static int sleepTime = 300000;
+
+ public static void main( String args[] ) throws InterruptedException
+ {
+ mainThread = Thread.currentThread();
+ try
+ {
+ init();
+ }
+ catch( TestPassedException e )
+ {
+ //The test passed, so just return from main and harness will
+ // interepret this return as a pass
+ return;
+ }
+ //At this point, neither test passed nor test failed has been
+ // called -- either would have thrown an exception and ended the
+ // test, so we know we have multiple threads.
+
+ //Test involves other threads, so sleep and wait for them to
+ // called pass() or fail()
+ try
+ {
+ Thread.sleep( sleepTime );
+ //Timed out, so fail the test
+ throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
+ }
+ catch (InterruptedException e)
+ {
+ if( ! testGeneratedInterrupt ) throw e;
+
+ //reset flag in case hit this code more than once for some reason (just safety)
+ testGeneratedInterrupt = false;
+ if ( theTestPassed == false )
+ {
+ throw new RuntimeException( failureMessage );
+ }
+ }
+
+ }//main
+
+ public static synchronized void setTimeoutTo( int seconds )
+ {
+ sleepTime = seconds * 1000;
+ }
+
+ public static synchronized void pass()
+ {
+ Sysout.println( "The test passed." );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //first check if this is executing in main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //Still in the main thread, so set the flag just for kicks,
+ // and throw a test passed exception which will be caught
+ // and end the test.
+ theTestPassed = true;
+ throw new TestPassedException();
+ }
+ //pass was called from a different thread, so set the flag and interrupt
+ // the main thead.
+ theTestPassed = true;
+ testGeneratedInterrupt = true;
+ mainThread.interrupt();
+ }//pass()
+
+ public static synchronized void fail()
+ {
+ //test writer didn't specify why test failed, so give generic
+ fail( "it just plain failed! :-)" );
+ }
+
+ public static synchronized void fail( String whyFailed )
+ {
+ Sysout.println( "The test failed: " + whyFailed );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //check if this called from main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //If main thread, fail now 'cause not sleeping
+ throw new RuntimeException( whyFailed );
+ }
+ theTestPassed = false;
+ testGeneratedInterrupt = true;
+ failureMessage = whyFailed;
+ mainThread.interrupt();
+ }//fail()
+
+ }// class Orient
+
+//This exception is used to exit from any level of call nesting
+// when it's determined that the test has passed, and immediately
+// end the test.
+class TestPassedException extends RuntimeException
+ {
+ }
+
+//*********** End Standard Test Machinery Section **********
+
+
+//************ Begin classes defined for the test ****************
+
+// make listeners in a class defined here, and instantiate them in init()
+
+/* Example of a class which may be written as part of a test
+class NewClass implements anInterface
+ {
+ static int newVar = 0;
+
+ public void eventDispatched(AWTEvent e)
+ {
+ //Counting events to see if we get enough
+ eventCount++;
+
+ if( eventCount == 20 )
+ {
+ //got enough events, so pass
+
+ Orient.pass();
+ }
+ else if( tries == 20 )
+ {
+ //tried too many times without getting enough events so fail
+
+ Orient.fail();
+ }
+
+ }// eventDispatched()
+
+ }// NewClass class
+
+*/
+
+
+//************** End classes defined for the test *******************
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog implements ActionListener
+ {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+ Panel buttonP = new Panel();
+ Button passB = new Button( "pass" );
+ Button failB = new Button( "fail" );
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ passB = new Button( "pass" );
+ passB.setActionCommand( "pass" );
+ passB.addActionListener( this );
+ buttonP.add( "East", passB );
+
+ failB = new Button( "fail" );
+ failB.setActionCommand( "fail" );
+ failB.addActionListener( this );
+ buttonP.add( "West", failB );
+
+ add( "South", buttonP );
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ //catch presses of the passed and failed buttons.
+ //simply call the standard pass() or fail() static methods of
+ //Orient
+ public void actionPerformed( ActionEvent e )
+ {
+ if( e.getActionCommand() == "pass" )
+ {
+ Orient.pass();
+ }
+ else
+ {
+ Orient.fail();
+ }
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/PDialogTest.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2007, 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 4855801
+ * @summary Changing margins in the page format does not have any effect
+ * @run main/manual PDialogTest
+ */
+import java.awt.print.*;
+import javax.print.attribute.*;
+import javax.print.attribute.standard.*;
+
+public class PDialogTest
+{
+
+ public static void main(String[] args) {
+ PageFormat page=new PageFormat();
+ while(true){
+ page=java.awt.print.PrinterJob.getPrinterJob().pageDialog(page);
+ }
+
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/PageSetupDialog.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,353 @@
+/*
+ * Copyright (c) 2007, 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 4197377
+ * @bug 4299145
+ * @bug 6358747
+ * @bug 6574633
+ * @summary Page setup dialog settings
+ * @author prr
+ * @run main/manual PageSetupDialog
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+public class PageSetupDialog extends Frame implements Printable {
+
+ PrinterJob myPrinterJob;
+ PageFormat myPageFormat;
+ Label pw, ph, pglm, pgiw, pgrm, pgtm, pgih, pgbm;
+ Label myWidthLabel;
+ Label myHeightLabel;
+ Label myImageableXLabel;
+ Label myImageableYLabel;
+ Label myImageableRightLabel;
+ Label myImageableBottomLabel;
+ Label myImageableWidthLabel;
+ Label myImageableHeightLabel;
+ Label myOrientationLabel;
+ Checkbox reverseCB;
+ boolean alpha = false;
+ boolean reverse = false;
+
+ protected void displayPageFormatAttributes() {
+
+ myWidthLabel.setText("Format Width = " + (float)myPageFormat.getWidth());
+ myHeightLabel.setText("Format Height = " + (float)myPageFormat.getHeight());
+ myImageableXLabel.setText
+ ("Format Left Margin = " + (float)myPageFormat.getImageableX());
+ myImageableRightLabel.setText
+ ("Format Right Margin = " + (float)(myPageFormat.getWidth() -
+ (myPageFormat.getImageableX() + myPageFormat.getImageableWidth())));
+ myImageableWidthLabel.setText
+ ("Format ImageableWidth = " + (float)myPageFormat.getImageableWidth());
+ myImageableYLabel.setText
+ ("Format Top Margin = " + (float)myPageFormat.getImageableY());
+ myImageableBottomLabel.setText
+ ("Format Bottom Margin = " + (float)(myPageFormat.getHeight() -
+ (myPageFormat.getImageableY() + myPageFormat.getImageableHeight())));
+ myImageableHeightLabel.setText
+ ("Format ImageableHeight = " + (float)myPageFormat.getImageableHeight());
+ int o = myPageFormat.getOrientation();
+ if (o == PageFormat.LANDSCAPE && reverse) {
+ o = PageFormat.REVERSE_LANDSCAPE;
+ myPageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE);
+ } else if (o == PageFormat.REVERSE_LANDSCAPE && !reverse) {
+ o = PageFormat.LANDSCAPE;
+ myPageFormat.setOrientation(PageFormat.LANDSCAPE);
+ }
+ myOrientationLabel.setText
+ ("Format Orientation = " +
+ (o == PageFormat.PORTRAIT ? "PORTRAIT" :
+ o == PageFormat.LANDSCAPE ? "LANDSCAPE" :
+ o == PageFormat.REVERSE_LANDSCAPE ? "REVERSE_LANDSCAPE" :
+ "<invalid>"));
+ Paper p = myPageFormat.getPaper();
+ pw.setText("Paper Width = " + (float)p.getWidth());
+ ph.setText("Paper Height = " + (float)p.getHeight());
+ pglm.setText("Paper Left Margin = " + (float)p.getImageableX());
+ pgiw.setText("Paper Imageable Width = " + (float)p.getImageableWidth());
+ pgrm.setText("Paper Right Margin = " +
+ (float)(p.getWidth() - (p.getImageableX()+p.getImageableWidth())));
+ pgtm.setText("Paper Top Margin = " + (float)p.getImageableY());
+ pgih.setText("Paper Imageable Height = " + (float)p.getImageableHeight());
+ pgbm.setText("Paper Bottom Margin = " +
+ (float)(p.getHeight() - (p.getImageableY()+p.getImageableHeight())));
+ }
+
+ public PageSetupDialog() {
+ super ("Page Dialog Test");
+ myPrinterJob = PrinterJob.getPrinterJob();
+ myPageFormat = new PageFormat();
+ Paper p = new Paper();
+ double margin = 1.5*72;
+ p.setImageableArea(margin, margin,
+ p.getWidth()-2*margin, p.getHeight()-2*margin);
+ myPageFormat.setPaper(p);
+ Panel c = new Panel();
+ c.setLayout (new GridLayout (9, 2, 0, 0));
+ c.add (reverseCB = new Checkbox("reverse if landscape"));
+ c.add (myOrientationLabel = new Label());
+ c.add (myWidthLabel = new Label());
+ c.add (pw = new Label());
+ c.add (myImageableXLabel = new Label());
+ c.add (pglm = new Label());
+ c.add (myImageableRightLabel = new Label());
+ c.add (pgrm = new Label());
+ c.add (myImageableWidthLabel = new Label());
+ c.add (pgiw = new Label());
+ c.add (myHeightLabel = new Label());
+ c.add (ph = new Label());
+ c.add (myImageableYLabel = new Label());
+ c.add (pgtm = new Label());
+ c.add (myImageableHeightLabel = new Label());
+ c.add (pgih = new Label());
+ c.add (myImageableBottomLabel = new Label());
+ c.add (pgbm = new Label());
+
+ reverseCB.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ reverse = e.getStateChange() == ItemEvent.SELECTED;
+ int o = myPageFormat.getOrientation();
+ if (o == PageFormat.LANDSCAPE ||
+ o == PageFormat.REVERSE_LANDSCAPE) {
+ displayPageFormatAttributes();
+ }
+ }
+ });
+
+ add("Center", c);
+ displayPageFormatAttributes();
+ Panel panel = new Panel();
+ Button pageButton = new Button ("Page Setup...");
+ pageButton.addActionListener(new ActionListener() {
+ public void actionPerformed (ActionEvent e) {
+ myPageFormat = myPrinterJob.pageDialog (myPageFormat);
+ displayPageFormatAttributes();
+ }
+ });
+ Button printButton = new Button ("Print ...");
+ printButton.addActionListener(new ActionListener() {
+ public void actionPerformed (ActionEvent e) {
+ try {
+ if (myPrinterJob.printDialog()) {
+ myPrinterJob.setPrintable(PageSetupDialog.this,
+ myPageFormat);
+ alpha = false;
+ myPrinterJob.print();
+ }
+ } catch (PrinterException pe ) {
+ }
+ }
+ });
+ Button printAlphaButton = new Button ("Print w/Alpha...");
+ printAlphaButton.addActionListener(new ActionListener() {
+ public void actionPerformed (ActionEvent e) {
+ try {
+ if (myPrinterJob.printDialog()) {
+ myPrinterJob.setPrintable(PageSetupDialog.this,
+ myPageFormat);
+ alpha = true;
+ myPrinterJob.print();
+ }
+ } catch (PrinterException pe ) {
+ }
+ }
+ });
+ panel.add (pageButton);
+ panel.add (printButton);
+ panel.add (printAlphaButton);
+ add("South", panel);
+ addWindowListener (new WindowAdapter() {
+ public void windowClosing (WindowEvent e) {
+ dispose();
+ System.exit (0);
+ }
+
+ });
+ //setSize (280, 550);
+ pack();
+ setVisible (true);
+ }
+
+ public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
+
+ if (pageIndex > 0) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ Graphics2D g2d = (Graphics2D)graphics;
+ g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
+ g2d.drawString("ORIGIN("+pageFormat.getImageableX()+","+
+ pageFormat.getImageableY()+")", 20, 20);
+ g2d.drawString("X THIS WAY", 200, 50);
+ g2d.drawString("Y THIS WAY", 60 , 200);
+ g2d.drawString("Graphics is " + g2d.getClass().getName(), 100, 100);
+ g2d.drawRect(0,0,(int)pageFormat.getImageableWidth(),
+ (int)pageFormat.getImageableHeight());
+ if (alpha) {
+ g2d.setColor(new Color(0,0,255,192));
+ } else {
+ g2d.setColor(Color.blue);
+ }
+ g2d.drawRect(1,1,(int)pageFormat.getImageableWidth()-2,
+ (int)pageFormat.getImageableHeight()-2);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public static void main( String[] args) {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test",
+ "This test is very flexible and requires much interaction.",
+ "If the platform print dialog supports it, adjust orientation",
+ "and margins and print pages and compare the results with the",
+ "request."
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ new PageSetupDialog();
+ }
+
+}
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/ReverseLandscapeTest.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2007, 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 4254954
+ * @summary PageFormat would fail on solaris when setting orientation
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+public class ReverseLandscapeTest extends Frame {
+
+ private TextCanvas c;
+
+ public static void main(String args[]) {
+ ReverseLandscapeTest f = new ReverseLandscapeTest();
+ f.show();
+ }
+
+ public ReverseLandscapeTest() {
+ super("JDK 1.2 Text Printing");
+
+ c = new TextCanvas();
+ add("Center", c);
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ PageFormat pf = pj.defaultPage();
+ pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
+
+ // This code can be added if one wishes to test printing
+// pf = pj.pageDialog(pf);
+
+// if (pj != null && pj.printDialog()) {
+
+// pj.setPrintable(c, pf);
+// try {
+// pj.print();
+// } catch (PrinterException pe) {
+// } finally {
+// System.err.println("PRINT RETURNED");
+// }
+// }
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+
+ pack();
+ }
+
+ class TextCanvas extends Panel implements Printable {
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+ int iw = getWidth();
+ int ih = getHeight();
+ Graphics2D g2d = (Graphics2D)g;
+
+ if (pgIndex > 0)
+ return Printable.NO_SUCH_PAGE;
+
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+ g2d.translate(iw/2, ih/2);
+ g2d.setFont(new Font("Times",Font.PLAIN, 12));
+ g2d.setPaint(new Color(0,0,0));
+ g2d.setStroke(new BasicStroke(1f));
+ g2d.drawString("Print REVERSE_LANDSCAPE", 30, 40);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public void paint(Graphics g) {
+ g.drawString("Print REVERSE_LANDSCAPE", 30, 40);
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(250, 100);
+ }
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/SetOrient.html Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,48 @@
+<!--
+ Copyright (c) 2007, 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.
+-->
+
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<!--
+ @test
+ @bug 4186119
+ @summary Confirm that the clip and transform of the Graphics2D is
+ affected by the landscape orientation of the PageFormat.
+ @run applet/manual=yesno SetOrient.html
+ -->
+<html>
+ <head>
+ <title>SetOrient</title>
+ </head>
+
+ <body>
+This test prints two pages and sends them to the printer.
+One page is in PORTRAIT orientation and the other is in LANDSCAPE
+orientation. On each page it draws an ellipse inscribed in the clip
+boundary established by the PrinterJob. The ellipse should fill the
+page within the bounds established by the default margins and not
+extend off any end or side of the page. Also, the string "Portrait"
+or "Landscape" should be oriented correctly.
+
+ <applet code="SetOrient.class" width=200 height=200></applet>
+ </body>
+</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/SetOrient.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2007, 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.
+ */
+
+/**
+ * @bug 4186119: setting orientation does not affect printer
+ * @summary Confirm that the clip and transform of the Graphics2D is
+ * affected by the landscape orientation of the PageFormat.
+ * @run applet/manual=yesno SetOrient.html
+ */
+
+import java.awt.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import java.applet.Applet;
+
+public class SetOrient extends Applet implements Printable {
+ PrinterJob pjob;
+
+ public void init() {
+ pjob = PrinterJob.getPrinterJob();
+
+ Book book = new Book();
+ PageFormat pf = pjob.defaultPage();
+ pf.setOrientation(PageFormat.PORTRAIT);
+ book.append(this, pf);
+ pf = pjob.defaultPage();
+ pf.setOrientation(PageFormat.LANDSCAPE);
+ book.append(this, pf);
+ pjob.setPageable(book);
+
+ try {
+ pjob.print();
+ } catch (PrinterException e) {
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+ Graphics2D g2d = (Graphics2D)g;
+ drawGraphics(g2d, pf);
+ return Printable.PAGE_EXISTS;
+ }
+
+ void drawGraphics(Graphics2D g, PageFormat pf) {
+ double ix = pf.getImageableX();
+ double iy = pf.getImageableY();
+ double iw = pf.getImageableWidth();
+ double ih = pf.getImageableHeight();
+
+ g.setColor(Color.black);
+ g.drawString(((pf.getOrientation() == PageFormat.PORTRAIT)
+ ? "Portrait" : "Landscape"),
+ (int) (ix+iw/2), (int) (iy+ih/2));
+ g.draw(new Ellipse2D.Double(ix, iy, iw, ih));
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/SmallPaperPrinting.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2007, 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.*;
+ import java.awt.print.*;
+
+ public class SmallPaperPrinting
+ {
+ public static void main(String args[])
+ {
+ System.out.println("----------------- Instructions --------------------");
+ System.out.println("Arguments: (none) - paper width=1, height=.0001");
+ System.out.println(" 1 - paper width=.0001, height=1");
+ System.out.println(" 2 - paper width=-1, height=1");
+ System.out.println("A passing test should catch a PrinterException");
+ System.out.println("and should display \"Print error: (exception msg)\".");
+ System.out.println("---------------------------------------------------\n");
+ PrinterJob job = PrinterJob.getPrinterJob();
+ PageFormat format = job.defaultPage();
+ Paper paper = format.getPaper();
+
+ double w = 1, h = .0001; // Generates ArithmeticException: / by zero.
+ if(args.length > 0 && args[0].equals("1")) {
+ w = .0001; h = 1; } // Generates IllegalArgumentException.
+ else if(args.length > 0 && args[0].equals("2")) {
+ w = -1; h = 1; } // Generates NegativeArraySizeException.
+ paper.setSize(w, h);
+ paper.setImageableArea(0, 0, w, h);
+ format.setPaper(paper);
+ job.setPrintable(
+ new Printable() {
+ public int print(Graphics g, PageFormat page_format, int page) {
+ return NO_SUCH_PAGE;
+ }
+ }, format);
+
+ try {
+ job.print(); }
+ catch(PrinterException e) {
+ System.err.println("Print error:\n" + e.getMessage()); // Passing test!
+ }
+ }
+ }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PageFormat/ValidateCustom.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2007, 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 4414987
+ * @author Jennifer Godinez
+ * @summary Displays width & height of validated custom paper size
+ * @run main/manual ValidateCustom
+ */
+import java.awt.*;
+import java.awt.print.*;
+import java.awt.geom.*;
+import javax.swing.*;
+
+public class ValidateCustom implements Pageable, Printable{
+
+ private static double PIXELS_PER_INCH = 72.0;
+ private static double WIDTH = 17.0; //width of paper in inches
+ private static double LENGTH = 24.0; //length of paper in inches
+ private static boolean VALIDATE = true;
+
+ private PrinterJob printerJob;
+ private PageFormat pageFormat;
+
+ ValidateCustom(){
+ printerJob = PrinterJob.getPrinterJob();
+ createPageFormat();
+ }
+
+ private void createPageFormat(){
+ pageFormat = new PageFormat();
+ Paper p = new Paper();
+ double width = WIDTH*PIXELS_PER_INCH;
+ double height = LENGTH*PIXELS_PER_INCH;
+ double ix = PIXELS_PER_INCH;
+ double iy = PIXELS_PER_INCH;
+ double iwidth = width - 2.0*PIXELS_PER_INCH;
+ double iheight = height - 2.0*PIXELS_PER_INCH;
+ p.setSize(width, height);
+ p.setImageableArea(ix, iy, iwidth, iheight);
+ pageFormat.setPaper(p);
+ }
+
+ public Printable getPrintable(int index){
+ return this;
+ }
+
+ public PageFormat getPageFormat(int index){
+ return pageFormat;
+ }
+
+ public int getNumberOfPages(){
+ return 1;
+ }
+
+ private void printPaperSize(PageFormat pf){
+ Paper p = pf.getPaper();
+ System.out.println("paper size = ("+p.getWidth()+", "+p.getHeight()+")");
+ }
+
+ public void print(){
+ //if(printerJob.printDialog())
+ {
+ try{
+ //printPaperSize(pageFormat);
+ if(VALIDATE){
+ this.pageFormat = printerJob.validatePage(this.pageFormat);
+ }
+ printPaperSize(pageFormat);
+ //printerJob.setPageable(this);
+ //printerJob.print();
+ }catch(Exception e){e.printStackTrace();}
+ }
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex){
+ if(pageIndex == 0){
+ Graphics2D g2 = (Graphics2D)g;
+ Rectangle2D r = new Rectangle2D.Double(PIXELS_PER_INCH, PIXELS_PER_INCH, PIXELS_PER_INCH, PIXELS_PER_INCH);
+ g2.setStroke(new BasicStroke(1.0f));
+ g2.draw(r);
+ return PAGE_EXISTS;
+ }else{
+ return NO_SUCH_PAGE;
+ }
+ }
+
+ public static void main(String[] args){
+ System.out.println("-----------------instructions--------------------");
+ System.out.println("You must have a printer installed in your system \nthat supports custom paper sizes in order to run this test.");
+ System.out.println("Passing test will display the correct width & height\nof custom paper in 1/72nds of an inch.\n");
+ System.out.println("-------------------------------------------------");
+ ValidateCustom pt = new ValidateCustom();
+ pt.print();
+ try{
+ System.in.read();
+ }catch(Exception e){}
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/Cancel/PrinterJobCancel.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,238 @@
+/*
+ * Copyright (c) 2007, 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 4245280
+ * @summary PrinterJob not cancelled when PrinterJob.cancel() is used
+ * @author prr
+ * @run main/manual PrinterJobCancel
+ */
+
+import java.awt.* ;
+import java.awt.print.* ;
+
+public class PrinterJobCancel extends Thread implements Printable {
+
+ PrinterJob pj ;
+ boolean okayed;
+
+ public static void main ( String args[] ) {
+
+ String[] instructions =
+ {
+ "Test that print job cancellation works.",
+ "You must have a printer available to perform this test.",
+ "This test silently starts a print job and while the job is",
+ "still being printed, cancels the print job",
+ "You should see a message on System.out that the job",
+ "was properly cancelled.",
+ "You will need to kill the application manually since regression",
+ "tests apparently aren't supposed to call System.exit()"
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJobCancel pjc = new PrinterJobCancel() ;
+
+ if (pjc.okayed) {
+ pjc.start();
+ try {
+ Thread.sleep(5000);
+ pjc.pj.cancel();
+ } catch ( InterruptedException e ) {
+ }
+ }
+ }
+
+ public PrinterJobCancel() {
+
+ pj = PrinterJob.getPrinterJob() ;
+ pj.setPrintable(this);
+ okayed = pj.printDialog();
+ }
+
+ public void run() {
+ boolean cancelWorked = false;
+ try {
+ pj.print() ;
+ }
+ catch ( PrinterAbortException paex ) {
+ cancelWorked = true;
+ System.out.println("Job was properly cancelled and we");
+ System.out.println("got the expected PrintAbortException");
+ }
+ catch ( PrinterException prex ) {
+ System.out.println("This is wrong .. we shouldn't be here");
+ System.out.println("Looks like a test failure");
+ prex.printStackTrace() ;
+ //throw prex;
+ }
+ finally {
+ System.out.println("DONE PRINTING");
+ if (!cancelWorked) {
+ System.out.println("Looks like the test failed - we didn't get");
+ System.out.println("the expected PrintAbortException ");
+ }
+ }
+ //System.exit(0);
+ }
+
+ public int print(Graphics g, PageFormat pagef, int pidx) {
+
+ if (pidx > 5) {
+ return( Printable.NO_SUCH_PAGE ) ;
+ }
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pagef.getImageableX(), pagef.getImageableY());
+ g2d.setColor(Color.black);
+
+ g2d.drawString(("This is page"+(pidx+1)), 60 , 80);
+ // Need to slow things down a bit .. important not to try this
+ // on the event dispathching thread of course.
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ }
+
+ return ( Printable.PAGE_EXISTS );
+ }
+
+}
+
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/CheckAccess.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2007, 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 4151121
+ * @summary Confirm that PrinterJob.getPrinterJob is access checked.
+ * @author Graham Hamilton
+ */
+
+import java.awt.print.*;
+import java.security.*;
+
+public class CheckAccess {
+
+ static boolean verbose;
+
+ private static void println(String mess) {
+ if (verbose) {
+ System.err.println(mess);
+ }
+ }
+
+ /**
+ * SecurityManager that rejects all print requests,
+ * but allows everything else.
+ */
+ static class PrintHater extends SecurityManager {
+
+ public void checkPermission(Permission p) {
+ // We're easy.
+ }
+
+ public void checkPrintJobAccess() {
+ throw new SecurityException("No way!");
+ }
+ }
+
+ public static void main(String argv[]) {
+
+ if (argv.length > 0 && argv[0].equals("-v")) {
+ verbose = true;
+ }
+
+ // Try to install our own security manager.
+ try {
+ SecurityManager sm = new PrintHater();
+ println("Installing PrintHater security manager");
+ System.setSecurityManager(sm);
+ println("Installed security manager OK");
+
+ } catch (Throwable th) {
+ System.err.println("Failed to install SecurityManager");
+ th.printStackTrace();
+ throw new RuntimeException("Failed to install SecurityManager");
+ }
+
+ try {
+
+ println("Calling PrinterJob.getPrinterJob()");
+ PrinterJob.getPrinterJob();
+
+ // Woops. We did not get the SecurityException we expected.
+ println("Failed to get SecurityException");
+ throw new RuntimeException("Failed to get expected SecurityException");
+
+ } catch (SecurityException ex) {
+ // Happy, happy. This is what we want.
+ println("Got expected SecurityException OK.");
+ return;
+ }
+
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/CheckPrivilege.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2007, 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 4151151
+ * @summary Confirm that low-level print code does doPrivilege.
+ * @author Graham Hamilton
+ */
+
+import java.awt.print.*;
+
+public class CheckPrivilege implements Printable {
+
+ static boolean verbose;
+
+ private static void println(String mess) {
+ if (verbose) {
+ System.err.println(mess);
+ }
+ }
+
+ /**
+ * SecurityManager that allows print requests, but
+ * causes things like "exec" to get checked.
+ */
+ static class PrintLover extends SecurityManager {
+ public void checkPrintJobAccess() {
+ }
+ public void checkPackageAccess(String pkg) {
+ }
+ public void checkPropertyAccess(String key) {
+ }
+ }
+
+ /**
+ * Internal exception to boucne us out of the print code
+ */
+ class Printing extends RuntimeException {
+ }
+
+ public static void main(String argv[]) {
+
+ System.out.println( "-----------------------------------------------------------------------");
+ System.out.println( "INSTRUCTIONS: You should have a printer configured in your system to do this test. Test fails if you get this error message:");
+ System.out.println(" \"Regression: printing causes a NullPointerException\"");
+ System.out.println( "-----------------------------------------------------------------------");
+
+ if (argv.length > 0 && argv[0].equals("-v")) {
+ verbose = true;
+ }
+
+ // We need to make sure AWT is initialized. This is bug #4162674
+ java.awt.Toolkit.getDefaultToolkit();
+
+ // Try to install our own security manager.
+ try {
+ SecurityManager sm = new PrintLover();
+ println("Installing PrintLover security manager");
+ System.setSecurityManager(sm);
+ println("Installed security manager OK");
+
+ } catch (Throwable th) {
+ System.err.println("Failed to install SecurityManager");
+ th.printStackTrace();
+ throw new RuntimeException("Failed to install SecurityManager");
+ }
+
+ try {
+ println("calling getPrinterJob");
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ if ((pj == null) || (pj.getPrintService() == null)){
+ return;
+ }
+
+ println("PrinterJob class is " + pj.getClass());
+ println("calling pj.setPrintable");
+ pj.setPrintable(new CheckPrivilege());
+ println("calling pj.print");
+ pj.print();
+ println("done pj.print");
+
+ } catch (Printing ex) {
+ // We get here if the print request started OK.
+ println("Caught \"Printing\" exception OK");
+
+ } catch (PrinterException ex) {
+ System.err.println("Caught " + ex);
+ throw new RuntimeException("" + ex);
+
+ } catch (NullPointerException ex) {
+ // This is the bug:
+ System.err.println("Caught " + ex);
+ System.err.println("Regression: printing causes a NullPointerException");
+ throw ex;
+ }
+
+ //System.exit(0);
+
+ }
+
+ // Back-call from the new print APIs.
+ // We always say we have bothing to print.
+ public int print(java.awt.Graphics g, PageFormat pf, int index) {
+ println("Started printing " + index);
+ return Printable.NO_SUCH_PAGE;
+ }
+
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/CompareImageable.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2007, 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 4748055
+ @summary PASS if the values are same in both cases (2 and 3) below.
+ @run main/manual CompareImageable
+*/
+
+/********************************************************************
+Testcase for comparing the imageable width and height of the paper
+with and without using print dialog.
+
+How to run:
+
+1. Launch the app. You'll find a checkbox and a print button.
+2. Click on the print button with the checkbox unselected. Note the
+imageable width and height displayed on the console
+3. Click on the print button with the checkbox selected. This popus up
+the print dialog. Click ok on the dialog. Note the imageable width and
+height displayed on the console.
+
+Result: It's a PASS if the values are same in both cases (2 and 3),
+ otherwise not.
+
+*********************************************************************/
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import java.awt.print.*;
+
+
+public class CompareImageable implements Printable {
+
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+
+ //get the printable width and height of the paper.
+ int pageHeight = (int)pgFmt.getImageableHeight();
+ int pageWidth = (int)pgFmt.getImageableWidth();
+
+ System.out.println("imageable width = " + pageWidth + " height = " + pageHeight);
+ return Printable.NO_SUCH_PAGE;
+ }
+
+
+ public static void main(String [] args) {
+
+ final JFrame frame = new JFrame("Print Test");
+ final JButton printBtn = new JButton("Print");
+ final JCheckBox dialogBtn = new JCheckBox("Native dialog");
+
+ JPanel panel = new JPanel(new FlowLayout());
+ panel.add(dialogBtn);
+ panel.add(printBtn);
+ frame.getContentPane().add(panel);
+
+ printBtn.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+
+ CompareImageable test = new CompareImageable();
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (dialogBtn.isSelected() && !pj.printDialog()) {
+ //user clicked 'Cancel' button in the print dialog. No printing.
+ return;
+ }
+
+ if (dialogBtn.isSelected()) {
+ System.out.println("With print dialog...");
+ } else {
+ System.out.println("Without print dialog...");
+ }
+
+ if (pj == null) {
+ System.out.println("No printer job found...");
+ return;
+ }
+ pj.setPrintable(test);
+
+ try {
+ pj.print();
+
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ });
+
+
+ frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
+ frame.setSize(400, 400);
+ frame.setVisible(true);
+
+ }
+}
Binary file jdk/test/java/awt/print/PrinterJob/CustomFont/A.ttf has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/CustomFont/CustomFont.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,416 @@
+/*
+ * Copyright (c) 2007, 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 4386025
+ @summary fonts not in win32 font directory print incorrectly.
+ @author prr: area=PrinterJob
+ @run main/manual CustomFont
+*/
+import java.io.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+
+public class CustomFont implements Printable {
+
+ private Image opaqueimg,transimg;
+
+ private static void init() {
+
+ //*** Create instructions for the user here ***
+
+ String[] instructions = {
+ "On-screen inspection is not possible for this printing-specific",
+ "test therefore its only output is a printed page.",
+ "To be able to run this test it is required to have a default",
+ "printer configured in your user environment.",
+ "",
+ "Visual inspection of the printed page is needed. A passing",
+ "test will print a page on which one line of text will be",
+ "printed: a long string of 'A' characters.",
+ "The A should have of a curly style",
+ "If instead its in the default sansserif font, the test fails",
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+
+ Book book = new Book();
+
+ PageFormat portrait = pjob.defaultPage();
+ book.append(new CustomFont(),portrait);
+
+ pjob.setPageable(book);
+
+ if (pjob.printDialog()) {
+ try {
+ pjob.print();
+ } catch (PrinterException e) {
+ System.err.println(e);
+ e.printStackTrace();
+ }
+ }
+ System.out.println("Done Printing");
+
+ }//End init()
+
+
+ Font customFont;
+ public CustomFont() {
+ try {
+ FileInputStream fin = new FileInputStream("A.ttf");
+ Font cf = Font.createFont(Font.TRUETYPE_FONT, fin);
+ customFont = cf.deriveFont(Font.PLAIN, 14);
+ } catch (Exception ioe) {
+ System.err.println(ioe.getMessage());
+ customFont = new Font("serif", Font.PLAIN, 14);
+ }
+ }
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+
+ Graphics2D g2D = (Graphics2D) g;
+ g2D.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+
+ g2D.setColor(Color.black);
+ g2D.setFont(customFont);
+ String str = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
+ g.drawString(str, 100, 100);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ /**
+ * The graphics is scaled and the font and the positions
+ * are reduced in respect to the scaling, so that all
+ * printing should be the same.
+ *
+ * @param g2D graphics2D to paint on
+ * @param font font to paint
+ * @param scale scale for the painting
+ * @param x x position
+ * @param y y position
+ */
+ private void printScale(Graphics2D g2D, Font font,
+ float scale, float x, float y) {
+
+ int RES = 72;
+
+ g2D.scale(scale, scale);
+
+ g2D.setFont (font.deriveFont(10.0f / scale));
+ g2D.drawString("This text is scaled by a factor of " + scale,
+ x * RES / scale, y * RES / scale);
+
+ g2D.scale(1/scale, 1/scale);
+
+}
+
+ /*****************************************************
+ Standard Test Machinery Section
+ DO NOT modify anything in this section -- it's a
+ standard chunk of code which has all of the
+ synchronisation necessary for the test harness.
+ By keeping it the same in all tests, it is easier
+ to read and understand someone else's test, as
+ well as insuring that all tests behave correctly
+ with the test harness.
+ There is a section following this for test-defined
+ classes
+ ******************************************************/
+ private static boolean theTestPassed = false;
+ private static boolean testGeneratedInterrupt = false;
+ private static String failureMessage = "";
+
+ private static Thread mainThread = null;
+
+ private static int sleepTime = 300000;
+
+ public static void main( String args[] ) throws InterruptedException
+ {
+ mainThread = Thread.currentThread();
+ try
+ {
+ init();
+ }
+ catch( TestPassedException e )
+ {
+ //The test passed, so just return from main and harness will
+ // interepret this return as a pass
+ return;
+ }
+ //At this point, neither test passed nor test failed has been
+ // called -- either would have thrown an exception and ended the
+ // test, so we know we have multiple threads.
+
+ //Test involves other threads, so sleep and wait for them to
+ // called pass() or fail()
+ try
+ {
+ Thread.sleep( sleepTime );
+ //Timed out, so fail the test
+ throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
+ }
+ catch (InterruptedException e)
+ {
+ if( ! testGeneratedInterrupt ) throw e;
+
+ //reset flag in case hit this code more than once for some reason (just safety)
+ testGeneratedInterrupt = false;
+ if ( theTestPassed == false )
+ {
+ throw new RuntimeException( failureMessage );
+ }
+ }
+
+ }//main
+
+ public static synchronized void setTimeoutTo( int seconds )
+ {
+ sleepTime = seconds * 1000;
+ }
+
+ public static synchronized void pass()
+ {
+ Sysout.println( "The test passed." );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //first check if this is executing in main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //Still in the main thread, so set the flag just for kicks,
+ // and throw a test passed exception which will be caught
+ // and end the test.
+ theTestPassed = true;
+ throw new TestPassedException();
+ }
+ //pass was called from a different thread, so set the flag and interrupt
+ // the main thead.
+ theTestPassed = true;
+ testGeneratedInterrupt = true;
+ mainThread.interrupt();
+ }//pass()
+
+ public static synchronized void fail()
+ {
+ //test writer didn't specify why test failed, s fail( "it just plain failed! :-)" );
+ }
+
+ public static synchronized void fail( String whyFailed )
+ {
+ Sysout.println( "The test failed: " + whyFailed );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //check if this called from main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //If main thread, fail now 'cause not sleeping
+ throw new RuntimeException( whyFailed );
+ }
+ theTestPassed = false;
+ testGeneratedInterrupt = true;
+ failureMessage = whyFailed;
+ mainThread.interrupt();
+ }//fail()
+
+}// class CustomFont
+
+//This exception is used to exit from any level of call nesting
+// when it's determined that the test has passed, and immediately
+// end the test.
+class TestPassedException extends RuntimeException
+ {
+ }
+
+
+//************** End classes defined for the test *******************
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog implements ActionListener {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+ Panel buttonP = new Panel();
+ Button passB = new Button( "pass" );
+ Button failB = new Button( "fail" );
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ passB = new Button( "pass" );
+ passB.setActionCommand( "pass" );
+ passB.addActionListener( this );
+ buttonP.add( "East", passB );
+
+ failB = new Button( "fail" );
+ failB.setActionCommand( "fail" );
+ failB.addActionListener( this );
+ buttonP.add( "West", failB );
+
+ add( "South", buttonP );
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ //catch presses of the passed and failed buttons.
+ //simply call the standard pass() or fail() static methods of
+ //CustomFont
+ public void actionPerformed( ActionEvent e )
+ {
+ if( e.getActionCommand() == "pass" )
+ {
+ CustomFont.pass();
+ }
+ else
+ {
+ CustomFont.fail();
+ }
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/DeviceScale.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2007, 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 1.2 02/05/15
+ @bug 4810363 4924441
+ @run main DeviceScale
+ @summary check the peek scale is the same as the device scale, and that the
+ clips are also the same
+*/
+import java.io.*;
+import java.net.*;
+import java.awt.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import javax.print.attribute.*;
+import javax.print.attribute.standard.*;
+
+public class DeviceScale implements Printable {
+
+ boolean firstTime = true;
+ double sx, sy;
+ Shape clip, firstClip;
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+ Graphics2D g2 = (Graphics2D)g;
+ if (pageIndex>=1) {
+ return Printable.NO_SUCH_PAGE;
+ }
+ AffineTransform at = g2.getTransform();
+ System.out.println(at);
+ clip = g2.getClip();
+ System.out.println(clip);
+ if (firstTime) {
+ firstTime = false;
+ sx = Math.abs(at.getScaleX());
+ sy = Math.abs(at.getScaleY());
+ firstClip = clip;
+ } else {
+ double newSx = Math.abs(at.getScaleX());
+ double newSy = Math.abs(at.getScaleY());
+ if (Math.abs(sx - newSx) > 0.1 ||
+ Math.abs(sy - newSy) > 0.1) {
+ throw new RuntimeException("different scale, was "+
+ sx+","+sy+" now " +
+ newSx+","+ newSy);
+ }
+ if (!clip.equals(firstClip)) {
+ throw new RuntimeException("different clip, was "+ firstClip +
+ " now "+ clip);
+ }
+ }
+ return Printable.PAGE_EXISTS;
+ }
+
+ public static void doit(OrientationRequested o) throws Exception {
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ if (pj.getPrintService() == null) {
+ System.out.println("No print service found.");
+ return;
+ }
+ pj.setPrintable(new DeviceScale());
+ PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
+ aset.add(o);
+ String fileName = "out.prn";
+ File f = new File(fileName);
+ f.deleteOnExit();
+ URI dest = f.toURI();
+ aset.add(new Destination(dest));
+ pj.print(aset);
+ }
+
+
+ public static void main(String arg[]) throws Exception {
+
+ doit(OrientationRequested.PORTRAIT);
+ doit(OrientationRequested.LANDSCAPE);
+ doit(OrientationRequested.REVERSE_LANDSCAPE);
+
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/DrawImage.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,282 @@
+/*
+ * Copyright (c) 2007, 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 4329866
+ * @summary Confirm that no printing exception is generated.
+ * @author jgodinez
+ * @run main/manual DrawImage
+ */
+
+import java.util.*;
+import java.text.*;
+import java.io.*;
+import java.net.*;
+import java.awt.*;
+import java.awt.font.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import java.awt.event.*;
+import java.awt.image.*;
+import java.awt.image.renderable.*;
+import javax.swing.*;
+import javax.swing.text.*;
+import javax.swing.border.*;
+import javax.swing.event.*;
+
+public class DrawImage
+{
+ protected static final double _hwBorder = 72 / 4; // 1/4 inch
+ protected static final double _border = 72 / 4; // 1/4 inch
+ protected static final int _objectBorder = 15;
+ protected static final int _verticalGap = 20;
+ protected static final int _textIndent = 150;
+
+ protected BufferedImage _image;
+
+ protected PageFormat _pageFormat;
+
+ public DrawImage(BufferedImage image) {
+ _image = image;
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ _pageFormat = pj.defaultPage();
+
+ }
+
+
+ protected int printImage(Graphics g, PageFormat pf, BufferedImage image) {
+ Graphics2D g2D = (Graphics2D)g;
+ g2D.transform(new AffineTransform(_pageFormat.getMatrix()));
+
+ int paperW = (int)pf.getImageableWidth(), paperH =
+ (int)pf.getImageableHeight();
+
+ int x = (int)pf.getImageableX(), y = (int)pf.getImageableY();
+ g2D.setClip(x, y, paperW, paperH);
+
+ // print images
+ if (image != null ) {
+ int imageH = image.getHeight(), imageW = image.getWidth();
+ // make slightly smaller (25) than max possible width
+ float scaleFactor = ((float)((paperW - 25) - _objectBorder -
+ _objectBorder) / (float)(imageW));
+ int scaledW = (int)(imageW * scaleFactor),
+ scaledH = (int)(imageH *scaleFactor);
+ BufferedImageOp scaleOp = new RescaleOp(scaleFactor, 0, null);
+ g2D.drawImage(image, scaleOp, x + _objectBorder, y + _objectBorder);
+ y += _objectBorder + scaledH + _objectBorder;
+ return Printable.PAGE_EXISTS;
+ }
+ else {
+ return Printable.NO_SUCH_PAGE;
+ }
+ }
+
+ public void print() {
+ try {
+ final PrinterJob pj = PrinterJob.getPrinterJob();
+ pj.setJobName("Print Image");
+ pj.setPrintable(new Printable() {
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+ int result = NO_SUCH_PAGE;
+ if (pageIndex == 0) {
+ result = printImage(g, _pageFormat, _image);
+ }
+ return result;
+ }
+ });
+ if (pj.printDialog()) {
+ try { pj.print(); }
+ catch (PrinterException e) {
+ System.out.println(e);
+ }
+ }
+
+ }
+ catch (Exception e) {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ public static void main(String[] args) {
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test.",
+ "The test passes if you get a printout of a gray rectangle",
+ "with white text without any exception."
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ BufferedImage image = prepareFrontImage();
+ DrawImage pt = new DrawImage(image);
+ pt.print();
+ // System.exit(0);
+ }
+
+
+
+ public static BufferedImage prepareFrontImage() {
+ // build my own test images
+ BufferedImage result = new BufferedImage(400, 200,
+ BufferedImage.TYPE_BYTE_GRAY);
+
+ Graphics2D g2D = (Graphics2D)result.getGraphics();
+ g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_OFF);
+ int w = result.getWidth(), h = result.getHeight();
+
+ g2D.setColor(Color.gray);
+ g2D.fill(new Rectangle(0, 0, w, h));
+
+ g2D.setColor(Color.white);
+
+ AffineTransform original = g2D.getTransform();
+ AffineTransform originXform = AffineTransform.getTranslateInstance(w /
+5, h / 5);
+ g2D.transform(originXform);
+
+
+ g2D.drawString("Front Side", 20, h / 2);
+
+ return result;
+ }
+
+
+}
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/DrawStringMethods.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,250 @@
+/*
+ * Copyright (c) 2007, 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 4185019
+ * @summary Confirm that all of the drawString methods on Graphics2D
+ * work for printer graphics objects.
+ * @run main/manual DrawStringMethods
+ */
+
+import java.awt.*;
+import java.text.*;
+import java.awt.font.*;
+import java.awt.print.*;
+
+public class DrawStringMethods implements Printable {
+
+ public static void main(String args[]) {
+ String[] instructions =
+ {
+ "Confirm that the methods are printed.",
+ " For Graphics: drawString, drawString, drawChars, drawBytes",
+ " For Graphics2D: drawString, drawString, drawGlyphVector"
+ };
+ Sysout.createDialogWithInstructions( instructions );
+
+
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+ PageFormat pf = pjob.defaultPage();
+ Book book = new Book();
+
+ book.append(new DrawStringMethods(), pf);
+ pjob.setPageable(book);
+
+ try {
+ pjob.print();
+ } catch (PrinterException e) {
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ public static AttributedCharacterIterator getIterator(String s) {
+ return new AttributedString(s).getIterator();
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+ int ix = (int) pf.getImageableX();
+ int iy = (int) pf.getImageableY();
+ String s;
+
+ g.setColor(Color.black);
+
+ iy += 50;
+ s = "--- Graphics methods: ---";
+ g.drawString(s, ix, iy);
+
+ iy += 30;
+ s = "drawString(String str, int x, int y)";
+ g.drawLine(ix, iy, ix+10, iy);
+ g.drawString(s, ix+20, iy);
+
+ iy += 30;
+ s = "drawString(AttributedCharacterIterator iterator, int x, int y)";
+ g.drawLine(ix, iy, ix+10, iy);
+ g.drawString(getIterator(s), ix+20, iy);
+
+ iy += 30;
+ s = "drawChars(char data[], int offset, int length, int x, int y)";
+ g.drawLine(ix, iy, ix+10, iy);
+ g.drawChars(s.toCharArray(), 0, s.length(), ix+20, iy);
+
+ iy += 30;
+ s = "drawBytes(byte data[], int offset, int length, int x, int y)";
+ byte data[] = new byte[s.length()];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) s.charAt(i);
+ }
+ g.drawLine(ix, iy, ix+10, iy);
+ g.drawBytes(data, 0, data.length, ix+20, iy);
+
+ iy += 50;
+ s = "--- Graphics2D methods: ---";
+ g.drawString(s, ix, iy);
+
+ if (g instanceof Graphics2D) {
+ Graphics2D g2d = (Graphics2D) g;
+ Font f = g2d.getFont();
+ FontRenderContext frc = g2d.getFontRenderContext();
+
+ iy += 30;
+ s = "drawString(String s, float x, float y)";
+ g.drawLine(ix, iy, ix+10, iy);
+ g2d.drawString(s, (float) ix+20, (float) iy);
+
+ iy += 30;
+ s = "drawString(AttributedCharacterIterator iterator, "+
+ "float x, float y)";
+ g.drawLine(ix, iy, ix+10, iy);
+ g2d.drawString(getIterator(s), (float) ix+20, (float) iy);
+
+ iy += 30;
+ s = "drawGlyphVector(GlyphVector g, float x, float y)";
+ g.drawLine(ix, iy, ix+10, iy);
+ g2d.drawGlyphVector(f.createGlyphVector(frc, s), ix+20, iy);
+ } else {
+ iy += 30;
+ s = "Graphics object does not support Graphics2D methods";
+ g.drawString(s, ix+20, iy);
+ }
+
+ return PAGE_EXISTS;
+ }
+}
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog
+ {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("South", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/EmptyFill.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2007, 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 4509958
+ * @summary Tests that the empty areas aren't drawn.
+ * @run main EmptyFill
+ */
+
+import java.io.*;
+import java.awt.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import javax.print.*;
+import javax.print.attribute.*;
+
+public class EmptyFill implements Printable {
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+
+ if (pageIndex > 0) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ g.setColor(Color.black);
+
+ int[] xq = { 75, 125, 75 };
+ int[] yq = { 140, 140, 140};
+
+ g.fillPolygon( xq, yq, 3 );
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public static void main(String arg[]) throws Exception {
+
+ DocFlavor psFlavor = new DocFlavor("application/postscript",
+ "java.io.OutputStream");
+
+ StreamPrintServiceFactory[] spfs =
+ PrinterJob.lookupStreamPrintServices("application/postscript");
+
+ if (spfs.length == 0) {
+ return;
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+ StreamPrintService svc = spfs[0].getPrintService(baos);
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ if (svc == null) {
+ return;
+ }
+ pj.setPrintService(svc);
+ pj.setPrintable(new EmptyFill());
+ pj.print();
+
+ String outStr = baos.toString("ISO-8859-1");
+ if (outStr.indexOf("\nfill\n") > 0) {
+ throw new Exception("Expected no fills");
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/GlyphPositions.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2007, 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 6186840 6324057
+ * @summary Tests that explicitly positioned glyphs print correctly.
+ * @run main GlyphPositions
+ */
+
+import java.io.*;
+import java.awt.*;
+import java.awt.font.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import javax.print.*;
+import javax.print.attribute.*;
+
+public class GlyphPositions implements Printable {
+
+ static String testString = "0123456789";
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+
+ if (pageIndex > 0) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ g.setColor(Color.black);
+ float x = (float)pf.getImageableX() + 20f,
+ y = (float)pf.getImageableY() + 30f;
+
+ Graphics2D g2 = (Graphics2D)g;
+ Font font = new Font("SansSerif", Font.PLAIN, 20);
+ FontRenderContext frc = g2.getFontRenderContext();
+ GlyphVector v = font.createGlyphVector(frc, testString);
+
+ for(int i = 0; i <= v.getNumGlyphs(); i++)
+ {
+ Point2D.Float p = new Point2D.Float();
+ p.x = i * 40f;
+ p.y = 0;
+ v.setGlyphPosition(i, p);
+ }
+
+ g2.drawGlyphVector(v, x, y);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public static void main(String arg[]) throws Exception {
+
+ DocFlavor psFlavor = new DocFlavor("application/postscript",
+ "java.io.OutputStream");
+
+ StreamPrintServiceFactory[] spfs =
+ PrinterJob.lookupStreamPrintServices("application/postscript");
+
+ if (spfs.length == 0) {
+ return;
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+ StreamPrintService svc = spfs[0].getPrintService(baos);
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ if (svc == null) {
+ return;
+ }
+ pj.setPrintService(svc);
+ pj.setPrintable(new GlyphPositions());
+ pj.print();
+
+ /* Expect to see that the 10 glyphs are drawn individually which
+ * because of their positions.
+ * This test will need to be updated if the postscript generation
+ * changes.
+ */
+ String outStr = baos.toString("ISO-8859-1");
+ String ls = System.getProperty("line.separator");
+ int indexCount = 0;
+ int index = 0;
+ while (index >= 0) {
+ index = outStr.indexOf("20.0 12 F"+ls, index+1);
+ if (index > 0) indexCount++;
+ }
+ if (indexCount < testString.length()) {
+ throw new Exception("Positions not used");
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/HeadlessPrintingTest.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2007, 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 4936867
+ * @summary Printing crashes in headless mode.
+ * @run main/othervm HeadlessPrintingTest
+ */
+
+
+import java.awt.*;
+import javax.print.*;
+import javax.print.attribute.*;
+import javax.print.attribute.standard.*;
+import java.awt.print.*;
+import java.io.*;
+
+public class HeadlessPrintingTest {
+
+ public static void main(String[] args) {
+ System.setProperty("java.awt.headless", "true");
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ pj.setPrintable(new Printable() {
+ public int print(Graphics g, PageFormat pg, int pageIndex) {
+ Graphics2D g2d = (Graphics2D)g;
+ if (pageIndex > 2) {
+ return Printable.NO_SUCH_PAGE;
+ } else {
+ g2d.translate(pg.getImageableX(), pg.getImageableY());
+ g2d.setColor(Color.RED);
+ g2d.drawString("page " + pageIndex, 100, 100);
+ return Printable.PAGE_EXISTS;
+ }
+ }
+ });
+
+ try {
+ HashPrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();
+ File f = File.createTempFile("out", "ps");
+ f.deleteOnExit();
+ Destination dest = new Destination(f.toURI());
+ attr.add(dest);
+ pj.print(attr);
+ } catch (Exception e) {
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/InitToBlack.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2007, 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.
+ */
+
+/**
+ * @bug 4184565
+ * @summary Confirm that the default foreground color on a printer
+ * graphics object is black so that rendering will appear
+ * without having to execute setColor first.
+ * @run applet/manual=yesno InitToBlack.html
+ */
+
+import java.awt.*;
+import java.awt.print.*;
+import java.applet.Applet;
+
+public class InitToBlack extends Applet implements Printable {
+
+ public void init() {
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+
+ Book book = new Book();
+ book.append(this, pjob.defaultPage());
+ pjob.setPageable(book);
+
+ try {
+ pjob.print();
+ } catch (PrinterException e) {
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+ Graphics2D g2d = (Graphics2D) g;
+ g2d.translate(pf.getImageableX(), pf.getImageableY());
+
+ g.drawString("Test Passes", 200, 200);
+
+ return PAGE_EXISTS;
+ }
+
+ public static void main(String[] args) {
+ new InitToBlack().init();
+ System.exit(0);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/InvalidPage.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,243 @@
+/*
+ * Copyright (c) 2007, 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 InvalidPage.java
+ * @bug 4671634 6506286
+ * @summary Invalid page format can crash win32 JRE
+ * @author prr
+ * @run main/manual InvalidPage
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+public class InvalidPage extends Frame implements Printable {
+
+ PrinterJob pJob;
+ PageFormat pf;
+
+ public InvalidPage() {
+ super ("Validate Page Test");
+ pJob = PrinterJob.getPrinterJob();
+ pf = pJob.defaultPage();
+ Paper p = pf.getPaper();
+ p.setImageableArea(0,0,p.getWidth(), p.getHeight());
+ pf.setPaper(p);
+ setLayout(new FlowLayout());
+ Panel panel = new Panel();
+ Button printButton = new Button ("Print");
+ printButton.addActionListener(new ActionListener() {
+ public void actionPerformed (ActionEvent e) {
+ try {
+ if (pJob.printDialog()) {
+ pJob.setPrintable(InvalidPage.this, pf);
+ pJob.print();
+ }
+ } catch (PrinterException pe ) {
+ }
+ }
+ });
+ panel.add (printButton);
+ add(panel);
+
+ addWindowListener (new WindowAdapter() {
+ public void windowClosing (WindowEvent e) {
+ dispose();
+ System.exit (0);
+ }
+
+ });
+ setSize (200, 200);
+ setVisible (true);
+ }
+
+ public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
+
+ if (pageIndex > 1) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ Graphics2D g2d = (Graphics2D)graphics;
+
+ g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
+ g2d.drawString("ORIGIN", 30, 30);
+ g2d.drawString("X THIS WAY", 200, 50);
+ g2d.drawString("Y THIS WAY", 60 , 200);
+ g2d.drawRect(0,0,(int)pageFormat.getImageableWidth(),
+ (int)pageFormat.getImageableHeight());
+ if (pageIndex == 0) {
+ g2d.setColor(Color.black);
+ } else {
+ g2d.setColor(new Color(0,0,0,128));
+ }
+ g2d.drawRect(1,1,(int)pageFormat.getImageableWidth()-2,
+ (int)pageFormat.getImageableHeight()-2);
+
+ g2d.drawLine(0,0,
+ (int)pageFormat.getImageableWidth(),
+ (int)pageFormat.getImageableHeight());
+ g2d.drawLine((int)pageFormat.getImageableWidth(),0,
+ 0,(int)pageFormat.getImageableHeight());
+ return Printable.PAGE_EXISTS;
+ }
+
+ public static void main( String[] args) {
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test",
+ "Press the print button, which brings up a print dialog and",
+ "in the dialog select a printer and press the print button",
+ "in the dialog. Repeat for as many printers as you have installed",
+ "On solaris and linux just one printer is sufficient",
+ "Collect the output and examine it, each print job has two pages",
+ "of very similar output, except that the 2nd page of the job may",
+ "appear in a different colour, and the output near the edge of",
+ "the page may be clipped. This is OK. Hold up both pieces of paper",
+ "to the light and confirm that the lines and text (where present)",
+ "are positioned identically on both pages",
+ "The test fails if the JRE crashes, or if the output from the two",
+ "pages of a job is aligned differently"
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ new InvalidPage();
+ }
+
+}
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/JobName/PrinterJobName.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,193 @@
+/*
+ * Copyright (c) 2007, 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 4205601
+ * @summary setJobName should be used by PrinterJob
+ * @author prr
+ * @run main/manual PrinterJobName
+ */
+
+import java.awt.*;
+import java.awt.print.*;
+
+public class PrinterJobName implements Printable {
+
+
+ static String theName = "Testing the Jobname setting";
+
+ public static void main(String[] args) {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test",
+ "This test prints a page with a banner/job name of",
+ theName
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJob job = PrinterJob.getPrinterJob();
+ job.setJobName(theName);
+ job.setPrintable(new PrinterJobName());
+ try {
+ job.print();
+ System.out.println("PRINTING DONE.");
+ }
+ catch (Exception exc) {
+ System.out.println("Printer Exception");
+ }
+ }
+
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+ if (pgIndex > 0 ) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ double iw = pgFmt.getImageableWidth();
+ double ih = pgFmt.getImageableHeight();
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+ g2d.drawString("Name is: "+theName,20,20 );
+ return Printable.PAGE_EXISTS;
+ }
+
+}
+
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/Legal/PrintTest.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,245 @@
+/*
+ * Copyright (c) 2007, 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 4886069 8023045
+ * @summary Confirm that printer recognizes the Legal selection either by
+ * prompting the user to put Legal paper or automatically selecting
+ * the tray containing Legal Paper. The printout image should not
+ * be shifted up by about 3".
+ * @run main/manual PrintTest
+ *
+ */
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.border.*;
+
+import java.awt.print.*;
+import javax.print.*;
+import javax.print.attribute.*;
+import javax.print.attribute.standard.*;
+import java.io.*;
+
+
+public class PrintTest extends JFrame {
+ private JPanel contentPane;
+ private JMenuBar jMenuBar1 = new JMenuBar();
+ private JMenu jMenuFile = new JMenu();
+ private JMenuItem jMenuItem1 = new JMenuItem();
+ private BorderLayout borderLayout1 = new BorderLayout();
+ private JPanel jPanel1 = new JPanel();
+ private BorderLayout borderLayout2 = new BorderLayout();
+ private JScrollPane jScrollPane1 = new JScrollPane();
+ private JTextArea jTextArea1 = new JTextArea();
+ private Border border1;
+
+ //Construct the frame
+ public PrintTest() {
+ enableEvents(AWTEvent.WINDOW_EVENT_MASK);
+ try {
+ jbInit();
+
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+ private void jbInit() throws Exception {
+ contentPane = (JPanel) this.getContentPane();
+ border1 = BorderFactory.createLineBorder(Color.black,1);
+ contentPane.setLayout(borderLayout1);
+ this.setTitle("Print Test");
+ jMenuFile.setText("File");
+ jMenuItem1.setText("Print");
+ jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(80, java.awt.event.KeyEvent.CTRL_MASK, false));
+ jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ jMenuItem1_actionPerformed(e);
+ }
+ });
+ jPanel1.setLayout(borderLayout2);
+ jTextArea1.setBorder(border1);
+ jTextArea1.setText("1. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "2. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "3. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "4. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "5. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "6. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "7. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "8. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "9. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "10. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "11. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "12. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "13. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "14. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "15. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "16. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "17. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "18. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "19. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "20. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "21. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "22. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "23. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "24. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "25. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "26. This is a printer test designed to illustrate a bug in the java printing API.\n\n"+
+ "27. This is a printer test designed to illustrate a bug in the java printing API.");
+ jMenuFile.add(jMenuItem1);
+ contentPane.add(jPanel1, BorderLayout.CENTER);
+ jPanel1.add(jScrollPane1, BorderLayout.CENTER);
+ jScrollPane1.getViewport().add(jTextArea1, null);
+ jScrollPane1.setPreferredSize(new Dimension(468,648));
+ jTextArea1.setPreferredSize(new Dimension(468,864));
+ jMenuBar1.add(jMenuFile);
+ this.setJMenuBar(jMenuBar1);
+ }
+
+ protected void processWindowEvent(WindowEvent e) {
+ super.processWindowEvent(e);
+ if (e.getID() == WindowEvent.WINDOW_CLOSING) {
+ System.exit(0);
+ }
+ }
+
+ void jMenuItem1_actionPerformed(ActionEvent e) {
+ PrintUtils.printComponent(jTextArea1);
+ }
+
+
+
+
+ public static class PrintUtils implements Printable {
+ private JComponent componentToBePrinted;
+ protected double scale =1.0;
+ PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
+
+
+ public static void printComponent(JComponent c) {
+ new PrintUtils(c).print();
+ }
+
+ public PrintUtils(JComponent componentToBePrinted) {
+ this.componentToBePrinted = componentToBePrinted;
+
+ }
+
+ void print() {
+ DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
+ pras.add(MediaSizeName.NA_LEGAL);
+
+ PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor,pras);
+ PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
+ if ((defaultService == null) || (printService.length == 0)) {
+ System.out.println("No default print service found. Test aborted.");
+ return;
+ }
+
+ PrintService service = ServiceUI.printDialog(null,100,100,printService,defaultService,flavor,pras);
+
+ if(service != null) {
+ DocPrintJob job = service.createPrintJob();
+ DocAttributeSet das = new HashDocAttributeSet();
+
+ Doc doc = new SimpleDoc(this,flavor,das);
+
+ try {
+ job.print(doc,pras);
+
+ } catch(PrintException pe) {
+ pe.printStackTrace();
+ }
+ }
+
+ }
+
+
+ public int print(Graphics g, PageFormat pageFormat, int pageIndex)
+ {
+
+ double h=componentToBePrinted.getHeight();
+ double pageHeight=pageFormat.getImageableHeight();
+
+ if (pageIndex * pageHeight > h * scale) {
+ return(NO_SUCH_PAGE);
+ } else {
+
+ Graphics2D g2d = (Graphics2D)g;
+
+ //move past unprintable area
+ double xOffset=pageFormat.getImageableX();
+ double yOffset=pageFormat.getImageableY();
+ g2d.translate(xOffset,yOffset);
+
+
+ //move to correct page taking into account the scaling
+ double newx=0;
+ double newy=pageHeight*(-pageIndex);
+ g2d.translate(newx / 1.0,newy / 1.0 );
+
+ //print
+
+ componentToBePrinted.print(g2d);
+ return(PAGE_EXISTS);
+ }
+ }
+
+ public static void disableDoubleBuffering(Component c) {
+ RepaintManager currentManager = RepaintManager.currentManager(c);
+ currentManager.setDoubleBufferingEnabled(false);
+ }
+
+ /** Re-enables double buffering globally. */
+
+ public static void enableDoubleBuffering(Component c) {
+ RepaintManager currentManager = RepaintManager.currentManager(c);
+ currentManager.setDoubleBufferingEnabled(true);
+ }
+}
+
+ public static void main(String[] args) {
+ try {
+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ }
+ PrintTest frame = new PrintTest();
+ frame.pack();
+
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ Dimension frameSize = frame.getSize();
+ if (frameSize.height > screenSize.height) {
+ frameSize.height = screenSize.height;
+ }
+ if (frameSize.width > screenSize.width) {
+ frameSize.width = screenSize.width;
+ }
+ frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
+ frame.setVisible(true);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/MultiThread/MultiThreadTest.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2007, 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 4922036
+ * @summary Confirm that no Exception is thrown and 2 identical output is produced.
+ * @run main/manual MultiThreadTest
+ */
+import java.io.*;
+import javax.print.*;
+
+
+public class MultiThreadTest extends Thread {
+
+ private PrintService service = PrintServiceLookup.lookupDefaultPrintService();
+ private Doc doc = null;
+
+ public MultiThreadTest(Doc docObject) {
+ this.doc = docObject;
+ }
+
+ public void print() {
+ try {
+ DocPrintJob job = null;
+
+ job = this.service.createPrintJob();
+ if (job == null) {
+ System.out.println("Fail: DocPrintJob is null...");
+ return;
+ }
+ System.out.println("About to print image...");
+
+ job.print(this.doc, null);
+ System.out.println("Image printed.");
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void run() {
+ this.print();
+ }
+
+ public static void main(String args[]) {
+ if (args.length <= 0) {
+ System.out.println("Usage: java MultiThreadTest <img file>");
+ return;
+ }
+ Object printData = null;
+
+ try {
+ File file = new File(args[0]);
+
+ printData = new byte[(int) file.length()];
+ FileInputStream in = new FileInputStream(file);
+
+ in.read((byte[]) printData);
+ in.close();
+ } catch (FileNotFoundException fe) {
+ System.out.println("ByteDoc: FileNotFoundException: "
+ + fe.toString());
+
+ } catch (IOException ie) {
+ System.out.println("ByteDoc: IOException: " + ie.toString());
+ }
+ Doc doc1 = new ByteDoc(printData, DocFlavor.BYTE_ARRAY.GIF);
+ Doc doc2 = new ByteDoc(printData, DocFlavor.BYTE_ARRAY.GIF);
+
+ Thread thread1 = new MultiThreadTest(doc1);
+ Thread thread2 = new MultiThreadTest(doc2);
+
+ thread1.start();
+ thread2.start();
+ }
+}
+
+
+class ByteDoc implements Doc {
+
+ protected DocFlavor flavor = null;
+ protected Object printData = null;
+ protected InputStream instream = null;
+ protected FileReader reader = null;
+
+ // constructor takes the resource file and the document flavor.
+ public ByteDoc(Object printdata, DocFlavor docFlavor) {
+ this.printData = printdata;
+ this.flavor = docFlavor;
+ }
+
+ public javax.print.attribute.DocAttributeSet getAttributes() {
+ return null;
+ }
+
+ public DocFlavor getDocFlavor() {
+ return this.flavor;
+ }
+
+ public Object getPrintData() {
+ return this.printData;
+ }
+
+ public Reader getReaderForText() {
+ // Document says that if MIME type is non-text and representation class is input stream
+ // then return null;
+ return null;
+ }
+
+ public InputStream getStreamForBytes() {
+ synchronized (this) {
+ if ((this.instream == null) && (this.printData instanceof byte[])) {
+ // its a byte array so create a ByteArrayInputStream.
+ System.out.println("creating ByteArrayInputStream...");
+ this.instream = new ByteArrayInputStream((byte[]) printData);
+ }
+ }
+ return this.instream;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/NullGetName.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2007, 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 6397684
+ @summary PASS if no VM crash.
+ @run main NullGetName
+*/
+
+
+import javax.print.*;
+import javax.print.attribute.*;
+import javax.print.event.*;
+import java.awt.print.*;
+
+
+public class NullGetName {
+
+ public static void main(String[] args) {
+ PrinterJob printerJob = PrinterJob.getPrinterJob();
+ try {
+ printerJob.setPrintService(new ImagePrintService());
+ } catch (PrinterException e) {
+ }
+ }
+}
+
+
+class ImagePrintService implements PrintService {
+
+
+ public Class[] getSupportedAttributeCategories() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isAttributeCategorySupported(Class category) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public String getName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public DocFlavor[] getSupportedDocFlavors() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+ public boolean isDocFlavorSupported(DocFlavor flavor) {
+ if(DocFlavor.SERVICE_FORMATTED.PAGEABLE.equals(flavor))
+ return true;
+ if(DocFlavor.SERVICE_FORMATTED.PRINTABLE.equals(flavor))
+ return true;
+ return false;
+ }
+
+ public DocPrintJob createPrintJob() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ServiceUIFactory getServiceUIFactory() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+ public PrintServiceAttributeSet getAttributes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void addPrintServiceAttributeListener(
+ PrintServiceAttributeListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removePrintServiceAttributeListener(
+ PrintServiceAttributeListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Object getDefaultAttributeValue(Class category) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public <T extends PrintServiceAttribute> T
+ getAttribute(Class<T> category) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isAttributeValueSupported(Attribute attrval,
+ DocFlavor flavor, AttributeSet attributes) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
+ AttributeSet attributes) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object getSupportedAttributeValues(Class category, DocFlavor flavor,
+ AttributeSet attributes) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/NumCopies.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 2007, 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 4258003
+ * @summary Checks the right number of copies are printed
+ * @author prr
+ * @run main/manual NumCopies
+ */
+
+import java.awt.*;
+import java.awt.print.*;
+
+public class NumCopies implements Printable {
+
+
+ public static void main(String[] args) {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test",
+ "This test should print a total of four pages which are two",
+ " copies of each of two pages which consist of the text :-",
+ "'This is page number N', where N is 0 and 1.",
+ "The pages should be uncollated."
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJob job = PrinterJob.getPrinterJob();
+ job.setCopies(2);
+ job.setPrintable(new NumCopies());
+ try {
+ job.print();
+ }
+ catch (Exception exc) {
+ System.out.println("Printer Exception");
+ }
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex)
+ throws PrinterException {
+
+ if (pageIndex > 1) {
+ return NO_SUCH_PAGE;
+ }
+ g.translate((int)pf.getImageableX(), (int)pf.getImageableY());
+ g.setColor(Color.black);
+ g.drawString("This is page number " + Integer.toString(pageIndex), 50, 50);
+ return PAGE_EXISTS ;
+ }
+
+}
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PSQuestionMark.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2007, 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 6217355 6324057
+ * @summary Tests that '?' prints with postscript fonts
+ * @run main PSQuestionMark
+ */
+
+import java.io.*;
+import java.awt.*;
+import java.awt.print.*;
+import javax.print.*;
+import javax.print.attribute.*;
+
+public class PSQuestionMark implements Printable {
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+
+ if (pageIndex > 0) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ g.setColor(Color.black);
+ g.setFont(new Font("Serif", Font.PLAIN, 12));
+ g.drawString("?", 100, 150);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public static void main(String arg[]) throws Exception {
+
+ DocFlavor psFlavor = new DocFlavor("application/postscript",
+ "java.io.OutputStream");
+
+ StreamPrintServiceFactory[] spfs =
+ PrinterJob.lookupStreamPrintServices("application/postscript");
+
+ if (spfs.length == 0) {
+ return;
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+ //FileOutputStream baos = new FileOutputStream("q.ps");
+ StreamPrintService svc = spfs[0].getPrintService(baos);
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ if (svc == null) {
+ return;
+ }
+ pj.setPrintService(svc);
+ pj.setPrintable(new PSQuestionMark());
+ pj.print();
+ //baos.close();
+
+ /* Expect to see the PS we generate for setting 12 pt Times Roman
+ * and the hex value of '?'
+ * "12.0 12 F"
+ * "<3f> 6.72 100.0 150.0 S"
+ * This test will need to be updated if the postscript generation
+ * changes.
+ */
+ String outStr = baos.toString("ISO-8859-1");
+ String ls = System.getProperty("line.separator");
+ if (outStr.indexOf("12.0 32 F"+ls+"<3f>") < 0) {
+ throw new Exception("PS font not used");
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PSWindingRule.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2007, 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 4423489
+ * @summary Tests that the postscript renders using the appropriate
+ * winding rule. Runs as "main" as can't run in sandbox.
+ * @run main PSWindingRule
+ */
+
+import java.io.*;
+import java.awt.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import javax.print.*;
+import javax.print.attribute.*;
+
+public class PSWindingRule implements Printable {
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+
+ if (pageIndex > 0) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ Graphics2D g2 = (Graphics2D)g;
+
+ GeneralPath path1 = new GeneralPath(PathIterator.WIND_EVEN_ODD);
+ GeneralPath path2 = new GeneralPath(PathIterator.WIND_EVEN_ODD);
+ GeneralPath path3 = new GeneralPath(PathIterator.WIND_EVEN_ODD);
+ path1.append(new Ellipse2D.Double(100, 100, 100, 100), false);
+ path1.append(new Ellipse2D.Double(120, 120, 60, 60), false);
+ path1.append(new Ellipse2D.Double(140, 140, 20, 20), false);
+
+ path2.append(new Ellipse2D.Double(150, 100, 100, 100), false);
+ path2.append(new Ellipse2D.Double(170, 120, 60, 60), false);
+ path2.append(new Ellipse2D.Double(190, 140, 20, 20), false);
+
+ path3.append(new Ellipse2D.Double(-50, -50, 100, 100), false);
+ path3.append(new Ellipse2D.Double(-30, -30, 60, 60), false);
+ path3.append(new Ellipse2D.Double(-10, -10, 20, 20), false);
+
+ Rectangle clip = new Rectangle();
+ g2.getClipBounds(clip);
+
+ g2.setColor(Color.white);
+ g2.fillRect(clip.x, clip.y, clip.width, clip.height);
+
+ g2.setColor(Color.red);
+ g2.fill(path1);
+
+ g2.setColor(Color.black);
+ g2.fill(path2);
+
+ g2.translate(150, 400);
+ g2.setColor(Color.red);
+ g2.fill(path3);
+
+ g2.translate(50, 0);
+ g2.setColor(Color.black);
+ g2.fill(path3);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public static void main(String arg[]) throws Exception {
+
+ DocFlavor psFlavor = new DocFlavor("application/postscript",
+ "java.io.OutputStream");
+
+ StreamPrintServiceFactory[] spfs =
+ PrinterJob.lookupStreamPrintServices("application/postscript");
+
+ if (spfs.length == 0) {
+ return;
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+ StreamPrintService svc = spfs[0].getPrintService(baos);
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ if (svc == null) {
+ return;
+ }
+ pj.setPrintService(svc);
+ pj.setPrintable(new PSWindingRule());
+ pj.print();
+
+ String outStr = baos.toString("ISO-8859-1");
+ int eofillCnt = 0;
+ int index = 0;
+ String ls = System.getProperty ("line.separator");
+
+ while (index >= 0) {
+ index = outStr.indexOf(ls+"EF"+ls, index+1);
+ if (index >=0 ) {
+ eofillCnt++;
+ }
+ }
+ if (eofillCnt != 4) {
+ throw new Exception("Expected 4 eofill's, got: " + eofillCnt);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PageDialogTest.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2007, 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 6302514
+ @run main/manual=yesno PageDialogTest
+ @summary A toolkit modal dialog should not be blocked by Page/Print dialog.
+*/
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+import javax.swing.*;
+
+public class PageDialogTest {
+
+ public static void main(String[] args) {
+ String[] instructions =
+ {
+ "The test shows a Toolkit modal dialog. ",
+ "Click the 'Open' button. It opens a page dialog.",
+ "The test fails if the page dialog blocks the toolkit",
+ "modal dialog, otherwise it passes."
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ Dialog td = new Dialog((Frame) null, "Toolkit modal dialog",
+ Dialog.ModalityType.TOOLKIT_MODAL);
+ td.setLayout(new FlowLayout());
+ td.add(new Button("Dummy"));
+ Button tdb = new Button("Open");
+ tdb.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ PrinterJob.getPrinterJob().pageDialog(new PageFormat());
+ }
+ });
+ td.add(tdb);
+ td.setSize(250, 150);
+ td.setVisible(true);
+ }
+}
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PageDlgPrnButton.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,228 @@
+/*
+ * Copyright (c) 2007, 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 4956397
+ * @run main/manual PageDlgPrnButton
+ */
+
+import java.awt.print.PrinterJob;
+import java.awt.print.PageFormat;
+import java.awt.print.Printable;
+import java.awt.print.PrinterException;
+
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.* ;
+
+public class PageDlgPrnButton implements Printable
+{
+ public static void main ( String args[] ) {
+
+ String[] instructions =
+ {"For non-windows OS, this test PASSes.",
+ "You must have at least 2 printers available to perform this test.",
+ "This test brings up a native Windows page dialog.",
+ "Click on the Printer... button and change the selected printer. ",
+ "Test passes if the printout comes from the new selected printer.",
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PageDlgPrnButton pdpb = new PageDlgPrnButton() ;
+ }
+
+ public PageDlgPrnButton()
+ {
+ try
+ {
+ pageDialogExample();
+ }
+ catch(Exception e)
+ {e.printStackTrace(System.err);}
+ }
+
+
+ // This example just displays the page dialog - you cannot change
+ // the printer (press the "Printer..." button and choose one if you like).
+ public void pageDialogExample() throws PrinterException
+ {
+ PrinterJob job = PrinterJob.getPrinterJob();
+ PageFormat originalPageFormat = job.defaultPage();
+ PageFormat pageFormat = job.pageDialog(originalPageFormat);
+
+ if(originalPageFormat == pageFormat) return;
+
+ job.setPrintable(this,pageFormat);
+ job.print();
+ }
+
+
+
+ public int print(Graphics g, PageFormat pageFormat, int pageIndex)
+ {
+ final int boxWidth = 100;
+ final int boxHeight = 100;
+ final Rectangle rect = new Rectangle(0,0,boxWidth,boxHeight);
+ final double pageH = pageFormat.getImageableHeight();
+ final double pageW = pageFormat.getImageableWidth();
+
+ if (pageIndex > 0) return (NO_SUCH_PAGE);
+
+ final Graphics2D g2d = (Graphics2D)g;
+
+ // Move the (x,y) origin to account for the left-hand and top margins
+ g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
+
+ // Draw the page bounding box
+ g2d.drawRect(0,0,(int)pageW,(int)pageH);
+
+ // Select the smaller scaling factor so that the figure
+ // fits on the page in both dimensions
+ final double scale = Math.min( (pageW/boxWidth), (pageH/boxHeight) );
+
+ if(scale < 1.0) g2d.scale(scale, scale);
+
+ // Paint the scaled component on the printer
+ g2d.fillRect(rect.x, rect.y, rect.width, rect.height);
+
+ return(PAGE_EXISTS);
+ }
+}
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PaintText.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2007, 2014, 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 6498340
+ * @summary No exception when printing text with a paint.
+ * @run main PaintText
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.text.*;
+import java.util.*;
+import java.awt.font.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import javax.swing.*;
+
+public class PaintText extends Component implements Printable {
+
+ static int preferredSize;
+ static int NUMTABS = 6;
+ int tabNumber;
+
+ public static void main(String args[]) {
+
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+ if (pjob.getPrintService() == null) {
+ System.out.println("No printers: cannot continue");
+ return;
+ }
+
+ PageFormat pf = pjob.defaultPage();
+ preferredSize = (int)pf.getImageableWidth();
+
+ Book book = new Book();
+
+ JTabbedPane p = new JTabbedPane();
+
+ for (int id=1; id <= NUMTABS; id++) {
+ String name = "Tab " + new Integer(id);
+ PaintText ptt = new PaintText(id);
+ p.add(name, ptt);
+ book.append(ptt, pf);
+ }
+ pjob.setPageable(book);
+
+ JFrame f = new JFrame();
+ f.add(BorderLayout.CENTER, p);
+ f.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {System.exit(0);}
+ });
+ f.pack();
+ f.show();
+
+ /* Non-jtreg execution will display the dialog */
+ if (System.getProperty("test.java") == null) {
+ if (!pjob.printDialog()) {
+ return;
+ }
+ }
+ try {
+ pjob.print();
+ } catch (PrinterException e) {
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ public PaintText(int id) {
+ tabNumber = id;
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+ System.out.println(""+pageIndex);
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pf.getImageableX(), pf.getImageableY());
+ g.drawString("ID="+tabNumber,100,20);
+ g.translate(0, 25);
+ paint(g);
+ return PAGE_EXISTS;
+ }
+
+ public Dimension getMinimumSize() {
+ return getPreferredSize();
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(preferredSize, preferredSize);
+ }
+
+ public void paint(Graphics g) {
+
+ /* fill with white before any transformation is applied */
+ g.setColor(Color.white);
+ g.fillRect(0, 0, getSize().width, getSize().height);
+
+ Graphics2D g2d = (Graphics2D)g;
+
+ Font f = new Font("Lucida Sans", Font.PLAIN, 40);
+ Color c = new Color(0,0,255,96);
+ Paint p = new GradientPaint(0f, 0f, Color.green,
+ 10f, 10f, Color.red,
+ true);
+ String s = "Sample Text To Paint";
+ float x = 20, y= 50;
+
+ switch (tabNumber) {
+ case 1:
+ g2d.setFont(f);
+ g2d.setColor(c);
+ g2d.drawString(s, x, y);
+ break;
+
+ case 2:
+ g2d.setFont(f);
+ g2d.setPaint(p);
+ g2d.drawString(s, x, y);
+ break;
+
+ case 3:
+ AttributedString as = new AttributedString(s);
+ as.addAttribute(TextAttribute.FONT, f);
+ as.addAttribute(TextAttribute.FOREGROUND, c);
+ g2d.drawString(as.getIterator(), x, y);
+ break;
+
+ case 4:
+ as = new AttributedString(s);
+ as.addAttribute(TextAttribute.FONT, f);
+ as.addAttribute(TextAttribute.FOREGROUND, p);
+ g2d.drawString(as.getIterator(), x, y);
+ break;
+
+ case 5:
+ as = new AttributedString(s);
+ as.addAttribute(TextAttribute.FONT, f);
+ as.addAttribute(TextAttribute.FOREGROUND, c);
+ FontRenderContext frc = g2d.getFontRenderContext();
+ TextLayout tl = new TextLayout(as.getIterator(), frc);
+ tl.draw(g2d, x, y);
+ break;
+
+ case 6:
+ as = new AttributedString(s);
+ as.addAttribute(TextAttribute.FONT, f);
+ as.addAttribute(TextAttribute.FOREGROUND, p);
+ frc = g2d.getFontRenderContext();
+ tl = new TextLayout(as.getIterator(), frc);
+ tl.draw(g2d, x, y);
+ break;
+
+ default:
+ }
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintAllFonts.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,213 @@
+/*
+ * Copyright (c) 2007, 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.
+ */
+
+/**
+ *
+ * @bug 4884389 7183516
+ * @summary Font specified with face name loses style on printing
+ * @run main/manual PrintRotatedText
+ */
+
+import java.awt.*;
+import java.awt.print.*;
+import java.awt.GraphicsEnvironment;
+
+public class PrintAllFonts implements Printable {
+
+ static Font[] allFonts;
+ int fontNum = 0;
+ int startNum = 0;
+ int lineHeight = 18;
+ boolean done = false;
+ int thisPage = 0;
+
+
+ public static void main(String[] args) throws Exception {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test and should use Win 98.",
+ "This bug is system dependent and is not always reproducible.",
+ " ",
+ "A passing test will have all text printed with correct font style.",
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ GraphicsEnvironment ge =
+ GraphicsEnvironment.getLocalGraphicsEnvironment();
+ allFonts = ge.getAllFonts();
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ pj.setPrintable(new PrintAllFonts());
+ if (pj.printDialog()) {
+ pj.print();
+ }
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+
+ if (fontNum >= allFonts.length && pageIndex > thisPage) {
+ return NO_SUCH_PAGE;
+ }
+ if (pageIndex > thisPage) {
+ startNum = fontNum;
+ thisPage = pageIndex;
+ } else {
+ fontNum = startNum;
+ }
+ g.setColor(Color.black);
+
+ int hgt = (int)pf.getImageableHeight();
+ int fontsPerPage = hgt/lineHeight;
+ int x = (int)pf.getImageableX()+10;
+ int y = (int)pf.getImageableY()+lineHeight;
+
+ for (int n = 0; n < fontsPerPage; n++) {
+ Font f = allFonts[fontNum].deriveFont(Font.PLAIN, 16);
+ g.setFont(f);
+ g.drawString(f.getFontName(), x, y);
+ y+= lineHeight;
+ fontNum++;
+ if (fontNum >= allFonts.length) {
+ break;
+ }
+ }
+ return PAGE_EXISTS;
+ }
+}
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintBadImage.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2007, 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 4398853
+ * @summary Printing shouldn't hang on bad images
+ * @author prr
+ * @run main/manual PrintBadImage
+ */
+
+import java.awt.*;
+import java.awt.print.*;
+
+
+public class PrintBadImage implements Printable {
+
+ public static void main(String args[]) {
+
+ PrintBadImage pbi = new PrintBadImage();
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ if (pj != null) {
+ pj.setPrintable(pbi);
+ try {
+ pj.print();
+ } catch (PrinterException pe) {
+ } finally {
+ System.err.println("PRINT RETURNED");
+ }
+ }
+ }
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+ if (pgIndex > 0)
+ return Printable.NO_SUCH_PAGE;
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+ Image imgJava = Toolkit.getDefaultToolkit().getImage("img.bad");
+ g2d.drawImage(imgJava, 0, 0, null);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintCompoundString.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,246 @@
+/*
+ * Copyright (c) 2007, 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 4396835
+ * @summary Compound font string not printing.
+ * @author prr
+ * @run main/manual PrintCompoundString
+ */
+
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+import java.text.*;
+
+public class PrintCompoundString extends Frame implements ActionListener {
+
+ private TextCanvas c;
+
+ public static void main(String args[]) {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test",
+ "This test should print a page which contains the same",
+ "text message as in the test window on the screen",
+ "You should also monitor the command line to see if any exceptions",
+ "were thrown",
+ "If an exception is thrown, or the page doesn't print properly",
+ "then the test fails",
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrintCompoundString f = new PrintCompoundString();
+ f.show();
+ }
+
+ public PrintCompoundString() {
+ super("JDK 1.2 drawString Printing");
+
+ c = new TextCanvas();
+ add("Center", c);
+
+ Button printButton = new Button("Print");
+ printButton.addActionListener(this);
+ add("South", printButton);
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+
+ pack();
+ }
+
+ public void actionPerformed(ActionEvent e) {
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (pj != null && pj.printDialog()) {
+
+ pj.setPrintable(c);
+ try {
+ pj.print();
+ } catch (PrinterException pe) {
+ } finally {
+ System.err.println("PRINT RETURNED");
+ }
+ }
+ }
+
+ class TextCanvas extends Panel implements Printable {
+
+ String nullStr = null;
+ String emptyStr = new String();
+ AttributedString nullAttStr = null;
+ AttributedString emptyAttStr = new AttributedString(emptyStr);
+ AttributedCharacterIterator nullIterator = null;
+ AttributedCharacterIterator emptyIterator = emptyAttStr.getIterator();
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+
+ if (pgIndex > 0)
+ return Printable.NO_SUCH_PAGE;
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+
+ paint(g);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public void paint(Graphics g1) {
+ Graphics2D g = (Graphics2D)g1;
+
+ String str = "Test string compound printing \u2203\u2200\u2211";
+ g.drawString(str, 20, 40);
+
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(450, 250);
+ }
+ }
+
+}
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintDialog.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,390 @@
+/*
+ * Copyright (c) 2007, 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 PrintDialog.java
+ @bug 4257903
+ @summary Confirm that the you see the print dialog.
+ @author prr: area=PrinterJob
+ @run main/manual PrintDialog
+*/
+
+
+//*** global search and replace PrintDialog with name of the test ***
+
+/**
+ * PrintDialog.java
+ *
+ * summary:
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+// This test is a "main" test as applets would need Runtime permission
+// "queuePrintJob".
+
+public class PrintDialog {
+
+
+ private static void init()
+ {
+ //*** Create instructions for the user here ***
+
+ String[] instructions =
+ {
+ "Visual inspection of the dialog is needed. It should be",
+ "a Printer Job Setup Dialog",
+ "You may cancel or OK the dialog."
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+ pjob.printDialog();
+
+ }//End init()
+
+
+ /*****************************************************
+ Standard Test Machinery Section
+ DO NOT modify anything in this section -- it's a
+ standard chunk of code which has all of the
+ synchronisation necessary for the test harness.
+ By keeping it the same in all tests, it is easier
+ to read and understand someone else's test, as
+ well as insuring that all tests behave correctly
+ with the test harness.
+ There is a section following this for test-defined
+ classes
+ ******************************************************/
+ private static boolean theTestPassed = false;
+ private static boolean testGeneratedInterrupt = false;
+ private static String failureMessage = "";
+
+ private static Thread mainThread = null;
+
+ private static int sleepTime = 300000;
+
+ public static void main( String args[] ) throws InterruptedException
+ {
+ mainThread = Thread.currentThread();
+ try
+ {
+ init();
+ }
+ catch( TestPassedException e )
+ {
+ //The test passed, so just return from main and harness will
+ // interepret this return as a pass
+ return;
+ }
+ //At this point, neither test passed nor test failed has been
+ // called -- either would have thrown an exception and ended the
+ // test, so we know we have multiple threads.
+
+ //Test involves other threads, so sleep and wait for them to
+ // called pass() or fail()
+ try
+ {
+ Thread.sleep( sleepTime );
+ //Timed out, so fail the test
+ throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
+ }
+ catch (InterruptedException e)
+ {
+ if( ! testGeneratedInterrupt ) throw e;
+
+ //reset flag in case hit this code more than once for some reason (just safety)
+ testGeneratedInterrupt = false;
+ if ( theTestPassed == false )
+ {
+ throw new RuntimeException( failureMessage );
+ }
+ }
+
+ }//main
+
+ public static synchronized void setTimeoutTo( int seconds )
+ {
+ sleepTime = seconds * 1000;
+ }
+
+ public static synchronized void pass()
+ {
+ Sysout.println( "The test passed." );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //first check if this is executing in main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //Still in the main thread, so set the flag just for kicks,
+ // and throw a test passed exception which will be caught
+ // and end the test.
+ theTestPassed = true;
+ throw new TestPassedException();
+ }
+ //pass was called from a different thread, so set the flag and interrupt
+ // the main thead.
+ theTestPassed = true;
+ testGeneratedInterrupt = true;
+ mainThread.interrupt();
+ }//pass()
+
+ public static synchronized void fail()
+ {
+ //test writer didn't specify why test failed, so give generic
+ fail( "it just plain failed! :-)" );
+ }
+
+ public static synchronized void fail( String whyFailed )
+ {
+ Sysout.println( "The test failed: " + whyFailed );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //check if this called from main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //If main thread, fail now 'cause not sleeping
+ throw new RuntimeException( whyFailed );
+ }
+ theTestPassed = false;
+ testGeneratedInterrupt = true;
+ failureMessage = whyFailed;
+ mainThread.interrupt();
+ }//fail()
+
+ }// class PrintDialog
+
+//This exception is used to exit from any level of call nesting
+// when it's determined that the test has passed, and immediately
+// end the test.
+class TestPassedException extends RuntimeException
+ {
+ }
+
+//*********** End Standard Test Machinery Section **********
+
+
+//************ Begin classes defined for the test ****************
+
+// make listeners in a class defined here, and instantiate them in init()
+
+/* Example of a class which may be written as part of a test
+class NewClass implements anInterface
+ {
+ static int newVar = 0;
+
+ public void eventDispatched(AWTEvent e)
+ {
+ //Counting events to see if we get enough
+ eventCount++;
+
+ if( eventCount == 20 )
+ {
+ //got enough events, so pass
+
+ PrintDialog.pass();
+ }
+ else if( tries == 20 )
+ {
+ //tried too many times without getting enough events so fail
+
+ PrintDialog.fail();
+ }
+
+ }// eventDispatched()
+
+ }// NewClass class
+
+*/
+
+
+//************** End classes defined for the test *******************
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog implements ActionListener
+ {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+ Panel buttonP = new Panel();
+ Button passB = new Button( "pass" );
+ Button failB = new Button( "fail" );
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ passB = new Button( "pass" );
+ passB.setActionCommand( "pass" );
+ passB.addActionListener( this );
+ buttonP.add( "East", passB );
+
+ failB = new Button( "fail" );
+ failB.setActionCommand( "fail" );
+ failB.addActionListener( this );
+ buttonP.add( "West", failB );
+
+ add( "South", buttonP );
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ //catch presses of the passed and failed buttons.
+ //simply call the standard pass() or fail() static methods of
+ //PrintDialog
+ public void actionPerformed( ActionEvent e )
+ {
+ if( e.getActionCommand() == "pass" )
+ {
+ PrintDialog.pass();
+ }
+ else
+ {
+ PrintDialog.fail();
+ }
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintDialogCancel.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,394 @@
+/*
+ * Copyright (c) 2007, 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 4398231
+ @summary Confirm that the print dialog returns false when cancelled.
+ @author prr: area=PrinterJob
+ @run main/manual PrintDialogCancel
+*/
+
+
+//*** global search and replace PrintDialogCancel with name of the test ***
+
+/**
+ * PrintDialogCancel.java
+ *
+ * summary:
+ */
+
+import javax.print.attribute.HashPrintRequestAttributeSet;
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+// This test is a "main" test as applets would need Runtime permission
+// "queuePrintJob".
+
+public class PrintDialogCancel {
+
+
+ private static void init()
+ {
+ //*** Create instructions for the user here ***
+
+ String[] instructions =
+ {
+ "Visual inspection of the dialog is needed. It should be",
+ "a Printer Job Setup Dialog",
+ "Do nothing except Cancel",
+ "You must NOT press OK",
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+ boolean rv = pjob.printDialog(new HashPrintRequestAttributeSet());
+ if (rv) {
+ throw new RuntimeException("User pressed cancel, but true returned");
+ }
+ }//End init()
+
+
+ /*****************************************************
+ Standard Test Machinery Section
+ DO NOT modify anything in this section -- it's a
+ standard chunk of code which has all of the
+ synchronisation necessary for the test harness.
+ By keeping it the same in all tests, it is easier
+ to read and understand someone else's test, as
+ well as insuring that all tests behave correctly
+ with the test harness.
+ There is a section following this for test-defined
+ classes
+ ******************************************************/
+ private static boolean theTestPassed = false;
+ private static boolean testGeneratedInterrupt = false;
+ private static String failureMessage = "";
+
+ private static Thread mainThread = null;
+
+ private static int sleepTime = 300000;
+
+ public static void main( String args[] ) throws InterruptedException
+ {
+ mainThread = Thread.currentThread();
+ try
+ {
+ init();
+ }
+ catch( TestPassedException e )
+ {
+ //The test passed, so just return from main and harness will
+ // interepret this return as a pass
+ return;
+ }
+ //At this point, neither test passed nor test failed has been
+ // called -- either would have thrown an exception and ended the
+ // test, so we know we have multiple threads.
+
+ //Test involves other threads, so sleep and wait for them to
+ // called pass() or fail()
+ try
+ {
+ Thread.sleep( sleepTime );
+ //Timed out, so fail the test
+ throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
+ }
+ catch (InterruptedException e)
+ {
+ if( ! testGeneratedInterrupt ) throw e;
+
+ //reset flag in case hit this code more than once for some reason (just safety)
+ testGeneratedInterrupt = false;
+ if ( theTestPassed == false )
+ {
+ throw new RuntimeException( failureMessage );
+ }
+ }
+
+ }//main
+
+ public static synchronized void setTimeoutTo( int seconds )
+ {
+ sleepTime = seconds * 1000;
+ }
+
+ public static synchronized void pass()
+ {
+ Sysout.println( "The test passed." );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //first check if this is executing in main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //Still in the main thread, so set the flag just for kicks,
+ // and throw a test passed exception which will be caught
+ // and end the test.
+ theTestPassed = true;
+ throw new TestPassedException();
+ }
+ //pass was called from a different thread, so set the flag and interrupt
+ // the main thead.
+ theTestPassed = true;
+ testGeneratedInterrupt = true;
+ mainThread.interrupt();
+ }//pass()
+
+ public static synchronized void fail()
+ {
+ //test writer didn't specify why test failed, so give generic
+ fail( "it just plain failed! :-)" );
+ }
+
+ public static synchronized void fail( String whyFailed )
+ {
+ Sysout.println( "The test failed: " + whyFailed );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //check if this called from main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //If main thread, fail now 'cause not sleeping
+ throw new RuntimeException( whyFailed );
+ }
+ theTestPassed = false;
+ testGeneratedInterrupt = true;
+ failureMessage = whyFailed;
+ mainThread.interrupt();
+ }//fail()
+
+ }// class PrintDialogCancel
+
+//This exception is used to exit from any level of call nesting
+// when it's determined that the test has passed, and immediately
+// end the test.
+class TestPassedException extends RuntimeException
+ {
+ }
+
+//*********** End Standard Test Machinery Section **********
+
+
+//************ Begin classes defined for the test ****************
+
+// make listeners in a class defined here, and instantiate them in init()
+
+/* Example of a class which may be written as part of a test
+class NewClass implements anInterface
+ {
+ static int newVar = 0;
+
+ public void eventDispatched(AWTEvent e)
+ {
+ //Counting events to see if we get enough
+ eventCount++;
+
+ if( eventCount == 20 )
+ {
+ //got enough events, so pass
+
+ PrintDialogCancel.pass();
+ }
+ else if( tries == 20 )
+ {
+ //tried too many times without getting enough events so fail
+
+ PrintDialogCancel.fail();
+ }
+
+ }// eventDispatched()
+
+ }// NewClass class
+
+*/
+
+
+//************** End classes defined for the test *******************
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog implements ActionListener
+ {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+ Panel buttonP = new Panel();
+ Button passB = new Button( "pass" );
+ Button failB = new Button( "fail" );
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ passB = new Button( "pass" );
+ passB.setActionCommand( "pass" );
+ passB.addActionListener( this );
+ buttonP.add( "East", passB );
+
+ failB = new Button( "fail" );
+ failB.setActionCommand( "fail" );
+ failB.addActionListener( this );
+ buttonP.add( "West", failB );
+
+ add( "South", buttonP );
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ //catch presses of the passed and failed buttons.
+ //simply call the standard pass() or fail() static methods of
+ //PrintDialogCancel
+ public void actionPerformed( ActionEvent e )
+ {
+ if( e.getActionCommand() == "pass" )
+ {
+ PrintDialogCancel.pass();
+ }
+ else
+ {
+ PrintDialogCancel.fail();
+ }
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintFontStyle.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) 2007, 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.*;
+import java.awt.print.*;
+import java.awt.GraphicsEnvironment;
+
+public class PrintFontStyle {
+ public static void main(String[] args) {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test and should use Win 98.",
+ "This bug is system dependent and is not always reproducible.",
+ " ",
+ "A passing test will have all text printed with correct font style.",
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJob pj=PrinterJob.getPrinterJob();
+ pj.setPrintable(new FontPrintable());
+ if (pj.printDialog())
+ {
+ try { pj.print(); }
+ catch (PrinterException e) {
+ System.out.println(e);
+ }
+ }
+ }
+}
+
+class FontPrintable
+ implements Printable {
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+ if (pageIndex != 0) return NO_SUCH_PAGE;
+ Graphics2D g2= (Graphics2D)g;
+
+ g2.setPaint(Color.black);
+
+ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ String[] fontList = ge.getAvailableFontFamilyNames();
+ g2.setFont (new Font ("Arial", Font.PLAIN, 20));
+ g2.drawString("Arial - Plain", 144, 120);
+ g2.setFont (new Font ("Arial", Font.BOLD, 20));
+ g2.drawString("Arial - Bold", 144, 145);
+ g2.setFont (new Font ("Arial", Font.ITALIC, 20));
+ g2.drawString("Arial - Italic", 144, 170);
+ g2.setFont (new Font ("Times New Roman", Font.PLAIN, 20));
+ g2.drawString("Times New Roman - Plain", 144, 195);
+ g2.setFont (new Font ("Times New Roman", Font.BOLD, 20));
+ g2.drawString("Times New Roman - Bold", 144, 220);
+ g2.setFont (new Font ("Times New Roman", Font.ITALIC, 20));
+ g2.drawString("Times New Roman - Italic", 144, 245);
+
+ return PAGE_EXISTS;
+ }
+}
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintImage.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,296 @@
+/*
+ * Copyright (c) 2007, 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 %I %W
+ * @bug 4298489
+ * @summary Confirm that output is same as screen.
+ * @author jgodinez
+ * @run main/manual PrintImage
+ */
+import java.awt.*;
+import java.awt.print.*;
+import java.awt.event.*;
+
+public class PrintImage extends Frame implements ActionListener {
+
+ private PrintImageCanvas printImageCanvas;
+
+ private MenuItem print1Menu = new MenuItem("PrintTest1");
+ private MenuItem print2Menu = new MenuItem("PrintTest2");
+ private MenuItem exitMenu = new MenuItem("Exit");
+
+ public static void main(String[] argv) {
+ String[] instructions =
+ { "You must have a printer available to perform this test,",
+ "prefererably Canon LaserShot A309GII.",
+ "Printing must be done in Win 98 Japanese 2nd Edition.",
+ "",
+ "Passing test : Output of text image for PrintTest1 and PrintTest2 should be same as that on the screen.",
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ new PrintImage();
+ }
+
+ public PrintImage() {
+ super("PrintImage");
+ initPrintImage();
+ }
+
+ public void initPrintImage() {
+
+ printImageCanvas = new PrintImageCanvas(this);
+
+ initMenu();
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent ev) {
+ dispose();
+ }
+ public void windowClosed(WindowEvent ev) {
+ System.exit(0);
+ }
+ });
+
+ setLayout(new BorderLayout());
+ add(printImageCanvas, BorderLayout.CENTER);
+ pack();
+
+ setSize(500,500);
+ setVisible(true);
+ }
+
+ private void initMenu() {
+ MenuBar mb = new MenuBar();
+ Menu me = new Menu("File");
+ me.add(print1Menu);
+ me.add(print2Menu);
+ me.add("-");
+ me.add(exitMenu);
+ mb.add(me);
+ this.setMenuBar(mb);
+
+ print1Menu.addActionListener(this);
+ print2Menu.addActionListener(this);
+ exitMenu.addActionListener(this);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ Object target = e.getSource();
+ if( target.equals(print1Menu) ) {
+ printMain1();
+ }
+ else if( target.equals(print2Menu) ) {
+ printMain2();
+ }
+ else if( target.equals(exitMenu) ) {
+ dispose();
+ }
+ }
+
+ private void printMain1(){
+
+ PrinterJob printerJob = PrinterJob.getPrinterJob();
+ PageFormat pageFormat = printerJob.defaultPage();
+
+ printerJob.setPrintable((Printable)printImageCanvas, pageFormat);
+
+ if(printerJob.printDialog()){
+ try {
+ printerJob.print();
+ }
+ catch(PrinterException p){
+ }
+ }
+ else
+ printerJob.cancel();
+ }
+
+ private void printMain2(){
+
+ PrinterJob printerJob = PrinterJob.getPrinterJob();
+ PageFormat pageFormat = printerJob.pageDialog(printerJob.defaultPage());
+
+ printerJob.setPrintable((Printable)printImageCanvas, pageFormat);
+
+ if(printerJob.printDialog()){
+ try {
+ printerJob.print();
+ }
+ catch(PrinterException p){
+ }
+ }
+ else
+ printerJob.cancel();
+ }
+
+}
+
+class PrintImageCanvas extends Canvas implements Printable {
+
+ private PrintImage pdsFrame;
+
+ public PrintImageCanvas(PrintImage pds) {
+ pdsFrame = pds;
+ }
+
+ public void paint(Graphics g) {
+ Font drawFont = new Font("MS Mincho",Font.ITALIC,50);
+ g.setFont(drawFont);
+ g.drawString("PrintSample!",100,150);
+ }
+
+ public int print(Graphics g, PageFormat pf, int pi)
+ throws PrinterException {
+
+ if(pi>=1)
+ return NO_SUCH_PAGE;
+ else{
+ Graphics2D g2 = (Graphics2D)g;
+ g.setColor(new Color(0,0,0,200));
+
+ Font drawFont = new Font("MS Mincho",Font.ITALIC,50);
+ g.setFont(drawFont);
+ g.drawString("PrintSample!",100,150);
+ return PAGE_EXISTS;
+ }
+ }
+}
+
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintNullString.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,328 @@
+/*
+ * Copyright (c) 2007, 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 4223328
+ * @summary Printer graphics must behave the same as screen graphics
+ * @author prr
+ * @run main/manual PrintNullString
+ */
+
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+import java.text.*;
+
+public class PrintNullString extends Frame implements ActionListener {
+
+ private TextCanvas c;
+
+ public static void main(String args[]) {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test",
+ "This test should print a page which contains the same",
+ "text messages as in the test window on the screen",
+ "The messages should contain only 'OK' and 'expected' messages",
+ "There should be no FAILURE messages.",
+ "You should also monitor the command line to see if any exceptions",
+ "were thrown",
+ "If the page fails to print, but there were no exceptions",
+ "then the problem is likely elsewhere (ie your printer)"
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrintNullString f = new PrintNullString();
+ f.show();
+ }
+
+ public PrintNullString() {
+ super("JDK 1.2 drawString Printing");
+
+ c = new TextCanvas();
+ add("Center", c);
+
+ Button printButton = new Button("Print");
+ printButton.addActionListener(this);
+ add("South", printButton);
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+
+ pack();
+ }
+
+ public void actionPerformed(ActionEvent e) {
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (pj != null && pj.printDialog()) {
+
+ pj.setPrintable(c);
+ try {
+ pj.print();
+ } catch (PrinterException pe) {
+ } finally {
+ System.err.println("PRINT RETURNED");
+ }
+ }
+ }
+
+ class TextCanvas extends Panel implements Printable {
+
+ String nullStr = null;
+ String emptyStr = new String();
+ AttributedString nullAttStr = null;
+ AttributedString emptyAttStr = new AttributedString(emptyStr);
+ AttributedCharacterIterator nullIterator = null;
+ AttributedCharacterIterator emptyIterator = emptyAttStr.getIterator();
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+
+ if (pgIndex > 0)
+ return Printable.NO_SUCH_PAGE;
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+
+ paint(g);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public void paint(Graphics g1) {
+ Graphics2D g = (Graphics2D)g1;
+
+ // API 1: null & empty drawString(String, int, int);
+ try {
+ g.drawString(nullStr, 20, 40);
+ g.drawString("FAILURE: No NPE for null String, int", 20, 40);
+ } catch (NullPointerException e) {
+ g.drawString("caught expected NPE for null String, int", 20, 40);
+ }/* catch (Exception e) {
+ g.drawString("FAILURE: unexpected exception for null String, int",
+ 20, 40);
+ }*/
+
+ //try {
+ g.drawString(emptyStr, 20, 60);
+ g.drawString("OK for empty String, int", 20, 60);
+ /*} catch (Exception e) {
+ g.drawString("FAILURE: unexpected exception for empty String, int",
+ 20, 60);
+ }*/
+
+
+ // API 2: null & empty drawString(String, float, float);
+ try {
+ g.drawString(nullStr, 20.0f, 80.0f);
+ g.drawString("FAILURE: No NPE for null String, float", 20, 80);
+ } catch (NullPointerException e) {
+ g.drawString("caught expected NPE for null String, float", 20, 80);
+ } /*catch (Exception e) {
+ g.drawString("FAILURE: unexpected exception for null String, float",
+ 20, 80);
+ }*/
+ //try {
+ g.drawString(emptyStr, 20.0f, 100.0f);
+ g.drawString("OK for empty String, float", 20.0f, 100.f);
+ /* } catch (Exception e) {
+ g.drawString("FAILURE: unexpected exception for empty String, float",
+ 20, 100);
+ }*/
+
+ // API 3: null & empty drawString(Iterator, int, int);
+ try {
+ g.drawString(nullIterator, 20, 120);
+ g.drawString("FAILURE: No NPE for null iterator, float", 20, 120);
+ } catch (NullPointerException e) {
+ g.drawString("caught expected NPE for null iterator, int", 20, 120);
+ } /*catch (Exception e) {
+ g.drawString("FAILURE: unexpected exception for null iterator, int",
+ 20, 120);
+ } */
+ try {
+ g.drawString(emptyIterator, 20, 140);
+ g.drawString("FAILURE: No IAE for empty iterator, int",
+ 20, 140);
+ } catch (IllegalArgumentException e) {
+ g.drawString("caught expected IAE for empty iterator, int",
+ 20, 140);
+ } /*catch (Exception e) {
+ g.drawString("FAILURE: unexpected exception for empty iterator, int",
+ 20, 140);
+ } */
+
+
+ // API 4: null & empty drawString(Iterator, float, int);
+ try {
+ g.drawString(nullIterator, 20.0f, 160.0f);
+ g.drawString("FAILURE: No NPE for null iterator, float", 20, 160);
+ } catch (NullPointerException e) {
+ g.drawString("caught expected NPE for null iterator, float", 20, 160);
+ } /*catch (Exception e) {
+ g.drawString("FAILURE: unexpected exception for null iterator, float",
+ 20, 160);
+ } */
+
+ try {
+ g.drawString(emptyIterator, 20, 180);
+ g.drawString("FAILURE: No IAE for empty iterator, float",
+ 20, 180);
+ } catch (IllegalArgumentException e) {
+ g.drawString("caught expected IAE for empty iterator, float",
+ 20, 180);
+ } /*catch (Exception e) {
+ g.drawString("FAILURE: unexpected exception for empty iterator, float",
+ 20, 180);
+ } */
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(450, 250);
+ }
+ }
+
+}
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintParenString.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,246 @@
+/*
+ * Copyright (c) 2007, 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 4399442
+ * @summary Brackets should be quoted in Postscript output
+ * @author prr
+ * @run main/manual PrintParenString
+ */
+
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+import java.text.*;
+
+public class PrintParenString extends Frame implements ActionListener {
+
+ private TextCanvas c;
+
+ public static void main(String args[]) {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test",
+ "This test should print a page which contains the same",
+ "text message as in the test window on the screen",
+ "You should also monitor the command line to see if any exceptions",
+ "were thrown",
+ "If an exception is thrown, or the page doesn't print properly",
+ "then the test fails",
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrintParenString f = new PrintParenString();
+ f.show();
+ }
+
+ public PrintParenString() {
+ super("JDK 1.2 drawString Printing");
+
+ c = new TextCanvas();
+ add("Center", c);
+
+ Button printButton = new Button("Print");
+ printButton.addActionListener(this);
+ add("South", printButton);
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+
+ pack();
+ }
+
+ public void actionPerformed(ActionEvent e) {
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (pj != null && pj.printDialog()) {
+
+ pj.setPrintable(c);
+ try {
+ pj.print();
+ } catch (PrinterException pe) {
+ } finally {
+ System.err.println("PRINT RETURNED");
+ }
+ }
+ }
+
+ class TextCanvas extends Panel implements Printable {
+
+ String nullStr = null;
+ String emptyStr = new String();
+ AttributedString nullAttStr = null;
+ AttributedString emptyAttStr = new AttributedString(emptyStr);
+ AttributedCharacterIterator nullIterator = null;
+ AttributedCharacterIterator emptyIterator = emptyAttStr.getIterator();
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+
+ if (pgIndex > 0)
+ return Printable.NO_SUCH_PAGE;
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+
+ paint(g);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public void paint(Graphics g1) {
+ Graphics2D g = (Graphics2D)g1;
+
+ String str = "String containing unclosed parenthesis (.";
+ g.drawString(str, 20, 40);
+
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(450, 250);
+ }
+ }
+
+}
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintRotatedText.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,204 @@
+/*
+ * Copyright (c) 2007, 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 4271596
+ * @bug 4460699
+ * @summary Rotated text printing
+ * @author prr
+ * @run main/manual PrintRotatedText
+ */
+
+/* Text is drawn as spokes of a wheel with both a uniform scale and
+ * a non-uniform scale.
+ * The test is checking whether the implementation properly handles this
+ * and in particular that asking win32 GDI to draw text rotated works
+ * properly.
+ *
+ */
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.font.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+
+public class PrintRotatedText extends Frame implements ActionListener {
+ static String fontname="Lucida Sans Regular"; // our font
+ private TextCanvas c;
+
+ public static void main(String args[]) {
+
+ PrintRotatedText f = new PrintRotatedText();
+ f.show();
+ }
+
+ public PrintRotatedText() {
+ super("JDK 1.2 Text Printing");
+
+ String []fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
+ for (int i=0;i<fonts.length;i++) {
+ if (fonts[i].equals("Times New Roman")) {
+ fontname = "Times New Roman";
+ }
+ }
+ c = new TextCanvas();
+ add("Center", c);
+
+ Button printButton = new Button("Print");
+ printButton.addActionListener(this);
+ add("South", printButton);
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+
+ pack();
+ }
+
+ public void actionPerformed(ActionEvent e) {
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (pj != null && pj.printDialog()) {
+
+ pj.setPageable(c);
+ try {
+ pj.print();
+ } catch (PrinterException pe) {
+ } finally {
+ System.err.println("PRINT RETURNED");
+ }
+ }
+ }
+
+ class TextCanvas extends Panel implements Pageable, Printable {
+
+ public static final int MAXPAGE = 8;
+ // public static final String extra ="\u0391A\u2200B\u2702C\u2778D";
+ public static final String extra ="\u0394\u03A9ABCD";
+ public String estr=extra;
+
+ public int getNumberOfPages() {
+ return MAXPAGE;
+ }
+
+ public PageFormat getPageFormat(int pageIndex) {
+ if (pageIndex > MAXPAGE) throw new IndexOutOfBoundsException();
+ PageFormat pf = new PageFormat();
+ Paper p = pf.getPaper();
+ p.setImageableArea(36, 36, p.getWidth()-72, p.getHeight()-72);
+ pf.setPaper(p);
+
+/*
+ if (pageIndex==1)
+ pf.setOrientation(PageFormat.LANDSCAPE);
+ else if (pageIndex==2)
+ pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
+*/
+
+ return pf;
+ }
+
+ public Printable getPrintable(int pageIndex) {
+ if (pageIndex > MAXPAGE) throw new IndexOutOfBoundsException();
+ return this;
+ }
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+System.out.println("****"+pgIndex);
+ double iw = pgFmt.getImageableWidth();
+ double ih = pgFmt.getImageableHeight();
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+ //g2d.drawString("top left of page format",20,20 );
+ int modulo = pgIndex % 4;
+ int divvy = pgIndex / 4;
+ if (divvy != 0 ) {
+ g2d.setFont(new Font(fontname,Font.PLAIN, 18));
+ estr = "";
+ } else {
+ estr = extra;
+ }
+
+ int xs = 1;
+ int ys = 1;
+
+ if (modulo == 1) {
+ xs = -1;
+ }
+ if (modulo == 2) {
+ ys = -1;
+ }
+ if (modulo == 3) {
+ xs = -1;
+ ys = -1;
+ }
+
+ g2d.translate(iw*0.25, ih*0.2);
+ drawTheText((Graphics2D)g2d.create(), xs*1.0,ys* 1.0);
+ g2d.translate(iw*0.25, ih*0.2);
+ drawTheText((Graphics2D)g2d.create(), xs*1.0,ys* 1.5);
+ g2d.translate(-iw*0.2, ih*0.3);
+ drawTheText((Graphics2D)g2d.create(), xs*1.5, ys*1.0);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ private void drawTheText(Graphics2D g2d, double sx, double sy) {
+ double mat[]= new double[6];
+
+ g2d.drawOval(-75,-75,150,150);
+ int degrees = 30;
+ for (int i=0;i<360;i=i+degrees) {
+ AffineTransform saveXfm = g2d.getTransform();
+ g2d.scale(sx, sy);
+ int ttype = g2d.getTransform().getType();
+ String s = "ANGLE="+i;
+ s +=estr;
+ g2d.drawString(s, 20, 0);
+ FontRenderContext frc = g2d.getFontRenderContext();
+ Font f = g2d.getFont();
+ Rectangle2D r2d = f.getStringBounds(s, frc);
+ g2d.drawLine(20, 1, 20+(int)r2d.getWidth(), 1);
+ g2d.scale(1.0/sx, 1.0/sy);
+ g2d.setTransform(saveXfm);
+
+ g2d.rotate(Math.toRadians(degrees));
+ }
+ }
+
+ public void paint(Graphics g) {
+ g.translate(200,200);
+ g.setFont(new Font("serif", Font.PLAIN, 12));
+ drawTheText((Graphics2D)g, 1.0, 1.5);
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(400, 400);
+ }
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintTextLayout.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2007, 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 4480930
+ * @summary TextLayout prints as filled shapes
+ * @author prr
+ * @run main/manual PrintTextLayout
+ */
+
+/* This is a MANUAL test and must be run on a system with a printer
+ * configured.
+ */
+
+import java.io.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.font.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import javax.print.attribute.*;
+import javax.print.attribute.standard.*;
+
+public class PrintTextLayout implements Printable {
+ static String[] fontnames = {
+ "Lucida Sans",
+ "Lucida Bright",
+ "Lucida Sans Typewriter",
+ "SansSerif",
+ "Serif",
+ "Monospaced",
+ };
+
+ static String text =
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890";
+
+ public static void main(String args[]) {
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (pj != null) {
+ PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
+ aset.add(new Destination((new File("./out.ps")).toURI()));
+ PageFormat pf = pj.defaultPage();
+ Paper p = pf.getPaper();
+ // Extend imageable width to reduce likelihood end of text
+ // is clipped as we'd like to see the end of the line.
+ p.setImageableArea(p.getImageableX(), p.getImageableY(),
+ p.getWidth()-p.getImageableX(),
+ p.getImageableHeight());
+ pf.setPaper(p);
+ pj.setPrintable( new PrintTextLayout(), pf);
+ try {
+ pj.print(aset);
+ } catch (PrinterException pe) {
+ pe.printStackTrace();
+ } finally {
+ }
+ }
+ }
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+ if (pgIndex > 0) return Printable.NO_SUCH_PAGE;
+
+ double iw = pgFmt.getImageableWidth();
+ double ih = pgFmt.getImageableHeight();
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY()+50);
+
+ float ypos = 20f;
+ for (int f=0; f< fontnames.length; f++) {
+ for (int s=0;s<4;s++) {
+ Font font = new Font(fontnames[f], s, 12);
+ ypos = drawText(g2d, font, ypos);
+ }
+ }
+ return Printable.PAGE_EXISTS;
+ }
+
+ float drawText(Graphics2D g2d, Font font, float ypos) {
+ int x = 10;
+ /* Set the graphics font to something odd before using TL so
+ * can be sure it picks up the font from the TL, not the graphics */
+ Font f1 = new Font("serif", Font.ITALIC, 1);
+ g2d.setFont(f1);
+ FontRenderContext frc = new FontRenderContext(null, false, false);
+ TextLayout tl = new TextLayout(text ,font, frc);
+ float ascent = tl.getAscent();
+ int dpos = (int)(ypos+ascent);
+ tl.draw(g2d, x, dpos);
+ int dpos2 = (int)(ypos+ascent+tl.getDescent());
+ g2d.drawLine(x, dpos2, x+(int)tl.getAdvance(), dpos2);
+ float tlHeight = tl.getAscent()+tl.getDescent()+tl.getLeading();
+ return ypos+tlHeight;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintTextPane.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2007, 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 PrintTextPane.java
+ @bug 6452415 6570471
+ @summary Test that swing text prints using GDI printer fonts.
+ @author prr: area=PrinterJob
+ @run main PrintTextPane
+
+ */
+import java.io.*;
+import java.net.*;
+import java.awt.*;
+import java.awt.event.*;
+import javax.print.attribute.*;
+import javax.print.attribute.standard.*;
+import javax.swing.*;
+import javax.swing.text.*;
+import java.awt.print.*;
+
+public class PrintTextPane extends JTextPane implements Printable {
+
+ static String text = "Twinkle twinkle little star, \n" +
+ "How I wonder what you are. \n" +
+ "Up above the world so high, \n" +
+ "Like a diamond in the sky. \n" +
+ "Twinkle, twinkle, little star, \n" +
+ "How I wonder what you are!\n";
+
+ public int print(Graphics g, PageFormat pf, int page)
+ throws PrinterException {
+ if (page > 0) {
+ return NO_SUCH_PAGE;
+ }
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pf.getImageableX(), pf.getImageableY());
+ printAll(g);
+ return PAGE_EXISTS;
+ }
+
+ public void printPane(PrintRequestAttributeSet aset) {
+ try {
+ print(null, null, false, null, aset, false);
+ } catch (PrinterException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ public void printPaneJob(PrintRequestAttributeSet aset) {
+ PrinterJob job = PrinterJob.getPrinterJob();
+ job.setPrintable(this);
+ try {
+ job.print(aset);
+ } catch (PrinterException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ public PrintTextPane(String fontFamily) {
+ super();
+ SimpleAttributeSet aset = new SimpleAttributeSet();
+ StyleConstants.setFontFamily(aset, fontFamily);
+ setCharacterAttributes(aset, false);
+ setText(text+text+text+text+text+text+text+text);
+ }
+
+ public static void main(String args[]) throws Exception {
+
+ String os = System.getProperty("os.name");
+
+ if (!os.startsWith("Windows")) {
+ return;
+ }
+
+ PrinterJob job = PrinterJob.getPrinterJob();
+ if (job.getPrintService() == null) {
+ System.err.println("Warning: no printers, skipping test");
+ return;
+ }
+ JFrame f = new JFrame("Print Text Pane1");
+ f.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {System.exit(0);}
+ });
+ PrintTextPane monoPane = new PrintTextPane("Monospaced");
+ f.add("East", monoPane);
+ PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
+ PrintTextPane courPane = new PrintTextPane("Courier New");
+ f.add("West", courPane);
+ f.pack();
+ f.setVisible(true);
+
+ File spoolFile = File.createTempFile("CourText", ".prn");
+ System.out.println(spoolFile);
+ Destination dest = new Destination(spoolFile.toURI());
+ aset.add(dest);
+ courPane.printPane(aset);
+ long courLen = spoolFile.length();
+ System.out.println("CourText="+spoolFile.length());
+ spoolFile.delete();
+
+ spoolFile = File.createTempFile("MonoText", ".prn");
+ System.out.println(spoolFile);
+ dest = new Destination(spoolFile.toURI());
+ aset.add(dest);
+ monoPane.printPane(aset);
+ long monoLen = spoolFile.length();
+ System.out.println("MonoText="+spoolFile.length());
+ spoolFile.delete();
+
+ if (courLen > 2 * monoLen) {
+ throw new RuntimeException("Shapes being printed?");
+ }
+
+ spoolFile = File.createTempFile("CourJob", ".prn");
+ System.out.println(spoolFile);
+ dest = new Destination(spoolFile.toURI());
+ aset.add(dest);
+ courPane.printPaneJob(aset);
+ courLen = spoolFile.length();
+ System.out.println("CourJob="+spoolFile.length());
+ spoolFile.delete();
+
+ spoolFile = File.createTempFile("MonoJob", ".prn");
+ System.out.println(spoolFile);
+ dest = new Destination(spoolFile.toURI());
+ aset.add(dest);
+ monoPane.printPaneJob(aset);
+ monoLen = spoolFile.length();
+ System.out.println("MonoJob="+spoolFile.length());
+ spoolFile.delete();
+
+ if (courLen > 2 * monoLen) {
+ throw new RuntimeException("Shapes being printed?");
+ }
+
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintTextTest.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,477 @@
+/*
+ * Copyright (c) 2007, 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.
+ */
+
+/**
+ * @test
+ * @bug 6425068 7157659
+ * @summary Confirm that text prints where we expect to the length we expect.
+ * @run main/manual=yesno PrintTextTest
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.text.*;
+import java.util.*;
+import java.awt.font.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import javax.swing.*;
+
+public class PrintTextTest extends Component implements Printable {
+
+ static int preferredSize;
+ Font textFont;
+ AffineTransform gxTx;
+ String page;
+ boolean useFM;
+
+ public static void main(String args[]) {
+ String[] instructions =
+ {
+ "This tests that printed text renders similarly to on-screen",
+ "under a variety of APIs and graphics and font transforms",
+ "Print to your preferred printer. Collect the output.",
+ "Refer to the onscreen buttons to cycle through the on-screen",
+ "content",
+ "For each page, confirm that the printed content corresponds to",
+ "the on-screen rendering for that *same* page.",
+ "Some cases may look odd but its intentional. Verify",
+ "it looks the same on screen and on the printer.",
+ "Note that text does not scale linearly from screen to printer",
+ "so some differences are normal and not a bug.",
+ "The easiest way to spot real problems is to check that",
+ "any underlines are the same length as the underlined text",
+ "and that any rotations are the same in each case.",
+ "Note that each on-screen page is printed in both portrait",
+ "and landscape mode",
+ "So for example, Page 1/Portrait, and Page 1/Landscape when",
+ "rotated to view properly, should both match Page 1 on screen.",
+ };
+ Sysout.createDialogWithInstructions(instructions);
+
+
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+ PageFormat portrait = pjob.defaultPage();
+ portrait.setOrientation(PageFormat.PORTRAIT);
+ preferredSize = (int)portrait.getImageableWidth();
+
+ PageFormat landscape = pjob.defaultPage();
+ landscape.setOrientation(PageFormat.LANDSCAPE);
+
+ Book book = new Book();
+
+ JTabbedPane p = new JTabbedPane();
+
+ int page = 1;
+ Font font = new Font("Dialog", Font.PLAIN, 18);
+ String name = "Page " + new Integer(page++);
+ PrintTextTest ptt = new PrintTextTest(name, font, null, false);
+ p.add(name, ptt);
+ book.append(ptt, portrait);
+ book.append(ptt, landscape);
+
+ font = new Font("Dialog", Font.PLAIN, 18);
+ name = "Page " + new Integer(page++);
+ ptt = new PrintTextTest(name, font, null, true);
+ p.add(name, ptt);
+ book.append(ptt, portrait);
+ book.append(ptt, landscape);
+
+ font = new Font("Lucida Sans", Font.PLAIN, 18);
+ name = "Page " + new Integer(page++);
+ ptt = new PrintTextTest(name, font, null, false);
+ p.add(name, ptt);
+ book.append(ptt, portrait);
+ book.append(ptt, landscape);
+
+ font = new Font("Lucida Sans", Font.PLAIN, 18);
+ AffineTransform rotTx = AffineTransform.getRotateInstance(0.15);
+ rotTx.translate(60,0);
+ name = "Page " + new Integer(page++);
+ ptt = new PrintTextTest(name, font, rotTx, false);
+ p.add(name, ptt);
+ book.append(ptt, portrait);
+ book.append(ptt, landscape);
+
+ font = font.deriveFont(rotTx);
+ name = "Page " + new Integer(page++);
+ ptt = new PrintTextTest(name, font, null, false);
+ p.add(ptt, BorderLayout.CENTER);
+ p.add(name, ptt);
+ book.append(ptt, portrait);
+ book.append(ptt, landscape);
+
+ if (System.getProperty("os.name").startsWith("Windows")) {
+ font = new Font("MS Gothic", Font.PLAIN, 12);
+ name = "Page " + new Integer(page++);
+ ptt = new PrintJAText(name, font, null, true);
+ p.add(ptt, BorderLayout.CENTER);
+ p.add(name, ptt);
+ book.append(ptt, portrait);
+ book.append(ptt, landscape);
+
+ font = new Font("MS Gothic", Font.PLAIN, 12);
+ name = "Page " + new Integer(page++);
+ rotTx = AffineTransform.getRotateInstance(0.15);
+ ptt = new PrintJAText(name, font, rotTx, true);
+ p.add(ptt, BorderLayout.CENTER);
+ p.add(name, ptt);
+ book.append(ptt, portrait);
+ book.append(ptt, landscape);
+ }
+
+ pjob.setPageable(book);
+
+ JFrame f = new JFrame();
+ f.add(BorderLayout.CENTER, p);
+ f.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {System.exit(0);}
+ });
+ f.pack();
+ f.show();
+
+ try {
+ if (pjob.printDialog()) {
+ pjob.print();
+ }
+ } catch (PrinterException e) {
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ public PrintTextTest(String page, Font font, AffineTransform gxTx,
+ boolean fm) {
+ this.page = page;
+ textFont = font;
+ this.gxTx = gxTx;
+ this.useFM = fm;
+ setBackground(Color.white);
+ }
+
+ public static AttributedCharacterIterator getIterator(String s) {
+ return new AttributedString(s).getIterator();
+ }
+
+ static String orient(PageFormat pf) {
+ if (pf.getOrientation() == PageFormat.PORTRAIT) {
+ return "Portrait";
+ } else {
+ return "Landscape";
+ }
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pf.getImageableX(), pf.getImageableY());
+ g.drawString(page+" "+orient(pf),50,20);
+ g.translate(0, 25);
+ paint(g);
+ return PAGE_EXISTS;
+ }
+
+ public Dimension getMinimumSize() {
+ return getPreferredSize();
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(preferredSize, preferredSize);
+ }
+
+ public void paint(Graphics g) {
+
+ /* fill with white before any transformation is applied */
+ g.setColor(Color.white);
+ g.fillRect(0, 0, getSize().width, getSize().height);
+
+
+ Graphics2D g2d = (Graphics2D) g;
+ if (gxTx != null) {
+ g2d.transform(gxTx);
+ }
+ if (useFM) {
+ g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
+ RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+ }
+
+ g.setFont(textFont);
+ FontMetrics fm = g.getFontMetrics();
+
+ String s;
+ int LS = 30;
+ int ix=10, iy=LS+10;
+ g.setColor(Color.black);
+
+ s = "drawString(String str, int x, int y)";
+ g.drawString(s, ix, iy);
+ if (!textFont.isTransformed()) {
+ g.drawLine(ix, iy+1, ix+fm.stringWidth(s), iy+1);
+ }
+
+ iy += LS;
+ s = "drawString(AttributedCharacterIterator iterator, int x, int y)";
+ g.drawString(getIterator(s), ix, iy);
+
+ iy += LS;
+ s = "\tdrawChars(\t\r\nchar[], int off, int len, int x, int y\t)";
+ g.drawChars(s.toCharArray(), 0, s.length(), ix, iy);
+ if (!textFont.isTransformed()) {
+ g.drawLine(ix, iy+1, ix+fm.stringWidth(s), iy+1);
+ }
+
+ iy += LS;
+ s = "drawBytes(byte[], int off, int len, int x, int y)";
+ byte data[] = new byte[s.length()];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) s.charAt(i);
+ }
+ g.drawBytes(data, 0, data.length, ix, iy);
+
+ Font f = g2d.getFont();
+ FontRenderContext frc = g2d.getFontRenderContext();
+
+ iy += LS;
+ s = "drawString(String s, float x, float y)";
+ g2d.drawString(s, (float) ix, (float) iy);
+ if (!textFont.isTransformed()) {
+ g.drawLine(ix, iy+1, ix+fm.stringWidth(s), iy+1);
+ }
+
+ iy += LS;
+ s = "drawString(AttributedCharacterIterator iterator, "+
+ "float x, float y)";
+ g2d.drawString(getIterator(s), (float) ix, (float) iy);
+
+ iy += LS;
+ s = "drawGlyphVector(GlyphVector g, float x, float y)";
+ GlyphVector gv = f.createGlyphVector(frc, s);
+ g2d.drawGlyphVector(gv, ix, iy);
+ Point2D adv = gv.getGlyphPosition(gv.getNumGlyphs());
+ if (!textFont.isTransformed()) {
+ g.drawLine(ix, iy+1, ix+(int)adv.getX(), iy+1);
+ }
+
+ iy += LS;
+ s = "GlyphVector with position adjustments";
+
+ gv = f.createGlyphVector(frc, s);
+ int ng = gv.getNumGlyphs();
+ adv = gv.getGlyphPosition(ng);
+ for (int i=0; i<ng; i++) {
+ Point2D gp = gv.getGlyphPosition(i);
+ double gx = gp.getX();
+ double gy = gp.getY();
+ if (i % 2 == 0) {
+ gy+=5;
+ } else {
+ gy-=5;
+ }
+ gp.setLocation(gx, gy);
+ gv.setGlyphPosition(i, gp);
+ }
+ g2d.drawGlyphVector(gv, ix, iy);
+ if (!textFont.isTransformed()) {
+ g.drawLine(ix, iy+1, ix+(int)adv.getX(), iy+1);
+ }
+
+ iy +=LS;
+ s = "drawString: \u0924\u094d\u0930 \u0915\u0948\u0930\u0947 End.";
+ g.drawString(s, ix, iy);
+ if (!textFont.isTransformed()) {
+ g.drawLine(ix, iy+1, ix+fm.stringWidth(s), iy+1);
+ }
+
+ iy += LS;
+ s = "TextLayout 1: \u0924\u094d\u0930 \u0915\u0948\u0930\u0947 End.";
+ TextLayout tl = new TextLayout(s, new HashMap(), frc);
+ tl.draw(g2d, ix, iy);
+
+ iy += LS;
+ s = "TextLayout 2: \u0924\u094d\u0930 \u0915\u0948\u0930\u0947 End.";
+ tl = new TextLayout(s, f, frc);
+ tl.draw(g2d, ix, iy);
+ }
+}
+
+class PrintJAText extends PrintTextTest {
+
+
+ public PrintJAText(String page, Font font, AffineTransform gxTx,
+ boolean fm) {
+ super(page, font, gxTx, fm);
+ }
+
+ private static final String TEXT =
+ "\u3042\u3044\u3046\u3048\u304a\u30a4\u30ed\u30cf" +
+ "\u30cb\u30db\u30d8\u30c8\u4e00\u4e01\u4e02\u4e05\uff08";
+
+
+ public void paint(Graphics g) {
+
+ /* fill with white before any transformation is applied */
+ g.setColor(Color.white);
+ g.fillRect(0, 0, getSize().width, getSize().height);
+
+
+ Graphics2D g2d = (Graphics2D) g;
+ if (gxTx != null) {
+ g2d.transform(gxTx);
+ }
+ if (useFM) {
+ g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
+ RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+ }
+
+ String text = TEXT + TEXT + TEXT;
+ g.setColor(Color.black);
+ int y = 20;
+ float origSize = 7f;
+ for (int i=0;i<11;i++) {
+ float size = origSize+(i*0.1f);
+ g2d.translate(0, size+6);
+ Font f = textFont.deriveFont(size);
+ g2d.setFont(f);
+ FontMetrics fontMetrics = g2d.getFontMetrics();
+ int stringWidth = fontMetrics.stringWidth(text);
+ g.drawLine(0, y+1, stringWidth, y+1);
+ g.drawString(text, 0, y);
+ y +=10;
+ }
+ }
+}
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog
+ {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 20, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("South", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+}// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintTranslatedFont.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,257 @@
+/*
+ * Copyright (c) 2007, 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 6359734
+ * @summary Test that fonts with a translation print where they should.
+ * @author prr
+ * @run main/manual PrintTranslatedFont
+ */
+
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import java.text.*;
+
+public class PrintTranslatedFont extends Frame implements ActionListener {
+
+ private TextCanvas c;
+
+ public static void main(String args[]) {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test",
+ "This test should print a page which contains the same",
+ "content as the test window on the screen, in particular the lines",
+ "should be immediately under the text",
+ "You should also monitor the command line to see if any exceptions",
+ "were thrown",
+ "If an exception is thrown, or the page doesn't print properly",
+ "then the test fails",
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrintTranslatedFont f = new PrintTranslatedFont();
+ f.show();
+ }
+
+ public PrintTranslatedFont() {
+ super("JDK 1.2 drawString Printing");
+
+ c = new TextCanvas();
+ add("Center", c);
+
+ Button printButton = new Button("Print");
+ printButton.addActionListener(this);
+ add("South", printButton);
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+
+ pack();
+ }
+
+ public void actionPerformed(ActionEvent e) {
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (pj != null && pj.printDialog()) {
+
+ pj.setPrintable(c);
+ try {
+ pj.print();
+ } catch (PrinterException pe) {
+ } finally {
+ System.err.println("PRINT RETURNED");
+ }
+ }
+ }
+
+ class TextCanvas extends Panel implements Printable {
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+
+ if (pgIndex > 0)
+ return Printable.NO_SUCH_PAGE;
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+
+ paint(g);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public void paint(Graphics g1) {
+ Graphics2D g = (Graphics2D)g1;
+
+ Font f = new Font("Dialog", Font.PLAIN, 20);
+ int tx = 20;
+ int ty = 20;
+ AffineTransform at = AffineTransform.getTranslateInstance(tx, ty);
+ f = f.deriveFont(at);
+ g.setFont(f);
+
+ FontMetrics fm = g.getFontMetrics();
+ String str = "Basic ascii string";
+ int sw = fm.stringWidth(str);
+ int posx = 20, posy = 40;
+ g.drawString(str, posx, posy);
+ g.drawLine(posx+tx, posy+ty+2, posx+tx+sw, posy+ty+2);
+
+ posx = 20; posy = 70;
+ str = "Test string compound printing \u2203\u2200";
+ sw = fm.stringWidth(str);
+ g.drawString(str, posx, posy);
+ g.drawLine(posx+tx, posy+ty+2, posx+tx+sw, posy+ty+2);
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(450, 250);
+ }
+ }
+
+}
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrintVolatileImage.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2007, 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 4511023
+ * @summary Image should be sent to printer, no exceptions thrown
+ * @author prr
+ * @run main/manual PrintVolatileImage
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.image.*;
+import java.awt.print.*;
+
+public class PrintVolatileImage extends Component
+ implements ActionListener, Printable {
+
+ VolatileImage vimg = null;
+
+ public static void main(String args[]) {
+ Frame f = new Frame();
+ PrintVolatileImage pvi = new PrintVolatileImage();
+ f.add("Center", pvi);
+ Button b = new Button("Print");
+ b.addActionListener(pvi);
+ f.add("South", b);
+ f.pack();
+ f.show();
+ }
+
+ public PrintVolatileImage() {
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(100,100);
+ }
+
+ public void paint(Graphics g) {
+ if (vimg == null) {
+ vimg = createVolatileImage(100,100);
+ Graphics ig = vimg.getGraphics();
+ ig.setColor(Color.white);
+ ig.fillRect(0,0,100,100);
+ ig.setColor(Color.black);
+ ig.drawLine(0,0,100,100);
+ ig.drawLine(100,0,0,100);
+ }
+ g.drawImage(vimg, 0,0, null);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (pj != null && pj.printDialog()) {
+ pj.setPrintable(this);
+ try {
+ pj.print();
+ } catch (PrinterException pe) {
+ } finally {
+ System.err.println("PRINT RETURNED");
+ }
+ }
+ }
+
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+ if (pgIndex > 0)
+ return Printable.NO_SUCH_PAGE;
+
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+ paint(g);
+ return Printable.PAGE_EXISTS;
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrinterDevice.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2007, 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.
+ */
+
+/*
+ *
+ * @bug 4276227
+ * @summary Checks that the PrinterGraphics is for a Printer GraphicsDevice.
+ * Test doesn't run unless there's a printer on the system.
+ * @author prr
+ * @run main/othervm PrinterDevice
+ */
+
+import java.awt.*;
+import java.awt.geom.*;
+import java.awt.print.*;
+import java.io.*;
+import javax.print.attribute.*;
+import javax.print.attribute.standard.*;
+
+public class PrinterDevice implements Printable {
+
+ public static void main(String args[]) throws PrinterException {
+ System.setProperty("java.awt.headless", "true");
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+ if (pj.getPrintService() == null) {
+ return; /* Need a printer to run this test */
+ }
+
+ PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
+ File f = new File("./out.prn");
+ f.deleteOnExit();
+ aset.add(new Destination(f.toURI()));
+ aset.add(OrientationRequested.LANDSCAPE);
+ pj.setPrintable(new PrinterDevice());
+ pj.print(aset);
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+ if (pageIndex > 0 ) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ /* Make sure calls to get DeviceConfig, its transforms,
+ * etc all work without exceptions and as expected */
+ Graphics2D g2 = (Graphics2D)g;
+ GraphicsConfiguration gConfig = g2.getDeviceConfiguration();
+ AffineTransform dt = gConfig.getDefaultTransform();
+ AffineTransform nt = gConfig.getNormalizingTransform();
+ AffineTransform gt = g2.getTransform();
+
+ System.out.println("Graphics2D transform = " + gt);
+ System.out.println("Default transform = " + dt);
+ System.out.println("Normalizing transform = " + nt);
+
+ Rectangle bounds = gConfig.getBounds();
+ System.out.println("Bounds = " + bounds);
+ if (!nt.isIdentity()) {
+ throw new RuntimeException("Expected Identity transdform");
+ }
+
+ /* Make sure that device really is TYPE_PRINTER */
+ GraphicsDevice gd = gConfig.getDevice();
+ System.out.println("Printer Device ID = " + gd.getIDstring());
+ if (!(gd.getType() == GraphicsDevice.TYPE_PRINTER)) {
+ throw new RuntimeException("Expected printer device");
+ }
+ System.out.println(" *** ");
+ System.out.println("");
+ return Printable.PAGE_EXISTS;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrinterDialogsModalityTest/PrinterDialogsModalityTest.html Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,43 @@
+<!--
+ Copyright (c) 2007, 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>
+<!--
+ @test
+ @bug 4784285 4785920
+ @summary check whether Print- and Page- dialogs are modal and correct window activated after their closing
+ @author Your Name: area=PrinterJob.modality
+ @run applet/manual=yesno PrinterDialogsModalityTest.html
+ -->
+<head>
+<title> PrinterDialogsModalityTest </title>
+</head>
+<body>
+
+<h1>PrinterDialogsModalityTest<br>Bug ID: 4784285 4785920</h1>
+
+<p> See the dialog box (usually in upper left corner) for instructions</p>
+
+<APPLET CODE="PrinterDialogsModalityTest.class" WIDTH=200 HEIGHT=200></APPLET>
+</body>
+</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrinterDialogsModalityTest/PrinterDialogsModalityTest.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,262 @@
+/*
+ * Copyright (c) 2007, 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 4784285 4785920
+ @summary check whether Print- and Page- dialogs are modal and correct window activated after their closing
+ @author son@sparc.spb.su: area=PrinterJob.modality
+ @run applet/manual=yesno PrinterDialogsModalityTest.html
+*/
+
+/**
+ * PrinterDialogsModalityTest.java
+ *
+ * summary: check whether Print- and Page- dialogs are modal and correct window activated after their closing
+ */
+
+import java.applet.Applet;
+
+import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.Dialog;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.TextArea;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import java.awt.print.PageFormat;
+import java.awt.print.PrinterJob;
+
+public class PrinterDialogsModalityTest extends Applet
+{
+ //Declare things used in the test, like buttons and labels here
+
+ public void init()
+ {
+ //Create instructions for the user here, as well as set up
+ // the environment -- set the layout manager, add buttons,
+ // etc.
+ this.setLayout (new BorderLayout ());
+
+ String[] instructions =
+ {
+ "This is a Windows only test, for other platforms consider it passed",
+ "After test start you will see frame titled \"test Frame\"",
+ "with two buttons - \"Page Dialog\" and \"Print Dialog\"",
+ "1. make the frame active by clicking on title",
+ "2. press \"Page Dialog\" button, page dailog should popup",
+ "3. make sure page dialog is modal (if not test is failed)",
+ "4. close the dialog (either cancel it or press ok)",
+ "5. make sure the frame is still active (if not test is failed)",
+ "6. press \"Print Dialog\" button, print dialog should popup",
+ "7. repeat steps 3.-5.",
+ "",
+ "If you are able to execute all steps successfully then test is passed, else failed."
+ };
+ Sysout.createDialogWithInstructions( instructions );
+
+ }//End init()
+
+ public void start ()
+ {
+ //Get things going. Request focus, set size, et cetera
+ setSize (200,200);
+ setVisible(true);
+ validate();
+
+ Button page = new Button("Page Dialog");
+ page.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ PrinterJob prnJob = PrinterJob.getPrinterJob();
+ prnJob.pageDialog(new PageFormat());
+ }
+ });
+ Button print = new Button("Print Dialog");
+ print.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ PrinterJob prnJob = PrinterJob.getPrinterJob();
+ prnJob.printDialog();
+ }
+ });
+ Frame frame = new Frame("Test Frame");
+ frame.setLayout(new FlowLayout());
+ frame.add(page);
+ frame.add(print);
+ frame.setLocation(200, 200);
+ frame.pack();
+ frame.setVisible(true);
+
+ }// start()
+
+ //The rest of this class is the actions which perform the test...
+
+ //Use Sysout.println to communicate with the user NOT System.out!!
+ //Sysout.println ("Something Happened!");
+
+}// class PrinterDialogsModalityTest
+
+/* Place other classes related to the test after this line */
+
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+{
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.setVisible(true);
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.setVisible(true);
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog
+{
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ setVisible(true);
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ System.out.println(messageIn);
+ }
+
+}// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/PrinterJobDialogBugDemo.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2007, 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 4775862
+ * @run main/manual PrinterJobDialogBugDemo
+ */
+import java.awt.BorderLayout;
+import java.awt.Container;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.print.Printable;
+import java.awt.print.PrinterException;
+import java.awt.print.PrinterJob;
+import javax.print.attribute.HashPrintRequestAttributeSet;
+import javax.print.attribute.PrintRequestAttributeSet;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.SwingConstants;
+
+public class PrinterJobDialogBugDemo extends JFrame implements Printable {
+
+ public static void main(String[] args) {
+ new PrinterJobDialogBugDemo();
+ }
+
+ private PrinterJobDialogBugDemo() {
+ super("Printer Job Dialog Bug Demo");
+
+ setDefaultCloseOperation(EXIT_ON_CLOSE);
+ setSize(700,700);
+
+ JButton btnPrint = new JButton("Print...");
+ btnPrint.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent ae) {
+ showPrintDialog();
+ }
+ });
+
+ Container contentPane = getContentPane();
+ contentPane.add(
+ new JLabel("<html>This is the main Application Window. " +
+ "To demonstrate the problem:" +
+ "<ol>" +
+ "<li>Click the Print button at the bottom of this window. " +
+ "The Print dialog will appear." +
+ "<li>Select another application window." +
+ "<li>On the Windows taskbar, click the coffee-cup icon for " +
+ "this demo application. This brings this window to the " +
+ "front but the Print dialog remains hidden. " +
+ "Since this window " +
+ "is no longer selectable, it can't be moved aside to expose "
++
+ "the Print dialog that is now behind it." +
+ "</ol>",
+ SwingConstants.CENTER),
+ BorderLayout.NORTH);
+ contentPane.add(btnPrint, BorderLayout.SOUTH);
+ setVisible(true);
+ }
+
+ private void showPrintDialog() {
+ PrinterJob printJob = PrinterJob.getPrinterJob();
+ printJob.setPrintable(this);
+ PrintRequestAttributeSet printRequestAttrSet =
+ new HashPrintRequestAttributeSet();
+ printJob.printDialog(printRequestAttrSet);
+ }
+
+ public int print(java.awt.Graphics g, java.awt.print.PageFormat pageFormat,
+int pageIndex) {
+ if (pageIndex == 0) {
+ return(PAGE_EXISTS);
+ } else {
+ return(NO_SUCH_PAGE);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/RemoveListener.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2007, 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 1.1 01/05/17
+ * @bug 4459889
+ * @summary No NullPointerException should occur.
+ * @run main RemoveListener
+*/
+import javax.print.*;
+import javax.print.attribute.*;
+import javax.print.event.*;
+import javax.print.attribute.standard.*;
+
+public class RemoveListener {
+ public static void main(String[] args){
+ PrintService[] pservices = PrintServiceLookup.lookupPrintServices(null, null);
+ if (pservices.length == 0){
+ return;
+ }
+ DocPrintJob pj = pservices[0].createPrintJob();
+ PrintJobAttributeSet aset = new HashPrintJobAttributeSet();
+ aset.add(JobState.PROCESSING);
+ PrintJobAttributeListener listener = new PJAListener();
+ pj.addPrintJobAttributeListener(listener, aset);
+ pj.removePrintJobAttributeListener(listener);
+ return;
+ }
+}
+
+class PJAListener implements PrintJobAttributeListener {
+ public void attributeUpdate(PrintJobAttributeEvent pjae){
+ return;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/ScaledText/ScaledText.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,438 @@
+/*
+ * Copyright (c) 2007, 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 4291373
+ @summary Printing of scaled text is wrong / disappearing
+ @author prr: area=PrinterJob
+ @run main/manual ScaledText
+*/
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+
+public class ScaledText implements Printable {
+
+ private Image opaqueimg,transimg;
+
+ private static void init() {
+
+ //*** Create instructions for the user here ***
+
+ String[] instructions = {
+ "On-screen inspection is not possible for this printing-specific",
+ "test therefore its only output is two printed pages.",
+ "To be able to run this test it is required to have a default",
+ "printer configured in your user environment.",
+ "",
+ "Visual inspection of the printed pages is needed. A passing",
+ "test will print a page on which 6 lines of text will be",
+ "printed, all of the same size. The test fails only if the sizes",
+ "are different, or not all of the sizes labelled 1.0, 2.0, 4.0",
+ "8.0, 16.0, 32.0 appear."
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+
+ Book book = new Book();
+
+ PageFormat portrait = pjob.defaultPage();
+ book.append(new ScaledText(),portrait);
+
+ pjob.setPageable(book);
+
+ if (pjob.printDialog()) {
+ try {
+ pjob.print();
+ } catch (PrinterException e) {
+ System.err.println(e);
+ e.printStackTrace();
+ }
+ }
+ System.out.println("Done Printing");
+
+ }//End init()
+
+
+ public ScaledText() {
+ }
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+
+ Graphics2D g2D = (Graphics2D) g;
+ g2D.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+
+ g2D.setColor(Color.black);
+ Font font = new Font("serif", Font.PLAIN, 1);
+
+ float scale;
+ float x;
+ float y;
+
+ scale = 1.0f;
+ x = 3.0f;
+ y = 3.0f;
+ printScale(g2D, font, scale, x, y);
+
+ scale = 2.0f;
+ x = 3.0f;
+ y = 3.5f;
+ printScale(g2D, font, scale, x, y);
+
+ scale = 4.0f;
+ x = 3.0f;
+ y = 4.0f;
+ printScale(g2D, font, scale, x, y);
+
+ scale = 8.0f;
+ x = 3.0f;
+ y = 4.5f;
+ printScale(g2D, font, scale, x, y);
+
+ scale = 16.0f;
+ x = 3.0f;
+ y = 5.0f;
+ printScale(g2D, font, scale, x, y);
+
+ scale = 32.0f;
+ x = 3.0f;
+ y = 5.5f;
+ printScale(g2D, font, scale, x, y);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ /**
+ * The graphics is scaled and the font and the positions
+ * are reduced in respect to the scaling, so that all
+ * printing should be the same.
+ *
+ * @param g2D graphics2D to paint on
+ * @param font font to paint
+ * @param scale scale for the painting
+ * @param x x position
+ * @param y y position
+ */
+ private void printScale(Graphics2D g2D, Font font,
+ float scale, float x, float y) {
+
+ int RES = 72;
+
+ g2D.scale(scale, scale);
+
+ g2D.setFont (font.deriveFont(10.0f / scale));
+ g2D.drawString("This text is scaled by a factor of " + scale,
+ x * RES / scale, y * RES / scale);
+
+ g2D.scale(1/scale, 1/scale);
+
+}
+
+ /*****************************************************
+ Standard Test Machinery Section
+ DO NOT modify anything in this section -- it's a
+ standard chunk of code which has all of the
+ synchronisation necessary for the test harness.
+ By keeping it the same in all tests, it is easier
+ to read and understand someone else's test, as
+ well as insuring that all tests behave correctly
+ with the test harness.
+ There is a section following this for test-defined
+ classes
+ ******************************************************/
+ private static boolean theTestPassed = false;
+ private static boolean testGeneratedInterrupt = false;
+ private static String failureMessage = "";
+
+ private static Thread mainThread = null;
+
+ private static int sleepTime = 300000;
+
+ public static void main( String args[] ) throws InterruptedException
+ {
+ mainThread = Thread.currentThread();
+ try
+ {
+ init();
+ }
+ catch( TestPassedException e )
+ {
+ //The test passed, so just return from main and harness will
+ // interepret this return as a pass
+ return;
+ }
+ //At this point, neither test passed nor test failed has been
+ // called -- either would have thrown an exception and ended the
+ // test, so we know we have multiple threads.
+
+ //Test involves other threads, so sleep and wait for them to
+ // called pass() or fail()
+ try
+ {
+ Thread.sleep( sleepTime );
+ //Timed out, so fail the test
+ throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
+ }
+ catch (InterruptedException e)
+ {
+ if( ! testGeneratedInterrupt ) throw e;
+
+ //reset flag in case hit this code more than once for some reason (just safety)
+ testGeneratedInterrupt = false;
+ if ( theTestPassed == false )
+ {
+ throw new RuntimeException( failureMessage );
+ }
+ }
+
+ }//main
+
+ public static synchronized void setTimeoutTo( int seconds )
+ {
+ sleepTime = seconds * 1000;
+ }
+
+ public static synchronized void pass()
+ {
+ Sysout.println( "The test passed." );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //first check if this is executing in main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //Still in the main thread, so set the flag just for kicks,
+ // and throw a test passed exception which will be caught
+ // and end the test.
+ theTestPassed = true;
+ throw new TestPassedException();
+ }
+ //pass was called from a different thread, so set the flag and interrupt
+ // the main thead.
+ theTestPassed = true;
+ testGeneratedInterrupt = true;
+ mainThread.interrupt();
+ }//pass()
+
+ public static synchronized void fail()
+ {
+ //test writer didn't specify why test failed, s fail( "it just plain failed! :-)" );
+ }
+
+ public static synchronized void fail( String whyFailed )
+ {
+ Sysout.println( "The test failed: " + whyFailed );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //check if this called from main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //If main thread, fail now 'cause not sleeping
+ throw new RuntimeException( whyFailed );
+ }
+ theTestPassed = false;
+ testGeneratedInterrupt = true;
+ failureMessage = whyFailed;
+ mainThread.interrupt();
+ }//fail()
+
+}// class ScaledText
+
+//This exception is used to exit from any level of call nesting
+// when it's determined that the test has passed, and immediately
+// end the test.
+class TestPassedException extends RuntimeException
+ {
+ }
+
+
+//************** End classes defined for the test *******************
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog implements ActionListener {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+ Panel buttonP = new Panel();
+ Button passB = new Button( "pass" );
+ Button failB = new Button( "fail" );
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ passB = new Button( "pass" );
+ passB.setActionCommand( "pass" );
+ passB.addActionListener( this );
+ buttonP.add( "East", passB );
+
+ failB = new Button( "fail" );
+ failB.setActionCommand( "fail" );
+ failB.addActionListener( this );
+ buttonP.add( "West", failB );
+
+ add( "South", buttonP );
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ //catch presses of the passed and failed buttons.
+ //simply call the standard pass() or fail() static methods of
+ //ScaledText
+ public void actionPerformed( ActionEvent e )
+ {
+ if( e.getActionCommand() == "pass" )
+ {
+ ScaledText.pass();
+ }
+ else
+ {
+ ScaledText.fail();
+ }
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/SecurityDialogTest.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,229 @@
+/*
+ * Copyright (c) 2007, 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 4937672 5100706 6252456
+ * @run main/manual SecurityDialogTest
+ */
+
+import java.awt.* ;
+import java.awt.print.* ;
+import java.io.*;
+import java.security.*;
+import javax.print.*;
+import javax.print.attribute.*;
+
+public class SecurityDialogTest {
+
+
+ public static void main ( String args[] ) {
+
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test.",
+ "This test brings up a native and cross-platform page and",
+ "print dialogs.",
+ "The dialogs should be displayed even when ",
+ "there is no queuePrintJob permission.",
+ "If the dialog has an option to save to file, the option ought",
+ "to be disabled if there is no read/write file permission.",
+ "You should test this by trying different policy files."
+ };
+
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ SecurityDialogTest pjc = new SecurityDialogTest() ;
+ }
+
+
+ public SecurityDialogTest() {
+
+ PrinterJob pj = PrinterJob.getPrinterJob() ;
+
+ // Install a security manager which does not allow reading and
+ // writing of files.
+ //PrintTestSecurityManager ptsm = new PrintTestSecurityManager();
+ SecurityManager ptsm = new SecurityManager();
+
+ try {
+ System.setSecurityManager(ptsm);
+ } catch (SecurityException e) {
+ System.out.println("Could not run test - security exception");
+ }
+
+ try {
+ PrintJob pjob = Toolkit.getDefaultToolkit().getPrintJob(new Frame(), "Printing", null, null);
+ Sysout.println("If the value of pjob is null, the test fails.\n");
+ Sysout.println(" pjob = "+pjob);
+ } catch (SecurityException e) {
+ }
+
+ PrintService[] services = PrinterJob.lookupPrintServices();
+ for (int i=0; i<services.length; i++) {
+ System.out.println("SecurityDialogTest service "+i+" : "+services[i]);
+ }
+
+ PrintService defservice = pj.getPrintService();
+ System.out.println("SecurityDialogTest default service : "+defservice);
+
+ System.out.println("SecurityDialogTest native PageDialog ");
+ PageFormat pf1 = pj.pageDialog(new PageFormat());
+
+ System.out.println("SecurityDialogTest swing PageDialog ");
+ PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
+ PageFormat pf2 = pj.pageDialog(attributes);
+
+ // With the security manager installed, save to file should now
+ // be denied.
+ System.out.println("SecurityDialogTest native printDialog ");
+ pj.printDialog();
+
+ System.out.println("SecurityDialogTest swing printDialog ");
+ pj.printDialog(attributes);
+ }
+
+
+ class PrintTestSecurityManager extends SecurityManager {
+ public void checkPackageAccess(String pkg) {
+ }
+ public void checkPropertyAccess(String key) {
+ }
+
+ }
+
+}
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/SetCopies/Test.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2007, 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 4694495
+ * @summary Check that the dialog shows copies = 3.
+ * @run main/manual Test
+ */
+import java.awt.print.*;
+import javax.print.*;
+import javax.print.attribute.*;
+import javax.print.attribute.standard.*;
+
+public class Test {
+ static public void main(String args[]) {
+ DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PAGEABLE;
+ PrintRequestAttributeSet aSet
+ = new HashPrintRequestAttributeSet();
+ PrintService[] services
+ = PrintServiceLookup.lookupPrintServices(flavor, aSet);
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ for (int i=0; i<services.length; i++)
+ System.out.println(services[i].getName());
+ try { pj.setPrintService(services[services.length-1]); }
+ catch (Exception e) { e.printStackTrace(); }
+ pj.setCopies(3);
+ pj.printDialog();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/SwingUIText.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,263 @@
+/*
+ * Copyright (c) 2007, 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 6488219 6560738 7158350 8017469
+ * @summary Test that text printed in Swing UI measures and looks OK.
+ * @run main/manual=yesno PrintTextTest
+ */
+
+import java.awt.*;
+import javax.swing.*;
+import java.awt.print.*;
+
+public class SwingUIText implements Printable {
+
+ static String[] instructions = {
+ "This tests that when a Swing UI is printed, that the text",
+ "in each component properly matches the length of the component",
+ "as seen on-screen, and that the spacing of the text is of",
+ "reasonable even-ness. This latter part is very subjective and",
+ "the comparison has to be with JDK1.5 GA, or JDK 1.6 GA",
+ };
+
+ static JFrame frame;
+
+ public static void main(String args[]) {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ createUI();
+ }
+ });
+ }
+
+ public static void createUI() {
+
+ Sysout.createDialogWithInstructions(instructions);
+
+ JPanel panel = new JPanel();
+ panel.setLayout(new GridLayout(4,1));
+
+ String text = "marvelous suspicious solving";
+ displayText(panel, text);
+
+ String itext = "\u0641\u0642\u0643 \u0644\u0627\u064b";
+ itext = itext+itext+itext+itext+itext+itext+itext;
+ displayText(panel, itext);
+
+ String itext2 = "\u0641"+text;
+ displayText(panel, itext2);
+
+ JEditorPane editor = new JEditorPane();
+ editor.setContentType("text/html");
+ String CELL = "<TD align=\"center\"><font style=\"font-size: 18;\">Text</font></TD>";
+ String TABLE_BEGIN = "<TABLE BORDER=1 cellpadding=1 cellspacing=0 width=100%>";
+ String TABLE_END = "</TABLE>";
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("<html><body>").append(TABLE_BEGIN);
+ for (int j = 0; j < 15; j++) {
+ buffer.append(CELL);
+ }
+ buffer.append("</tr>");
+ buffer.append(TABLE_END).append("</body></html>");
+ editor.setText(buffer.toString());
+
+ panel.add(editor);
+
+ frame = new JFrame("Swing UI Text Printing Test");
+ frame.getContentPane().add(panel);
+ frame.pack();
+ frame.setVisible(true);
+
+ PrinterJob job = PrinterJob.getPrinterJob();
+ PageFormat pf = job.defaultPage();
+ job.setPrintable(new SwingUIText(), pf);
+ if (job.printDialog()) {
+ try { job.print(); }
+ catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+
+ static void displayText(JPanel p, String text) {
+ JPanel panel = new JPanel();
+ panel.setLayout(new GridLayout(2,1));
+ JPanel row = new JPanel();
+ Font font = new Font("Dialog", Font.PLAIN, 12);
+
+ JLabel label = new JLabel(text);
+ label.setFont(font);
+ row.add(label);
+
+ JButton button = new JButton("Print "+text);
+ button.setMnemonic('P');
+ button.setFont(font);
+ row.add(button);
+
+ panel.add(row);
+
+ row = new JPanel();
+ JTextField textField = new JTextField(text);
+ row.add(textField);
+
+ JTextArea textArea = new JTextArea();
+ textArea.setText(text);
+ row.add(textArea);
+
+ panel.add(row);
+ p.add(panel);
+ }
+
+ public int print(Graphics g, PageFormat pf, int pageIndex)
+ throws PrinterException {
+
+ if (pageIndex >= 1) {
+ return Printable.NO_SUCH_PAGE;
+ }
+ g.translate((int)pf.getImageableX(), (int)pf.getImageableY());
+ frame.printAll(g);
+
+ return Printable.PAGE_EXISTS;
+ }
+
+}
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog
+ {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 10, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("South", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+}// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/ThinLines.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,429 @@
+/*
+ * Copyright (c) 2007, 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 4190081
+ @summary Confirm that the you see "Z" shapes on the printed page.
+ @author prr/rbi: area=PrinterJob
+ @run main/manual ThinLines
+*/
+
+
+//*** global search and replace ThinLines with name of the test ***
+
+/**
+ * ThinLines.java
+ *
+ * summary:
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+
+// This test is a "main" test as applets would need Runtime permission
+// "queuePrintJob".
+
+public class ThinLines implements Printable {
+
+ private static final int INCH = 72;
+
+ private static void init()
+ {
+ //*** Create instructions for the user here ***
+
+ String[] instructions =
+ {
+ "On-screen inspection is not possible for this printing-specific",
+ "test therefore its only output is a printed page.",
+ "To be able to run this test it is required to have a default",
+ "printer configured in your user environment.",
+ "",
+ "Visual inspection of the printed page is needed. A passing",
+ "test will print a large \"Z\" shape which is repeated 6 times.",
+ "The top-most and diagonal lines of each \"Z\" are thin lines.",
+ "The bottom line of each \"Z\" is a thicker line.",
+ "In a failing test, the thin lines do not appear."
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ PrinterJob pjob = PrinterJob.getPrinterJob();
+ PageFormat pf = pjob.defaultPage();
+ Book book = new Book();
+
+ book.append(new ThinLines(), pf);
+ pjob.setPageable(book);
+
+ try {
+ pjob.print();
+ } catch (PrinterException e) {
+ e.printStackTrace();
+ }
+
+ }//End init()
+
+ public int print(Graphics g, PageFormat pf, int pageIndex) {
+ Graphics2D g2d = (Graphics2D) g;
+ g2d.translate(pf.getImageableX(), pf.getImageableY());
+
+ g2d.setColor(Color.black);
+ Stroke thinLine = new BasicStroke(0.01f);
+ Stroke thickLine = new BasicStroke(1.0f);
+
+
+ for (int y = 100; y < 900; y += 100) {
+ g2d.setStroke(thinLine);
+ g2d.drawLine(INCH, y, INCH * 3, y);
+ g2d.drawLine(INCH * 3, y, INCH, y + INCH/2);
+ g2d.setStroke(thickLine);
+ g2d.drawLine(INCH, y + INCH/2, INCH * 3, y + INCH/2);
+ }
+
+ return PAGE_EXISTS;
+ }
+
+
+
+ /*****************************************************
+ Standard Test Machinery Section
+ DO NOT modify anything in this section -- it's a
+ standard chunk of code which has all of the
+ synchronisation necessary for the test harness.
+ By keeping it the same in all tests, it is easier
+ to read and understand someone else's test, as
+ well as insuring that all tests behave correctly
+ with the test harness.
+ There is a section following this for test-defined
+ classes
+ ******************************************************/
+ private static boolean theTestPassed = false;
+ private static boolean testGeneratedInterrupt = false;
+ private static String failureMessage = "";
+
+ private static Thread mainThread = null;
+
+ private static int sleepTime = 300000;
+
+ public static void main( String args[] ) throws InterruptedException
+ {
+ mainThread = Thread.currentThread();
+ try
+ {
+ init();
+ }
+ catch( TestPassedException e )
+ {
+ //The test passed, so just return from main and harness will
+ // interepret this return as a pass
+ return;
+ }
+ //At this point, neither test passed nor test failed has been
+ // called -- either would have thrown an exception and ended the
+ // test, so we know we have multiple threads.
+
+ //Test involves other threads, so sleep and wait for them to
+ // called pass() or fail()
+ try
+ {
+ Thread.sleep( sleepTime );
+ //Timed out, so fail the test
+ throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
+ }
+ catch (InterruptedException e)
+ {
+ if( ! testGeneratedInterrupt ) throw e;
+
+ //reset flag in case hit this code more than once for some reason (just safety)
+ testGeneratedInterrupt = false;
+ if ( theTestPassed == false )
+ {
+ throw new RuntimeException( failureMessage );
+ }
+ }
+
+ }//main
+
+ public static synchronized void setTimeoutTo( int seconds )
+ {
+ sleepTime = seconds * 1000;
+ }
+
+ public static synchronized void pass()
+ {
+ Sysout.println( "The test passed." );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //first check if this is executing in main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //Still in the main thread, so set the flag just for kicks,
+ // and throw a test passed exception which will be caught
+ // and end the test.
+ theTestPassed = true;
+ throw new TestPassedException();
+ }
+ //pass was called from a different thread, so set the flag and interrupt
+ // the main thead.
+ theTestPassed = true;
+ testGeneratedInterrupt = true;
+ mainThread.interrupt();
+ }//pass()
+
+ public static synchronized void fail()
+ {
+ //test writer didn't specify why test failed, so give generic
+ fail( "it just plain failed! :-)" );
+ }
+
+ public static synchronized void fail( String whyFailed )
+ {
+ Sysout.println( "The test failed: " + whyFailed );
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
+ //check if this called from main thread
+ if ( mainThread == Thread.currentThread() )
+ {
+ //If main thread, fail now 'cause not sleeping
+ throw new RuntimeException( whyFailed );
+ }
+ theTestPassed = false;
+ testGeneratedInterrupt = true;
+ failureMessage = whyFailed;
+ mainThread.interrupt();
+ }//fail()
+
+ }// class ThinLines
+
+//This exception is used to exit from any level of call nesting
+// when it's determined that the test has passed, and immediately
+// end the test.
+class TestPassedException extends RuntimeException
+ {
+ }
+
+//*********** End Standard Test Machinery Section **********
+
+
+//************ Begin classes defined for the test ****************
+
+// make listeners in a class defined here, and instantiate them in init()
+
+/* Example of a class which may be written as part of a test
+class NewClass implements anInterface
+ {
+ static int newVar = 0;
+
+ public void eventDispatched(AWTEvent e)
+ {
+ //Counting events to see if we get enough
+ eventCount++;
+
+ if( eventCount == 20 )
+ {
+ //got enough events, so pass
+
+ ThinLines.pass();
+ }
+ else if( tries == 20 )
+ {
+ //tried too many times without getting enough events so fail
+
+ ThinLines.fail();
+ }
+
+ }// eventDispatched()
+
+ }// NewClass class
+
+*/
+
+
+//************** End classes defined for the test *******************
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog implements ActionListener
+ {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+ Panel buttonP = new Panel();
+ Button passB = new Button( "pass" );
+ Button failB = new Button( "fail" );
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ passB = new Button( "pass" );
+ passB.setActionCommand( "pass" );
+ passB.addActionListener( this );
+ buttonP.add( "East", passB );
+
+ failB = new Button( "fail" );
+ failB.setActionCommand( "fail" );
+ failB.addActionListener( this );
+ buttonP.add( "West", failB );
+
+ add( "South", buttonP );
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ //catch presses of the passed and failed buttons.
+ //simply call the standard pass() or fail() static methods of
+ //ThinLines
+ public void actionPerformed( ActionEvent e )
+ {
+ if( e.getActionCommand() == "pass" )
+ {
+ ThinLines.pass();
+ }
+ else
+ {
+ ThinLines.fail();
+ }
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/XparColor.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,258 @@
+/*
+ * Copyright (c) 2007, 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.
+ */
+
+/**
+ * @bug 4179262
+ * @summary Confirm that transparent colors are printed correctly. The
+ * printout should show transparent rings with increasing darkness toward
+ * the center.
+ *@run applet/manual=yesno XparColor.html
+ */
+
+import java.applet.Applet;
+import java.awt.*;
+import java.awt.print.*;
+import java.awt.event.*;
+import java.awt.geom.Ellipse2D;
+
+
+/**
+ * Creating colors with an alpha value.
+ */
+public class XparColor extends Applet implements Printable {
+
+ public void init() {
+ String[] instructions =
+ {
+ "This test verify that the BullsEye rings are printed correctly. The printout should show transparent rings with increasing darkness toward the center"
+ };
+ Sysout.createDialogWithInstructions( instructions );
+ }
+
+ public XparColor() {
+ PrinterJob printJob = PrinterJob.getPrinterJob();
+ printJob.setPrintable(this);
+ if (printJob.printDialog()) {
+ try {
+ printJob.print();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+
+ public static void main(String s[]) {
+ XparColor xc = new XparColor();
+ PrinterJob printJob = PrinterJob.getPrinterJob();
+ printJob.setPrintable(xc);
+ if (printJob.printDialog()) {
+ try {
+ printJob.print();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ public int print(Graphics g, PageFormat pf, int pi)
+ throws PrinterException {
+ if (pi >= 1) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ Graphics2D g2d = (Graphics2D) g;
+ g2d.translate(pf.getImageableX(), pf.getImageableY());
+ g2d.translate(pf.getImageableWidth() / 2,
+ pf.getImageableHeight() / 2);
+
+ Dimension d = new Dimension(400, 400);
+
+ double scale = Math.min(pf.getImageableWidth() / d.width,
+ pf.getImageableHeight() / d.height);
+ if (scale < 1.0) {
+ g2d.scale(scale, scale);
+ }
+
+ g2d.translate(-d.width / 2.0, -d.height / 2.0);
+
+ Graphics2D g2 = (Graphics2D)g;
+ drawDemo(d.width, d.height, g2);
+ g2.dispose();
+
+ return Printable.PAGE_EXISTS;
+ }
+
+ public void drawDemo(int w, int h, Graphics2D g2) {
+
+ Color reds[] = { Color.red.darker(), Color.red };
+ for (int N = 0; N < 18; N++) {
+ float i = (N + 2) / 2.0f;
+ float x = (float) (5+i*(w/2/10));
+ float y = (float) (5+i*(h/2/10));
+ float ew = (w-10)-(i*w/10);
+ float eh = (h-10)-(i*h/10);
+ float alpha = (N == 0) ? 0.1f : 1.0f / (19.0f - N);
+ if ( N >= 16 )
+ g2.setColor(reds[N-16]);
+ else
+ g2.setColor(new Color(0f, 0f, 0f, alpha));
+ g2.fill(new Ellipse2D.Float(x,y,ew,eh));
+ }
+ }
+}
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+ chunk of code whose purpose is to make user
+ interaction uniform, and thereby make it simpler
+ to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+ for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+ WithInstructions method. Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+ with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+ as standalone.
+ */
+
+class Sysout
+ {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+ }// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog
+ {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("South", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/print/PrinterJob/raster/RasterTest.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,268 @@
+/*
+ * Copyright (c) 2007, 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 4242639
+ * @summary Printing quality problem on Canon and NEC
+ * @author prr
+ * @run main/manual RasterTest
+ */
+import java.awt.*;
+import java.awt.geom.*;
+import java.awt.event.*;
+import java.awt.print.*;
+import java.awt.Toolkit;
+import java.awt.image.BufferedImage;
+
+
+public class RasterTest extends Frame implements ActionListener {
+
+ private RasterCanvas c;
+
+ public static void main(String args[]) {
+ String[] instructions =
+ {
+ "You must have a printer available to perform this test",
+ "This test uses rendering operations which force the implementation",
+ "to print the page as a raster",
+ "You should see two square images, the 1st containing overlapping",
+ "composited squares, the lower image shows a gradient paint.",
+ "The printed output should match the on-screen display, although",
+ "only colour printers will be able to accurately reproduce the",
+ "subtle color changes."
+ };
+ Sysout.createDialog( );
+ Sysout.printInstructions( instructions );
+
+ RasterTest f = new RasterTest();
+ f.show();
+ }
+
+ public RasterTest() {
+ super("Java 2D Raster Printing");
+
+ c = new RasterCanvas();
+ add("Center", c);
+
+ Button printButton = new Button("Print");
+ printButton.addActionListener(this);
+ add("South", printButton);
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+
+ pack();
+
+ setBackground(Color.white);
+
+ }
+
+ public void actionPerformed(ActionEvent e) {
+
+ PrinterJob pj = PrinterJob.getPrinterJob();
+
+ if (pj != null && pj.printDialog()) {
+ pj.setPrintable(c);
+ try {
+ pj.print();
+ } catch (PrinterException pe) {
+ } finally {
+ System.err.println("PRINT RETURNED");
+ }
+ }
+}
+
+
+ class RasterCanvas extends Canvas implements Printable {
+
+
+ public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
+ if (pgIndex > 0)
+ return Printable.NO_SUCH_PAGE;
+
+ Graphics2D g2d= (Graphics2D)g;
+ g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
+ doPaint(g2d);
+ return Printable.PAGE_EXISTS;
+ }
+
+ public void paint(Graphics g) {
+ doPaint(g);
+ }
+
+ public void paintComponent(Graphics g) {
+ doPaint(g);
+ }
+
+ public void doPaint(Graphics g) {
+ Graphics2D g2 = (Graphics2D)g;
+
+ g2.setColor(Color.black);
+
+ BufferedImage bimg = new BufferedImage(200, 200,
+ BufferedImage.TYPE_INT_ARGB);
+ Graphics ig = bimg.getGraphics();
+ Color alphared = new Color(255, 0, 0, 128);
+ Color alphagreen = new Color(0, 255, 0, 128);
+ Color alphablue = new Color(0, 0, 255, 128);
+ ig.setColor(alphared);
+ ig.fillRect(0,0,200,200);
+ ig.setColor(alphagreen);
+ ig.fillRect(25,25,150,150);
+ ig.setColor(alphablue);
+ ig.fillRect(75,75,125,125);
+ g.drawImage(bimg, 10, 25, this);
+
+ GradientPaint gp =
+ new GradientPaint(10.0f, 10.0f, alphablue, 210.0f, 210.0f, alphared, true);
+ g2.setPaint(gp);
+ g2.fillRect(10, 240, 200, 200);
+
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(500, 500);
+ }
+
+ }
+
+}
+
+
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions( String[] instructions )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ dialog.printInstructions( instructions );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+ public static void createDialog( )
+ {
+ dialog = new TestDialog( new Frame(), "Instructions" );
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
+ dialog.printInstructions( defInstr );
+ dialog.show();
+ println( "Any messages for the tester will display here." );
+ }
+
+
+ public static void printInstructions( String[] instructions )
+ {
+ dialog.printInstructions( instructions );
+ }
+
+
+ public static void println( String messageIn )
+ {
+ dialog.displayMessage( messageIn );
+ }
+
+}// Sysout class
+
+/**
+ This is part of the standard test machinery. It provides a place for the
+ test instructions to be displayed, and a place for interactive messages
+ to the user to be displayed.
+ To have the test instructions displayed, see Sysout.
+ To have a message to the user be displayed, see Sysout.
+ Do not call anything in this dialog directly.
+ */
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog( Frame frame, String name )
+ {
+ super( frame, name );
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+ add( "North", instructionsText );
+
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+ add("Center", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions( String[] instructions )
+ {
+ //Clear out any current instructions
+ instructionsText.setText( "" );
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for( int i=0; i < instructions.length; i++ )
+ {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[ i ];
+ while( remainingStr.length() > 0 )
+ {
+ //if longer than max then chop off first max chars to print
+ if( remainingStr.length() >= maxStringLength )
+ {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf( ' ', maxStringLength - 1 );
+
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
+ }
+ //else just print
+ else
+ {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append( printStr + "\n" );
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage( String messageIn )
+ {
+ messageText.append( messageIn + "\n" );
+ }
+
+ }// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/beans/Introspector/Test8039776.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2014, 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.Set;
+import java.util.SortedSet;
+
+import static java.beans.Introspector.getBeanInfo;
+
+/*
+ * @test
+ * @bug 8039776
+ * @summary Tests that Introspector does not throw NPE
+ * @author Sergey Malenkov
+ */
+
+public class Test8039776 {
+ public static void main(String[] args) throws Exception {
+ getBeanInfo(Base.class, Object.class);
+ getBeanInfo(Child.class, Base.class);
+ getBeanInfo(Child.class, Object.class);
+ }
+
+ public static class Base {
+ private SortedSet<Object> value;
+
+ public Set<Object> getValue() {
+ return this.value;
+ }
+
+ public void setValue(SortedSet<Object> value) {
+ this.value = value;
+ }
+ }
+
+ public static class Child extends Base {
+ public Set<Object> getValue() {
+ return super.getValue();
+ }
+
+ public void setValue(SortedSet<Object> items) {
+ super.setValue(items);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/beans/Introspector/TestCacheRecursion.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2014, 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.util.Cache;
+
+/*
+ * @test
+ * @bug 8039137
+ * @summary Tests Cache recursion
+ * @author Sergey Malenkov
+ * @compile -XDignore.symbol.file TestCacheRecursion.java
+ * @run main TestCacheRecursion
+ */
+
+public class TestCacheRecursion {
+ private static boolean ERROR;
+ private static final Cache<Class<?>,Boolean> CACHE
+ = new Cache<Class<?>,Boolean>(Cache.Kind.WEAK, Cache.Kind.STRONG) {
+ @Override
+ public Boolean create(Class<?> type) {
+ if (ERROR) {
+ throw new Error("not initialized");
+ }
+ type = type.getSuperclass();
+ return (type != null) && get(type);
+ }
+ };
+
+ public static void main(String[] args) {
+ CACHE.get(Z.class);
+ ERROR = true;
+ for (Class<?> type = Z.class; type != null; type = type.getSuperclass()) {
+ CACHE.get(type);
+ }
+ }
+
+ private class A {}
+ private class B extends A {}
+ private class C extends B {}
+ private class D extends C {}
+ private class E extends D {}
+ private class F extends E {}
+ private class G extends F {}
+ private class H extends G {}
+ private class I extends H {}
+ private class J extends I {}
+ private class K extends J {}
+ private class L extends K {}
+ private class M extends L {}
+ private class N extends M {}
+ private class O extends N {}
+ private class P extends O {}
+ private class Q extends P {}
+ private class R extends Q {}
+ private class S extends R {}
+ private class T extends S {}
+ private class U extends T {}
+ private class V extends U {}
+ private class W extends V {}
+ private class X extends W {}
+ private class Y extends X {}
+ private class Z extends Y {}
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JCheckBox/8032667/bug8032667.html Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,36 @@
+<!--
+ Copyright (c) 2014, 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>
+
+Verify that scaled components are rendered smoothly to image.
+
+1. Run the test.
+2. Check that Selected and Deselected JCheckBox icons are drawn smoothly.
+If so, press PASS, else press FAIL.
+
+<applet code="bug8032667.class" width=400 height=400></applet>
+
+</body>
+</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JCheckBox/8032667/bug8032667.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2014, 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.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+import javax.swing.JApplet;
+import javax.swing.JCheckBox;
+import javax.swing.JComponent;
+import javax.swing.SwingUtilities;
+
+/* @test
+ * @bug 8032667
+ * @summary [macosx] Components cannot be rendered in HiDPI to BufferedImage
+ * @run applet/manual=yesno bug8032667.html
+ */
+public class bug8032667 extends JApplet {
+
+ static final int scale = 2;
+ static final int width = 130;
+ static final int height = 50;
+ static final int scaledWidth = scale * width;
+ static final int scaledHeight = scale * height;
+
+ @Override
+ public void init() {
+ SwingUtilities.invokeLater(new Runnable() {
+
+ @Override
+ public void run() {
+
+ final Image image1 = getImage(getCheckBox("Deselected", false));
+ final Image image2 = getImage(getCheckBox("Selected", true));
+
+ Canvas canvas = new Canvas() {
+
+ @Override
+ public void paint(Graphics g) {
+ super.paint(g);
+ g.drawImage(image1, 0, 0, scaledWidth, scaledHeight, this);
+ g.drawImage(image2, 0, scaledHeight + 5,
+ scaledWidth, scaledHeight, this);
+ }
+ };
+
+ getContentPane().add(canvas, BorderLayout.CENTER);
+ }
+ });
+ }
+
+ static JCheckBox getCheckBox(String text, boolean selected) {
+ JCheckBox checkBox = new JCheckBox(text);
+ checkBox.setSelected(selected);
+ checkBox.setSize(new Dimension(width, height));
+ return checkBox;
+ }
+
+ static Image getImage(JComponent component) {
+ final BufferedImage image = new BufferedImage(
+ scaledWidth, scaledHeight, BufferedImage.TYPE_INT_ARGB);
+ final Graphics g = image.getGraphics();
+ ((Graphics2D) g).scale(scale, scale);
+ component.paint(g);
+ g.dispose();
+
+ return image;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JCheckBox/8032667/bug8032667_image_diff.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2014, 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.Dimension;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+import javax.swing.JCheckBox;
+import javax.swing.JComponent;
+import javax.swing.SwingUtilities;
+import sun.awt.OSInfo;
+
+/* @test
+ * @bug 8032667
+ * @summary [macosx] Components cannot be rendered in HiDPI to BufferedImage
+ * @run main bug8032667_image_diff
+ */
+public class bug8032667_image_diff {
+
+ static final int IMAGE_WIDTH = 130;
+ static final int IMAGE_HEIGHT = 50;
+
+ public static void main(String[] args) throws Exception {
+
+ if(!OSInfo.OSType.MACOSX.equals(OSInfo.getOSType())){
+ return;
+ }
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+
+ JCheckBox checkBox = new JCheckBox();
+ checkBox.setSelected(true);
+ checkBox.setSize(new Dimension(IMAGE_WIDTH, IMAGE_HEIGHT));
+
+ final BufferedImage image1 = getHiDPIImage(checkBox);
+ final BufferedImage image2 = getScaledImage(checkBox);
+
+ if(equal(image1, image2)){
+ throw new RuntimeException("2x image equals to non smooth image");
+ }
+ }
+ });
+ }
+
+ static boolean equal(BufferedImage image1, BufferedImage image2) {
+
+ int w = image1.getWidth();
+ int h = image1.getHeight();
+
+ if (w != image2.getWidth() || h != image2.getHeight()) {
+ return false;
+ }
+
+ for (int i = 0; i < w; i++) {
+ for (int j = 0; j < h; j++) {
+ int color1 = image1.getRGB(i, j);
+ int color2 = image2.getRGB(i, j);
+
+ if (color1 != color2) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ static BufferedImage getHiDPIImage(JComponent component) {
+ return getImage(component, 2, IMAGE_WIDTH, IMAGE_HEIGHT);
+ }
+
+ static BufferedImage getScaledImage(JComponent component) {
+ Image image1x = getImage(component, 1, IMAGE_WIDTH, IMAGE_HEIGHT);
+ final BufferedImage image2x = new BufferedImage(
+ 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_ARGB);
+ final Graphics g = image2x.getGraphics();
+ ((Graphics2D) g).scale(2, 2);
+ g.drawImage(image1x, 0, 0, null);
+ g.dispose();
+ return image2x;
+ }
+
+ static BufferedImage getImage(JComponent component, int scale, int width, int height) {
+ final BufferedImage image = new BufferedImage(
+ scale * width, scale * height, BufferedImage.TYPE_INT_ARGB);
+ final Graphics g = image.getGraphics();
+ ((Graphics2D) g).scale(scale, scale);
+ component.paint(g);
+ g.dispose();
+ return image;
+ }
+}
--- a/jdk/test/javax/swing/JTable/8031971/bug8031971.java Wed Apr 16 11:56:58 2014 +0100
+++ b/jdk/test/javax/swing/JTable/8031971/bug8031971.java Wed Apr 16 12:42:40 2014 -0700
@@ -29,7 +29,7 @@
/**
* @test
- * @bug 8031971
+ * @bug 8031971 8039750
* @author Alexander Scherbatiy
* @summary Use only public methods in the SwingLazyValue
* @run main bug8031971
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JTable/8032874/bug8032874.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2014, 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 8032874
+ * @summary Test whether ArrayIndexOutOfBoundsException is thrown or not,
+ * once selected row is removed from JTable with Sorter and Filter
+ * @author Dmitry Markov
+ * @run main bug8032874
+ */
+
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.*;
+import javax.swing.table.AbstractTableModel;
+import javax.swing.table.TableRowSorter;
+
+import sun.awt.SunToolkit;
+
+public class bug8032874 {
+ private static final int ROW_COUNT = 5;
+ private static JTable table;
+ private static TestTableModel tableModel;
+
+ public static void main(String args[]) throws Exception {
+ SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ createAndShowUI();
+ }
+ });
+ toolkit.realSync();
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ table.getRowSorter().toggleSortOrder(0);
+ table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
+ table.setRowSelectionInterval(1, 2);
+ }
+ });
+ toolkit.realSync();
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ for (int i = 0; i < ROW_COUNT; i++) {
+ tableModel.remove(0);
+ table.getRowSorter().toggleSortOrder(0);
+ }
+ }
+ });
+ }
+
+ public static void createAndShowUI() {
+ try {
+ UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ JFrame frame = new JFrame("bug8032874");
+ frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+
+ JPanel panel = new JPanel();
+ panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
+
+ tableModel = new TestTableModel();
+ table = new JTable(tableModel);
+ table.setSurrendersFocusOnKeystroke(true);
+
+ final TableRowSorter<TestTableModel> rowSorter = new TableRowSorter<TestTableModel>(tableModel);
+ rowSorter.setRowFilter(new RowFilter<TestTableModel, Integer>() {
+ @Override
+ public boolean include(Entry<? extends TestTableModel, ? extends Integer> entry) {
+ return entry.getIdentifier() % 2 == 0;
+ }
+ });
+ table.setRowSorter(rowSorter);
+
+ JScrollPane jScrollPane = new JScrollPane(table);
+ panel.add(jScrollPane);
+
+ frame.setContentPane(panel);
+ frame.setSize(new Dimension(800, 600));
+ frame.setVisible(true);
+ }
+
+ private static class TestTableModel extends AbstractTableModel {
+ private final List<Integer> data;
+
+ public TestTableModel() {
+ data = new ArrayList<Integer>();
+
+ for (int i = 0; i < ROW_COUNT; i++) {
+ data.add(i);
+ }
+ }
+
+ @Override
+ public int getRowCount() {
+ return data.size();
+ }
+
+ @Override
+ public int getColumnCount() {
+ return 1;
+ }
+
+ @Override
+ public Object getValueAt(int rowIndex, int columnIndex) {
+ return data.get(rowIndex);
+ }
+
+ public void remove(int row) {
+ data.remove(row);
+ fireTableRowsDeleted(row, row);
+ }
+ }
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JTree/8038113/bug8038113.html Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,36 @@
+<!--
+ Copyright (c) 2014, 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>
+
+Verify that scaled icons are rendered smoothly.
+
+1. Run the test.
+2. Check that Collapsed and Expanded JTree icons are drawn smoothly.
+If so, press PASS, else press FAIL.
+
+<applet code="bug8038113.class" width=400 height=400></applet>
+
+</body>
+</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JTree/8038113/bug8038113.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2014, 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.BasicStroke;
+import java.awt.BorderLayout;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import javax.swing.Icon;
+import javax.swing.JApplet;
+import javax.swing.JPanel;
+import javax.swing.JTree;
+import javax.swing.SwingUtilities;
+import javax.swing.plaf.basic.BasicTreeUI;
+
+/* @test
+ * @bug 8038113
+ * @summary [macosx] JTree icon is not rendered in high resolution on Retina
+ * @run applet/manual=yesno bug8038113.html
+ */
+public class bug8038113 extends JApplet {
+
+ @Override
+ public void init() {
+ SwingUtilities.invokeLater(new Runnable() {
+
+ @Override
+ public void run() {
+
+ final JTree tree = new JTree();
+ final BasicTreeUI treeUI = (BasicTreeUI) tree.getUI();
+
+ final JPanel panel = new JPanel() {
+
+ @Override
+ public void paint(Graphics g) {
+ super.paint(g);
+ Graphics2D g2 = (Graphics2D) g;
+ g2.setStroke(new BasicStroke(0.5f));
+ g2.scale(2, 2);
+
+ int x = 10;
+ int y = 10;
+ Icon collapsedIcon = treeUI.getCollapsedIcon();
+ Icon expandeIcon = treeUI.getExpandedIcon();
+ int w = collapsedIcon.getIconWidth();
+ int h = collapsedIcon.getIconHeight();
+ collapsedIcon.paintIcon(this, g, x, y);
+ g.drawRect(x, y, w, h);
+
+ y += 10 + h;
+ w = expandeIcon.getIconWidth();
+ h = expandeIcon.getIconHeight();
+ expandeIcon.paintIcon(this, g, x, y);
+ g.drawRect(x, y, w, h);
+
+ }
+ };
+ getContentPane().setLayout(new BorderLayout());
+ getContentPane().add(panel, BorderLayout.CENTER);
+ }
+ });
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/SwingUtilities/8032219/DrawRect.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2014, 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 sun.swing.SwingUtilities2;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+/**
+ * @test
+ * @bug 8032219
+ * @author Sergey Bylokhov
+ */
+public final class DrawRect {
+
+ private static final int size = 50;
+
+ private static final Rectangle[] rects = {
+ new Rectangle(0, 0, 1, 1),
+ new Rectangle(0, 0, 1, 2),
+ new Rectangle(0, 0, 2, 1),
+ new Rectangle(10, 10, 10, 10),
+ new Rectangle(10, 10, -1, -1),
+ new Rectangle(-1, -1, 10, 10),
+ new Rectangle(-1, -1, -10, -10),
+ new Rectangle(0, 0, size, size),
+ };
+
+ private static final Rectangle[] vlines = {new Rectangle(0, 0, 0, 0),
+ new Rectangle(0, 0, 0, 1),
+ new Rectangle(0, 0, 0, -1),
+ new Rectangle(1, 1, 0, 1),
+ new Rectangle(1, 1, 0, -1),
+ new Rectangle(15, 15, 0, 10),
+ new Rectangle(15, 15, 0, -10),
+ };
+ private static final Rectangle[] hlines = {new Rectangle(0, 0, 0, 0),
+ new Rectangle(0, 0, 1, 0),
+ new Rectangle(0, 0, -1, 0),
+ new Rectangle(1, 1, 1, 0),
+ new Rectangle(1, 1, -1, 0),
+ new Rectangle(15, 15, 10, 0),
+ new Rectangle(15, 15, -10, 0),
+ };
+
+ public static void main(final String[] args) throws IOException {
+ BufferedImage gold = new BufferedImage(size, size,
+ BufferedImage.TYPE_INT_ARGB);
+ Graphics2D g = gold.createGraphics();
+ BufferedImage bi = new BufferedImage(size, size,
+ BufferedImage.TYPE_INT_ARGB);
+ Graphics2D g2d = bi.createGraphics();
+ g2d.setColor(new Color(0, 250, 0, 100));
+ g2d.setBackground(Color.BLACK);
+ g.setColor(new Color(0, 250, 0, 100));
+ g.setBackground(Color.BLACK);
+ // Rectangle
+ for (final Rectangle r : rects) {
+ g.clearRect(0, 0, size, size);
+ g2d.clearRect(0, 0, size, size);
+ g.drawRect(r.x, r.y, r.width, r.height);
+ SwingUtilities2.drawRect(g2d, r.x, r.y, r.width, r.height);
+ test(gold, bi);
+ }
+ // Vertical Line
+ for (final Rectangle l : vlines) {
+ g.clearRect(0, 0, size, size);
+ g2d.clearRect(0, 0, size, size);
+ g.drawLine(l.x, l.y, l.x + l.width, l.y + l.height);
+ SwingUtilities2.drawVLine(g2d, l.x, l.y, l.y + l.height);
+ test(gold, bi);
+ }
+ // Horizontal Line
+ for (final Rectangle l : hlines) {
+ g.clearRect(0, 0, size, size);
+ g2d.clearRect(0, 0, size, size);
+ g.drawLine(l.x, l.y, l.x + l.width, l.y + l.height);
+ SwingUtilities2.drawHLine(g2d, l.x, l.x+l.width, l.y);
+ test(gold, bi);
+ }
+
+ g.dispose();
+ g2d.dispose();
+ }
+
+ private static void test(final BufferedImage gold, final BufferedImage bi)
+ throws IOException {
+ for (int x = 0; x < size; x++) {
+ for (int y = 0; y < size; y++) {
+ if (gold.getRGB(x, y) != bi.getRGB(x, y)) {
+ ImageIO.write(gold, "png", new File("gold.png"));
+ ImageIO.write(bi, "png", new File("image.png"));
+ throw new RuntimeException("wrong color");
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/plaf/metal/MetalLookAndFeel/Test8039750.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2014, 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 javax.swing.UIDefaults;
+import javax.swing.border.CompoundBorder;
+import javax.swing.plaf.metal.MetalLookAndFeel;
+
+/*
+ * @test
+ * @bug 8039750
+ * @summary Tests MetalLazyValue removing
+ * @author Sergey Malenkov
+ */
+public class Test8039750 {
+ public static void main(String[] args) {
+ UIDefaults table= new MetalLookAndFeel().getDefaults();
+ test(table.get("ToolBar.rolloverBorder"),
+ "javax.swing.plaf.metal.MetalBorders$ButtonBorder",
+ "javax.swing.plaf.metal.MetalBorders$RolloverMarginBorder");
+ test(table.get("ToolBar.nonrolloverBorder"),
+ "javax.swing.plaf.metal.MetalBorders$ButtonBorder",
+ "javax.swing.plaf.metal.MetalBorders$RolloverMarginBorder");
+ test(table.get("RootPane.frameBorder"),
+ "javax.swing.plaf.metal.MetalBorders$FrameBorder");
+ test(table.get("RootPane.plainDialogBorder"),
+ "javax.swing.plaf.metal.MetalBorders$DialogBorder");
+ test(table.get("RootPane.informationDialogBorder"),
+ "javax.swing.plaf.metal.MetalBorders$DialogBorder");
+ test(table.get("RootPane.errorDialogBorder"),
+ "javax.swing.plaf.metal.MetalBorders$ErrorDialogBorder");
+ test(table.get("RootPane.colorChooserDialogBorder"),
+ "javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
+ test(table.get("RootPane.fileChooserDialogBorder"),
+ "javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
+ test(table.get("RootPane.questionDialogBorder"),
+ "javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
+ test(table.get("RootPane.warningDialogBorder"),
+ "javax.swing.plaf.metal.MetalBorders$WarningDialogBorder");
+ }
+
+ private static void test(Object value, String name) {
+ if (!value.getClass().getName().equals(name)) {
+ throw new Error(name);
+ }
+ }
+
+ private static void test(Object value, String one, String two) {
+ if (value instanceof CompoundBorder) {
+ CompoundBorder border = (CompoundBorder) value;
+ test(border.getOutsideBorder(), one);
+ test(border.getInsideBorder(), two);
+ } else {
+ throw new Error("CompoundBorder");
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/text/GlyphView/4984669/bug4984669.html Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,30 @@
+<html>
+<!--
+ Copyright (c) 2014, 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.
+-->
+<body>
+<applet code="bug4984669.class" width=300 height=300></applet>
+The four lines printed above in a bold typeface should all be underlined.
+It is a bug if any of these lines is underlined only partially.
+The very first line should not be underlined at all.
+</body>
+</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/text/GlyphView/4984669/bug4984669.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2014, 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 4984669 8002148
+ @summary Tests HTML underlining
+ @author Peter Zhelezniakov
+ @run applet/manual=yesno bug4984669.html
+*/
+import javax.swing.*;
+import javax.swing.text.*;
+
+public class bug4984669 extends JApplet
+{
+ public void init() {
+ JEditorPane pane = new JEditorPane();
+ this.getContentPane().add(new JScrollPane(pane));
+ pane.setEditorKit(new StyledEditorKit());
+
+ try {
+ pane.getDocument().insertString(0,"12 \n",null);
+ MutableAttributeSet attrs = new SimpleAttributeSet();
+
+ StyleConstants.setFontSize(attrs, 36);
+ StyleConstants.setBold(attrs, true);
+ StyleConstants.setUnderline(attrs, true);
+ pane.getDocument().insertString(6, "aa\n", attrs);
+ pane.getDocument().insertString(9, "bbb\n", attrs);
+ pane.getDocument().insertString(13, "cccc\n", attrs);
+ pane.getDocument().insertString(18, "ddddd\n", attrs);
+ } catch (Exception e) {
+ throw new Error("Failed: Unexpected Exception", e);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/lib/testlibrary/ExtendedRobot.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,372 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+
+import sun.awt.ExtendedKeyCodes;
+import sun.awt.SunToolkit;
+import sun.security.action.GetIntegerAction;
+
+import java.awt.AWTException;
+import java.awt.Robot;
+import java.awt.GraphicsDevice;
+import java.awt.Toolkit;
+import java.awt.Point;
+import java.awt.MouseInfo;
+import java.awt.event.InputEvent;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * ExtendedRobot is a subclass of {@link java.awt.Robot}. It provides some convenience methods that are
+ * ought to be moved to {@link java.awt.Robot} class.
+ * <p>
+ * ExtendedRobot uses delay {@link #getSyncDelay()} to make syncing threads with {@link #waitForIdle()}
+ * more stable. This delay can be set once on creating object and could not be changed throughout object
+ * lifecycle. Constructor reads vm integer property {@code java.awt.robotdelay} and sets the delay value
+ * equal to the property value. If the property was not set 500 milliseconds default value is used.
+ * <p>
+ * When using jtreg you would include this class via something like:
+ * <pre>
+ * {@literal @}library ../../../../lib/testlibrary
+ * {@literal @}build ExtendedRobot
+ * </pre>
+ *
+ * @author Dmitriy Ermashov
+ * @since 1.9
+ */
+
+public class ExtendedRobot extends Robot {
+
+ private static int DEFAULT_SPEED = 20; // Speed for mouse glide and click
+ private static int DEFAULT_SYNC_DELAY = 500; // Default Additional delay for waitForIdle()
+ private static int DEFAULT_STEP_LENGTH = 2; // Step length (in pixels) for mouse glide
+
+ private final int syncDelay = DEFAULT_SYNC_DELAY;
+
+ //TODO: uncomment three lines below after moving functionality to java.awt.Robot
+ //{
+ // syncDelay = AccessController.doPrivileged(new GetIntegerAction("java.awt.robotdelay", DEFAULT_SYNC_DELAY));
+ //}
+
+ /**
+ * Constructs an ExtendedRobot object in the coordinate system of the primary screen.
+ *
+ * @throws AWTException if the platform configuration does not allow low-level input
+ * control. This exception is always thrown when
+ * GraphicsEnvironment.isHeadless() returns true
+ * @throws SecurityException if {@code createRobot} permission is not granted
+ *
+ * @see java.awt.GraphicsEnvironment#isHeadless
+ * @see SecurityManager#checkPermission
+ * @see java.awt.AWTPermission
+ */
+ public ExtendedRobot() throws AWTException {
+ super();
+ }
+
+ /**
+ * Creates an ExtendedRobot for the given screen device. Coordinates passed
+ * to ExtendedRobot method calls like mouseMove and createScreenCapture will
+ * be interpreted as being in the same coordinate system as the specified screen.
+ * Note that depending on the platform configuration, multiple screens may either:
+ * <ul>
+ * <li>share the same coordinate system to form a combined virtual screen</li>
+ * <li>use different coordinate systems to act as independent screens</li>
+ * </ul>
+ * This constructor is meant for the latter case.
+ * <p>
+ * If screen devices are reconfigured such that the coordinate system is
+ * affected, the behavior of existing ExtendedRobot objects is undefined.
+ *
+ * @param screen A screen GraphicsDevice indicating the coordinate
+ * system the Robot will operate in.
+ * @throws AWTException if the platform configuration does not allow low-level input
+ * control. This exception is always thrown when
+ * GraphicsEnvironment.isHeadless() returns true.
+ * @throws IllegalArgumentException if {@code screen} is not a screen
+ * GraphicsDevice.
+ * @throws SecurityException if {@code createRobot} permission is not granted
+ *
+ * @see java.awt.GraphicsEnvironment#isHeadless
+ * @see GraphicsDevice
+ * @see SecurityManager#checkPermission
+ * @see java.awt.AWTPermission
+ */
+ public ExtendedRobot(GraphicsDevice screen) throws AWTException {
+ super(screen);
+ }
+
+ /**
+ * Returns delay length for {@link #waitForIdle()} method
+ *
+ * @return Current delay value
+ *
+ * @see #waitForIdle()
+ */
+ public int getSyncDelay(){ return this.syncDelay; }
+
+ /**
+ * Clicks mouse button(s) by calling {@link java.awt.Robot#mousePress(int)} and
+ * {@link java.awt.Robot#mouseRelease(int)} methods
+ *
+ *
+ * @param buttons The button mask; a combination of one or more mouse button masks.
+ * @throws IllegalArgumentException if the {@code buttons} mask contains the mask for
+ * extra mouse button and support for extended mouse buttons is
+ * {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java
+ * @throws IllegalArgumentException if the {@code buttons} mask contains the mask for
+ * extra mouse button that does not exist on the mouse and support for extended
+ * mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled}
+ * by Java
+ *
+ * @see #mousePress(int)
+ * @see #mouseRelease(int)
+ * @see InputEvent#getMaskForButton(int)
+ * @see Toolkit#areExtraMouseButtonsEnabled()
+ * @see java.awt.event.MouseEvent
+ */
+ public void click(int buttons) {
+ mousePress(buttons);
+ waitForIdle(DEFAULT_SPEED);
+ mouseRelease(buttons);
+ waitForIdle();
+ }
+
+ /**
+ * Clicks mouse button 1
+ *
+ * @throws IllegalArgumentException if the {@code buttons} mask contains the mask for
+ * extra mouse button and support for extended mouse buttons is
+ * {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java
+ * @throws IllegalArgumentException if the {@code buttons} mask contains the mask for
+ * extra mouse button that does not exist on the mouse and support for extended
+ * mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled}
+ * by Java
+ *
+ * @see #click(int)
+ */
+ public void click() {
+ click(InputEvent.BUTTON1_DOWN_MASK);
+ }
+
+ /**
+ * Waits until all events currently on the event queue have been processed with given
+ * delay after syncing threads. It uses more advanced method of synchronizing threads
+ * unlike {@link java.awt.Robot#waitForIdle()}
+ *
+ * @param delayValue Additional delay length in milliseconds to wait until thread
+ * sync been completed
+ * @throws sun.awt.SunToolkit.IllegalThreadException if called on the AWT event
+ * dispatching thread
+ */
+ public synchronized void waitForIdle(int delayValue) {
+ SunToolkit.flushPendingEvents();
+ ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
+ delay(delayValue);
+ }
+
+ /**
+ * Waits until all events currently on the event queue have been processed with delay
+ * {@link #getSyncDelay()} after syncing threads. It uses more advanced method of
+ * synchronizing threads unlike {@link java.awt.Robot#waitForIdle()}
+ *
+ * @throws sun.awt.SunToolkit.IllegalThreadException if called on the AWT event
+ * dispatching thread
+ *
+ * @see #waitForIdle(int)
+ */
+ @Override
+ public synchronized void waitForIdle() {
+ waitForIdle(syncDelay);
+ }
+
+ /**
+ * Move the mouse in multiple steps from where it is
+ * now to the destination coordinates.
+ *
+ * @param x Destination point x coordinate
+ * @param y Destination point y coordinate
+ *
+ * @see #glide(int, int, int, int)
+ */
+ public void glide(int x, int y) {
+ Point p = MouseInfo.getPointerInfo().getLocation();
+ glide(p.x, p.y, x, y);
+ }
+
+ /**
+ * Move the mouse in multiple steps from where it is
+ * now to the destination point.
+ *
+ * @param dest Destination point
+ *
+ * @see #glide(int, int)
+ */
+ public void glide(Point dest) {
+ glide(dest.x, dest.y);
+ }
+
+ /**
+ * Move the mouse in multiple steps from source coordinates
+ * to the destination coordinates.
+ *
+ * @param fromX Source point x coordinate
+ * @param fromY Source point y coordinate
+ * @param toX Destination point x coordinate
+ * @param toY Destination point y coordinate
+ *
+ * @see #glide(int, int, int, int, int, int)
+ */
+ public void glide(int fromX, int fromY, int toX, int toY) {
+ glide(fromX, fromY, toX, toY, DEFAULT_STEP_LENGTH, DEFAULT_SPEED);
+ }
+
+ /**
+ * Move the mouse in multiple steps from source point to the
+ * destination point with default speed and step length.
+ *
+ * @param src Source point
+ * @param dest Destination point
+ *
+ * @see #glide(int, int, int, int, int, int)
+ */
+ public void glide(Point src, Point dest) {
+ glide(src.x, src.y, dest.x, dest.y, DEFAULT_STEP_LENGTH, DEFAULT_SPEED);
+ }
+
+ /**
+ * Move the mouse in multiple steps from source point to the
+ * destination point with given speed and step length.
+ *
+ * @param srcX Source point x cordinate
+ * @param srcY Source point y cordinate
+ * @param destX Destination point x cordinate
+ * @param destY Destination point y cordinate
+ * @param stepLength Approximate length of one step
+ * @param speed Delay between steps.
+ *
+ * @see #mouseMove(int, int)
+ * @see #delay(int)
+ */
+ public void glide(int srcX, int srcY, int destX, int destY, int stepLength, int speed) {
+ int stepNum;
+ double tDx, tDy;
+ double dx, dy, ds;
+ double x, y;
+
+ dx = (destX - srcX);
+ dy = (destY - srcY);
+ ds = Math.sqrt(dx*dx + dy*dy);
+
+ tDx = dx / ds * stepLength;
+ tDy = dy / ds * stepLength;
+
+ int stepsCount = (int) ds / stepLength;
+
+ // Walk the mouse to the destination one step at a time
+ mouseMove(srcX, srcY);
+
+ for (x = srcX, y = srcY, stepNum = 0;
+ stepNum < stepsCount;
+ stepNum++) {
+ x += tDx;
+ y += tDy;
+ mouseMove((int)x, (int)y);
+ delay(speed);
+ }
+
+ // Ensure the mouse moves to the right destination.
+ // The steps may have led the mouse to a slightly wrong place.
+ mouseMove(destX, destY);
+ }
+
+ /**
+ * Moves mouse pointer to given screen coordinates.
+ *
+ * @param position Target position
+ *
+ * @see java.awt.Robot#mouseMove(int, int)
+ */
+ public synchronized void mouseMove(Point position) {
+ mouseMove(position.x, position.y);
+ }
+
+ /**
+ * Successively presses and releases a given key.
+ * <p>
+ * Key codes that have more than one physical key associated with them
+ * (e.g. {@code KeyEvent.VK_SHIFT} could mean either the
+ * left or right shift key) will map to the left key.
+ *
+ * @param keycode Key to press (e.g. {@code KeyEvent.VK_A})
+ * @throws IllegalArgumentException if {@code keycode} is not
+ * a valid key
+ *
+ * @see java.awt.Robot#keyPress(int)
+ * @see java.awt.Robot#keyRelease(int)
+ * @see java.awt.event.KeyEvent
+ */
+ public void type(int keycode) {
+ keyPress(keycode);
+ waitForIdle(DEFAULT_SPEED);
+ keyRelease(keycode);
+ waitForIdle(DEFAULT_SPEED);
+ }
+
+ /**
+ * Types given character
+ *
+ * @param c Character to be typed (e.g. {@code 'a'})
+ *
+ * @see #type(int)
+ * @see java.awt.event.KeyEvent
+ */
+ public void type(char c) {
+ type(ExtendedKeyCodes.getExtendedKeyCodeForChar(c));
+ }
+
+ /**
+ * Types given array of characters one by one
+ *
+ * @param symbols Array of characters to be typed
+ *
+ * @see #type(char)
+ */
+ public void type(char[] symbols) {
+ for (int i = 0; i < symbols.length; i++) {
+ type(symbols[i]);
+ }
+ }
+
+ /**
+ * Types given string
+ *
+ * @param s String to be typed
+ *
+ * @see #type(char[])
+ */
+ public void type(String s) {
+ type(s.toCharArray());
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/java2d/DrawCachedImageAndTransform.java Wed Apr 16 12:42:40 2014 -0700
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2014, 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.Color;
+import java.awt.Graphics2D;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsEnvironment;
+import java.awt.image.BufferedImage;
+import java.awt.image.VolatileImage;
+
+/**
+ * @test
+ * @bug 8039774
+ * @summary Verifies that we get no exception, when we draw with scale
+ * BufferedImage to VolatileImage via intermediate texture.
+ * @author Sergey Bylokhov
+ * @run main/othervm -Dsun.java2d.accthreshold=0 DrawCachedImageAndTransform
+ */
+public final class DrawCachedImageAndTransform {
+
+ public static void main(String[] args) {
+ GraphicsEnvironment ge = GraphicsEnvironment
+ .getLocalGraphicsEnvironment();
+ GraphicsConfiguration gc = ge.getDefaultScreenDevice()
+ .getDefaultConfiguration();
+ VolatileImage vi = gc.createCompatibleVolatileImage(100, 100);
+
+ Graphics2D g2d = vi.createGraphics();
+ g2d.scale(2, 2);
+ BufferedImage img = new BufferedImage(50, 50,
+ BufferedImage.TYPE_INT_ARGB);
+
+ g2d.drawImage(img, 10, 25, Color.blue, null);
+ g2d.dispose();
+ }
+}