changed the type used in ImagePanel from an int to an enum

This commit is contained in:
ingmargoudt 2017-03-07 22:28:10 +01:00
parent 0a77c186be
commit 4aaf73e0d2
9 changed files with 61 additions and 56 deletions

View file

@ -55,6 +55,7 @@ import mage.client.util.gui.ArrowBuilder;
import mage.client.util.gui.countryBox.CountryUtil; import mage.client.util.gui.countryBox.CountryUtil;
import mage.client.util.stats.UpdateMemUsageTask; import mage.client.util.stats.UpdateMemUsageTask;
import mage.components.ImagePanel; import mage.components.ImagePanel;
import mage.components.ImagePanelStyle;
import mage.constants.PlayerAction; import mage.constants.PlayerAction;
import mage.interfaces.MageClient; import mage.interfaces.MageClient;
import mage.interfaces.callback.CallbackClient; import mage.interfaces.callback.CallbackClient;
@ -426,7 +427,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
} else { } else {
InputStream is = this.getClass().getResourceAsStream(filename); InputStream is = this.getClass().getResourceAsStream(filename);
BufferedImage background = ImageIO.read(is); BufferedImage background = ImageIO.read(is);
backgroundPane = new ImagePanel(background, ImagePanel.SCALED); backgroundPane = new ImagePanel(background, ImagePanelStyle.SCALED);
} }
backgroundPane.setSize(1024, 768); backgroundPane.setSize(1024, 768);
desktopPane.add(backgroundPane, JLayeredPane.DEFAULT_LAYER); desktopPane.add(backgroundPane, JLayeredPane.DEFAULT_LAYER);

View file

@ -44,6 +44,7 @@ import mage.client.util.NaturalOrderCardNumberComparator;
import mage.client.util.audio.AudioManager; import mage.client.util.audio.AudioManager;
import mage.client.util.sets.ConstructedFormats; import mage.client.util.sets.ConstructedFormats;
import mage.components.ImagePanel; import mage.components.ImagePanel;
import mage.components.ImagePanelStyle;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.view.CardView; import mage.view.CardView;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -89,12 +90,12 @@ public class MageBook extends JComponent {
setMinimumSize(new Dimension(conf.WIDTH, conf.HEIGHT)); setMinimumSize(new Dimension(conf.WIDTH, conf.HEIGHT));
//setBorder(BorderFactory.createLineBorder(Color.green)); //setBorder(BorderFactory.createLineBorder(Color.green));
jPanelLeft = getImagePanel(LEFT_PANEL_IMAGE_PATH, ImagePanel.TILED); jPanelLeft = getImagePanel(LEFT_PANEL_IMAGE_PATH, ImagePanelStyle.TILED);
jPanelLeft.setPreferredSize(new Dimension(LEFT_RIGHT_PAGES_WIDTH, 0)); jPanelLeft.setPreferredSize(new Dimension(LEFT_RIGHT_PAGES_WIDTH, 0));
jPanelLeft.setLayout(null); jPanelLeft.setLayout(null);
jPanelCenter = getImagePanel(CENTER_PANEL_IMAGE_PATH, ImagePanel.SCALED); jPanelCenter = getImagePanel(CENTER_PANEL_IMAGE_PATH, ImagePanelStyle.SCALED);
jPanelCenter.setLayout(new BorderLayout()); jPanelCenter.setLayout(new BorderLayout());
jPanelRight = getImagePanel(RIGHT_PANEL_IMAGE_PATH, ImagePanel.TILED); jPanelRight = getImagePanel(RIGHT_PANEL_IMAGE_PATH, ImagePanelStyle.TILED);
jPanelRight.setPreferredSize(new Dimension(LEFT_RIGHT_PAGES_WIDTH, 0)); jPanelRight.setPreferredSize(new Dimension(LEFT_RIGHT_PAGES_WIDTH, 0));
jPanelRight.setLayout(null); jPanelRight.setLayout(null);
@ -267,7 +268,7 @@ public class MageBook extends JComponent {
return cards.subList(start, end); return cards.subList(start, end);
} }
private ImagePanel getImagePanel(String filename, int type) { private ImagePanel getImagePanel(String filename, ImagePanelStyle type) {
try { try {
InputStream is = this.getClass().getResourceAsStream(filename); InputStream is = this.getClass().getResourceAsStream(filename);

View file

@ -70,6 +70,7 @@ import mage.client.util.ImageHelper;
import mage.client.util.gui.BufferedImageBuilder; import mage.client.util.gui.BufferedImageBuilder;
import mage.client.util.gui.countryBox.CountryUtil; import mage.client.util.gui.countryBox.CountryUtil;
import mage.components.ImagePanel; import mage.components.ImagePanel;
import mage.components.ImagePanelStyle;
import mage.constants.CardType; import mage.constants.CardType;
import static mage.constants.Constants.DEFAULT_AVATAR_ID; import static mage.constants.Constants.DEFAULT_AVATAR_ID;
import static mage.constants.Constants.MAX_AVATAR_ID; import static mage.constants.Constants.MAX_AVATAR_ID;
@ -417,7 +418,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
lifeLabel.setToolTipText("Life"); lifeLabel.setToolTipText("Life");
Image imageLife = ImageHelper.getImageFromResources("/info/life.png"); Image imageLife = ImageHelper.getImageFromResources("/info/life.png");
BufferedImage resizedLife = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(imageLife, BufferedImage.TYPE_INT_ARGB), r); BufferedImage resizedLife = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(imageLife, BufferedImage.TYPE_INT_ARGB), r);
life = new ImagePanel(resizedLife, ImagePanel.ACTUAL); life = new ImagePanel(resizedLife, ImagePanelStyle.ACTUAL);
life.setToolTipText("Life"); life.setToolTipText("Life");
life.setOpaque(false); life.setOpaque(false);
// hand area // hand area
@ -425,7 +426,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
handLabel.setToolTipText("Hand"); handLabel.setToolTipText("Hand");
Image imageHand = ImageHelper.getImageFromResources("/info/hand.png"); Image imageHand = ImageHelper.getImageFromResources("/info/hand.png");
BufferedImage resizedHand = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(imageHand, BufferedImage.TYPE_INT_ARGB), r); BufferedImage resizedHand = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(imageHand, BufferedImage.TYPE_INT_ARGB), r);
hand = new ImagePanel(resizedHand, ImagePanel.ACTUAL); hand = new ImagePanel(resizedHand, ImagePanelStyle.ACTUAL);
hand.setToolTipText("Hand"); hand.setToolTipText("Hand");
hand.setOpaque(false); hand.setOpaque(false);
@ -435,7 +436,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
poisonLabel.setToolTipText("Poison"); poisonLabel.setToolTipText("Poison");
Image imagePoison = ImageHelper.getImageFromResources("/info/poison.png"); Image imagePoison = ImageHelper.getImageFromResources("/info/poison.png");
BufferedImage resizedPoison = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(imagePoison, BufferedImage.TYPE_INT_ARGB), r); BufferedImage resizedPoison = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(imagePoison, BufferedImage.TYPE_INT_ARGB), r);
poison = new ImagePanel(resizedPoison, ImagePanel.ACTUAL); poison = new ImagePanel(resizedPoison, ImagePanelStyle.ACTUAL);
poison.setToolTipText("Poison"); poison.setToolTipText("Poison");
poison.setOpaque(false); poison.setOpaque(false);
@ -512,7 +513,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
energyLabel.setToolTipText("Energy"); energyLabel.setToolTipText("Energy");
Image imageEnergy = ImageHelper.getImageFromResources("/info/energy.png"); Image imageEnergy = ImageHelper.getImageFromResources("/info/energy.png");
BufferedImage resizedEnergy = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(imageEnergy, BufferedImage.TYPE_INT_ARGB), r); BufferedImage resizedEnergy = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(imageEnergy, BufferedImage.TYPE_INT_ARGB), r);
energy = new ImagePanel(resizedEnergy, ImagePanel.ACTUAL); energy = new ImagePanel(resizedEnergy, ImagePanelStyle.ACTUAL);
energy.setToolTipText("Energy"); energy.setToolTipText("Energy");
energy.setOpaque(false); energy.setOpaque(false);
@ -522,7 +523,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
experienceLabel.setToolTipText("Experience"); experienceLabel.setToolTipText("Experience");
Image imageExperience = ImageHelper.getImageFromResources("/info/experience.png"); Image imageExperience = ImageHelper.getImageFromResources("/info/experience.png");
BufferedImage resizedExperience = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(imageExperience, BufferedImage.TYPE_INT_ARGB), r); BufferedImage resizedExperience = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(imageExperience, BufferedImage.TYPE_INT_ARGB), r);
experience = new ImagePanel(resizedExperience, ImagePanel.ACTUAL); experience = new ImagePanel(resizedExperience, ImagePanelStyle.ACTUAL);
experience.setToolTipText("Experience"); experience.setToolTipText("Experience");
experience.setOpaque(false); experience.setOpaque(false);

View file

