Merge pull request #214 into master

Slider redesign
This commit is contained in:
Karl Tauber
2020-12-04 22:43:05 +01:00
25 changed files with 895 additions and 245 deletions

View File

@@ -286,6 +286,7 @@ public class FlatComponentsTest
JLabel sliderLabel = new JLabel();
JSlider slider1 = new JSlider();
JSlider slider6 = new JSlider();
JLabel sliderLabel2 = new JLabel();
slider3 = new JSlider();
JSlider slider5 = new JSlider();
JLabel progressBarLabel = new JLabel();
@@ -1200,12 +1201,16 @@ public class FlatComponentsTest
//---- slider1 ----
slider1.setValue(30);
add(slider1, "cell 1 19 3 1,aligny top,grow 100 0");
add(slider1, "cell 1 19 3 1,growx");
//---- slider6 ----
slider6.setEnabled(false);
slider6.setValue(30);
add(slider6, "cell 1 19 3 1,aligny top,growy 0");
add(slider6, "cell 1 19 3 1");
//---- sliderLabel2 ----
sliderLabel2.setText("baseline");
add(sliderLabel2, "cell 0 20,alignx right,growx 0");
//---- slider3 ----
slider3.setMinorTickSpacing(10);
@@ -1214,7 +1219,7 @@ public class FlatComponentsTest
slider3.setPaintLabels(true);
slider3.setValue(30);
slider3.addChangeListener(e -> changeProgress());
add(slider3, "cell 1 20 3 1,aligny top,grow 100 0");
add(slider3, "cell 1 20 3 1,growx");
//---- slider5 ----
slider5.setMinorTickSpacing(10);
@@ -1223,7 +1228,7 @@ public class FlatComponentsTest
slider5.setPaintLabels(true);
slider5.setEnabled(false);
slider5.setValue(30);
add(slider5, "cell 1 20 3 1,aligny top,growy 0");
add(slider5, "cell 1 20 3 1");
//---- progressBarLabel ----
progressBarLabel.setText("JProgressBar:");

View File

