diff --git a/src/magic/ui/DelayedViewer.java b/src/magic/ui/DelayedViewer.java new file mode 100644 index 0000000000..34f9345c41 --- /dev/null +++ b/src/magic/ui/DelayedViewer.java @@ -0,0 +1,8 @@ +package magic.ui; + +public interface DelayedViewer { + + public void showDelayed(); + + public void hideDelayed(); +} diff --git a/src/magic/ui/DelayedViewersThread.java b/src/magic/ui/DelayedViewersThread.java index 37fa781d8f..962dae666c 100644 --- a/src/magic/ui/DelayedViewersThread.java +++ b/src/magic/ui/DelayedViewersThread.java @@ -1,6 +1,5 @@ package magic.ui; -import java.awt.Component; import java.util.HashMap; import java.util.Map; @@ -8,24 +7,24 @@ public class DelayedViewersThread extends Thread { private static final DelayedViewersThread VIEWER_THREAD=new DelayedViewersThread(); - private final Map delayedViewers; + private final Map delayedViewers; private DelayedViewersThread() { - delayedViewers=new HashMap(); + delayedViewers=new HashMap(); start(); } - public synchronized void showViewer(final Component component,final int delay) { + public synchronized void showViewer(final DelayedViewer delayedViewer,final int delay) { - delayedViewers.put(component,System.currentTimeMillis()+delay); + delayedViewers.put(delayedViewer,System.currentTimeMillis()+delay); notify(); } - public synchronized void hideViewer(final Component component) { + public synchronized void hideViewer(final DelayedViewer delayedViewer) { - delayedViewers.remove(component); - component.setVisible(false); + delayedViewers.remove(delayedViewer); + delayedViewer.hideDelayed(); } @Override @@ -38,12 +37,12 @@ public class DelayedViewersThread extends Thread { wait(); } final long time=System.currentTimeMillis(); - for (final Component component : delayedViewers.keySet()) { + for (final DelayedViewer delayedViewer : delayedViewers.keySet()) { - final long delayedTime=delayedViewers.get(component); + final long delayedTime=delayedViewers.get(delayedViewer); if (delayedTime<=time) { - component.setVisible(true); - delayedViewers.remove(component); + delayedViewer.showDelayed(); + delayedViewers.remove(delayedViewer); } } wait(100); diff --git a/src/magic/ui/viewer/CardViewer.java b/src/magic/ui/viewer/CardViewer.java index 301a65fd95..c1e773696f 100644 --- a/src/magic/ui/viewer/CardViewer.java +++ b/src/magic/ui/viewer/CardViewer.java @@ -8,10 +8,11 @@ import javax.swing.JPanel; import magic.data.CardImages; import magic.model.MagicCardDefinition; +import magic.ui.DelayedViewer; import magic.ui.widget.FontsAndBorders; import magic.ui.widget.TitleBar; -public class CardViewer extends JPanel { +public class CardViewer extends JPanel implements DelayedViewer { private static final long serialVersionUID = 1L; @@ -45,4 +46,16 @@ public class CardViewer extends JPanel { repaint(); } } + + @Override + public void showDelayed() { + + setVisible(true); + } + + @Override + public void hideDelayed() { + + setVisible(false); + } } \ No newline at end of file diff --git a/src/magic/ui/viewer/ImageViewer.java b/src/magic/ui/viewer/ImageViewer.java index eeebcdd5cd..30af6c7b01 100644 --- a/src/magic/ui/viewer/ImageViewer.java +++ b/src/magic/ui/viewer/ImageViewer.java @@ -17,14 +17,17 @@ import javax.swing.JPanel; import magic.MagicMain; import magic.model.MagicRandom; +import magic.ui.DelayedViewer; +import magic.ui.DelayedViewersThread; /** * Landscape image viewer. */ -public class ImageViewer extends JPanel { +public class ImageViewer extends JPanel implements DelayedViewer { private static final long serialVersionUID = 1L; + private static final int DELAY=500; private static final int VIEWER_WIDTH=300; private static final int ZOOM_FACTOR=4; @@ -33,6 +36,7 @@ public class ImageViewer extends JPanel { private final BufferedImage image; private Image scaledImage=null; + private boolean showScaled=false; private boolean scaled=false; private int imageWidth; private int imageHeight; @@ -91,18 +95,23 @@ public class ImageViewer extends JPanel { final MouseAdapter mouseListener=new MouseAdapter() { + @Override + public void mouseEntered(final MouseEvent e) { + + DelayedViewersThread.getInstance().showViewer(ImageViewer.this,DELAY); + } + @Override public void mouseExited(final MouseEvent e) { - scaled=false; - repaint(); + DelayedViewersThread.getInstance().hideViewer(ImageViewer.this); } @Override public void mouseMoved(final MouseEvent e) { final int y=e.getY(); - if (y<=viewerHeight) { + if (y<=viewerHeight&&showScaled) { final int x=e.getX(); int px=(x*imageWidth)/getWidth(); int py=(y*imageHeight)/viewerHeight; @@ -133,6 +142,21 @@ public class ImageViewer extends JPanel { } } + @Override + public void showDelayed() { + + showScaled=true; + repaint(); + } + + @Override + public void hideDelayed() { + + showScaled=false; + scaled=false; + repaint(); + } + @Override public void paint(final Graphics g) {