mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 06:57:13 -06:00
FlatAnimatorTest: added test for precise scrolling with trackpad
This commit is contained in:
@@ -46,6 +46,8 @@ public class FlatAnimatorTest
|
|||||||
FlatAnimatorTest() {
|
FlatAnimatorTest() {
|
||||||
initComponents();
|
initComponents();
|
||||||
|
|
||||||
|
updateChartDelayedChanged();
|
||||||
|
|
||||||
lineChartPanel.setSecondWidth( 500 );
|
lineChartPanel.setSecondWidth( 500 );
|
||||||
mouseWheelTestPanel.lineChartPanel = lineChartPanel;
|
mouseWheelTestPanel.lineChartPanel = lineChartPanel;
|
||||||
}
|
}
|
||||||
@@ -90,16 +92,16 @@ public class FlatAnimatorTest
|
|||||||
|
|
||||||
private void initComponents() {
|
private void initComponents() {
|
||||||
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
||||||
JLabel label1 = new JLabel();
|
JLabel linearLabel = new JLabel();
|
||||||
linearScrollBar = new JScrollBar();
|
linearScrollBar = new JScrollBar();
|
||||||
JLabel label2 = new JLabel();
|
JLabel easeInOutLabel = new JLabel();
|
||||||
easeInOutScrollBar = new JScrollBar();
|
easeInOutScrollBar = new JScrollBar();
|
||||||
startButton = new JButton();
|
startButton = new JButton();
|
||||||
JLabel label3 = new JLabel();
|
JLabel mouseWheelTestLabel = new JLabel();
|
||||||
mouseWheelTestPanel = new FlatAnimatorTest.MouseWheelTestPanel();
|
mouseWheelTestPanel = new FlatAnimatorTest.MouseWheelTestPanel();
|
||||||
JScrollPane scrollPane1 = new JScrollPane();
|
JScrollPane lineChartScrollPane = new JScrollPane();
|
||||||
lineChartPanel = new FlatSmoothScrollingTest.LineChartPanel();
|
lineChartPanel = new FlatSmoothScrollingTest.LineChartPanel();
|
||||||
JLabel label4 = new JLabel();
|
JLabel lineChartInfoLabel = new JLabel();
|
||||||
updateChartDelayedCheckBox = new JCheckBox();
|
updateChartDelayedCheckBox = new JCheckBox();
|
||||||
JButton clearChartButton = new JButton();
|
JButton clearChartButton = new JButton();
|
||||||
|
|
||||||
@@ -112,24 +114,23 @@ public class FlatAnimatorTest
|
|||||||
// rows
|
// rows
|
||||||
"[]" +
|
"[]" +
|
||||||
"[]" +
|
"[]" +
|
||||||
"[]" +
|
"[]para" +
|
||||||
"[]" +
|
|
||||||
"[top]" +
|
"[top]" +
|
||||||
"[400,grow,fill]" +
|
"[400,grow,fill]" +
|
||||||
"[]"));
|
"[]"));
|
||||||
|
|
||||||
//---- label1 ----
|
//---- linearLabel ----
|
||||||
label1.setText("Linear:");
|
linearLabel.setText("Linear:");
|
||||||
add(label1, "cell 0 0");
|
add(linearLabel, "cell 0 0");
|
||||||
|
|
||||||
//---- linearScrollBar ----
|
//---- linearScrollBar ----
|
||||||
linearScrollBar.setOrientation(Adjustable.HORIZONTAL);
|
linearScrollBar.setOrientation(Adjustable.HORIZONTAL);
|
||||||
linearScrollBar.setBlockIncrement(1);
|
linearScrollBar.setBlockIncrement(1);
|
||||||
add(linearScrollBar, "cell 1 0");
|
add(linearScrollBar, "cell 1 0");
|
||||||
|
|
||||||
//---- label2 ----
|
//---- easeInOutLabel ----
|
||||||
label2.setText("Ease in out:");
|
easeInOutLabel.setText("Ease in out:");
|
||||||
add(label2, "cell 0 1");
|
add(easeInOutLabel, "cell 0 1");
|
||||||
|
|
||||||
//---- easeInOutScrollBar ----
|
//---- easeInOutScrollBar ----
|
||||||
easeInOutScrollBar.setOrientation(Adjustable.HORIZONTAL);
|
easeInOutScrollBar.setOrientation(Adjustable.HORIZONTAL);
|
||||||
@@ -141,36 +142,36 @@ public class FlatAnimatorTest
|
|||||||
startButton.addActionListener(e -> start());
|
startButton.addActionListener(e -> start());
|
||||||
add(startButton, "cell 0 2");
|
add(startButton, "cell 0 2");
|
||||||
|
|
||||||
//---- label3 ----
|
//---- mouseWheelTestLabel ----
|
||||||
label3.setText("Mouse wheel test:");
|
mouseWheelTestLabel.setText("Mouse wheel test:");
|
||||||
add(label3, "cell 0 4");
|
add(mouseWheelTestLabel, "cell 0 3");
|
||||||
|
|
||||||
//---- mouseWheelTestPanel ----
|
//---- mouseWheelTestPanel ----
|
||||||
mouseWheelTestPanel.setBorder(new LineBorder(Color.red));
|
mouseWheelTestPanel.setBorder(new LineBorder(Color.red));
|
||||||
add(mouseWheelTestPanel, "cell 1 4,height 100");
|
add(mouseWheelTestPanel, "cell 1 3,height 100");
|
||||||
|
|
||||||
//======== scrollPane1 ========
|
//======== lineChartScrollPane ========
|
||||||
{
|
{
|
||||||
scrollPane1.setViewportView(lineChartPanel);
|
lineChartScrollPane.putClientProperty("JScrollPane.smoothScrolling", false);
|
||||||
|
lineChartScrollPane.setViewportView(lineChartPanel);
|
||||||
}
|
}
|
||||||
add(scrollPane1, "cell 0 5 2 1");
|
add(lineChartScrollPane, "cell 0 4 2 1");
|
||||||
|
|
||||||
//---- label4 ----
|
//---- lineChartInfoLabel ----
|
||||||
label4.setText("X: time (500ms per line) / Y: value (10% per line)");
|
lineChartInfoLabel.setText("X: time (500ms per line) / Y: value (10% per line)");
|
||||||
add(label4, "cell 0 6 2 1");
|
add(lineChartInfoLabel, "cell 0 5 2 1");
|
||||||
|
|
||||||
//---- updateChartDelayedCheckBox ----
|
//---- updateChartDelayedCheckBox ----
|
||||||
updateChartDelayedCheckBox.setText("Update chart delayed");
|
updateChartDelayedCheckBox.setText("Update chart delayed");
|
||||||
updateChartDelayedCheckBox.setMnemonic('U');
|
updateChartDelayedCheckBox.setMnemonic('U');
|
||||||
updateChartDelayedCheckBox.setSelected(true);
|
|
||||||
updateChartDelayedCheckBox.addActionListener(e -> updateChartDelayedChanged());
|
updateChartDelayedCheckBox.addActionListener(e -> updateChartDelayedChanged());
|
||||||
add(updateChartDelayedCheckBox, "cell 0 6 2 1,alignx right,growx 0");
|
add(updateChartDelayedCheckBox, "cell 0 5 2 1,alignx right,growx 0");
|
||||||
|
|
||||||
//---- clearChartButton ----
|
//---- clearChartButton ----
|
||||||
clearChartButton.setText("Clear Chart");
|
clearChartButton.setText("Clear Chart");
|
||||||
clearChartButton.setMnemonic('C');
|
clearChartButton.setMnemonic('C');
|
||||||
clearChartButton.addActionListener(e -> clearChart());
|
clearChartButton.addActionListener(e -> clearChart());
|
||||||
add(clearChartButton, "cell 0 6 2 1,alignx right,growx 0");
|
add(clearChartButton, "cell 0 5 2 1,alignx right,growx 0");
|
||||||
// JFormDesigner - End of component initialization //GEN-END:initComponents
|
// JFormDesigner - End of component initialization //GEN-END:initComponents
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,14 +229,36 @@ public class FlatAnimatorTest
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseWheelMoved( MouseWheelEvent e ) {
|
public void mouseWheelMoved( MouseWheelEvent e ) {
|
||||||
lineChartPanel.addValue( 0.5 + (e.getWheelRotation() / 10.), true, Color.red );
|
double preciseWheelRotation = e.getPreciseWheelRotation();
|
||||||
|
|
||||||
|
// add a dot in the middle of the chart for the wheel rotation
|
||||||
|
// for unprecise wheels the rotation value is usually -1 or +1
|
||||||
|
// for precise wheels the rotation value is in range ca. -10 to +10,
|
||||||
|
// depending how fast the wheel is rotated
|
||||||
|
lineChartPanel.addValue( 0.5 + (preciseWheelRotation / 20.), true, Color.red );
|
||||||
|
|
||||||
|
// increase/decrease target value if animation is in progress
|
||||||
|
int newValue = (int) ((targetValue < 0 ? value : targetValue) + (STEP * preciseWheelRotation));
|
||||||
|
newValue = Math.min( Math.max( newValue, 0 ), MAX_VALUE );
|
||||||
|
|
||||||
|
if( preciseWheelRotation != 0 &&
|
||||||
|
preciseWheelRotation != e.getWheelRotation() )
|
||||||
|
{
|
||||||
|
// do not use animation for precise scrolling (e.g. with trackpad)
|
||||||
|
|
||||||
|
// stop running animation (if any)
|
||||||
|
animator.stop();
|
||||||
|
|
||||||
|
value = newValue;
|
||||||
|
valueLabel.setText( String.valueOf( value ) );
|
||||||
|
|
||||||
|
lineChartPanel.addValue( value / (double) MAX_VALUE, Color.red );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// start next animation at the current value
|
// start next animation at the current value
|
||||||
startValue = value;
|
startValue = value;
|
||||||
|
targetValue = newValue;
|
||||||
// increase/decrease target value if animation is in progress
|
|
||||||
targetValue = (targetValue < 0 ? value : targetValue) + (STEP * e.getWheelRotation());
|
|
||||||
targetValue = Math.min( Math.max( targetValue, 0 ), MAX_VALUE );
|
|
||||||
|
|
||||||
// restart animator
|
// restart animator
|
||||||
animator.cancel();
|
animator.cancel();
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ 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": "[fill][grow,fill]"
|
"$columnConstraints": "[fill][grow,fill]"
|
||||||
"$rowConstraints": "[][][][][top][400,grow,fill][]"
|
"$rowConstraints": "[][][]para[top][400,grow,fill][]"
|
||||||
} ) {
|
} ) {
|
||||||
name: "this"
|
name: "this"
|
||||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
name: "label1"
|
name: "linearLabel"
|
||||||
"text": "Linear:"
|
"text": "Linear:"
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 0 0"
|
"value": "cell 0 0"
|
||||||
@@ -29,7 +29,7 @@ new FormModel {
|
|||||||
"value": "cell 1 0"
|
"value": "cell 1 0"
|
||||||
} )
|
} )
|
||||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
name: "label2"
|
name: "easeInOutLabel"
|
||||||
"text": "Ease in out:"
|
"text": "Ease in out:"
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 0 1"
|
"value": "cell 0 1"
|
||||||
@@ -55,10 +55,10 @@ new FormModel {
|
|||||||
"value": "cell 0 2"
|
"value": "cell 0 2"
|
||||||
} )
|
} )
|
||||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
name: "label3"
|
name: "mouseWheelTestLabel"
|
||||||
"text": "Mouse wheel test:"
|
"text": "Mouse wheel test:"
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 0 4"
|
"value": "cell 0 3"
|
||||||
} )
|
} )
|
||||||
add( new FormComponent( "com.formdev.flatlaf.testing.FlatAnimatorTest$MouseWheelTestPanel" ) {
|
add( new FormComponent( "com.formdev.flatlaf.testing.FlatAnimatorTest$MouseWheelTestPanel" ) {
|
||||||
name: "mouseWheelTestPanel"
|
name: "mouseWheelTestPanel"
|
||||||
@@ -67,10 +67,11 @@ new FormModel {
|
|||||||
"JavaCodeGenerator.variableLocal": false
|
"JavaCodeGenerator.variableLocal": false
|
||||||
}
|
}
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 1 4,height 100"
|
"value": "cell 1 3,height 100"
|
||||||
} )
|
} )
|
||||||
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: "lineChartScrollPane"
|
||||||
|
"$client.JScrollPane.smoothScrolling": false
|
||||||
add( new FormComponent( "com.formdev.flatlaf.testing.FlatSmoothScrollingTest$LineChartPanel" ) {
|
add( new FormComponent( "com.formdev.flatlaf.testing.FlatSmoothScrollingTest$LineChartPanel" ) {
|
||||||
name: "lineChartPanel"
|
name: "lineChartPanel"
|
||||||
auxiliary() {
|
auxiliary() {
|
||||||
@@ -78,25 +79,24 @@ new FormModel {
|
|||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 0 5 2 1"
|
"value": "cell 0 4 2 1"
|
||||||
} )
|
} )
|
||||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
name: "label4"
|
name: "lineChartInfoLabel"
|
||||||
"text": "X: time (500ms per line) / Y: value (10% per line)"
|
"text": "X: time (500ms per line) / Y: value (10% per line)"
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 0 6 2 1"
|
"value": "cell 0 5 2 1"
|
||||||
} )
|
} )
|
||||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||||
name: "updateChartDelayedCheckBox"
|
name: "updateChartDelayedCheckBox"
|
||||||
"text": "Update chart delayed"
|
"text": "Update chart delayed"
|
||||||
"mnemonic": 85
|
"mnemonic": 85
|
||||||
"selected": true
|
|
||||||
auxiliary() {
|
auxiliary() {
|
||||||
"JavaCodeGenerator.variableLocal": false
|
"JavaCodeGenerator.variableLocal": false
|
||||||
}
|
}
|
||||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "updateChartDelayedChanged", false ) )
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "updateChartDelayedChanged", false ) )
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 0 6 2 1,alignx right,growx 0"
|
"value": "cell 0 5 2 1,alignx right,growx 0"
|
||||||
} )
|
} )
|
||||||
add( new FormComponent( "javax.swing.JButton" ) {
|
add( new FormComponent( "javax.swing.JButton" ) {
|
||||||
name: "clearChartButton"
|
name: "clearChartButton"
|
||||||
@@ -104,7 +104,7 @@ new FormModel {
|
|||||||
"mnemonic": 67
|
"mnemonic": 67
|
||||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "clearChart", false ) )
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "clearChart", false ) )
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 0 6 2 1,alignx right,growx 0"
|
"value": "cell 0 5 2 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 )
|
||||||
|
|||||||
@@ -347,6 +347,7 @@ public class FlatSmoothScrollingTest
|
|||||||
|
|
||||||
//======== scrollPane1 ========
|
//======== scrollPane1 ========
|
||||||
{
|
{
|
||||||
|
scrollPane1.putClientProperty("JScrollPane.smoothScrolling", false);
|
||||||
scrollPane1.setViewportView(lineChartPanel);
|
scrollPane1.setViewportView(lineChartPanel);
|
||||||
}
|
}
|
||||||
add(scrollPane1, "cell 0 5 4 1,width 100");
|
add(scrollPane1, "cell 0 5 4 1,width 100");
|
||||||
@@ -465,7 +466,7 @@ public class FlatSmoothScrollingTest
|
|||||||
implements Scrollable
|
implements Scrollable
|
||||||
{
|
{
|
||||||
private static final int NEW_SEQUENCE_TIME_LAG = 500;
|
private static final int NEW_SEQUENCE_TIME_LAG = 500;
|
||||||
private static final int NEW_SEQUENCE_GAP = 20;
|
private static final int NEW_SEQUENCE_GAP = 50;
|
||||||
|
|
||||||
private int secondWidth = 1000;
|
private int secondWidth = 1000;
|
||||||
|
|
||||||
@@ -538,9 +539,15 @@ public class FlatSmoothScrollingTest
|
|||||||
|
|
||||||
// scroll horizontally
|
// scroll horizontally
|
||||||
if( lastUsedChartColor != null ) {
|
if( lastUsedChartColor != null ) {
|
||||||
|
// compute chart width of last used color and start of last sequence
|
||||||
int[] lastSeqX = new int[1];
|
int[] lastSeqX = new int[1];
|
||||||
int cw = chartWidth( color2dataMap.get( lastUsedChartColor ), lastSeqX );
|
int cw = chartWidth( color2dataMap.get( lastUsedChartColor ), lastSeqX );
|
||||||
scrollRectToVisible( new Rectangle( lastSeqX[0], 0, cw - lastSeqX[0], getHeight() ) );
|
|
||||||
|
// scroll to end of last sequence (of last used color)
|
||||||
|
int lastSeqWidth = cw - lastSeqX[0];
|
||||||
|
int width = Math.min( lastSeqWidth, getParent().getWidth() );
|
||||||
|
int x = cw - width;
|
||||||
|
scrollRectToVisible( new Rectangle( x, 0, width, getHeight() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -148,6 +148,7 @@ new FormModel {
|
|||||||
} )
|
} )
|
||||||
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"
|
||||||
|
"$client.JScrollPane.smoothScrolling": false
|
||||||
add( new FormComponent( "com.formdev.flatlaf.testing.FlatSmoothScrollingTest$LineChartPanel" ) {
|
add( new FormComponent( "com.formdev.flatlaf.testing.FlatSmoothScrollingTest$LineChartPanel" ) {
|
||||||
name: "lineChartPanel"
|
name: "lineChartPanel"
|
||||||
} )
|
} )
|
||||||
|
|||||||
Reference in New Issue
Block a user