Testing: added "opaque" checkbox to test apps

This commit is contained in:
Karl Tauber
2019-10-24 12:44:16 +02:00
parent 7f43b3003c
commit 136481c110
10 changed files with 56 additions and 13 deletions

View File

@@ -28,7 +28,7 @@ public class FlatChooserTest
public static void main( String[] args ) {
SwingUtilities.invokeLater( () -> {
FlatTestFrame frame = FlatTestFrame.create( args, "FlatChooserTest" );
frame.showFrame( new FlatChooserTest() );
frame.showFrame( FlatChooserTest::new );
} );
}

View File

@@ -29,7 +29,7 @@ public class FlatComponents2Test
public static void main( String[] args ) {
SwingUtilities.invokeLater( () -> {
FlatTestFrame frame = FlatTestFrame.create( args, "FlatComponents2Test" );
frame.showFrame( new FlatComponents2Test() );
frame.showFrame( FlatComponents2Test::new );
} );
}

View File

@@ -30,7 +30,7 @@ public class FlatComponentsTest
public static void main( String[] args ) {
SwingUtilities.invokeLater( () -> {
FlatTestFrame frame = FlatTestFrame.create( args, "FlatComponentsTest" );
frame.showFrame( new FlatComponentsTest() );
frame.showFrame( FlatComponentsTest::new );
} );
}

View File

@@ -19,7 +19,7 @@ public class FlatContainerTest
public static void main( String[] args ) {
SwingUtilities.invokeLater( () -> {
FlatTestFrame frame = FlatTestFrame.create( args, "FlatContainerTest" );
frame.showFrame( new FlatContainerTest() );
frame.showFrame( FlatContainerTest::new );
} );
}

View File

@@ -31,7 +31,7 @@ public class FlatMenusTest
public static void main( String[] args ) {
SwingUtilities.invokeLater( () -> {
FlatTestFrame frame = FlatTestFrame.create( args, "FlatMenusTest" );
frame.showFrame( new FlatMenusTest() );
frame.showFrame( FlatMenusTest::new );
} );
}

View File

@@ -32,7 +32,7 @@ public class FlatOptionPaneTest
public static void main( String[] args ) {
SwingUtilities.invokeLater( () -> {
FlatTestFrame frame = FlatTestFrame.create( args, "FlatOptionPaneTest" );
frame.showFrame( new FlatOptionPaneTest() );
frame.showFrame( FlatOptionPaneTest::new );
} );
}

View File

@@ -23,6 +23,7 @@ import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
import java.util.prefs.Preferences;
import javax.swing.*;
import javax.swing.plaf.ColorUIResource;
@@ -33,6 +34,8 @@ import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.FlatIntelliJLaf;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.FlatLightLaf;
import com.formdev.flatlaf.extras.*;
import com.formdev.flatlaf.extras.TriStateCheckBox.State;
import com.formdev.flatlaf.ui.FlatUIUtils;
import com.formdev.flatlaf.util.SystemInfo;
import com.formdev.flatlaf.util.UIScale;
@@ -49,6 +52,7 @@ public class FlatTestFrame
private static final String KEY_SCALE_FACTOR = "scaleFactor";
private final String title;
private Supplier<JComponent> contentFactory;
private JComponent content;
private FlatInspector inspector;
@@ -211,8 +215,9 @@ public class FlatTestFrame
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
}
public void showFrame( JComponent content ) {
this.content = content;
public void showFrame( Supplier<JComponent> contentFactory ) {
this.contentFactory = contentFactory;
this.content = contentFactory.get();
contentPanel.getContentPane().add( content );
pack();
@@ -403,6 +408,27 @@ public class FlatTestFrame
}
}
private void opaqueChanged() {
State opaque = opaqueTriStateCheckBox.getState();
if( opaque == State.INDETERMINATE )
recreateContent();
else {
updateComponentsRecur( content, (c, type) -> {
if( c instanceof JComponent )
((JComponent)c).setOpaque( opaque == State.SELECTED );
} );
contentPanel.repaint();
}
}
private void recreateContent() {
contentPanel.getContentPane().remove( content );
content = contentFactory.get();
contentPanel.getContentPane().add( content );
contentPanel.revalidate();
contentPanel.repaint();
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
dialogPane = new JPanel();
@@ -415,6 +441,7 @@ public class FlatTestFrame
inspectCheckBox = new JCheckBox();
explicitColorsCheckBox = new JCheckBox();
backgroundCheckBox = new JCheckBox();
opaqueTriStateCheckBox = new TriStateCheckBox();
closeButton = new JButton();
//======== this ========
@@ -450,6 +477,7 @@ public class FlatTestFrame
"[fill]" +
"[fill]" +
"[fill]" +
"[fill]" +
"[grow,fill]" +
"[button,fill]",
// rows
@@ -508,9 +536,15 @@ public class FlatTestFrame
backgroundCheckBox.addActionListener(e -> backgroundChanged());
buttonBar.add(backgroundCheckBox, "cell 6 0");
//---- opaqueTriStateCheckBox ----
opaqueTriStateCheckBox.setText("opaque");
opaqueTriStateCheckBox.setMnemonic('O');
opaqueTriStateCheckBox.addActionListener(e -> opaqueChanged());
buttonBar.add(opaqueTriStateCheckBox, "cell 7 0");
//---- closeButton ----
closeButton.setText("Close");
buttonBar.add(closeButton, "cell 8 0");
buttonBar.add(closeButton, "cell 9 0");
}
dialogPane.add(buttonBar, BorderLayout.SOUTH);
}
@@ -529,6 +563,7 @@ public class FlatTestFrame
private JCheckBox inspectCheckBox;
private JCheckBox explicitColorsCheckBox;
private JCheckBox backgroundCheckBox;
private TriStateCheckBox opaqueTriStateCheckBox;
private JButton closeButton;
// JFormDesigner - End of variables declaration //GEN-END:variables

View File

@@ -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][grow,fill][button,fill]"
"$columnConstraints": "[fill][fill][fill][fill][fill][fill][fill][fill][grow,fill][button,fill]"
"$rowSpecs": "[fill]"
} ) {
name: "buttonBar"
@@ -99,11 +99,19 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 6 0"
} )
add( new FormComponent( "com.formdev.flatlaf.extras.TriStateCheckBox" ) {
name: "opaqueTriStateCheckBox"
"text": "opaque"
"mnemonic": 79
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "opaqueChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 7 0"
} )
add( new FormComponent( "javax.swing.JButton" ) {
name: "closeButton"
"text": "Close"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 8 0"
"value": "cell 9 0"
} )
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "South"

View File

@@ -30,7 +30,7 @@ public class FlatExtrasTest
public static void main( String[] args ) {
SwingUtilities.invokeLater( () -> {
FlatTestFrame frame = FlatTestFrame.create( args, "FlatExtrasTest" );
frame.showFrame( new FlatExtrasTest() );
frame.showFrame( FlatExtrasTest::new );
} );
}

View File

@@ -35,7 +35,7 @@ public class FlatSwingXTest
SwingUtilities.invokeLater( () -> {
FlatTestFrame frame = FlatTestFrame.create( args, "FlatSwingXTest" );
frame.useApplyComponentOrientation = true;
frame.showFrame( new FlatSwingXTest() );
frame.showFrame( FlatSwingXTest::new );
} );
}