Merge remote-tracking branch 'origin/develop-1.x' into main

# Conflicts:
#	CHANGELOG.md
This commit is contained in:
Karl Tauber
2021-12-07 16:05:31 +01:00
11 changed files with 237 additions and 20 deletions

View File

@@ -0,0 +1,76 @@
/*
* Copyright 2021 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.testing;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import com.formdev.flatlaf.FlatLightLaf;
/**
* Used to test AWT components on macOS, which internally use Swing.
*
* @author Karl Tauber
*/
public class FlatAWTTest
{
public static void main( String[] args ) {
EventQueue.invokeLater( () -> {
FlatLightLaf.setup();
Frame frame = new Frame( "FlatAWTTest" );
frame.addWindowListener( new WindowAdapter() {
@Override
public void windowClosing( WindowEvent e ) {
System.exit( 0 );
}
} );
frame.setLayout( new FlowLayout() );
frame.add( new Label( "text" ) );
frame.add( new Button( "text" ) );
frame.add( new Checkbox( "text" ) );
CheckboxGroup checkboxGroup = new CheckboxGroup();
frame.add( new Checkbox( "radio 1", true, checkboxGroup ) );
frame.add( new Checkbox( "radio 2", false, checkboxGroup ) );
frame.add( new Checkbox( "radio 3", false, checkboxGroup ) );
Choice choice = new Choice();
choice.add( "item 1" );
choice.add( "item 2" );
choice.add( "item 3" );
frame.add( choice );
frame.add( new TextField( "text" ) );
frame.add( new TextArea( "text" ) );
List list = new List();
list.add( "item 1" );
list.add( "item 2" );
frame.add( list );
frame.add( new Scrollbar() );
frame.add( new ScrollPane() );
frame.add( new Panel() );
frame.add( new Canvas() );
frame.setSize( 800, 600 );
frame.setVisible( true );
});
}
}

View File

@@ -0,0 +1,83 @@
/*
* Copyright 2021 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.testing;
import java.awt.Container;
import java.awt.FlowLayout;
import java.util.Random;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatLightLaf;
/**
* @author Karl Tauber
*/
public class FlatStressTest
{
public static void main( String[] args ) {
SwingUtilities.invokeLater( () -> {
FlatLightLaf.setup();
new FlatStressTest();
} );
}
protected FlatStressTest() {
JFrame frame = new JFrame( "FlatStressTest" );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
Container contentPane = frame.getContentPane();
contentPane.setLayout( new FlowLayout() );
contentPane.add( createStressTest() );
frame.setSize( 800, 600 );
frame.setLocationRelativeTo( null );
frame.setVisible( true );
}
private JComponent createStressTest() {
return createComboBoxStressTest();
}
// for https://github.com/JFormDesigner/FlatLaf/issues/432
// simulates StackOverflowError in FlatComboBoxUI when doing stuff in various threads
//
// requires adding `Thread.sleep( 1 );` to `FlatComboBoxUI.CellPaddingBorder.install()`
// after invocation of `uninstall()`
private JComponent createComboBoxStressTest() {
Random random = new Random();
JComboBox<String> comboBox = new JComboBox<>();
comboBox.putClientProperty( FlatClientProperties.MINIMUM_WIDTH, 0 );
for( int i = 0; i < 100; i++ )
comboBox.addItem( Integer.toString( random.nextInt() ) );
Thread thread = new Thread( () -> {
for(;;) {
comboBox.setSelectedIndex( random.nextInt( comboBox.getItemCount() ) );
comboBox.putClientProperty( FlatClientProperties.MINIMUM_WIDTH, random.nextInt( 500 ) );
}
});
thread.setDaemon( true );
thread.start();
return comboBox;
}
}