mirror of
https://github.com/correl/mage.git
synced 2024-11-14 19:19:32 +00:00
Some changes to reduce memory leaks.
This commit is contained in:
parent
e2c0e211ef
commit
30ddcaf99b
12 changed files with 139 additions and 83 deletions
|
@ -1,5 +1,5 @@
|
|||
#default levels
|
||||
log4j.rootLogger=debug, console, logfile
|
||||
log4j.rootLogger=info, console, logfile
|
||||
|
||||
#console log
|
||||
log4j.appender.console=org.apache.log4j.ConsoleAppender
|
||||
|
|
|
@ -553,7 +553,6 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
}
|
||||
|
||||
public static void deactivate(MagePane frame) {
|
||||
//MusicPlayer.stopBGM();
|
||||
frame.setVisible(false);
|
||||
MagePane topmost = getTopMost(frame);
|
||||
if (activeFrame != frame) {
|
||||
|
@ -623,16 +622,8 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
|
||||
public void showDraft(UUID draftId) {
|
||||
try {
|
||||
DraftPane draftPane = null;
|
||||
for(Component component :desktopPane.getComponents()) {
|
||||
if (component instanceof DraftPane) {
|
||||
draftPane = (DraftPane) component;
|
||||
}
|
||||
}
|
||||
if (draftPane == null) {
|
||||
draftPane = new DraftPane();
|
||||
desktopPane.add(draftPane, JLayeredPane.DEFAULT_LAYER);
|
||||
}
|
||||
DraftPane draftPane = new DraftPane();
|
||||
desktopPane.add(draftPane, JLayeredPane.DEFAULT_LAYER);
|
||||
draftPane.setMaximum(true);
|
||||
draftPane.setVisible(true);
|
||||
draftPane.showDraft(draftId);
|
||||
|
@ -640,7 +631,17 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
} catch (PropertyVetoException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void endDraft(UUID draftId) {
|
||||
// inform all open draft panes about
|
||||
for (JInternalFrame window : desktopPane.getAllFramesInLayer(JLayeredPane.DEFAULT_LAYER)) {
|
||||
if (window instanceof DraftPane) {
|
||||
DraftPane draftPane = (DraftPane) window;
|
||||
draftPane.hideDraft();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void showTournament(UUID tournamentId) {
|
||||
try {
|
||||
for(Component component :desktopPane.getComponents()) {
|
||||
|
@ -992,6 +993,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
} else {
|
||||
name = "Deck Editor";
|
||||
}
|
||||
// use already open editor
|
||||
JInternalFrame[] windows = desktopPane.getAllFramesInLayer(JLayeredPane.DEFAULT_LAYER);
|
||||
for (JInternalFrame window : windows) {
|
||||
if (window instanceof DeckEditorPane && window.getTitle().equals(name)) {
|
||||
|
@ -1000,6 +1002,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
DeckEditorPane deckEditorPane = new DeckEditorPane();
|
||||
desktopPane.add(deckEditorPane, JLayeredPane.DEFAULT_LAYER);
|
||||
|
@ -1156,6 +1159,14 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
return drafts.get(draftId);
|
||||
}
|
||||
|
||||
public static void removeDraft(UUID draftId) {
|
||||
DraftPanel draftPanel = drafts.get(draftId);
|
||||
if (draftPanel != null) {
|
||||
drafts.remove(draftId);
|
||||
draftPanel.hideDraft();
|
||||
}
|
||||
}
|
||||
|
||||
public static void addDraft(UUID draftId, DraftPanel draftPanel) {
|
||||
drafts.put(draftId, draftPanel);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
package mage.client.dialog;
|
||||
|
||||
import java.awt.KeyboardFocusManager;
|
||||
import mage.utils.MageVersion;
|
||||
|
||||
/*
|
||||
|
@ -48,7 +49,7 @@ public class AboutDialog extends MageDialog {
|
|||
public AboutDialog() {
|
||||
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
initComponents();
|
||||
this.modal = true;
|
||||
this.modal = false;
|
||||
}
|
||||
|
||||
public void showDialog(MageVersion version) {
|
||||
|
@ -131,8 +132,6 @@ public class AboutDialog extends MageDialog {
|
|||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed
|
||||
|
||||
|
||||
this.removeDialog();
|
||||
}//GEN-LAST:event_btnOkActionPerformed
|
||||
|
||||
|
|
|
@ -1,37 +1,36 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MageDialog.java
|
||||
*
|
||||
* Created on 15-Dec-2009, 10:28:27 PM
|
||||
*/
|
||||
|
||||
package mage.client.dialog;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
@ -48,13 +47,15 @@ import mage.client.MageFrame;
|
|||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class MageDialog extends javax.swing.JInternalFrame {
|
||||
|
||||
public class MageDialog extends javax.swing.JInternalFrame {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(MageDialog.class);
|
||||
|
||||
protected boolean modal = false;
|
||||
|
||||
/** Creates new form MageDialog */
|
||||
/**
|
||||
* Creates new form MageDialog
|
||||
*/
|
||||
public MageDialog() {
|
||||
initComponents();
|
||||
}
|
||||
|
@ -163,35 +164,47 @@ import mage.client.MageFrame;
|
|||
}
|
||||
|
||||
public void removeDialog() {
|
||||
setVisible(false);
|
||||
MageFrame.getDesktop().remove(this);
|
||||
this.ui.uninstallUI(this);
|
||||
this.dispose();
|
||||
// avoid memory leak of javax.swing.plaf.nimbus.NimbusStyle$CacheKey
|
||||
KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
|
||||
//this.setVisible(false);
|
||||
// important to set close before removing the JInternalFrame to avoid memory leaks (http://bugs.java.com/view_bug.do?bug_id=7163808)
|
||||
try {
|
||||
this.setSelected(false);
|
||||
this.setClosed(true);
|
||||
} catch (PropertyVetoException ex) {
|
||||
java.util.logging.Logger.getLogger(MageDialog.class.getName()).log(Level.SEVERE, null, ex);
|
||||
java.util.logging.Logger.getLogger(MageDialog.class.getName()).log(Level.SEVERE, "setClosed(false) failed", ex);
|
||||
}
|
||||
MageFrame.getDesktop().remove(this);
|
||||
// this.ui.uninstallUI(this);
|
||||
logger.warn("Remove Dialog " + this.getClass().getName() + " Components left: " + this.getComponentCount());
|
||||
for (Component comp : this.getComponents()) {
|
||||
logger.warn("Existing Component: " + comp.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to set a tooltip text on icon and titel bar
|
||||
*
|
||||
* used in {@link ExileZoneDialog} and {@link ShowCardsDialog}
|
||||
*
|
||||
* @param text
|
||||
*/
|
||||
public void setTitelBarToolTip(final String text) {
|
||||
desktopIcon.setToolTipText(text); //tooltip on icon
|
||||
Component[] children = getComponents();
|
||||
if (children != null) {
|
||||
for(int i = 0; i < children.length; i++) {
|
||||
if (children[i].getClass().getName().equalsIgnoreCase(
|
||||
"javax.swing.plaf.synth.SynthInternalFrameTitlePane")){
|
||||
((JComponent)children[i]).setToolTipText(text);//tooltip on title bar
|
||||
for (Component children1 : children) {
|
||||
if (children1.getClass().getName().equalsIgnoreCase("javax.swing.plaf.synth.SynthInternalFrameTitlePane")) {
|
||||
((JComponent) children1).setToolTipText(text); //tooltip on title bar
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 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.
|
||||
/**
|
||||
* 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")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
|
@ -214,5 +227,4 @@ import mage.client.MageFrame;
|
|||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
}
|
||||
|
|
|
@ -39,9 +39,11 @@ import mage.client.plugins.impl.Plugins;
|
|||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import mage.client.MageFrame;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -73,9 +75,16 @@ public class DraftPane extends MagePane {
|
|||
this.setTitle("Draft - " + draftId);
|
||||
this.draftPanel1.showDraft(draftId);
|
||||
}
|
||||
|
||||
public void hideDraft() {
|
||||
draftPanel1.hideDraft();
|
||||
|
||||
public void hideDraft() {
|
||||
KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
|
||||
try {
|
||||
this.setClosed(true);
|
||||
} catch (PropertyVetoException ex) {
|
||||
|
||||
}
|
||||
this.hideFrame();
|
||||
MageFrame.getDesktop().remove(this);
|
||||
}
|
||||
|
||||
/** This method is called from within the constructor to
|
||||
|
|
|
@ -64,7 +64,7 @@ public class DraftPanel extends javax.swing.JPanel {
|
|||
private int timeout;
|
||||
private boolean picked;
|
||||
|
||||
private static CardsView emptyView = new CardsView();
|
||||
private static final CardsView emptyView = new CardsView();
|
||||
|
||||
/** Creates new form DraftPanel */
|
||||
public DraftPanel() {
|
||||
|
@ -162,7 +162,7 @@ public class DraftPanel extends javax.swing.JPanel {
|
|||
c = c.getParent();
|
||||
}
|
||||
if (c != null) {
|
||||
((DraftPane)c).hideFrame();
|
||||
((DraftPane)c).hideDraft();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ public class FeedbackPanel extends javax.swing.JPanel {
|
|||
}
|
||||
|
||||
public void getFeedback(FeedbackMode mode, String message, boolean special, Map<String, Serializable> options, int messageId) {
|
||||
logger.info("text: " + message);
|
||||
logger.debug("text: " + message);
|
||||
|
||||
synchronized (this) {
|
||||
if (messageId < this.lastMessageId) {
|
||||
|
|
|
@ -34,19 +34,27 @@
|
|||
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class GamePane extends MagePane {
|
||||
|
||||
|
||||
private static final Logger logger = Logger.getLogger(MageDialog.class);
|
||||
|
||||
/** Creates new form GamePane */
|
||||
public GamePane() {
|
||||
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
initComponents();
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
|
@ -65,15 +73,26 @@ public class GamePane extends MagePane {
|
|||
}
|
||||
|
||||
public void hideGame() {
|
||||
// try {
|
||||
MageFrame.deactivate(this);
|
||||
MageFrame.getDesktop().remove(this);
|
||||
|
||||
KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
|
||||
gamePanel.cleanUp();
|
||||
|
||||
this.getUI().uninstallUI(this);
|
||||
this.removeAll();
|
||||
this.dispose();
|
||||
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);
|
||||
|
|
|
@ -249,7 +249,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
} catch (InterruptedException ex) {
|
||||
logger.fatal("popupContainer error:", ex);
|
||||
}
|
||||
this.removeAll();
|
||||
// this.removeAll();
|
||||
}
|
||||
|
||||
private void saveDividerLocations() {
|
||||
|
|
|
@ -77,14 +77,14 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
|
||||
@Override
|
||||
public synchronized void processCallback(final ClientCallback callback) {
|
||||
logger.info(callback.getMessageId() + " - " + callback.getMethod());
|
||||
logger.debug(callback.getMessageId() + " - " + callback.getMethod());
|
||||
SaveObjectUtil.saveObject(callback.getData(), callback.getMethod());
|
||||
callback.setData(CompressUtil.decompress(callback.getData()));
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
logger.info(callback.getMessageId() + " -- " + callback.getMethod());
|
||||
logger.debug(callback.getMessageId() + " -- " + callback.getMethod());
|
||||
if (callback.getMethod().equals("startGame")) {
|
||||
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||
GameManager.getInstance().setCurrentPlayerUUID(message.getPlayerId());
|
||||
|
@ -269,10 +269,7 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
Deck deck = DeckUtil.construct(deckView);
|
||||
construct(deck, message.getTableId(), message.getTime());
|
||||
} else if (callback.getMethod().equals("draftOver")) {
|
||||
DraftPanel panel = MageFrame.getDraft(callback.getObjectId());
|
||||
if (panel != null) {
|
||||
panel.hideDraft();
|
||||
}
|
||||
MageFrame.removeDraft(callback.getObjectId());
|
||||
} else if (callback.getMethod().equals("draftPick")) {
|
||||
DraftClientMessage message = (DraftClientMessage) callback.getData();
|
||||
DraftPanel panel = MageFrame.getDraft(callback.getObjectId());
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
#default levels
|
||||
log4j.rootLogger=info, console, logfile
|
||||
# Suppress SQL info messages
|
||||
log4j.logger.com.j256.ormlite=warn
|
||||
|
||||
#log4j.logger.org.jboss.remoting=debug
|
||||
#log4j.logger.org.jboss.logging=debug
|
||||
log4j.logger.mage.player.ai.ComputerPlayer6=debug
|
||||
log4j.logger.mage.client.remote.CallbackClientImpl=debug
|
||||
#log4j.logger.mage.client.remote.CallbackClientImpl=debug
|
||||
log4j.logger.mage.client.game.FeedbackPanel=debug
|
||||
|
||||
#console log
|
||||
log4j.appender.console=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.console.layout=org.apache.log4j.PatternLayout
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#default levels
|
||||
log4j.rootLogger=debug, console, logfile
|
||||
log4j.logger.com.j256.ormlite=warn
|
||||
|
||||
#log4j.logger.mage.player.ai.ComputerPlayer6=debug
|
||||
#console log
|
||||
log4j.appender.console=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.console.layout=org.apache.log4j.PatternLayout
|
||||
|
|
Loading…
Reference in a new issue