Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9ff9e62

Browse files
committed
8271315: Redo: Nimbus JTree renderer properties persist across L&F changes
Backport-of: e43a907f20f99fa1f788fcbe2e99631dd01578d4
1 parente7e83d5 commit9ff9e62

File tree

5 files changed

+279
-8
lines changed

5 files changed

+279
-8
lines changed

‎src/java.desktop/share/classes/javax/swing/plaf/nimbus/NimbusIcon.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* An icon that delegates to a painter.
4444
* @author rbair
4545
*/
46-
classNimbusIconimplementsSynthIcon {
46+
classNimbusIconimplementsSynthIcon,UIResource {
4747
privateintwidth;
4848
privateintheight;
4949
privateStringprefix;

‎src/java.desktop/share/classes/javax/swing/plaf/nimbus/skin.laf‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27352,10 +27352,10 @@
2735227352
<contentMargins top="0" bottom="0" left="0" right="0"/>
2735327353
<style>
2735427354
<textForeground>
27355-
<matte red="0" green="0" blue="0" alpha="0" uiDefaultParentName="text" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0" uiResource="false"/>
27355+
<matte red="0" green="0" blue="0" alpha="0" uiDefaultParentName="text" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0" uiResource="true"/>
2735627356
</textForeground>
2735727357
<textBackground>
27358-
<matte red="255" green="255" blue="255" alpha="255" uiDefaultParentName="nimbusLightBackground" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0" uiResource="false"/>
27358+
<matte red="255" green="255" blue="255" alpha="255" uiDefaultParentName="nimbusLightBackground" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0" uiResource="true"/>
2735927359
</textBackground>
2736027360
<background>
2736127361
<matte red="255" green="255" blue="255" alpha="255" uiDefaultParentName="nimbusLightBackground" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0"/>
@@ -27379,10 +27379,10 @@
2737927379
<insets top="2" left="0" bottom="1" right="5"/>
2738027380
</uiProperty>
2738127381
<uiProperty name="selectionForeground" type="COLOR">
27382-
<matte red="255" green="255" blue="255" alpha="255" uiDefaultParentName="nimbusSelectedText" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0" uiResource="false"/>
27382+
<matte red="255" green="255" blue="255" alpha="255" uiDefaultParentName="nimbusSelectedText" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0" uiResource="true"/>
2738327383
</uiProperty>
2738427384
<uiProperty name="selectionBackground" type="COLOR">
27385-
<matte red="57" green="105" blue="138" alpha="255" uiDefaultParentName="nimbusSelectionBackground" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0" uiResource="false"/>
27385+
<matte red="57" green="105" blue="138" alpha="255" uiDefaultParentName="nimbusSelectionBackground" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0" uiResource="true"/>
2738627386
</uiProperty>
2738727387
<uiProperty name="dropLineColor" type="COLOR">
2738827388
<matte red="242" green="242" blue="242" alpha="255" uiDefaultParentName="nimbusFocus" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0" alphaOffset="0"/>
@@ -27621,7 +27621,9 @@
2762127621
<stateTypes/>
2762227622
<contentMargins top="0" bottom="0" left="0" right="0"/>
2762327623
<style>
27624-
<textForeground/>
27624+
<textForeground>
27625+
<matte red="255" green="255" blue="255" alpha="255" uiDefaultParentName="nimbusSelectedText" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0" uiResource="true"/>
27626+
</textForeground>
2762527627
<textBackground/>
2762627628
<background/>
2762727629
<uiproperties/>

‎src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLabelUI.java‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
importjavax.swing.plaf.*;
3030
importjavax.swing.plaf.basic.*;
3131
importjavax.swing.text.View;
32+
importjavax.swing.tree.DefaultTreeCellRenderer;
3233
importjava.awt.Dimension;
3334
importjava.awt.Rectangle;
3435
importjava.awt.Insets;
@@ -207,8 +208,14 @@ protected void paint(SynthContext context, Graphics g) {
207208
Iconicon = (label.isEnabled()) ?label.getIcon() :
208209
label.getDisabledIcon();
209210

210-
g.setColor(context.getStyle().getColor(context,
211-
ColorType.TEXT_FOREGROUND));
211+
if (labelinstanceofDefaultTreeCellRenderer &&
212+
label.getForeground()instanceofUIResource) {
213+
g.setColor(label.getForeground());
214+
}else {
215+
g.setColor(context.getStyle().getColor(context,
216+
ColorType.TEXT_FOREGROUND));
217+
}
218+
212219
g.setFont(style.getFont(context));
213220
context.getStyle().getGraphicsUtils(context).paintText(
214221
context,g,label.getText(),icon,
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
/*
24+
* @test
25+
* @bug 8266510 8271315
26+
* @summary Verifies Nimbus JTree default tree cell renderer use selected text color
27+
* @run main/manual NimbusJTreeSelTextColor
28+
*/
29+
importjava.util.concurrent.CountDownLatch;
30+
importjava.util.concurrent.TimeUnit;
31+
importjava.awt.Color;
32+
importjava.awt.GridBagLayout;
33+
importjava.awt.Insets;
34+
importjava.awt.GridBagConstraints;
35+
importjava.awt.event.ActionEvent;
36+
importjava.awt.event.ActionListener;
37+
importjava.awt.event.WindowAdapter;
38+
importjava.awt.event.WindowEvent;
39+
importjavax.swing.JButton;
40+
importjavax.swing.JComponent;
41+
importjavax.swing.JFrame;
42+
importjavax.swing.JPanel;
43+
importjavax.swing.JTextArea;
44+
importjavax.swing.JTree;
45+
importjavax.swing.SwingUtilities;
46+
importjavax.swing.tree.DefaultTreeCellRenderer;
47+
importjavax.swing.UIManager;
48+
49+
publicclassNimbusJTreeSelTextColor {
50+
51+
privatestaticJFrameframe;
52+
privatestaticJTreetree;
53+
privatestaticDefaultTreeCellRenderertreeCellRenderer;
54+
privatestaticvolatileCountDownLatchcountDownLatch;
55+
privatestaticvolatilebooleantestResult;
56+
57+
privatestaticfinalStringINSTRUCTIONS ="INSTRUCTIONS:\n\n"
58+
+"Verify selected text color is same as selected tree leaf icon color.\n "
59+
+"If the color is same ie, white\n"
60+
+"then press Pass otherwise press Fail.";
61+
62+
publicstaticvoidmain(Stringargs[])throwsException{
63+
countDownLatch =newCountDownLatch(1);
64+
65+
SwingUtilities.invokeAndWait(NimbusJTreeSelTextColor::createUI);
66+
countDownLatch.await(5,TimeUnit.MINUTES);
67+
68+
if (!testResult) {
69+
thrownewRuntimeException("Selected text color not same as selected tree leaf icon color!");
70+
}
71+
}
72+
73+
privatestaticvoidcreateUI() {
74+
try {
75+
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
76+
}catch (Exceptione) {
77+
thrownewRuntimeException(e);
78+
}
79+
80+
JFramemainFrame =newJFrame();
81+
GridBagLayoutlayout =newGridBagLayout();
82+
JPanelmainControlPanel =newJPanel(layout);
83+
JPanelresultButtonPanel =newJPanel(layout);
84+
85+
GridBagConstraintsgbc =newGridBagConstraints();
86+
87+
gbc.gridx =0;
88+
gbc.gridy =0;
89+
gbc.insets =newInsets(5,15,5,15);
90+
gbc.fill =GridBagConstraints.HORIZONTAL;
91+
mainControlPanel.add(createComponent(),gbc);
92+
93+
JTextAreainstructionTextArea =newJTextArea();
94+
instructionTextArea.setText(INSTRUCTIONS);
95+
instructionTextArea.setEditable(false);
96+
instructionTextArea.setBackground(Color.white);
97+
98+
gbc.gridx =0;
99+
gbc.gridy =1;
100+
gbc.fill =GridBagConstraints.HORIZONTAL;
101+
mainControlPanel.add(instructionTextArea,gbc);
102+
103+
JButtonpassButton =newJButton("Pass");
104+
passButton.setActionCommand("Pass");
105+
passButton.addActionListener((ActionEvente) -> {
106+
testResult =true;
107+
mainFrame.dispose();
108+
countDownLatch.countDown();
109+
110+
});
111+
112+
JButtonfailButton =newJButton("Fail");
113+
failButton.setActionCommand("Fail");
114+
failButton.addActionListener(newActionListener() {
115+
@Override
116+
publicvoidactionPerformed(ActionEvente) {
117+
mainFrame.dispose();
118+
countDownLatch.countDown();
119+
}
120+
});
121+
122+
gbc.gridx =0;
123+
gbc.gridy =0;
124+
125+
resultButtonPanel.add(passButton,gbc);
126+
gbc.gridx =1;
127+
gbc.gridy =0;
128+
resultButtonPanel.add(failButton,gbc);
129+
130+
gbc.gridx =0;
131+
gbc.gridy =2;
132+
mainControlPanel.add(resultButtonPanel,gbc);
133+
134+
mainFrame.add(mainControlPanel);
135+
mainFrame.pack();
136+
137+
mainFrame.addWindowListener(newWindowAdapter() {
138+
139+
@Override
140+
publicvoidwindowClosing(WindowEvente) {
141+
mainFrame.dispose();
142+
countDownLatch.countDown();
143+
}
144+
});
145+
mainFrame.setLocationRelativeTo(null);
146+
mainFrame.setVisible(true);
147+
}
148+
149+
privatestaticJComponentcreateComponent() {
150+
tree =newJTree();
151+
152+
treeCellRenderer =newDefaultTreeCellRenderer();
153+
tree.setRootVisible(true);
154+
tree.setShowsRootHandles(true);
155+
156+
tree.setCellRenderer(treeCellRenderer);
157+
tree.setSelectionRow(1);
158+
returntree;
159+
}
160+
}
161+
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
importjavax.swing.UIManager;
25+
importjavax.swing.UnsupportedLookAndFeelException;
26+
importjavax.swing.plaf.UIResource;
27+
importjavax.swing.plaf.nimbus.NimbusLookAndFeel;
28+
importjava.awt.Color;
29+
30+
/**
31+
* @test
32+
* @bug 8271315
33+
* @summary Nimbus JTree renderer properties persist across L&F changes
34+
* @key headful
35+
* @run main NimbusPropertiesDoNotImplUIResource
36+
*/
37+
38+
publicclassNimbusPropertiesDoNotImplUIResource {
39+
privatestaticfinalString[]defPropertyKeys =newString[] {
40+
"Tree.leafIcon","Tree.closedIcon",
41+
"Tree.openIcon","Tree.selectionForeground",
42+
"Tree.textForeground","Tree.selectionBackground",
43+
"Tree.textBackground","Tree.selectionBorderColor"};
44+
45+
privatestaticStringfailedKeys;
46+
47+
publicstaticvoidmain(String[]args)throwsException {
48+
UIManager.LookAndFeelInfo[]installedLookAndFeels;
49+
installedLookAndFeels =UIManager.getInstalledLookAndFeels();
50+
51+
for (UIManager.LookAndFeelInfoLF :installedLookAndFeels) {
52+
try {
53+
UIManager.setLookAndFeel(LF.getClassName());
54+
failedKeys =null;
55+
for (StringpropertyKey :defPropertyKeys) {
56+
verifyProperty(propertyKey);
57+
}
58+
if (failedKeys !=null) {
59+
thrownewRuntimeException("JTree renderer Properties " +
60+
failedKeys +" are not instance of UIResource for "
61+
+LF.getClassName());
62+
}
63+
}catch (UnsupportedLookAndFeelExceptione) {
64+
System.out.println("Note: LookAndFeel " +LF.getClassName()
65+
+" is not supported on this configuration");
66+
}
67+
}
68+
69+
// Check that both uiResource option true and false work for
70+
// getDerivedColor method of NimbusLookAndFeel
71+
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
72+
Colorcolor1 = ((NimbusLookAndFeel)UIManager.getLookAndFeel())
73+
.getDerivedColor("text",0,0,0,0,false);
74+
if (color1instanceofUIResource) {
75+
thrownewRuntimeException("color1 should not be instance of " +
76+
"UIResource");
77+
}
78+
79+
Colorcolor2 = ((NimbusLookAndFeel)UIManager.getLookAndFeel())
80+
.getDerivedColor("text",0,0,0,0,true);
81+
if (!(color2instanceofUIResource)) {
82+
thrownewRuntimeException("color2 should be instance of " +
83+
"UIResource");
84+
}
85+
86+
}
87+
88+
privatestaticvoidverifyProperty(StringpropertyKey) {
89+
Objectproperty =UIManager.get(propertyKey);
90+
if (property ==null) {
91+
return;
92+
}
93+
if (!(propertyinstanceofUIResource)) {
94+
if (failedKeys ==null) {
95+
failedKeys =":" +propertyKey;
96+
}else {
97+
failedKeys +="," +propertyKey;
98+
}
99+
}
100+
}
101+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp