fixed issue 36

This commit is contained in:
BetaSteward 2010-12-05 03:36:59 +00:00
parent 632775c617
commit 63d1710cb7
3 changed files with 25 additions and 1 deletions

View file

@ -39,6 +39,7 @@ import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import mage.client.MageFrame;
import mage.client.remote.Session;
import mage.client.util.gui.GuiDisplayUtil;
import mage.view.AbilityPickerView;
/**
@ -66,6 +67,7 @@ public class AbilityPicker extends JPopupMenu implements PopupMenuListener {
this.add(new AbilityPickerAction(choice.getKey(), choice.getValue()));
}
this.show(MageFrame.getDesktop(), p.x, p.y);
GuiDisplayUtil.keepComponentInsideScreen(p.x, p.y, this);
}
@Override

View file

@ -1,7 +1,10 @@
package mage.client.util.gui;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JLabel;
@ -101,4 +104,23 @@ public class GuiDisplayUtil {
return out.toString().toLowerCase();
}
public static void keepComponentInsideScreen(int x, int y, Component c) {
Dimension screenDim = c.getToolkit().getScreenSize();
Insets insets = c.getToolkit().getScreenInsets(c.getGraphicsConfiguration());
if (x + c.getWidth() > screenDim.width - insets.right) {
x = (screenDim.width - insets.right) - c.getWidth();
} else if (x < insets.left) {
x = insets.left;
}
if (y + c.getHeight() > screenDim.height - insets.bottom) {
y = (screenDim.height - insets.bottom) - c.getHeight();
} else if (y < insets.top) {
y = insets.top;
}
c.setLocation(x, y);
}
}