mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 03:22:00 -08:00
Updated mageactioncallback. Commented out popups for a while (not always work correctly). Added delayed viewer.
This commit is contained in:
parent
0721c843d2
commit
1fcac53bf7
2 changed files with 78 additions and 41 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package mage.client.plugins.adapters;
|
package mage.client.plugins.adapters;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
|
|
@ -8,8 +9,9 @@ import java.awt.image.BufferedImage;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.swing.JDesktopPane;
|
||||||
|
import javax.swing.JLayeredPane;
|
||||||
import javax.swing.Popup;
|
import javax.swing.Popup;
|
||||||
import javax.swing.PopupFactory;
|
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import mage.cards.MageCard;
|
import mage.cards.MageCard;
|
||||||
|
|
@ -18,9 +20,11 @@ import mage.cards.action.ActionCallback;
|
||||||
import mage.cards.action.TransferData;
|
import mage.cards.action.TransferData;
|
||||||
import mage.client.MageFrame;
|
import mage.client.MageFrame;
|
||||||
import mage.client.cards.BigCard;
|
import mage.client.cards.BigCard;
|
||||||
|
import mage.client.components.MageComponents;
|
||||||
import mage.client.game.PlayAreaPanel;
|
import mage.client.game.PlayAreaPanel;
|
||||||
import mage.client.plugins.impl.Plugins;
|
import mage.client.plugins.impl.Plugins;
|
||||||
import mage.client.remote.Session;
|
import mage.client.remote.Session;
|
||||||
|
import mage.client.thread.DelayedViewerThread;
|
||||||
import mage.client.util.DefaultActionCallback;
|
import mage.client.util.DefaultActionCallback;
|
||||||
import mage.client.util.ImageHelper;
|
import mage.client.util.ImageHelper;
|
||||||
import mage.client.util.gui.ArrowBuilder;
|
import mage.client.util.gui.ArrowBuilder;
|
||||||
|
|
@ -62,10 +66,7 @@ public class MageActionCallback implements ActionCallback {
|
||||||
public void mouseEntered(MouseEvent e, final TransferData data) {
|
public void mouseEntered(MouseEvent e, final TransferData data) {
|
||||||
this.popupCard = data.card;
|
this.popupCard = data.card;
|
||||||
if (popup != null) {
|
if (popup != null) {
|
||||||
//synchronized (MageActionCallback.this) {
|
//DelayedViewerThread.getInstance().hide(data.popupText);
|
||||||
popup.hide();
|
|
||||||
state = 0;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw Arrows for targets
|
// Draw Arrows for targets
|
||||||
|
|
@ -111,34 +112,22 @@ public class MageActionCallback implements ActionCallback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//showPopup(data);
|
||||||
|
}
|
||||||
|
|
||||||
Thread t = new Thread(new Runnable() {
|
private void showPopup(final TransferData data) {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(500);
|
((JDesktopPane)session.getUI().getComponent(MageComponents.DESKTOP_PANE)).add(data.popupText, JLayeredPane.POPUP_LAYER);
|
||||||
} catch (InterruptedException e1) {}
|
data.popupText.setBounds((int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40, 200, 200);
|
||||||
state = 1;
|
data.popupText.setText("Test");
|
||||||
}
|
DelayedViewerThread.getInstance().show((Component)data.popupText, 500);
|
||||||
});
|
} catch (InterruptedException ie) {
|
||||||
t.start();
|
ie.printStackTrace();
|
||||||
showPopup(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showPopup( final TransferData data) {
|
//PopupFactory factory = PopupFactory.getSharedInstance();
|
||||||
while (state == 0) {
|
//popup = factory.getPopup(data.component, data.popupText, (int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40);
|
||||||
try {
|
//popup.show();
|
||||||
Thread.sleep(10);
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (state > 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
PopupFactory factory = PopupFactory.getSharedInstance();
|
|
||||||
popup = factory.getPopup(data.component, data.popupText, (int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40);
|
|
||||||
popup.show();
|
|
||||||
// hack to get popup to resize to fit text
|
// hack to get popup to resize to fit text
|
||||||
//popup.hide();
|
//popup.hide();
|
||||||
//popup = factory.getPopup(data.component, data.popupText, (int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40);
|
//popup = factory.getPopup(data.component, data.popupText, (int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40);
|
||||||
|
|
@ -176,20 +165,13 @@ public class MageActionCallback implements ActionCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseExited(MouseEvent e) {
|
public void mouseExited(MouseEvent e, final TransferData data) {
|
||||||
this.popupCard = null;
|
this.popupCard = null;
|
||||||
|
//DelayedViewerThread.getInstance().hide(data.popupText);
|
||||||
if (popup != null) {
|
if (popup != null) {
|
||||||
//synchronized (MageActionCallback.this) {
|
//popup.hide();
|
||||||
if (t != null) {
|
|
||||||
try {
|
|
||||||
t.stop();
|
|
||||||
} catch (Exception e1) {}
|
|
||||||
}
|
}
|
||||||
popup.hide();
|
|
||||||
state = 0;
|
|
||||||
//}
|
|
||||||
ArrowBuilder.removeAllArrows();
|
ArrowBuilder.removeAllArrows();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
package mage.client.thread;
|
||||||
|
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
public class DelayedViewerThread extends Thread {
|
||||||
|
private static DelayedViewerThread fInstance = new DelayedViewerThread();
|
||||||
|
|
||||||
|
public static DelayedViewerThread getInstance() {
|
||||||
|
return fInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Map<Component, Long> delayedViewers;
|
||||||
|
|
||||||
|
protected DelayedViewerThread() {
|
||||||
|
delayedViewers = new HashMap<Component, Long>();
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void show(Component component, long delay) {
|
||||||
|
delayedViewers.put(component, System.currentTimeMillis() + delay);
|
||||||
|
notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void hide(Component component) {
|
||||||
|
delayedViewers.remove(component);
|
||||||
|
component.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void run() {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
if (delayedViewers.isEmpty()) {
|
||||||
|
wait();
|
||||||
|
}
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Iterator<Component> it = delayedViewers.keySet().iterator(); it.hasNext();) {
|
||||||
|
Component component = it.next();
|
||||||
|
final long delayedTime = delayedViewers.get(component);
|
||||||
|
if (delayedTime <= time) {
|
||||||
|
component.setVisible(true);
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wait(100);
|
||||||
|
} catch (final InterruptedException ex) {
|
||||||
|
System.out.println("Interrupted : " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue