added system properties "flatlaf.animation" and "flatlaf.smoothScrolling" to disable all animations or smooth scrolling via command line (without modifying the application)

This commit is contained in:
Karl Tauber
2020-08-08 16:19:36 +02:00
parent fdabca99b2
commit 1ebfe00f3c
7 changed files with 53 additions and 2 deletions

View File

@@ -132,6 +132,14 @@ public interface FlatSystemProperties
*/
String ANIMATION = "flatlaf.animation";
/**
* Specifies whether smooth scrolling is enabled.
* <p>
* <strong>Allowed Values</strong> {@code false} and {@code true}<br>
* <strong>Default</strong> {@code true}
*/
String SMOOTH_SCROLLING = "flatlaf.smoothScrolling";
/**
* Specifies whether vertical text position is corrected when UI is scaled on HiDPI screens.
* <p>

View File

@@ -40,6 +40,7 @@ import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicScrollBarUI;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.FlatSystemProperties;
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableField;
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableLookupProvider;
@@ -540,6 +541,9 @@ public class FlatScrollBarUI
}
protected boolean isSmoothScrollingEnabled() {
if( !Animator.useAnimation() || !FlatSystemProperties.getBoolean( FlatSystemProperties.SMOOTH_SCROLLING, true ) )
return false;
// if scroll bar is child of scroll pane, check only client property of scroll pane
Container parent = scrollbar.getParent();
JComponent c = (parent instanceof JScrollPane) ? (JScrollPane) parent : scrollbar;

View File

@@ -48,8 +48,10 @@ import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicScrollPaneUI;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatSystemProperties;
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
import com.formdev.flatlaf.util.Animator;
import com.formdev.flatlaf.util.LoggingFacade;
/**
@@ -160,6 +162,9 @@ public class FlatScrollPaneUI
}
protected boolean isSmoothScrollingEnabled() {
if( !Animator.useAnimation() || !FlatSystemProperties.getBoolean( FlatSystemProperties.SMOOTH_SCROLLING, true ) )
return false;
Object smoothScrolling = scrollpane.getClientProperty( FlatClientProperties.SCROLL_PANE_SMOOTH_SCROLLING );
if( smoothScrolling instanceof Boolean )
return (Boolean) smoothScrolling;

View File

@@ -33,6 +33,7 @@ import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.FlatIntelliJLaf;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.FlatLightLaf;
import com.formdev.flatlaf.FlatSystemProperties;
import com.formdev.flatlaf.demo.HintManager.Hint;
import com.formdev.flatlaf.demo.extras.*;
import com.formdev.flatlaf.demo.intellijthemes.*;
@@ -266,6 +267,14 @@ class DemoFrame
repaint();
}
private void animationChanged() {
boolean enabled = animationMenuItem.isSelected();
System.setProperty( FlatSystemProperties.ANIMATION, Boolean.toString( enabled ) );
smoothScrollingMenuItem.setEnabled( enabled );
animatedLafChangeMenuItem.setEnabled( enabled );
}
private void smoothScrollingChanged() {
UIManager.put( "ScrollPane.smoothScrolling", smoothScrollingMenuItem.isSelected() );
}
@@ -509,6 +518,7 @@ class DemoFrame
showTitleBarIconMenuItem = new JCheckBoxMenuItem();
underlineMenuSelectionMenuItem = new JCheckBoxMenuItem();
alwaysShowMnemonicsMenuItem = new JCheckBoxMenuItem();
animationMenuItem = new JCheckBoxMenuItem();
smoothScrollingMenuItem = new JCheckBoxMenuItem();
animatedLafChangeMenuItem = new JCheckBoxMenuItem();
JMenuItem showHintsMenuItem = new JMenuItem();
@@ -797,6 +807,13 @@ class DemoFrame
alwaysShowMnemonicsMenuItem.setText("Always show mnemonics");
alwaysShowMnemonicsMenuItem.addActionListener(e -> alwaysShowMnemonics());
optionsMenu.add(alwaysShowMnemonicsMenuItem);
optionsMenu.addSeparator();
//---- animationMenuItem ----
animationMenuItem.setText("Animation");
animationMenuItem.setSelected(true);
animationMenuItem.addActionListener(e -> animationChanged());
optionsMenu.add(animationMenuItem);
//---- smoothScrollingMenuItem ----
smoothScrollingMenuItem.setText("Smooth Scrolling");
@@ -992,6 +1009,7 @@ class DemoFrame
private JCheckBoxMenuItem showTitleBarIconMenuItem;
private JCheckBoxMenuItem underlineMenuSelectionMenuItem;
private JCheckBoxMenuItem alwaysShowMnemonicsMenuItem;
private JCheckBoxMenuItem animationMenuItem;
private JCheckBoxMenuItem smoothScrollingMenuItem;
private JCheckBoxMenuItem animatedLafChangeMenuItem;
private JMenuItem aboutMenuItem;

View File

@@ -418,6 +418,18 @@ new FormModel {
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "alwaysShowMnemonics", false ) )
} )
add( new FormComponent( "javax.swing.JPopupMenu$Separator" ) {
name: "separator9"
} )
add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) {
name: "animationMenuItem"
"text": "Animation"
"selected": true
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "animationChanged", false ) )
} )
add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) {
name: "smoothScrollingMenuItem"
"text": "Smooth Scrolling"

View File

@@ -25,6 +25,7 @@ import java.awt.Window;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.beans.Beans;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
@@ -156,6 +157,9 @@ public class IJThemesPanel
}
private void updateThemesList() {
if( Beans.isDesignTime() )
return; // disable if running in GUI builder
int filterLightDark = filterComboBox.getSelectedIndex();
boolean showLight = (filterLightDark != 2);
boolean showDark = (filterLightDark != 1);

View File

@@ -67,7 +67,7 @@ public class FlatAnimatedLafChange
* Invoke before setting new look and feel.
*/
public static void showSnapshot() {
if( !FlatSystemProperties.getBoolean( "flatlaf.animatedLafChange", true ) )
if( !Animator.useAnimation() || !FlatSystemProperties.getBoolean( "flatlaf.animatedLafChange", true ) )
return;
// stop already running animation
@@ -138,7 +138,7 @@ public class FlatAnimatedLafChange
* Invoke after updating UI.
*/
public static void hideSnapshotWithAnimation() {
if( !FlatSystemProperties.getBoolean( "flatlaf.animatedLafChange", true ) )
if( !Animator.useAnimation() || !FlatSystemProperties.getBoolean( "flatlaf.animatedLafChange", true ) )
return;
if( oldUIsnapshots.isEmpty() )