forked from External/mage
[UI] card image zoom in/out on mouse wheel with 700 ms timeout
This commit is contained in:
parent
6d24c7001b
commit
7443e2a9fa
4 changed files with 55 additions and 5 deletions
|
|
@ -24,9 +24,14 @@ import org.jdesktop.swingx.JXPanel;
|
|||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class MageActionCallback implements ActionCallback {
|
||||
|
||||
|
|
@ -41,6 +46,9 @@ public class MageActionCallback implements ActionCallback {
|
|||
private volatile boolean state = false;
|
||||
private boolean enlarged = false;
|
||||
|
||||
private static final ScheduledExecutorService timeoutExecutor = Executors.newScheduledThreadPool(1);
|
||||
private ScheduledFuture<?> hideTimeout;
|
||||
|
||||
public MageActionCallback() {
|
||||
}
|
||||
|
||||
|
|
@ -70,6 +78,7 @@ public class MageActionCallback implements ActionCallback {
|
|||
@Override
|
||||
public void mouseEntered(MouseEvent e, final TransferData data) {
|
||||
hidePopup();
|
||||
cancelTimeout();
|
||||
this.popupCard = data.card;
|
||||
this.popupData = data;
|
||||
|
||||
|
|
@ -270,6 +279,7 @@ public class MageActionCallback implements ActionCallback {
|
|||
@Override
|
||||
public void mouseExited(MouseEvent e, final TransferData data) {
|
||||
hidePopup();
|
||||
startHideTimeout();
|
||||
this.state = false;
|
||||
//ArrowBuilder.removeAllArrows();
|
||||
ArrowBuilder.removeArrowsByType(ArrowBuilder.Type.TARGET);
|
||||
|
|
@ -306,6 +316,15 @@ public class MageActionCallback implements ActionCallback {
|
|||
}
|
||||
}
|
||||
|
||||
public void mouseWheelMoved(MouseWheelEvent e, TransferData data) {
|
||||
int notches = e.getWheelRotation();
|
||||
if (notches < 0) {
|
||||
enlargeCard();
|
||||
} else {
|
||||
hideCard();
|
||||
}
|
||||
}
|
||||
|
||||
private void displayCard(final CardView card, final TransferData data) {
|
||||
if (!enlarged) {
|
||||
return;
|
||||
|
|
@ -374,4 +393,20 @@ public class MageActionCallback implements ActionCallback {
|
|||
});
|
||||
}
|
||||
|
||||
private synchronized void startHideTimeout() {
|
||||
cancelTimeout();
|
||||
hideTimeout = timeoutExecutor.schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
hideCard();
|
||||
}
|
||||
}, 700, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
private synchronized void cancelTimeout() {
|
||||
if (hideTimeout != null) {
|
||||
hideTimeout.cancel(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue