From 14f90bfc77da389bb5feb320de12b6fd7bd13ff3 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Thu, 28 Mar 2019 09:12:17 +0400 Subject: [PATCH] UI: added debug tool to test modal/non-modal dialog system (available from debug menu); --- .../mage/client/dialog/TestModalDialog.form | 194 ++++++++++ .../mage/client/dialog/TestModalDialog.java | 345 ++++++++++++++++++ .../client/dialog/TestModalSampleDialog.form | 65 ++++ .../client/dialog/TestModalSampleDialog.java | 119 ++++++ 4 files changed, 723 insertions(+) create mode 100644 Mage.Client/src/main/java/mage/client/dialog/TestModalDialog.form create mode 100644 Mage.Client/src/main/java/mage/client/dialog/TestModalDialog.java create mode 100644 Mage.Client/src/main/java/mage/client/dialog/TestModalSampleDialog.form create mode 100644 Mage.Client/src/main/java/mage/client/dialog/TestModalSampleDialog.java diff --git a/Mage.Client/src/main/java/mage/client/dialog/TestModalDialog.form b/Mage.Client/src/main/java/mage/client/dialog/TestModalDialog.form new file mode 100644 index 0000000000..ee033ae8af --- /dev/null +++ b/Mage.Client/src/main/java/mage/client/dialog/TestModalDialog.form @@ -0,0 +1,194 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/Mage.Client/src/main/java/mage/client/dialog/TestModalDialog.java b/Mage.Client/src/main/java/mage/client/dialog/TestModalDialog.java new file mode 100644 index 0000000000..fd2e785cbe --- /dev/null +++ b/Mage.Client/src/main/java/mage/client/dialog/TestModalDialog.java @@ -0,0 +1,345 @@ +package mage.client.dialog; + +import mage.client.MageFrame; +import org.apache.log4j.Logger; + +import javax.swing.*; +import java.awt.event.KeyEvent; + +/** + * @author JayDi85 + */ +public class TestModalDialog extends MageDialog { + + private static final Logger logger = Logger.getLogger(TestModalDialog.class); + + private final TestModalSampleDialog constModalDialog1; + private final TestModalSampleDialog constModalDialog2; + private final TestModalSampleDialog constModalDialog3; + + private final TestModalSampleDialog constNonModalDialog1; + private final TestModalSampleDialog constNonModalDialog2; + private final TestModalSampleDialog constNonModalDialog3; + + public TestModalDialog() { + initComponents(); + + constModalDialog1 = new TestModalSampleDialog("const modal dialog 1", true, true, -50, -50); + constModalDialog2 = new TestModalSampleDialog("const modal dialog 2", true, true, -100, -100); + constModalDialog3 = new TestModalSampleDialog("const modal dialog 3", true, true, -150, -150); + + constNonModalDialog1 = new TestModalSampleDialog("const non modal dialog 1", false, true, -50, -50); + constNonModalDialog2 = new TestModalSampleDialog("const non modal dialog 2", false, true, -100, -100); + constNonModalDialog3 = new TestModalSampleDialog("const non modal dialog 3", false, true, -150, -150); + } + + public void showDialog() { + this.setModal(false); + getRootPane().setDefaultButton(buttonCancel); + + // 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); + + this.setVisible(true); + } + + private void onCancel() { + this.removeDialog(); + } + + private void showLater(TestModalSampleDialog dialog) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + logger.info(dialog.getTitle()); + dialog.showDialog(); + } + }); + } + + private void showConstModalDialogs(boolean isReverse) { + if (isReverse) { + showLater(constModalDialog3); + showLater(constModalDialog2); + showLater(constModalDialog1); + } else { + showLater(constModalDialog1); + showLater(constModalDialog2); + showLater(constModalDialog3); + } + } + + private void showConstNonModalDialogs(boolean isReverse) { + if (isReverse) { + showLater(constNonModalDialog3); + showLater(constNonModalDialog2); + showLater(constNonModalDialog1); + } else { + showLater(constNonModalDialog1); + showLater(constNonModalDialog2); + showLater(constNonModalDialog3); + } + } + + private void showDynModalDialogs(boolean isReverse) { + TestModalSampleDialog dynDialog1 = new TestModalSampleDialog("dyn modal dialog 1", true, false, -50, -50); + TestModalSampleDialog dynDialog2 = new TestModalSampleDialog("dyn modal dialog 2", true, false, -100, -100); + TestModalSampleDialog dynDialog3 = new TestModalSampleDialog("dyn modal dialog 3", true, false, -150, -150); + + if (isReverse) { + showLater(dynDialog3); + showLater(dynDialog2); + showLater(dynDialog1); + } else { + showLater(dynDialog1); + showLater(dynDialog2); + showLater(dynDialog3); + } + } + + private void showDynNonModalDialogs(boolean isReverse) { + TestModalSampleDialog dynDialog1 = new TestModalSampleDialog("dyn non modal dialog 1", false, false, -50, -50); + TestModalSampleDialog dynDialog2 = new TestModalSampleDialog("dyn non modal dialog 2", false, false, -100, -100); + TestModalSampleDialog dynDialog3 = new TestModalSampleDialog("dyn non modal dialog 3", false, false, -150, -150); + + if (isReverse) { + showLater(dynDialog3); + showLater(dynDialog2); + showLater(dynDialog1); + } else { + showLater(dynDialog1); + showLater(dynDialog2); + showLater(dynDialog3); + } + } + + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + buttonCancel = new javax.swing.JButton(); + jLabel1 = new javax.swing.JLabel(); + buttonShowConstModal123 = new javax.swing.JButton(); + buttonShowConstModal321 = new javax.swing.JButton(); + buttonShowDynModal123 = new javax.swing.JButton(); + buttonShowDynModal321 = new javax.swing.JButton(); + jLabel2 = new javax.swing.JLabel(); + buttonShowConstNonModal123 = new javax.swing.JButton(); + buttonShowConstNonModal321 = new javax.swing.JButton(); + buttonShowDynNonModal321 = new javax.swing.JButton(); + buttonShowDynNonModal123 = new javax.swing.JButton(); + buttonPrintFramesList = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + buttonCancel.setText("Close"); + buttonCancel.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonCancelActionPerformed(evt); + } + }); + + jLabel1.setText("Test modal dialog system:"); + + buttonShowConstModal123.setText("const modal 123"); + buttonShowConstModal123.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonShowConstModal123ActionPerformed(evt); + } + }); + + buttonShowConstModal321.setText("const modal 321"); + buttonShowConstModal321.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonShowConstModal321ActionPerformed(evt); + } + }); + + buttonShowDynModal123.setText("dyn modal 123"); + buttonShowDynModal123.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonShowDynModal123ActionPerformed(evt); + } + }); + + buttonShowDynModal321.setText("dyn modal 321"); + buttonShowDynModal321.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonShowDynModal321ActionPerformed(evt); + } + }); + + jLabel2.setText("Test mon modal dialog system:"); + + buttonShowConstNonModal123.setText("const non modal 123"); + buttonShowConstNonModal123.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonShowConstNonModal123ActionPerformed(evt); + } + }); + + buttonShowConstNonModal321.setText("const non modal 321"); + buttonShowConstNonModal321.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonShowConstNonModal321ActionPerformed(evt); + } + }); + + buttonShowDynNonModal321.setText("dyn non modal 321"); + buttonShowDynNonModal321.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonShowDynNonModal321ActionPerformed(evt); + } + }); + + buttonShowDynNonModal123.setText("dyn non modal 123"); + buttonShowDynNonModal123.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonShowDynNonModal123ActionPerformed(evt); + } + }); + + buttonPrintFramesList.setText("print frames list"); + buttonPrintFramesList.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonPrintFramesListActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1) + .addGroup(layout.createSequentialGroup() + .addComponent(buttonShowConstModal123) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonShowConstModal321)) + .addGroup(layout.createSequentialGroup() + .addComponent(buttonShowDynModal123) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonShowDynModal321)) + .addComponent(jLabel2) + .addGroup(layout.createSequentialGroup() + .addComponent(buttonShowConstNonModal123) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonShowConstNonModal321)) + .addGroup(layout.createSequentialGroup() + .addComponent(buttonShowDynNonModal123) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonShowDynNonModal321)) + .addComponent(buttonPrintFramesList)) + .addGap(0, 44, Short.MAX_VALUE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonShowConstModal123) + .addComponent(buttonShowConstModal321)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonShowDynModal123) + .addComponent(buttonShowDynModal321)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonShowConstNonModal123) + .addComponent(buttonShowConstNonModal321)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonShowDynNonModal123) + .addComponent(buttonShowDynNonModal321)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonPrintFramesList) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 129, Short.MAX_VALUE) + .addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + private void buttonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelActionPerformed + onCancel(); + }//GEN-LAST:event_buttonCancelActionPerformed + + private void buttonShowConstModal123ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowConstModal123ActionPerformed + showConstModalDialogs(false); + }//GEN-LAST:event_buttonShowConstModal123ActionPerformed + + private void buttonShowConstModal321ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowConstModal321ActionPerformed + showConstModalDialogs(true); + }//GEN-LAST:event_buttonShowConstModal321ActionPerformed + + private void buttonShowDynModal123ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowDynModal123ActionPerformed + showDynModalDialogs(false); + }//GEN-LAST:event_buttonShowDynModal123ActionPerformed + + private void buttonShowDynModal321ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowDynModal321ActionPerformed + showDynModalDialogs(true); + }//GEN-LAST:event_buttonShowDynModal321ActionPerformed + + private void buttonShowConstNonModal123ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowConstNonModal123ActionPerformed + showConstNonModalDialogs(false); + }//GEN-LAST:event_buttonShowConstNonModal123ActionPerformed + + private void buttonShowConstNonModal321ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowConstNonModal321ActionPerformed + showConstNonModalDialogs(true); + }//GEN-LAST:event_buttonShowConstNonModal321ActionPerformed + + private void buttonShowDynNonModal321ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowDynNonModal321ActionPerformed + showDynNonModalDialogs(true); + }//GEN-LAST:event_buttonShowDynNonModal321ActionPerformed + + private void buttonShowDynNonModal123ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowDynNonModal123ActionPerformed + showDynNonModalDialogs(false); + }//GEN-LAST:event_buttonShowDynNonModal123ActionPerformed + + private void buttonPrintFramesListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPrintFramesListActionPerformed + MageDialog.printFramesOrder("print"); + }//GEN-LAST:event_buttonPrintFramesListActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton buttonCancel; + private javax.swing.JButton buttonPrintFramesList; + private javax.swing.JButton buttonShowConstModal123; + private javax.swing.JButton buttonShowConstModal321; + private javax.swing.JButton buttonShowConstNonModal123; + private javax.swing.JButton buttonShowConstNonModal321; + private javax.swing.JButton buttonShowDynModal123; + private javax.swing.JButton buttonShowDynModal321; + private javax.swing.JButton buttonShowDynNonModal123; + private javax.swing.JButton buttonShowDynNonModal321; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + // End of variables declaration//GEN-END:variables +} diff --git a/Mage.Client/src/main/java/mage/client/dialog/TestModalSampleDialog.form b/Mage.Client/src/main/java/mage/client/dialog/TestModalSampleDialog.form new file mode 100644 index 0000000000..263652f535 --- /dev/null +++ b/Mage.Client/src/main/java/mage/client/dialog/TestModalSampleDialog.form @@ -0,0 +1,65 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/Mage.Client/src/main/java/mage/client/dialog/TestModalSampleDialog.java b/Mage.Client/src/main/java/mage/client/dialog/TestModalSampleDialog.java new file mode 100644 index 0000000000..19575ad9a0 --- /dev/null +++ b/Mage.Client/src/main/java/mage/client/dialog/TestModalSampleDialog.java @@ -0,0 +1,119 @@ +package mage.client.dialog; + +import mage.client.MageFrame; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.KeyEvent; + +/** + * @author JayDi85 + */ +public class TestModalSampleDialog extends MageDialog { + + private final boolean useModal; + private final boolean useHideDialog; + private final int offsetX; + private final int offsetY; + + public TestModalSampleDialog(String name, boolean useModal, boolean useHideDialog, int offsetX, int offsetY) { + initComponents(); + + this.useModal = useModal; + this.useHideDialog = useHideDialog; + this.offsetX = offsetX; + this.offsetY = offsetY; + + labelInfo.setText(name); + this.setTitle(name); + } + + public void showDialog() { + this.setModal(useModal); + getRootPane().setDefaultButton(buttonCancel); + + // 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(); + Point p = this.getLocation(); + p.x = p.x + offsetX; + p.y = p.y + offsetY; + this.setLocation(p); + + // Close on "ESC" + registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + + this.setVisible(true); + } + + private void onCancel() { + if (useHideDialog) { + this.hideDialog(); + } else { + this.removeDialog(); + } + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + buttonCancel = new javax.swing.JButton(); + labelInfo = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + buttonCancel.setText("Close"); + buttonCancel.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonCancelActionPerformed(evt); + } + }); + + labelInfo.setText("Sample dialog"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap(290, Short.MAX_VALUE) + .addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(labelInfo) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addComponent(labelInfo) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 234, Short.MAX_VALUE) + .addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + private void buttonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelActionPerformed + onCancel(); + }//GEN-LAST:event_buttonCancelActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton buttonCancel; + private javax.swing.JLabel labelInfo; + // End of variables declaration//GEN-END:variables +}