Skip to content

Commit

Permalink
ScrollPane: allow specifying scroll pane border arc for multi-line te…
Browse files Browse the repository at this point in the history
…xt components, lists, tables and trees
  • Loading branch information
DevCharly committed Nov 25, 2023
1 parent 0c604b1 commit b1fdbde
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JViewport;
import javax.swing.UIManager;
import javax.swing.plaf.basic.BasicBorders;
import com.formdev.flatlaf.FlatClientProperties;
Expand Down Expand Up @@ -195,8 +194,7 @@ protected Paint getBorderColor( Component c ) {
protected boolean isEnabled( Component c ) {
if( c instanceof JScrollPane ) {
// check whether view component is disabled
JViewport viewport = ((JScrollPane)c).getViewport();
Component view = (viewport != null) ? viewport.getView() : null;
Component view = FlatScrollPaneUI.getView( (JScrollPane) c );
if( view != null && !isEnabled( view ) )
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,23 @@

import java.awt.Component;
import java.awt.Insets;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.text.JTextComponent;
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
import com.formdev.flatlaf.util.UIScale;

/**
* Border for {@link javax.swing.JScrollPane}.
*
* @uiDefault ScrollPane.arc int
* @uiDefault ScrollPane.List.arc int
* @uiDefault ScrollPane.Table.arc int
* @uiDefault ScrollPane.TextComponent.arc int
* @uiDefault ScrollPane.Tree.arc int
* @author Karl Tauber
* @since 3.3
Expand All @@ -35,6 +44,22 @@ public class FlatScrollPaneBorder
{
@Styleable protected int arc = UIManager.getInt( "ScrollPane.arc" );

private boolean isArcStyled;
private final int listArc = FlatUIUtils.getUIInt( "ScrollPane.List.arc", -1 );
private final int tableArc = FlatUIUtils.getUIInt( "ScrollPane.Table.arc", -1 );
private final int textComponentArc = FlatUIUtils.getUIInt( "ScrollPane.TextComponent.arc", -1 );
private final int treeArc = FlatUIUtils.getUIInt( "ScrollPane.Tree.arc", -1 );

@Override
public Object applyStyleProperty( String key, Object value ) {
Object oldValue = super.applyStyleProperty( key, value );

if( "arc".equals( key ) )
isArcStyled = true;

return oldValue;
}

@Override
public Insets getBorderInsets( Component c, Insets insets ) {
insets = super.getBorderInsets( c, insets );
Expand All @@ -55,6 +80,21 @@ protected int getArc( Component c ) {
if( isCellEditor( c ) )
return 0;

if( isArcStyled )
return arc;

if( c instanceof JScrollPane ) {
Component view = FlatScrollPaneUI.getView( (JScrollPane) c );
if( listArc >= 0 && view instanceof JList )
return listArc;
if( tableArc >= 0 && view instanceof JTable )
return tableArc;
if( textComponentArc >= 0&& view instanceof JTextComponent )
return textComponentArc;
if( treeArc >= 0 && view instanceof JTree )
return treeArc;
}

return arc;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public static boolean isPermanentFocusOwner( JScrollPane scrollPane ) {
return false;
}

private static Component getView( JScrollPane scrollPane ) {
static Component getView( JScrollPane scrollPane ) {
JViewport viewport = scrollPane.getViewport();
return (viewport != null) ? viewport.getView() : null;
}
Expand Down Expand Up @@ -537,13 +537,15 @@ public void componentRemoved( ContainerEvent e ) {
@Override
public void focusGained( FocusEvent e ) {
// necessary to update focus border
scrollpane.repaint();
if( scrollpane.getBorder() instanceof FlatBorder )
scrollpane.repaint();
}

@Override
public void focusLost( FocusEvent e ) {
// necessary to update focus border
scrollpane.repaint();
if( scrollpane.getBorder() instanceof FlatBorder )
scrollpane.repaint();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,10 @@ ScrollPane.background = $ScrollBar.track
ScrollPane.fillUpperCorner = true
ScrollPane.smoothScrolling = true
ScrollPane.arc = 0
#ScrollPane.List.arc = -1
#ScrollPane.Table.arc = -1
#ScrollPane.TextComponent.arc = -1
#ScrollPane.Tree.arc = -1


#---- SearchField ----
Expand Down
4 changes: 2 additions & 2 deletions flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ ScrollBarUI com.formdev.flatlaf.ui.FlatScrollBarUI

ScrollPane.arc 20
ScrollPane.background #88ff88 HSL 120 100 77 javax.swing.plaf.ColorUIResource [UI]
ScrollPane.border [lazy] 1,10,1,10 false com.formdev.flatlaf.ui.FlatScrollPaneBorder [UI]
ScrollPane.border [lazy] 1,9,1,9 false com.formdev.flatlaf.ui.FlatScrollPaneBorder [UI]
ScrollPane.fillUpperCorner true
ScrollPane.font [active] $defaultFont [UI]
ScrollPane.foreground #ff0000 HSL 0 100 50 javax.swing.plaf.ColorUIResource [UI]
Expand Down Expand Up @@ -1155,7 +1155,7 @@ Table.foreground #ff0000 HSL 0 100 50 javax.swing.plaf.Colo
Table.gridColor #00ffff HSL 180 100 50 javax.swing.plaf.ColorUIResource [UI]
Table.intercellSpacing 0,0 javax.swing.plaf.DimensionUIResource [UI]
Table.rowHeight 25
Table.scrollPaneBorder [lazy] 1,10,1,10 false com.formdev.flatlaf.ui.FlatScrollPaneBorder [UI]
Table.scrollPaneBorder [lazy] 1,9,1,9 false com.formdev.flatlaf.ui.FlatScrollPaneBorder [UI]
Table.selectionBackground #00aa00 HSL 120 100 33 javax.swing.plaf.ColorUIResource [UI]
Table.selectionForeground #ffff00 HSL 60 100 50 javax.swing.plaf.ColorUIResource [UI]
Table.selectionInactiveBackground #888888 HSL 0 0 53 javax.swing.plaf.ColorUIResource [UI]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,10 @@ ScrollBar.trackHighlight
ScrollBar.trackInsets
ScrollBar.width
ScrollBarUI
ScrollPane.List.arc
ScrollPane.Table.arc
ScrollPane.TextComponent.arc
ScrollPane.Tree.arc
ScrollPane.ancestorInputMap
ScrollPane.ancestorInputMap.RightToLeft
ScrollPane.arc
Expand Down

0 comments on commit b1fdbde

Please sign in to comment.