mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 23:07:15 -06:00
Styling: support ScrollPane
This commit is contained in:
@@ -29,6 +29,8 @@ import java.awt.event.MouseWheelEvent;
|
|||||||
import java.awt.event.MouseWheelListener;
|
import java.awt.event.MouseWheelListener;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
@@ -69,6 +71,9 @@ public class FlatScrollPaneUI
|
|||||||
{
|
{
|
||||||
private Handler handler;
|
private Handler handler;
|
||||||
|
|
||||||
|
private Map<String, Object> oldStyleValues;
|
||||||
|
private AtomicBoolean borderShared;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatScrollPaneUI();
|
return new FlatScrollPaneUI();
|
||||||
}
|
}
|
||||||
@@ -80,6 +85,8 @@ public class FlatScrollPaneUI
|
|||||||
int focusWidth = UIManager.getInt( "Component.focusWidth" );
|
int focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||||
LookAndFeel.installProperty( c, "opaque", focusWidth == 0 );
|
LookAndFeel.installProperty( c, "opaque", focusWidth == 0 );
|
||||||
|
|
||||||
|
applyStyle( FlatStyleSupport.getStyle( c ) );
|
||||||
|
|
||||||
MigLayoutVisualPadding.install( scrollpane );
|
MigLayoutVisualPadding.install( scrollpane );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +95,9 @@ public class FlatScrollPaneUI
|
|||||||
MigLayoutVisualPadding.uninstall( scrollpane );
|
MigLayoutVisualPadding.uninstall( scrollpane );
|
||||||
|
|
||||||
super.uninstallUI( c );
|
super.uninstallUI( c );
|
||||||
|
|
||||||
|
oldStyleValues = null;
|
||||||
|
borderShared = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -272,7 +282,13 @@ public class FlatScrollPaneUI
|
|||||||
((JButton)corner).setBorder( BorderFactory.createEmptyBorder() );
|
((JButton)corner).setBorder( BorderFactory.createEmptyBorder() );
|
||||||
((JButton)corner).setFocusable( false );
|
((JButton)corner).setFocusable( false );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case FlatClientProperties.STYLE:
|
||||||
|
applyStyle( e.getNewValue() );
|
||||||
|
scrollpane.revalidate();
|
||||||
|
scrollpane.repaint();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -283,6 +299,27 @@ public class FlatScrollPaneUI
|
|||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
protected void applyStyle( Object style ) {
|
||||||
|
oldStyleValues = FlatStyleSupport.parseAndApply( oldStyleValues, style, this::applyStyleProperty );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
protected Object applyStyleProperty( String key, Object value ) {
|
||||||
|
if( key.equals( "focusWidth" ) ) {
|
||||||
|
int focusWidth = (value instanceof Integer) ? (int) value : UIManager.getInt( "Component.focusWidth" );
|
||||||
|
LookAndFeel.installProperty( scrollpane, "opaque", focusWidth == 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( borderShared == null )
|
||||||
|
borderShared = new AtomicBoolean( true );
|
||||||
|
return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, scrollpane, borderShared );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateViewport( PropertyChangeEvent e ) {
|
protected void updateViewport( PropertyChangeEvent e ) {
|
||||||
super.updateViewport( e );
|
super.updateViewport( e );
|
||||||
|
|||||||
@@ -430,6 +430,18 @@ public class FlatStylingTests
|
|||||||
ui.applyStyle( "pressedButtonBackground: #fff" );
|
ui.applyStyle( "pressedButtonBackground: #fff" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void scrollPane() {
|
||||||
|
FlatScrollPaneUI ui = new FlatScrollPaneUI();
|
||||||
|
|
||||||
|
// create border
|
||||||
|
UIManager.put( "ScrollPane.border", new FlatBorder() );
|
||||||
|
ui.installUI( new JScrollPane() );
|
||||||
|
|
||||||
|
// border
|
||||||
|
flatBorder( style -> ui.applyStyle( style ) );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void separator() {
|
void separator() {
|
||||||
FlatSeparatorUI ui = new FlatSeparatorUI( false );
|
FlatSeparatorUI ui = new FlatSeparatorUI( false );
|
||||||
|
|||||||
Reference in New Issue
Block a user