forked from External/mage
More changes to reduce memory leaks.
This commit is contained in:
parent
da2dc4cd5a
commit
e2c0e211ef
4 changed files with 229 additions and 149 deletions
|
|
@ -34,13 +34,10 @@
|
|||
|
||||
package mage.client.game;
|
||||
|
||||
import java.beans.PropertyVetoException;
|
||||
import mage.client.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.SwingUtilities;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.MagePane;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -68,13 +65,20 @@ public class GamePane extends MagePane {
|
|||
}
|
||||
|
||||
public void hideGame() {
|
||||
try {
|
||||
gamePanel.hideGame();
|
||||
this.setClosed(true);
|
||||
} catch (PropertyVetoException ex) {
|
||||
Logger.getLogger(GamePane.class.getName()).log(Level.SEVERE, "GamePane could not be closed", ex);
|
||||
this.dispose();
|
||||
}
|
||||
// try {
|
||||
MageFrame.deactivate(this);
|
||||
MageFrame.getDesktop().remove(this);
|
||||
|
||||
gamePanel.cleanUp();
|
||||
|
||||
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 watchGame(UUID gameId) {
|
||||
|
|
|
|||
|
|
@ -27,6 +27,46 @@
|
|||
*/
|
||||
package mage.client.game;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.GroupLayout;
|
||||
import javax.swing.GroupLayout.Alignment;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLayeredPane;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.border.LineBorder;
|
||||
import javax.swing.plaf.basic.BasicSplitPaneDivider;
|
||||
import javax.swing.plaf.basic.BasicSplitPaneUI;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.action.ActionCallback;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.cards.BigCard;
|
||||
|
|
@ -36,35 +76,34 @@ import mage.client.components.HoverButton;
|
|||
import mage.client.components.MageComponents;
|
||||
import mage.client.components.ext.dlg.DialogManager;
|
||||
import mage.client.components.layout.RelativeLayout;
|
||||
import mage.client.dialog.*;
|
||||
import mage.client.dialog.ExileZoneDialog;
|
||||
import mage.client.dialog.PickChoiceDialog;
|
||||
import mage.client.dialog.PickNumberDialog;
|
||||
import mage.client.dialog.PickPileDialog;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import mage.client.dialog.ShowCardsDialog;
|
||||
import mage.client.game.FeedbackPanel.FeedbackMode;
|
||||
import mage.client.plugins.adapters.MageActionCallback;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.CardsViewUtil;
|
||||
import mage.client.util.Config;
|
||||
import mage.client.util.GameManager;
|
||||
import mage.client.util.PhaseManager;
|
||||
import mage.client.util.gui.ArrowBuilder;
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.remote.Session;
|
||||
import mage.view.*;
|
||||
import mage.view.AbilityPickerView;
|
||||
import mage.view.CardsView;
|
||||
import mage.view.ExileView;
|
||||
import mage.view.GameView;
|
||||
import mage.view.LookedAtView;
|
||||
import mage.view.MatchView;
|
||||
import mage.view.PlayerView;
|
||||
import mage.view.RevealedView;
|
||||
import mage.view.SimpleCardsView;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mage.plugins.card.utils.impl.ImageManagerImpl;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.GroupLayout.Alignment;
|
||||
import javax.swing.border.LineBorder;
|
||||
import javax.swing.plaf.basic.BasicSplitPaneDivider;
|
||||
import javax.swing.plaf.basic.BasicSplitPaneUI;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import mage.cards.Card;
|
||||
import mage.client.util.CardsViewUtil;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com, nantuko8
|
||||
|
|
@ -105,12 +144,12 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
|
||||
// Override layout (I can't edit generated code)
|
||||
this.setLayout(new BorderLayout());
|
||||
final JLayeredPane j = new JLayeredPane();
|
||||
j.setSize(1024, 768);
|
||||
this.add(j);
|
||||
j.add(jSplitPane0, JLayeredPane.DEFAULT_LAYER);
|
||||
final JLayeredPane jLayeredBackgroundPane = new JLayeredPane();
|
||||
jLayeredBackgroundPane.setSize(1024, 768);
|
||||
this.add(jLayeredBackgroundPane);
|
||||
jLayeredBackgroundPane.add(jSplitPane0, JLayeredPane.DEFAULT_LAYER);
|
||||
|
||||
Map<String, JComponent> myUi = getUIComponents(j);
|
||||
Map<String, JComponent> myUi = getUIComponents(jLayeredBackgroundPane);
|
||||
Plugins.getInstance().updateGamePanel(myUi);
|
||||
|
||||
// Enlarge jlayeredpane on resize
|
||||
|
|
@ -119,7 +158,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
public void componentResized(ComponentEvent e) {
|
||||
int width = ((JComponent) e.getSource()).getWidth();
|
||||
int height = ((JComponent) e.getSource()).getHeight();
|
||||
j.setSize(width, height);
|
||||
jLayeredBackgroundPane.setSize(width, height);
|
||||
jSplitPane0.setSize(width, height);
|
||||
|
||||
if (height < storedHeight) {
|
||||
|
|
@ -160,12 +199,39 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
MageFrame.removeGame(gameId);
|
||||
saveDividerLocations();
|
||||
this.gameChatPanel.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);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
|
||||
this.getUI().uninstallUI(this);
|
||||
|
||||
|
||||
if (pickNumber != null) {
|
||||
MageFrame.getDesktop().remove(pickNumber);
|
||||
pickNumber.removeDialog();
|
||||
}
|
||||
for (ExileZoneDialog exile: exiles.values()) {
|
||||
|
|
@ -174,12 +240,16 @@ 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() {
|
||||
|
|
@ -324,13 +394,12 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
* Closes the game and it's resources
|
||||
*/
|
||||
public void hideGame() {
|
||||
cleanUp();
|
||||
Component c = this.getParent();
|
||||
while (c != null && !(c instanceof GamePane)) {
|
||||
c = c.getParent();
|
||||
}
|
||||
if (c != null) {
|
||||
((GamePane)c).hideFrame();
|
||||
((GamePane)c).hideGame();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import java.awt.event.ActionEvent;
|
|||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
|
@ -76,14 +77,22 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
update(player);
|
||||
}
|
||||
|
||||
public void CleanUp() {
|
||||
for (MouseListener ml :battlefieldPanel.getMainPanel().getMouseListeners()) {
|
||||
battlefieldPanel.getMainPanel().removeMouseListener(ml);
|
||||
}
|
||||
this.removeAll();
|
||||
this.getUI().uninstallUI(this);
|
||||
}
|
||||
|
||||
private void addPopupMenu() {
|
||||
final JPopupMenu Pmenu;
|
||||
final JPopupMenu popupMenu;
|
||||
JMenuItem menuItem;
|
||||
|
||||
Pmenu = new JPopupMenu();
|
||||
popupMenu = new JPopupMenu();
|
||||
|
||||
menuItem = new JMenuItem("F2 - Confirm");
|
||||
Pmenu.add(menuItem);
|
||||
popupMenu.add(menuItem);
|
||||
|
||||
// Confirm (F2)
|
||||
menuItem.addActionListener(new ActionListener() {
|
||||
|
|
@ -97,7 +106,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
|
||||
|
||||
menuItem = new JMenuItem("F3 - Cancel previous F4/F9 skip action");
|
||||
Pmenu.add(menuItem);
|
||||
popupMenu.add(menuItem);
|
||||
|
||||
// Cancel (F3)
|
||||
menuItem.addActionListener(new ActionListener() {
|
||||
|
|
@ -107,10 +116,10 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
}
|
||||
});
|
||||
|
||||
Pmenu.addSeparator();
|
||||
popupMenu.addSeparator();
|
||||
|
||||
menuItem = new JMenuItem("F4 - Skip phases until next turn (stop on stack/attack/block)");
|
||||
Pmenu.add(menuItem);
|
||||
popupMenu.add(menuItem);
|
||||
|
||||
// Skip to next turn (F4)
|
||||
menuItem.addActionListener(new ActionListener() {
|
||||
|
|
@ -121,7 +130,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
});
|
||||
|
||||
menuItem = new JMenuItem("F9 - Skip everything until own next turn (stop on attack/block)");
|
||||
Pmenu.add(menuItem);
|
||||
popupMenu.add(menuItem);
|
||||
|
||||
// Skip to next own turn (F9)
|
||||
menuItem.addActionListener(new ActionListener() {
|
||||
|
|
@ -131,10 +140,10 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
}
|
||||
});
|
||||
|
||||
Pmenu.addSeparator();
|
||||
popupMenu.addSeparator();
|
||||
|
||||
menuItem = new JMenuItem("Concede game");
|
||||
Pmenu.add(menuItem);
|
||||
popupMenu.add(menuItem);
|
||||
|
||||
// Concede
|
||||
menuItem.addActionListener(new ActionListener() {
|
||||
|
|
@ -146,10 +155,10 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
}
|
||||
});
|
||||
|
||||
Pmenu.addSeparator();
|
||||
popupMenu.addSeparator();
|
||||
|
||||
menuItem = new JMenuItem("Concede complete match");
|
||||
Pmenu.add(menuItem);
|
||||
popupMenu.add(menuItem);
|
||||
|
||||
// Quit match
|
||||
menuItem.addActionListener(new ActionListener() {
|
||||
|
|
@ -170,20 +179,20 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
@Override
|
||||
public void mouseReleased(MouseEvent Me) {
|
||||
if (Me.isPopupTrigger() && playingMode) {
|
||||
Pmenu.show(Me.getComponent(), Me.getX(), Me.getY());
|
||||
popupMenu.show(Me.getComponent(), Me.getX(), Me.getY());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addPopupMenuWatcher() {
|
||||
final JPopupMenu Pmenu;
|
||||
final JPopupMenu popupMenu;
|
||||
JMenuItem menuItem;
|
||||
|
||||
Pmenu = new JPopupMenu();
|
||||
popupMenu = new JPopupMenu();
|
||||
|
||||
menuItem = new JMenuItem("Stop watching");
|
||||
Pmenu.add(menuItem);
|
||||
popupMenu.add(menuItem);
|
||||
|
||||
// Stop watching
|
||||
menuItem.addActionListener(new ActionListener() {
|
||||
|
|
@ -200,7 +209,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
@Override
|
||||
public void mouseReleased(MouseEvent Me) {
|
||||
if (Me.isPopupTrigger() && playingMode) {
|
||||
Pmenu.show(Me.getComponent(), Me.getX(), Me.getY());
|
||||
popupMenu.show(Me.getComponent(), Me.getX(), Me.getY());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue