Browse Source

Make sure animation is only started if slider variant is used.

Restrict repainted animation area to slider bounds.
pull/214/head
weisj 4 years ago
parent
commit
0bf6ed065b
  1. 7
      core/src/main/java/com/github/weisj/darklaf/ui/togglebutton/DarkToggleButtonListener.java

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

@ -21,6 +21,7 @@
*/ */
package com.github.weisj.darklaf.ui.togglebutton; package com.github.weisj.darklaf.ui.togglebutton;
import java.awt.*;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import javax.swing.*; import javax.swing.*;
@ -75,6 +76,7 @@ public class DarkToggleButtonListener extends DarkButtonListener<DarkToggleButto
@Override @Override
public void stateChanged(final ChangeEvent e) { public void stateChanged(final ChangeEvent e) {
super.stateChanged(e); super.stateChanged(e);
if (!ToggleButtonConstants.isSlider(button)) return;
boolean sel = button.isSelected(); boolean sel = button.isSelected();
if (sel != selected) { if (sel != selected) {
selected = sel; selected = sel;
@ -83,6 +85,7 @@ public class DarkToggleButtonListener extends DarkButtonListener<DarkToggleButto
if (animator.isRunning()) { if (animator.isRunning()) {
startFrame = animator.getCurrentFrame(); startFrame = animator.getCurrentFrame();
} }
animator.animationBounds = ui.getSliderBounds(button);
animator.suspend(); animator.suspend();
animator.reverse = !sel; animator.reverse = !sel;
animator.setEndValue(endState); animator.setEndValue(endState);
@ -96,6 +99,7 @@ public class DarkToggleButtonListener extends DarkButtonListener<DarkToggleButto
private float state; private float state;
private float endValue; private float endValue;
private boolean reverse; private boolean reverse;
private Rectangle animationBounds;
public SliderAnimator(final JComponent c) { public SliderAnimator(final JComponent c) {
super(10, 100, 0); super(10, 100, 0);
@ -117,11 +121,12 @@ public class DarkToggleButtonListener extends DarkButtonListener<DarkToggleButto
protected void paintCycleEnd() { protected void paintCycleEnd() {
this.state = endValue; this.state = endValue;
repaint(); repaint();
animationBounds = null;
} }
private void repaint() { private void repaint() {
if (c != null) { if (c != null) {
c.paintImmediately(c.getVisibleRect()); c.paintImmediately(animationBounds != null ? animationBounds : c.getVisibleRect());
} }
} }

Loading…
Cancel
Save