8345004: [BACKOUT] GTK & Nimbus LAF: Tabbed pane's background color is not expected one when change the opaque checkbox.

Reviewed-by: psadhukhan, kizune
This commit is contained in:
Abhishek Kumar 2024-11-27 08:24:01 +00:00
parent 4ae6ce61ea
commit 96388be1b5
6 changed files with 35 additions and 96 deletions

View File

@ -356,8 +356,6 @@ public class GTKLookAndFeel extends SynthLookAndFeel {
Double defaultCaretAspectRatio = Double.valueOf(0.025); Double defaultCaretAspectRatio = Double.valueOf(0.025);
Color caretColor = table.getColor("caretColor"); Color caretColor = table.getColor("caretColor");
Color controlText = table.getColor("controlText"); Color controlText = table.getColor("controlText");
Color tabbedPaneBg = new ColorUIResource(238, 238, 238);
Color unselectedTabColor = new ColorUIResource(255, 255, 255);
Object fieldInputMap = new UIDefaults.LazyInputMap(new Object[] { Object fieldInputMap = new UIDefaults.LazyInputMap(new Object[] {
"ctrl C", DefaultEditorKit.copyAction, "ctrl C", DefaultEditorKit.copyAction,
@ -1029,11 +1027,6 @@ public class GTKLookAndFeel extends SynthLookAndFeel {
"TabbedPane.selectedLabelShift", 3, "TabbedPane.selectedLabelShift", 3,
"TabbedPane.font", new FontLazyValue(Region.TABBED_PANE), "TabbedPane.font", new FontLazyValue(Region.TABBED_PANE),
"TabbedPane.selectedTabPadInsets", new InsetsUIResource(2, 2, 0, 1), "TabbedPane.selectedTabPadInsets", new InsetsUIResource(2, 2, 0, 1),
"TabbedPane.selected", tabbedPaneBg,
"TabbedPane.contentOpaque", Boolean.TRUE,
"TabbedPane.tabsOpaque", Boolean.TRUE,
"TabbedPane.contentAreaColor", tabbedPaneBg,
"TabbedPane.unselectedBackground", unselectedTabColor,
"Table.scrollPaneBorder", zeroBorder, "Table.scrollPaneBorder", zeroBorder,
"Table.background", tableBg, "Table.background", tableBg,

View File

@ -935,27 +935,22 @@ class GTKPainter extends SynthPainter {
Graphics g, Graphics g,
int x, int y, int w, int h, int x, int y, int w, int h,
int tabIndex) { int tabIndex) {
Region id = context.getRegion();
int state = context.getComponentState();
int gtkState = ((state & SynthConstants.SELECTED) != 0 ?
SynthConstants.ENABLED : SynthConstants.PRESSED);
JTabbedPane pane = (JTabbedPane)context.getComponent(); JTabbedPane pane = (JTabbedPane)context.getComponent();
if (UIManager.getBoolean("TabbedPane.tabsOpaque") || pane.isOpaque()) { int placement = pane.getTabPlacement();
Region id = context.getRegion();
int state = context.getComponentState();
int gtkState = ((state & SynthConstants.SELECTED) != 0 ?
SynthConstants.ENABLED : SynthConstants.PRESSED);
int placement = pane.getTabPlacement();
// Fill the tab rect area synchronized (UNIXToolkit.GTK_LOCK) {
g.fillRect(x, y, w, h); if (!ENGINE.paintCachedImage(g, x, y, w, h,
id, gtkState, placement, tabIndex)) {
synchronized (UNIXToolkit.GTK_LOCK) { PositionType side = POSITIONS[placement - 1];
if (!ENGINE.paintCachedImage(g, x, y, w, h, ENGINE.startPainting(g, x, y, w, h,
id, gtkState, placement, tabIndex)) { id, gtkState, placement, tabIndex);
PositionType side = POSITIONS[placement - 1]; ENGINE.paintExtension(g, context, id, gtkState,
ENGINE.startPainting(g, x, y, w, h, ShadowType.OUT, "tab", x, y, w, h, side, tabIndex);
id, gtkState, placement, tabIndex); ENGINE.finishPainting();
ENGINE.paintExtension(g, context, id, gtkState,
ShadowType.OUT, "tab", x, y, w, h, side, tabIndex);
ENGINE.finishPainting();
}
} }
} }
} }

View File

@ -2111,27 +2111,24 @@ class SynthPainterImpl extends SynthPainter {
public void paintTabbedPaneTabBackground(SynthContext context, Graphics g, public void paintTabbedPaneTabBackground(SynthContext context, Graphics g,
int x, int y, int w, int h, int x, int y, int w, int h,
int tabIndex, int orientation) { int tabIndex, int orientation) {
JTabbedPane pane = (JTabbedPane)context.getComponent(); if (orientation == JTabbedPane.LEFT) {
if (UIManager.getBoolean("TabbedPane.tabsOpaque") || pane.isOpaque()) { AffineTransform transform = new AffineTransform();
if (orientation == JTabbedPane.LEFT) { transform.scale(-1, 1);
AffineTransform transform = new AffineTransform(); transform.rotate(Math.toRadians(90));
transform.scale(-1, 1); paintBackground(context, g, y, x, h, w, transform);
transform.rotate(Math.toRadians(90)); } else if (orientation == JTabbedPane.RIGHT) {
paintBackground(context, g, y, x, h, w, transform); AffineTransform transform = new AffineTransform();
} else if (orientation == JTabbedPane.RIGHT) { transform.rotate(Math.toRadians(90));
AffineTransform transform = new AffineTransform(); transform.translate(0, -(x + w));
transform.rotate(Math.toRadians(90)); paintBackground(context, g, y, 0, h, w, transform);
transform.translate(0, -(x + w)); } else if (orientation == JTabbedPane.BOTTOM) {
paintBackground(context, g, y, 0, h, w, transform); AffineTransform transform = new AffineTransform();
} else if (orientation == JTabbedPane.BOTTOM) { transform.translate(x, y);
AffineTransform transform = new AffineTransform(); transform.scale(1, -1);
transform.translate(x, y); transform.translate(0, -h);
transform.scale(1, -1); paintBackground(context, g, 0, 0, w, h, transform);
transform.translate(0, -h); } else {
paintBackground(context, g, 0, 0, w, h, transform); paintBackground(context, g, x, y, w, h, null);
} else {
paintBackground(context, g, x, y, w, h, null);
}
} }
} }

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved. Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it This code is free software; you can redistribute it and/or modify it
@ -83,9 +83,6 @@
<uiColor name="nimbusDisabledText"> <uiColor name="nimbusDisabledText">
<matte red="142" green="143" blue="145" alpha="255" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0"/> <matte red="142" green="143" blue="145" alpha="255" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0"/>
</uiColor> </uiColor>
<uiColor name="nimbusTabbedPaneContentArea">
<matte red="238" green="238" blue="238" alpha="255" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0"/>
</uiColor>
<uiColor name="nimbusLightBackground"> <uiColor name="nimbusLightBackground">
<matte red="255" green="255" blue="255" alpha="255" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0"/> <matte red="255" green="255" blue="255" alpha="255" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0"/>
</uiColor> </uiColor>
@ -21649,11 +21646,6 @@
<uiProperty name="tabOverlap" type="INT" value="-1"/> <uiProperty name="tabOverlap" type="INT" value="-1"/>
<uiProperty name="extendTabsToBase" type="BOOLEAN" value="true"/> <uiProperty name="extendTabsToBase" type="BOOLEAN" value="true"/>
<uiProperty name="useBasicArrows" type="BOOLEAN" value="true"/> <uiProperty name="useBasicArrows" type="BOOLEAN" value="true"/>
<uiProperty name="contentOpaque" type="BOOLEAN" value="true"/>
<uiProperty name="tabsOpaque" type="BOOLEAN" value="true"/>
<uiProperty name="contentAreaColor" type="COLOR">
<matte red="238" green="238" blue="238" alpha="255" uiDefaultParentName="nimbusTabbedPaneContentArea" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0"/>
</uiProperty>
<uiProperty name="shadow" type="COLOR"> <uiProperty name="shadow" type="COLOR">
<matte red="142" green="143" blue="145" alpha="255" uiDefaultParentName="nimbusDisabledText" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0"/> <matte red="142" green="143" blue="145" alpha="255" uiDefaultParentName="nimbusDisabledText" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0"/>
</uiProperty> </uiProperty>

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,7 +26,6 @@
package javax.swing.plaf.synth; package javax.swing.plaf.synth;
import java.awt.Component; import java.awt.Component;
import java.awt.Color;
import java.awt.Font; import java.awt.Font;
import java.awt.FontMetrics; import java.awt.FontMetrics;
import java.awt.Graphics; import java.awt.Graphics;
@ -122,12 +121,6 @@ public class SynthTabbedPaneUI extends BasicTabbedPaneUI
private boolean selectedTabIsPressed = false; private boolean selectedTabIsPressed = false;
// Background color for selected tab and content pane
private Color selectColor;
// Background color for unselected tabs
private Color unselectedBackground;
private boolean contentOpaque = true;
/** /**
* *
* Constructs a {@code SynthTabbedPaneUI}. * Constructs a {@code SynthTabbedPaneUI}.
@ -153,9 +146,6 @@ public class SynthTabbedPaneUI extends BasicTabbedPaneUI
*/ */
@Override @Override
protected void installDefaults() { protected void installDefaults() {
selectColor = UIManager.getColor("TabbedPane.selected");
contentOpaque = UIManager.getBoolean("TabbedPane.contentOpaque");
unselectedBackground = UIManager.getColor("TabbedPane.unselectedBackground");
updateStyle(tabPane); updateStyle(tabPane);
} }
@ -647,12 +637,6 @@ public class SynthTabbedPaneUI extends BasicTabbedPaneUI
} }
} }
if (isSelected) {
g.setColor(selectColor);
} else {
g.setColor(getUnselectedBackgroundAt(tabIndex));
}
tabContext.getPainter().paintTabbedPaneTabBackground(tabContext, g, tabContext.getPainter().paintTabbedPaneTabBackground(tabContext, g,
x, y, width, height, tabIndex, placement); x, y, width, height, tabIndex, placement);
tabContext.getPainter().paintTabbedPaneTabBorder(tabContext, g, tabContext.getPainter().paintTabbedPaneTabBorder(tabContext, g,
@ -675,14 +659,6 @@ public class SynthTabbedPaneUI extends BasicTabbedPaneUI
} }
} }
private Color getUnselectedBackgroundAt(int index) {
Color color = tabPane.getBackgroundAt(index);
if (color instanceof UIResource && unselectedBackground != null) {
return unselectedBackground;
}
return color;
}
private void layoutLabel(SynthContext ss, int tabPlacement, private void layoutLabel(SynthContext ss, int tabPlacement,
FontMetrics metrics, int tabIndex, FontMetrics metrics, int tabIndex,
String title, Icon icon, String title, Icon icon,
@ -760,21 +736,6 @@ public class SynthTabbedPaneUI extends BasicTabbedPaneUI
h -= (y - insets.top); h -= (y - insets.top);
} }
SynthLookAndFeel.updateSubregion(ss, g, new Rectangle(x, y, w, h)); SynthLookAndFeel.updateSubregion(ss, g, new Rectangle(x, y, w, h));
if (tabPane.getTabCount() > 0 && (contentOpaque || tabPane.isOpaque())) {
// Fill region behind content area
Color color = UIManager.getColor("TabbedPane.contentAreaColor");
if (color != null) {
g.setColor(color);
} else if (selectColor == null || selectedIndex == -1) {
g.setColor(tabPane.getBackground());
} else {
g.setColor(selectColor);
}
// fill content area rect for both GTK and Nimbus LAF here
g.fillRect(x, y, w, h);
}
ss.getPainter().paintTabbedPaneContentBackground(ss, g, x, y, ss.getPainter().paintTabbedPaneContentBackground(ss, g, x, y,
w, h); w, h);
ss.getPainter().paintTabbedPaneContentBorder(ss, g, x, y, w, h); ss.getPainter().paintTabbedPaneContentBorder(ss, g, x, y, w, h);

View File

@ -791,6 +791,7 @@ jdk/jfr/jvm/TestWaste.java 8282427 generic-
javax/swing/JFileChooser/6698013/bug6698013.java 8024419 macosx-all javax/swing/JFileChooser/6698013/bug6698013.java 8024419 macosx-all
javax/swing/JColorChooser/8065098/bug8065098.java 8065647 macosx-all javax/swing/JColorChooser/8065098/bug8065098.java 8065647 macosx-all
javax/swing/JTabbedPane/4666224/bug4666224.java 8144124 macosx-all javax/swing/JTabbedPane/4666224/bug4666224.java 8144124 macosx-all
javax/swing/JTabbedPane/TestJTabbedPaneOpaqueColor.java 8345090 windows-all,linux-all
javax/swing/SwingUtilities/TestTextPosInPrint.java 8227025 windows-all javax/swing/SwingUtilities/TestTextPosInPrint.java 8227025 windows-all
java/awt/event/MouseEvent/SpuriousExitEnter/SpuriousExitEnter_1.java 7131438,8022539 generic-all java/awt/event/MouseEvent/SpuriousExitEnter/SpuriousExitEnter_1.java 7131438,8022539 generic-all