Skip to content

Commit

Permalink
7175397: The divider color is not changed to green when dragging for …
Browse files Browse the repository at this point in the history
…Nimbus LaF.

Reviewed-by: jdv
  • Loading branch information
prsadhuk committed Oct 18, 2022
1 parent 8c40b7d commit 78fed9d
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
Expand Up @@ -65,6 +65,8 @@ public class SynthSplitPaneUI extends BasicSplitPaneUI
*/
private SynthStyle dividerStyle;

private Color dividerDraggingColor;

/**
*
* Constructs a {@code SynthSplitPaneUI}.
Expand All @@ -89,6 +91,8 @@ public static ComponentUI createUI(JComponent x) {
protected void installDefaults() {
updateStyle(splitPane);

dividerDraggingColor = UIManager.getColor("SplitPaneDivider.draggingColor");

setOrientation(splitPane.getOrientation());
setContinuousLayout(splitPane.isContinuousLayout());

Expand Down Expand Up @@ -256,6 +260,19 @@ public BasicSplitPaneDivider createDefaultDivider() {
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}
*/
Expand All @@ -265,6 +282,7 @@ protected Component createDefaultNonContinuousLayoutDivider() {
return new Canvas() {
public void paint(Graphics g) {
paintDragDivider(g, 0, 0, getWidth(), getHeight());
setDividerDraggingColor(g, 0);
}
};
}
Expand Down Expand Up @@ -345,15 +363,18 @@ private void paintDragDivider(Graphics g, int x, int y, int w, int h) {
*/
@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);
} else {
paintDragDivider(g, 0, getLastDragLocation(),
splitPane.getWidth() - 1, dividerSize - 1);
}
setDividerDraggingColor(g, getLastDragLocation());
}
}
}
95 changes: 95 additions & 0 deletions test/jdk/javax/swing/plaf/nimbus/TestNimbusDividerDragColor.java
@@ -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();
}
}

0 comments on commit 78fed9d

Please sign in to comment.