@@ -1141,14 +1141,20 @@ new FormModel {
name: "slider1"
"value": 30
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 19 3 1,aligny top,grow 100 0"
"value": "cell 1 19 3 1,growx"
} )
add( new FormComponent( "javax.swing.JSlider" ) {
name: "slider6"
"enabled": false
"value": 30
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 19 3 1,aligny top,growy 0"
"value": "cell 1 19 3 1"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "sliderLabel2"
"text": "baseline"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 20,alignx right,growx 0"
} )
add( new FormComponent( "javax.swing.JSlider" ) {
name: "slider3"
@@ -1162,7 +1168,7 @@ new FormModel {
}
addEvent( new FormEvent( "javax.swing.event.ChangeListener", "stateChanged", "changeProgress", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 20 3 1,aligny top,grow 100 0"
"value": "cell 1 20 3 1,growx"
} )
add( new FormComponent( "javax.swing.JSlider" ) {
name: "slider5"
@@ -1173,7 +1179,7 @@ new FormModel {
"enabled": false
"value": 30
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 20 3 1,aligny top,growy 0"
"value": "cell 1 20 3 1"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "progressBarLabel"

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2020 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.jideoss;
import com.formdev.flatlaf.FlatDefaultsAddon;
/**
* JIDE Common Layer addon for FlatLaf for testing.
* <p>
* Finds JIDE Common Layer addon .properties file for the given LaF class
* in the same package as this class.
*
* @author Karl Tauber
*/
public class FlatJideOssDefaultsTestAddon
extends FlatDefaultsAddon
{
}

View File

@@ -18,6 +18,7 @@ package com.formdev.flatlaf.testing.jideoss;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JSlider;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
@@ -50,13 +51,19 @@ public class FlatRangeSliderTest
}
private void paintLabels() {
horizontalRangeSlider.setPaintLabels( paintLabel.isSelected() );
verticalRangeSlider.setPaintLabels( paintLabel.isSelected() );
boolean selected = paintLabel.isSelected();
horizontalRangeSlider.setPaintLabels( selected );
verticalRangeSlider.setPaintLabels( selected );
horizontalSlider.setPaintLabels( selected );
verticalSlider.setPaintLabels( selected );
}
private void paintTicks() {
horizontalRangeSlider.setPaintTicks( paintTick.isSelected() );
verticalRangeSlider.setPaintTicks( paintTick.isSelected() );
boolean selected = paintTick.isSelected();
horizontalRangeSlider.setPaintTicks( selected );
verticalRangeSlider.setPaintTicks( selected );
horizontalSlider.setPaintTicks( selected );
verticalSlider.setPaintTicks( selected );
}
private void initComponents() {
@@ -64,8 +71,14 @@ public class FlatRangeSliderTest
JLabel tabbedPaneLabel = new JLabel();
JLabel horizontalLabel = new JLabel();
horizontalRangeSlider = new RangeSlider();
horizontalSlider = new JSlider();
horizontalRangeSlider2 = new RangeSlider();
horizontalSlider2 = new JSlider();
JLabel verticalLabel = new JLabel();
verticalRangeSlider = new RangeSlider();
verticalSlider = new JSlider();
verticalRangeSlider2 = new RangeSlider();
verticalSlider2 = new JSlider();
paintTick = new JCheckBox();
paintLabel = new JCheckBox();
@@ -74,10 +87,13 @@ public class FlatRangeSliderTest
"insets dialog,hidemode 3",
// columns
"[left]" +
"[fill]",
"[240,left]",
// rows
"[fill]" +
"[center]" +
"[]" +
"[]" +
"[]" +
"[grow,fill]" +
"[]"));
@@ -88,57 +104,92 @@ public class FlatRangeSliderTest
//---- horizontalLabel ----
horizontalLabel.setText("Horizontal");
add(horizontalLabel, "cell 0 1");
add(horizontalRangeSlider, "cell 1 1");
//---- horizontalRangeSlider ----
horizontalRangeSlider.setLowValue(30);
horizontalRangeSlider.setHighValue(80);
horizontalRangeSlider.setMajorTickSpacing(10);
horizontalRangeSlider.setMinorTickSpacing(5);
horizontalRangeSlider.setPaintTicks(true);
horizontalRangeSlider.setPaintLabels(true);
add(horizontalRangeSlider, "cell 1 1,growx");
//---- horizontalSlider ----
horizontalSlider.setMinorTickSpacing(5);
horizontalSlider.setPaintTicks(true);
horizontalSlider.setMajorTickSpacing(10);
horizontalSlider.setPaintLabels(true);
horizontalSlider.setValue(30);
add(horizontalSlider, "cell 1 2,growx");
//---- horizontalRangeSlider2 ----
horizontalRangeSlider2.setLowValue(30);
horizontalRangeSlider2.setHighValue(80);
add(horizontalRangeSlider2, "cell 1 3,growx");
//---- horizontalSlider2 ----
horizontalSlider2.setValue(30);
add(horizontalSlider2, "cell 1 4,growx");
//---- verticalLabel ----
verticalLabel.setText("Vertical");
add(verticalLabel, "cell 0 2,aligny top,growy 0");
add(verticalLabel, "cell 0 5,aligny top,growy 0");
//---- verticalRangeSlider ----
verticalRangeSlider.setOrientation(SwingConstants.VERTICAL);
add(verticalRangeSlider, "cell 1 2,alignx left,growx 0");
verticalRangeSlider.setLowValue(30);
verticalRangeSlider.setHighValue(80);
verticalRangeSlider.setMajorTickSpacing(10);
verticalRangeSlider.setMinorTickSpacing(5);
verticalRangeSlider.setPaintTicks(true);
verticalRangeSlider.setPaintLabels(true);
add(verticalRangeSlider, "cell 1 5,alignx left,growx 0");
//---- verticalSlider ----
verticalSlider.setMinorTickSpacing(5);
verticalSlider.setPaintTicks(true);
verticalSlider.setMajorTickSpacing(10);
verticalSlider.setPaintLabels(true);
verticalSlider.setOrientation(SwingConstants.VERTICAL);
verticalSlider.setValue(30);
add(verticalSlider, "cell 1 5");
//---- verticalRangeSlider2 ----
verticalRangeSlider2.setOrientation(SwingConstants.VERTICAL);
verticalRangeSlider2.setLowValue(30);
verticalRangeSlider2.setHighValue(80);
add(verticalRangeSlider2, "cell 1 5");
//---- verticalSlider2 ----
verticalSlider2.setOrientation(SwingConstants.VERTICAL);
verticalSlider2.setValue(30);
add(verticalSlider2, "cell 1 5");
//---- paintTick ----
paintTick.setText("PaintTicks");
paintTick.setMnemonic('T');
paintTick.setSelected(true);
paintTick.addActionListener(e -> paintTicks());
add(paintTick, "cell 0 3 2 1");
add(paintTick, "cell 0 6 2 1");
//---- paintLabel ----
paintLabel.setText("PaintLabels");
paintLabel.setMnemonic('L');
paintLabel.setSelected(true);
paintLabel.addActionListener(e -> paintLabels());
add(paintLabel, "cell 0 3 2 1");
add(paintLabel, "cell 0 6 2 1");
// JFormDesigner - End of component initialization //GEN-END:initComponents
horizontalRangeSlider.setOrientation( SwingConstants.HORIZONTAL );
horizontalRangeSlider.setMinimum( 0 );
horizontalRangeSlider.setMaximum( 100 );
horizontalRangeSlider.setLowValue( 10 );
horizontalRangeSlider.setHighValue( 90 );
horizontalRangeSlider.setLabelTable( horizontalRangeSlider.createStandardLabels( 10 ) );
horizontalRangeSlider.setMinorTickSpacing( 5 );
horizontalRangeSlider.setMajorTickSpacing( 10 );
horizontalRangeSlider.setPaintTicks( true );
horizontalRangeSlider.setPaintLabels( true );
verticalRangeSlider.setOrientation( SwingConstants.VERTICAL );
verticalRangeSlider.setMinimum( 0 );
verticalRangeSlider.setMaximum( 100 );
verticalRangeSlider.setLowValue( 10 );
verticalRangeSlider.setHighValue( 90 );
verticalRangeSlider.setLabelTable( horizontalRangeSlider.createStandardLabels( 10 ) );
verticalRangeSlider.setMinorTickSpacing( 5 );
verticalRangeSlider.setMajorTickSpacing( 10 );
verticalRangeSlider.setPaintTicks( true );
verticalRangeSlider.setPaintLabels( true );
}
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
private RangeSlider horizontalRangeSlider;
private JSlider horizontalSlider;
private RangeSlider horizontalRangeSlider2;
private JSlider horizontalSlider2;
private RangeSlider verticalRangeSlider;
private JSlider verticalSlider;
private RangeSlider verticalRangeSlider2;
private JSlider verticalSlider2;
private JCheckBox paintTick;
private JCheckBox paintLabel;
// JFormDesigner - End of variables declaration //GEN-END:variables

View File

@@ -8,8 +8,8 @@ new FormModel {
}
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "insets dialog,hidemode 3"
"$columnConstraints": "[left][fill]"
"$rowConstraints": "[fill][center][grow,fill][]"
"$columnConstraints": "[left][240,left]"
"$rowConstraints": "[fill][center][][][][grow,fill][]"
} ) {
name: "this"
add( new FormComponent( "javax.swing.JLabel" ) {
@@ -26,26 +26,105 @@ new FormModel {
} )
add( new FormComponent( "com.jidesoft.swing.RangeSlider" ) {
name: "horizontalRangeSlider"
"lowValue": 30
"highValue": 80
"majorTickSpacing": 10
"minorTickSpacing": 5
"paintTicks": true
"paintLabels": true
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 1"
"value": "cell 1 1,growx"
} )
add( new FormComponent( "javax.swing.JSlider" ) {
name: "horizontalSlider"
"minorTickSpacing": 5
"paintTicks": true
"majorTickSpacing": 10
"paintLabels": true
"value": 30
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 2,growx"
} )
add( new FormComponent( "com.jidesoft.swing.RangeSlider" ) {
name: "horizontalRangeSlider2"
"lowValue": 30
"highValue": 80
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 3,growx"
} )
add( new FormComponent( "javax.swing.JSlider" ) {
name: "horizontalSlider2"
"value": 30
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 4,growx"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "verticalLabel"
"text": "Vertical"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 2,aligny top,growy 0"
"value": "cell 0 5,aligny top,growy 0"
} )
add( new FormComponent( "com.jidesoft.swing.RangeSlider" ) {
name: "verticalRangeSlider"
"orientation": 1
"lowValue": 30
"highValue": 80
"majorTickSpacing": 10
"minorTickSpacing": 5
"paintTicks": true
"paintLabels": true
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 2,alignx left,growx 0"
"value": "cell 1 5,alignx left,growx 0"
} )
add( new FormComponent( "javax.swing.JSlider" ) {
name: "verticalSlider"
"minorTickSpacing": 5
"paintTicks": true
"majorTickSpacing": 10
"paintLabels": true
"orientation": 1
"value": 30
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 5"
} )
add( new FormComponent( "com.jidesoft.swing.RangeSlider" ) {
name: "verticalRangeSlider2"
"orientation": 1
"lowValue": 30
"highValue": 80
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 5"
} )
add( new FormComponent( "javax.swing.JSlider" ) {
name: "verticalSlider2"
"orientation": 1
"value": 30
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 5"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "paintTick"
@@ -57,7 +136,7 @@ new FormModel {
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "paintTicks", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 3 2 1"
"value": "cell 0 6 2 1"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "paintLabel"
@@ -69,7 +148,7 @@ new FormModel {
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "paintLabels", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 3 2 1"
"value": "cell 0 6 2 1"
} )
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 )

View File

@@ -64,6 +64,7 @@ import com.formdev.flatlaf.intellijthemes.FlatAllIJThemes;
import com.formdev.flatlaf.testing.FlatTestLaf;
import com.formdev.flatlaf.ui.FlatLineBorder;
import com.formdev.flatlaf.util.ColorFunctions.ColorFunction;
import com.formdev.flatlaf.util.ColorFunctions.Fade;
import com.formdev.flatlaf.util.ColorFunctions.HSLIncreaseDecrease;
import com.formdev.flatlaf.util.DerivedColor;
import com.formdev.flatlaf.util.StringUtils;
@@ -399,13 +400,18 @@ public class UIDefaultsDump
HSLIncreaseDecrease func = (HSLIncreaseDecrease) function;
String name;
switch( func.hslIndex ) {
case 2: name = func.increase ? "lighten" : "darken"; break;
case 0: name = "spin"; break;
case 1: name = func.increase ? "saturate" : "desaturate"; break;
case 2: name = func.increase ? "lighten" : "darken"; break;
case 3: name = func.increase ? "fadein" : "fadeout"; break;
default: throw new IllegalArgumentException();
}
out.printf( "%s(%.0f%%%s%s)", name, func.amount,
(func.relative ? " relative" : ""),
(func.autoInverse ? " autoInverse" : "") );
} else if( function instanceof Fade ) {
Fade func = (Fade) function;
out.printf( "fade(%.0f%%)", func.amount );
} else
throw new IllegalArgumentException( "unknown color function: " + function );
}