8057574: inconsistent behavior for setBackground (Windows/Linux)
Reviewed-by: serb, arapte
This commit is contained in:
parent
a73a3830ee
commit
282908c590
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2016, 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
|
||||
@ -174,27 +174,24 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
|
||||
|
||||
cachedFocusableWindow = isFocusableWindow();
|
||||
|
||||
Font f = target.getFont();
|
||||
if (f == null) {
|
||||
f = XWindow.getDefaultFont();
|
||||
target.setFont(f);
|
||||
// we should not call setFont because it will call a repaint
|
||||
// which the peer may not be ready to do yet.
|
||||
if (!target.isFontSet()) {
|
||||
target.setFont(XWindow.getDefaultFont());
|
||||
// we should not call setFont because it will call a repaint
|
||||
// which the peer may not be ready to do yet.
|
||||
}
|
||||
Color c = target.getBackground();
|
||||
if (c == null) {
|
||||
Color background = SystemColor.window;
|
||||
target.setBackground(background);
|
||||
// we should not call setBackGround because it will call a repaint
|
||||
// which the peer may not be ready to do yet.
|
||||
if (!target.isBackgroundSet()) {
|
||||
target.setBackground(SystemColor.window);
|
||||
// we should not call setBackGround because it will call a repaint
|
||||
// which the peer may not be ready to do yet.
|
||||
|
||||
}
|
||||
c = target.getForeground();
|
||||
if (c == null) {
|
||||
target.setForeground(SystemColor.windowText);
|
||||
// we should not call setForeGround because it will call a repaint
|
||||
// which the peer may not be ready to do yet.
|
||||
if (!target.isForegroundSet()) {
|
||||
target.setForeground(SystemColor.windowText);
|
||||
// we should not call setForeGround because it will call a repaint
|
||||
// which the peer may not be ready to do yet.
|
||||
}
|
||||
|
||||
|
||||
alwaysOnTop = ((Window)target).isAlwaysOnTop() && ((Window)target).isAlwaysOnTopSupported();
|
||||
|
||||
GraphicsConfiguration gc = getGraphicsConfiguration();
|
||||
|
@ -37,10 +37,6 @@ final class WDialogPeer extends WWindowPeer implements DialogPeer {
|
||||
// target has none explicitly specified.
|
||||
static final Color defaultBackground = SystemColor.control;
|
||||
|
||||
// If target doesn't have its background color set, we set its
|
||||
// background to platform default.
|
||||
boolean needDefaultBackground;
|
||||
|
||||
WDialogPeer(Dialog target) {
|
||||
super(target);
|
||||
|
||||
@ -67,7 +63,7 @@ final class WDialogPeer extends WWindowPeer implements DialogPeer {
|
||||
Dialog target = (Dialog)this.target;
|
||||
// Need to set target's background to default _before_ a call
|
||||
// to super.initialize.
|
||||
if (needDefaultBackground) {
|
||||
if (!target.isBackgroundSet()) {
|
||||
target.setBackground(defaultBackground);
|
||||
}
|
||||
|
||||
@ -133,19 +129,6 @@ final class WDialogPeer extends WWindowPeer implements DialogPeer {
|
||||
}
|
||||
}
|
||||
|
||||
/* Native create() peeks at target's background and if it's null
|
||||
* calls this method to arrage for default background to be set on
|
||||
* target. Can't make the check in Java, since getBackground will
|
||||
* return owner's background if target has none set.
|
||||
*/
|
||||
private void setDefaultColor() {
|
||||
// Can't call target.setBackground directly, since we are
|
||||
// called on toolkit thread. Can't schedule a Runnable on the
|
||||
// EventHandlerThread because of the race condition. So just
|
||||
// set a flag and call target.setBackground in initialize.
|
||||
needDefaultBackground = true;
|
||||
}
|
||||
|
||||
native void pSetIMMOption(String option);
|
||||
void notifyIMMOptionChange(){
|
||||
InputMethodManager.getInstance().notifyChangeRequest((Component)target);
|
||||
|
@ -177,12 +177,17 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer,
|
||||
|
||||
updateInsets(insets_);
|
||||
|
||||
Font f = ((Window)target).getFont();
|
||||
if (f == null) {
|
||||
f = defaultFont;
|
||||
((Window)target).setFont(f);
|
||||
setFont(f);
|
||||
if (!((Window) target).isFontSet()) {
|
||||
((Window) target).setFont(defaultFont);
|
||||
setFont(defaultFont);
|
||||
}
|
||||
if (!((Window) target).isForegroundSet()) {
|
||||
((Window) target).setForeground(SystemColor.windowText);
|
||||
}
|
||||
if (!((Window) target).isBackgroundSet()) {
|
||||
((Window) target).setBackground(SystemColor.window);
|
||||
}
|
||||
|
||||
// Express our interest in display changes
|
||||
GraphicsConfiguration gc = getGraphicsConfiguration();
|
||||
((Win32GraphicsDevice)gc.getDevice()).addDisplayChangedListener(this);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2016, 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
|
||||
@ -100,7 +100,6 @@ AwtDialog* AwtDialog::Create(jobject peer, jobject parent)
|
||||
{
|
||||
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
|
||||
|
||||
jobject background = NULL;
|
||||
jobject target = NULL;
|
||||
AwtDialog* dialog = NULL;
|
||||
|
||||
@ -181,22 +180,13 @@ AwtDialog* AwtDialog::Create(jobject peer, jobject parent)
|
||||
}
|
||||
dialog->DoUpdateIcon();
|
||||
|
||||
|
||||
background = env->GetObjectField(target,
|
||||
AwtComponent::backgroundID);
|
||||
if (background == NULL) {
|
||||
JNU_CallMethodByName(env, NULL,
|
||||
peer, "setDefaultColor", "()V");
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
env->DeleteLocalRef(background);
|
||||
env->DeleteLocalRef(target);
|
||||
throw;
|
||||
}
|
||||
|
||||
done:
|
||||
env->DeleteLocalRef(background);
|
||||
env->DeleteLocalRef(target);
|
||||
|
||||
return dialog;
|
||||
|
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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 8057574
|
||||
@summary Verify that child Dialog does not inherit parent's Properties
|
||||
@run main ChildDialogProperties
|
||||
*/
|
||||
import java.awt.Color;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Font;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Label;
|
||||
|
||||
public class ChildDialogProperties {
|
||||
|
||||
private Dialog parentDialog;
|
||||
private Dialog dialogChild;
|
||||
private Frame parentFrame;
|
||||
private Dialog frameChildDialog;
|
||||
private Label parentLabel;
|
||||
private Font parentFont;
|
||||
private Label childLabel;
|
||||
|
||||
private static final int WIDTH = 200;
|
||||
private static final int HEIGHT = 200;
|
||||
|
||||
public void testChildPropertiesWithDialogAsParent() {
|
||||
|
||||
parentDialog = new Dialog((Dialog) null, "parent Dialog");
|
||||
parentDialog.setSize(WIDTH, HEIGHT);
|
||||
parentDialog.setLocation(100, 100);
|
||||
parentDialog.setBackground(Color.RED);
|
||||
|
||||
parentLabel = new Label("ParentForegroundAndFont");
|
||||
parentFont = new Font("Courier New", Font.ITALIC, 15);
|
||||
parentDialog.setForeground(Color.BLUE);
|
||||
parentDialog.setFont(parentFont);
|
||||
|
||||
parentDialog.add(parentLabel);
|
||||
parentDialog.setVisible(true);
|
||||
|
||||
dialogChild = new Dialog(parentDialog, "Dialog's child");
|
||||
dialogChild.setSize(WIDTH, HEIGHT);
|
||||
dialogChild.setLocation(WIDTH + 200, 100);
|
||||
childLabel = new Label("ChildForegroundAndFont");
|
||||
dialogChild.add(childLabel);
|
||||
|
||||
dialogChild.setVisible(true);
|
||||
|
||||
if (parentDialog.getBackground() == dialogChild.getBackground()) {
|
||||
dispose();
|
||||
throw new RuntimeException("Child Dialog Should NOT Inherit "
|
||||
+ "Parent Dialog's Background Color");
|
||||
}
|
||||
|
||||
if (parentDialog.getForeground() == dialogChild.getForeground()) {
|
||||
dispose();
|
||||
throw new RuntimeException("Child Dialog Should NOT Inherit "
|
||||
+ "Parent Dialog's Foreground Color");
|
||||
}
|
||||
|
||||
if (parentDialog.getFont() == dialogChild.getFont()) {
|
||||
dispose();
|
||||
throw new RuntimeException("Child Dialog Should NOT Inherit "
|
||||
+ "Parent Dialog's Font Style/Color");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testChildPropertiesWithFrameAsParent() {
|
||||
|
||||
parentFrame = new Frame("parent Frame");
|
||||
parentFrame.setSize(WIDTH, HEIGHT);
|
||||
parentFrame.setLocation(100, 400);
|
||||
parentFrame.setBackground(Color.BLUE);
|
||||
parentLabel = new Label("ParentForegroundAndFont");
|
||||
parentFont = new Font("Courier New", Font.ITALIC, 15);
|
||||
parentFrame.setForeground(Color.RED);
|
||||
parentFrame.setFont(parentFont);
|
||||
parentFrame.add(parentLabel);
|
||||
parentFrame.setVisible(true);
|
||||
|
||||
frameChildDialog = new Dialog(parentFrame, "Frame's child");
|
||||
frameChildDialog.setSize(WIDTH, HEIGHT);
|
||||
frameChildDialog.setLocation(WIDTH + 200, 400);
|
||||
childLabel = new Label("ChildForegroundAndFont");
|
||||
frameChildDialog.add(childLabel);
|
||||
frameChildDialog.setVisible(true);
|
||||
|
||||
if (parentFrame.getBackground() == frameChildDialog.getBackground()) {
|
||||
dispose();
|
||||
throw new RuntimeException("Child Dialog Should NOT Inherit "
|
||||
+ "Parent Frame's Background Color");
|
||||
}
|
||||
|
||||
if (parentFrame.getForeground() == frameChildDialog.getForeground()) {
|
||||
dispose();
|
||||
throw new RuntimeException("Child Dialog Should NOT Inherit "
|
||||
+ "Parent Frame's Foreground Color");
|
||||
}
|
||||
|
||||
if (parentFrame.getFont() == frameChildDialog.getFont()) {
|
||||
dispose();
|
||||
throw new RuntimeException("Child Dialog Should NOT Inherit "
|
||||
+ "Parent Frame's Font Style/Color");
|
||||
}
|
||||
}
|
||||
|
||||
private void dispose() {
|
||||
|
||||
if (parentDialog != null) {
|
||||
parentDialog.dispose();
|
||||
}
|
||||
if (parentFrame != null) {
|
||||
parentFrame.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
ChildDialogProperties obj = new ChildDialogProperties();
|
||||
// TestCase1: When Parent is Dialog, Child is Dialog
|
||||
obj.testChildPropertiesWithDialogAsParent();
|
||||
// TestCase2: When Parent is Frame, chis is Dialog
|
||||
obj.testChildPropertiesWithFrameAsParent();
|
||||
obj.dispose();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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 8057574
|
||||
@summary Verify that child Window does not inherit parent's Properties
|
||||
@run main ChildWindowProperties
|
||||
*/
|
||||
import java.awt.Color;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Font;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Label;
|
||||
import java.awt.Panel;
|
||||
import java.awt.Window;
|
||||
|
||||
public class ChildWindowProperties {
|
||||
|
||||
private Dialog parentDialog;
|
||||
private Window windowChild;
|
||||
private Frame parentFrame;
|
||||
private Window frameChildWindow;
|
||||
private Label parentLabel;
|
||||
private Font parentFont;
|
||||
private Label childLabel;
|
||||
|
||||
private static final int WIDTH = 200;
|
||||
private static final int HEIGHT = 200;
|
||||
|
||||
public void testChildPropertiesWithDialogAsParent() {
|
||||
|
||||
parentDialog = new Dialog((Dialog) null, "parent Dialog");
|
||||
parentDialog.setSize(WIDTH, HEIGHT);
|
||||
parentDialog.setLocation(100, 100);
|
||||
parentDialog.setBackground(Color.RED);
|
||||
parentLabel = new Label("ParentForegroundAndFont");
|
||||
parentFont = new Font("Courier New", Font.ITALIC, 15);
|
||||
parentDialog.setForeground(Color.BLUE);
|
||||
parentDialog.setFont(parentFont);
|
||||
|
||||
parentDialog.add(parentLabel);
|
||||
parentDialog.setVisible(true);
|
||||
|
||||
windowChild = new Window(parentDialog);
|
||||
windowChild.setSize(WIDTH, HEIGHT);
|
||||
windowChild.setLocation(WIDTH + 200, 100);
|
||||
childLabel = new Label("ChildForegroundAndFont");
|
||||
windowChild.add(childLabel);
|
||||
windowChild.setVisible(true);
|
||||
|
||||
if (parentDialog.getBackground() == windowChild.getBackground()) {
|
||||
dispose();
|
||||
throw new RuntimeException("Child Window Should NOT Inherit "
|
||||
+ "Parent Dialog's Background Color");
|
||||
}
|
||||
if (parentDialog.getForeground() == windowChild.getForeground()) {
|
||||
dispose();
|
||||
throw new RuntimeException("Child Window Should NOT Inherit "
|
||||
+ "Parent Dialog's Foreground Color");
|
||||
}
|
||||
if (parentDialog.getFont() == windowChild.getFont()) {
|
||||
dispose();
|
||||
throw new RuntimeException("Child Window Should NOT Inherit "
|
||||
+ "Parent Dialog's Font Color");
|
||||
}
|
||||
}
|
||||
|
||||
public void testChildPropertiesWithFrameAsParent() {
|
||||
|
||||
parentFrame = new Frame("parent Frame");
|
||||
parentFrame.setSize(WIDTH, HEIGHT);
|
||||
parentFrame.setLocation(100, 400);
|
||||
parentFrame.setBackground(Color.BLUE);
|
||||
parentLabel = new Label("ParentForegroundAndFont");
|
||||
parentFont = new Font("Courier New", Font.ITALIC, 15);
|
||||
parentFrame.setForeground(Color.RED);
|
||||
parentFrame.setFont(parentFont);
|
||||
parentFrame.add(parentLabel);
|
||||
parentFrame.setVisible(true);
|
||||
|
||||
frameChildWindow = new Window(parentFrame);
|
||||
frameChildWindow.setSize(WIDTH, HEIGHT);
|
||||
frameChildWindow.setLocation(WIDTH + 200, 400);
|
||||
childLabel = new Label("ChildForegroundAndFont");
|
||||
frameChildWindow.add(childLabel);
|
||||
frameChildWindow.setVisible(true);
|
||||
|
||||
if (parentFrame.getBackground() == frameChildWindow.getBackground()) {
|
||||
dispose();
|
||||
throw new RuntimeException("Child Window Should NOT Inherit "
|
||||
+ "Parent Frame's Background Color");
|
||||
}
|
||||
if (parentDialog.getForeground() == windowChild.getForeground()) {
|
||||
dispose();
|
||||
throw new RuntimeException("Child Window Should NOT Inherit "
|
||||
+ "Parent Frame's Foreground Color");
|
||||
}
|
||||
if (parentDialog.getFont() == windowChild.getFont()) {
|
||||
dispose();
|
||||
throw new RuntimeException("Child Window Should NOT Inherit "
|
||||
+ "Parent Frame's Font Color");
|
||||
}
|
||||
}
|
||||
|
||||
public void testPanelBackground() {
|
||||
Window window = new Frame();
|
||||
window.setBackground(Color.GREEN);
|
||||
Panel panel = new Panel();
|
||||
window.add(panel);
|
||||
window.pack();
|
||||
window.setVisible(true);
|
||||
if (panel.getBackground() != Color.GREEN) {
|
||||
window.dispose();
|
||||
throw new RuntimeException("Panel Background Color Not Valid");
|
||||
}
|
||||
window.dispose();
|
||||
}
|
||||
|
||||
private void dispose() {
|
||||
|
||||
if (parentDialog != null) {
|
||||
parentDialog.dispose();
|
||||
}
|
||||
if (parentFrame != null) {
|
||||
parentFrame.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
ChildWindowProperties obj = new ChildWindowProperties();
|
||||
// TestCase1: When Parent is Dialog, Child is Window
|
||||
obj.testChildPropertiesWithDialogAsParent();
|
||||
// TestCase2: When Parent is Frame, chis is Window
|
||||
obj.testChildPropertiesWithFrameAsParent();
|
||||
// TestCase3: Panel Background Test
|
||||
obj.testPanelBackground();
|
||||
obj.dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user