mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
More efficient use of background image. Now Mage takes much less memory. Also updated plugins in Mage.Tests.
This commit is contained in:
parent
b1fdc03c4e
commit
fb8cd79b59
5 changed files with 45 additions and 34 deletions
Binary file not shown.
|
@ -1,6 +1,6 @@
|
||||||
package org.mage.plugins.theme;
|
package org.mage.plugins.theme;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -23,6 +23,7 @@ import org.apache.log4j.Logger;
|
||||||
public class ThemePluginImpl implements ThemePlugin {
|
public class ThemePluginImpl implements ThemePlugin {
|
||||||
|
|
||||||
private final static Logger log = Logger.getLogger(ThemePluginImpl.class);
|
private final static Logger log = Logger.getLogger(ThemePluginImpl.class);
|
||||||
|
private static BufferedImage background;
|
||||||
|
|
||||||
@Init
|
@Init
|
||||||
public void init() {
|
public void init() {
|
||||||
|
@ -73,20 +74,9 @@ public class ThemePluginImpl implements ThemePlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public JComponent updateTable(Map<String, JComponent> ui) {
|
public JComponent updateTable(Map<String, JComponent> ui) {
|
||||||
String filename = "/background.png";
|
ImagePanel bgPanel = createImagePanelInstance();
|
||||||
try {
|
|
||||||
InputStream is = this.getClass().getResourceAsStream(filename);
|
|
||||||
|
|
||||||
if (is == null)
|
|
||||||
throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
|
|
||||||
|
|
||||||
BufferedImage background = ImageIO.read(is);
|
|
||||||
|
|
||||||
if (background == null)
|
|
||||||
throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
|
|
||||||
|
|
||||||
ImagePanel bgPanel = new ImagePanel(background, ImagePanel.SCALED);
|
|
||||||
|
|
||||||
unsetOpaque(ui.get("jScrollPane1"));
|
unsetOpaque(ui.get("jScrollPane1"));
|
||||||
unsetOpaque(ui.get("jPanel1"));
|
unsetOpaque(ui.get("jPanel1"));
|
||||||
|
@ -96,11 +86,32 @@ public class ThemePluginImpl implements ThemePlugin {
|
||||||
viewport.setBackground(new Color(255,255,255,50));
|
viewport.setBackground(new Color(255,255,255,50));
|
||||||
}
|
}
|
||||||
return bgPanel;
|
return bgPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ImagePanel createImagePanelInstance() {
|
||||||
|
if (background == null) {
|
||||||
|
synchronized (ThemePluginImpl.class) {
|
||||||
|
if (background == null) {
|
||||||
|
String filename = "/background.png";
|
||||||
|
try {
|
||||||
|
InputStream is = this.getClass().getResourceAsStream(filename);
|
||||||
|
|
||||||
|
if (is == null)
|
||||||
|
throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
|
||||||
|
|
||||||
|
background = ImageIO.read(is);
|
||||||
|
|
||||||
|
if (background == null)
|
||||||
|
throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new ImagePanel(background, ImagePanel.SCALED);
|
||||||
|
}
|
||||||
|
|
||||||
private void unsetOpaque(JComponent c) {
|
private void unsetOpaque(JComponent c) {
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1,11 +1,14 @@
|
||||||
package org.mage.test.serverside;
|
package org.mage.test.serverside;
|
||||||
|
|
||||||
import mage.Constants;
|
import mage.Constants;
|
||||||
|
import mage.Constants.ColoredManaSymbol;
|
||||||
|
import mage.cards.Card;
|
||||||
import mage.cards.decks.Deck;
|
import mage.cards.decks.Deck;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.GameException;
|
import mage.game.GameException;
|
||||||
import mage.game.GameOptions;
|
import mage.game.GameOptions;
|
||||||
import mage.game.TwoPlayerDuel;
|
import mage.game.TwoPlayerDuel;
|
||||||
|
import mage.player.ai.ComputerPlayer;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.sets.Sets;
|
import mage.sets.Sets;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -16,9 +19,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import mage.Constants.ColoredManaSymbol;
|
|
||||||
import mage.cards.Card;
|
|
||||||
import mage.player.ai.ComputerPlayer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ayratn
|
* @author ayratn
|
||||||
|
|
Loading…
Reference in a new issue