replace public fields with encapsulation

This commit is contained in:
Ingmar Goudt 2019-03-03 09:51:14 +01:00
parent d1e319787c
commit 8319fbf9ad
26 changed files with 544 additions and 327 deletions

View file

@ -77,7 +77,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
this.gameId = gameId;
this.card = card;
this.bigCard = bigCard;
small = new BufferedImage(Config.dimensions.frameWidth, Config.dimensions.frameHeight, BufferedImage.TYPE_INT_RGB);
small = new BufferedImage(Config.dimensions.getFrameWidth(), Config.dimensions.getFrameHeight(), BufferedImage.TYPE_INT_RGB);
backgroundName = getBackgroundName();
background = ImageHelper.getBackground(card, backgroundName);
@ -129,7 +129,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
gSmall.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gSmall.setColor(Color.BLACK);
gSmall.drawImage(ImageHelper.scaleImage(image, Config.dimensions.frameWidth, Config.dimensions.frameHeight), 0, 0, this);
gSmall.drawImage(ImageHelper.scaleImage(image, Config.dimensions.getFrameWidth(), Config.dimensions.getFrameHeight()), 0, 0, this);
gImage.setFont(new Font("Arial", Font.PLAIN, NAME_FONT_MAX_SIZE));
gImage.drawString(card.getName()+"TEST", CONTENT_MAX_XOFFSET, NAME_MAX_YOFFSET);
@ -145,16 +145,16 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
gImage.dispose();
gSmall.setFont(new Font("Arial", Font.PLAIN, Config.dimensions.nameFontSize));
gSmall.drawString(card.getName()+"TEST2", Config.dimensions.contentXOffset, Config.dimensions.nameYOffset);
gSmall.setFont(new Font("Arial", Font.PLAIN, Config.dimensions.getNameFontSize()));
gSmall.drawString(card.getName()+"TEST2", Config.dimensions.getContentXOffset(), Config.dimensions.getNameYOffset());
if (card.isCreature()) {
gSmall.drawString(card.getPower() + "/-/" + card.getToughness(), Config.dimensions.powBoxTextLeft, Config.dimensions.powBoxTextTop);
gSmall.drawString(card.getPower() + "/-/" + card.getToughness(), Config.dimensions.getPowBoxTextLeft(), Config.dimensions.getPowBoxTextTop());
} else if (card.isPlanesWalker()) {
gSmall.drawString(card.getLoyalty(), Config.dimensions.powBoxTextLeft, Config.dimensions.powBoxTextTop);
gSmall.drawString(card.getLoyalty(), Config.dimensions.getPowBoxTextLeft(), Config.dimensions.getPowBoxTextTop());
}
if (!card.getCardTypes().isEmpty()) {
gSmall.drawString(cardType, Config.dimensions.contentXOffset, Config.dimensions.typeYOffset);
gSmall.drawString(cardType, Config.dimensions.getContentXOffset(), Config.dimensions.getTypeYOffset());
}
drawText();
@ -287,7 +287,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
setMinimumSize(getPreferredSize());
setOpaque(false);
setPreferredSize(new Dimension(dimension.frameWidth, dimension.frameHeight));
setPreferredSize(new Dimension(dimension.getFrameWidth(), dimension.getFrameHeight()));
setLayout(null);
jScrollPane1.setBorder(null);
@ -304,7 +304,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
add(jScrollPane1);
jScrollPane1.setBounds(20, 110, 130, 100);
jScrollPane1.setBounds(new Rectangle(dimension.contentXOffset, dimension.textYOffset, dimension.textWidth, dimension.textHeight));
jScrollPane1.setBounds(new Rectangle(dimension.getContentXOffset(), dimension.getTextYOffset(), dimension.getTextWidth(), dimension.getTextHeight()));
}// </editor-fold>//GEN-END:initComponents
@Override
@ -355,11 +355,11 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
tooltipPopup.hide();
}
PopupFactory factory = PopupFactory.getSharedInstance();
tooltipPopup = factory.getPopup(this, tooltipText, (int) this.getLocationOnScreen().getX() + Config.dimensions.frameWidth, (int) this.getLocationOnScreen().getY() + 40);
tooltipPopup = factory.getPopup(this, tooltipText, (int) this.getLocationOnScreen().getX() + Config.dimensions.getFrameWidth(), (int) this.getLocationOnScreen().getY() + 40);
tooltipPopup.show();
//hack to get tooltipPopup to resize to fit text
tooltipPopup.hide();
tooltipPopup = factory.getPopup(this, tooltipText, (int) this.getLocationOnScreen().getX() + Config.dimensions.frameWidth, (int) this.getLocationOnScreen().getY() + 40);
tooltipPopup = factory.getPopup(this, tooltipText, (int) this.getLocationOnScreen().getX() + Config.dimensions.getFrameWidth(), (int) this.getLocationOnScreen().getY() + 40);
tooltipPopup.show();
tooltipShowing = true;

View file

