From 2de4506ad292a91a757133a7403b0b4f0560e00f Mon Sep 17 00:00:00 2001 From: magenoxx Date: Mon, 16 Jul 2012 16:49:09 +0400 Subject: [PATCH] [UI] Added popup menu. Moved Concede action to popup. --- .../mage/client/game/BattlefieldPanel.java | 3 ++ .../main/java/mage/client/game/GamePanel.java | 6 ---- .../java/mage/client/game/PlayAreaPanel.java | 36 +++++++++++++++++-- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java b/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java index fc63aa95ef..fa09fec63f 100644 --- a/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java +++ b/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java @@ -294,4 +294,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane { this.add(jScrollPane); } + public JComponent getMainPanel() { + return jPanel; + } } diff --git a/Mage.Client/src/main/java/mage/client/game/GamePanel.java b/Mage.Client/src/main/java/mage/client/game/GamePanel.java index 1da48b3136..b715441ee3 100644 --- a/Mage.Client/src/main/java/mage/client/game/GamePanel.java +++ b/Mage.Client/src/main/java/mage/client/game/GamePanel.java @@ -130,12 +130,6 @@ public class GamePanel extends javax.swing.JPanel { throw new RuntimeException(e); } - /*SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - bigCard.setDefaultImage(); - } - });*/ } private Map getUIComponents(JLayeredPane jLayeredPane) { diff --git a/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java b/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java index db618469cd..65ac7d53fa 100644 --- a/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java +++ b/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java @@ -36,6 +36,10 @@ import javax.swing.*; import javax.swing.GroupLayout.Alignment; import javax.swing.LayoutStyle.ComponentPlacement; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.UUID; /** @@ -51,9 +55,8 @@ public class PlayAreaPanel extends javax.swing.JPanel { public PlayAreaPanel() { initComponents(); setOpaque(false); - //jScrollPane1.setOpaque(false); - //jScrollPane1.getViewport().setOpaque(false); battlefieldPanel.setOpaque(false); + addPopupMenu(); } public PlayAreaPanel(PlayerView player, BigCard bigCard, UUID gameId, boolean me) { @@ -62,6 +65,35 @@ public class PlayAreaPanel extends javax.swing.JPanel { update(player); } + private void addPopupMenu() { + final JPopupMenu Pmenu; + JMenuItem menuItem; + + Pmenu = new JPopupMenu(); + menuItem = new JMenuItem("Concede"); + Pmenu.add(menuItem); + + // Concede + menuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (JOptionPane.showConfirmDialog(PlayAreaPanel.this, "Are you sure you want to concede?", "Confirm concede", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { + MageFrame.getSession().concedeGame(gameId); + } + } + }); + + menuItem = new JMenuItem("Cancel"); + Pmenu.add(menuItem); + + battlefieldPanel.getMainPanel().addMouseListener(new MouseAdapter() { + public void mouseReleased(MouseEvent Me) { + if (Me.isPopupTrigger()) { + Pmenu.show(Me.getComponent(), Me.getX(), Me.getY()); + } + } + }); + } + public final void init(PlayerView player, BigCard bigCard, UUID gameId) { this.playerPanel.init(gameId, player.getPlayerId(), bigCard); this.battlefieldPanel.init(gameId, bigCard);