From d843dec3b7d68c94b4d46ce4eb9909889cac6060 Mon Sep 17 00:00:00 2001 From: Leonid Romanov Date: Thu, 31 Jan 2013 18:25:59 +0400 Subject: [PATCH 1/4] 8007006: [macosx] Closing subwindow loses main window menus Reviewed-by: anthony --- jdk/src/macosx/native/sun/awt/AWTWindow.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jdk/src/macosx/native/sun/awt/AWTWindow.m b/jdk/src/macosx/native/sun/awt/AWTWindow.m index 3af7c6c736f..bac24ff8d52 100644 --- a/jdk/src/macosx/native/sun/awt/AWTWindow.m +++ b/jdk/src/macosx/native/sun/awt/AWTWindow.m @@ -813,9 +813,9 @@ JNF_COCOA_ENTER(env); if ([nsWindow isKeyWindow]) [window.javaMenuBar deactivate]; window.javaMenuBar = menuBar; - // if ([self isKeyWindow]) { - [CMenuBar activate:window.javaMenuBar modallyDisabled:NO]; - // } + if ([nsWindow isKeyWindow]) { + [CMenuBar activate:window.javaMenuBar modallyDisabled:NO]; + } }]; JNF_COCOA_EXIT(env); From 018fbffe544031d8eac44ac6088f11cf7bbb4dad Mon Sep 17 00:00:00 2001 From: Pete Brunet Date: Thu, 31 Jan 2013 18:51:17 +0400 Subject: [PATCH 2/4] 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring Reviewed-by: art, anthony, alexsch --- jdk/src/share/classes/java/awt/Component.java | 24 +++++++---- jdk/src/share/classes/java/awt/Container.java | 24 ++++++++++- .../share/classes/javax/swing/JComponent.java | 43 ++++++++----------- 3 files changed, 57 insertions(+), 34 deletions(-) diff --git a/jdk/src/share/classes/java/awt/Component.java b/jdk/src/share/classes/java/awt/Component.java index 42e422d3e93..3bfb115c15e 100644 --- a/jdk/src/share/classes/java/awt/Component.java +++ b/jdk/src/share/classes/java/awt/Component.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -8994,7 +8994,10 @@ public abstract class Component implements ImageObserver, MenuContainer, * to the individual objects which extend Component. */ - AccessibleContext accessibleContext = null; + /** + * The {@code AccessibleContext} associated with this {@code Component}. + */ + protected AccessibleContext accessibleContext = null; /** * Gets the AccessibleContext associated @@ -9034,6 +9037,13 @@ public abstract class Component implements ImageObserver, MenuContainer, protected AccessibleAWTComponent() { } + /** + * Number of PropertyChangeListener objects registered. It's used + * to add/remove ComponentListener and FocusListener to track + * target Component's state. + */ + private volatile transient int propertyListenersCount = 0; + protected ComponentListener accessibleAWTComponentHandler = null; protected FocusListener accessibleAWTFocusHandler = null; @@ -9098,10 +9108,12 @@ public abstract class Component implements ImageObserver, MenuContainer, public void addPropertyChangeListener(PropertyChangeListener listener) { if (accessibleAWTComponentHandler == null) { accessibleAWTComponentHandler = new AccessibleAWTComponentHandler(); - Component.this.addComponentListener(accessibleAWTComponentHandler); } if (accessibleAWTFocusHandler == null) { accessibleAWTFocusHandler = new AccessibleAWTFocusHandler(); + } + if (propertyListenersCount++ == 0) { + Component.this.addComponentListener(accessibleAWTComponentHandler); Component.this.addFocusListener(accessibleAWTFocusHandler); } super.addPropertyChangeListener(listener); @@ -9115,13 +9127,9 @@ public abstract class Component implements ImageObserver, MenuContainer, * @param listener The PropertyChangeListener to be removed */ public void removePropertyChangeListener(PropertyChangeListener listener) { - if (accessibleAWTComponentHandler != null) { + if (--propertyListenersCount == 0) { Component.this.removeComponentListener(accessibleAWTComponentHandler); - accessibleAWTComponentHandler = null; - } - if (accessibleAWTFocusHandler != null) { Component.this.removeFocusListener(accessibleAWTFocusHandler); - accessibleAWTFocusHandler = null; } super.removePropertyChangeListener(listener); } diff --git a/jdk/src/share/classes/java/awt/Container.java b/jdk/src/share/classes/java/awt/Container.java index 78af6b10c62..1118852f0e9 100644 --- a/jdk/src/share/classes/java/awt/Container.java +++ b/jdk/src/share/classes/java/awt/Container.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -3824,6 +3824,12 @@ public class Container extends Component { return Container.this.getAccessibleAt(p); } + /** + * Number of PropertyChangeListener objects registered. It's used + * to add/remove ContainerListener to track target Container's state. + */ + private volatile transient int propertyListenersCount = 0; + protected ContainerListener accessibleContainerHandler = null; /** @@ -3859,11 +3865,27 @@ public class Container extends Component { public void addPropertyChangeListener(PropertyChangeListener listener) { if (accessibleContainerHandler == null) { accessibleContainerHandler = new AccessibleContainerHandler(); + } + if (propertyListenersCount++ == 0) { Container.this.addContainerListener(accessibleContainerHandler); } super.addPropertyChangeListener(listener); } + /** + * Remove a PropertyChangeListener from the listener list. + * This removes a PropertyChangeListener that was registered + * for all properties. + * + * @param listener the PropertyChangeListener to be removed + */ + public void removePropertyChangeListener(PropertyChangeListener listener) { + if (--propertyListenersCount == 0) { + Container.this.removeContainerListener(accessibleContainerHandler); + } + super.removePropertyChangeListener(listener); + } + } // inner class AccessibleAWTContainer /** diff --git a/jdk/src/share/classes/javax/swing/JComponent.java b/jdk/src/share/classes/javax/swing/JComponent.java index dbf4b3c3343..dac623a37bd 100644 --- a/jdk/src/share/classes/javax/swing/JComponent.java +++ b/jdk/src/share/classes/javax/swing/JComponent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -3643,26 +3643,6 @@ public abstract class JComponent extends Container implements Serializable, } } - /** - * The AccessibleContext associated with this - * JComponent. - */ - protected AccessibleContext accessibleContext = null; - - /** - * Returns the AccessibleContext associated with this - * JComponent. The method implemented by this base - * class returns null. Classes that extend JComponent - * should implement this method to return the - * AccessibleContext associated with the subclass. - * - * @return the AccessibleContext of this - * JComponent - */ - public AccessibleContext getAccessibleContext() { - return accessibleContext; - } - /** * Inner class of JComponent used to provide default support for * accessibility. This class is not meant to be used directly by @@ -3689,7 +3669,18 @@ public abstract class JComponent extends Container implements Serializable, super(); } - protected ContainerListener accessibleContainerHandler = null; + /** + * Number of PropertyChangeListener objects registered. It's used + * to add/remove ContainerListener and FocusListener to track + * target JComponent's state + */ + private volatile transient int propertyListenersCount = 0; + + /** + * This field duplicates the one in java.awt.Component.AccessibleAWTComponent, + * so it has been deprecated. + */ + @Deprecated protected FocusListener accessibleFocusHandler = null; /** @@ -3747,10 +3738,12 @@ public abstract class JComponent extends Container implements Serializable, public void addPropertyChangeListener(PropertyChangeListener listener) { if (accessibleFocusHandler == null) { accessibleFocusHandler = new AccessibleFocusHandler(); - JComponent.this.addFocusListener(accessibleFocusHandler); } if (accessibleContainerHandler == null) { accessibleContainerHandler = new AccessibleContainerHandler(); + } + if (propertyListenersCount++ == 0) { + JComponent.this.addFocusListener(accessibleFocusHandler); JComponent.this.addContainerListener(accessibleContainerHandler); } super.addPropertyChangeListener(listener); @@ -3764,9 +3757,9 @@ public abstract class JComponent extends Container implements Serializable, * @param listener the PropertyChangeListener to be removed */ public void removePropertyChangeListener(PropertyChangeListener listener) { - if (accessibleFocusHandler != null) { + if (--propertyListenersCount == 0) { JComponent.this.removeFocusListener(accessibleFocusHandler); - accessibleFocusHandler = null; + JComponent.this.removeContainerListener(accessibleContainerHandler); } super.removePropertyChangeListener(listener); } From ab3443893820bc0c964d4e8aa5c632fc8cae5e20 Mon Sep 17 00:00:00 2001 From: Petr Pchelko Date: Mon, 4 Feb 2013 13:54:53 +0000 Subject: [PATCH 3/4] 8005405: [macosx] Drag and Drop: wrong animation when dropped outside any drop target Changed the calculation of the drag image offset Reviewed-by: serb, kizune --- .../lwawt/macosx/CDragSourceContextPeer.java | 45 +++++++------------ jdk/src/macosx/native/sun/awt/CDragSource.m | 14 +++--- 2 files changed, 20 insertions(+), 39 deletions(-) diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CDragSourceContextPeer.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CDragSourceContextPeer.java index cec7c552b94..b4f9fd7abb5 100644 --- a/jdk/src/macosx/classes/sun/lwawt/macosx/CDragSourceContextPeer.java +++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CDragSourceContextPeer.java @@ -88,40 +88,25 @@ public final class CDragSourceContextPeer extends SunDragSourceContextPeer { DragGestureEvent trigger = getTrigger(); InputEvent triggerEvent = trigger.getTriggerEvent(); - Point dragOrigin = trigger.getDragOrigin(); + Point dragOrigin = new Point(trigger.getDragOrigin()); int extModifiers = (triggerEvent.getModifiers() | triggerEvent.getModifiersEx()); long timestamp = triggerEvent.getWhen(); int clickCount = ((triggerEvent instanceof MouseEvent) ? (((MouseEvent) triggerEvent).getClickCount()) : 1); - // Get drag source component and its peer: Component component = trigger.getComponent(); - Point componentOffset = new Point(); - ComponentPeer peer = component.getPeer(); - - // For a lightweight component traverse up the hierarchy to the first heavyweight - // which will be used as the ComponentModel for the native drag source. - if (component.isLightweight()) { - Point loc = component.getLocation(); - componentOffset.translate(loc.x, loc.y); - - for (Component parent = component.getParent(); parent != null; parent = parent.getParent()) { - if (parent.isLightweight() == false) { - peer = parent.getPeer(); - break; - } - - loc = parent.getLocation(); - componentOffset.translate(loc.x, loc.y); - } + // For a lightweight component traverse up the hierarchy to the root + Point loc = component.getLocation(); + Component rootComponent = component; + while (!(rootComponent instanceof Window)) { + dragOrigin.translate(loc.x, loc.y); + rootComponent = rootComponent.getParent(); + loc = rootComponent.getLocation(); } - // Make sure the drop target is a ComponentModel: - if (!(peer instanceof LWComponentPeer)) - throw new IllegalArgumentException("DragSource's peer must be a ComponentModel."); - - // Get model pointer (CButton.m and such) and its native peer: - LWComponentPeer model = (LWComponentPeer) peer; - CPlatformWindow platformWindow = (CPlatformWindow) model.getPlatformWindow(); + //It sure will be LWComponentPeer instance as rootComponent is a Window + LWComponentPeer peer = (LWComponentPeer)rootComponent.getPeer(); + //Get a pointer to a native window + CPlatformWindow platformWindow = (CPlatformWindow) peer.getPlatformWindow(); long nativeWindowPtr = platformWindow.getNSWindowPtr(); // Get drag cursor: @@ -155,7 +140,7 @@ public final class CDragSourceContextPeer extends SunDragSourceContextPeer { try { // Create native dragging source: final long nativeDragSource = createNativeDragSource(component, peer, nativeWindowPtr, transferable, triggerEvent, - (int) (dragOrigin.getX() + componentOffset.x), (int) (dragOrigin.getY() + componentOffset.y), extModifiers, + (int) (dragOrigin.getX()), (int) (dragOrigin.getY()), extModifiers, clickCount, timestamp, cursor, fDragCImage, dragImageOffset.x, dragImageOffset.y, getDragSourceContext().getSourceActions(), formats, formatMap); @@ -165,8 +150,8 @@ public final class CDragSourceContextPeer extends SunDragSourceContextPeer { setNativeContext(nativeDragSource); CCursorManager.getInstance().startDrag( - (int) (dragOrigin.getX() + componentOffset.x), - (int) (dragOrigin.getY() + componentOffset.y)); + (int) (dragOrigin.getX()), + (int) (dragOrigin.getY())); } catch (Exception e) { diff --git a/jdk/src/macosx/native/sun/awt/CDragSource.m b/jdk/src/macosx/native/sun/awt/CDragSource.m index ef7b09a6edc..635026483d3 100644 --- a/jdk/src/macosx/native/sun/awt/CDragSource.m +++ b/jdk/src/macosx/native/sun/awt/CDragSource.m @@ -443,9 +443,9 @@ static BOOL sNeedsEnter; NSGraphicsContext* graphicsContext = [NSGraphicsContext graphicsContextWithWindow:window]; // Convert mouse coordinates to NS: - NSPoint location = NSMakePoint(fDragPos.x, fDragPos.y); - NSPoint eventLocation = [fView convertPoint:location toView:nil]; - + NSPoint eventLocation = [fView convertPoint:NSMakePoint(fDragPos.x, fDragPos.y) toView:nil]; + eventLocation.y = [[fView window] frame].size.height - eventLocation.y; + // Convert fTriggerEventTimeStamp to NS - AWTEvent.h defines UTC(nsEvent) as ((jlong)[event timestamp] * 1000): NSTimeInterval timeStamp = fTriggerEventTimeStamp / 1000; @@ -497,12 +497,9 @@ static BOOL sNeedsEnter; NSImage* dragImage = fDragImage; // Get drag origin and offset: - NSPoint dragOrigin; - dragOrigin.x = fDragPos.x; - dragOrigin.y = fDragPos.y; - dragOrigin = [view convertPoint:[dragEvent locationInWindow] fromView:nil]; + NSPoint dragOrigin = [dragEvent locationInWindow]; dragOrigin.x += fDragImageOffset.x; - dragOrigin.y += [dragImage size].height + fDragImageOffset.y; + dragOrigin.y -= fDragImageOffset.y + [dragImage size].height; // Drag offset values don't seem to matter: NSSize dragOffset = NSMakeSize(0, 0); @@ -516,7 +513,6 @@ static BOOL sNeedsEnter; DLog5(@" - drag image: %f, %f (%f x %f)", fDragImageOffset.x, fDragImageOffset.y, [dragImage size].width, [dragImage size].height); DLog3(@" - event point (window) %f, %f", [dragEvent locationInWindow].x, [dragEvent locationInWindow].y); DLog3(@" - drag point (view) %f, %f", dragOrigin.x, dragOrigin.y); - // Set up the fDragKeyModifier, so we know if the operation has changed // Set up the fDragMouseModifier, so we can |= it later (since CoreDrag doesn't tell us mouse states during a drag) fDragKeyModifiers = [DnDUtilities extractJavaExtKeyModifiersFromJavaExtModifiers:fModifiers]; From 5712b216b4ad44dd7b981c3104c14917d70b262f Mon Sep 17 00:00:00 2001 From: Konstantin Shefov Date: Mon, 4 Feb 2013 16:01:06 +0000 Subject: [PATCH 4/4] 7077259: [TEST_BUG] [macosx] Test work correctly only when default L&F is Metal Reviewed-by: serb, alexsch --- jdk/test/javax/swing/JSlider/4252173/bug4252173.java | 12 ++++++------ .../javax/swing/JSpinner/6532833/bug6532833.java | 11 ++++++----- .../swing/plaf/metal/MetalSliderUI/Test6657026.java | 9 ++++----- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/jdk/test/javax/swing/JSlider/4252173/bug4252173.java b/jdk/test/javax/swing/JSlider/4252173/bug4252173.java index 128a32a1e79..1db70adb993 100644 --- a/jdk/test/javax/swing/JSlider/4252173/bug4252173.java +++ b/jdk/test/javax/swing/JSlider/4252173/bug4252173.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 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 @@ -22,11 +22,11 @@ */ /* @test - @bug 4252173 - @summary Inability to reuse the HorizontalSliderThumbIcon - @author Pavel Porvatov - @run main bug4252173 -*/ + * @bug 4252173 7077259 + * @summary Inability to reuse the HorizontalSliderThumbIcon + * @author Pavel Porvatov + * @run main/othervm -Dswing.defaultlaf=javax.swing.plaf.metal.MetalLookAndFeel bug4252173 + */ import javax.swing.*; import javax.swing.plaf.metal.DefaultMetalTheme; diff --git a/jdk/test/javax/swing/JSpinner/6532833/bug6532833.java b/jdk/test/javax/swing/JSpinner/6532833/bug6532833.java index 184fe69d96d..80013da7a81 100644 --- a/jdk/test/javax/swing/JSpinner/6532833/bug6532833.java +++ b/jdk/test/javax/swing/JSpinner/6532833/bug6532833.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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 @@ -22,10 +22,11 @@ */ /* @test - @bug 6532833 - @summary PIT: Metal LAF - The right side border is not shown for the Spinner after the removing the buttons - @author Pavel Porvatov -*/ + * @bug 6532833 7077259 + * @summary PIT: Metal LAF - The right side border is not shown for the Spinner after the removing the buttons + * @author Pavel Porvatov + * @run main/othervm -Dswing.defaultlaf=javax.swing.plaf.metal.MetalLookAndFeel bug6532833 + */ import javax.swing.*; import java.awt.*; diff --git a/jdk/test/javax/swing/plaf/metal/MetalSliderUI/Test6657026.java b/jdk/test/javax/swing/plaf/metal/MetalSliderUI/Test6657026.java index 5c65b15ce45..924999e46f8 100644 --- a/jdk/test/javax/swing/plaf/metal/MetalSliderUI/Test6657026.java +++ b/jdk/test/javax/swing/plaf/metal/MetalSliderUI/Test6657026.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 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 @@ -23,22 +23,21 @@ /* * @test - * @bug 6657026 + * @bug 6657026 7077259 * @summary Tests shared MetalSliderUI in different application contexts * @author Sergey Malenkov + * @run main/othervm -Dswing.defaultlaf=javax.swing.plaf.metal.MetalLookAndFeel Test6657026 */ -import sun.awt.SunToolkit; - import javax.swing.JSlider; import javax.swing.UIManager; import javax.swing.plaf.metal.MetalLookAndFeel; import javax.swing.plaf.metal.MetalSliderUI; +import sun.awt.SunToolkit; public class Test6657026 extends MetalSliderUI implements Runnable { public static void main(String[] args) throws Exception { - UIManager.setLookAndFeel(new MetalLookAndFeel()); JSlider slider = new JSlider(); test(slider);