UI defaults inspector: support embedding into any window

This commit is contained in:
Karl Tauber
2021-01-09 00:38:46 +01:00
parent e3cac95d37
commit 00b4e0a6fd
5 changed files with 263 additions and 215 deletions

View File

@@ -27,6 +27,7 @@ import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Supplier;
import javax.swing.*;
import javax.swing.FocusManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.metal.MetalLookAndFeel;
@@ -504,6 +505,29 @@ public class FlatTestFrame
inspector.setEnabled( inspectCheckBox.isSelected() );
}
private void uiDefaultsInspectorChanged() {
getContentPane().removeAll();
FocusManager focusManager = FocusManager.getCurrentManager();
Component focusOwner = focusManager.getFocusOwner();
if( uiDefaultsInspectorCheckBox.isSelected() ) {
JComponent uiDefaultsInspector = FlatUIDefaultsInspector.createInspectorPanel();
JSplitPane splitPane = new JSplitPane();
splitPane.setLeftComponent( dialogPane );
splitPane.setRightComponent( uiDefaultsInspector );
getContentPane().add( splitPane, BorderLayout.CENTER );
} else
getContentPane().add( dialogPane, BorderLayout.CENTER );
if( focusOwner != null && focusOwner.isDisplayable() )
focusOwner.requestFocusInWindow();
pack();
setLocationRelativeTo( null );
}
private void scaleFactorChanged() {
String scaleFactor = (String) scaleFactorComboBox.getSelectedItem();
if( "default".equals( scaleFactor ) )
@@ -662,6 +686,7 @@ public class FlatTestFrame
rightToLeftCheckBox = new JCheckBox();
enabledCheckBox = new JCheckBox();
inspectCheckBox = new JCheckBox();
uiDefaultsInspectorCheckBox = new JCheckBox();
explicitColorsCheckBox = new JCheckBox();
backgroundCheckBox = new JCheckBox();
opaqueTriStateCheckBox = new FlatTriStateCheckBox();
@@ -704,6 +729,7 @@ public class FlatTestFrame
"[fill]" +
"[fill]" +
"[fill]" +
"[fill]" +
"[grow,fill]" +
"[button,fill]",
// rows
@@ -757,23 +783,29 @@ public class FlatTestFrame
inspectCheckBox.addActionListener(e -> inspectChanged());
buttonBar.add(inspectCheckBox, "cell 5 0");
//---- uiDefaultsInspectorCheckBox ----
uiDefaultsInspectorCheckBox.setText("UI defaults");
uiDefaultsInspectorCheckBox.setMnemonic('U');
uiDefaultsInspectorCheckBox.addActionListener(e -> uiDefaultsInspectorChanged());
buttonBar.add(uiDefaultsInspectorCheckBox, "cell 6 0");
//---- explicitColorsCheckBox ----
explicitColorsCheckBox.setText("explicit colors");
explicitColorsCheckBox.setMnemonic('X');
explicitColorsCheckBox.addActionListener(e -> explicitColorsChanged());
buttonBar.add(explicitColorsCheckBox, "cell 6 0");
buttonBar.add(explicitColorsCheckBox, "cell 7 0");
//---- backgroundCheckBox ----
backgroundCheckBox.setText("background");
backgroundCheckBox.setMnemonic('B');
backgroundCheckBox.addActionListener(e -> backgroundChanged());
buttonBar.add(backgroundCheckBox, "cell 7 0");
buttonBar.add(backgroundCheckBox, "cell 8 0");
//---- opaqueTriStateCheckBox ----
opaqueTriStateCheckBox.setText("opaque");
opaqueTriStateCheckBox.setMnemonic('O');
opaqueTriStateCheckBox.addActionListener(e -> opaqueChanged());
buttonBar.add(opaqueTriStateCheckBox, "cell 8 0");
buttonBar.add(opaqueTriStateCheckBox, "cell 9 0");
//---- sizeVariantComboBox ----
sizeVariantComboBox.setModel(new DefaultComboBoxModel<>(new String[] {
@@ -784,11 +816,11 @@ public class FlatTestFrame
}));
sizeVariantComboBox.setSelectedIndex(2);
sizeVariantComboBox.addActionListener(e -> sizeVariantChanged());
buttonBar.add(sizeVariantComboBox, "cell 9 0");
buttonBar.add(sizeVariantComboBox, "cell 10 0");
//---- closeButton ----
closeButton.setText("Close");
buttonBar.add(closeButton, "cell 11 0");
buttonBar.add(closeButton, "cell 12 0");
}
dialogPane.add(buttonBar, BorderLayout.SOUTH);
dialogPane.add(themesPanel, BorderLayout.EAST);
@@ -807,6 +839,7 @@ public class FlatTestFrame
private JCheckBox rightToLeftCheckBox;
private JCheckBox enabledCheckBox;
private JCheckBox inspectCheckBox;
private JCheckBox uiDefaultsInspectorCheckBox;
private JCheckBox explicitColorsCheckBox;
private JCheckBox backgroundCheckBox;
private FlatTriStateCheckBox opaqueTriStateCheckBox;

View File

@@ -1,4 +1,4 @@
JFDML JFormDesigner: "7.0.2.0.298" Java: "14" encoding: "UTF-8"
JFDML JFormDesigner: "7.0.3.1.342" Java: "15" encoding: "UTF-8"
new FormModel {
contentType: "form/swing"
@@ -21,7 +21,7 @@ new FormModel {
} )
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "insets dialog"
"$columnConstraints": "[fill][fill][fill][fill][fill][fill][fill][fill][fill][fill][grow,fill][button,fill]"
"$columnConstraints": "[fill][fill][fill][fill][fill][fill][fill][fill][fill][fill][fill][grow,fill][button,fill]"
"$rowSpecs": "[fill]"
} ) {
name: "buttonBar"
@@ -91,13 +91,21 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 0"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "uiDefaultsInspectorCheckBox"
"text": "UI defaults"
"mnemonic": 85
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "uiDefaultsInspectorChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 6 0"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "explicitColorsCheckBox"
"text": "explicit colors"
"mnemonic": 88
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "explicitColorsChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 6 0"
"value": "cell 7 0"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "backgroundCheckBox"
@@ -105,7 +113,7 @@ new FormModel {
"mnemonic": 66
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "backgroundChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 7 0"
"value": "cell 8 0"
} )
add( new FormComponent( "com.formdev.flatlaf.extras.components.FlatTriStateCheckBox" ) {
name: "opaqueTriStateCheckBox"
@@ -113,7 +121,7 @@ new FormModel {
"mnemonic": 79
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "opaqueChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 8 0"
"value": "cell 9 0"
} )
add( new FormComponent( "javax.swing.JComboBox" ) {
name: "sizeVariantComboBox"
@@ -127,13 +135,13 @@ new FormModel {
"selectedIndex": 2
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "sizeVariantChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 9 0"
"value": "cell 10 0"
} )
add( new FormComponent( "javax.swing.JButton" ) {
name: "closeButton"
"text": "Close"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 11 0"
"value": "cell 12 0"
} )
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "South"