1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-13 01:01:11 -09:00

UI: fixed rare error with wrong dialog position after multiple popups ();

This commit is contained in:
Oleg Agafonov 2019-03-28 09:19:16 +04:00
parent 14f90bfc77
commit c58b28f94f
12 changed files with 185 additions and 173 deletions

View file

@ -45,14 +45,14 @@ public class DeckExportClipboardDialog extends MageDialog {
this.setResizable(true);
getRootPane().setDefaultButton(buttonOK);
this.makeWindowCentered();
// windows settings
MageFrame.getDesktop().remove(this);
if (this.isModal()) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
} else {
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
}
this.makeWindowCentered();
// Close on "ESC"
registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

View file

@ -41,14 +41,14 @@ public class DeckImportClipboardDialog extends MageDialog {
this.setResizable(true);
getRootPane().setDefaultButton(buttonOK);
this.makeWindowCentered();
// windows settings
MageFrame.getDesktop().remove(this);
if (this.isModal()) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
} else {
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
}
this.makeWindowCentered();
// Close on "ESC"
registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

View file

@ -114,14 +114,15 @@ public class AddLandDialog extends MageDialog {
}
getRootPane().setDefaultButton(btnOK);
this.makeWindowCentered();
// windows settings
MageFrame.getDesktop().remove(this);
if (this.isModal()) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
} else {
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
}
this.makeWindowCentered();
// Close on "ESC"
registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

View file

