From 63314e533348de80c79ffddab70e6163bb9d79f1 Mon Sep 17 00:00:00 2001 From: serb Date: Wed, 2 Apr 2014 15:23:08 +0400 Subject: 8029196: Focus border of JButton.buttonType=roundRect is cut off Reviewed-by: pchelko, alexsch --- src/macosx/classes/apple/laf/JRSUIConstants.java | 9 +++- .../com/apple/laf/AquaButtonExtendedTypes.java | 7 ++- src/macosx/classes/com/apple/laf/AquaPainter.java | 56 +++++++++++++++------- src/macosx/native/com/apple/laf/JRSUIController.m | 4 +- 4 files changed, 54 insertions(+), 22 deletions(-) diff --git a/src/macosx/classes/apple/laf/JRSUIConstants.java b/src/macosx/classes/apple/laf/JRSUIConstants.java index 40b2fc2db..272b1f1f2 100644 --- a/src/macosx/classes/apple/laf/JRSUIConstants.java +++ b/src/macosx/classes/apple/laf/JRSUIConstants.java @@ -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.nio.ByteBuffer; 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 { diff --git a/src/macosx/classes/com/apple/laf/AquaButtonExtendedTypes.java b/src/macosx/classes/com/apple/laf/AquaButtonExtendedTypes.java index 2735eb484..f35203689 100644 --- a/src/macosx/classes/com/apple/laf/AquaButtonExtendedTypes.java +++ b/src/macosx/classes/com/apple/laf/AquaButtonExtendedTypes.java @@ -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 apple.laf.JRSUIConstants.*; 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 * "default font" and sizes for controls in Java Aqua Look and Feel @@ -145,7 +147,8 @@ public class AquaButtonExtendedTypes { protected static Map getAllTypes() { final Map specifiersByName = new HashMap(); - 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) { diff --git a/src/macosx/classes/com/apple/laf/AquaPainter.java b/src/macosx/classes/com/apple/laf/AquaPainter.java index a5bc8fb25..ee4fcba1a 100644 --- a/src/macosx/classes/com/apple/laf/AquaPainter.java +++ b/src/macosx/classes/com/apple/laf/AquaPainter.java @@ -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,39 +141,59 @@ abstract class AquaPainter { 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 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 width = bounds.width; - final int height = bounds.height; - AquaPixelsKey key = new AquaPixelsKey(config, - width, height, bounds, controlState); - Image img = (BufferedImage) cache.getImage(key); + final AquaPixelsKey key = new AquaPixelsKey(config, imgW, imgH, + bounds, controlState); + Image img = cache.getImage(key); if (img == null) { - Image baseImage = createImage(width, height, bounds, control, - controlState); + Image baseImage = createImage(imgX, imgY, imgW, imgH, bounds, + control, controlState); img = new MultiResolutionBufferedImage(baseImage, - (rvWidth, rvHeight) -> createImage(rvWidth, rvHeight, - bounds, control, controlState)); + (rvWidth, rvHeight) -> createImage(imgX, imgY, + rvWidth, rvHeight, bounds, control, controlState)); if (!controlState.is(JRSUIConstants.Animating.YES)) { cache.setImage(key, img); } } - 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 imgW, int imgH, final Rectangle bounds, - final JRSUIControl control, JRSUIState controlState) { + 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); @@ -181,8 +201,9 @@ abstract class AquaPainter { final DataBufferInt buffer = (DataBufferInt) raster.getDataBuffer(); control.set(controlState); - control.paint(SunWritableRaster.stealData(buffer, 0), - imgW, imgH, 0, 0, bounds.width, bounds.height); + control.paint(SunWritableRaster.stealData(buffer, 0), imgW, imgH, + bounds.x - imgX, bounds.y - imgY, bounds.width, + bounds.height); SunWritableRaster.markDirty(buffer); return img; } @@ -212,6 +233,7 @@ abstract class AquaPainter { this.hash = hash(); } + @Override public int getPixelCount() { return pixelCount; } diff --git a/src/macosx/native/com/apple/laf/JRSUIController.m b/src/macosx/native/com/apple/laf/JRSUIController.m index ab6c50ac4..0f92f43fe 100644 --- a/src/macosx/native/com/apple/laf/JRSUIController.m +++ b/src/macosx/native/com/apple/laf/JRSUIController.m @@ -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 @@ static inline jint doPaintImage 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); -- cgit v1.2.3