FlatSmoothScrollingTest: added "custom" scroll pane for testing smooth scrolling in case that scroll view does not implement Scrollable interface

This commit is contained in:
Karl Tauber
2020-08-12 17:31:55 +02:00
parent 3573188025
commit 865a56875f
2 changed files with 128 additions and 90 deletions

View File

@@ -76,6 +76,7 @@ public class FlatSmoothScrollingTest
textAreaLabel.setIcon( new ColorIcon( Color.magenta.darker() ) ); textAreaLabel.setIcon( new ColorIcon( Color.magenta.darker() ) );
textPaneLabel.setIcon( new ColorIcon( Color.cyan.darker() ) ); textPaneLabel.setIcon( new ColorIcon( Color.cyan.darker() ) );
editorPaneLabel.setIcon( new ColorIcon( Color.orange.darker() ) ); editorPaneLabel.setIcon( new ColorIcon( Color.orange.darker() ) );
customLabel.setIcon( new ColorIcon( Color.pink ) );
listScrollPane.getVerticalScrollBar().getModel().addChangeListener( new ScrollBarChangeHandler( "list vert", Color.red.darker() ) ); listScrollPane.getVerticalScrollBar().getModel().addChangeListener( new ScrollBarChangeHandler( "list vert", Color.red.darker() ) );
listScrollPane.getHorizontalScrollBar().getModel().addChangeListener( new ScrollBarChangeHandler( "list horz", Color.red ) ); listScrollPane.getHorizontalScrollBar().getModel().addChangeListener( new ScrollBarChangeHandler( "list horz", Color.red ) );
@@ -95,6 +96,9 @@ public class FlatSmoothScrollingTest
editorPaneScrollPane.getVerticalScrollBar().getModel().addChangeListener( new ScrollBarChangeHandler( "editorPane vert", Color.orange.darker() ) ); editorPaneScrollPane.getVerticalScrollBar().getModel().addChangeListener( new ScrollBarChangeHandler( "editorPane vert", Color.orange.darker() ) );
editorPaneScrollPane.getHorizontalScrollBar().getModel().addChangeListener( new ScrollBarChangeHandler( "editorPane horz", Color.orange ) ); editorPaneScrollPane.getHorizontalScrollBar().getModel().addChangeListener( new ScrollBarChangeHandler( "editorPane horz", Color.orange ) );
customScrollPane.getVerticalScrollBar().getModel().addChangeListener( new ScrollBarChangeHandler( "custom vert", Color.pink ) );
customScrollPane.getHorizontalScrollBar().getModel().addChangeListener( new ScrollBarChangeHandler( "custom horz", Color.pink.darker() ) );
ArrayList<String> items = new ArrayList<>(); ArrayList<String> items = new ArrayList<>();
for( char ch = '0'; ch < 'z'; ch++ ) { for( char ch = '0'; ch < 'z'; ch++ ) {
char[] chars = new char[ch - '0' + 1]; char[] chars = new char[ch - '0' + 1];
@@ -197,6 +201,8 @@ public class FlatSmoothScrollingTest
listLabel = new JLabel(); listLabel = new JLabel();
treeLabel = new JLabel(); treeLabel = new JLabel();
tableLabel = new JLabel(); tableLabel = new JLabel();
showTableGridCheckBox = new JCheckBox();
autoResizeModeCheckBox = new JCheckBox();
listScrollPane = new FlatSmoothScrollingTest.DebugScrollPane(); listScrollPane = new FlatSmoothScrollingTest.DebugScrollPane();
list = new JList<>(); list = new JList<>();
treeScrollPane = new FlatSmoothScrollingTest.DebugScrollPane(); treeScrollPane = new FlatSmoothScrollingTest.DebugScrollPane();
@@ -206,19 +212,20 @@ public class FlatSmoothScrollingTest
textAreaLabel = new JLabel(); textAreaLabel = new JLabel();
textPaneLabel = new JLabel(); textPaneLabel = new JLabel();
editorPaneLabel = new JLabel(); editorPaneLabel = new JLabel();
customLabel = new JLabel();
textAreaScrollPane = new FlatSmoothScrollingTest.DebugScrollPane(); textAreaScrollPane = new FlatSmoothScrollingTest.DebugScrollPane();
textArea = new JTextArea(); textArea = new JTextArea();
textPaneScrollPane = new FlatSmoothScrollingTest.DebugScrollPane(); textPaneScrollPane = new FlatSmoothScrollingTest.DebugScrollPane();
textPane = new JTextPane(); textPane = new JTextPane();
editorPaneScrollPane = new FlatSmoothScrollingTest.DebugScrollPane(); editorPaneScrollPane = new FlatSmoothScrollingTest.DebugScrollPane();
editorPane = new JEditorPane(); editorPane = new JEditorPane();
panel1 = new JPanel(); customScrollPane = new JScrollPane();
showTableGridCheckBox = new JCheckBox(); button1 = new JButton();
autoResizeModeCheckBox = new JCheckBox();
updateChartDelayedCheckBox = new JCheckBox();
clearChartButton = new JButton();
scrollPane1 = new JScrollPane(); scrollPane1 = new JScrollPane();
lineChartPanel = new FlatSmoothScrollingTest.LineChartPanel(); lineChartPanel = new FlatSmoothScrollingTest.LineChartPanel();
label1 = new JLabel();
updateChartDelayedCheckBox = new JCheckBox();
clearChartButton = new JButton();
//======== this ======== //======== this ========
setLayout(new MigLayout( setLayout(new MigLayout(
@@ -234,7 +241,8 @@ public class FlatSmoothScrollingTest
"[200,grow,fill]" + "[200,grow,fill]" +
"[]" + "[]" +
"[200,grow,fill]" + "[200,grow,fill]" +
"[300,grow,fill]")); "[300,grow,fill]" +
"[]"));
//---- smoothScrollingCheckBox ---- //---- smoothScrollingCheckBox ----
smoothScrollingCheckBox.setText("Smooth scrolling"); smoothScrollingCheckBox.setText("Smooth scrolling");
@@ -256,7 +264,19 @@ public class FlatSmoothScrollingTest
//---- tableLabel ---- //---- tableLabel ----
tableLabel.setText("JTable:"); tableLabel.setText("JTable:");
tableLabel.setHorizontalTextPosition(SwingConstants.LEADING); tableLabel.setHorizontalTextPosition(SwingConstants.LEADING);
add(tableLabel, "cell 2 1"); add(tableLabel, "cell 2 1 2 1");
//---- showTableGridCheckBox ----
showTableGridCheckBox.setText("Show table grid");
showTableGridCheckBox.setMnemonic('G');
showTableGridCheckBox.addActionListener(e -> showTableGridChanged());
add(showTableGridCheckBox, "cell 2 1 2 1,alignx right,growx 0");
//---- autoResizeModeCheckBox ----
autoResizeModeCheckBox.setText("Auto-resize mode");
autoResizeModeCheckBox.setSelected(true);
autoResizeModeCheckBox.addActionListener(e -> autoResizeModeChanged());
add(autoResizeModeCheckBox, "cell 2 1 2 1,alignx right,growx 0");
//======== listScrollPane ======== //======== listScrollPane ========
{ {
@@ -291,6 +311,10 @@ public class FlatSmoothScrollingTest
editorPaneLabel.setHorizontalTextPosition(SwingConstants.LEADING); editorPaneLabel.setHorizontalTextPosition(SwingConstants.LEADING);
add(editorPaneLabel, "cell 2 3"); add(editorPaneLabel, "cell 2 3");
//---- customLabel ----
customLabel.setText("Custom:");
add(customLabel, "cell 3 3");
//======== textAreaScrollPane ======== //======== textAreaScrollPane ========
{ {
textAreaScrollPane.setViewportView(textArea); textAreaScrollPane.setViewportView(textArea);
@@ -309,51 +333,40 @@ public class FlatSmoothScrollingTest
} }
add(editorPaneScrollPane, "cell 2 4"); add(editorPaneScrollPane, "cell 2 4");
//======== panel1 ======== //======== customScrollPane ========
{ {
panel1.setLayout(new MigLayout(
"ltr,insets 0,hidemode 3",
// columns
"[200,right]",
// rows
"[]0" +
"[]" +
"[grow]" +
"[]" +
"[]"));
//---- showTableGridCheckBox ---- //---- button1 ----
showTableGridCheckBox.setText("Show table grid"); button1.setText("I'm a large button, but do not implement Scrollable interface");
showTableGridCheckBox.setMnemonic('G'); button1.setPreferredSize(new Dimension(800, 800));
showTableGridCheckBox.addActionListener(e -> showTableGridChanged()); button1.setHorizontalAlignment(SwingConstants.LEADING);
panel1.add(showTableGridCheckBox, "cell 0 0"); button1.setVerticalAlignment(SwingConstants.TOP);
customScrollPane.setViewportView(button1);
//---- autoResizeModeCheckBox ----
autoResizeModeCheckBox.setText("Auto-resize mode");
autoResizeModeCheckBox.setSelected(true);
autoResizeModeCheckBox.addActionListener(e -> autoResizeModeChanged());
panel1.add(autoResizeModeCheckBox, "cell 0 1");
//---- updateChartDelayedCheckBox ----
updateChartDelayedCheckBox.setText("Update chart delayed");
updateChartDelayedCheckBox.setMnemonic('U');
updateChartDelayedCheckBox.setSelected(true);
updateChartDelayedCheckBox.addActionListener(e -> updateChartDelayedChanged());
panel1.add(updateChartDelayedCheckBox, "cell 0 3");
//---- clearChartButton ----
clearChartButton.setText("Clear Chart");
clearChartButton.setMnemonic('C');
clearChartButton.addActionListener(e -> clearChart());
panel1.add(clearChartButton, "cell 0 4");
} }
add(panel1, "cell 3 3 1 2,growy"); add(customScrollPane, "cell 3 4");
//======== scrollPane1 ======== //======== scrollPane1 ========
{ {
scrollPane1.setViewportView(lineChartPanel); scrollPane1.setViewportView(lineChartPanel);
} }
add(scrollPane1, "cell 0 5 4 1,width 100"); add(scrollPane1, "cell 0 5 4 1,width 100");
//---- label1 ----
label1.setText("X: time (200ms per line) / Y: scroll bar value (10% per line)");
add(label1, "cell 0 6 4 1");
//---- updateChartDelayedCheckBox ----
updateChartDelayedCheckBox.setText("Update chart delayed");
updateChartDelayedCheckBox.setMnemonic('U');
updateChartDelayedCheckBox.setSelected(true);
updateChartDelayedCheckBox.addActionListener(e -> updateChartDelayedChanged());
add(updateChartDelayedCheckBox, "cell 0 6 4 1,alignx right,growx 0");
//---- clearChartButton ----
clearChartButton.setText("Clear Chart");
clearChartButton.setMnemonic('C');
clearChartButton.addActionListener(e -> clearChart());
add(clearChartButton, "cell 0 6 4 1,alignx right,growx 0");
// JFormDesigner - End of component initialization //GEN-END:initComponents // JFormDesigner - End of component initialization //GEN-END:initComponents
} }
@@ -362,6 +375,8 @@ public class FlatSmoothScrollingTest
private JLabel listLabel; private JLabel listLabel;
private JLabel treeLabel; private JLabel treeLabel;
private JLabel tableLabel; private JLabel tableLabel;
private JCheckBox showTableGridCheckBox;
private JCheckBox autoResizeModeCheckBox;
private FlatSmoothScrollingTest.DebugScrollPane listScrollPane; private FlatSmoothScrollingTest.DebugScrollPane listScrollPane;
private JList<String> list; private JList<String> list;
private FlatSmoothScrollingTest.DebugScrollPane treeScrollPane; private FlatSmoothScrollingTest.DebugScrollPane treeScrollPane;
@@ -371,19 +386,20 @@ public class FlatSmoothScrollingTest
private JLabel textAreaLabel; private JLabel textAreaLabel;
private JLabel textPaneLabel; private JLabel textPaneLabel;
private JLabel editorPaneLabel; private JLabel editorPaneLabel;
private JLabel customLabel;
private FlatSmoothScrollingTest.DebugScrollPane textAreaScrollPane; private FlatSmoothScrollingTest.DebugScrollPane textAreaScrollPane;
private JTextArea textArea; private JTextArea textArea;
private FlatSmoothScrollingTest.DebugScrollPane textPaneScrollPane; private FlatSmoothScrollingTest.DebugScrollPane textPaneScrollPane;
private JTextPane textPane; private JTextPane textPane;
private FlatSmoothScrollingTest.DebugScrollPane editorPaneScrollPane; private FlatSmoothScrollingTest.DebugScrollPane editorPaneScrollPane;
private JEditorPane editorPane; private JEditorPane editorPane;
private JPanel panel1; private JScrollPane customScrollPane;
private JCheckBox showTableGridCheckBox; private JButton button1;
private JCheckBox autoResizeModeCheckBox;
private JCheckBox updateChartDelayedCheckBox;
private JButton clearChartButton;
private JScrollPane scrollPane1; private JScrollPane scrollPane1;
private FlatSmoothScrollingTest.LineChartPanel lineChartPanel; private FlatSmoothScrollingTest.LineChartPanel lineChartPanel;
private JLabel label1;
private JCheckBox updateChartDelayedCheckBox;
private JButton clearChartButton;
// JFormDesigner - End of variables declaration //GEN-END:variables // JFormDesigner - End of variables declaration //GEN-END:variables
//---- class ScrollBarChangeHandler --------------------------------------- //---- class ScrollBarChangeHandler ---------------------------------------
@@ -533,6 +549,11 @@ public class FlatSmoothScrollingTest
int secondWidth = (int) (SECOND_WIDTH * scaleFactor); int secondWidth = (int) (SECOND_WIDTH * scaleFactor);
int seqGapWidth = (int) (NEW_SEQUENCE_GAP * scaleFactor); int seqGapWidth = (int) (NEW_SEQUENCE_GAP * scaleFactor);
Color lineColor = FlatUIUtils.getUIColor( "Component.borderColor", Color.lightGray );
Color lineColor2 = FlatLaf.isLafDark()
? new HSLColor( lineColor ).adjustTone( 30 )
: new HSLColor( lineColor ).adjustShade( 30 );
g.translate( x, y ); g.translate( x, y );
// fill background // fill background
@@ -540,16 +561,18 @@ public class FlatSmoothScrollingTest
g.fillRect( x, y, width, height ); g.fillRect( x, y, width, height );
// paint horizontal lines // paint horizontal lines
g.setColor( UIManager.getColor( "Component.borderColor" ) );
for( int i = 1; i < 10; i++ ) { for( int i = 1; i < 10; i++ ) {
int hy = (height * i) / 10; int hy = (height * i) / 10;
g.setColor( (i != 5) ? lineColor : lineColor2 );
g.drawLine( 0, hy, width, hy ); g.drawLine( 0, hy, width, hy );
} }
// paint vertical lines // paint vertical lines
int twoHundredMillisWidth = secondWidth / 5; int twoHundredMillisWidth = secondWidth / 5;
for( int i = twoHundredMillisWidth; i < width; i += twoHundredMillisWidth ) for( int i = twoHundredMillisWidth; i < width; i += twoHundredMillisWidth ) {
g.setColor( (i % secondWidth != 0) ? lineColor : lineColor2 );
g.drawLine( i, 0, i, height ); g.drawLine( i, 0, i, height );
}
// paint lines // paint lines
for( Map.Entry<Color, List<Data>> e : color2dataMap.entrySet() ) { for( Map.Entry<Color, List<Data>> e : color2dataMap.entrySet() ) {

View File

@@ -6,7 +6,7 @@ new FormModel {
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "ltr,insets dialog,hidemode 3" "$layoutConstraints": "ltr,insets dialog,hidemode 3"
"$columnConstraints": "[200,fill][200,fill][200,fill][200,fill]" "$columnConstraints": "[200,fill][200,fill][200,fill][200,fill]"
"$rowConstraints": "[][][200,grow,fill][][200,grow,fill][300,grow,fill]" "$rowConstraints": "[][][200,grow,fill][][200,grow,fill][300,grow,fill][]"
} ) { } ) {
name: "this" name: "this"
add( new FormComponent( "javax.swing.JCheckBox" ) { add( new FormComponent( "javax.swing.JCheckBox" ) {
@@ -37,7 +37,23 @@ new FormModel {
"text": "JTable:" "text": "JTable:"
"horizontalTextPosition": 10 "horizontalTextPosition": 10
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 1" "value": "cell 2 1 2 1"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "showTableGridCheckBox"
"text": "Show table grid"
"mnemonic": 71
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showTableGridChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 1 2 1,alignx right,growx 0"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "autoResizeModeCheckBox"
"text": "Auto-resize mode"
"selected": true
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "autoResizeModeChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 1 2 1,alignx right,growx 0"
} ) } )
add( new FormContainer( "com.formdev.flatlaf.testing.FlatSmoothScrollingTest$DebugScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { add( new FormContainer( "com.formdev.flatlaf.testing.FlatSmoothScrollingTest$DebugScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) {
name: "listScrollPane" name: "listScrollPane"
@@ -88,6 +104,12 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 3" "value": "cell 2 3"
} ) } )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "customLabel"
"text": "Custom:"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 3 3"
} )
add( new FormContainer( "com.formdev.flatlaf.testing.FlatSmoothScrollingTest$DebugScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { add( new FormContainer( "com.formdev.flatlaf.testing.FlatSmoothScrollingTest$DebugScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) {
name: "textAreaScrollPane" name: "textAreaScrollPane"
add( new FormComponent( "javax.swing.JTextArea" ) { add( new FormComponent( "javax.swing.JTextArea" ) {
@@ -112,47 +134,17 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 4" "value": "cell 2 4"
} ) } )
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) {
"$columnConstraints": "[200,right]" name: "customScrollPane"
"$rowConstraints": "[]0[][grow][][]"
"$layoutConstraints": "ltr,insets 0,hidemode 3"
} ) {
name: "panel1"
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "showTableGridCheckBox"
"text": "Show table grid"
"mnemonic": 71
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showTableGridChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 0"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "autoResizeModeCheckBox"
"text": "Auto-resize mode"
"selected": true
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "autoResizeModeChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 1"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "updateChartDelayedCheckBox"
"text": "Update chart delayed"
"mnemonic": 85
"selected": true
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "updateChartDelayedChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 3"
} )
add( new FormComponent( "javax.swing.JButton" ) { add( new FormComponent( "javax.swing.JButton" ) {
name: "clearChartButton" name: "button1"
"text": "Clear Chart" "text": "I'm a large button, but do not implement Scrollable interface"
"mnemonic": 67 "preferredSize": new java.awt.Dimension( 800, 800 )
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "clearChart", false ) ) "horizontalAlignment": 10
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "verticalAlignment": 1
"value": "cell 0 4"
} ) } )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 3 3 1 2,growy" "value": "cell 3 4"
} ) } )
add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) {
name: "scrollPane1" name: "scrollPane1"
@@ -162,6 +154,29 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 5 4 1,width 100" "value": "cell 0 5 4 1,width 100"
} ) } )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label1"
"text": "X: time (200ms per line) / Y: scroll bar value (10% per line)"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 6 4 1"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "updateChartDelayedCheckBox"
"text": "Update chart delayed"
"mnemonic": 85
"selected": true
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "updateChartDelayedChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 6 4 1,alignx right,growx 0"
} )
add( new FormComponent( "javax.swing.JButton" ) {
name: "clearChartButton"
"text": "Clear Chart"
"mnemonic": 67
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "clearChart", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 6 4 1,alignx right,growx 0"
} )
}, new FormLayoutConstraints( null ) { }, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 ) "location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 790, 715 ) "size": new java.awt.Dimension( 790, 715 )