Some changes to prevent memory leaks from gamePane (not fiished yet).

This commit is contained in:
LevelX2 2014-01-30 17:35:12 +01:00
parent f32b28abcc
commit da2dc4cd5a
5 changed files with 51 additions and 22 deletions

View file

@ -147,9 +147,9 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
private static Session session;
private ConnectDialog connectDialog;
private ErrorDialog errorDialog;
private final ErrorDialog errorDialog;
private static CallbackClient callbackClient;
private static Preferences prefs = Preferences.userNodeForPackage(MageFrame.class);
private static final Preferences prefs = Preferences.userNodeForPackage(MageFrame.class);
private JLabel title;
private Rectangle titleRectangle;
private static final MageVersion version = new MageVersion(1, 3, 0, "");
@ -159,13 +159,13 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
//TODO: make gray theme, implement theme selector in preferences dialog
private static boolean grayMode = false;
private static Map<UUID, ChatPanel> chats = new HashMap<UUID, ChatPanel>();
private static Map<UUID, GamePanel> games = new HashMap<UUID, GamePanel>();
private static Map<UUID, DraftPanel> drafts = new HashMap<UUID, DraftPanel>();
private static Map<UUID, TournamentPanel> tournaments = new HashMap<UUID, TournamentPanel>();
private static MageUI ui = new MageUI();
private static final Map<UUID, ChatPanel> chats = new HashMap<UUID, ChatPanel>();
private static final Map<UUID, GamePanel> games = new HashMap<UUID, GamePanel>();
private static final Map<UUID, DraftPanel> drafts = new HashMap<UUID, DraftPanel>();
private static final Map<UUID, TournamentPanel> tournaments = new HashMap<UUID, TournamentPanel>();
private static final MageUI ui = new MageUI();
private static ScheduledExecutorService pingTaskExecutor = Executors.newSingleThreadScheduledExecutor();
private static final ScheduledExecutorService pingTaskExecutor = Executors.newSingleThreadScheduledExecutor();
private static long startTime;
@ -579,6 +579,12 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
return topmost;
}
/**
* Shows a game for a player of the game
*
* @param gameId
* @param playerId
*/
public void showGame(UUID gameId, UUID playerId) {
try {
GamePane gamePane = new GamePane();
@ -1133,13 +1139,18 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
chats.remove(chatId);
}
public static void addGame(UUID gameId, GamePanel gamePanel) {
games.put(gameId, gamePanel);
}
public static GamePanel getGame(UUID gameId) {
return games.get(gameId);
}
public static void addGame(UUID gameId, GamePanel gamePanel) {
games.put(gameId, gamePanel);
public static void removeGame(UUID gameId) {
games.remove(gameId);
}
public static DraftPanel getDraft(UUID draftId) {
return drafts.get(draftId);
@ -1230,7 +1241,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
}
class MagePaneMenuItem extends JCheckBoxMenuItem {
private MagePane frame;
private final MagePane frame;
public MagePaneMenuItem(MagePane frame) {
super(frame.getTitle());

View file

@ -228,6 +228,7 @@ public class FeedbackDialog extends javax.swing.JDialog {
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
dialog.setVisible(false);
dialog.dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
private void sendButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendButtonActionPerformed

View file

@ -222,7 +222,7 @@ public class FeedbackPanel extends javax.swing.JPanel {
logger.debug("feedback - clear");
}
public void customInitComponents() {
private void customInitComponents() {
btnRight = new javax.swing.JButton();
btnLeft = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();

View file

@ -34,10 +34,13 @@
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;
/**
*
@ -65,7 +68,13 @@ public class GamePane extends MagePane {
}
public void hideGame() {
gamePanel.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();
}
}
public void watchGame(UUID gameId) {

View file

@ -73,16 +73,16 @@ public final class GamePanel extends javax.swing.JPanel {
private static final Logger logger = Logger.getLogger(GamePanel.class);
private static final String YOUR_HAND = "Your hand";
private static final int X_PHASE_WIDTH = 55;
private Map<UUID, PlayAreaPanel> players = new HashMap<UUID, PlayAreaPanel>();
private Map<UUID, ExileZoneDialog> exiles = new HashMap<UUID, ExileZoneDialog>();
private Map<String, ShowCardsDialog> revealed = new HashMap<String, ShowCardsDialog>();
private Map<String, ShowCardsDialog> lookedAt = new HashMap<String, ShowCardsDialog>();
private static final int X_PHASE_WIDTH = 55;
private final Map<UUID, PlayAreaPanel> players = new HashMap<UUID, PlayAreaPanel>();
private final Map<UUID, ExileZoneDialog> exiles = new HashMap<UUID, ExileZoneDialog>();
private final Map<String, ShowCardsDialog> revealed = new HashMap<String, ShowCardsDialog>();
private final Map<String, ShowCardsDialog> lookedAt = new HashMap<String, ShowCardsDialog>();
private UUID gameId;
private UUID playerId;
private Session session;
private ReplayTask replayTask;
private PickNumberDialog pickNumber;
private final PickNumberDialog pickNumber;
private JLayeredPane jLayeredPane;
private String chosenHandKey = "You";
private boolean smallMode = false;
@ -157,12 +157,17 @@ public final class GamePanel extends javax.swing.JPanel {
}
public void cleanUp() {
MageFrame.removeGame(gameId);
saveDividerLocations();
this.gameChatPanel.disconnect();
this.players.clear();
logger.debug("players clear.");
this.pnlBattlefield.removeAll();
pickNumber.hideDialog();
this.getUI().uninstallUI(this);
if (pickNumber != null) {
pickNumber.removeDialog();
}
for (ExileZoneDialog exile: exiles.values()) {
exile.hideDialog();
}
@ -174,7 +179,7 @@ public final class GamePanel extends javax.swing.JPanel {
popupContainer.setVisible(false);
} catch (InterruptedException ex) {
logger.fatal("popupContainer error:", ex);
}
}
}
private void saveDividerLocations() {
@ -315,6 +320,9 @@ public final class GamePanel extends javax.swing.JPanel {
}
}
/**
* Closes the game and it's resources
*/
public void hideGame() {
cleanUp();
Component c = this.getParent();