mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 22:47:13 -06:00
new: support for hover on splitpane divider
This commit is contained in:
@@ -21,6 +21,7 @@ import java.awt.Container;
|
|||||||
import java.awt.Cursor;
|
import java.awt.Cursor;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
|
import java.awt.Dimension;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
@@ -52,6 +53,8 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
* @uiDefault SplitPane.border Border
|
* @uiDefault SplitPane.border Border
|
||||||
* @uiDefault SplitPaneDivider.border Border
|
* @uiDefault SplitPaneDivider.border Border
|
||||||
* @uiDefault SplitPaneDivider.draggingColor Color only used if continuousLayout is false
|
* @uiDefault SplitPaneDivider.draggingColor Color only used if continuousLayout is false
|
||||||
|
* @uiDefault SplitPaneDivider.showHover boolean optional; default is false
|
||||||
|
* @uiDefault SplitPaneDivider.hoverColor Color the divider color on mouse hover if SplitPaneDivider.showHover is enabled
|
||||||
*
|
*
|
||||||
* <!-- BasicSplitPaneDivider -->
|
* <!-- BasicSplitPaneDivider -->
|
||||||
*
|
*
|
||||||
@@ -89,6 +92,8 @@ public class FlatSplitPaneUI
|
|||||||
|
|
||||||
private Map<String, Object> oldStyleValues;
|
private Map<String, Object> oldStyleValues;
|
||||||
|
|
||||||
|
private boolean dragging;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatSplitPaneUI();
|
return new FlatSplitPaneUI();
|
||||||
}
|
}
|
||||||
@@ -183,11 +188,35 @@ public class FlatSplitPaneUI
|
|||||||
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see javax.swing.plaf.basic.BasicSplitPaneUI#startDragging()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void startDragging() {
|
||||||
|
super.startDragging();
|
||||||
|
|
||||||
|
// update dragging status
|
||||||
|
dragging = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see javax.swing.plaf.basic.BasicSplitPaneUI#finishDraggingTo(int)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void finishDraggingTo( int location ) {
|
||||||
|
super.finishDraggingTo( location );
|
||||||
|
|
||||||
|
// update dragging status
|
||||||
|
dragging = false;
|
||||||
|
}
|
||||||
|
|
||||||
//---- class FlatSplitPaneDivider -----------------------------------------
|
//---- class FlatSplitPaneDivider -----------------------------------------
|
||||||
|
|
||||||
protected class FlatSplitPaneDivider
|
protected class FlatSplitPaneDivider
|
||||||
extends BasicSplitPaneDivider
|
extends BasicSplitPaneDivider
|
||||||
{
|
{
|
||||||
|
@Styleable protected Color hoverColor = UIManager.getColor("SplitPaneDivider.hoverColor");
|
||||||
|
@Styleable protected boolean showHover = UIManager.getBoolean("SplitPaneDivider.showHover");
|
||||||
@Styleable protected String style = UIManager.getString( "SplitPaneDivider.style" );
|
@Styleable protected String style = UIManager.getString( "SplitPaneDivider.style" );
|
||||||
@Styleable protected Color gripColor = UIManager.getColor( "SplitPaneDivider.gripColor" );
|
@Styleable protected Color gripColor = UIManager.getColor( "SplitPaneDivider.gripColor" );
|
||||||
@Styleable protected int gripDotCount = FlatUIUtils.getUIInt( "SplitPaneDivider.gripDotCount", 3 );
|
@Styleable protected int gripDotCount = FlatUIUtils.getUIInt( "SplitPaneDivider.gripDotCount", 3 );
|
||||||
@@ -251,6 +280,21 @@ public class FlatSplitPaneUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paint( Graphics g ) {
|
public void paint( Graphics g ) {
|
||||||
|
|
||||||
|
if( showHover && isMouseOver() && !dragging ) {
|
||||||
|
g.setColor( hoverColor );
|
||||||
|
|
||||||
|
// respect basic ui paint code
|
||||||
|
Dimension size = splitPane.getSize();
|
||||||
|
if( orientation == JSplitPane.HORIZONTAL_SPLIT ) {
|
||||||
|
g.fillRect( 0, 0, dividerSize - 1,
|
||||||
|
size.height - 1 );
|
||||||
|
} else {
|
||||||
|
g.fillRect( 0, 0, size.width - 1,
|
||||||
|
dividerSize - 1 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
super.paint( g );
|
super.paint( g );
|
||||||
|
|
||||||
if( "plain".equals( style ) )
|
if( "plain".equals( style ) )
|
||||||
@@ -264,6 +308,17 @@ public class FlatSplitPaneUI
|
|||||||
FlatUIUtils.resetRenderingHints( g, oldRenderingHints );
|
FlatUIUtils.resetRenderingHints( g, oldRenderingHints );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see javax.swing.plaf.basic.BasicSplitPaneDivider#setMouseOver(boolean)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void setMouseOver( boolean mouseOver ) {
|
||||||
|
super.setMouseOver( mouseOver );
|
||||||
|
|
||||||
|
if( showHover )
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
protected void paintGrip( Graphics g, int x, int y, int width, int height ) {
|
protected void paintGrip( Graphics g, int x, int y, int width, int height ) {
|
||||||
FlatUIUtils.paintGrip( g, x, y, width, height,
|
FlatUIUtils.paintGrip( g, x, y, width, height,
|
||||||
splitPane.getOrientation() == JSplitPane.VERTICAL_SPLIT,
|
splitPane.getOrientation() == JSplitPane.VERTICAL_SPLIT,
|
||||||
|
|||||||
@@ -303,6 +303,8 @@ Slider.disabledThumbColor = $Slider.disabledTrackColor
|
|||||||
#---- SplitPane ----
|
#---- SplitPane ----
|
||||||
|
|
||||||
SplitPaneDivider.draggingColor = $Component.borderColor
|
SplitPaneDivider.draggingColor = $Component.borderColor
|
||||||
|
SplitPaneDivider.showHover = false
|
||||||
|
SplitPaneDivider.hoverColor = darken($Component.borderColor,5%,derived)
|
||||||
|
|
||||||
|
|
||||||
#---- TabbedPane ----
|
#---- TabbedPane ----
|
||||||
|
|||||||
@@ -309,6 +309,8 @@ Slider.disabledThumbColor = $Slider.disabledTrackColor
|
|||||||
#---- SplitPane ----
|
#---- SplitPane ----
|
||||||
|
|
||||||
SplitPaneDivider.draggingColor = $Component.borderColor
|
SplitPaneDivider.draggingColor = $Component.borderColor
|
||||||
|
SplitPaneDivider.showHover = false
|
||||||
|
SplitPaneDivider.hoverColor = darken($Component.borderColor,5%,derived)
|
||||||
|
|
||||||
|
|
||||||
#---- TabbedPane ----
|
#---- TabbedPane ----
|
||||||
|
|||||||
@@ -368,6 +368,8 @@ Spinner.focusedBackground = #ff8
|
|||||||
#---- SplitPane ----
|
#---- SplitPane ----
|
||||||
|
|
||||||
SplitPaneDivider.draggingColor = #800
|
SplitPaneDivider.draggingColor = #800
|
||||||
|
SplitPaneDivider.showHover = false
|
||||||
|
SplitPaneDivider.hoverColor = #a00
|
||||||
SplitPaneDivider.oneTouchArrowColor = #0f0
|
SplitPaneDivider.oneTouchArrowColor = #0f0
|
||||||
SplitPaneDivider.oneTouchHoverArrowColor = #f00
|
SplitPaneDivider.oneTouchHoverArrowColor = #f00
|
||||||
SplitPaneDivider.oneTouchPressedArrowColor = #00f
|
SplitPaneDivider.oneTouchPressedArrowColor = #00f
|
||||||
|
|||||||
Reference in New Issue
Block a user