mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
Improved subclassing:
- reviewed all private methods and made them protected/public where it might be useful for subclasses - ComboBox and Spinner: added protected getBackground() and getForeground() methods to allow subclasses to change colors - TabbedPane: moved tab separator painting to own method (issue #113)
This commit is contained in:
@@ -67,14 +67,14 @@ public class FlatCheckBoxMenuItemIcon
|
||||
g2.draw( path );
|
||||
}
|
||||
|
||||
private Color getCheckmarkColor( Component c ) {
|
||||
protected Color getCheckmarkColor( Component c ) {
|
||||
if( c instanceof JMenuItem && ((JMenuItem)c).isArmed() && !isUnderlineSelection() )
|
||||
return selectionForeground;
|
||||
|
||||
return c.isEnabled() ? checkmarkColor : disabledCheckmarkColor;
|
||||
}
|
||||
|
||||
private boolean isUnderlineSelection() {
|
||||
protected boolean isUnderlineSelection() {
|
||||
// not storing value of "MenuItem.selectionType" in class to allow changing at runtime
|
||||
return "underline".equals( UIManager.getString( "MenuItem.selectionType" ) );
|
||||
}
|
||||
|
||||
@@ -65,14 +65,14 @@ public class FlatMenuArrowIcon
|
||||
}
|
||||
}
|
||||
|
||||
private Color getArrowColor( Component c ) {
|
||||
protected Color getArrowColor( Component c ) {
|
||||
if( c instanceof JMenu && ((JMenu)c).isSelected() && !isUnderlineSelection() )
|
||||
return selectionForeground;
|
||||
|
||||
return c.isEnabled() ? arrowColor : disabledArrowColor;
|
||||
}
|
||||
|
||||
private boolean isUnderlineSelection() {
|
||||
protected boolean isUnderlineSelection() {
|
||||
// not storing value of "MenuItem.selectionType" in class to allow changing at runtime
|
||||
return "underline".equals( UIManager.getString( "MenuItem.selectionType" ) );
|
||||
}
|
||||
|
||||
@@ -317,12 +317,11 @@ public class FlatComboBoxUI
|
||||
// use non-UIResource colors because when SwingUtilities.updateComponentTreeUI()
|
||||
// is used, then the editor is updated after the combobox and the
|
||||
// colors are again replaced with default colors
|
||||
boolean enabled = editor.isEnabled();
|
||||
editor.setForeground( FlatUIUtils.nonUIResource( (enabled || editor instanceof JTextComponent)
|
||||
? comboBox.getForeground()
|
||||
: disabledForeground ) );
|
||||
if( editor instanceof JTextComponent )
|
||||
((JTextComponent)editor).setDisabledTextColor( FlatUIUtils.nonUIResource( disabledForeground ) );
|
||||
boolean isTextComponent = editor instanceof JTextComponent;
|
||||
editor.setForeground( FlatUIUtils.nonUIResource( getForeground( isTextComponent || editor.isEnabled() ) ) );
|
||||
|
||||
if( isTextComponent )
|
||||
((JTextComponent)editor).setDisabledTextColor( FlatUIUtils.nonUIResource( getForeground( false ) ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -358,9 +357,7 @@ public class FlatComboBoxUI
|
||||
boolean isLeftToRight = comboBox.getComponentOrientation().isLeftToRight();
|
||||
|
||||
// paint background
|
||||
g2.setColor( enabled
|
||||
? (editableBackground != null && comboBox.isEditable() ? editableBackground : c.getBackground())
|
||||
: getDisabledBackground( comboBox ) );
|
||||
g2.setColor( getBackground( enabled ) );
|
||||
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
|
||||
|
||||
// paint arrow button background
|
||||
@@ -399,8 +396,8 @@ public class FlatComboBoxUI
|
||||
uninstallCellPaddingBorder( c );
|
||||
|
||||
boolean enabled = comboBox.isEnabled();
|
||||
c.setForeground( enabled ? comboBox.getForeground() : disabledForeground );
|
||||
c.setBackground( enabled ? comboBox.getBackground() : getDisabledBackground( comboBox ) );
|
||||
c.setBackground( getBackground( enabled ) );
|
||||
c.setForeground( getForeground( enabled ) );
|
||||
|
||||
boolean shouldValidate = (c instanceof JPanel);
|
||||
if( padding != null )
|
||||
@@ -420,8 +417,14 @@ public class FlatComboBoxUI
|
||||
// not necessary because already painted in update()
|
||||
}
|
||||
|
||||
private Color getDisabledBackground( JComponent c ) {
|
||||
return isIntelliJTheme ? FlatUIUtils.getParentBackground( c ) : disabledBackground;
|
||||
protected Color getBackground( boolean enabled ) {
|
||||
return enabled
|
||||
? (editableBackground != null && comboBox.isEditable() ? editableBackground : comboBox.getBackground())
|
||||
: (isIntelliJTheme ? FlatUIUtils.getParentBackground( comboBox ) : disabledBackground);
|
||||
}
|
||||
|
||||
protected Color getForeground( boolean enabled ) {
|
||||
return enabled ? comboBox.getForeground() : disabledForeground;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -371,7 +371,7 @@ debug*/
|
||||
return menuItem instanceof JMenu && ((JMenu)menuItem).isTopLevelMenu();
|
||||
}
|
||||
|
||||
private boolean isUnderlineSelection() {
|
||||
protected boolean isUnderlineSelection() {
|
||||
return "underline".equals( UIManager.getString( "MenuItem.selectionType" ) );
|
||||
}
|
||||
|
||||
@@ -416,6 +416,13 @@ debug*/
|
||||
if( accelerator == cachedAccelerator )
|
||||
return cachedAcceleratorText;
|
||||
|
||||
cachedAccelerator = accelerator;
|
||||
cachedAcceleratorText = getTextForAccelerator( accelerator );
|
||||
|
||||
return cachedAcceleratorText;
|
||||
}
|
||||
|
||||
protected String getTextForAccelerator( KeyStroke accelerator ) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
int modifiers = accelerator.getModifiers();
|
||||
if( modifiers != 0 )
|
||||
@@ -427,10 +434,7 @@ debug*/
|
||||
else
|
||||
buf.append( accelerator.getKeyChar() );
|
||||
|
||||
cachedAccelerator = accelerator;
|
||||
cachedAcceleratorText = buf.toString();
|
||||
|
||||
return cachedAcceleratorText;
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
//---- class MinSizeIcon --------------------------------------------------
|
||||
|
||||
@@ -240,7 +240,7 @@ public class FlatScrollBarUI
|
||||
return button;
|
||||
}
|
||||
|
||||
private boolean isShowButtons() {
|
||||
protected boolean isShowButtons() {
|
||||
Object showButtons = scrollbar.getClientProperty( FlatClientProperties.SCROLL_BAR_SHOW_BUTTONS );
|
||||
if( showButtons == null && scrollbar.getParent() instanceof JScrollPane )
|
||||
showButtons = ((JScrollPane)scrollbar.getParent()).getClientProperty( FlatClientProperties.SCROLL_BAR_SHOW_BUTTONS );
|
||||
|
||||
@@ -206,8 +206,8 @@ public class FlatSpinnerUI
|
||||
// use non-UIResource colors because when SwingUtilities.updateComponentTreeUI()
|
||||
// is used, then the text field is updated after the spinner and the
|
||||
// colors are again replaced with default colors
|
||||
textField.setForeground( FlatUIUtils.nonUIResource( spinner.getForeground() ) );
|
||||
textField.setDisabledTextColor( FlatUIUtils.nonUIResource( disabledForeground ) );
|
||||
textField.setForeground( FlatUIUtils.nonUIResource( getForeground( true ) ) );
|
||||
textField.setDisabledTextColor( FlatUIUtils.nonUIResource( getForeground( false ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,6 +217,16 @@ public class FlatSpinnerUI
|
||||
: null;
|
||||
}
|
||||
|
||||
protected Color getBackground( boolean enabled ) {
|
||||
return enabled
|
||||
? spinner.getBackground()
|
||||
: (isIntelliJTheme ? FlatUIUtils.getParentBackground( spinner ) : disabledBackground);
|
||||
}
|
||||
|
||||
protected Color getForeground( boolean enabled ) {
|
||||
return enabled ? spinner.getForeground() : disabledForeground;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LayoutManager createLayout() {
|
||||
return getHandler();
|
||||
@@ -266,9 +276,7 @@ public class FlatSpinnerUI
|
||||
boolean isLeftToRight = spinner.getComponentOrientation().isLeftToRight();
|
||||
|
||||
// paint background
|
||||
g2.setColor( enabled
|
||||
? c.getBackground()
|
||||
: (isIntelliJTheme ? FlatUIUtils.getParentBackground( c ) : disabledBackground) );
|
||||
g2.setColor( getBackground( enabled ) );
|
||||
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
|
||||
|
||||
// paint arrow buttons background
|
||||
|
||||
@@ -333,7 +333,13 @@ public class FlatTabbedPaneUI
|
||||
// paint tab separators
|
||||
if( clientPropertyBoolean( tabPane, TABBED_PANE_SHOW_TAB_SEPARATORS, showTabSeparators ) &&
|
||||
!isLastInRun( tabIndex ) )
|
||||
{
|
||||
paintTabSeparator( g, tabPlacement, x, y, w, h );
|
||||
|
||||
if( isSelected )
|
||||
paintTabSelection( g, tabPlacement, x, y, w, h );
|
||||
}
|
||||
|
||||
protected void paintTabSeparator( Graphics g, int tabPlacement, int x, int y, int w, int h ) {
|
||||
float sepWidth = UIScale.scale( 1f );
|
||||
float offset = tabSeparatorsFullHeight ? 0 : UIScale.scale( 5f );
|
||||
|
||||
@@ -350,10 +356,6 @@ public class FlatTabbedPaneUI
|
||||
}
|
||||
}
|
||||
|
||||
if( isSelected )
|
||||
paintTabSelection( g, tabPlacement, x, y, w, h );
|
||||
}
|
||||
|
||||
protected void paintTabSelection( Graphics g, int tabPlacement, int x, int y, int w, int h ) {
|
||||
// increase clip bounds in scroll-tab-layout to paint over the separator line
|
||||
Rectangle clipBounds = isScrollTabLayout() ? g.getClipBounds() : null;
|
||||
|
||||
@@ -86,7 +86,7 @@ public class FlatTableCellBorder
|
||||
/**
|
||||
* Checks whether at least one selected cell is editable.
|
||||
*/
|
||||
private boolean isSelectionEditable( JTable table ) {
|
||||
protected boolean isSelectionEditable( JTable table ) {
|
||||
if( table.getRowSelectionAllowed() ) {
|
||||
int columnCount = table.getColumnCount();
|
||||
int[] selectedRows = table.getSelectedRows();
|
||||
|
||||
@@ -35,7 +35,7 @@ public class ColorFunctions
|
||||
return HSLColor.toRGB( hsl, alpha );
|
||||
}
|
||||
|
||||
private static float clamp( float value ) {
|
||||
public static float clamp( float value ) {
|
||||
return (value < 0)
|
||||
? 0
|
||||
: ((value > 100)
|
||||
|
||||
@@ -68,7 +68,7 @@ public class SystemInfo
|
||||
IS_KDE = (IS_LINUX && System.getenv( "KDE_FULL_SESSION" ) != null);
|
||||
}
|
||||
|
||||
private static long scanVersion( String version ) {
|
||||
public static long scanVersion( String version ) {
|
||||
int major = 1;
|
||||
int minor = 0;
|
||||
int micro = 0;
|
||||
@@ -86,7 +86,7 @@ public class SystemInfo
|
||||
return toVersion( major, minor, micro, patch );
|
||||
}
|
||||
|
||||
private static long toVersion( int major, int minor, int micro, int patch ) {
|
||||
public static long toVersion( int major, int minor, int micro, int patch ) {
|
||||
return ((long) major << 48) + ((long) minor << 32) + ((long) micro << 16) + patch;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user