From 7443e2a9facfb5d6463b35537c9f7d5caeeccda5 Mon Sep 17 00:00:00 2001 From: magenoxx Date: Mon, 16 Jul 2012 16:08:12 +0400 Subject: [PATCH] [UI] card image zoom in/out on mouse wheel with 700 ms timeout --- .../plugins/adapters/MageActionCallback.java | 35 +++++++++++++++++++ .../java/org/mage/card/arcane/CardPanel.java | 12 +++++-- .../src/mage/cards/action/ActionCallback.java | 4 ++- .../mage/cards/action/impl/EmptyCallback.java | 9 +++-- 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java index 28f93bbe4e..87bcb556e3 100644 --- a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java +++ b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java @@ -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); + } + } } + diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java index eb4d391385..25fce0fefb 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java @@ -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); + } } diff --git a/Mage.Common/src/mage/cards/action/ActionCallback.java b/Mage.Common/src/mage/cards/action/ActionCallback.java index 550f892478..da476c1319 100644 --- a/Mage.Common/src/mage/cards/action/ActionCallback.java +++ b/Mage.Common/src/mage/cards/action/ActionCallback.java @@ -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(); } diff --git a/Mage.Common/src/mage/cards/action/impl/EmptyCallback.java b/Mage.Common/src/mage/cards/action/impl/EmptyCallback.java index 5d5e66edff..5fc9615068 100644 --- a/Mage.Common/src/mage/cards/action/impl/EmptyCallback.java +++ b/Mage.Common/src/mage/cards/action/impl/EmptyCallback.java @@ -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() { }