Added 'design' functionality
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
/* Author: Maple
|
||||
* Jan. 23 2026
|
||||
* */
|
||||
|
||||
package org.openautonomousconnection.oacswing.animated;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public interface AnimatedComponent {
|
||||
void setCurrentRun(Timer timer);
|
||||
Timer getCurrentRun();
|
||||
|
||||
void setAnimationPath(AnimationPath animationPath);
|
||||
AnimationPath getAnimationPath();
|
||||
|
||||
void setBounds(int x, int y, int width, int height);
|
||||
|
||||
default void play(double speed, boolean loop) {
|
||||
AtomicInteger ticksPassed = new AtomicInteger();
|
||||
|
||||
this.setCurrentRun(new Timer(0, e -> {
|
||||
|
||||
if(ticksPassed.get() * speed / (100) < 1) {
|
||||
ticksPassed.addAndGet(this.getAnimationPath().getInbetweens());
|
||||
return;
|
||||
}
|
||||
|
||||
KeyFrame next = this.getAnimationPath().getNext();
|
||||
|
||||
if(next == null) {
|
||||
if(loop)
|
||||
this.getAnimationPath().reset();
|
||||
else
|
||||
((Timer) e.getSource()).stop();
|
||||
return;
|
||||
}
|
||||
|
||||
this.setBounds(next.position().x, next.position().y, next.width(), next.height());
|
||||
|
||||
ticksPassed.set(0);
|
||||
}));
|
||||
|
||||
this.getCurrentRun().start();
|
||||
}
|
||||
|
||||
default void play(double speed) {
|
||||
this.play(speed, false);
|
||||
}
|
||||
|
||||
default void play() {
|
||||
this.play(1, false);
|
||||
}
|
||||
|
||||
default void stop() {
|
||||
if(this.getCurrentRun() != null)
|
||||
if(this.getCurrentRun().isRunning())
|
||||
this.getCurrentRun().stop();
|
||||
|
||||
this.getAnimationPath().reset();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
/* Author: Maple
|
||||
* Jan. 24 2026
|
||||
* */
|
||||
|
||||
package org.openautonomousconnection.oacswing.animated;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -1,56 +1,22 @@
|
||||
/* Author: Maple
|
||||
* Jan. 23 2026
|
||||
* */
|
||||
|
||||
package org.openautonomousconnection.oacswing.animated;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.openautonomousconnection.oacswing.JAnimatedComponent;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class JAnimatedPanel extends JPanel implements JAnimatedComponent {
|
||||
public class JAnimatedPanel extends JPanel implements AnimatedComponent {
|
||||
@Getter @Setter
|
||||
private AnimationPath animationPath;
|
||||
|
||||
@Getter @Setter
|
||||
private Timer currentRun = null;
|
||||
|
||||
public JAnimatedPanel(AnimationPath animationPath) {
|
||||
this.animationPath = animationPath;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void play(double speed, boolean loop) {
|
||||
|
||||
AtomicInteger ticksPassed = new AtomicInteger();
|
||||
|
||||
this.currentRun = new Timer(0, e -> {
|
||||
|
||||
if(ticksPassed.get() * speed / (100) < 1) {
|
||||
ticksPassed.addAndGet(animationPath.getInbetweens());
|
||||
return;
|
||||
}
|
||||
|
||||
KeyFrame next = animationPath.getNext();
|
||||
|
||||
if(next == null) {
|
||||
((Timer) e.getSource()).stop();
|
||||
return;
|
||||
}
|
||||
|
||||
setBounds(next.position().x, next.position().y, next.width(), next.height());
|
||||
|
||||
ticksPassed.set(0);
|
||||
});
|
||||
|
||||
this.currentRun.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if(this.currentRun != null)
|
||||
if(this.currentRun.isRunning())
|
||||
this.currentRun.stop();
|
||||
|
||||
this.animationPath.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/* Author: Maple
|
||||
* Jan. 24 2026
|
||||
* */
|
||||
|
||||
package org.openautonomousconnection.oacswing.animated;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
Reference in New Issue
Block a user