mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
GUI: fixed memory leak on gui-desktop
This commit is contained in:
@@ -223,7 +223,6 @@ public class Game {
|
|||||||
rules = rules0;
|
rules = rules0;
|
||||||
match = match0;
|
match = match0;
|
||||||
this.id = nextId();
|
this.id = nextId();
|
||||||
match.addGame(this);
|
|
||||||
|
|
||||||
int highestTeam = -1;
|
int highestTeam = -1;
|
||||||
for (RegisteredPlayer psc : players0) {
|
for (RegisteredPlayer psc : players0) {
|
||||||
|
|||||||
@@ -24,11 +24,13 @@ import java.util.List;
|
|||||||
public class GameView extends TrackableObject {
|
public class GameView extends TrackableObject {
|
||||||
private static final long serialVersionUID = 8522884512960961528L;
|
private static final long serialVersionUID = 8522884512960961528L;
|
||||||
|
|
||||||
|
private final transient Game game; //TODO: Remove this when possible before network support added
|
||||||
private final transient Match match; //TODO: Remove this when possible before network support added
|
private final transient Match match; //TODO: Remove this when possible before network support added
|
||||||
|
|
||||||
public GameView(final Game game) {
|
public GameView(final Game game) {
|
||||||
super(game.getId(), game.getTracker());
|
super(game.getId(), game.getTracker());
|
||||||
match = game.getMatch();
|
match = game.getMatch();
|
||||||
|
this.game = game;
|
||||||
set(TrackableProperty.Title, game.getMatch().getTitle());
|
set(TrackableProperty.Title, game.getMatch().getTitle());
|
||||||
set(TrackableProperty.WinningTeam, -1);
|
set(TrackableProperty.WinningTeam, -1);
|
||||||
|
|
||||||
@@ -48,7 +50,7 @@ public class GameView extends TrackableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Game getGame() {
|
public Game getGame() {
|
||||||
return getMatch().getGameById(getId()); // Match currently has only One running Game
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FCollectionView<PlayerView> getPlayers() {
|
public FCollectionView<PlayerView> getPlayers() {
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ public class Match {
|
|||||||
private final String title;
|
private final String title;
|
||||||
|
|
||||||
private final EventBus events = new EventBus("match events");
|
private final EventBus events = new EventBus("match events");
|
||||||
private final Map<Integer, Game> runningGames = Maps.newHashMap();
|
|
||||||
private final Map<Integer, GameOutcome> gameOutcomes = Maps.newHashMap();
|
private final Map<Integer, GameOutcome> gameOutcomes = Maps.newHashMap();
|
||||||
|
|
||||||
private GameOutcome lastOutcome = null;
|
private GameOutcome lastOutcome = null;
|
||||||
@@ -97,25 +96,15 @@ public class Match {
|
|||||||
|
|
||||||
// will pull UI dialog, when the UI is listening
|
// will pull UI dialog, when the UI is listening
|
||||||
game.fireEvent(new GameEventGameFinished());
|
game.fireEvent(new GameEventGameFinished());
|
||||||
// FIXME needed to close the Match Dialog because that this moment there isn't any game
|
|
||||||
runningGames.remove(game.getId());
|
|
||||||
|
|
||||||
//run GC after game is finished
|
//run GC after game is finished
|
||||||
System.gc();
|
System.gc();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Game getGameById(int id) {
|
|
||||||
return runningGames.get(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GameOutcome getOutcomeById(int id) {
|
public GameOutcome getOutcomeById(int id) {
|
||||||
return gameOutcomes.get(id);
|
return gameOutcomes.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addGame(Game game) {
|
|
||||||
runningGames.put(game.getId(), game);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearGamesPlayed() {
|
public void clearGamesPlayed() {
|
||||||
gameOutcomes.clear();
|
gameOutcomes.clear();
|
||||||
for (RegisteredPlayer p : players) {
|
for (RegisteredPlayer p : players) {
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ import forge.util.gui.SOptionPane;
|
|||||||
import forge.view.FView;
|
import forge.view.FView;
|
||||||
import forge.view.arcane.CardPanel;
|
import forge.view.arcane.CardPanel;
|
||||||
import forge.view.arcane.FloatingZone;
|
import forge.view.arcane.FloatingZone;
|
||||||
|
import net.miginfocom.layout.LinkHandler;
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1028,6 +1029,7 @@ public final class CMatchUI
|
|||||||
FThreads.invokeInEdtNowOrLater(new Runnable() {
|
FThreads.invokeInEdtNowOrLater(new Runnable() {
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
Singletons.getView().getNavigationBar().closeTab(screen);
|
Singletons.getView().getNavigationBar().closeTab(screen);
|
||||||
|
LinkHandler.clearWeakReferencesNow();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2214,7 +2214,7 @@ public class FSkin {
|
|||||||
}
|
}
|
||||||
private static class SkinScrollBarUI extends BasicScrollBarUI implements ILocalRepaint {
|
private static class SkinScrollBarUI extends BasicScrollBarUI implements ILocalRepaint {
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
private static JButton hiddenButton = new JButton() {
|
private static class HiddenButton extends JButton {
|
||||||
@Override
|
@Override
|
||||||
public Dimension getPreferredSize() {
|
public Dimension getPreferredSize() {
|
||||||
return new Dimension(0, 0);
|
return new Dimension(0, 0);
|
||||||
@@ -2229,26 +2229,42 @@ public class FSkin {
|
|||||||
|
|
||||||
private final boolean vertical;
|
private final boolean vertical;
|
||||||
private boolean hovered;
|
private boolean hovered;
|
||||||
|
private MouseAdapter hoverListener;
|
||||||
|
|
||||||
|
private static class SkinScrollBarListener extends MouseAdapter {
|
||||||
|
private SkinScrollBarUI barUI;
|
||||||
|
|
||||||
|
private SkinScrollBarListener(SkinScrollBarUI barUI) {
|
||||||
|
this.barUI = barUI;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(final MouseEvent e) {
|
||||||
|
barUI.hovered = true;
|
||||||
|
barUI.repaintSelf();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(final MouseEvent e) {
|
||||||
|
barUI.hovered = false;
|
||||||
|
barUI.repaintSelf();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private SkinScrollBarUI(final JScrollBar scrollbar, final boolean vertical0) {
|
private SkinScrollBarUI(final JScrollBar scrollbar, final boolean vertical0) {
|
||||||
vertical = vertical0;
|
vertical = vertical0;
|
||||||
scrollbar.setOpaque(false);
|
|
||||||
scrollbar.addMouseListener(new MouseAdapter() {
|
|
||||||
@Override
|
|
||||||
public void mouseEntered(final MouseEvent e) {
|
|
||||||
hovered = true;
|
|
||||||
repaintSelf();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
hoverListener = new SkinScrollBarListener(this);
|
||||||
public void mouseExited(final MouseEvent e) {
|
scrollbar.setOpaque(false);
|
||||||
hovered = false;
|
scrollbar.addMouseListener(hoverListener);
|
||||||
repaintSelf();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
scrollbar.setUI(this);
|
scrollbar.setUI(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void uninstallListeners() {
|
||||||
|
super.uninstallListeners();
|
||||||
|
scrollbar.removeMouseListener(hoverListener);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void repaintSelf() {
|
public void repaintSelf() {
|
||||||
final Dimension d = scrollbar.getSize();
|
final Dimension d = scrollbar.getSize();
|
||||||
@@ -2257,12 +2273,12 @@ public class FSkin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JButton createIncreaseButton(final int orientation) {
|
protected JButton createIncreaseButton(final int orientation) {
|
||||||
return hiddenButton; //hide increase button
|
return new HiddenButton(); //hide increase button
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JButton createDecreaseButton(final int orientation) {
|
protected JButton createDecreaseButton(final int orientation) {
|
||||||
return hiddenButton; //hide decrease button
|
return new HiddenButton(); //hide decrease button
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user