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.stats.UpdateMemUsageTask;
import mage.components.ImagePanel;
import mage.components.ImagePanelStyle;
import mage.constants.PlayerAction;
import mage.interfaces.MageClient;
import mage.interfaces.callback.CallbackClient;
@ -426,7 +427,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
} else {
InputStream is = this.getClass().getResourceAsStream(filename);
BufferedImage background = ImageIO.read(is);
backgroundPane = new ImagePanel(background, ImagePanel.SCALED);
backgroundPane = new ImagePanel(background, ImagePanelStyle.SCALED);
}
backgroundPane.setSize(1024, 768);
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.sets.ConstructedFormats;
import mage.components.ImagePanel;
import mage.components.ImagePanelStyle;
import mage.constants.Rarity;
import mage.view.CardView;
import org.apache.log4j.Logger;
@ -89,12 +90,12 @@ public class MageBook extends JComponent {
setMinimumSize(new Dimension(conf.WIDTH, conf.HEIGHT));
//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.setLayout(null);
jPanelCenter = getImagePanel(CENTER_PANEL_IMAGE_PATH, ImagePanel.SCALED);
jPanelCenter = getImagePanel(CENTER_PANEL_IMAGE_PATH, ImagePanelStyle.SCALED);
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.setLayout(null);
@ -267,7 +268,7 @@ public class MageBook extends JComponent {
return cards.subList(start, end);
}
private ImagePanel getImagePanel(String filename, int type) {
private ImagePanel getImagePanel(String filename, ImagePanelStyle type) {
try {
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.countryBox.CountryUtil;
import mage.components.ImagePanel;
import mage.components.ImagePanelStyle;
import mage.constants.CardType;
import static mage.constants.Constants.DEFAULT_AVATAR_ID;
import static mage.constants.Constants.MAX_AVATAR_ID;
@ -417,7 +418,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
lifeLabel.setToolTipText("Life");
Image imageLife = ImageHelper.getImageFromResources("/info/life.png");
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.setOpaque(false);
// hand area
@ -425,7 +426,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
handLabel.setToolTipText("Hand");
Image imageHand = ImageHelper.getImageFromResources("/info/hand.png");
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.setOpaque(false);
@ -435,7 +436,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
poisonLabel.setToolTipText("Poison");
Image imagePoison = ImageHelper.getImageFromResources("/info/poison.png");
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.setOpaque(false);
@ -512,7 +513,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
energyLabel.setToolTipText("Energy");
Image imageEnergy = ImageHelper.getImageFromResources("/info/energy.png");
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.setOpaque(false);
@ -522,7 +523,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
experienceLabel.setToolTipText("Experience");
Image imageExperience = ImageHelper.getImageFromResources("/info/experience.png");
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.setOpaque(false);

View file

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

View file

@ -8,6 +8,7 @@ import javax.imageio.ImageIO;
import javax.swing.*;
import mage.client.dialog.PreferencesDialog;
import mage.components.ImagePanel;
import mage.components.ImagePanelStyle;
import mage.interfaces.plugin.ThemePlugin;
import net.xeoh.plugins.base.annotations.PluginImplementation;
import net.xeoh.plugins.base.annotations.events.Init;
@ -82,7 +83,7 @@ public class ThemePluginImpl implements ThemePlugin {
}
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("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) {

View file

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

View file

@ -9,20 +9,18 @@ import javax.swing.JViewport;
@SuppressWarnings("serial")
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 int style;
private ImagePanelStyle style;
private float alignmentX = 0.5f;
private float alignmentY = 0.5f;
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.style = style;
setLayout(new BorderLayout());
@ -68,12 +66,10 @@ public class ImagePanel extends JPanel {
case TILED:
drawTiled(g);
break;
case SCALED:
Dimension d = getSize();
g.drawImage(image, 0, 0, d.width, d.height, null);
break;
case ACTUAL:
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.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import mage.utils.MageVersion;
import mage.view.GameTypeView;
import mage.view.TournamentTypeView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class ServerState implements Serializable {
@ -71,13 +72,9 @@ public class ServerState implements Serializable {
}
public List<GameTypeView> getTournamentGameTypes() {
List<GameTypeView> tournamentGameTypes = new ArrayList<>();
for(GameTypeView gameTypeView: gameTypes) {
if (gameTypeView.getMinPlayers() == 2 && gameTypeView.getMaxPlayers() == 2) {
tournamentGameTypes.add(gameTypeView);
}
}
return tournamentGameTypes;
return gameTypes.stream()
.filter(gameTypeView -> gameTypeView.getMinPlayers() == 2 && gameTypeView.getMaxPlayers() == 2)
.collect(Collectors.toList());
}
public List<TournamentTypeView> getTournamentTypes() {