[UI] card image zoom in/out on mouse wheel with 700 ms timeout

This commit is contained in:
magenoxx 2012-07-16 16:08:12 +04:00
parent 6d24c7001b
commit 7443e2a9fa
4 changed files with 55 additions and 5 deletions

View file

@ -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);
}
}
}

View file

@ -28,10 +28,10 @@ import java.util.UUID;
/**
* Main class for drawing Mage card object.
*
* @author arcane, nantuko
* @author arcane, nantuko, noxx
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public class CardPanel extends MagePermanent implements MouseListener, MouseMotionListener {
public class CardPanel extends MagePermanent implements MouseListener, MouseMotionListener, MouseWheelListener {
private static final long serialVersionUID = -3272134219262184410L;
private static final Logger log = Logger.getLogger(CardPanel.class);
@ -146,6 +146,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
addMouseListener(this);
addMouseMotionListener(this);
addMouseWheelListener(this);
titleText = new GlowText();
setText(gameCard);
@ -891,4 +892,11 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
updateImage();
}
}
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if (gameCard.isFaceDown()) return;
data.component = this;
callback.mouseWheelMoved(e, data);
}
}

View file

@ -1,13 +1,15 @@
package mage.cards.action;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
public interface ActionCallback {
void mouseClicked(MouseEvent e, TransferData data);
void mousePressed(MouseEvent e, TransferData data);
void mouseMoved(MouseEvent e, TransferData data);
void mouseEntered(MouseEvent e, TransferData data);
void mouseExited(MouseEvent e, TransferData dat);
void mouseExited(MouseEvent e, TransferData data);
void mouseWheelMoved(MouseWheelEvent e, TransferData data);
void hidePopup();
}

View file

@ -1,10 +1,11 @@
package mage.cards.action.impl;
import java.awt.event.MouseEvent;
import mage.cards.action.ActionCallback;
import mage.cards.action.TransferData;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
/**
* Callback that does nothing on any action
*
@ -24,6 +25,10 @@ public class EmptyCallback implements ActionCallback {
public void mouseExited(MouseEvent e, TransferData data) {
}
@Override
public void mouseWheelMoved(MouseWheelEvent e, TransferData data) {
}
@Override
public void hidePopup() {
}