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

@@ -9,6 +9,8 @@ FlatLaf Change Log
buttons. buttons.
- TextComponent: Clip placeholder text if it does not fit into visible area. (PR - TextComponent: Clip placeholder text if it does not fit into visible area. (PR
#229) #229)
- Extras: Support embedding UI defaults inspector into any window (see
`FlatUIDefaultsInspector.createInspectorPanel()`.
#### Fixed bugs #### Fixed bugs

View File

@@ -66,9 +66,8 @@ public class FlatUIDefaultsInspector
{ {
private static final int KEY_MODIFIERS_MASK = InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK | InputEvent.ALT_DOWN_MASK | InputEvent.META_DOWN_MASK; private static final int KEY_MODIFIERS_MASK = InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK | InputEvent.ALT_DOWN_MASK | InputEvent.META_DOWN_MASK;
private static FlatUIDefaultsInspector inspector; private static JFrame inspectorFrame;
private final String title;
private final PropertyChangeListener lafListener = this::lafChanged; private final PropertyChangeListener lafListener = this::lafChanged;
private final PropertyChangeListener lafDefaultsListener = this::lafDefaultsChanged; private final PropertyChangeListener lafDefaultsListener = this::lafDefaultsChanged;
private boolean refreshPending; private boolean refreshPending;
@@ -92,27 +91,31 @@ public class FlatUIDefaultsInspector
} }
public static void show() { public static void show() {
if( inspector != null ) { if( inspectorFrame != null ) {
inspector.ensureOnScreen(); ensureOnScreen( inspectorFrame );
inspector.frame.toFront(); inspectorFrame.toFront();
return; return;
} }
inspector = new FlatUIDefaultsInspector(); inspectorFrame = new FlatUIDefaultsInspector().createFrame();
inspector.frame.setVisible( true ); inspectorFrame.setVisible( true );
} }
public static void hide() { public static void hide() {
if( inspector != null ) if( inspectorFrame != null )
inspector.frame.dispose(); inspectorFrame.dispose();
}
/**
* Creates a UI defaults inspector panel that can be embedded into any window.
*/
public static JComponent createInspectorPanel() {
return new FlatUIDefaultsInspector().panel;
} }
private FlatUIDefaultsInspector() { private FlatUIDefaultsInspector() {
initComponents(); initComponents();
title = frame.getTitle();
updateWindowTitle();
panel.setBorder( new ScaledEmptyBorder( 10, 10, 10, 10 ) ); panel.setBorder( new ScaledEmptyBorder( 10, 10, 10, 10 ) );
filterPanel.setBorder( new ScaledEmptyBorder( 0, 0, 10, 0 ) ); filterPanel.setBorder( new ScaledEmptyBorder( 0, 0, 10, 0 ) );
@@ -143,24 +146,21 @@ public class FlatUIDefaultsInspector
table.getRowSorter().setSortKeys( Collections.singletonList( table.getRowSorter().setSortKeys( Collections.singletonList(
new RowSorter.SortKey( 0, SortOrder.ASCENDING ) ) ); new RowSorter.SortKey( 0, SortOrder.ASCENDING ) ) );
// restore window bounds
Preferences prefs = getPrefs();
int x = prefs.getInt( "x", -1 );
int y = prefs.getInt( "y", -1 );
int width = prefs.getInt( "width", UIScale.scale( 600 ) );
int height = prefs.getInt( "height", UIScale.scale( 800 ) );
frame.setSize( width, height );
if( x != -1 && y != -1 ) {
frame.setLocation( x, y );
ensureOnScreen();
} else
frame.setLocationRelativeTo( null );
// restore column widths // restore column widths
Preferences prefs = getPrefs();
TableColumnModel columnModel = table.getColumnModel(); TableColumnModel columnModel = table.getColumnModel();
columnModel.getColumn( 0 ).setPreferredWidth( prefs.getInt( "column1width", 100 ) ); columnModel.getColumn( 0 ).setPreferredWidth( prefs.getInt( "column1width", 100 ) );
columnModel.getColumn( 1 ).setPreferredWidth( prefs.getInt( "column2width", 100 ) ); columnModel.getColumn( 1 ).setPreferredWidth( prefs.getInt( "column2width", 100 ) );
PropertyChangeListener columnWidthListener = e -> {
if( "width".equals( e.getPropertyName() ) ) {
prefs.putInt( "column1width", columnModel.getColumn( 0 ).getWidth() );
prefs.putInt( "column2width", columnModel.getColumn( 1 ).getWidth() );
}
};
columnModel.getColumn( 0 ).addPropertyChangeListener( columnWidthListener );
columnModel.getColumn( 1 ).addPropertyChangeListener( columnWidthListener );
// restore filter // restore filter
String filter = prefs.get( "filter", "" ); String filter = prefs.get( "filter", "" );
String valueType = prefs.get( "valueType", null ); String valueType = prefs.get( "valueType", null );
@@ -169,20 +169,66 @@ public class FlatUIDefaultsInspector
if( valueType != null ) if( valueType != null )
valueTypeField.setSelectedItem( valueType ); valueTypeField.setSelectedItem( valueType );
UIManager.addPropertyChangeListener( lafListener ); panel.addPropertyChangeListener( "ancestor", e -> {
UIManager.getDefaults().addPropertyChangeListener( lafDefaultsListener ); if( e.getNewValue() != null ) {
UIManager.addPropertyChangeListener( lafListener );
UIManager.getDefaults().addPropertyChangeListener( lafDefaultsListener );
} else {
UIManager.removePropertyChangeListener( lafListener );
UIManager.getDefaults().removePropertyChangeListener( lafDefaultsListener );
}
} );
// register F5 key to refresh // register F5 key to refresh
((JComponent)frame.getContentPane()).registerKeyboardAction( panel.registerKeyboardAction(
e -> refresh(), e -> refresh(),
KeyStroke.getKeyStroke( KeyEvent.VK_F5, 0, false ), KeyStroke.getKeyStroke( KeyEvent.VK_F5, 0, false ),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
}
private JFrame createFrame() {
JFrame frame = new JFrame();
frame.setTitle( "UI Defaults Inspector" );
frame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE );
frame.addWindowListener( new WindowAdapter() {
@Override
public void windowClosed( WindowEvent e ) {
inspectorFrame = null;
}
@Override
public void windowClosing( WindowEvent e ) {
saveWindowBounds( frame );
}
@Override
public void windowDeactivated( WindowEvent e ) {
saveWindowBounds( frame );
}
} );
updateWindowTitle( frame );
frame.getContentPane().add( panel, BorderLayout.CENTER );
// restore window bounds
Preferences prefs = getPrefs();
int x = prefs.getInt( "x", -1 );
int y = prefs.getInt( "y", -1 );
int width = prefs.getInt( "width", UIScale.scale( 600 ) );
int height = prefs.getInt( "height", UIScale.scale( 800 ) );
frame.setSize( width, height );
if( x != -1 && y != -1 ) {
frame.setLocation( x, y );
ensureOnScreen( frame );
} else
frame.setLocationRelativeTo( null );
// register ESC key to close frame // register ESC key to close frame
((JComponent)frame.getContentPane()).registerKeyboardAction( ((JComponent)frame.getContentPane()).registerKeyboardAction(
e -> frame.dispose(), e -> frame.dispose(),
KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0, false ), KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0, false ),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
return frame;
} }
private void delegateKey( int keyCode, String actionKey ) { private void delegateKey( int keyCode, String actionKey ) {
@@ -202,7 +248,7 @@ public class FlatUIDefaultsInspector
} ); } );
} }
private void ensureOnScreen() { private static void ensureOnScreen( JFrame frame ) {
Rectangle frameBounds = frame.getBounds(); Rectangle frameBounds = frame.getBounds();
boolean onScreen = false; boolean onScreen = false;
for( GraphicsDevice screen : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices() ) { for( GraphicsDevice screen : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices() ) {
@@ -219,12 +265,12 @@ public class FlatUIDefaultsInspector
frame.setLocationRelativeTo( null ); frame.setLocationRelativeTo( null );
} }
void lafChanged( PropertyChangeEvent e ) { private void lafChanged( PropertyChangeEvent e ) {
if( "lookAndFeel".equals( e.getPropertyName() ) ) if( "lookAndFeel".equals( e.getPropertyName() ) )
refresh(); refresh();
} }
void lafDefaultsChanged( PropertyChangeEvent e ) { private void lafDefaultsChanged( PropertyChangeEvent e ) {
if( refreshPending ) if( refreshPending )
return; return;
@@ -235,11 +281,13 @@ public class FlatUIDefaultsInspector
} ); } );
} }
void refresh() { private void refresh() {
ItemsTableModel model = (ItemsTableModel) table.getModel(); ItemsTableModel model = (ItemsTableModel) table.getModel();
model.setItems( getUIDefaultsItems() ); model.setItems( getUIDefaultsItems() );
updateWindowTitle(); JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass( JFrame.class, panel );
if( frame != null )
updateWindowTitle( frame );
} }
private Item[] getUIDefaultsItems() { private Item[] getUIDefaultsItems() {
@@ -277,33 +325,27 @@ public class FlatUIDefaultsInspector
return items.toArray( new Item[items.size()] ); return items.toArray( new Item[items.size()] );
} }
private void updateWindowTitle() { private void updateWindowTitle( JFrame frame ) {
frame.setTitle( title + " - " + UIManager.getLookAndFeel().getName() ); String title = frame.getTitle();
String sep = " - ";
int sepIndex = title.indexOf( sep );
if( sepIndex >= 0 )
title = title.substring( 0, sepIndex );
frame.setTitle( title + sep + UIManager.getLookAndFeel().getName() );
} }
private void saveWindowBounds() { private void saveWindowBounds( JFrame frame ) {
Preferences prefs = getPrefs(); Preferences prefs = getPrefs();
prefs.putInt( "x", frame.getX() ); prefs.putInt( "x", frame.getX() );
prefs.putInt( "y", frame.getY() ); prefs.putInt( "y", frame.getY() );
prefs.putInt( "width", frame.getWidth() ); prefs.putInt( "width", frame.getWidth() );
prefs.putInt( "height", frame.getHeight() ); prefs.putInt( "height", frame.getHeight() );
TableColumnModel columnModel = table.getColumnModel();
prefs.putInt( "column1width", columnModel.getColumn( 0 ).getWidth() );
prefs.putInt( "column2width", columnModel.getColumn( 1 ).getWidth() );
} }
private Preferences getPrefs() { private Preferences getPrefs() {
return Preferences.userRoot().node( "flatlaf-uidefaults-inspector" ); return Preferences.userRoot().node( "flatlaf-uidefaults-inspector" );
} }
private void windowClosed() {
UIManager.removePropertyChangeListener( lafListener );
UIManager.getDefaults().removePropertyChangeListener( lafDefaultsListener );
inspector = null;
}
private void filterChanged() { private void filterChanged() {
String filter = filterField.getText().trim(); String filter = filterField.getText().trim();
String valueType = (String) valueTypeField.getSelectedItem(); String valueType = (String) valueTypeField.getSelectedItem();
@@ -360,7 +402,6 @@ public class FlatUIDefaultsInspector
private void initComponents() { private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
frame = new JFrame();
panel = new JPanel(); panel = new JPanel();
filterPanel = new JPanel(); filterPanel = new JPanel();
flterLabel = new JLabel(); flterLabel = new JLabel();
@@ -370,99 +411,75 @@ public class FlatUIDefaultsInspector
scrollPane = new JScrollPane(); scrollPane = new JScrollPane();
table = new JTable(); table = new JTable();
//======== frame ======== //======== panel ========
{ {
frame.setTitle("UI Defaults Inspector"); panel.setLayout(new BorderLayout());
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
FlatUIDefaultsInspector.this.windowClosed();
}
@Override
public void windowClosing(WindowEvent e) {
saveWindowBounds();
}
@Override
public void windowDeactivated(WindowEvent e) {
saveWindowBounds();
}
});
Container frameContentPane = frame.getContentPane();
frameContentPane.setLayout(new BorderLayout());
//======== panel ======== //======== filterPanel ========
{ {
panel.setLayout(new BorderLayout()); filterPanel.setLayout(new GridBagLayout());
((GridBagLayout)filterPanel.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0};
((GridBagLayout)filterPanel.getLayout()).rowHeights = new int[] {0, 0};
((GridBagLayout)filterPanel.getLayout()).columnWeights = new double[] {0.0, 1.0, 0.0, 0.0, 1.0E-4};
((GridBagLayout)filterPanel.getLayout()).rowWeights = new double[] {0.0, 1.0E-4};
//======== filterPanel ======== //---- flterLabel ----
{ flterLabel.setText("Filter:");
filterPanel.setLayout(new GridBagLayout()); flterLabel.setLabelFor(filterField);
((GridBagLayout)filterPanel.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0}; flterLabel.setDisplayedMnemonic('F');
((GridBagLayout)filterPanel.getLayout()).rowHeights = new int[] {0, 0}; filterPanel.add(flterLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
((GridBagLayout)filterPanel.getLayout()).columnWeights = new double[] {0.0, 1.0, 0.0, 0.0, 1.0E-4}; GridBagConstraints.CENTER, GridBagConstraints.BOTH,
((GridBagLayout)filterPanel.getLayout()).rowWeights = new double[] {0.0, 1.0E-4}; new Insets(0, 0, 0, 10), 0, 0));
//---- flterLabel ---- //---- filterField ----
flterLabel.setText("Filter:"); filterField.putClientProperty("JTextField.placeholderText", "enter one or more filter strings, separated by space characters");
flterLabel.setLabelFor(filterField); filterPanel.add(filterField, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
flterLabel.setDisplayedMnemonic('F'); GridBagConstraints.CENTER, GridBagConstraints.BOTH,
filterPanel.add(flterLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, new Insets(0, 0, 0, 10), 0, 0));
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 10), 0, 0));
//---- filterField ---- //---- valueTypeLabel ----
filterField.putClientProperty("JTextField.placeholderText", "enter one or more filter strings, separated by space characters"); valueTypeLabel.setText("Value Type:");
filterPanel.add(filterField, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, valueTypeLabel.setLabelFor(valueTypeField);
GridBagConstraints.CENTER, GridBagConstraints.BOTH, valueTypeLabel.setDisplayedMnemonic('T');
new Insets(0, 0, 0, 10), 0, 0)); filterPanel.add(valueTypeLabel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 10), 0, 0));
//---- valueTypeLabel ---- //---- valueTypeField ----
valueTypeLabel.setText("Value Type:"); valueTypeField.setModel(new DefaultComboBoxModel<>(new String[] {
valueTypeLabel.setLabelFor(valueTypeField); "(any)",
valueTypeLabel.setDisplayedMnemonic('T'); "Boolean",
filterPanel.add(valueTypeLabel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, "Border",
GridBagConstraints.CENTER, GridBagConstraints.BOTH, "Color",
new Insets(0, 0, 0, 10), 0, 0)); "Dimension",
"Float",
//---- valueTypeField ---- "Font",
valueTypeField.setModel(new DefaultComboBoxModel<>(new String[] { "Icon",
"(any)", "Insets",
"Boolean", "Integer",
"Border", "String",
"Color", "(other)"
"Dimension", }));
"Float", valueTypeField.addActionListener(e -> filterChanged());
"Font", filterPanel.add(valueTypeField, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0,
"Icon", GridBagConstraints.CENTER, GridBagConstraints.BOTH,
"Insets", new Insets(0, 0, 0, 0), 0, 0));
"Integer",
"String",
"(other)"
}));
valueTypeField.addActionListener(e -> filterChanged());
filterPanel.add(valueTypeField, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
}
panel.add(filterPanel, BorderLayout.NORTH);
//======== scrollPane ========
{
//---- table ----
table.setAutoCreateRowSorter(true);
scrollPane.setViewportView(table);
}
panel.add(scrollPane, BorderLayout.CENTER);
} }
frameContentPane.add(panel, BorderLayout.CENTER); panel.add(filterPanel, BorderLayout.NORTH);
//======== scrollPane ========
{
//---- table ----
table.setAutoCreateRowSorter(true);
scrollPane.setViewportView(table);
}
panel.add(scrollPane, BorderLayout.CENTER);
} }
// JFormDesigner - End of component initialization //GEN-END:initComponents // JFormDesigner - End of component initialization //GEN-END:initComponents
} }
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
private JFrame frame;
private JPanel panel; private JPanel panel;
private JPanel filterPanel; private JPanel filterPanel;
private JLabel flterLabel; private JLabel flterLabel;

View File

@@ -1,83 +1,71 @@
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 { new FormModel {
contentType: "form/swing" contentType: "form/swing"
root: new FormRoot { root: new FormRoot {
add( new FormWindow( "javax.swing.JFrame", new FormLayoutManager( class java.awt.BorderLayout ) ) { add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.BorderLayout ) ) {
name: "frame" name: "panel"
"title": "UI Defaults Inspector" add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.GridBagLayout ) {
"defaultCloseOperation": 2 "$columnSpecs": "0, 0:1.0, 0, 0"
"$sizePolicy": 2 "$rowSpecs": "0"
"$locationPolicy": 2 "$hGap": 10
addEvent( new FormEvent( "java.awt.event.WindowListener", "windowClosed", "windowClosed", false ) ) "$vGap": 5
addEvent( new FormEvent( "java.awt.event.WindowListener", "windowClosing", "saveWindowBounds", false ) ) "$alignLeft": true
addEvent( new FormEvent( "java.awt.event.WindowListener", "windowDeactivated", "saveWindowBounds", false ) ) "$alignTop": true
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.BorderLayout ) ) { } ) {
name: "panel" name: "filterPanel"
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.GridBagLayout ) { add( new FormComponent( "javax.swing.JLabel" ) {
"$columnSpecs": "0, 0:1.0, 0, 0" name: "flterLabel"
"$rowSpecs": "0" "text": "Filter:"
"$hGap": 10 "labelFor": new FormReference( "filterField" )
"$vGap": 5 "displayedMnemonic": 70
"$alignLeft": true }, new FormLayoutConstraints( class com.jformdesigner.runtime.GridBagConstraintsEx ) )
"$alignTop": true add( new FormComponent( "javax.swing.JTextField" ) {
} ) { name: "filterField"
name: "filterPanel" "$client.JTextField.placeholderText": "enter one or more filter strings, separated by space characters"
add( new FormComponent( "javax.swing.JLabel" ) { }, new FormLayoutConstraints( class com.jformdesigner.runtime.GridBagConstraintsEx ) {
name: "flterLabel" "gridx": 1
"text": "Filter:"
"labelFor": new FormReference( "filterField" )
"displayedMnemonic": 70
}, new FormLayoutConstraints( class com.jformdesigner.runtime.GridBagConstraintsEx ) )
add( new FormComponent( "javax.swing.JTextField" ) {
name: "filterField"
"$client.JTextField.placeholderText": "enter one or more filter strings, separated by space characters"
}, new FormLayoutConstraints( class com.jformdesigner.runtime.GridBagConstraintsEx ) {
"gridx": 1
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "valueTypeLabel"
"text": "Value Type:"
"labelFor": new FormReference( "valueTypeField" )
"displayedMnemonic": 84
}, new FormLayoutConstraints( class com.jformdesigner.runtime.GridBagConstraintsEx ) {
"gridx": 2
} )
add( new FormComponent( "javax.swing.JComboBox" ) {
name: "valueTypeField"
"model": new javax.swing.DefaultComboBoxModel {
selectedItem: "(any)"
addElement( "(any)" )
addElement( "Boolean" )
addElement( "Border" )
addElement( "Color" )
addElement( "Dimension" )
addElement( "Float" )
addElement( "Font" )
addElement( "Icon" )
addElement( "Insets" )
addElement( "Integer" )
addElement( "String" )
addElement( "(other)" )
}
auxiliary() {
"JavaCodeGenerator.typeParameters": "String"
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "filterChanged", false ) )
}, new FormLayoutConstraints( class com.jformdesigner.runtime.GridBagConstraintsEx ) {
"gridx": 3
} )
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "North"
} ) } )
add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { add( new FormComponent( "javax.swing.JLabel" ) {
name: "scrollPane" name: "valueTypeLabel"
add( new FormComponent( "javax.swing.JTable" ) { "text": "Value Type:"
name: "table" "labelFor": new FormReference( "valueTypeField" )
"autoCreateRowSorter": true "displayedMnemonic": 84
} ) }, new FormLayoutConstraints( class com.jformdesigner.runtime.GridBagConstraintsEx ) {
}, new FormLayoutConstraints( class java.lang.String ) { "gridx": 2
"value": "Center" } )
add( new FormComponent( "javax.swing.JComboBox" ) {
name: "valueTypeField"
"model": new javax.swing.DefaultComboBoxModel {
selectedItem: "(any)"
addElement( "(any)" )
addElement( "Boolean" )
addElement( "Border" )
addElement( "Color" )
addElement( "Dimension" )
addElement( "Float" )
addElement( "Font" )
addElement( "Icon" )
addElement( "Insets" )
addElement( "Integer" )
addElement( "String" )
addElement( "(other)" )
}
auxiliary() {
"JavaCodeGenerator.typeParameters": "String"
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "filterChanged", false ) )
}, new FormLayoutConstraints( class com.jformdesigner.runtime.GridBagConstraintsEx ) {
"gridx": 3
} )
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "North"
} )
add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) {
name: "scrollPane"
add( new FormComponent( "javax.swing.JTable" ) {
name: "table"
"autoCreateRowSorter": true
} ) } )
}, new FormLayoutConstraints( class java.lang.String ) { }, new FormLayoutConstraints( class java.lang.String ) {
"value": "Center" "value": "Center"

View File

@@ -27,6 +27,7 @@ import java.util.function.BiConsumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import javax.swing.*; import javax.swing.*;
import javax.swing.FocusManager;
import javax.swing.UIManager.LookAndFeelInfo; import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.plaf.ColorUIResource; import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.metal.MetalLookAndFeel; import javax.swing.plaf.metal.MetalLookAndFeel;
@@ -504,6 +505,29 @@ public class FlatTestFrame
inspector.setEnabled( inspectCheckBox.isSelected() ); 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() { private void scaleFactorChanged() {
String scaleFactor = (String) scaleFactorComboBox.getSelectedItem(); String scaleFactor = (String) scaleFactorComboBox.getSelectedItem();
if( "default".equals( scaleFactor ) ) if( "default".equals( scaleFactor ) )
@@ -662,6 +686,7 @@ public class FlatTestFrame
rightToLeftCheckBox = new JCheckBox(); rightToLeftCheckBox = new JCheckBox();
enabledCheckBox = new JCheckBox(); enabledCheckBox = new JCheckBox();
inspectCheckBox = new JCheckBox(); inspectCheckBox = new JCheckBox();
uiDefaultsInspectorCheckBox = new JCheckBox();
explicitColorsCheckBox = new JCheckBox(); explicitColorsCheckBox = new JCheckBox();
backgroundCheckBox = new JCheckBox(); backgroundCheckBox = new JCheckBox();
opaqueTriStateCheckBox = new FlatTriStateCheckBox(); opaqueTriStateCheckBox = new FlatTriStateCheckBox();
@@ -704,6 +729,7 @@ public class FlatTestFrame
"[fill]" + "[fill]" +
"[fill]" + "[fill]" +
"[fill]" + "[fill]" +
"[fill]" +
"[grow,fill]" + "[grow,fill]" +
"[button,fill]", "[button,fill]",
// rows // rows
@@ -757,23 +783,29 @@ public class FlatTestFrame
inspectCheckBox.addActionListener(e -> inspectChanged()); inspectCheckBox.addActionListener(e -> inspectChanged());
buttonBar.add(inspectCheckBox, "cell 5 0"); 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 ----
explicitColorsCheckBox.setText("explicit colors"); explicitColorsCheckBox.setText("explicit colors");
explicitColorsCheckBox.setMnemonic('X'); explicitColorsCheckBox.setMnemonic('X');
explicitColorsCheckBox.addActionListener(e -> explicitColorsChanged()); explicitColorsCheckBox.addActionListener(e -> explicitColorsChanged());
buttonBar.add(explicitColorsCheckBox, "cell 6 0"); buttonBar.add(explicitColorsCheckBox, "cell 7 0");
//---- backgroundCheckBox ---- //---- backgroundCheckBox ----
backgroundCheckBox.setText("background"); backgroundCheckBox.setText("background");
backgroundCheckBox.setMnemonic('B'); backgroundCheckBox.setMnemonic('B');
backgroundCheckBox.addActionListener(e -> backgroundChanged()); backgroundCheckBox.addActionListener(e -> backgroundChanged());
buttonBar.add(backgroundCheckBox, "cell 7 0"); buttonBar.add(backgroundCheckBox, "cell 8 0");
//---- opaqueTriStateCheckBox ---- //---- opaqueTriStateCheckBox ----
opaqueTriStateCheckBox.setText("opaque"); opaqueTriStateCheckBox.setText("opaque");
opaqueTriStateCheckBox.setMnemonic('O'); opaqueTriStateCheckBox.setMnemonic('O');
opaqueTriStateCheckBox.addActionListener(e -> opaqueChanged()); opaqueTriStateCheckBox.addActionListener(e -> opaqueChanged());
buttonBar.add(opaqueTriStateCheckBox, "cell 8 0"); buttonBar.add(opaqueTriStateCheckBox, "cell 9 0");
//---- sizeVariantComboBox ---- //---- sizeVariantComboBox ----
sizeVariantComboBox.setModel(new DefaultComboBoxModel<>(new String[] { sizeVariantComboBox.setModel(new DefaultComboBoxModel<>(new String[] {
@@ -784,11 +816,11 @@ public class FlatTestFrame
})); }));
sizeVariantComboBox.setSelectedIndex(2); sizeVariantComboBox.setSelectedIndex(2);
sizeVariantComboBox.addActionListener(e -> sizeVariantChanged()); sizeVariantComboBox.addActionListener(e -> sizeVariantChanged());
buttonBar.add(sizeVariantComboBox, "cell 9 0"); buttonBar.add(sizeVariantComboBox, "cell 10 0");
//---- closeButton ---- //---- closeButton ----
closeButton.setText("Close"); closeButton.setText("Close");
buttonBar.add(closeButton, "cell 11 0"); buttonBar.add(closeButton, "cell 12 0");
} }
dialogPane.add(buttonBar, BorderLayout.SOUTH); dialogPane.add(buttonBar, BorderLayout.SOUTH);
dialogPane.add(themesPanel, BorderLayout.EAST); dialogPane.add(themesPanel, BorderLayout.EAST);
@@ -807,6 +839,7 @@ public class FlatTestFrame
private JCheckBox rightToLeftCheckBox; private JCheckBox rightToLeftCheckBox;
private JCheckBox enabledCheckBox; private JCheckBox enabledCheckBox;
private JCheckBox inspectCheckBox; private JCheckBox inspectCheckBox;
private JCheckBox uiDefaultsInspectorCheckBox;
private JCheckBox explicitColorsCheckBox; private JCheckBox explicitColorsCheckBox;
private JCheckBox backgroundCheckBox; private JCheckBox backgroundCheckBox;
private FlatTriStateCheckBox opaqueTriStateCheckBox; 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 { new FormModel {
contentType: "form/swing" contentType: "form/swing"
@@ -21,7 +21,7 @@ new FormModel {
} ) } )
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "insets dialog" "$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]" "$rowSpecs": "[fill]"
} ) { } ) {
name: "buttonBar" name: "buttonBar"
@@ -91,13 +91,21 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 0" "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" ) { add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "explicitColorsCheckBox" name: "explicitColorsCheckBox"
"text": "explicit colors" "text": "explicit colors"
"mnemonic": 88 "mnemonic": 88
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "explicitColorsChanged", false ) ) addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "explicitColorsChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 6 0" "value": "cell 7 0"
} ) } )
add( new FormComponent( "javax.swing.JCheckBox" ) { add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "backgroundCheckBox" name: "backgroundCheckBox"
@@ -105,7 +113,7 @@ new FormModel {
"mnemonic": 66 "mnemonic": 66
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "backgroundChanged", false ) ) addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "backgroundChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 7 0" "value": "cell 8 0"
} ) } )
add( new FormComponent( "com.formdev.flatlaf.extras.components.FlatTriStateCheckBox" ) { add( new FormComponent( "com.formdev.flatlaf.extras.components.FlatTriStateCheckBox" ) {
name: "opaqueTriStateCheckBox" name: "opaqueTriStateCheckBox"
@@ -113,7 +121,7 @@ new FormModel {
"mnemonic": 79 "mnemonic": 79
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "opaqueChanged", false ) ) addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "opaqueChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 8 0" "value": "cell 9 0"
} ) } )
add( new FormComponent( "javax.swing.JComboBox" ) { add( new FormComponent( "javax.swing.JComboBox" ) {
name: "sizeVariantComboBox" name: "sizeVariantComboBox"
@@ -127,13 +135,13 @@ new FormModel {
"selectedIndex": 2 "selectedIndex": 2
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "sizeVariantChanged", false ) ) addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "sizeVariantChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 9 0" "value": "cell 10 0"
} ) } )
add( new FormComponent( "javax.swing.JButton" ) { add( new FormComponent( "javax.swing.JButton" ) {
name: "closeButton" name: "closeButton"
"text": "Close" "text": "Close"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 11 0" "value": "cell 12 0"
} ) } )
}, new FormLayoutConstraints( class java.lang.String ) { }, new FormLayoutConstraints( class java.lang.String ) {
"value": "South" "value": "South"