@ -221,7 +221,7 @@ public class Cards extends javax.swing.JPanel {
private Dimension getCardDimension() {
if (cardDimension == null) {
cardDimension = new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
cardDimension = new Dimension(Config.dimensions.getFrameWidth(), Config.dimensions.getFrameHeight());
}
return cardDimension;
}

View file

@ -84,7 +84,7 @@ public class DraftGrid extends javax.swing.JPanel implements MouseListener {
for (int i = 1; i < maxRows; i++) {
scale = (double) (this.getHeight()/i) / Constants.FRAME_MAX_HEIGHT;
cardDimension = new CardDimensions(scale);
maxCards = this.getWidth() / (cardDimension.frameWidth + offsetX);
maxCards = this.getWidth() / (cardDimension.getFrameWidth() + offsetX);
if ((maxCards * i) >= booster.size()) {
numColumns = booster.size() / i;
if (booster.size() % i > 0) {
@ -95,8 +95,8 @@ public class DraftGrid extends javax.swing.JPanel implements MouseListener {
}
if (cardDimension != null) {
Rectangle rectangle = new Rectangle(cardDimension.frameWidth, cardDimension.frameHeight);
Dimension dimension = new Dimension(cardDimension.frameWidth, cardDimension.frameHeight);
Rectangle rectangle = new Rectangle(cardDimension.getFrameWidth(), cardDimension.getFrameHeight());
Dimension dimension = new Dimension(cardDimension.getFrameWidth(), cardDimension.getFrameHeight());
List<CardView> sortedCards = new ArrayList<>(booster.values());
sortedCards.sort(new CardViewRarityComparator());
@ -105,7 +105,7 @@ public class DraftGrid extends javax.swing.JPanel implements MouseListener {
cardImg.addMouseListener(this);
add(cardImg);
cardImg.update(card);
rectangle.setLocation(curColumn * (cardDimension.frameWidth + offsetX) + offsetX, curRow * (rectangle.height + offsetY) + offsetY);
rectangle.setLocation(curColumn * (cardDimension.getFrameWidth() + offsetX) + offsetX, curRow * (rectangle.height + offsetY) + offsetY);
cardImg.setBounds(rectangle);
cardImg.setCardBounds(rectangle.x, rectangle.y, rectangle.width, rectangle.height);

View file

@ -49,7 +49,7 @@ public class Permanent extends Card {
super(permanent, bigCard, dimensions, gameId);
this.setSize(this.getPreferredSize());
this.permanent = permanent;
tappedImage = new BufferedImage(Config.dimensions.frameHeight, Config.dimensions.frameWidth, BufferedImage.TYPE_INT_RGB);
tappedImage = new BufferedImage(Config.dimensions.getFrameHeight(), Config.dimensions.getFrameWidth(), BufferedImage.TYPE_INT_RGB);
}
public UUID getPermanentId() {
@ -173,10 +173,10 @@ public class Permanent extends Card {
g2.setColor(Color.BLACK);
}
if (permanent.isTapped()) {
g2.drawRect(0, 0, Config.dimensions.frameHeight - 1, Config.dimensions.frameWidth - 1);
g2.drawRect(0, 0, Config.dimensions.getFrameHeight() - 1, Config.dimensions.getFrameWidth() - 1);
}
else {
g2.drawRect(0, 0, Config.dimensions.frameWidth - 1, Config.dimensions.frameHeight - 1);
g2.drawRect(0, 0, Config.dimensions.getFrameWidth() - 1, Config.dimensions.getFrameHeight() - 1);
}
}
@ -185,7 +185,7 @@ public class Permanent extends Card {
Graphics2D g = (Graphics2D) tappedImage.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.drawImage(TransformedImageCache.getRotatedResizedImage(small, dimension.frameWidth, dimension.frameHeight, Math.toRadians(90.0)), 0, 0, this);
g.drawImage(TransformedImageCache.getRotatedResizedImage(small, dimension.getFrameWidth(), dimension.getFrameHeight(), Math.toRadians(90.0)), 0, 0, this);
g.dispose();
}
@ -206,10 +206,10 @@ public class Permanent extends Card {
@Override
public Dimension getPreferredSize() {
if (permanent != null && permanent.isTapped()) {
return new Dimension(Config.dimensions.frameHeight, Config.dimensions.frameWidth);
return new Dimension(Config.dimensions.getFrameHeight(), Config.dimensions.getFrameWidth());
}
else {
return new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
return new Dimension(Config.dimensions.getFrameWidth(), Config.dimensions.getFrameHeight());
}
}
@ -229,7 +229,7 @@ public class Permanent extends Card {
tooltipPopup.hide();
}
PopupFactory factory = PopupFactory.getSharedInstance();
int x = (int) this.getLocationOnScreen().getX() + (permanent.isTapped()?Config.dimensions.frameHeight:Config.dimensions.frameWidth);
int x = (int) this.getLocationOnScreen().getX() + (permanent.isTapped()? Config.dimensions.getFrameHeight() : Config.dimensions.getFrameWidth());
int y = (int) this.getLocationOnScreen().getY() + 40;
tooltipPopup = factory.getPopup(this, tooltipText, x, y);
tooltipPopup.show();

View file

@ -71,7 +71,7 @@ public abstract class IDialogPanel extends JXPanel {
protected Dimension getCardDimension() {
if (cardDimension == null) {
cardDimension = new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
cardDimension = new Dimension(Config.dimensions.getFrameWidth(), Config.dimensions.getFrameHeight());
}
return cardDimension;
}

View file

@ -250,7 +250,7 @@ public class MageBook extends JComponent {
// calculate the x offset of the second (right) page
int second_page_x = (conf.WIDTH - 2 * LEFT_RIGHT_PAGES_WIDTH)
- (cardDimensions.frameWidth + CardPosition.GAP_X) * conf.CARD_COLUMNS + CardPosition.GAP_X - OFFSET_X;
- (cardDimensions.getFrameWidth() + CardPosition.GAP_X) * conf.CARD_COLUMNS + CardPosition.GAP_X - OFFSET_X;
rectangle.setLocation(second_page_x, OFFSET_Y);
for (int i = conf.CARDS_PER_PAGE / 2; i < min(conf.CARDS_PER_PAGE, size); i++) {
@ -277,7 +277,7 @@ public class MageBook extends JComponent {
// calculate the x offset of the second (right) page
int second_page_x = (conf.WIDTH - 2 * LEFT_RIGHT_PAGES_WIDTH)
- (cardDimensions.frameWidth + CardPosition.GAP_X) * conf.CARD_COLUMNS + CardPosition.GAP_X - OFFSET_X;
- (cardDimensions.getFrameWidth() + CardPosition.GAP_X) * conf.CARD_COLUMNS + CardPosition.GAP_X - OFFSET_X;
rectangle.setLocation(second_page_x, OFFSET_Y);
for (int i = conf.CARDS_PER_PAGE / 2; i < min(conf.CARDS_PER_PAGE, size); i++) {
@ -302,7 +302,7 @@ public class MageBook extends JComponent {
rectangle.translate(OFFSET_X, OFFSET_Y);
// calculate the x offset of the second (right) page
int second_page_x = (conf.WIDTH - 2 * LEFT_RIGHT_PAGES_WIDTH)
- (cardDimensions.frameWidth + CardPosition.GAP_X) * conf.CARD_COLUMNS + CardPosition.GAP_X - OFFSET_X;
- (cardDimensions.getFrameWidth() + CardPosition.GAP_X) * conf.CARD_COLUMNS + CardPosition.GAP_X - OFFSET_X;
// Already have numTokens tokens presented. Appending the emblems to the end of these.
numTokens = numTokens % conf.CARDS_PER_PAGE;
@ -358,7 +358,7 @@ public class MageBook extends JComponent {
rectangle.translate(OFFSET_X, OFFSET_Y);
int second_page_x = (conf.WIDTH - 2 * LEFT_RIGHT_PAGES_WIDTH)
- (cardDimensions.frameWidth + CardPosition.GAP_X) * conf.CARD_COLUMNS + CardPosition.GAP_X - OFFSET_X;
- (cardDimensions.getFrameWidth() + CardPosition.GAP_X) * conf.CARD_COLUMNS + CardPosition.GAP_X - OFFSET_X;
numTokensEmblems = numTokensEmblems % conf.CARDS_PER_PAGE;
if (numTokensEmblems < conf.CARDS_PER_PAGE / 2) {
@ -404,20 +404,20 @@ public class MageBook extends JComponent {
private void addCard(CardView card, BigCard bigCard, UUID gameId, Rectangle rectangle) {
if (cardDimension == null) {
cardDimension = new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
cardDimension = new Dimension(Config.dimensions.getFrameWidth(), Config.dimensions.getFrameHeight());
}
final MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, cardDimension, gameId, true, true);
cardImg.setBounds(rectangle);
jLayeredPane.add(cardImg, JLayeredPane.DEFAULT_LAYER, 10);
cardImg.update(card);
cardImg.setCardBounds(rectangle.x, rectangle.y, cardDimensions.frameWidth, cardDimensions.frameHeight);
cardImg.setCardBounds(rectangle.x, rectangle.y, cardDimensions.getFrameWidth(), cardDimensions.getFrameHeight());
cardImg.setCardCaptionTopOffset(8); // card caption below real card caption to see full name even with mana icons
// card number label
JLabel cardNumber = new JLabel();
int dy = -5; // image panel have empty space in bottom (bug?), need to move label up
cardNumber.setBounds(rectangle.x, rectangle.y + cardImg.getHeight() + dy, cardDimensions.frameWidth, 20);
cardNumber.setBounds(rectangle.x, rectangle.y + cardImg.getHeight() + dy, cardDimensions.getFrameWidth(), 20);
cardNumber.setHorizontalAlignment(SwingConstants.CENTER);
//cardNumber.setBorder(BorderFactory.createLineBorder(new Color(180, 50, 150), 3, true));
cardNumber.setFont(jLayeredPane.getFont().deriveFont(jLayeredPane.getFont().getStyle() | Font.BOLD));
@ -427,7 +427,7 @@ public class MageBook extends JComponent {
// draft rating label (
JLabel draftRating = new JLabel();
dy = -5 * 2 + cardNumber.getHeight(); // under card number
draftRating.setBounds(rectangle.x, rectangle.y + cardImg.getHeight() + dy, cardDimensions.frameWidth, 20);
draftRating.setBounds(rectangle.x, rectangle.y + cardImg.getHeight() + dy, cardDimensions.getFrameWidth(), 20);
draftRating.setHorizontalAlignment(SwingConstants.CENTER);
//draftRating.setBorder(BorderFactory.createLineBorder(new Color(0, 0, 150), 3, true));
draftRating.setFont(jLayeredPane.getFont().deriveFont(jLayeredPane.getFont().getStyle() | Font.BOLD));
@ -441,7 +441,7 @@ public class MageBook extends JComponent {
private void addToken(Token token, BigCard bigCard, UUID gameId, Rectangle rectangle) {
if (cardDimension == null) {
cardDimension = new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
cardDimension = new Dimension(Config.dimensions.getFrameWidth(), Config.dimensions.getFrameHeight());
}
PermanentToken newToken = new PermanentToken(token, null, token.getOriginalExpansionSetCode(), null);
newToken.removeSummoningSickness();
@ -451,7 +451,7 @@ public class MageBook extends JComponent {
cardImg.setBounds(rectangle);
jLayeredPane.add(cardImg, JLayeredPane.DEFAULT_LAYER, 10);
cardImg.update(theToken);
cardImg.setCardBounds(rectangle.x, rectangle.y, cardDimensions.frameWidth, cardDimensions.frameHeight);
cardImg.setCardBounds(rectangle.x, rectangle.y, cardDimensions.getFrameWidth(), cardDimensions.getFrameHeight());
}
private void addEmblem(Emblem emblem, BigCard bigCard, UUID gameId, Rectangle rectangle) {
@ -855,8 +855,8 @@ public class MageBook extends JComponent {
public static Rectangle translatePosition(int index, Rectangle r, Configuration conf) {
Rectangle rect = new Rectangle(r);
rect.translate((cardDimensions.frameWidth + GAP_X) * conf.dx[index],
(cardDimensions.frameHeight + GAP_Y) * conf.dy[index]);
rect.translate((cardDimensions.getFrameWidth() + GAP_X) * conf.dx[index],
(cardDimensions.getFrameHeight() + GAP_Y) * conf.dy[index]);
return rect;
}

View file

@ -249,8 +249,8 @@ public class TableModel extends AbstractTableModel implements ICardGrid {
private void addCard(CardView card, BigCard bigCard, UUID gameId) {
if (cardDimension == null) {
cardDimension = new Dimension(Config.dimensions.frameWidth,
Config.dimensions.frameHeight);
cardDimension = new Dimension(Config.dimensions.getFrameWidth(),
Config.dimensions.getFrameHeight());
}
cards.put(card.getId(), card);

View file

@ -235,7 +235,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
private void addPermanent(PermanentView permanent, final int count) {
if (cardDimension == null) {
cardDimension = new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
cardDimension = new Dimension(Config.dimensions.getFrameWidth(), Config.dimensions.getFrameHeight());
}
final MagePermanent perm = Plugins.instance.getMagePermanent(permanent, bigCard, cardDimension, gameId, true);
if (!Plugins.instance.isCardPluginLoaded()) {

View file

@ -111,7 +111,7 @@ public class MageActionCallback implements ActionCallback {
}
private void showTooltipPopup(final TransferData data, final Component parentComponent, final Point parentPoint) {
if (data.component != null) {
if (data.getComponent() != null) {
tooltipDelay = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_TOOLTIPS_DELAY, 300);
if (tooltipDelay == 0) {
return;
@ -120,18 +120,18 @@ public class MageActionCallback implements ActionCallback {
if (cardInfoPane == null) {
PopupFactory factory = PopupFactory.getSharedInstance();
if (data.locationOnScreen == null) {
if (data.component == null) {
if (data.getLocationOnScreen() == null) {
if (data.getComponent() == null) {
return;
}
data.locationOnScreen = data.component.getLocationOnScreen();
data.setLocationOnScreen(data.getComponent().getLocationOnScreen());
}
data.popupText.updateText();
tooltipPopup = factory.getPopup(data.component, data.popupText, (int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40);
data.getPopupText().updateText();
tooltipPopup = factory.getPopup(data.getComponent(), data.getPopupText(), (int) data.getLocationOnScreen().getX() + data.getPopupOffsetX(), (int) data.getLocationOnScreen().getY() + data.getPopupOffsetY() + 40);
tooltipPopup.show();
// hack to get popup to resize to fit text
tooltipPopup.hide();
tooltipPopup = factory.getPopup(data.component, data.popupText, (int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40);
tooltipPopup = factory.getPopup(data.getComponent(), data.getPopupText(), (int) data.getLocationOnScreen().getX() + data.getPopupOffsetX(), (int) data.getLocationOnScreen().getY() + data.getPopupOffsetY() + 40);
tooltipPopup.show();
} else {
sumbitShowPopupTask(data, parentComponent, parentPoint);
@ -145,7 +145,7 @@ public class MageActionCallback implements ActionCallback {
ThreadUtils.sleep(tooltipDelay);
if (tooltipCard == null
|| !tooltipCard.equals(data.card)
|| !tooltipCard.equals(data.getCard())
|| SessionHandler.getSession() == null
|| !popupTextWindowOpen
|| enlargedWindowState != EnlargedWindowState.CLOSED) {
@ -156,7 +156,7 @@ public class MageActionCallback implements ActionCallback {
final Component popupContainer = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER);
Component popup2 = MageFrame.getUI().getComponent(MageComponents.CARD_INFO_PANE);
((CardInfoPane) popup2).setCard(data.card, popupContainer);
((CardInfoPane) popup2).setCard(data.getCard(), popupContainer);
showPopup(popupContainer, popup2);
@ -172,11 +172,11 @@ public class MageActionCallback implements ActionCallback {
|| enlargedWindowState != EnlargedWindowState.CLOSED) {
return;
}
if (data.locationOnScreen == null) {
data.locationOnScreen = data.component.getLocationOnScreen();
if (data.getLocationOnScreen() == null) {
data.setLocationOnScreen(data.getComponent().getLocationOnScreen());
}
Point location = new Point((int) data.locationOnScreen.getX() + data.popupOffsetX - 40, (int) data.locationOnScreen.getY() + data.popupOffsetY - 40);
Point location = new Point((int) data.getLocationOnScreen().getX() + data.getPopupOffsetX() - 40, (int) data.getLocationOnScreen().getY() + data.getPopupOffsetY() - 40);
location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, infoPane, parentComponent);
location.translate(-parentPoint.x, -parentPoint.y);
popupContainer.setLocation(location);
@ -190,7 +190,7 @@ public class MageActionCallback implements ActionCallback {
@Override
public void mousePressed(MouseEvent e, TransferData data) {
data.component.requestFocusInWindow();
data.getComponent().requestFocusInWindow();
// for some reason sometime mouseRelease happens before numerous Mouse_Dragged events
// that results in not finished dragging
@ -201,23 +201,23 @@ public class MageActionCallback implements ActionCallback {
prevCardPanel = null;
cardPanels.clear();
Point mouse = new Point(e.getX(), e.getY());
SwingUtilities.convertPointToScreen(mouse, data.component);
SwingUtilities.convertPointToScreen(mouse, data.getComponent());
initialMousePos = new Point((int) mouse.getX(), (int) mouse.getY());
initialCardPos = data.component.getLocation();
initialCardPos = data.getComponent().getLocation();
// Closes popup & enlarged view if a card/Permanent is selected
hideTooltipPopup();
}
@Override
public void mouseReleased(MouseEvent e, TransferData transferData) {
CardPanel card = ((CardPanel) transferData.component);
CardPanel card = ((CardPanel) transferData.getComponent());
if (e.isPopupTrigger() /*&& card.getPopupMenu() != null*/) {
hideTooltipPopup();
} else if (card.getZone() != null && card.getZone().equalsIgnoreCase("hand")) {
int maxXOffset = 0;
if (isDragging) {
Point mouse = new Point(e.getX(), e.getY());
SwingUtilities.convertPointToScreen(mouse, transferData.component);
SwingUtilities.convertPointToScreen(mouse, transferData.getComponent());
maxXOffset = Math.abs((int) (mouse.getX() - initialMousePos.x));
}
@ -225,15 +225,15 @@ public class MageActionCallback implements ActionCallback {
this.startedDragging = false;
if (maxXOffset < MIN_X_OFFSET_REQUIRED) { // we need this for protection from small card movements
transferData.component.requestFocusInWindow();
DefaultActionCallback.instance.mouseClicked(transferData.gameId, transferData.card);
transferData.getComponent().requestFocusInWindow();
DefaultActionCallback.instance.mouseClicked(transferData.getGameId(), transferData.getCard());
// Closes popup & enlarged view if a card/Permanent is selected
hideTooltipPopup();
}
e.consume();
} else {
transferData.component.requestFocusInWindow();
DefaultActionCallback.instance.mouseClicked(transferData.gameId, transferData.card);
transferData.getComponent().requestFocusInWindow();
DefaultActionCallback.instance.mouseClicked(transferData.getGameId(), transferData.getCard());
// Closes popup & enlarged view if a card/Permanent is selected
hideTooltipPopup();
e.consume();
@ -261,7 +261,7 @@ public class MageActionCallback implements ActionCallback {
if (!Plugins.instance.isCardPluginLoaded()) {
return;
}
if (!popupData.card.equals(transferData.card)) {
if (!popupData.getCard().equals(transferData.getCard())) {
this.popupData = transferData;
handleOverNewView(transferData);
@ -274,7 +274,7 @@ public class MageActionCallback implements ActionCallback {
@Override
public void mouseDragged(MouseEvent e, TransferData transferData) {
CardPanel cardPanel = ((CardPanel) transferData.component);
CardPanel cardPanel = ((CardPanel) transferData.getComponent());
if (cardPanel.getZone() == null || !cardPanel.getZone().equalsIgnoreCase("hand")) {
// drag'n'drop is allowed for HAND zone only
return;
@ -287,7 +287,7 @@ public class MageActionCallback implements ActionCallback {
prevCardPanel = cardPanel;
Point cardPanelLocationOld = cardPanel.getLocation();
Point mouse = new Point(e.getX(), e.getY());
SwingUtilities.convertPointToScreen(mouse, transferData.component);
SwingUtilities.convertPointToScreen(mouse, transferData.getComponent());
int xOffset = cardPanel.getXOffset(cardPanel.getCardWidth());
int newX = Math.max(initialCardPos.x + (int) (mouse.getX() - initialMousePos.x) - xOffset, 0);
cardPanel.setCardBounds(
@ -306,7 +306,7 @@ public class MageActionCallback implements ActionCallback {
@Override
public void mouseExited(MouseEvent e, final TransferData data) {
if (data != null) {
hideAll(data.gameId);
hideAll(data.getGameId());
} else {
hideAll(null);
}
@ -362,20 +362,20 @@ public class MageActionCallback implements ActionCallback {
// Prevent to show tooltips from panes not in front
MagePane topPane = MageFrame.getTopMost(null);
if (topPane instanceof GamePane) {
if (!((GamePane) topPane).getGameId().equals(data.gameId)) {
if (!((GamePane) topPane).getGameId().equals(data.getGameId())) {
return;
}
} else if (data.gameId != null) {
} else if (data.getGameId() != null) {
return;
}
hideTooltipPopup();
cancelTimeout();
Component parentComponent = SwingUtilities.getRoot(data.component);
Component parentComponent = SwingUtilities.getRoot(data.getComponent());
Point parentPoint = parentComponent.getLocationOnScreen();
if (data.locationOnScreen == null) {
data.locationOnScreen = data.component.getLocationOnScreen();
if (data.getLocationOnScreen() == null) {
data.setLocationOnScreen(data.getComponent().getLocationOnScreen());
}
ArrowUtil.drawArrowsForTargets(data, parentPoint);
@ -383,12 +383,12 @@ public class MageActionCallback implements ActionCallback {
ArrowUtil.drawArrowsForPairedCards(data, parentPoint);
ArrowUtil.drawArrowsForBandedCards(data, parentPoint);
ArrowUtil.drawArrowsForEnchantPlayers(data, parentPoint);
tooltipCard = data.card;
tooltipCard = data.getCard();
showTooltipPopup(data, parentComponent, parentPoint);
}
private void handlePopup(TransferData transferData) {
MageCard mageCard = (MageCard) transferData.component;
MageCard mageCard = (MageCard) transferData.getComponent();
if (!popupTextWindowOpen
|| !Objects.equals(mageCard.getOriginal().getId(), bigCard.getCardId())) {
if (bigCard.getWidth() > 0) {
@ -502,7 +502,7 @@ public class MageActionCallback implements ActionCallback {
this.enlargeMode = showAlternative;
CardView cardView = null;
if (popupData != null) {
cardView = popupData.card;
cardView = popupData.getCard();
}
if (this.popupTextWindowOpen) {
hideTooltipPopup();
@ -566,17 +566,17 @@ public class MageActionCallback implements ActionCallback {
}
final Component popupContainer = MageFrame.getUI().getComponent(mageComponentCardPreviewContainer);
Component cardPreviewPane = MageFrame.getUI().getComponent(mageComponentCardPreviewPane);
Component parentComponent = SwingUtilities.getRoot(transferData.component);
Component parentComponent = SwingUtilities.getRoot(transferData.getComponent());
if (cardPreviewPane != null && parentComponent != null) {
Point parentPoint = parentComponent.getLocationOnScreen();
transferData.locationOnScreen = transferData.component.getLocationOnScreen();
Point location = new Point((int) transferData.locationOnScreen.getX() + transferData.popupOffsetX - 40, (int) transferData.locationOnScreen.getY() + transferData.popupOffsetY - 40);
transferData.setLocationOnScreen(transferData.getComponent().getLocationOnScreen());
Point location = new Point((int) transferData.getLocationOnScreen().getX() + transferData.getPopupOffsetX() - 40, (int) transferData.getLocationOnScreen().getY() + transferData.getPopupOffsetY() - 40);
location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, cardPreviewPane, parentComponent);
location.translate(-parentPoint.x, -parentPoint.y);
popupContainer.setLocation(location);
popupContainer.setVisible(true);
MageCard mageCard = (MageCard) transferData.component;
MageCard mageCard = (MageCard) transferData.getComponent();
Image image = null;
switch (enlargeMode) {
case COPY:

View file

@ -61,9 +61,9 @@ public class CombatGroup extends javax.swing.JPanel {
attackers = new mage.client.cards.Cards();
lblDefender = new javax.swing.JLabel();
blockers.setPreferredSize(new java.awt.Dimension(Config.dimensions.frameWidth + 8, Config.dimensions.frameHeight + 25));
blockers.setPreferredSize(new java.awt.Dimension(Config.dimensions.getFrameWidth() + 8, Config.dimensions.getFrameHeight() + 25));
attackers.setPreferredSize(new java.awt.Dimension(Config.dimensions.frameWidth + 8, Config.dimensions.frameHeight + 25));
attackers.setPreferredSize(new java.awt.Dimension(Config.dimensions.getFrameWidth() + 8, Config.dimensions.getFrameHeight() + 25));
lblDefender.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lblDefender.setText("Defender");

View file

@ -14,7 +14,7 @@ public final class IgnoreList {
+ "<br/>\\unignore [username] - remove a username from your ignore list on this server.</font>";
public static final int MAX_IGNORE_LIST_SIZE = 50;
public static Set<ChatMessage.MessageType> IGNORED_MESSAGE_TYPES
public static final Set<ChatMessage.MessageType> IGNORED_MESSAGE_TYPES
= ImmutableSet.of(ChatMessage.MessageType.TALK,
ChatMessage.MessageType.WHISPER_FROM);

View file

@ -19,32 +19,32 @@ public final class ArrowUtil {
private ArrowUtil() {}
public static void drawArrowsForPairedCards(TransferData data, Point parentPoint) {
if (data.card.getPairedCard() != null) {
Point me = new Point(data.locationOnScreen);
if (data.getCard().getPairedCard() != null) {
Point me = new Point(data.getLocationOnScreen());
me.translate(-parentPoint.x, -parentPoint.y);
UUID uuid = data.card.getPairedCard();
for (PlayAreaPanel pa : MageFrame.getGame(data.gameId).getPlayers().values()) {
UUID uuid = data.getCard().getPairedCard();
for (PlayAreaPanel pa : MageFrame.getGame(data.getGameId()).getPlayers().values()) {
MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid);
if (permanent != null) {
Point target = permanent.getLocationOnScreen();
target.translate(-parentPoint.x, -parentPoint.y);
ArrowBuilder.getBuilder().addArrow(data.gameId, (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 40, (int) target.getY() + 10, Color.green, ArrowBuilder.Type.PAIRED);
ArrowBuilder.getBuilder().addArrow(data.getGameId(), (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 40, (int) target.getY() + 10, Color.green, ArrowBuilder.Type.PAIRED);
}
}
}
}
public static void drawArrowsForBandedCards(TransferData data, Point parentPoint) {
if (data.card.getBandedCards() != null && !data.card.getBandedCards().isEmpty()) {
Point me = new Point(data.locationOnScreen);
if (data.getCard().getBandedCards() != null && !data.getCard().getBandedCards().isEmpty()) {
Point me = new Point(data.getLocationOnScreen());
me.translate(-parentPoint.x, -parentPoint.y);
for (PlayAreaPanel pa : MageFrame.getGame(data.gameId).getPlayers().values()) {
for (UUID uuid : data.card.getBandedCards()) {
for (PlayAreaPanel pa : MageFrame.getGame(data.getGameId()).getPlayers().values()) {
for (UUID uuid : data.getCard().getBandedCards()) {
MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid);
if (permanent != null) {
Point target = permanent.getLocationOnScreen();
target.translate(-parentPoint.x, -parentPoint.y);
ArrowBuilder.getBuilder().addArrow(data.gameId, (int) me.getX() + 55, (int) me.getY() + 25, (int) target.getX() + 60, (int) target.getY() + 35, Color.yellow, ArrowBuilder.Type.BANDED);
ArrowBuilder.getBuilder().addArrow(data.getGameId(), (int) me.getX() + 55, (int) me.getY() + 25, (int) target.getX() + 60, (int) target.getY() + 35, Color.yellow, ArrowBuilder.Type.BANDED);
}
}
}
@ -52,17 +52,17 @@ public final class ArrowUtil {
}
public static void drawArrowsForEnchantPlayers(TransferData data, Point parentPoint) {
if (data.gameId != null && MageFrame.getGame(data.gameId) != null) {
for (PlayAreaPanel pa : MageFrame.getGame(data.gameId).getPlayers().values()) {
if (data.getGameId() != null && MageFrame.getGame(data.getGameId()) != null) {
for (PlayAreaPanel pa : MageFrame.getGame(data.getGameId()).getPlayers().values()) {
PlayerPanelExt playAreaPanel = pa.getPlayerPanel();
if (playAreaPanel != null && playAreaPanel.getPlayer() != null && playAreaPanel.getPlayer().hasAttachments()) {
Point me = new Point(data.locationOnScreen);
Point me = new Point(data.getLocationOnScreen());
me.translate(-parentPoint.x, -parentPoint.y);
for (UUID attachmentId : playAreaPanel.getPlayer().getAttachments()) {
if (attachmentId.equals(data.card.getId())) {
if (attachmentId.equals(data.getCard().getId())) {
Point player = pa.getLocationOnScreen();
player.translate(-parentPoint.x, -parentPoint.y);
ArrowBuilder.getBuilder().addArrow(data.gameId,(int) me.getX() + 35, (int) me.getY(), (int) player.getX() + 40, (int) player.getY() - 40, Color.magenta, ArrowBuilder.Type.ENCHANT_PLAYERS);
ArrowBuilder.getBuilder().addArrow(data.getGameId(),(int) me.getX() + 35, (int) me.getY(), (int) player.getX() + 40, (int) player.getY() - 40, Color.magenta, ArrowBuilder.Type.ENCHANT_PLAYERS);
}
}
}
@ -71,45 +71,45 @@ public final class ArrowUtil {
}
public static void drawArrowsForSource(TransferData data, Point parentPoint) {
if (data.card.isAbility()) {
Point me = new Point(data.locationOnScreen);
if (data.getCard().isAbility()) {
Point me = new Point(data.getLocationOnScreen());
me.translate(-parentPoint.x, -parentPoint.y);
UUID uuid = data.card.getParentId();
for (PlayAreaPanel pa : MageFrame.getGame(data.gameId).getPlayers().values()) {
UUID uuid = data.getCard().getParentId();
for (PlayAreaPanel pa : MageFrame.getGame(data.getGameId()).getPlayers().values()) {
MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid);
if (permanent != null) {
Point source = permanent.getLocationOnScreen();
source.translate(-parentPoint.x, -parentPoint.y);
ArrowBuilder.getBuilder().addArrow(data.gameId, (int) source.getX() + 40, (int) source.getY() + 10, (int) me.getX() + 35, (int) me.getY() + 20, Color.blue, ArrowBuilder.Type.SOURCE);
ArrowBuilder.getBuilder().addArrow(data.getGameId(), (int) source.getX() + 40, (int) source.getY() + 10, (int) me.getX() + 35, (int) me.getY() + 20, Color.blue, ArrowBuilder.Type.SOURCE);
}
}
}
}
public static void drawArrowsForTargets(TransferData data, Point parentPoint) {
java.util.List<UUID> targets = data.card.getTargets();
java.util.List<UUID> targets = data.getCard().getTargets();
if (targets == null) {
return;
}
Point me = new Point(data.locationOnScreen);
Point me = new Point(data.getLocationOnScreen());
me.translate(-parentPoint.x, -parentPoint.y);
for (UUID uuid : targets) {
PlayAreaPanel p = MageFrame.getGame(data.gameId).getPlayers().get(uuid);
PlayAreaPanel p = MageFrame.getGame(data.getGameId()).getPlayers().get(uuid);
if (p != null) {
Point target = p.getLocationOnScreen();
target.translate(-parentPoint.x, -parentPoint.y);
ArrowBuilder.getBuilder().addArrow(data.gameId, (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 40, (int) target.getY() - 40, Color.red, ArrowBuilder.Type.TARGET);
ArrowBuilder.getBuilder().addArrow(data.getGameId(), (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 40, (int) target.getY() - 40, Color.red, ArrowBuilder.Type.TARGET);
continue;
}
for (PlayAreaPanel panel : MageFrame.getGame(data.gameId).getPlayers().values()) {
for (PlayAreaPanel panel : MageFrame.getGame(data.getGameId()).getPlayers().values()) {
MagePermanent permanent = panel.getBattlefieldPanel().getPermanents().get(uuid);
if (permanent != null) {
Point target = permanent.getLocationOnScreen();
target.translate(-parentPoint.x, -parentPoint.y);
ArrowBuilder.getBuilder().addArrow(data.gameId, (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 40, (int) target.getY() + 10, Color.red, ArrowBuilder.Type.TARGET);
ArrowBuilder.getBuilder().addArrow(data.getGameId(), (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 40, (int) target.getY() + 10, Color.red, ArrowBuilder.Type.TARGET);
continue;
}
@ -117,12 +117,12 @@ public final class ArrowUtil {
if (view != null) {
CardsView graveyard = view.getGraveyard();
if (graveyard.containsKey(uuid)) {
p = MageFrame.getGame(data.gameId).getPlayers().get(view.getPlayerId());
p = MageFrame.getGame(data.getGameId()).getPlayers().get(view.getPlayerId());
if (p != null) {
Point target = p.getLocationOnScreen();
target.translate(-parentPoint.x, -parentPoint.y);
int yOffset = p.isSmallMode() ? (PlayAreaPanel.PANEL_HEIGHT - PlayAreaPanel.PANEL_HEIGHT_SMALL) : 0;
ArrowBuilder.getBuilder().addArrow(data.gameId, (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 15, (int) target.getY() + 145 - yOffset, Color.red, ArrowBuilder.Type.TARGET);
ArrowBuilder.getBuilder().addArrow(data.getGameId(), (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 15, (int) target.getY() + 145 - yOffset, Color.red, ArrowBuilder.Type.TARGET);
}
}
}

View file

@ -14,8 +14,8 @@ import java.util.Map;
*/
public class FastSearchUtil {
public static String DEFAULT_EXPANSION_SEARCH_MESSAGE = "Select set or expansion";
public static String DEFAULT_EXPANSION_TOOLTIP_MESSAGE = "Fast search set or expansion";
public static final String DEFAULT_EXPANSION_SEARCH_MESSAGE = "Select set or expansion";
public static final String DEFAULT_EXPANSION_TOOLTIP_MESSAGE = "Fast search set or expansion";
public static void showFastSearchForStringComboBox(JComboBox combo, String chooseMessage) {
showFastSearchForStringComboBox(combo, chooseMessage, 300, 500);

View file

@ -27,8 +27,24 @@ public final class GuiDisplayUtil {
public static class TextLines {
public int basicTextLength;
public ArrayList<String> lines;
private int basicTextLength;
private java.util.List<String> lines;
public int getBasicTextLength() {
return basicTextLength;
}
public void setBasicTextLength(int basicTextLength) {
this.basicTextLength = basicTextLength;
}
public java.util.List<String> getLines() {
return lines;
}
public void setLines(java.util.List<String> lines) {
this.lines = lines;
}
}
public static void restoreDividerLocations(Rectangle bounds, String lastDividerLocation, JComponent component) {
@ -165,9 +181,9 @@ public final class GuiDisplayUtil {
public static TextLines getTextLinesfromCardView(CardView card) {
TextLines textLines = new TextLines();
textLines.lines = new ArrayList<>(card.getRules());
textLines.setLines(new ArrayList<>(card.getRules()));
for (String rule : card.getRules()) {
textLines.basicTextLength += rule.length();
textLines.setBasicTextLength(textLines.getBasicTextLength() + rule.length());
}
if (card.getMageObjectType().canHaveCounters()) {
ArrayList<CounterView> counters = new ArrayList<>();
@ -192,15 +208,15 @@ public final class GuiDisplayUtil {
index++;
}
}
textLines.lines.add(sb.toString());
textLines.basicTextLength += 50;
textLines.getLines().add(sb.toString());
textLines.setBasicTextLength(textLines.getBasicTextLength() + 50);
}
}
if (card.getMageObjectType().isPermanent() && card instanceof PermanentView) {
int damage = ((PermanentView) card).getDamage();
if (damage > 0) {
textLines.lines.add("<span color='red'><b>Damage dealt:</b> " + damage + "</span>");
textLines.basicTextLength += 50;
textLines.getLines().add("<span color='red'><b>Damage dealt:</b> " + damage + "</span>");
textLines.setBasicTextLength(textLines.getBasicTextLength() + 50);
}
}
return textLines;
@ -350,8 +366,8 @@ public final class GuiDisplayUtil {
}
}
}
if (!textLines.lines.isEmpty()) {
for (String textLine : textLines.lines) {
if (!textLines.getLines().isEmpty()) {
for (String textLine : textLines.getLines()) {
if (textLine != null && !textLine.replace(".", "").trim().isEmpty()) {
rule.append("<p style='margin: 2px'>").append(textLine).append("</p>");
}