mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 15:07:11 -06:00
FlatTestFrame: reduced duplicate code
This commit is contained in:
@@ -22,8 +22,7 @@ import java.awt.event.ComponentEvent;
|
|||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.util.function.BiConsumer;
|
||||||
import java.beans.PropertyChangeListener;
|
|
||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.plaf.ColorUIResource;
|
import javax.swing.plaf.ColorUIResource;
|
||||||
@@ -290,7 +289,15 @@ public class FlatTestFrame
|
|||||||
boolean explicit = explicitColorsCheckBox.isSelected();
|
boolean explicit = explicitColorsCheckBox.isSelected();
|
||||||
ColorUIResource restoreColor = new ColorUIResource( Color.white );
|
ColorUIResource restoreColor = new ColorUIResource( Color.white );
|
||||||
|
|
||||||
explicitColors( content, explicit, restoreColor );
|
updateComponentsRecur( content, (c, type) -> {
|
||||||
|
if( type == "view" || type == "tab" ) {
|
||||||
|
c.setForeground( explicit ? Color.magenta : restoreColor );
|
||||||
|
c.setBackground( explicit ? Color.orange : restoreColor );
|
||||||
|
} else {
|
||||||
|
c.setForeground( explicit ? Color.blue : restoreColor );
|
||||||
|
c.setBackground( explicit ? Color.red : restoreColor );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
// because colors may depend on state (e.g. disabled JTextField)
|
// because colors may depend on state (e.g. disabled JTextField)
|
||||||
// it is best to update all UI delegates to get correct result
|
// it is best to update all UI delegates to get correct result
|
||||||
@@ -299,40 +306,6 @@ public class FlatTestFrame
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void explicitColors( Container container, boolean explicit, ColorUIResource restoreColor ) {
|
|
||||||
for( Component c : container.getComponents() ) {
|
|
||||||
if( c instanceof JPanel ) {
|
|
||||||
explicitColors( (JPanel) c, explicit, restoreColor );
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
c.setForeground( explicit ? Color.blue : restoreColor );
|
|
||||||
c.setBackground( explicit ? Color.red : restoreColor );
|
|
||||||
|
|
||||||
if( c instanceof JScrollPane ) {
|
|
||||||
Component view = ((JScrollPane)c).getViewport().getView();
|
|
||||||
if( view != null ) {
|
|
||||||
view.setForeground( explicit ? Color.magenta : restoreColor );
|
|
||||||
view.setBackground( explicit ? Color.orange : restoreColor );
|
|
||||||
}
|
|
||||||
} else if( c instanceof JTabbedPane ) {
|
|
||||||
JTabbedPane tabPane = (JTabbedPane)c;
|
|
||||||
int tabCount = tabPane.getTabCount();
|
|
||||||
for( int i = 0; i < tabCount; i++ ) {
|
|
||||||
Component tab = tabPane.getComponentAt( i );
|
|
||||||
if( tab != null ) {
|
|
||||||
tab.setForeground( explicit ? Color.magenta : restoreColor );
|
|
||||||
tab.setBackground( explicit ? Color.orange : restoreColor );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( c instanceof JToolBar )
|
|
||||||
explicitColors( (JToolBar) c, explicit, restoreColor );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void rightToLeftChanged() {
|
private void rightToLeftChanged() {
|
||||||
contentPanel.applyComponentOrientation( rightToLeftCheckBox.isSelected()
|
contentPanel.applyComponentOrientation( rightToLeftCheckBox.isSelected()
|
||||||
? ComponentOrientation.RIGHT_TO_LEFT
|
? ComponentOrientation.RIGHT_TO_LEFT
|
||||||
@@ -342,35 +315,10 @@ public class FlatTestFrame
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void enabledChanged() {
|
private void enabledChanged() {
|
||||||
enabledDisable( content, enabledCheckBox.isSelected() );
|
boolean enabled = enabledCheckBox.isSelected();
|
||||||
}
|
updateComponentsRecur( content, (c, type) -> {
|
||||||
|
|
||||||
private void enabledDisable( Container container, boolean enabled ) {
|
|
||||||
for( Component c : container.getComponents() ) {
|
|
||||||
if( c instanceof JPanel ) {
|
|
||||||
enabledDisable( (JPanel) c, enabled );
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
c.setEnabled( enabled );
|
c.setEnabled( enabled );
|
||||||
|
} );
|
||||||
if( c instanceof JScrollPane ) {
|
|
||||||
Component view = ((JScrollPane)c).getViewport().getView();
|
|
||||||
if( view != null )
|
|
||||||
view.setEnabled( enabled );
|
|
||||||
} else if( c instanceof JTabbedPane ) {
|
|
||||||
JTabbedPane tabPane = (JTabbedPane)c;
|
|
||||||
int tabCount = tabPane.getTabCount();
|
|
||||||
for( int i = 0; i < tabCount; i++ ) {
|
|
||||||
Component tab = tabPane.getComponentAt( i );
|
|
||||||
if( tab != null )
|
|
||||||
tab.setEnabled( enabled );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( c instanceof JToolBar )
|
|
||||||
enabledDisable( (JToolBar) c, enabled );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void inspectChanged() {
|
private void inspectChanged() {
|
||||||
@@ -404,6 +352,34 @@ public class FlatTestFrame
|
|||||||
scaleFactorComboBox.setEnabled( !UIScale.isSystemScalingEnabled() && UIManager.getLookAndFeel() instanceof FlatLaf );
|
scaleFactorComboBox.setEnabled( !UIScale.isSystemScalingEnabled() && UIManager.getLookAndFeel() instanceof FlatLaf );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateComponentsRecur( Container container, BiConsumer<Component, String> action ) {
|
||||||
|
for( Component c : container.getComponents() ) {
|
||||||
|
if( c instanceof JPanel ) {
|
||||||
|
updateComponentsRecur( (JPanel) c, action );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
action.accept( c, null );
|
||||||
|
|
||||||
|
if( c instanceof JScrollPane ) {
|
||||||
|
Component view = ((JScrollPane)c).getViewport().getView();
|
||||||
|
if( view != null )
|
||||||
|
action.accept( view, "view" );
|
||||||
|
} else if( c instanceof JTabbedPane ) {
|
||||||
|
JTabbedPane tabPane = (JTabbedPane)c;
|
||||||
|
int tabCount = tabPane.getTabCount();
|
||||||
|
for( int i = 0; i < tabCount; i++ ) {
|
||||||
|
Component tab = tabPane.getComponentAt( i );
|
||||||
|
if( tab != null )
|
||||||
|
action.accept( tab, "tab" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( c instanceof JToolBar )
|
||||||
|
updateComponentsRecur( (JToolBar) c, action );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void initComponents() {
|
private void initComponents() {
|
||||||
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
||||||
dialogPane = new JPanel();
|
dialogPane = new JPanel();
|
||||||
|
|||||||
Reference in New Issue
Block a user