7175397: The divider color is not changed to green when dragging for Nimbus LaF.

Reviewed-by: jdv
This commit is contained in:
Prasanta Sadhukhan 2022-10-18 14:05:37 +00:00
parent 8c40b7dc8c
commit 78fed9d307
2 changed files with 116 additions and 0 deletions
src/java.desktop/share/classes/javax/swing/plaf/synth
test/jdk/javax/swing/plaf/nimbus

@ -65,6 +65,8 @@ public class SynthSplitPaneUI extends BasicSplitPaneUI
*/
private SynthStyle dividerStyle;
private Color dividerDraggingColor;
/**
*
* Constructs a {@code SynthSplitPaneUI}.
@ -89,6 +91,8 @@ public class SynthSplitPaneUI extends BasicSplitPaneUI
protected void installDefaults() {
updateStyle(splitPane);
dividerDraggingColor = UIManager.getColor("SplitPaneDivider.draggingColor");
setOrientation(splitPane.getOrientation());
setContinuousLayout(splitPane.isContinuousLayout());
@ -256,6 +260,19 @@ public class SynthSplitPaneUI extends BasicSplitPaneUI
return divider;
}
private void setDividerDraggingColor(Graphics g, int loc) {
if (!isContinuousLayout() && getLastDragLocation() != -1 &&
dividerDraggingColor != null) {
g.setColor(dividerDraggingColor);
if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
g.fillRect(loc, 0, dividerSize - 1, splitPane.getHeight() - 1);
} else {
g.fillRect(0, loc, splitPane.getWidth() - 1, dividerSize - 1);
}
}
}
/**
* {@inheritDoc}
*/
@ -265,6 +282,7 @@ public class SynthSplitPaneUI extends BasicSplitPaneUI
return new Canvas() {
public void paint(Graphics g) {
paintDragDivider(g, 0, 0, getWidth(), getHeight());
setDividerDraggingColor(g, 0);
}
};
}
@ -345,8 +363,10 @@ public class SynthSplitPaneUI extends BasicSplitPaneUI
*/
@Override
public void finishedPaintingChildren(JSplitPane jc, Graphics g) {
if(jc == splitPane && getLastDragLocation() != -1 &&
!isContinuousLayout() && !draggingHW) {
if(jc.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
paintDragDivider(g, getLastDragLocation(), 0, dividerSize - 1,
splitPane.getHeight() - 1);
@ -354,6 +374,7 @@ public class SynthSplitPaneUI extends BasicSplitPaneUI
paintDragDivider(g, 0, getLastDragLocation(),
splitPane.getWidth() - 1, dividerSize - 1);
}
setDividerDraggingColor(g, getLastDragLocation());
}
}
}

@ -0,0 +1,95 @@
/*
* Copyright (c) 2022, 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 4820080
@summary RFE: Cannot Change the JSplitPane Divider Color while dragging
@key headful
@library /java/awt/regtesthelpers
@build PassFailJFrame
@run main/manual TestNimbusDividerDragColor
*/
import java.awt.Color;
import java.awt.Panel;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JSplitPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
public class TestNimbusDividerDragColor {
private static JFrame frame;
private static final String INSTRUCTIONS =
"Drag the dividers of the splitpanes (both top and bottom).\n " +
" If the divider color is green while dragging\n " +
" then test passes, otherwise test fails";
public static void init() {
UIManager.put("SplitPaneDivider.draggingColor", Color.green);
frame = new JFrame();
Box box = new Box(BoxLayout.Y_AXIS);
frame.getContentPane().add(box);
JPanel jleft = new JPanel();
jleft.setBackground(Color.darkGray);
JPanel jright = new JPanel();
jright.setBackground(Color.darkGray);
JSplitPane jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jleft, jright);
jsp.setContinuousLayout(false);
box.add(jsp);
box.add(Box.createVerticalStrut(5));
box.add(new JSeparator());
box.add(Box.createVerticalStrut(5));
Panel left = new Panel();
left.setBackground(Color.darkGray);
Panel right = new Panel();
right.setBackground(Color.darkGray);
JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);
sp.setContinuousLayout(false);
box.add(sp);
frame.add(box);
frame.setSize(200, 200);
frame.setVisible(true);
}
public static void main(String[] argv) throws Exception {
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
PassFailJFrame passFailJFrame = new PassFailJFrame(
"JFileChooser Test Instructions", INSTRUCTIONS, 5);
SwingUtilities.invokeAndWait(() -> init());
PassFailJFrame.addTestWindow(frame);
PassFailJFrame.positionTestWindow(
frame, PassFailJFrame.Position.HORIZONTAL);
passFailJFrame.awaitAndCheck();
}
}