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

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);
}
@ -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

@ -5,31 +5,29 @@
*
* Created on 3-Feb-2010, 8:59:11 PM
*/
package mage.client.dialog;
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;
/**
import javax.swing.*;
import java.awt.*;
import java.io.Serializable;
import java.util.Map;
import java.util.UUID;
/**
* @author BetaSteward_at_googlemail.com
*/
public class ShowCardsDialog extends MageDialog {
public class ShowCardsDialog extends MageDialog {
// remember if this dialog was already auto positioned, so don't do it after the first time
private boolean positioned;
@ -101,9 +99,10 @@ public class ShowCardsDialog extends MageDialog {
this.setModal(modal);
// window settings
if (this.isModal()){
MageFrame.getDesktop().remove(this);
if (this.isModal()) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
}else{
} else {
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
}
@ -135,4 +134,4 @@ public class ShowCardsDialog extends MageDialog {
}
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