Browse Source

Add flag to disable animations (global and individual components).

pull/214/head
weisj 4 years ago
parent
commit
dfb2a75032
  1. 20
      core/src/main/java/com/github/weisj/darklaf/graphics/Animator.java
  2. 5
      core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollBarListener.java
  3. 10
      core/src/main/java/com/github/weisj/darklaf/ui/togglebutton/DarkToggleButtonListener.java
  4. 2
      core/src/main/resources/com/github/weisj/darklaf/properties/overwrites.properties
  5. 1
      core/src/main/resources/com/github/weisj/darklaf/properties/ui/scrollBar.properties
  6. 1
      core/src/main/resources/com/github/weisj/darklaf/properties/ui/toggleButton.properties

20
core/src/main/java/com/github/weisj/darklaf/graphics/Animator.java

@ -29,8 +29,13 @@ import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.*;
import com.github.weisj.darklaf.DarkLaf;
import com.github.weisj.darklaf.util.PropertyValue;
/** @author Konstantin Bulenkov */
public abstract class Animator {
public static final String ANIMATIONS_FLAG = DarkLaf.SYSTEM_PROPERTY_PREFIX + "animations";
private static final ScheduledExecutorService scheduler = createScheduler();
private final int totalFrames;
@ -47,6 +52,7 @@ public abstract class Animator {
private int currentFrame;
private long startTime;
private long stopTime;
private boolean enabled = true;
private volatile boolean disposed = false;
public Animator(final int totalFrames, final int cycleDuration, final int delayFrames) {
@ -120,11 +126,23 @@ public abstract class Animator {
resume(0);
}
private boolean animationsEnabled() {
return enabled && !PropertyValue.FALSE.equals(System.getProperty(ANIMATIONS_FLAG));
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(final boolean enabled) {
this.enabled = enabled;
}
public void resume(final int startFrame) {
if (startFrame < 0) {
throw new IllegalArgumentException("Starting frame must be non negative.");
}
if (cycleDuration == 0 || startFrame >= totalFrames) {
if (cycleDuration == 0 || startFrame >= totalFrames || !animationsEnabled()) {
currentFrame = totalFrames - 1;
paint();
animationDone();

5
core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollBarListener.java

@ -56,10 +56,15 @@ public class DarkScrollBarListener extends MouseAdapter implements AdjustmentLis
public DarkScrollBarListener(final JScrollBar scrollbar, final DarkScrollBarUI ui) {
this.scrollbar = scrollbar;
this.ui = ui;
boolean animationsEnabled = UIManager.getBoolean("ScrollBar.animated");
trackFadeoutAnimator = createTrackFadeoutAnimator();
trackFadeinAnimator = createTrackFadeinAnimator();
thumbFadeoutAnimator = createThumbFadeoutAnimator();
thumbFadeinAnimator = createThumbFadeinAnimator();
trackFadeoutAnimator.setEnabled(animationsEnabled);
trackFadeinAnimator.setEnabled(animationsEnabled);
thumbFadeoutAnimator.setEnabled(animationsEnabled);
thumbFadeinAnimator.setEnabled(animationsEnabled);
}
public void uninstall() {

10
core/src/main/java/com/github/weisj/darklaf/ui/togglebutton/DarkToggleButtonListener.java

@ -40,7 +40,12 @@ public class DarkToggleButtonListener extends DarkButtonListener<DarkToggleButto
super(b, ui);
this.selected = b.isSelected();
button = b;
animator = new SliderAnimator(b);
animator = createAnimator();
animator.setEnabled(UIManager.getBoolean("ToggleButton.animated"));
}
protected SliderAnimator createAnimator() {
return new SliderAnimator(button);
}
public float getAnimationState() {
@ -72,13 +77,14 @@ public class DarkToggleButtonListener extends DarkButtonListener<DarkToggleButto
boolean sel = button.isSelected();
if (sel != selected) {
selected = sel;
float endState = sel ? 1 : 0;
int startFrame = 0;
if (animator.isRunning()) {
startFrame = animator.getCurrentFrame();
}
animator.suspend();
animator.setForward(sel);
animator.setEndValue(sel ? 1 : 0);
animator.setEndValue(endState);
animator.resume(startFrame);
}
}

2
core/src/main/resources/com/github/weisj/darklaf/properties/overwrites.properties

@ -33,3 +33,5 @@ Tree.defaultLineStyle = treeLineStyle
Tree.showFullRowInPopup = treeRowPopup
ToolTip.defaultStyle = tooltipStyle
TitlePane.unifiedMenuBar = unifiedMenuBar
ToggleButton.animated = animations
ScrollBar.animated = animations

1
core/src/main/resources/com/github/weisj/darklaf/properties/ui/scrollBar.properties

@ -35,3 +35,4 @@ ScrollBar.thumbHighlight = null
ScrollBar.smallWidth = 8
ScrollBar.width = 10
ScrollBar.thumbAlpha = 60
ScrollBar.animated = true

1
core/src/main/resources/com/github/weisj/darklaf/properties/ui/toggleButton.properties

@ -40,3 +40,4 @@ ToggleButton.activeFillColor = %textForegroundInactive
ToggleButton.sliderSize = 35,17
ToggleButton.showSliderHints = false
ToggleButton.animated = true

Loading…
Cancel
Save