mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
FlatAnimatorTest:
- support synchronized line chart - LineChartPanel: added slider to change horizontal scaling - FlatAnimatedIconTest: added line chart panel - FlatAnimatedBorderTest: added line chart panel
This commit is contained in:
@@ -37,6 +37,14 @@ import net.miginfocom.swing.*;
|
||||
public class FlatAnimatedBorderTest
|
||||
extends FlatTestPanel
|
||||
{
|
||||
private static final Color CHART_FADE_1 = Color.blue;
|
||||
private static final Color CHART_FADE_2 = Color.red;
|
||||
private static final Color CHART_MATERIAL_1 = Color.green;
|
||||
private static final Color CHART_MATERIAL_2 = Color.magenta;
|
||||
private static final Color CHART_MINIMAL = Color.orange;
|
||||
|
||||
private static final String CHART_COLOR_KEY = "chartColor";
|
||||
|
||||
public static void main( String[] args ) {
|
||||
SwingUtilities.invokeLater( () -> {
|
||||
FlatTestFrame frame = FlatTestFrame.create( args, "FlatAnimatedBorderTest" );
|
||||
@@ -47,25 +55,43 @@ public class FlatAnimatedBorderTest
|
||||
FlatAnimatedBorderTest() {
|
||||
initComponents();
|
||||
|
||||
textField5.setBorder( new AnimatedFocusFadeBorder() );
|
||||
textField6.setBorder( new AnimatedFocusFadeBorder() );
|
||||
fade1TextField.setBorder( new AnimatedFocusFadeBorder() );
|
||||
fade2TextField.setBorder( new AnimatedFocusFadeBorder() );
|
||||
|
||||
textField1.setBorder( new AnimatedMaterialBorder() );
|
||||
textField2.setBorder( new AnimatedMaterialBorder() );
|
||||
material1TextField.setBorder( new AnimatedMaterialBorder() );
|
||||
material2TextField.setBorder( new AnimatedMaterialBorder() );
|
||||
|
||||
textField4.setBorder( new AnimatedMinimalTestBorder() );
|
||||
minimalTextField.setBorder( new AnimatedMinimalTestBorder() );
|
||||
|
||||
fade1TextField.putClientProperty( CHART_COLOR_KEY, CHART_FADE_1 );
|
||||
fade2TextField.putClientProperty( CHART_COLOR_KEY, CHART_FADE_2 );
|
||||
material1TextField.putClientProperty( CHART_COLOR_KEY, CHART_MATERIAL_1 );
|
||||
material2TextField.putClientProperty( CHART_COLOR_KEY, CHART_MATERIAL_2 );
|
||||
minimalTextField.putClientProperty( CHART_COLOR_KEY, CHART_MINIMAL );
|
||||
|
||||
fade1ChartColor.setForeground( CHART_FADE_1 );
|
||||
fade2ChartColor.setForeground( CHART_FADE_2 );
|
||||
material1ChartColor.setForeground( CHART_MATERIAL_1 );
|
||||
material2ChartColor.setForeground( CHART_MATERIAL_2 );
|
||||
minimalChartColor.setForeground( CHART_MINIMAL );
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
||||
label3 = new JLabel();
|
||||
textField5 = new JTextField();
|
||||
textField6 = new JTextField();
|
||||
lineChartPanel = new FlatAnimatorTest.LineChartPanel();
|
||||
fade1TextField = new JTextField();
|
||||
fade1ChartColor = new FlatAnimatorTest.JChartColor();
|
||||
fade2TextField = new JTextField();
|
||||
fade2ChartColor = new FlatAnimatorTest.JChartColor();
|
||||
label2 = new JLabel();
|
||||
textField1 = new JTextField();
|
||||
textField2 = new JTextField();
|
||||
material1TextField = new JTextField();
|
||||
material1ChartColor = new FlatAnimatorTest.JChartColor();
|
||||
material2TextField = new JTextField();
|
||||
material2ChartColor = new FlatAnimatorTest.JChartColor();
|
||||
label1 = new JLabel();
|
||||
textField4 = new JTextField();
|
||||
minimalTextField = new JTextField();
|
||||
minimalChartColor = new FlatAnimatorTest.JChartColor();
|
||||
durationLabel = new JLabel();
|
||||
durationField = new JSpinner();
|
||||
|
||||
@@ -73,6 +99,8 @@ public class FlatAnimatedBorderTest
|
||||
setLayout(new MigLayout(
|
||||
"insets dialog,hidemode 3",
|
||||
// columns
|
||||
"[fill]" +
|
||||
"[fill]para" +
|
||||
"[fill]",
|
||||
// rows
|
||||
"[]" +
|
||||
@@ -89,19 +117,25 @@ public class FlatAnimatedBorderTest
|
||||
//---- label3 ----
|
||||
label3.setText("Fade:");
|
||||
add(label3, "cell 0 0");
|
||||
add(textField5, "cell 0 1");
|
||||
add(textField6, "cell 0 2");
|
||||
add(lineChartPanel, "cell 2 0 1 10");
|
||||
add(fade1TextField, "cell 0 1");
|
||||
add(fade1ChartColor, "cell 1 1");
|
||||
add(fade2TextField, "cell 0 2");
|
||||
add(fade2ChartColor, "cell 1 2");
|
||||
|
||||
//---- label2 ----
|
||||
label2.setText("Material:");
|
||||
add(label2, "cell 0 3");
|
||||
add(textField1, "cell 0 4");
|
||||
add(textField2, "cell 0 5");
|
||||
add(material1TextField, "cell 0 4");
|
||||
add(material1ChartColor, "cell 1 4");
|
||||
add(material2TextField, "cell 0 5");
|
||||
add(material2ChartColor, "cell 1 5");
|
||||
|
||||
//---- label1 ----
|
||||
label1.setText("Minimal:");
|
||||
add(label1, "cell 0 6");
|
||||
add(textField4, "cell 0 7");
|
||||
add(minimalTextField, "cell 0 7");
|
||||
add(minimalChartColor, "cell 1 7");
|
||||
|
||||
//---- durationLabel ----
|
||||
durationLabel.setText("Duration:");
|
||||
@@ -115,13 +149,19 @@ public class FlatAnimatedBorderTest
|
||||
|
||||
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
|
||||
private JLabel label3;
|
||||
private JTextField textField5;
|
||||
private JTextField textField6;
|
||||
private FlatAnimatorTest.LineChartPanel lineChartPanel;
|
||||
private JTextField fade1TextField;
|
||||
private FlatAnimatorTest.JChartColor fade1ChartColor;
|
||||
private JTextField fade2TextField;
|
||||
private FlatAnimatorTest.JChartColor fade2ChartColor;
|
||||
private JLabel label2;
|
||||
private JTextField textField1;
|
||||
private JTextField textField2;
|
||||
private JTextField material1TextField;
|
||||
private FlatAnimatorTest.JChartColor material1ChartColor;
|
||||
private JTextField material2TextField;
|
||||
private FlatAnimatorTest.JChartColor material2ChartColor;
|
||||
private JLabel label1;
|
||||
private JTextField textField4;
|
||||
private JTextField minimalTextField;
|
||||
private FlatAnimatorTest.JChartColor minimalChartColor;
|
||||
private JLabel durationLabel;
|
||||
private JSpinner durationField;
|
||||
// JFormDesigner - End of variables declaration //GEN-END:variables
|
||||
@@ -154,6 +194,11 @@ public class FlatAnimatedBorderTest
|
||||
Color color = ColorFunctions.mix( Color.red, Color.lightGray, animatedValue );
|
||||
FlatUIUtils.paintOutlinedComponent( g, x, y, width, height, 0, 0, 0, lw, 0,
|
||||
null, color, null );
|
||||
|
||||
if( animatedValue != 0 && animatedValue != 1 ) {
|
||||
Color chartColor = (Color) ((JComponent)c).getClientProperty( CHART_COLOR_KEY );
|
||||
lineChartPanel.lineChart.addValue( animatedValue, chartColor );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -212,6 +257,11 @@ public class FlatAnimatedBorderTest
|
||||
g2d.fill( new Rectangle2D.Float( x2 + (width2 - lw) / 2, y2 + height2 - lh, lw, lh ) );
|
||||
}
|
||||
} );
|
||||
|
||||
if( animatedValue != 0 && animatedValue != 1 ) {
|
||||
Color chartColor = (Color) ((JComponent)c).getClientProperty( CHART_COLOR_KEY );
|
||||
lineChartPanel.lineChart.addValue( animatedValue, chartColor );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -253,6 +303,11 @@ public class FlatAnimatedBorderTest
|
||||
|
||||
g.setColor( Color.blue );
|
||||
g.fillRect( x, y + height - lh, Math.round( width * animatedValue ), lh );
|
||||
|
||||
if( animatedValue != 0 && animatedValue != 1 ) {
|
||||
Color chartColor = (Color) ((JComponent)c).getClientProperty( CHART_COLOR_KEY );
|
||||
lineChartPanel.lineChart.addValue( animatedValue, chartColor );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
JFDML JFormDesigner: "7.0.4.0.360" Java: "16" encoding: "UTF-8"
|
||||
JFDML JFormDesigner: "7.0.5.0.382" Java: "16" encoding: "UTF-8"
|
||||
|
||||
new FormModel {
|
||||
contentType: "form/swing"
|
||||
root: new FormRoot {
|
||||
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||
"$layoutConstraints": "insets dialog,hidemode 3"
|
||||
"$columnConstraints": "[fill]"
|
||||
"$columnConstraints": "[fill][fill]para[fill]"
|
||||
"$rowConstraints": "[][][]para[][][]para[][][grow][]"
|
||||
} ) {
|
||||
name: "this"
|
||||
@@ -15,16 +15,31 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 0"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.testing.FlatAnimatorTest$LineChartPanel" ) {
|
||||
name: "lineChartPanel"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 0 1 10"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JTextField" ) {
|
||||
name: "textField5"
|
||||
name: "fade1TextField"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 1"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.testing.FlatAnimatorTest$JChartColor" ) {
|
||||
name: "fade1ChartColor"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 1"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JTextField" ) {
|
||||
name: "textField6"
|
||||
name: "fade2TextField"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 2"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.testing.FlatAnimatorTest$JChartColor" ) {
|
||||
name: "fade2ChartColor"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 2"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "label2"
|
||||
"text": "Material:"
|
||||
@@ -32,15 +47,25 @@ new FormModel {
|
||||
"value": "cell 0 3"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JTextField" ) {
|
||||
name: "textField1"
|
||||
name: "material1TextField"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 4"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.testing.FlatAnimatorTest$JChartColor" ) {
|
||||
name: "material1ChartColor"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 4"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JTextField" ) {
|
||||
name: "textField2"
|
||||
name: "material2TextField"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 5"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.testing.FlatAnimatorTest$JChartColor" ) {
|
||||
name: "material2ChartColor"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 5"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "label1"
|
||||
"text": "Minimal:"
|
||||
@@ -48,10 +73,15 @@ new FormModel {
|
||||
"value": "cell 0 6"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JTextField" ) {
|
||||
name: "textField4"
|
||||
name: "minimalTextField"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 7"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.testing.FlatAnimatorTest$JChartColor" ) {
|
||||
name: "minimalChartColor"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 7"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "durationLabel"
|
||||
"text": "Duration:"
|
||||
@@ -70,7 +100,7 @@ new FormModel {
|
||||
} )
|
||||
}, new FormLayoutConstraints( null ) {
|
||||
"location": new java.awt.Point( 0, 0 )
|
||||
"size": new java.awt.Dimension( 405, 315 )
|
||||
"size": new java.awt.Dimension( 725, 325 )
|
||||
} )
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,14 @@ import net.miginfocom.swing.*;
|
||||
public class FlatAnimatedIconTest
|
||||
extends FlatTestPanel
|
||||
{
|
||||
private static final Color CHART_RADIO_BUTTON_1 = Color.blue;
|
||||
private static final Color CHART_RADIO_BUTTON_2 = Color.red;
|
||||
private static final Color CHART_RADIO_BUTTON_3 = Color.green;
|
||||
private static final Color CHART_CHECK_BOX_1 = Color.magenta;
|
||||
private static final Color CHART_CHECK_BOX_2 = Color.orange;
|
||||
|
||||
private static final String CHART_COLOR_KEY = "chartColor";
|
||||
|
||||
public static void main( String[] args ) {
|
||||
SwingUtilities.invokeLater( () -> {
|
||||
FlatTestFrame frame = FlatTestFrame.create( args, "FlatAnimatedIconTest" );
|
||||
@@ -50,15 +58,33 @@ public class FlatAnimatedIconTest
|
||||
|
||||
checkBox1.setIcon( new AnimatedSwitchIcon() );
|
||||
checkBox2.setIcon( new AnimatedMinimalTestIcon() );
|
||||
|
||||
radioButton1.putClientProperty( CHART_COLOR_KEY, CHART_RADIO_BUTTON_1 );
|
||||
radioButton2.putClientProperty( CHART_COLOR_KEY, CHART_RADIO_BUTTON_2 );
|
||||
radioButton3.putClientProperty( CHART_COLOR_KEY, CHART_RADIO_BUTTON_3 );
|
||||
checkBox1.putClientProperty( CHART_COLOR_KEY, CHART_CHECK_BOX_1 );
|
||||
checkBox2.putClientProperty( CHART_COLOR_KEY, CHART_CHECK_BOX_2 );
|
||||
|
||||
radioButton1ChartColor.setForeground( CHART_RADIO_BUTTON_1 );
|
||||
radioButton2ChartColor.setForeground( CHART_RADIO_BUTTON_2 );
|
||||
radioButton3ChartColor.setForeground( CHART_RADIO_BUTTON_3 );
|
||||
checkBox1ChartColor.setForeground( CHART_CHECK_BOX_1 );
|
||||
checkBox2ChartColor.setForeground( CHART_CHECK_BOX_2 );
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
||||
radioButton1 = new JRadioButton();
|
||||
radioButton1ChartColor = new FlatAnimatorTest.JChartColor();
|
||||
lineChartPanel = new FlatAnimatorTest.LineChartPanel();
|
||||
radioButton2 = new JRadioButton();
|
||||
radioButton2ChartColor = new FlatAnimatorTest.JChartColor();
|
||||
radioButton3 = new JRadioButton();
|
||||
radioButton3ChartColor = new FlatAnimatorTest.JChartColor();
|
||||
checkBox1 = new JCheckBox();
|
||||
checkBox1ChartColor = new FlatAnimatorTest.JChartColor();
|
||||
checkBox2 = new JCheckBox();
|
||||
checkBox2ChartColor = new FlatAnimatorTest.JChartColor();
|
||||
durationLabel = new JLabel();
|
||||
durationField = new JSpinner();
|
||||
|
||||
@@ -66,8 +92,9 @@ public class FlatAnimatedIconTest
|
||||
setLayout(new MigLayout(
|
||||
"insets dialog,hidemode 3",
|
||||
// columns
|
||||
"[]para" +
|
||||
"[fill]",
|
||||
"[]" +
|
||||
"[fill]para" +
|
||||
"[grow,fill]",
|
||||
// rows
|
||||
"[]" +
|
||||
"[]" +
|
||||
@@ -81,30 +108,36 @@ public class FlatAnimatedIconTest
|
||||
radioButton1.setText("radio 1");
|
||||
radioButton1.setSelected(true);
|
||||
add(radioButton1, "cell 0 0");
|
||||
add(radioButton1ChartColor, "cell 1 0");
|
||||
add(lineChartPanel, "cell 2 0 1 6");
|
||||
|
||||
//---- radioButton2 ----
|
||||
radioButton2.setText("radio 2");
|
||||
add(radioButton2, "cell 0 1");
|
||||
add(radioButton2ChartColor, "cell 1 1");
|
||||
|
||||
//---- radioButton3 ----
|
||||
radioButton3.setText("radio 3");
|
||||
add(radioButton3, "cell 0 2");
|
||||
add(radioButton3ChartColor, "cell 1 2");
|
||||
|
||||
//---- checkBox1 ----
|
||||
checkBox1.setText("switch");
|
||||
add(checkBox1, "cell 0 3");
|
||||
add(checkBox1ChartColor, "cell 1 3");
|
||||
|
||||
//---- checkBox2 ----
|
||||
checkBox2.setText("minimal");
|
||||
add(checkBox2, "cell 0 4");
|
||||
add(checkBox2ChartColor, "cell 1 4");
|
||||
|
||||
//---- durationLabel ----
|
||||
durationLabel.setText("Duration:");
|
||||
add(durationLabel, "cell 0 6 2 1");
|
||||
add(durationLabel, "cell 0 6 3 1");
|
||||
|
||||
//---- durationField ----
|
||||
durationField.setModel(new SpinnerNumberModel(200, 100, null, 50));
|
||||
add(durationField, "cell 0 6 2 1");
|
||||
add(durationField, "cell 0 6 3 1");
|
||||
|
||||
//---- buttonGroup1 ----
|
||||
ButtonGroup buttonGroup1 = new ButtonGroup();
|
||||
@@ -116,10 +149,16 @@ public class FlatAnimatedIconTest
|
||||
|
||||
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
|
||||
private JRadioButton radioButton1;
|
||||
private FlatAnimatorTest.JChartColor radioButton1ChartColor;
|
||||
private FlatAnimatorTest.LineChartPanel lineChartPanel;
|
||||
private JRadioButton radioButton2;
|
||||
private FlatAnimatorTest.JChartColor radioButton2ChartColor;
|
||||
private JRadioButton radioButton3;
|
||||
private FlatAnimatorTest.JChartColor radioButton3ChartColor;
|
||||
private JCheckBox checkBox1;
|
||||
private FlatAnimatorTest.JChartColor checkBox1ChartColor;
|
||||
private JCheckBox checkBox2;
|
||||
private FlatAnimatorTest.JChartColor checkBox2ChartColor;
|
||||
private JLabel durationLabel;
|
||||
private JSpinner durationField;
|
||||
// JFormDesigner - End of variables declaration //GEN-END:variables
|
||||
@@ -163,6 +202,11 @@ public class FlatAnimatedIconTest
|
||||
float xy = (SIZE - dotDiameter) / 2f;
|
||||
g.setColor( color );
|
||||
((Graphics2D)g).fill( new Ellipse2D.Float( xy, xy, dotDiameter, dotDiameter ) );
|
||||
|
||||
if( animatedValue != 0 && animatedValue != 1 ) {
|
||||
Color chartColor = (Color) ((JComponent)c).getClientProperty( CHART_COLOR_KEY );
|
||||
lineChartPanel.lineChart.addValue( animatedValue, chartColor );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -200,6 +244,11 @@ public class FlatAnimatedIconTest
|
||||
int thumbY = y + 2;
|
||||
g.setColor( Color.white );
|
||||
((Graphics2D)g).fill( new Ellipse2D.Float( thumbX, thumbY, thumbSize, thumbSize ) );
|
||||
|
||||
if( animatedValue != 0 && animatedValue != 1 ) {
|
||||
Color chartColor = (Color) ((JComponent)c).getClientProperty( CHART_COLOR_KEY );
|
||||
lineChartPanel.lineChart.addValue( animatedValue, chartColor );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -239,6 +288,11 @@ public class FlatAnimatedIconTest
|
||||
g.setColor( Color.red );
|
||||
g.drawRect( x, y, w - 1, h - 1 );
|
||||
g.fillRect( x, y, Math.round( w * animatedValue ), h );
|
||||
|
||||
if( animatedValue != 0 && animatedValue != 1 ) {
|
||||
Color chartColor = (Color) ((JComponent)c).getClientProperty( CHART_COLOR_KEY );
|
||||
lineChartPanel.lineChart.addValue( animatedValue, chartColor );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
JFDML JFormDesigner: "7.0.2.0.298" Java: "15" encoding: "UTF-8"
|
||||
JFDML JFormDesigner: "7.0.5.0.382" Java: "16" encoding: "UTF-8"
|
||||
|
||||
new FormModel {
|
||||
contentType: "form/swing"
|
||||
root: new FormRoot {
|
||||
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||
"$layoutConstraints": "insets dialog,hidemode 3"
|
||||
"$columnConstraints": "[]para[fill]"
|
||||
"$columnConstraints": "[][fill]para[grow,fill]"
|
||||
"$rowConstraints": "[][][]para[][][grow][]"
|
||||
} ) {
|
||||
name: "this"
|
||||
@@ -17,6 +17,16 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 0"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.testing.FlatAnimatorTest$JChartColor" ) {
|
||||
name: "radioButton1ChartColor"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 0"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.testing.FlatAnimatorTest$LineChartPanel" ) {
|
||||
name: "lineChartPanel"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 0 1 6"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JRadioButton" ) {
|
||||
name: "radioButton2"
|
||||
"text": "radio 2"
|
||||
@@ -24,6 +34,11 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 1"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.testing.FlatAnimatorTest$JChartColor" ) {
|
||||
name: "radioButton2ChartColor"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 1"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JRadioButton" ) {
|
||||
name: "radioButton3"
|
||||
"text": "radio 3"
|
||||
@@ -31,23 +46,38 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 2"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.testing.FlatAnimatorTest$JChartColor" ) {
|
||||
name: "radioButton3ChartColor"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 2"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||
name: "checkBox1"
|
||||
"text": "switch"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 3"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.testing.FlatAnimatorTest$JChartColor" ) {
|
||||
name: "checkBox1ChartColor"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 3"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||
name: "checkBox2"
|
||||
"text": "minimal"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 4"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.testing.FlatAnimatorTest$JChartColor" ) {
|
||||
name: "checkBox2ChartColor"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 4"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "durationLabel"
|
||||
"text": "Duration:"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 6 2 1"
|
||||
"value": "cell 0 6 3 1"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JSpinner" ) {
|
||||
name: "durationField"
|
||||
@@ -57,11 +87,11 @@ new FormModel {
|
||||
value: 200
|
||||
}
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 6 2 1"
|
||||
"value": "cell 0 6 3 1"
|
||||
} )
|
||||
}, new FormLayoutConstraints( null ) {
|
||||
"location": new java.awt.Point( 0, 0 )
|
||||
"size": new java.awt.Dimension( 415, 350 )
|
||||
"size": new java.awt.Dimension( 810, 350 )
|
||||
} )
|
||||
add( new FormNonVisual( "javax.swing.ButtonGroup" ) {
|
||||
name: "buttonGroup1"
|
||||
|
||||
@@ -170,8 +170,17 @@ public class FlatAnimatorTest
|
||||
LineChartPanel() {
|
||||
initComponents();
|
||||
|
||||
secondsWidthSlider.setValue( lineChart.getSecondsWidth() );
|
||||
updateChartDelayedChanged();
|
||||
lineChart.setSecondWidth( 500 );
|
||||
}
|
||||
|
||||
void setSecondsWidth( int secondsWidth ) {
|
||||
lineChart.setSecondsWidth( secondsWidth );
|
||||
secondsWidthSlider.setValue( secondsWidth );
|
||||
}
|
||||
|
||||
private void secondsWidthChanged() {
|
||||
lineChart.setSecondsWidth( secondsWidthSlider.getValue() );
|
||||
}
|
||||
|
||||
private void updateChartDelayedChanged() {
|
||||
@@ -187,6 +196,7 @@ public class FlatAnimatorTest
|
||||
JScrollPane lineChartScrollPane = new JScrollPane();
|
||||
lineChart = new FlatAnimatorTest.LineChart();
|
||||
JLabel lineChartInfoLabel = new JLabel();
|
||||
secondsWidthSlider = new JSlider();
|
||||
updateChartDelayedCheckBox = new JCheckBox();
|
||||
JButton clearChartButton = new JButton();
|
||||
|
||||
@@ -211,6 +221,12 @@ public class FlatAnimatorTest
|
||||
lineChartInfoLabel.setText("X: time (500ms per line) / Y: value (10% per line)");
|
||||
add(lineChartInfoLabel, "cell 0 1 2 1");
|
||||
|
||||
//---- secondsWidthSlider ----
|
||||
secondsWidthSlider.setMinimum(100);
|
||||
secondsWidthSlider.setMaximum(2000);
|
||||
secondsWidthSlider.addChangeListener(e -> secondsWidthChanged());
|
||||
add(secondsWidthSlider, "cell 0 1 2 1");
|
||||
|
||||
//---- updateChartDelayedCheckBox ----
|
||||
updateChartDelayedCheckBox.setText("Update chart delayed");
|
||||
updateChartDelayedCheckBox.setMnemonic('U');
|
||||
@@ -227,6 +243,7 @@ public class FlatAnimatorTest
|
||||
|
||||
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
|
||||
FlatAnimatorTest.LineChart lineChart;
|
||||
private JSlider secondsWidthSlider;
|
||||
private JCheckBox updateChartDelayedCheckBox;
|
||||
// JFormDesigner - End of variables declaration //GEN-END:variables
|
||||
}
|
||||
@@ -238,18 +255,21 @@ public class FlatAnimatorTest
|
||||
implements Scrollable
|
||||
{
|
||||
private static final int NEW_SEQUENCE_TIME_LAG = 500;
|
||||
private static final int NEW_SEQUENCE_GAP = 50;
|
||||
private static final int NEW_SEQUENCE_GAP = 100;
|
||||
|
||||
private int secondWidth = 1000;
|
||||
private boolean asynchron;
|
||||
private int secondsWidth = 500;
|
||||
|
||||
private static class Data {
|
||||
final double value;
|
||||
final boolean dot;
|
||||
final Color chartColor;
|
||||
final long time; // in milliseconds
|
||||
|
||||
Data( double value, boolean dot, long time ) {
|
||||
Data( double value, boolean dot, Color chartColor, long time ) {
|
||||
this.value = value;
|
||||
this.dot = dot;
|
||||
this.chartColor = chartColor;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
@@ -260,7 +280,8 @@ public class FlatAnimatorTest
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<Color, List<Data>> color2dataMap = new HashMap<>();
|
||||
private final List<Data> syncChartData = new ArrayList<>();
|
||||
private final Map<Color, List<Data>> asyncColor2dataMap = new HashMap<>();
|
||||
private final Timer repaintTime;
|
||||
private Color lastUsedChartColor;
|
||||
private boolean updateDelayed;
|
||||
@@ -270,13 +291,24 @@ public class FlatAnimatorTest
|
||||
repaintTime.setRepeats( false );
|
||||
}
|
||||
|
||||
void enableAsynchron() {
|
||||
if( !syncChartData.isEmpty() )
|
||||
throw new IllegalStateException();
|
||||
|
||||
asynchron = true;
|
||||
}
|
||||
|
||||
void addValue( double value, Color chartColor ) {
|
||||
addValue( value, false, chartColor );
|
||||
}
|
||||
|
||||
void addValue( double value, boolean dot, Color chartColor ) {
|
||||
List<Data> chartData = color2dataMap.computeIfAbsent( chartColor, k -> new ArrayList<>() );
|
||||
chartData.add( new Data( value, dot, System.nanoTime() / 1000000) );
|
||||
List<Data> chartData = asyncColor2dataMap.computeIfAbsent( chartColor, k -> new ArrayList<>() );
|
||||
Data data = new Data( value, dot, chartColor, System.nanoTime() / 1000000 );
|
||||
if( asynchron )
|
||||
chartData.add( data );
|
||||
else
|
||||
syncChartData.add( data );
|
||||
|
||||
lastUsedChartColor = chartColor;
|
||||
|
||||
@@ -288,7 +320,8 @@ public class FlatAnimatorTest
|
||||
}
|
||||
|
||||
void clear() {
|
||||
color2dataMap.clear();
|
||||
syncChartData.clear();
|
||||
asyncColor2dataMap.clear();
|
||||
lastUsedChartColor = null;
|
||||
|
||||
repaint();
|
||||
@@ -299,8 +332,14 @@ public class FlatAnimatorTest
|
||||
this.updateDelayed = updateDelayed;
|
||||
}
|
||||
|
||||
void setSecondWidth( int secondWidth ) {
|
||||
this.secondWidth = secondWidth;
|
||||
int getSecondsWidth() {
|
||||
return secondsWidth;
|
||||
}
|
||||
|
||||
void setSecondsWidth( int secondsWidth ) {
|
||||
this.secondsWidth = secondsWidth;
|
||||
repaint();
|
||||
revalidate();
|
||||
}
|
||||
|
||||
private void repaintAndRevalidate() {
|
||||
@@ -311,7 +350,7 @@ public class FlatAnimatorTest
|
||||
if( lastUsedChartColor != null ) {
|
||||
// compute chart width of last used color and start of last sequence
|
||||
int[] lastSeqX = new int[1];
|
||||
int cw = chartWidth( color2dataMap.get( lastUsedChartColor ), lastSeqX );
|
||||
int cw = chartWidth( asynchron ? asyncColor2dataMap.get( lastUsedChartColor ) : syncChartData, lastSeqX );
|
||||
|
||||
// scroll to end of last sequence (of last used color)
|
||||
int lastSeqWidth = cw - lastSeqX[0];
|
||||
@@ -334,8 +373,7 @@ public class FlatAnimatorTest
|
||||
private void paintImpl( Graphics2D g, int x, int y, int width, int height, double scaleFactor ) {
|
||||
FlatUIUtils.setRenderingHints( g );
|
||||
|
||||
int secondWidth = (int) (this.secondWidth * scaleFactor);
|
||||
int seqGapWidth = (int) (NEW_SEQUENCE_GAP * scaleFactor);
|
||||
int secondsWidth = (int) (this.secondsWidth * scaleFactor);
|
||||
|
||||
Color lineColor = FlatUIUtils.getUIColor( "Component.borderColor", Color.lightGray );
|
||||
Color lineColor2 = FlatLaf.isLafDark()
|
||||
@@ -356,72 +394,86 @@ public class FlatAnimatorTest
|
||||
}
|
||||
|
||||
// paint vertical lines
|
||||
int twoHundredMillisWidth = secondWidth / 5;
|
||||
int twoHundredMillisWidth = secondsWidth / 5;
|
||||
for( int i = twoHundredMillisWidth; i < width; i += twoHundredMillisWidth ) {
|
||||
g.setColor( (i % secondWidth != 0) ? lineColor : lineColor2 );
|
||||
g.setColor( (i % secondsWidth != 0) ? lineColor : lineColor2 );
|
||||
g.drawLine( i, 0, i, height );
|
||||
}
|
||||
|
||||
// paint lines
|
||||
for( Map.Entry<Color, List<Data>> e : color2dataMap.entrySet() ) {
|
||||
List<Data> chartData = e.getValue();
|
||||
for( Map.Entry<Color, List<Data>> e : asyncColor2dataMap.entrySet() ) {
|
||||
List<Data> chartData = asynchron ? e.getValue() : syncChartData;
|
||||
Color chartColor = e.getKey();
|
||||
if( FlatLaf.isLafDark() )
|
||||
chartColor = new HSLColor( chartColor ).adjustTone( 50 );
|
||||
Color temporaryValueColor = new Color( (chartColor.getRGB() & 0xffffff) | 0x40000000, true );
|
||||
paintChartData( g, chartData, chartColor, height, scaleFactor );
|
||||
}
|
||||
}
|
||||
|
||||
long seqTime = 0;
|
||||
int seqX = 0;
|
||||
long ptime = 0;
|
||||
int px = 0;
|
||||
int py = 0;
|
||||
int pcount = 0;
|
||||
private void paintChartData( Graphics2D g, List<Data> chartData, Color chartColor, int height, double scaleFactor ) {
|
||||
if( FlatLaf.isLafDark() )
|
||||
chartColor = new HSLColor( chartColor ).adjustTone( 50 );
|
||||
Color temporaryValueColor = new Color( (chartColor.getRGB() & 0xffffff) | 0x40000000, true );
|
||||
|
||||
g.setColor( chartColor );
|
||||
int seqGapWidth = (int) (NEW_SEQUENCE_GAP * scaleFactor);
|
||||
long seqTime = 0;
|
||||
int seqX = 0;
|
||||
long ptime = 0;
|
||||
int px = 0;
|
||||
int py = height - 1;
|
||||
int cx = px;
|
||||
int cy = py;
|
||||
int pcount = 0;
|
||||
|
||||
boolean first = true;
|
||||
int size = chartData.size();
|
||||
for( int i = 0; i < size; i++ ) {
|
||||
Data data = chartData.get( i );
|
||||
int dy = (int) ((height - 1) * data.value);
|
||||
g.setColor( chartColor );
|
||||
|
||||
if( data.dot ) {
|
||||
int dotx = px;
|
||||
if( i > 0 && data.time > ptime + NEW_SEQUENCE_TIME_LAG )
|
||||
dotx += seqGapWidth;
|
||||
int o = UIScale.scale( 1 );
|
||||
int s = UIScale.scale( 3 );
|
||||
g.fillRect( dotx - o, dy - o, s, s );
|
||||
continue;
|
||||
}
|
||||
boolean first = true;
|
||||
int size = chartData.size();
|
||||
for( int i = 0; i < size; i++ ) {
|
||||
Data data = chartData.get( i );
|
||||
boolean useData = (data.chartColor == chartColor);
|
||||
int dy = height - 1 - (int) ((height - 1) * data.value);
|
||||
|
||||
if( data.time > ptime + NEW_SEQUENCE_TIME_LAG ) {
|
||||
if( !first && pcount == 0 )
|
||||
g.drawLine( px, py, px + (int) (4 * scaleFactor), py );
|
||||
if( data.dot ) {
|
||||
int dotx = px;
|
||||
if( i > 0 && data.time > ptime + NEW_SEQUENCE_TIME_LAG )
|
||||
dotx += seqGapWidth;
|
||||
int o = UIScale.scale( 1 );
|
||||
int s = UIScale.scale( 3 );
|
||||
g.fillRect( dotx - o, dy - o, s, s );
|
||||
continue;
|
||||
}
|
||||
|
||||
// start new sequence
|
||||
seqTime = data.time;
|
||||
seqX = !first ? px + seqGapWidth : 0;
|
||||
px = seqX;
|
||||
pcount = 0;
|
||||
first = false;
|
||||
} else {
|
||||
boolean isTemporaryValue = isTemporaryValue( chartData, i ) || isTemporaryValue( chartData, i - 1 );
|
||||
if( isTemporaryValue )
|
||||
g.setColor( temporaryValueColor );
|
||||
if( data.time > ptime + NEW_SEQUENCE_TIME_LAG ) {
|
||||
if( !first && pcount == 0 )
|
||||
g.drawLine( px, py, px + (int) (4 * scaleFactor), py );
|
||||
|
||||
// line in sequence
|
||||
int dx = (int) (seqX + (((data.time - seqTime) / 1000.) * secondWidth));
|
||||
g.drawLine( px, py, dx, dy );
|
||||
px = dx;
|
||||
pcount++;
|
||||
// start new sequence
|
||||
seqTime = data.time;
|
||||
seqX = !first ? px + seqGapWidth : 0;
|
||||
px = seqX;
|
||||
pcount = 0;
|
||||
first = false;
|
||||
} else {
|
||||
boolean isTemporaryValue = isTemporaryValue( chartData, i ) || isTemporaryValue( chartData, i - 1 );
|
||||
if( isTemporaryValue )
|
||||
g.setColor( temporaryValueColor );
|
||||
|
||||
if( isTemporaryValue )
|
||||
g.setColor( chartColor );
|
||||
}
|
||||
// line in sequence
|
||||
int dx = (int) (seqX + (((data.time - seqTime) / 1000.) * secondsWidth));
|
||||
if( useData )
|
||||
g.drawLine( cx, cy, dx, dy );
|
||||
px = dx;
|
||||
pcount++;
|
||||
|
||||
py = dy;
|
||||
ptime = data.time;
|
||||
if( isTemporaryValue )
|
||||
g.setColor( chartColor );
|
||||
}
|
||||
|
||||
py = dy;
|
||||
ptime = data.time;
|
||||
|
||||
if( useData ) {
|
||||
cx = px;
|
||||
cy = py;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -450,8 +502,11 @@ public class FlatAnimatorTest
|
||||
|
||||
private int chartWidth() {
|
||||
int width = 0;
|
||||
for( List<Data> chartData : color2dataMap.values() )
|
||||
width = Math.max( width, chartWidth( chartData, null ) );
|
||||
if( asynchron ) {
|
||||
for( List<Data> chartData : asyncColor2dataMap.values() )
|
||||
width = Math.max( width, chartWidth( chartData, null ) );
|
||||
} else
|
||||
width = Math.max( width, chartWidth( syncChartData, null ) );
|
||||
return width;
|
||||
}
|
||||
|
||||
@@ -472,7 +527,7 @@ public class FlatAnimatorTest
|
||||
px = seqX;
|
||||
} else {
|
||||
// line in sequence
|
||||
int dx = (int) (seqX + (((data.time - seqTime) / 1000.) * secondWidth));
|
||||
int dx = (int) (seqX + (((data.time - seqTime) / 1000.) * secondsWidth));
|
||||
px = dx;
|
||||
}
|
||||
|
||||
@@ -497,7 +552,7 @@ public class FlatAnimatorTest
|
||||
|
||||
@Override
|
||||
public int getScrollableUnitIncrement( Rectangle visibleRect, int orientation, int direction ) {
|
||||
return secondWidth;
|
||||
return secondsWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -528,6 +583,11 @@ public class FlatAnimatorTest
|
||||
return new Dimension( UIScale.scale( 24 ), UIScale.scale( 12 ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getMinimumSize() {
|
||||
return getPreferredSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent( Graphics g ) {
|
||||
g.setColor( getForeground() );
|
||||
|
||||
@@ -143,6 +143,17 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 1 2 1"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JSlider" ) {
|
||||
name: "secondsWidthSlider"
|
||||
"minimum": 100
|
||||
"maximum": 2000
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
addEvent( new FormEvent( "javax.swing.event.ChangeListener", "stateChanged", "secondsWidthChanged", false ) )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 1 2 1"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||
name: "updateChartDelayedCheckBox"
|
||||
"text": "Update chart delayed"
|
||||
|
||||
Reference in New Issue
Block a user