mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 23:07:15 -06:00
Merge remote-tracking branch 'origin/main' into styling
# Conflicts: # flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java # flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java
This commit is contained in:
@@ -48,6 +48,7 @@ import com.formdev.flatlaf.util.DerivedColor;
|
||||
*
|
||||
* @uiDefault Component.focusWidth int
|
||||
* @uiDefault Component.innerFocusWidth int or float
|
||||
* @uiDefault Component.innerOutlineWidth int or float
|
||||
* @uiDefault Component.focusColor Color
|
||||
* @uiDefault Component.borderColor Color
|
||||
* @uiDefault Component.disabledBorderColor Color
|
||||
|
||||
@@ -27,6 +27,7 @@ import javax.swing.JComponent;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicListUI;
|
||||
import com.formdev.flatlaf.FlatClientProperties;
|
||||
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
|
||||
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
||||
|
||||
@@ -140,8 +141,22 @@ public class FlatListUI
|
||||
|
||||
@Override
|
||||
protected PropertyChangeListener createPropertyChangeListener() {
|
||||
return FlatStylingSupport.createPropertyChangeListener( list, this::applyStyle,
|
||||
super.createPropertyChangeListener() );
|
||||
PropertyChangeListener superListener = super.createPropertyChangeListener();
|
||||
return e -> {
|
||||
superListener.propertyChange( e );
|
||||
|
||||
switch( e.getPropertyName() ) {
|
||||
case FlatClientProperties.COMPONENT_FOCUS_OWNER:
|
||||
toggleSelectionColors();
|
||||
break;
|
||||
|
||||
case FlatClientProperties.STYLE:
|
||||
applyStyle( e.getNewValue() );
|
||||
list.revalidate();
|
||||
list.repaint();
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.awt.GridBagConstraints;
|
||||
import java.awt.Insets;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
@@ -162,8 +163,15 @@ public class FlatOptionPaneUI
|
||||
cons.insets.bottom = UIScale.scale( messagePadding );
|
||||
|
||||
// disable line wrapping for HTML
|
||||
if( msg instanceof String && BasicHTML.isHTMLString( (String) msg ) )
|
||||
maxll = Integer.MAX_VALUE;
|
||||
if( msg != null &&
|
||||
!(msg instanceof Component) &&
|
||||
!(msg instanceof Object[]) &&
|
||||
!(msg instanceof Icon) )
|
||||
{
|
||||
msg = msg.toString();
|
||||
if( BasicHTML.isHTMLString( (String) msg ) )
|
||||
maxll = Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
// fix right-to-left alignment if super.addMessageComponents() breaks longer lines
|
||||
// into multiple labels and puts them into a box that aligns them to the left
|
||||
|
||||
@@ -24,8 +24,8 @@ import javax.swing.plaf.ComponentUI;
|
||||
*
|
||||
* <!-- BasicSeparatorUI -->
|
||||
*
|
||||
* @uiDefault PopupMenuSeparator.background Color unused
|
||||
* @uiDefault PopupMenuSeparator.foreground Color
|
||||
* @uiDefault Separator.background Color unused
|
||||
* @uiDefault Separator.foreground Color
|
||||
*
|
||||
* <!-- FlatSeparatorUI -->
|
||||
*
|
||||
|
||||
@@ -45,6 +45,7 @@ public class FlatTableHeaderBorder
|
||||
{
|
||||
protected Color separatorColor = UIManager.getColor( "TableHeader.separatorColor" );
|
||||
protected Color bottomSeparatorColor = UIManager.getColor( "TableHeader.bottomSeparatorColor" );
|
||||
protected boolean showLastVerticalLine = UIManager.getBoolean( "TableHeader.showLastVerticalLine" );
|
||||
|
||||
public FlatTableHeaderBorder() {
|
||||
super( UIManager.getInsets( "TableHeader.cellMargins" ) );
|
||||
@@ -137,6 +138,9 @@ public class FlatTableHeaderBorder
|
||||
}
|
||||
|
||||
protected boolean hideTrailingVerticalLine( JTableHeader header ) {
|
||||
if( showLastVerticalLine )
|
||||
return false;
|
||||
|
||||
Container viewport = header.getParent();
|
||||
Container viewportParent = (viewport != null) ? viewport.getParent() : null;
|
||||
if( !(viewportParent instanceof JScrollPane) )
|
||||
|
||||
@@ -18,10 +18,13 @@ package com.formdev.flatlaf.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.Map;
|
||||
@@ -32,6 +35,7 @@ import javax.swing.JTable;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.event.MouseInputListener;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.UIResource;
|
||||
import javax.swing.plaf.basic.BasicTableHeaderUI;
|
||||
@@ -62,6 +66,7 @@ import com.formdev.flatlaf.util.UIScale;
|
||||
* @uiDefault TableHeader.cellMargins Insets
|
||||
* @uiDefault TableHeader.separatorColor Color
|
||||
* @uiDefault TableHeader.bottomSeparatorColor Color
|
||||
* @uiDefault TableHeader.showLastVerticalLine boolean
|
||||
*
|
||||
* <!-- FlatAscendingSortIcon and FlatDescendingSortIcon -->
|
||||
*
|
||||
@@ -173,6 +178,11 @@ public class FlatTableHeaderUI
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MouseInputListener createMouseInputListener() {
|
||||
return new FlatMouseInputHandler();
|
||||
}
|
||||
|
||||
// overridden and made public to allow usage in custom renderers
|
||||
@Override
|
||||
public int getRolloverColumn() {
|
||||
@@ -331,4 +341,54 @@ public class FlatTableHeaderUI
|
||||
return (origBorder != null) ? origBorder.isBorderOpaque() : false;
|
||||
}
|
||||
}
|
||||
|
||||
//---- class FlatMouseInputHandler ----------------------------------------
|
||||
|
||||
/**
|
||||
* @since 1.6
|
||||
*/
|
||||
protected class FlatMouseInputHandler
|
||||
extends MouseInputHandler
|
||||
{
|
||||
Cursor oldCursor;
|
||||
|
||||
@Override
|
||||
public void mouseMoved( MouseEvent e ) {
|
||||
// restore old cursor, which is necessary because super.mouseMoved() swaps cursors
|
||||
if( oldCursor != null ) {
|
||||
header.setCursor( oldCursor );
|
||||
oldCursor = null;
|
||||
}
|
||||
|
||||
super.mouseMoved( e );
|
||||
|
||||
// if resizing last column is not possible, then Swing still shows a resize cursor,
|
||||
// which can be confusing for the user --> change cursor to standard cursor
|
||||
JTable table;
|
||||
int column;
|
||||
if( header.isEnabled() &&
|
||||
(table = header.getTable()) != null &&
|
||||
table.getAutoResizeMode() != JTable.AUTO_RESIZE_OFF &&
|
||||
header.getCursor() == Cursor.getPredefinedCursor( Cursor.E_RESIZE_CURSOR ) &&
|
||||
(column = header.columnAtPoint( e.getPoint() )) >= 0 &&
|
||||
column == header.getColumnModel().getColumnCount() - 1 )
|
||||
{
|
||||
// mouse is in last column
|
||||
Rectangle r = header.getHeaderRect( column );
|
||||
r.grow( -3, 0 );
|
||||
if( !r.contains( e.getX(), e.getY() ) ) {
|
||||
// mouse is in left or right resize area of last column
|
||||
boolean isResizeLastColumn = (e.getX() >= r.x + (r.width / 2));
|
||||
if( !header.getComponentOrientation().isLeftToRight() )
|
||||
isResizeLastColumn = !isResizeLastColumn;
|
||||
|
||||
if( isResizeLastColumn ) {
|
||||
// resize is not possible --> change cursor to standard cursor
|
||||
oldCursor = header.getCursor();
|
||||
header.setCursor( Cursor.getDefaultCursor() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ import com.formdev.flatlaf.util.UIScale;
|
||||
* @uiDefault Table.rowHeight int
|
||||
* @uiDefault Table.showHorizontalLines boolean
|
||||
* @uiDefault Table.showVerticalLines boolean
|
||||
* @uiDefault Table.showLastVerticalLine boolean
|
||||
* @uiDefault Table.intercellSpacing Dimension
|
||||
* @uiDefault Table.selectionInactiveBackground Color
|
||||
* @uiDefault Table.selectionInactiveForeground Color
|
||||
@@ -97,6 +98,7 @@ public class FlatTableUI
|
||||
{
|
||||
protected boolean showHorizontalLines;
|
||||
protected boolean showVerticalLines;
|
||||
protected boolean showLastVerticalLine;
|
||||
protected Dimension intercellSpacing;
|
||||
|
||||
@Styleable protected Color selectionBackground;
|
||||
@@ -133,6 +135,7 @@ public class FlatTableUI
|
||||
|
||||
showHorizontalLines = UIManager.getBoolean( "Table.showHorizontalLines" );
|
||||
showVerticalLines = UIManager.getBoolean( "Table.showVerticalLines" );
|
||||
showLastVerticalLine = UIManager.getBoolean( "Table.showLastVerticalLine" );
|
||||
intercellSpacing = UIManager.getDimension( "Table.intercellSpacing" );
|
||||
|
||||
selectionBackground = UIManager.getColor( "Table.selectionBackground" );
|
||||
@@ -187,15 +190,27 @@ public class FlatTableUI
|
||||
protected void installListeners() {
|
||||
super.installListeners();
|
||||
|
||||
propertyChangeListener = FlatStylingSupport.createPropertyChangeListener( table, this::applyStyle, null );
|
||||
table.addPropertyChangeListener( FlatClientProperties.STYLE, propertyChangeListener );
|
||||
propertyChangeListener = e -> {
|
||||
switch( e.getPropertyName() ) {
|
||||
case FlatClientProperties.COMPONENT_FOCUS_OWNER:
|
||||
toggleSelectionColors();
|
||||
break;
|
||||
|
||||
case FlatClientProperties.STYLE:
|
||||
applyStyle( e.getNewValue() );
|
||||
table.revalidate();
|
||||
table.repaint();
|
||||
break;
|
||||
}
|
||||
};
|
||||
table.addPropertyChangeListener( propertyChangeListener );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void uninstallListeners() {
|
||||
super.uninstallListeners();
|
||||
|
||||
table.removePropertyChangeListener( FlatClientProperties.STYLE, propertyChangeListener );
|
||||
table.removePropertyChangeListener( propertyChangeListener );
|
||||
propertyChangeListener = null;
|
||||
}
|
||||
|
||||
@@ -377,6 +392,9 @@ public class FlatTableUI
|
||||
}
|
||||
|
||||
protected boolean hideLastVerticalLine() {
|
||||
if( showLastVerticalLine )
|
||||
return false;
|
||||
|
||||
Container viewport = SwingUtilities.getUnwrappedParent( table );
|
||||
Container viewportParent = (viewport != null) ? viewport.getParent() : null;
|
||||
if( !(viewportParent instanceof JScrollPane) )
|
||||
|
||||
@@ -342,12 +342,13 @@ public class FlatTextFieldUI
|
||||
// compute placeholder location
|
||||
Rectangle r = getVisibleEditorRect();
|
||||
FontMetrics fm = c.getFontMetrics( c.getFont() );
|
||||
String clippedPlaceholder = JavaCompatibility.getClippedString( c, fm, (String) placeholder, r.width );
|
||||
int x = r.x + (c.getComponentOrientation().isLeftToRight() ? 0 : r.width - fm.stringWidth( clippedPlaceholder ));
|
||||
int y = r.y + fm.getAscent() + ((r.height - fm.getHeight()) / 2);
|
||||
|
||||
// paint placeholder
|
||||
g.setColor( placeholderForeground );
|
||||
String clippedPlaceholder = JavaCompatibility.getClippedString( c, fm, (String) placeholder, r.width );
|
||||
FlatUIUtils.drawString( c, g, clippedPlaceholder, r.x, y );
|
||||
FlatUIUtils.drawString( c, g, clippedPlaceholder, x, y );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -628,6 +628,7 @@ TabbedPane.closeCrossLineWidth = {float}1
|
||||
Table.rowHeight = 20
|
||||
Table.showHorizontalLines = false
|
||||
Table.showVerticalLines = false
|
||||
Table.showLastVerticalLine = false
|
||||
Table.consistentHomeEndKeyBehavior = true
|
||||
Table.intercellSpacing = {dimension}0,0
|
||||
Table.scrollPaneBorder = com.formdev.flatlaf.ui.FlatBorder
|
||||
@@ -657,7 +658,7 @@ TableHeader.cellBorder = com.formdev.flatlaf.ui.FlatTableHeaderBorder
|
||||
TableHeader.cellMargins = 2,3,2,3
|
||||
TableHeader.focusCellBackground = $TableHeader.background
|
||||
TableHeader.background = @textComponentBackground
|
||||
|
||||
TableHeader.showLastVerticalLine = false
|
||||
|
||||
#---- TextArea ----
|
||||
|
||||
|
||||
Reference in New Issue
Block a user