@ -63,19 +63,19 @@ public class DownloadImagesDialog extends MageDialog {
}
public void showDialog(MageDialogState mageDialogState) {
showDownloadControls(false); // call to change window size
// window settings
MageFrame.getDesktop().remove(this);
if (this.isModal()) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
} else {
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
}
if (mageDialogState != null) {
mageDialogState.setStateToDialog(this);
} else {
this.makeWindowCentered();
}
if (mageDialogState != null) mageDialogState.setStateToDialog(this);
else this.makeWindowCentered();
showDownloadControls(false); // call to change window size
this.setVisible(true);
}
@ -106,7 +106,7 @@ public class DownloadImagesDialog extends MageDialog {
public JButton getCancelButton() {
return this.buttonCancel;
}
public JButton getStopButton() {
return this.buttonStop;
}
@ -288,7 +288,7 @@ public class DownloadImagesDialog extends MageDialog {
panelSourceLeft.add(labelSource);
comboSource.setMaximumRowCount(15);
comboSource.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
comboSource.setModel(new javax.swing.DefaultComboBoxModel<>(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"}));
comboSource.setMinimumSize(new java.awt.Dimension(300, 20));
comboSource.setPreferredSize(new java.awt.Dimension(400, 25));
panelSourceLeft.add(comboSource);
@ -305,7 +305,7 @@ public class DownloadImagesDialog extends MageDialog {
panelSourceRight.add(labelLanguage);
comboLanguage.setMaximumRowCount(15);
comboLanguage.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
comboLanguage.setModel(new javax.swing.DefaultComboBoxModel<>(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"}));
comboLanguage.setPreferredSize(new java.awt.Dimension(90, 25));
panelSourceRight.add(comboLanguage);
@ -328,7 +328,7 @@ public class DownloadImagesDialog extends MageDialog {
panelModeSelect.setLayout(new javax.swing.BoxLayout(panelModeSelect, javax.swing.BoxLayout.X_AXIS));
comboSets.setMaximumRowCount(15);
comboSets.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
comboSets.setModel(new javax.swing.DefaultComboBoxModel<>(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"}));
comboSets.setPreferredSize(new java.awt.Dimension(373, 25));
panelModeSelect.add(comboSets);
panelModeSelect.add(fillerMode1);

View file

@ -14,7 +14,7 @@ import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
/**
* @author BetaSteward_at_googlemail.com
* @author BetaSteward_at_googlemail.com, JayDi85
*/
public class MageDialog extends javax.swing.JInternalFrame {
@ -33,6 +33,22 @@ public class MageDialog extends javax.swing.JInternalFrame {
}
public static void printFramesOrder(String name) {
///*
JInternalFrame[] frames = MageFrame.getDesktop().getAllFrames();
System.out.println("--- " + name + " ---");
int order = 0;
for (JInternalFrame frame : frames) {
order++;
int zorder = -1;
if (frame.getParent() != null) {
zorder = frame.getParent().getComponentZOrder(frame);
}
System.out.println(order + ". " + frame.getClass() + " (" + frame.getTitle() + ") : layer = " + frame.getLayer() + ", zorder = " + zorder);
}
//*/
}
@Override
public void show() {
super.show();
@ -45,17 +61,6 @@ public class MageDialog extends javax.swing.JInternalFrame {
// - JLayeredPane.MODAL_LAYER: all modal dialogs (user required actions - select cards in game, new game window, error windows)
// - JLayeredPane.POPUP_LAYER: hints and other top level graphics
// - JLayeredPane.DRAG_LAYER: top most layer for critical actions and user controls
/*
JInternalFrame[] frames = MageFrame.getDesktop().getAllFrames();
System.out.println("---");
for(JInternalFrame frame: frames){
int zorder = -1;
if (frame.getParent() != null){
frame.getParent().getComponentZOrder(frame);
}
System.out.println(frame.getClass() + " (" + frame.getTitle() + ") : layer = " + frame.getLayer() + ", zorder = " + zorder);
}
*/
if (modal) {
this.setClosable(false);
@ -71,9 +76,16 @@ public class MageDialog extends javax.swing.JInternalFrame {
@Override
public void setVisible(boolean value) {
super.setVisible(value);
if (value) {
this.toFront();
try {
this.setSelected(true);
} catch (PropertyVetoException e) {
//
}
}
if (modal) {
this.setClosable(false);
if (value) {
@ -195,7 +207,7 @@ public class MageDialog extends javax.swing.JInternalFrame {
}
public void makeWindowCentered() {
makeWindowCentered(this, getWidth(), getHeight());
makeWindowCentered(this, this.getWidth(), this.getHeight());
}
public static void makeWindowCentered(Component component, int width, int height) {

View file

@ -32,7 +32,7 @@ public class PickCheckBoxDialog extends MageDialog {
if (!(obj instanceof java.awt.Component)) {
throw new IllegalArgumentException("Must be a java.awt.Component!");
}
this.scrollList.setViewportView((java.awt.Component) obj);
this.scrollList.setViewportView(obj);
}
private javax.swing.JList get_a_Jlist_from_ScrollListView() {
@ -181,16 +181,14 @@ public class PickCheckBoxDialog extends MageDialog {
}
// window settings
MageFrame.getDesktop().remove(this);
if (this.isModal()) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
} else {
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
}
if (mageDialogState != null) {
mageDialogState.setStateToDialog(this);
} else {
this.makeWindowCentered();
}
if (mageDialogState != null) mageDialogState.setStateToDialog(this);
else this.makeWindowCentered();
// final load
loadData();
@ -366,7 +364,7 @@ public class PickCheckBoxDialog extends MageDialog {
}
public Object getObjectValue() {
return (CheckBoxList.CheckBoxListItem) this.objectValue;
return this.objectValue;
}
@Override

View file

@ -145,17 +145,14 @@ public class PickChoiceDialog extends MageDialog {
}
// window settings
MageFrame.getDesktop().remove(this);
if (this.isModal()) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
} else {
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
}
if (mageDialogState != null) {
mageDialogState.setStateToDialog(this);
} else {
this.makeWindowCentered();
}
if (mageDialogState != null) mageDialogState.setStateToDialog(this);
else this.makeWindowCentered();
// final load
loadData();
@ -404,7 +401,7 @@ public class PickChoiceDialog extends MageDialog {
.addContainerGap())
);
panelCommandsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[]{btCancel, btOK});
panelCommandsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, btCancel, btOK);
panelCommandsLayout.setVerticalGroup(
panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

View file

@ -30,11 +30,13 @@ public class PickNumberDialog extends MageDialog {
this.pack();
// window settings
MageFrame.getDesktop().remove(this);
if (this.isModal()) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
} else {
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
}
this.getRootPane().setDefaultButton(this.btnOk); // restore default button after root panel change (no need actually)
// enable spinner's enter key like text (one enter press instead two)

View file

@ -69,23 +69,20 @@ public class PickPileDialog extends MageDialog {
this.pile1.loadCardsNarrow(pile1, bigCard, gameId);
this.pile2.loadCardsNarrow(pile2, bigCard, gameId);
if (getParent() != MageFrame.getDesktop() /*|| this.isClosed*/) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
}
this.setModal(true);
pack();
this.makeWindowCentered();
this.revalidate();
this.repaint();
this.setModal(true);
// window settings
// windows settings
MageFrame.getDesktop().remove(this);
if (this.isModal()) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
} else {
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
}
this.makeWindowCentered();
this.revalidate(); // TODO: remove?
this.repaint(); // TODO: remove?
this.setVisible(true);
}

View file

@ -1,138 +1,137 @@
/*
* ShowCardsDialog.java
*
* Created on 3-Feb-2010, 8:59:11 PM
*/
package mage.client.dialog;
* ShowCardsDialog.java
*
* Created on 3-Feb-2010, 8:59:11 PM
*/
package mage.client.dialog;
import java.awt.Component;
import java.awt.Point;
import java.io.Serializable;
import java.util.Map;
import java.util.UUID;
import javax.swing.JLayeredPane;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import mage.client.MageFrame;
import mage.client.cards.BigCard;
import mage.client.cards.CardArea;
import mage.client.util.Event;
import mage.client.util.Listener;
import mage.client.util.SettingsManager;
import mage.client.util.gui.GuiDisplayUtil;
import mage.game.events.PlayerQueryEvent.QueryType;
import mage.view.CardsView;
import org.mage.card.arcane.CardPanel;
import mage.client.MageFrame;
import mage.client.cards.BigCard;
import mage.client.cards.CardArea;
import mage.client.util.Event;
import mage.client.util.Listener;
import mage.client.util.SettingsManager;
import mage.client.util.gui.GuiDisplayUtil;
import mage.game.events.PlayerQueryEvent.QueryType;
import mage.view.CardsView;
import org.mage.card.arcane.CardPanel;
/**
* @author BetaSteward_at_googlemail.com
*/
public class ShowCardsDialog extends MageDialog {
import javax.swing.*;
import java.awt.*;
import java.io.Serializable;
import java.util.Map;
import java.util.UUID;
// remember if this dialog was already auto positioned, so don't do it after the first time
private boolean positioned;
/**
* @author BetaSteward_at_googlemail.com
*/
public class ShowCardsDialog extends MageDialog {
/**
* Creates new form ShowCardsDialog
*/
public ShowCardsDialog() {
this.positioned = false;
// remember if this dialog was already auto positioned, so don't do it after the first time
private boolean positioned;
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
initComponents();
/**
* Creates new form ShowCardsDialog
*/
public ShowCardsDialog() {
this.positioned = false;
this.setModal(false);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
initComponents();
}
this.setModal(false);
public void cleanUp() {
cardArea.cleanUp();
for (Component comp : cardArea.getComponents()) {
if (comp instanceof CardPanel) {
((CardPanel) comp).cleanUp();
cardArea.remove(comp);
}
}
}
}
@Override
public void changeGUISize() {
setGUISize();
cardArea.changeGUISize();
}
public void cleanUp() {
cardArea.cleanUp();
for (Component comp : cardArea.getComponents()) {
if (comp instanceof CardPanel) {
((CardPanel) comp).cleanUp();
cardArea.remove(comp);
}
}
}
private void setGUISize() {
@Override
public void changeGUISize() {
setGUISize();
cardArea.changeGUISize();
}
}
private void setGUISize() {
public void loadCards(String name, CardsView showCards, BigCard bigCard,
UUID gameId, boolean modal, Map<String, Serializable> options,
JPopupMenu popupMenu, Listener<Event> eventListener) {
this.title = name;
this.setTitelBarToolTip(name);
cardArea.clearCardEventListeners();
cardArea.loadCards(showCards, bigCard, gameId);
if (options != null) {
if (options.containsKey("chosen")) {
java.util.List<UUID> chosenCards = (java.util.List<UUID>) options.get("chosen");
cardArea.selectCards(chosenCards);
}
if (options.containsKey("choosable")) {
java.util.List<UUID> choosableCards = (java.util.List<UUID>) options.get("choosable");
cardArea.markCards(choosableCards);
}
if (options.containsKey("queryType") && options.get("queryType") == QueryType.PICK_ABILITY) {
cardArea.setPopupMenu(popupMenu);
}
}
if (popupMenu != null) {
this.cardArea.setPopupMenu(popupMenu);
}
if (eventListener != null) {
this.cardArea.addCardEventListener(eventListener);
}
}
pack();
public void loadCards(String name, CardsView showCards, BigCard bigCard,
UUID gameId, boolean modal, Map<String, Serializable> options,
JPopupMenu popupMenu, Listener<Event> eventListener) {
this.title = name;
this.setTitelBarToolTip(name);
cardArea.clearCardEventListeners();
cardArea.loadCards(showCards, bigCard, gameId);
if (options != null) {
if (options.containsKey("chosen")) {
java.util.List<UUID> chosenCards = (java.util.List<UUID>) options.get("chosen");
cardArea.selectCards(chosenCards);
}
if (options.containsKey("choosable")) {
java.util.List<UUID> choosableCards = (java.util.List<UUID>) options.get("choosable");
cardArea.markCards(choosableCards);
}
if (options.containsKey("queryType") && options.get("queryType") == QueryType.PICK_ABILITY) {
cardArea.setPopupMenu(popupMenu);
}
}
if (popupMenu != null) {
this.cardArea.setPopupMenu(popupMenu);
}
if (eventListener != null) {
this.cardArea.addCardEventListener(eventListener);
}
this.revalidate();
this.repaint();
this.setModal(modal);
pack();
// window settings
if (this.isModal()){
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
}else{
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
}
this.revalidate();
this.repaint();
this.setModal(modal);
SwingUtilities.invokeLater(() -> {
if (!positioned) {
int width = ShowCardsDialog.this.getWidth();
int height = ShowCardsDialog.this.getHeight();
if (width > 0 && height > 0) {
Point centered = SettingsManager.instance.getComponentPosition(width, height);
ShowCardsDialog.this.setLocation(centered.x, centered.y);
positioned = true;
GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, ShowCardsDialog.this);
}
}
ShowCardsDialog.this.setVisible(true);
});
}
// window settings
MageFrame.getDesktop().remove(this);
if (this.isModal()) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
} else {
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
}
private void initComponents() {
SwingUtilities.invokeLater(() -> {
if (!positioned) {
int width = ShowCardsDialog.this.getWidth();
int height = ShowCardsDialog.this.getHeight();
if (width > 0 && height > 0) {
Point centered = SettingsManager.instance.getComponentPosition(width, height);
ShowCardsDialog.this.setLocation(centered.x, centered.y);
positioned = true;
GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, ShowCardsDialog.this);
}
}
ShowCardsDialog.this.setVisible(true);
});
}
cardArea = new CardArea();
private void initComponents() {
setClosable(true);
setResizable(true);
getContentPane().setLayout(new java.awt.BorderLayout());
getContentPane().add(cardArea, java.awt.BorderLayout.CENTER);
setGUISize();
pack();
}
cardArea = new CardArea();
private CardArea cardArea;
}
setClosable(true);
setResizable(true);
getContentPane().setLayout(new java.awt.BorderLayout());
getContentPane().add(cardArea, java.awt.BorderLayout.CENTER);
setGUISize();
pack();
}
private CardArea cardArea;
}

View file

@ -193,8 +193,6 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
// PROGRESS BAR
uiDialog.getProgressBar().setValue(0);
uiDialog.showDownloadControls(false);
}
public void findMissingCards() {

View file

@ -19,6 +19,7 @@ public class MageVersion implements Serializable, Comparable<MageVersion> {
public static final String MAGE_VERSION_MINOR_PATCH = "V5"; // default
// strict mode
private static final boolean MAGE_VERSION_MINOR_PATCH_MUST_BE_SAME = true; // set true on uncompatible github changes, set false after new major release (after MAGE_VERSION_PATCH changes)
public static final boolean MAGE_VERSION_SHOW_BUILD_TIME = true;
private final int major;
private final int minor;
@ -26,7 +27,6 @@ public class MageVersion implements Serializable, Comparable<MageVersion> {
private final String minorPatch; // doesn't matter for compatibility
private final String buildTime;
private String editionInfo;
private final boolean showBuildTime = true;
public MageVersion(Class sourceClass) {
this(MAGE_VERSION_MAJOR, MAGE_VERSION_MINOR, MAGE_VERSION_PATCH, MAGE_VERSION_MINOR_PATCH, MAGE_EDITION_INFO, sourceClass);
@ -40,7 +40,7 @@ public class MageVersion implements Serializable, Comparable<MageVersion> {
this.editionInfo = editionInfo;
// build time
this.buildTime = showBuildTime ? JarVersion.getBuildTime(sourceClass) : "";
this.buildTime = JarVersion.getBuildTime(sourceClass);
}
public int getMajor() {
@ -59,10 +59,18 @@ public class MageVersion implements Serializable, Comparable<MageVersion> {
return minorPatch;
}
public String toString(boolean showBuildTime) {
// 1.4.32-betaV0 (build: time)
String res = major + "." + minor + '.' + patch + editionInfo + minorPatch;
if (showBuildTime && !this.buildTime.isEmpty()) {
res += " (build: " + this.buildTime + ")";
}
return res;
}
@Override
public String toString() {
// 1.4.32-betaV0 (build: time)
return major + "." + minor + '.' + patch + editionInfo + minorPatch + (!this.buildTime.isEmpty() ? " (build: " + this.buildTime + ")" : "");
return toString(MAGE_VERSION_SHOW_BUILD_TIME);
}
@Override