@ -7,6 +7,7 @@ import mage.client.dialog.PreferencesDialog;
import mage.client.util.ImageCaches; import mage.client.util.ImageCaches;
import mage.client.util.ImageHelper; import mage.client.util.ImageHelper;
import mage.components.ImagePanel; import mage.components.ImagePanel;
import mage.components.ImagePanelStyle;
import mage.constants.AbilityType; import mage.constants.AbilityType;
import mage.utils.CardUtil; import mage.utils.CardUtil;
import mage.view.CardView; import mage.view.CardView;
@ -243,7 +244,7 @@ public class CardPanelComponentImpl extends CardPanel {
// Sickness overlay // Sickness overlay
BufferedImage sickness = ImageManagerImpl.getInstance().getSicknessImage(); BufferedImage sickness = ImageManagerImpl.getInstance().getSicknessImage();
overlayPanel = new ImagePanel(sickness, ImagePanel.SCALED); overlayPanel = new ImagePanel(sickness, ImagePanelStyle.SCALED);
overlayPanel.setOpaque(false); overlayPanel.setOpaque(false);
add(overlayPanel); add(overlayPanel);

View file

@ -8,6 +8,7 @@ import javax.imageio.ImageIO;
import javax.swing.*; import javax.swing.*;
import mage.client.dialog.PreferencesDialog; import mage.client.dialog.PreferencesDialog;
import mage.components.ImagePanel; import mage.components.ImagePanel;
import mage.components.ImagePanelStyle;
import mage.interfaces.plugin.ThemePlugin; import mage.interfaces.plugin.ThemePlugin;
import net.xeoh.plugins.base.annotations.PluginImplementation; import net.xeoh.plugins.base.annotations.PluginImplementation;
import net.xeoh.plugins.base.annotations.events.Init; import net.xeoh.plugins.base.annotations.events.Init;
@ -82,7 +83,7 @@ public class ThemePluginImpl implements ThemePlugin {
} }
if (ui.containsKey("gamePanel") && ui.containsKey("jLayeredPane")) { if (ui.containsKey("gamePanel") && ui.containsKey("jLayeredPane")) {
ImagePanel bgPanel = new ImagePanel(backgroundImage, ImagePanel.TILED); ImagePanel bgPanel = new ImagePanel(backgroundImage, ImagePanelStyle.TILED);
unsetOpaque(ui.get("jSplitPane1")); unsetOpaque(ui.get("jSplitPane1"));
unsetOpaque(ui.get("pnlBattlefield")); unsetOpaque(ui.get("pnlBattlefield"));
@ -190,7 +191,7 @@ public class ThemePluginImpl implements ThemePlugin {
} }
} }
} }
return new ImagePanel(background, ImagePanel.SCALED); return new ImagePanel(background, ImagePanelStyle.SCALED);
} }
private void unsetOpaque(JComponent c) { private void unsetOpaque(JComponent c) {

View file

@ -31,7 +31,6 @@ package mage.cards;
import static mage.constants.Constants.*; import static mage.constants.Constants.*;
/** /**
*
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class CardDimensions { public class CardDimensions {
@ -51,19 +50,19 @@ public class CardDimensions {
public int nameFontSize; public int nameFontSize;
public CardDimensions(double scaleFactor) { public CardDimensions(double scaleFactor) {
frameHeight = (int)(FRAME_MAX_HEIGHT * scaleFactor); frameHeight = (int) (FRAME_MAX_HEIGHT * scaleFactor);
frameWidth = (int)(FRAME_MAX_WIDTH * scaleFactor); frameWidth = (int) (FRAME_MAX_WIDTH * scaleFactor);
symbolHeight = (int)(SYMBOL_MAX_HEIGHT * scaleFactor); symbolHeight = (int) (SYMBOL_MAX_HEIGHT * scaleFactor);
symbolWidth = (int)(SYMBOL_MAX_WIDTH * scaleFactor); symbolWidth = (int) (SYMBOL_MAX_WIDTH * scaleFactor);
contentXOffset = (int)(CONTENT_MAX_XOFFSET * scaleFactor); contentXOffset = (int) (CONTENT_MAX_XOFFSET * scaleFactor);
nameYOffset = (int)(NAME_MAX_YOFFSET * scaleFactor); nameYOffset = (int) (NAME_MAX_YOFFSET * scaleFactor);
typeYOffset = (int)(TYPE_MAX_YOFFSET * scaleFactor); typeYOffset = (int) (TYPE_MAX_YOFFSET * scaleFactor);
textYOffset = (int)(TEXT_MAX_YOFFSET * scaleFactor); textYOffset = (int) (TEXT_MAX_YOFFSET * scaleFactor);
textWidth = (int)(TEXT_MAX_WIDTH * scaleFactor); textWidth = (int) (TEXT_MAX_WIDTH * scaleFactor);
textHeight = (int)(TEXT_MAX_HEIGHT * scaleFactor); textHeight = (int) (TEXT_MAX_HEIGHT * scaleFactor);
powBoxTextTop = (int)(POWBOX_TEXT_MAX_TOP * scaleFactor); powBoxTextTop = (int) (POWBOX_TEXT_MAX_TOP * scaleFactor);
powBoxTextLeft = (int)(POWBOX_TEXT_MAX_LEFT * scaleFactor); powBoxTextLeft = (int) (POWBOX_TEXT_MAX_LEFT * scaleFactor);
nameFontSize = Math.max(9, (int)(NAME_FONT_MAX_SIZE * scaleFactor)); nameFontSize = Math.max(9, (int) (NAME_FONT_MAX_SIZE * scaleFactor));
} }
} }

View file

@ -9,20 +9,18 @@ import javax.swing.JViewport;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class ImagePanel extends JPanel { public class ImagePanel extends JPanel {
public static final int TILED = 0;
public static final int SCALED = 1;
public static final int ACTUAL = 2;
private BufferedImage image; private BufferedImage image;
private int style; private ImagePanelStyle style;
private float alignmentX = 0.5f; private float alignmentX = 0.5f;
private float alignmentY = 0.5f; private float alignmentY = 0.5f;
public ImagePanel(BufferedImage image) { public ImagePanel(BufferedImage image) {
this(image, TILED); this(image, ImagePanelStyle.TILED);
} }
public ImagePanel(BufferedImage image, int style) { public ImagePanel(BufferedImage image, ImagePanelStyle style) {
this.image = image; this.image = image;
this.style = style; this.style = style;
setLayout(new BorderLayout()); setLayout(new BorderLayout());
@ -65,18 +63,16 @@ public class ImagePanel extends JPanel {
return; return;
switch (style) { switch (style) {
case TILED: case TILED:
drawTiled(g); drawTiled(g);
break; break;
case SCALED:
case SCALED: Dimension d = getSize();
Dimension d = getSize(); g.drawImage(image, 0, 0, d.width, d.height, null);
g.drawImage(image, 0, 0, d.width, d.height, null); break;
break; case ACTUAL:
drawActual(g);
case ACTUAL: break;
drawActual(g);
break;
} }
} }

View file

@ -0,0 +1,8 @@
package mage.components;
/**
* Created by IGOUDT on 7-3-2017.
*/
public enum ImagePanelStyle {
TILED, SCALED, ACTUAL
}

View file

@ -31,12 +31,13 @@ package mage.interfaces;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import mage.utils.MageVersion; import mage.utils.MageVersion;
import mage.view.GameTypeView; import mage.view.GameTypeView;
import mage.view.TournamentTypeView; import mage.view.TournamentTypeView;
/** /**
*
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class ServerState implements Serializable { public class ServerState implements Serializable {
@ -52,8 +53,8 @@ public class ServerState implements Serializable {
private final long expansionsContentVersion; private final long expansionsContentVersion;
public ServerState(List<GameTypeView> gameTypes, List<TournamentTypeView> tournamentTypes, public ServerState(List<GameTypeView> gameTypes, List<TournamentTypeView> tournamentTypes,
String[] playerTypes, String[] deckTypes, String[] draftCubes, boolean testMode, String[] playerTypes, String[] deckTypes, String[] draftCubes, boolean testMode,
MageVersion version, long cardsContentVersion, long expansionsContentVersion) { MageVersion version, long cardsContentVersion, long expansionsContentVersion) {
this.gameTypes = gameTypes; this.gameTypes = gameTypes;
this.tournamentTypes = tournamentTypes; this.tournamentTypes = tournamentTypes;
this.playerTypes = playerTypes; this.playerTypes = playerTypes;
@ -71,13 +72,9 @@ public class ServerState implements Serializable {
} }
public List<GameTypeView> getTournamentGameTypes() { public List<GameTypeView> getTournamentGameTypes() {
List<GameTypeView> tournamentGameTypes = new ArrayList<>(); return gameTypes.stream()
for(GameTypeView gameTypeView: gameTypes) { .filter(gameTypeView -> gameTypeView.getMinPlayers() == 2 && gameTypeView.getMaxPlayers() == 2)
if (gameTypeView.getMinPlayers() == 2 && gameTypeView.getMaxPlayers() == 2) { .collect(Collectors.toList());
tournamentGameTypes.add(gameTypeView);
}
}
return tournamentGameTypes;
} }
public List<TournamentTypeView> getTournamentTypes() { public List<TournamentTypeView> getTournamentTypes() {