forked from External/mage
Removed more memory leaks in game and editor panes and panels of client.
This commit is contained in:
parent
48a7e52701
commit
dda33f86a4
12 changed files with 199 additions and 95 deletions
|
|
@ -42,6 +42,8 @@ import java.util.Map.Entry;
|
|||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* ************************ U N U S E D *********************************
|
||||
*
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
|
|
@ -50,7 +52,7 @@ public class AbilityPicker extends JPopupMenu implements PopupMenuListener {
|
|||
private Session session;
|
||||
private UUID gameId;
|
||||
|
||||
public AbilityPicker() {
|
||||
public AbilityPicker(String ThisIsnotUsedAnymore) {
|
||||
this.addPopupMenuListener(this);
|
||||
}
|
||||
|
||||
|
|
@ -59,8 +61,14 @@ public class AbilityPicker extends JPopupMenu implements PopupMenuListener {
|
|||
this.gameId = gameId;
|
||||
}
|
||||
|
||||
public void cleanUp() {
|
||||
this.removePopupMenuListener(this);
|
||||
}
|
||||
|
||||
public void show(AbilityPickerView choices, Point p) {
|
||||
if (p == null) return;
|
||||
if (p == null) {
|
||||
return;
|
||||
}
|
||||
this.removeAll();
|
||||
for (Entry<UUID, String> choice: choices.getChoices().entrySet()) {
|
||||
this.add(new AbilityPickerAction(choice.getKey(), choice.getValue()));
|
||||
|
|
|
|||
|
|
@ -34,12 +34,9 @@
|
|||
|
||||
package mage.client.game;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.KeyboardFocusManager;
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.util.UUID;
|
||||
import javax.swing.SwingUtilities;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.MagePane;
|
||||
import mage.client.dialog.MageDialog;
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
@ -72,32 +69,16 @@ public class GamePane extends MagePane {
|
|||
gamePanel.showGame(gameId, playerId);
|
||||
}
|
||||
|
||||
public void hideGame() {
|
||||
KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
|
||||
public void cleanUp() {
|
||||
gamePanel.cleanUp();
|
||||
this.getInputMap().clear();
|
||||
this.getActionMap().clear();
|
||||
}
|
||||
|
||||
try {
|
||||
this.setClosed(true);
|
||||
} catch (PropertyVetoException ex) {
|
||||
logger.fatal("Closing Game: setClosed - ", ex);
|
||||
}
|
||||
MageFrame.deactivate(this);
|
||||
MageFrame.getDesktop().remove(this);
|
||||
|
||||
logger.warn("Remove Dialog " + this.getClass().getName() + " Components left: "+ this.getComponentCount());
|
||||
|
||||
for (Component comp: this.getComponents()) {
|
||||
logger.warn("Existing Component: " + comp.getClass().getName());
|
||||
}
|
||||
|
||||
// this.getUI().uninstallUI(this);
|
||||
// this.removeAll();
|
||||
// this.dispose();
|
||||
// this.setClosed(true);
|
||||
// } catch (PropertyVetoException ex) {
|
||||
// Logger.getLogger(GamePane.class.getName()).log(Level.SEVERE, "GamePane could not be closed", ex);
|
||||
// this.dispose();
|
||||
// }
|
||||
public void hideGame() {
|
||||
KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
|
||||
this.cleanUp();
|
||||
this.removeFrame();
|
||||
}
|
||||
|
||||
public void watchGame(UUID gameId) {
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import java.awt.event.ActionEvent;
|
|||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
|
|
@ -199,39 +200,28 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
MageFrame.removeGame(gameId);
|
||||
saveDividerLocations();
|
||||
this.gameChatPanel.disconnect();
|
||||
this.userChatPanel.disconnect();
|
||||
|
||||
for (MouseListener ml :this.getMouseListeners()) {
|
||||
this.removeMouseListener(ml);
|
||||
}
|
||||
for (MouseListener ml :this.btnConcede.getMouseListeners()) {
|
||||
this.btnConcede.removeMouseListener(ml);
|
||||
}
|
||||
for (MouseListener ml :this.btnEndTurn.getMouseListeners()) {
|
||||
this.btnEndTurn.removeMouseListener(ml);
|
||||
}
|
||||
for (MouseListener ml :this.btnSwitchHands.getMouseListeners()) {
|
||||
this.btnSwitchHands.removeMouseListener(ml);
|
||||
}
|
||||
this.removeListener();
|
||||
|
||||
for (ActionListener al :this.btnStopWatching.getActionListeners()) {
|
||||
this.btnStopWatching.removeActionListener(al);
|
||||
}
|
||||
for (ActionListener al :this.btnNextPlay.getActionListeners()) {
|
||||
this.btnNextPlay.removeActionListener(al);
|
||||
}
|
||||
for(Map.Entry<UUID, PlayAreaPanel> playAreaPanelEntry: players.entrySet()) {
|
||||
playAreaPanelEntry.getValue().CleanUp();
|
||||
// playAreaPanelEntry.getValue().getUI().uninstallUI(playAreaPanelEntry.getValue());
|
||||
// playAreaPanelEntry.getValue().removeAll();
|
||||
}
|
||||
this.players.clear();
|
||||
|
||||
this.pnlBattlefield.removeAll();
|
||||
jLayeredPane.remove(abilityPicker);
|
||||
this.abilityPicker.cleanUp();
|
||||
|
||||
this.getUI().uninstallUI(this);
|
||||
jLayeredPane.remove(DialogManager.getManager(gameId));
|
||||
DialogManager.removeGame(gameId);
|
||||
|
||||
this.getInputMap().clear();
|
||||
this.getActionMap().clear();
|
||||
|
||||
// this.pnlBattlefield.removeAll();
|
||||
// this.getUI().uninstallUI(this);
|
||||
|
||||
if (pickNumber != null) {
|
||||
MageFrame.getDesktop().remove(pickNumber);
|
||||
pickNumber.removeDialog();
|
||||
}
|
||||
for (ExileZoneDialog exile: exiles.values()) {
|
||||
|
|
@ -240,16 +230,13 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
for (ShowCardsDialog reveal: revealed.values()) {
|
||||
reveal.hideDialog();
|
||||
}
|
||||
this.jSplitPane0.getUI().uninstallUI(jSplitPane0);
|
||||
this.jSplitPane0.removeAll();
|
||||
|
||||
|
||||
try {
|
||||
Component popupContainer = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER);
|
||||
popupContainer.setVisible(false);
|
||||
} catch (InterruptedException ex) {
|
||||
logger.fatal("popupContainer error:", ex);
|
||||
}
|
||||
// this.removeAll();
|
||||
}
|
||||
|
||||
private void saveDividerLocations() {
|
||||
|
|
@ -877,8 +864,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
});
|
||||
|
||||
int c = JComponent.WHEN_IN_FOCUSED_WINDOW;
|
||||
KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0);
|
||||
|
||||
KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0);
|
||||
this.getInputMap(c).put(ks, "F4_PRESS");
|
||||
this.getActionMap().put("F4_PRESS", new AbstractAction() {
|
||||
@Override
|
||||
|
|
@ -1028,6 +1015,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
}
|
||||
});
|
||||
|
||||
// Replay panel to control replay of games
|
||||
javax.swing.GroupLayout gl_pnlReplay = new javax.swing.GroupLayout(pnlReplay);
|
||||
pnlReplay.setLayout(gl_pnlReplay);
|
||||
gl_pnlReplay.setHorizontalGroup(
|
||||
|
|
@ -1052,6 +1040,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
.addComponent(btnPreviousPlay, javax.swing.GroupLayout.PREFERRED_SIZE, 31, Short.MAX_VALUE)
|
||||
);
|
||||
|
||||
// Game info panel (buttons on the right panel)
|
||||
javax.swing.GroupLayout gl_pnlGameInfo = new javax.swing.GroupLayout(pnlGameInfo);
|
||||
pnlGameInfo.setLayout(gl_pnlGameInfo);
|
||||
gl_pnlGameInfo.setHorizontalGroup(
|
||||
|
|
@ -1222,6 +1211,57 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
);
|
||||
}
|
||||
|
||||
private void removeListener() {
|
||||
for (MouseListener ml :this.getMouseListeners()) {
|
||||
this.removeMouseListener(ml);
|
||||
}
|
||||
for (MouseListener ml :this.btnConcede.getMouseListeners()) {
|
||||
this.btnConcede.removeMouseListener(ml);
|
||||
}
|
||||
for (MouseListener ml :this.btnEndTurn.getMouseListeners()) {
|
||||
this.btnEndTurn.removeMouseListener(ml);
|
||||
}
|
||||
for (MouseListener ml :this.btnSwitchHands.getMouseListeners()) {
|
||||
this.btnSwitchHands.removeMouseListener(ml);
|
||||
}
|
||||
for (ActionListener al :this.btnPlay.getActionListeners()) {
|
||||
this.btnPlay.removeActionListener(al);
|
||||
}
|
||||
for (ActionListener al :this.btnStopWatching.getActionListeners()) {
|
||||
this.btnStopWatching.removeActionListener(al);
|
||||
}
|
||||
for (ActionListener al :this.btnStopReplay.getActionListeners()) {
|
||||
this.btnStopReplay.removeActionListener(al);
|
||||
}
|
||||
for (ActionListener al :this.btnNextPlay.getActionListeners()) {
|
||||
this.btnNextPlay.removeActionListener(al);
|
||||
}
|
||||
for (ActionListener al :this.btnNextPlay.getActionListeners()) {
|
||||
this.btnNextPlay.removeActionListener(al);
|
||||
}
|
||||
for (ActionListener al :this.btnPreviousPlay.getActionListeners()) {
|
||||
this.btnPreviousPlay.removeActionListener(al);
|
||||
}
|
||||
for (ActionListener al :this.btnSkipForward.getActionListeners()) {
|
||||
this.btnSkipForward.removeActionListener(al);
|
||||
}
|
||||
|
||||
final BasicSplitPaneUI myUi = (BasicSplitPaneUI) jSplitPane0.getUI();
|
||||
final BasicSplitPaneDivider divider = myUi.getDivider();
|
||||
final JButton upArrowButton = (JButton) divider.getComponent(0);
|
||||
for (ActionListener al: upArrowButton.getActionListeners()) {
|
||||
upArrowButton.removeActionListener(al);
|
||||
}
|
||||
final JButton downArrowButton = (JButton) divider.getComponent(1);
|
||||
for (ActionListener al: downArrowButton.getActionListeners()) {
|
||||
downArrowButton.removeActionListener(al);
|
||||
}
|
||||
|
||||
for (ComponentListener cl : this.getComponentListeners()) {
|
||||
this.removeComponentListener(cl);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnConcedeActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
if (modalQuestion("Are you sure you want to concede?", "Confirm concede") == JOptionPane.YES_OPTION) {
|
||||
session.concedeGame(gameId);
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ public class HelperPanel extends JPanel {
|
|||
//private javax.swing.JButton btnStopTimer;
|
||||
|
||||
private MageTextArea textArea;
|
||||
private javax.swing.JScrollPane jScrollPane1;
|
||||
|
||||
private javax.swing.JButton linkLeft;
|
||||
private javax.swing.JButton linkRight;
|
||||
|
|
|
|||
|
|
@ -38,10 +38,13 @@ import javax.swing.LayoutStyle.ComponentPlacement;
|
|||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.util.UUID;
|
||||
import javax.swing.event.MenuKeyListener;
|
||||
import javax.swing.plaf.basic.BasicPopupMenuUI;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -49,6 +52,7 @@ import java.util.UUID;
|
|||
*/
|
||||
public class PlayAreaPanel extends javax.swing.JPanel {
|
||||
|
||||
private final JPopupMenu popupMenu;
|
||||
private UUID playerId;
|
||||
private UUID gameId;
|
||||
private boolean smallMode = false;
|
||||
|
|
@ -63,8 +67,9 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
initComponents();
|
||||
setOpaque(false);
|
||||
battlefieldPanel.setOpaque(false);
|
||||
popupMenu = new JPopupMenu();
|
||||
if (isPlayer) {
|
||||
addPopupMenu();
|
||||
addPopupMenuPlayer();
|
||||
} else {
|
||||
addPopupMenuWatcher();
|
||||
}
|
||||
|
|
@ -80,16 +85,32 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
public void CleanUp() {
|
||||
for (MouseListener ml :battlefieldPanel.getMainPanel().getMouseListeners()) {
|
||||
battlefieldPanel.getMainPanel().removeMouseListener(ml);
|
||||
}
|
||||
this.removeAll();
|
||||
this.getUI().uninstallUI(this);
|
||||
}
|
||||
playerPanel.cleanUp();
|
||||
for (KeyListener kl: popupMenu.getKeyListeners()) {
|
||||
popupMenu.removeKeyListener(kl);
|
||||
}
|
||||
for (MenuKeyListener mkl: popupMenu.getMenuKeyListeners()) {
|
||||
popupMenu.removeMenuKeyListener(mkl);
|
||||
}
|
||||
|
||||
for (Component child : popupMenu.getComponents()) {
|
||||
if (child instanceof JMenuItem) {
|
||||
JMenuItem menuItem = (JMenuItem) child;
|
||||
for (ActionListener al: menuItem.getActionListeners()) {
|
||||
menuItem.removeActionListener(al);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (MouseListener ml :battlefieldPanel.getMainPanel().getMouseListeners()) {
|
||||
battlefieldPanel.getMainPanel().removeMouseListener(ml);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void addPopupMenu() {
|
||||
final JPopupMenu popupMenu;
|
||||
JMenuItem menuItem;
|
||||
private void addPopupMenuPlayer() {
|
||||
|
||||
popupMenu = new JPopupMenu();
|
||||
JMenuItem menuItem;
|
||||
|
||||
menuItem = new JMenuItem("F2 - Confirm");
|
||||
popupMenu.add(menuItem);
|
||||
|
|
@ -170,11 +191,6 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
}
|
||||
});
|
||||
|
||||
// Pmenu.addSeparator();
|
||||
//
|
||||
// menuItem = new JMenuItem("Cancel");
|
||||
// Pmenu.add(menuItem);
|
||||
|
||||
battlefieldPanel.getMainPanel().addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent Me) {
|
||||
|
|
@ -186,11 +202,8 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
}
|
||||
|
||||
private void addPopupMenuWatcher() {
|
||||
final JPopupMenu popupMenu;
|
||||
JMenuItem menuItem;
|
||||
|
||||
popupMenu = new JPopupMenu();
|
||||
|
||||
menuItem = new JMenuItem("Stop watching");
|
||||
popupMenu.add(menuItem);
|
||||
|
||||
|
|
|
|||
|
|
@ -152,6 +152,10 @@ public class PlayerPanelExt extends javax.swing.JPanel {
|
|||
}
|
||||
}
|
||||
|
||||
public void cleanUp() {
|
||||
this.timer.cancel();
|
||||
}
|
||||
|
||||
public void update(PlayerView player) {
|
||||
this.player = player;
|
||||
int playerLife = player.getLife();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue