From 16bf6d69907c9e1dd0714166c567237e968fe2bf Mon Sep 17 00:00:00 2001 From: jendave Date: Tue, 25 Oct 2011 09:14:52 +0000 Subject: [PATCH] checkstyle --- src/main/java/arcane/ui/CardArea.java | 135 ++++-- src/main/java/arcane/ui/CardPanel.java | 241 ++++++---- .../java/arcane/ui/CardPanelContainer.java | 433 +++++++++++------- src/main/java/arcane/ui/HandArea.java | 24 +- src/main/java/arcane/ui/PlayArea.java | 299 +++++++----- src/main/java/arcane/ui/ScaledImagePanel.java | 146 ++++-- src/main/java/arcane/ui/ViewPanel.java | 18 +- src/main/java/arcane/ui/package-info.java | 2 +- src/main/java/forge/item/ItemPoolView.java | 1 + 9 files changed, 850 insertions(+), 449 deletions(-) diff --git a/src/main/java/arcane/ui/CardArea.java b/src/main/java/arcane/ui/CardArea.java index d89a9ca65ed..fb5431eece4 100644 --- a/src/main/java/arcane/ui/CardArea.java +++ b/src/main/java/arcane/ui/CardArea.java @@ -1,30 +1,39 @@ package arcane.ui; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.MouseEvent; + +import javax.swing.JFrame; +import javax.swing.JLayeredPane; +import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; + import arcane.ui.util.Animation; import arcane.ui.util.CardPanelMouseListener; -import javax.swing.*; -import java.awt.*; -import java.awt.event.MouseEvent; - /** *

CardArea class.

* * @author Forge * @version $Id$ */ -public class CardArea extends CardPanelContainer - implements CardPanelMouseListener { +public class CardArea extends CardPanelContainer implements CardPanelMouseListener +{ /** * */ private static final long serialVersionUID = -5836122075999621592L; /** - * Constant GUTTER_Y=5 + * Constant GUTTER_Y=5. */ public static final int GUTTER_Y = 5; /** - * Constant GUTTER_X=5 + * Constant GUTTER_X=5. */ public static final int GUTTER_X = 5; /** @@ -60,13 +69,13 @@ public class CardArea extends CardPanelContainer * * @param scrollPane a {@link javax.swing.JScrollPane} object. */ - public CardArea(JScrollPane scrollPane) { + public CardArea(final JScrollPane scrollPane) { super(scrollPane); setBackground(Color.white); } /** {@inheritDoc} */ - public CardPanel getCardPanel(int x, int y) { + public final CardPanel getCardPanel(final int x, final int y) { if (isVertical) { for (int i = cardPanels.size() - 1; i >= 0; i--) { CardPanel panel = cardPanels.get(i); @@ -76,7 +85,9 @@ public class CardArea extends CardPanelContainer int panelHeight = panel.getCardHeight(); if (x > panelX && x < panelX + panelWidth) { if (y > panelY && y < panelY + panelHeight) { - if (!panel.isDisplayEnabled()) return null; + if (!panel.isDisplayEnabled()) { + return null; + } return panel; } } @@ -90,7 +101,9 @@ public class CardArea extends CardPanelContainer int panelHeight = panel.getCardHeight(); if (x > panelX && x < panelX + panelWidth) { if (y > panelY && y < panelY + panelHeight) { - if (!panel.isDisplayEnabled()) return null; + if (!panel.isDisplayEnabled()) { + return null; + } return panel; } } @@ -104,8 +117,10 @@ public class CardArea extends CardPanelContainer * * @since 1.0.15 */ - public void doLayout() { - if (cardPanels.isEmpty()) return; + public final void doLayout() { + if (cardPanels.isEmpty()) { + return; + } Rectangle rect = scrollPane.getVisibleRect(); Insets insets = scrollPane.getInsets(); @@ -126,11 +141,16 @@ public class CardArea extends CardPanelContainer cardHeight = Math.round(cardWidth * CardPanel.ASPECT_RATIO); cardSpacingX = Math.round(cardWidth * VERT_CARD_SPACING_X); cardSpacingY = cardHeight + Math.round(cardWidth * VERT_CARD_SPACING_Y); - int maxRows = (int) Math.floor((cardAreaWidth - GUTTER_X * 2 + cardSpacingX) / (cardWidth + cardSpacingX)); - if (this.maxRows > 0) maxRows = Math.min(this.maxRows, maxRows); + int maxRows = + (int) Math.floor((cardAreaWidth - GUTTER_X * 2 + cardSpacingX) / (cardWidth + cardSpacingX)); + if (this.maxRows > 0) { + maxRows = Math.min(this.maxRows, maxRows); + } int availableRowHeight = cardAreaHeight - GUTTER_Y * 2; - int availableCardsPerRow = (int) Math.floor((availableRowHeight - (cardHeight - cardSpacingY)) / (double) cardSpacingY); - actualCardsPerRow = Math.max(availableCardsPerRow, (int) Math.ceil(cardPanels.size() / (float) maxRows)); + int availableCardsPerRow = + (int) Math.floor((availableRowHeight - (cardHeight - cardSpacingY)) / (double) cardSpacingY); + actualCardsPerRow = + Math.max(availableCardsPerRow, (int) Math.ceil(cardPanels.size() / (float) maxRows)); int actualRowHeight = (int) Math.floor((actualCardsPerRow - 1) * cardSpacingY + cardHeight); float overflow = actualRowHeight - availableRowHeight; if (overflow > 0) { @@ -139,16 +159,22 @@ public class CardArea extends CardPanelContainer cardSpacingY -= offsetY; } actualRowHeight = (int) Math.floor((actualCardsPerRow - 1) * cardSpacingY + cardHeight); - if (actualRowHeight >= 0 && actualRowHeight <= availableRowHeight) break; + if (actualRowHeight >= 0 && actualRowHeight <= availableRowHeight) { + break; + } cardWidth--; - if (cardWidth == cardWidthMin) break; + if (cardWidth == cardWidthMin) { + break; + } } float x = GUTTER_X; int y = GUTTER_Y; int zOrder = cardPanels.size() - 1, rowCount = 0; for (CardPanel panel : cardPanels) { - if (panel != mouseDragPanel) panel.setCardBounds((int) Math.floor(x), y, cardWidth, cardHeight); + if (panel != mouseDragPanel) { + panel.setCardBounds((int) Math.floor(x), y, cardWidth, cardHeight); + } y += cardSpacingY; maxWidth = Math.round(x) + cardWidth + GUTTER_X; maxHeight = Math.max(maxHeight, (y + (cardHeight - cardSpacingY) + GUTTER_Y)); @@ -167,11 +193,17 @@ public class CardArea extends CardPanelContainer int extraCardSpacingX = Math.round(cardWidth * HORIZ_CARD_SPACING_X); cardSpacingY = Math.round(cardHeight * HORIZ_CARD_SPACING_Y); cardSpacingX = cardWidth + extraCardSpacingX; - int maxRows = (int) Math.floor((cardAreaHeight - GUTTER_Y * 2 + cardSpacingY) / (double) (cardHeight + cardSpacingY)); - if (this.maxRows > 0) maxRows = Math.min(this.maxRows, maxRows); + int maxRows = + (int) Math.floor((cardAreaHeight - GUTTER_Y * 2 + cardSpacingY) / + (double) (cardHeight + cardSpacingY)); + if (this.maxRows > 0) { + maxRows = Math.min(this.maxRows, maxRows); + } int availableRowWidth = cardAreaWidth - GUTTER_X * 2; - int availableCardsPerRow = (int) Math.floor((availableRowWidth - (cardWidth - cardSpacingX)) / cardSpacingX); - actualCardsPerRow = Math.max(availableCardsPerRow, (int) Math.ceil(cardPanels.size() / (float) maxRows)); + int availableCardsPerRow = + (int) Math.floor((availableRowWidth - (cardWidth - cardSpacingX)) / cardSpacingX); + actualCardsPerRow = + Math.max(availableCardsPerRow, (int) Math.ceil(cardPanels.size() / (float) maxRows)); int actualRowWidth = (int) Math.floor((actualCardsPerRow - 1) * cardSpacingX + cardWidth); float overflow = actualRowWidth - availableRowWidth; if (overflow > 0) { @@ -180,16 +212,22 @@ public class CardArea extends CardPanelContainer cardSpacingX -= offsetX; } actualRowWidth = (int) Math.floor((actualCardsPerRow - 1) * cardSpacingX + cardWidth); - if (actualRowWidth <= availableRowWidth) break; + if (actualRowWidth <= availableRowWidth) { + break; + } cardWidth--; - if (cardWidth == cardWidthMin) break; + if (cardWidth == cardWidthMin) { + break; + } } float x = GUTTER_X; int y = GUTTER_Y; int zOrder = 0, rowCount = 0; for (CardPanel panel : cardPanels) { - if (panel != mouseDragPanel) panel.setCardBounds((int) Math.floor(x), y, cardWidth, cardHeight); + if (panel != mouseDragPanel) { + panel.setCardBounds((int) Math.floor(x), y, cardWidth, cardHeight); + } x += cardSpacingX; maxWidth = Math.max(maxWidth, Math.round(x + (cardWidth - cardSpacingX) + GUTTER_X) - 1); maxHeight = Math.max(maxHeight, y + (cardHeight - cardSpacingY) + GUTTER_Y); @@ -213,16 +251,18 @@ public class CardArea extends CardPanelContainer } /** {@inheritDoc} */ - public void paint(Graphics g) { + public final void paint(final Graphics g) { boolean hasScrollbars = scrollPane.getVerticalScrollBar().isVisible(); - if (hasScrollbars != this.hasScrollbars) revalidate(); + if (hasScrollbars != this.hasScrollbars) { + revalidate(); + } this.hasScrollbars = hasScrollbars; super.paint(g); } /** {@inheritDoc} */ - public void mouseDragStart(CardPanel dragPanel, MouseEvent evt) { + public final void mouseDragStart(final CardPanel dragPanel, final MouseEvent evt) { super.mouseDragStart(dragPanel, evt); mouseDragStartX = dragPanel.getCardX(); @@ -240,7 +280,9 @@ public class CardArea extends CardPanelContainer } /** {@inheritDoc} */ - public void mouseDragged(CardPanel dragPanel, int dragOffsetX, int dragOffsetY, MouseEvent evt) { + public final void mouseDragged(final CardPanel dragPanel, + final int dragOffsetX, final int dragOffsetY, final MouseEvent evt) + { super.mouseDragged(dragPanel, dragOffsetX, dragOffsetY, evt); int mouseX = evt.getX(); @@ -251,10 +293,15 @@ public class CardArea extends CardPanelContainer CardPanel.dragAnimationPanel.setLocation(p.x, p.y); CardPanel panel = getCardPanel(mouseX, mouseY); - if (panel == null || panel == dragPanel) return; + if (panel == null || panel == dragPanel) { + return; + } int index = cardPanels.size(); - while (--index >= 0) - if (cardPanels.get(index) == panel) break; + while (--index >= 0) { + if (cardPanels.get(index) == panel) { + break; + } + } cardPanels.remove(dragPanel); cardPanels.add(index, dragPanel); mouseDragStartX = panel.getCardX(); @@ -263,7 +310,7 @@ public class CardArea extends CardPanelContainer } /** {@inheritDoc} */ - public void mouseDragEnd(CardPanel dragPanel, MouseEvent evt) { + public final void mouseDragEnd(final CardPanel dragPanel, final MouseEvent evt) { super.mouseDragEnd(dragPanel, evt); doLayout(); JLayeredPane layeredPane = SwingUtilities.getRootPane(CardPanel.dragAnimationPanel).getLayeredPane(); @@ -272,8 +319,8 @@ public class CardArea extends CardPanelContainer int startWidth = CardPanel.dragAnimationPanel.getCardWidth(); Point endPos = SwingUtilities.convertPoint(this, dragPanel.getCardLocation(), layeredPane); int endWidth = dragPanel.getCardWidth(); - Animation.moveCard(startX, startY, startWidth, endPos.x, endPos.y, endWidth, CardPanel.dragAnimationPanel, dragPanel, - layeredPane, 200); + Animation.moveCard(startX, startY, startWidth, endPos.x, endPos.y, endWidth, + CardPanel.dragAnimationPanel, dragPanel, layeredPane, 200); } /** @@ -281,7 +328,7 @@ public class CardArea extends CardPanelContainer * * @return a float. */ - public float getMaxCoverage() { + public final float getMaxCoverage() { return maxCoverage; } @@ -290,7 +337,7 @@ public class CardArea extends CardPanelContainer * * @param maxCoverage a float. */ - public void setMaxCoverage(float maxCoverage) { + public final void setMaxCoverage(float maxCoverage) { this.maxCoverage = maxCoverage; } @@ -299,7 +346,7 @@ public class CardArea extends CardPanelContainer * * @param maxRows a int. */ - public void setMaxRows(int maxRows) { + public final void setMaxRows(int maxRows) { this.maxRows = maxRows; } @@ -308,7 +355,7 @@ public class CardArea extends CardPanelContainer * * @return a int. */ - public int getMaxRows() { + public final int getMaxRows() { return maxRows; } @@ -317,7 +364,7 @@ public class CardArea extends CardPanelContainer * * @param isVertical a boolean. */ - public void setVertical(boolean isVertical) { + public final void setVertical(final boolean isVertical) { this.isVertical = isVertical; } @@ -326,7 +373,7 @@ public class CardArea extends CardPanelContainer * * @return a boolean. */ - public boolean isVertical() { + public final boolean isVertical() { return isVertical; } } diff --git a/src/main/java/arcane/ui/CardPanel.java b/src/main/java/arcane/ui/CardPanel.java index a4cbe7fa114..213d3bbf70a 100644 --- a/src/main/java/arcane/ui/CardPanel.java +++ b/src/main/java/arcane/ui/CardPanel.java @@ -21,42 +21,60 @@ import java.util.List; * @version $Id$ */ public class CardPanel extends JPanel implements CardContainer { - /** Constant serialVersionUID=2361907095724263295L */ + /** Constant serialVersionUID=2361907095724263295L. */ private static final long serialVersionUID = 2361907095724263295L; /** - * Constant TAPPED_ANGLE=Math.PI / 2 + * Constant TAPPED_ANGLE=Math.PI / 2. */ public static final double TAPPED_ANGLE = Math.PI / 2; /** - * Constant ASPECT_RATIO=3.5f / 2.5f + * Constant ASPECT_RATIO=3.5f / 2.5f. */ public static final float ASPECT_RATIO = 3.5f / 2.5f; /** - * Constant dragAnimationPanel + * Constant dragAnimationPanel. */ public static CardPanel dragAnimationPanel; - /** Constant ROUNDED_CORNER_SIZE=0.1f */ + /** Constant ROUNDED_CORNER_SIZE=0.1f. */ private static final float ROUNDED_CORNER_SIZE = 0.1f; - /** Constant SELECTED_BORDER_SIZE=0.01f */ + /** Constant SELECTED_BORDER_SIZE=0.01f. */ private static final float SELECTED_BORDER_SIZE = 0.01f; - /** Constant BLACK_BORDER_SIZE=0.03f */ + /** Constant BLACK_BORDER_SIZE=0.03f. */ private static final float BLACK_BORDER_SIZE = 0.03f; - /** Constant TEXT_GLOW_SIZE=6 */ + /** Constant TEXT_GLOW_SIZE=6. */ private static final int TEXT_GLOW_SIZE = 6; - /** Constant TEXT_GLOW_INTENSITY=3f */ + /** Constant TEXT_GLOW_INTENSITY=3f. */ private static final float TEXT_GLOW_INTENSITY = 3f; - /** Constant rotCenterToTopCorner=1.0295630140987000315797369464196f */ + /** Constant rotCenterToTopCorner=1.0295630140987000315797369464196f. */ private static final float rotCenterToTopCorner = 1.0295630140987000315797369464196f; - /** Constant rotCenterToBottomCorner=0.7071067811865475244008443621048f */ + /** Constant rotCenterToBottomCorner=0.7071067811865475244008443621048f. */ private static final float rotCenterToBottomCorner = 0.7071067811865475244008443621048f; + /** + * + */ public Card gameCard; + /** + * + */ public CardPanel attachedToPanel; + /** + * + */ public List attachedPanels = new ArrayList(); + /** + * + */ public boolean tapped; + /** + * + */ public double tappedAngle = 0; + /** + * + */ public ScaledImagePanel imagePanel; private GlowText titleText; @@ -73,7 +91,7 @@ public class CardPanel extends JPanel implements CardContainer { * * @param newGameCard a {@link forge.Card} object. */ - public CardPanel(Card newGameCard) { + public CardPanel(final Card newGameCard) { this.gameCard = newGameCard; setBackground(Color.black); @@ -101,12 +119,12 @@ public class CardPanel extends JPanel implements CardContainer { addComponentListener(new ComponentAdapter() { @Override - public void componentShown(ComponentEvent e) { + public void componentShown(final ComponentEvent e) { setCard(gameCard); } @Override - public void componentResized(ComponentEvent e) { + public void componentResized(final ComponentEvent e) { setCard(gameCard); } }); @@ -121,7 +139,7 @@ public class CardPanel extends JPanel implements CardContainer { * @param srcImageBlurred a {@link java.awt.Image} object. * @param srcImageBlurred a {@link java.awt.Image} object. */ - private void setImage(Image srcImage, Image srcImageBlurred) { + private void setImage(final Image srcImage, final Image srcImageBlurred) { synchronized (imagePanel) { imagePanel.setImage(srcImage, srcImageBlurred); repaint(); @@ -139,12 +157,13 @@ public class CardPanel extends JPanel implements CardContainer { * * @param panel a {@link arcane.ui.CardPanel} object. */ - public void setImage(final CardPanel panel) { + public final void setImage(final CardPanel panel) { synchronized (panel.imagePanel) { - if (panel.imagePanel.hasImage()) + if (panel.imagePanel.hasImage()) { setImage(panel.imagePanel.srcImage, panel.imagePanel.srcImageBlurred); - else + } else { panel.imageLoadListeners.add(this); + } } } @@ -153,7 +172,7 @@ public class CardPanel extends JPanel implements CardContainer { * * @param scalingType a {@link arcane.ui.ScaledImagePanel.ScalingType} object. */ - public void setScalingType(ScalingType scalingType) { + public final void setScalingType(final ScalingType scalingType) { imagePanel.setScalingType(scalingType); } @@ -162,7 +181,7 @@ public class CardPanel extends JPanel implements CardContainer { * * @param displayEnabled a boolean. */ - public void setDisplayEnabled(boolean displayEnabled) { + public final void setDisplayEnabled(final boolean displayEnabled) { this.displayEnabled = displayEnabled; } @@ -171,7 +190,7 @@ public class CardPanel extends JPanel implements CardContainer { * * @return a boolean. */ - public boolean isDisplayEnabled() { + public final boolean isDisplayEnabled() { return displayEnabled; } @@ -180,7 +199,7 @@ public class CardPanel extends JPanel implements CardContainer { * * @param isAnimationPanel a boolean. */ - public void setAnimationPanel(boolean isAnimationPanel) { + public final void setAnimationPanel(final boolean isAnimationPanel) { this.isAnimationPanel = isAnimationPanel; } @@ -189,7 +208,7 @@ public class CardPanel extends JPanel implements CardContainer { * * @param isSelected a boolean. */ - public void setSelected(boolean isSelected) { + public final void setSelected(final boolean isSelected) { this.isSelected = isSelected; repaint(); } @@ -199,14 +218,18 @@ public class CardPanel extends JPanel implements CardContainer { * * @param showCastingCost a boolean. */ - public void setShowCastingCost(boolean showCastingCost) { + public final void setShowCastingCost(final boolean showCastingCost) { this.showCastingCost = showCastingCost; } /** {@inheritDoc} */ - public void paint(Graphics g) { - if (!displayEnabled) return; - if (!isValid()) super.validate(); + public final void paint(final Graphics g) { + if (!displayEnabled) { + return; + } + if (!isValid()) { + super.validate(); + } Graphics2D g2d = (Graphics2D) g; if (tappedAngle > 0) { g2d = (Graphics2D) g2d.create(); @@ -217,7 +240,7 @@ public class CardPanel extends JPanel implements CardContainer { } /** {@inheritDoc} */ - protected void paintComponent(Graphics g) { + protected final void paintComponent(final Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); @@ -226,24 +249,27 @@ public class CardPanel extends JPanel implements CardContainer { if (this.gameCard != null) { if ((!this.gameCard.getImageFilename().equals("none")) && (!this.gameCard.getName().equals("Morph"))) { - if ((this.gameCard.getCurSetCode().equals("2ED")) || - (this.gameCard.getCurSetCode().equals("3ED")) || - (this.gameCard.getCurSetCode().equals("4ED")) || - (this.gameCard.getCurSetCode().equals("5ED")) || - (this.gameCard.getCurSetCode().equals("6ED")) || - (this.gameCard.getCurSetCode().equals("7ED")) || - (this.gameCard.getCurSetCode().equals("8ED")) || - (this.gameCard.getCurSetCode().equals("9ED")) || - (this.gameCard.getCurSetCode().equals("CHR")) || - (this.gameCard.getCurSetCode().equals("S99")) || - (this.gameCard.getCurSetCode().equals("PTK")) || - (this.gameCard.getCurSetCode().equals("S00"))) { + if ((this.gameCard.getCurSetCode().equals("2ED")) + || (this.gameCard.getCurSetCode().equals("3ED")) + || (this.gameCard.getCurSetCode().equals("4ED")) + || (this.gameCard.getCurSetCode().equals("5ED")) + || (this.gameCard.getCurSetCode().equals("6ED")) + || (this.gameCard.getCurSetCode().equals("7ED")) + || (this.gameCard.getCurSetCode().equals("8ED")) + || (this.gameCard.getCurSetCode().equals("9ED")) + || (this.gameCard.getCurSetCode().equals("CHR")) + || (this.gameCard.getCurSetCode().equals("S99")) + || (this.gameCard.getCurSetCode().equals("PTK")) + || (this.gameCard.getCurSetCode().equals("S00"))) + { if (!isSelected) { g2d.setColor(Color.black); int offset = tapped ? 1 : 0; - for (int i = 1, n = Math.max(1, Math.round(cardWidth * SELECTED_BORDER_SIZE)); i <= n; i++) - g2d.drawRoundRect(cardXOffset - i, cardYOffset - i + offset, cardWidth + i * 2 - 1, cardHeight + i * 2 - 1, + for (int i = 1, n = Math.max(1, Math.round(cardWidth * SELECTED_BORDER_SIZE)); i <= n; i++) { + g2d.drawRoundRect(cardXOffset - i, cardYOffset - i + offset, + cardWidth + i * 2 - 1, cardHeight + i * 2 - 1, cornerSize, cornerSize); + } } g2d.setColor(Color.white); } else { @@ -257,71 +283,88 @@ public class CardPanel extends JPanel implements CardContainer { if (isSelected) { g2d.setColor(Color.green); int offset = tapped ? 1 : 0; - for (int i = 1, n = Math.max(1, Math.round(cardWidth * SELECTED_BORDER_SIZE)); i <= n; i++) - g2d.drawRoundRect(cardXOffset - i, cardYOffset - i + offset, cardWidth + i * 2 - 1, cardHeight + i * 2 - 1, + for (int i = 1, n = Math.max(1, Math.round(cardWidth * SELECTED_BORDER_SIZE)); i <= n; i++) { + g2d.drawRoundRect(cardXOffset - i, cardYOffset - i + offset, + cardWidth + i * 2 - 1, cardHeight + i * 2 - 1, cornerSize, cornerSize); + } } } /** {@inheritDoc} */ - protected void paintChildren(Graphics g) { + protected final void paintChildren(final Graphics g) { super.paintChildren(g); - + boolean canDrawOverCard = showCastingCost && !isAnimationPanel; - - if (!canDrawOverCard) + + if (!canDrawOverCard) { return; - + } + int width = ManaSymbols.getWidth(gameCard.getManaCost()); - if(cardWidth < 200) - ManaSymbols.draw(g, gameCard.getManaCost(), cardXOffset + cardWidth / 2 - width / 2, cardYOffset + cardHeight / 2); - + if (cardWidth < 200) { + ManaSymbols.draw(g, gameCard.getManaCost(), + cardXOffset + cardWidth / 2 - width / 2, cardYOffset + cardHeight / 2); + } + int counters = getCard().getNumberOfCounters(); - if(counters == 1) { - ManaSymbols.drawSymbol("counters1", g, cardXOffset - 15, cardYOffset + cardHeight - (cardHeight / 3) - 40); - } else if(counters == 2) { - ManaSymbols.drawSymbol("counters2", g, cardXOffset - 15, cardYOffset + cardHeight - (cardHeight / 3) - 40); - } else if(counters == 3) { - ManaSymbols.drawSymbol("counters3", g, cardXOffset - 15, cardYOffset + cardHeight - (cardHeight / 3) - 40); - } else if(counters > 3) { - ManaSymbols.drawSymbol("countersMulti", g, cardXOffset - 15, cardYOffset + cardHeight - (cardHeight / 3) - 40); + if (counters == 1) { + ManaSymbols.drawSymbol("counters1", g, cardXOffset - 15, + cardYOffset + cardHeight - (cardHeight / 3) - 40); + } else if (counters == 2) { + ManaSymbols.drawSymbol("counters2", g, cardXOffset - 15, + cardYOffset + cardHeight - (cardHeight / 3) - 40); + } else if (counters == 3) { + ManaSymbols.drawSymbol("counters3", g, cardXOffset - 15, + cardYOffset + cardHeight - (cardHeight / 3) - 40); + } else if (counters > 3) { + ManaSymbols.drawSymbol("countersMulti", g, cardXOffset - 15, + cardYOffset + cardHeight - (cardHeight / 3) - 40); } //int yOff = (cardHeight/4) + 2; if (getCard().isAttacking()) { - ManaSymbols.drawSymbol("attack", g, cardXOffset + cardWidth / 4 - 16, cardYOffset + cardHeight - (cardHeight / 8) - 16); + ManaSymbols.drawSymbol("attack", g, cardXOffset + cardWidth / 4 - 16, + cardYOffset + cardHeight - (cardHeight / 8) - 16); } else if (getCard().isBlocking()) { - ManaSymbols.drawSymbol("defend", g, cardXOffset + cardWidth / 4 - 16, cardYOffset + cardHeight - (cardHeight / 8) - 16); + ManaSymbols.drawSymbol("defend", g, cardXOffset + cardWidth / 4 - 16, + cardYOffset + cardHeight - (cardHeight / 8) - 16); + } + + if (getCard().isCreature() && getCard().hasSickness() && AllZoneUtil.isCardInPlay(getCard())) { + ManaSymbols.drawSymbol("summonsick", g, cardXOffset + cardWidth / 2 - 16, + cardYOffset + cardHeight - (cardHeight / 8) - 16); + } + + if (getCard().isPhasedOut()) { + ManaSymbols.drawSymbol("phasing", g, cardXOffset + cardWidth / 2 - 16, + cardYOffset + cardHeight - (cardHeight / 8) - 16); } - if (getCard().isCreature() && getCard().hasSickness() && AllZoneUtil.isCardInPlay(getCard())) - ManaSymbols.drawSymbol("summonsick", g, cardXOffset + cardWidth / 2 - 16, cardYOffset + cardHeight - (cardHeight / 8) - 16); - - if (getCard().isPhasedOut()) - ManaSymbols.drawSymbol("phasing", g, cardXOffset + cardWidth / 2 - 16, cardYOffset + cardHeight - (cardHeight / 8) - 16); - if (getCard() != null) { if (this.gameCard.getFoil() > 0) { - String fl = String.format("foil%02d", getCard().getFoil()); - int z = Math.round(cardWidth * BLACK_BORDER_SIZE); - ManaSymbols.draw(g, fl, cardXOffset + z, cardYOffset + z, cardWidth - (2*z), cardHeight - (2*z)); + String fl = String.format("foil%02d", getCard().getFoil()); + int z = Math.round(cardWidth * BLACK_BORDER_SIZE); + ManaSymbols.draw(g, fl, cardXOffset + z, cardYOffset + z, cardWidth - (2 * z), cardHeight - (2 * z)); } - + if (getCard().getName().equals("Mana Pool") && !isAnimationPanel) { if (AllZone.getHumanPlayer().getManaPool() != null) { String s = AllZone.getHumanPlayer().getManaPool().getManaList(); if (!s.equals("|||||||||||")) { - String mList[] = s.split("\\|", 12); + String[] mList = s.split("\\|", 12); int n = 0; for (int i = 0; i < 2; i++) { for (int j = 0; j < 6; j++) { if (!mList[n].equals("")) { width = ManaSymbols.getWidth(mList[n]); - ManaSymbols.draw(g, mList[n], cardXOffset + ((i + 1) * (cardWidth / 3)) - width / 2, cardYOffset + ((j + 1) * (cardHeight / 7))); + ManaSymbols.draw(g, mList[n], + cardXOffset + ((i + 1) * (cardWidth / 3)) - width / 2, + cardYOffset + ((j + 1) * (cardHeight / 7))); } n++; @@ -338,7 +381,7 @@ public class CardPanel extends JPanel implements CardContainer { * * @since 1.0.15 */ - public void doLayout() { + public final void doLayout() { int borderSize = Math.round(cardWidth * BLACK_BORDER_SIZE); imagePanel.setLocation(cardXOffset + borderSize, cardYOffset + borderSize); imagePanel.setSize(cardWidth - borderSize * 2, cardHeight - borderSize * 2); @@ -358,10 +401,11 @@ public class CardPanel extends JPanel implements CardContainer { int ptY = Math.round(cardHeight * (675f / 680)) - ptSize.height; ptText.setLocation(cardXOffset + ptX - TEXT_GLOW_SIZE / 2, cardYOffset + ptY - TEXT_GLOW_SIZE / 2); - if (isAnimationPanel || cardWidth < 200) + if (isAnimationPanel || cardWidth < 200) { imagePanel.setScalingType(ScalingType.nearestNeighbor); - else + } else { imagePanel.setScalingType(ScalingType.bilinear); + } } /** @@ -369,7 +413,7 @@ public class CardPanel extends JPanel implements CardContainer { * * @return a {@link java.lang.String} object. */ - public String toString() { + public final String toString() { return gameCard.getName(); } @@ -381,7 +425,7 @@ public class CardPanel extends JPanel implements CardContainer { * @param width a int. * @param height a int. */ - public void setCardBounds(int x, int y, int width, int height) { + public final void setCardBounds(final int x, final int y, int width, int height) { cardWidth = width; cardHeight = height; int rotCenterX = Math.round(width / 2f); @@ -400,10 +444,12 @@ public class CardPanel extends JPanel implements CardContainer { /** *

repaint.

*/ - public void repaint() { + public final void repaint() { Rectangle b = getBounds(); JRootPane rootPane = SwingUtilities.getRootPane(this); - if (rootPane == null) return; + if (rootPane == null) { + return; + } Point p = SwingUtilities.convertPoint(getParent(), b.x, b.y, rootPane); rootPane.repaint(p.x, p.y, b.width, b.height); } @@ -413,7 +459,7 @@ public class CardPanel extends JPanel implements CardContainer { * * @return a int. */ - public int getCardX() { + public final int getCardX() { return getX() + cardXOffset; } @@ -422,7 +468,7 @@ public class CardPanel extends JPanel implements CardContainer { * * @return a int. */ - public int getCardY() { + public final int getCardY() { return getY() + cardYOffset; } @@ -431,7 +477,7 @@ public class CardPanel extends JPanel implements CardContainer { * * @return a int. */ - public int getCardWidth() { + public final int getCardWidth() { return cardWidth; } @@ -440,7 +486,7 @@ public class CardPanel extends JPanel implements CardContainer { * * @return a int. */ - public int getCardHeight() { + public final int getCardHeight() { return cardHeight; } @@ -449,7 +495,7 @@ public class CardPanel extends JPanel implements CardContainer { * * @return a {@link java.awt.Point} object. */ - public Point getCardLocation() { + public final Point getCardLocation() { Point p = getLocation(); p.x += cardXOffset; p.y += cardYOffset; @@ -461,10 +507,11 @@ public class CardPanel extends JPanel implements CardContainer { * * @param card a {@link forge.Card} object. */ - public void setText(Card card) { - if (card == null || !Singletons.getModel().getPreferences().cardOverlay) + public final void setText(final Card card) { + if (card == null || !Singletons.getModel().getPreferences().cardOverlay) { return; - + } + if (card.isFaceDown()) { titleText.setText(""); showCastingCost = false; @@ -474,7 +521,9 @@ public class CardPanel extends JPanel implements CardContainer { } if (card.isCreature() && card.isPlaneswalker()) { - ptText.setText(card.getNetAttack() + "/" + card.getNetDefense() + " (" + String.valueOf(card.getCounters(Counters.LOYALTY)) + ")"); + ptText.setText(card.getNetAttack() + "/" + + card.getNetDefense() + + " (" + String.valueOf(card.getCounters(Counters.LOYALTY)) + ")"); } else if (card.isCreature()) { ptText.setText(card.getNetAttack() + "/" + card.getNetDefense()); } else if (card.isPlaneswalker()) { @@ -489,15 +538,19 @@ public class CardPanel extends JPanel implements CardContainer { * * @return a {@link forge.Card} object. */ - public Card getCard() { + public final Card getCard() { return gameCard; } /** {@inheritDoc} */ - public void setCard(Card card) { - if (gameCard != null && gameCard.equals(card) && isAnimationPanel && imagePanel.hasImage()) return; + public final void setCard(final Card card) { + if (gameCard != null && gameCard.equals(card) && isAnimationPanel && imagePanel.hasImage()) { + return; + } this.gameCard = card; - if (!isShowing()) return; + if (!isShowing()) { + return; + } Insets i = getInsets(); Image image = card == null ? null : ImageCache.getImage(card, getWidth() - i.left - i.right, getHeight() - i.top - i.bottom); diff --git a/src/main/java/arcane/ui/CardPanelContainer.java b/src/main/java/arcane/ui/CardPanelContainer.java index 995752a2543..6642fa9b3c2 100644 --- a/src/main/java/arcane/ui/CardPanelContainer.java +++ b/src/main/java/arcane/ui/CardPanelContainer.java @@ -1,34 +1,51 @@ package arcane.ui; -import arcane.ui.util.CardPanelMouseListener; -import arcane.ui.util.UI; -import forge.Card; -import forge.Constant; - -import javax.swing.*; -import java.awt.*; +import java.awt.Dimension; +import java.awt.Rectangle; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import java.util.ArrayList; import java.util.List; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; + +import arcane.ui.util.CardPanelMouseListener; +import arcane.ui.util.UI; +import forge.Card; +import forge.Constant; + /** - * Manages mouse events and common funcitonality for CardPanel containing components. - * + * Manages mouse events and common functionality for CardPanel containing + * components. + * * @author Forge * @version $Id$ */ -abstract public class CardPanelContainer extends JPanel { - /** Constant serialVersionUID=-6400018234895548306L */ +public abstract class CardPanelContainer extends JPanel { + /** Constant serialVersionUID=-6400018234895548306L. */ private static final long serialVersionUID = -6400018234895548306L; - /** Constant DRAG_SMUDGE=10 */ - private final static int DRAG_SMUDGE = 10; + /** Constant DRAG_SMUDGE=10. */ + private static final int DRAG_SMUDGE = 10; + /** + * + */ public List cardPanels = new ArrayList(); + /** + * + */ protected JScrollPane scrollPane; + /** + * + */ protected int cardWidthMin = 50, cardWidthMax = Constant.Runtime.width[0]; + /** + * + */ protected CardPanel mouseOverPanel, mouseDownPanel, mouseDragPanel; private List listeners = new ArrayList(2); @@ -38,17 +55,20 @@ abstract public class CardPanelContainer extends JPanel { private int zoneID; /** - *

Constructor for CardPanelContainer.

- * - * @param scrollPane a {@link javax.swing.JScrollPane} object. + *

+ * Constructor for CardPanelContainer. + *

+ * + * @param scrollPane + * a {@link javax.swing.JScrollPane} object. */ - public CardPanelContainer(JScrollPane scrollPane) { + public CardPanelContainer(final JScrollPane scrollPane) { this.scrollPane = scrollPane; setOpaque(true); addMouseMotionListener(new MouseMotionListener() { - public void mouseDragged(MouseEvent evt) { + public void mouseDragged(final MouseEvent evt) { if (!dragEnabled) { mouseOutPanel(evt); return; @@ -60,15 +80,20 @@ abstract public class CardPanelContainer extends JPanel { int x = evt.getX(); int y = evt.getY(); CardPanel panel = getCardPanel(x, y); - if (panel == null) return; - if (panel != mouseDownPanel) return; + if (panel == null) { + return; + } + if (panel != mouseDownPanel) { + return; + } if (intialMouseDragX == -1) { intialMouseDragX = x; intialMouseDragY = y; return; } - if (Math.abs(x - intialMouseDragX) < DRAG_SMUDGE && Math.abs(y - intialMouseDragY) < DRAG_SMUDGE) + if (Math.abs(x - intialMouseDragX) < DRAG_SMUDGE && Math.abs(y - intialMouseDragY) < DRAG_SMUDGE) { return; + } mouseDownPanel = null; mouseDragPanel = panel; mouseDragOffsetX = panel.getX() - intialMouseDragX; @@ -76,10 +101,14 @@ abstract public class CardPanelContainer extends JPanel { CardPanelContainer.this.mouseDragStart(mouseDragPanel, evt); } - public void mouseMoved(MouseEvent evt) { + public void mouseMoved(final MouseEvent evt) { CardPanel panel = getCardPanel(evt.getX(), evt.getY()); - if (mouseOverPanel != null && mouseOverPanel != panel) CardPanelContainer.this.mouseOutPanel(evt); - if (panel == null) return; + if (mouseOverPanel != null && mouseOverPanel != panel) { + CardPanelContainer.this.mouseOutPanel(evt); + } + if (panel == null) { + return; + } mouseOverPanel = panel; mouseOverPanel.setSelected(true); CardPanelContainer.this.mouseOver(panel, evt); @@ -89,16 +118,20 @@ abstract public class CardPanelContainer extends JPanel { addMouseListener(new MouseAdapter() { private boolean[] buttonsDown = new boolean[4]; - public void mousePressed(MouseEvent evt) { + public void mousePressed(final MouseEvent evt) { int button = evt.getButton(); - if (button < 1 || button > 3) return; + if (button < 1 || button > 3) { + return; + } buttonsDown[button] = true; mouseDownPanel = getCardPanel(evt.getX(), evt.getY()); } - public void mouseReleased(MouseEvent evt) { + public void mouseReleased(final MouseEvent evt) { int button = evt.getButton(); - if (button < 1 || button > 3) return; + if (button < 1 || button > 3) { + return; + } if (dragEnabled) { intialMouseDragX = -1; @@ -109,7 +142,9 @@ abstract public class CardPanelContainer extends JPanel { } } - if (!buttonsDown[button]) return; + if (!buttonsDown[button]) { + return; + } buttonsDown[button] = false; CardPanel panel = getCardPanel(evt.getX(), evt.getY()); @@ -133,76 +168,95 @@ abstract public class CardPanelContainer extends JPanel { } } - public void mouseExited(MouseEvent evt) { + public void mouseExited(final MouseEvent evt) { mouseOutPanel(evt); } - public void mouseEntered(MouseEvent e) { + public void mouseEntered(final MouseEvent e) { } }); } /** - *

mouseOutPanel.

- * - * @param evt a {@link java.awt.event.MouseEvent} object. + *

+ * mouseOutPanel. + *

+ * + * @param evt + * a {@link java.awt.event.MouseEvent} object. */ - private void mouseOutPanel(MouseEvent evt) { - if (mouseOverPanel == null) return; + private void mouseOutPanel(final MouseEvent evt) { + if (mouseOverPanel == null) { + return; + } mouseOverPanel.setSelected(false); mouseOut(mouseOverPanel, evt); mouseOverPanel = null; } - /*public void resetDrag(){ - mouseDragPanel = null; - invalidate(); - };*/ + /* + * public void resetDrag(){ mouseDragPanel = null; invalidate(); }; + */ /** - *

getCardPanel.

- * - * @param x a int. - * @param y a int. + *

+ * getCardPanel. + *

+ * + * @param x + * a int. + * @param y + * a int. * @return a {@link arcane.ui.CardPanel} object. */ - abstract protected CardPanel getCardPanel(int x, int y); + protected abstract CardPanel getCardPanel(int x, int y); /** * Must call from the Swing event thread. - * - * @param card a {@link forge.Card} object. + * + * @param card + * a {@link forge.Card} object. * @return a {@link arcane.ui.CardPanel} object. */ - public CardPanel addCard(Card card) { + public final CardPanel addCard(final Card card) { final CardPanel placeholder = new CardPanel(card); placeholder.setDisplayEnabled(false); cardPanels.add(placeholder); add(placeholder); doLayout(); - // int y = Math.min(placeholder.getHeight(), scrollPane.getVisibleRect().height); - scrollRectToVisible(new Rectangle(placeholder.getCardX(), placeholder.getCardY(), placeholder.getCardWidth(), placeholder - .getCardHeight())); + // int y = Math.min(placeholder.getHeight(), + // scrollPane.getVisibleRect().height); + scrollRectToVisible(new Rectangle(placeholder.getCardX(), placeholder.getCardY(), placeholder.getCardWidth(), + placeholder.getCardHeight())); return placeholder; } /** - *

getCardPanel.

- * - * @param gameCardID a int. + *

+ * getCardPanel. + *

+ * + * @param gameCardID + * a int. * @return a {@link arcane.ui.CardPanel} object. */ - public CardPanel getCardPanel(int gameCardID) { - for (CardPanel panel : cardPanels) - if (panel.gameCard.getUniqueNumber() == gameCardID) return panel; + public final CardPanel getCardPanel(final int gameCardID) { + for (CardPanel panel : cardPanels) { + if (panel.gameCard.getUniqueNumber() == gameCardID) { + return panel; + } + } return null; } /** - *

removeCardPanel.

- * - * @param fromPanel a {@link arcane.ui.CardPanel} object. + *

+ * removeCardPanel. + *

+ * + * @param fromPanel + * a {@link arcane.ui.CardPanel} object. */ - public void removeCardPanel(final CardPanel fromPanel) { + public final void removeCardPanel(final CardPanel fromPanel) { UI.invokeAndWait(new Runnable() { public void run() { if (mouseDragPanel != null) { @@ -222,9 +276,11 @@ abstract public class CardPanelContainer extends JPanel { } /** - *

clear.

+ *

+ * clear. + *

*/ - public void clear() { + public final void clear() { UI.invokeAndWait(new Runnable() { public void run() { cardPanels.clear(); @@ -238,194 +294,265 @@ abstract public class CardPanelContainer extends JPanel { } /** - *

Getter for the field scrollPane.

- * + *

+ * Getter for the field scrollPane. + *

+ * * @return a {@link javax.swing.JScrollPane} object. */ - public JScrollPane getScrollPane() { + public final JScrollPane getScrollPane() { return scrollPane; } /** - *

Getter for the field cardWidthMin.

- * + *

+ * Getter for the field cardWidthMin. + *

+ * * @return a int. */ - public int getCardWidthMin() { + public final int getCardWidthMin() { return cardWidthMin; } /** - *

Setter for the field cardWidthMin.

- * - * @param cardWidthMin a int. + *

+ * Setter for the field cardWidthMin. + *

+ * + * @param cardWidthMin + * a int. */ - public void setCardWidthMin(int cardWidthMin) { + public final void setCardWidthMin(int cardWidthMin) { this.cardWidthMin = cardWidthMin; } /** - *

Getter for the field cardWidthMax.

- * + *

+ * Getter for the field cardWidthMax. + *

+ * * @return a int. */ - public int getCardWidthMax() { + public final int getCardWidthMax() { return cardWidthMax; } /** - *

Setter for the field cardWidthMax.

- * - * @param cardWidthMax a int. + *

+ * Setter for the field cardWidthMax. + *

+ * + * @param cardWidthMax + * a int. */ - public void setCardWidthMax(int cardWidthMax) { + public final void setCardWidthMax(int cardWidthMax) { this.cardWidthMax = cardWidthMax; } /** - *

isDragEnabled.

- * + *

+ * isDragEnabled. + *

+ * * @return a boolean. */ - public boolean isDragEnabled() { + public final boolean isDragEnabled() { return dragEnabled; } /** - *

Setter for the field dragEnabled.

- * - * @param dragEnabled a boolean. + *

+ * Setter for the field dragEnabled. + *

+ * + * @param dragEnabled + * a boolean. */ - public void setDragEnabled(boolean dragEnabled) { + public final void setDragEnabled(boolean dragEnabled) { this.dragEnabled = dragEnabled; } /** - *

addCardPanelMouseListener.

- * - * @param listener a {@link arcane.ui.util.CardPanelMouseListener} object. + *

+ * addCardPanelMouseListener. + *

+ * + * @param listener + * a {@link arcane.ui.util.CardPanelMouseListener} object. */ - public void addCardPanelMouseListener(CardPanelMouseListener listener) { + public final void addCardPanelMouseListener(final CardPanelMouseListener listener) { listeners.add(listener); } /** - *

mouseLeftClicked.

- * - * @param panel a {@link arcane.ui.CardPanel} object. - * @param evt a {@link java.awt.event.MouseEvent} object. + *

+ * mouseLeftClicked. + *

+ * + * @param panel + * a {@link arcane.ui.CardPanel} object. + * @param evt + * a {@link java.awt.event.MouseEvent} object. */ - public void mouseLeftClicked(CardPanel panel, MouseEvent evt) { - for (CardPanelMouseListener listener : listeners) + public void mouseLeftClicked(final CardPanel panel, final MouseEvent evt) { + for (CardPanelMouseListener listener : listeners) { listener.mouseLeftClicked(panel, evt); + } } /** - *

mouseRightClicked.

- * - * @param panel a {@link arcane.ui.CardPanel} object. - * @param evt a {@link java.awt.event.MouseEvent} object. + *

+ * mouseRightClicked. + *

+ * + * @param panel + * a {@link arcane.ui.CardPanel} object. + * @param evt + * a {@link java.awt.event.MouseEvent} object. */ - public void mouseRightClicked(CardPanel panel, MouseEvent evt) { - for (CardPanelMouseListener listener : listeners) + public final void mouseRightClicked(final CardPanel panel, final MouseEvent evt) { + for (CardPanelMouseListener listener : listeners) { listener.mouseRightClicked(panel, evt); + } } /** - *

mouseMiddleClicked.

- * - * @param panel a {@link arcane.ui.CardPanel} object. - * @param evt a {@link java.awt.event.MouseEvent} object. + *

+ * mouseMiddleClicked. + *

+ * + * @param panel + * a {@link arcane.ui.CardPanel} object. + * @param evt + * a {@link java.awt.event.MouseEvent} object. */ - public void mouseMiddleClicked(CardPanel panel, MouseEvent evt) { - for (CardPanelMouseListener listener : listeners) + public final void mouseMiddleClicked(final CardPanel panel, final MouseEvent evt) { + for (CardPanelMouseListener listener : listeners) { listener.mouseMiddleClicked(panel, evt); + } } /** - *

mouseDragEnd.

- * - * @param dragPanel a {@link arcane.ui.CardPanel} object. - * @param evt a {@link java.awt.event.MouseEvent} object. + *

+ * mouseDragEnd. + *

+ * + * @param dragPanel + * a {@link arcane.ui.CardPanel} object. + * @param evt + * a {@link java.awt.event.MouseEvent} object. */ - public void mouseDragEnd(CardPanel dragPanel, MouseEvent evt) { - for (CardPanelMouseListener listener : listeners) + public void mouseDragEnd(final CardPanel dragPanel, final MouseEvent evt) { + for (CardPanelMouseListener listener : listeners) { listener.mouseDragEnd(dragPanel, evt); + } } /** - *

mouseDragged.

- * - * @param dragPanel a {@link arcane.ui.CardPanel} object. - * @param dragOffsetX a int. - * @param dragOffsetY a int. - * @param evt a {@link java.awt.event.MouseEvent} object. + *

+ * mouseDragged. + *

+ * + * @param dragPanel + * a {@link arcane.ui.CardPanel} object. + * @param dragOffsetX + * a int. + * @param dragOffsetY + * a int. + * @param evt + * a {@link java.awt.event.MouseEvent} object. */ - public void mouseDragged(CardPanel dragPanel, int dragOffsetX, int dragOffsetY, MouseEvent evt) { - for (CardPanelMouseListener listener : listeners) + public void mouseDragged(final CardPanel dragPanel, final int dragOffsetX, final int dragOffsetY, + final MouseEvent evt) { + for (CardPanelMouseListener listener : listeners) { listener.mouseDragged(mouseDragPanel, mouseDragOffsetX, mouseDragOffsetY, evt); + } } /** - *

mouseDragStart.

- * - * @param dragPanel a {@link arcane.ui.CardPanel} object. - * @param evt a {@link java.awt.event.MouseEvent} object. + *

+ * mouseDragStart. + *

+ * + * @param dragPanel + * a {@link arcane.ui.CardPanel} object. + * @param evt + * a {@link java.awt.event.MouseEvent} object. */ - public void mouseDragStart(CardPanel dragPanel, MouseEvent evt) { - for (CardPanelMouseListener listener : listeners) + public void mouseDragStart(final CardPanel dragPanel, final MouseEvent evt) { + for (CardPanelMouseListener listener : listeners) { listener.mouseDragStart(mouseDragPanel, evt); + } } /** - *

mouseOut.

- * - * @param panel a {@link arcane.ui.CardPanel} object. - * @param evt a {@link java.awt.event.MouseEvent} object. + *

+ * mouseOut. + *

+ * + * @param panel + * a {@link arcane.ui.CardPanel} object. + * @param evt + * a {@link java.awt.event.MouseEvent} object. */ - public void mouseOut(CardPanel panel, MouseEvent evt) { - for (CardPanelMouseListener listener : listeners) + public final void mouseOut(final CardPanel panel, final MouseEvent evt) { + for (CardPanelMouseListener listener : listeners) { listener.mouseOut(mouseOverPanel, evt); + } } /** - *

mouseOver.

- * - * @param panel a {@link arcane.ui.CardPanel} object. - * @param evt a {@link java.awt.event.MouseEvent} object. + *

+ * mouseOver. + *

+ * + * @param panel + * a {@link arcane.ui.CardPanel} object. + * @param evt + * a {@link java.awt.event.MouseEvent} object. */ - public void mouseOver(CardPanel panel, MouseEvent evt) { - for (CardPanelMouseListener listener : listeners) + public final void mouseOver(final CardPanel panel, final MouseEvent evt) { + for (CardPanelMouseListener listener : listeners) { listener.mouseOver(panel, evt); + } } /** - *

getCardFromMouseOverPanel.

- * + *

+ * getCardFromMouseOverPanel. + *

+ * * @return a {@link forge.Card} object. */ - public Card getCardFromMouseOverPanel() { - if (mouseOverPanel != null) + public final Card getCardFromMouseOverPanel() { + if (mouseOverPanel != null) { return mouseOverPanel.gameCard; - else + } else { return null; + } } /** - *

Getter for the field zoneID.

- * + *

+ * Getter for the field zoneID. + *

+ * * @return a int. */ - public int getZoneID() { + public final int getZoneID() { return zoneID; } /** - *

Setter for the field zoneID.

- * - * @param zoneID a int. + *

+ * Setter for the field zoneID. + *

+ * + * @param zoneID + * a int. */ - public void setZoneID(int zoneID) { + public void setZoneID(final int zoneID) { this.zoneID = zoneID; } } diff --git a/src/main/java/arcane/ui/HandArea.java b/src/main/java/arcane/ui/HandArea.java index 1977031ac83..654bf156bdd 100644 --- a/src/main/java/arcane/ui/HandArea.java +++ b/src/main/java/arcane/ui/HandArea.java @@ -13,7 +13,7 @@ import java.awt.event.MouseEvent; * @version $Id$ */ public class HandArea extends CardArea { - /** Constant serialVersionUID=7488132628637407745L */ + /** Constant serialVersionUID=7488132628637407745L. */ private static final long serialVersionUID = 7488132628637407745L; /** @@ -22,36 +22,40 @@ public class HandArea extends CardArea { * @param scrollPane a {@link javax.swing.JScrollPane} object. * @param frame a {@link java.awt.Frame} object. */ - public HandArea(JScrollPane scrollPane, final Frame frame) { + public HandArea(final JScrollPane scrollPane, final Frame frame) { super(scrollPane); setDragEnabled(true); setVertical(true); addCardPanelMouseListener(new CardPanelMouseListener() { - public void mouseRightClicked(CardPanel panel, MouseEvent evt) { + public void mouseRightClicked(final CardPanel panel, final MouseEvent evt) { } - public void mouseOver(CardPanel panel, MouseEvent evt) { + public void mouseOver(final CardPanel panel, final MouseEvent evt) { } - public void mouseOut(CardPanel panel, MouseEvent evt) { + public void mouseOut(final CardPanel panel, final MouseEvent evt) { } - public void mouseMiddleClicked(CardPanel panel, MouseEvent evt) { + public void mouseMiddleClicked(final CardPanel panel, final MouseEvent evt) { } - public void mouseLeftClicked(CardPanel panel, MouseEvent evt) { + public void mouseLeftClicked(final CardPanel panel, final MouseEvent evt) { } - public void mouseDragged(CardPanel dragPanel, int dragOffsetX, int dragOffsetY, MouseEvent evt) { + public void mouseDragged(final CardPanel dragPanel, + final int dragOffsetX, + final int dragOffsetY, + final MouseEvent evt) + { } - public void mouseDragStart(CardPanel dragPanel, MouseEvent evt) { + public void mouseDragStart(final CardPanel dragPanel, final MouseEvent evt) { } - public void mouseDragEnd(CardPanel dragPanel, MouseEvent evt) { + public void mouseDragEnd(final CardPanel dragPanel, final MouseEvent evt) { } }); } diff --git a/src/main/java/arcane/ui/PlayArea.java b/src/main/java/arcane/ui/PlayArea.java index 81fe634fa5c..177dfc2871c 100644 --- a/src/main/java/arcane/ui/PlayArea.java +++ b/src/main/java/arcane/ui/PlayArea.java @@ -1,36 +1,41 @@ package arcane.ui; -import arcane.ui.util.CardPanelMouseListener; -import forge.Card; - -import javax.swing.*; -import java.awt.*; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Rectangle; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import javax.swing.JScrollPane; + +import arcane.ui.util.CardPanelMouseListener; +import forge.Card; + /** - *

PlayArea class.

- * + *

+ * PlayArea class. + *

+ * * @author Forge * @version $Id$ */ public class PlayArea extends CardPanelContainer implements CardPanelMouseListener { - /** Constant serialVersionUID=8333013579724492513L */ + /** Constant serialVersionUID=8333013579724492513L. */ private static final long serialVersionUID = 8333013579724492513L; - /** Constant GUTTER_Y=5 */ - static private final int GUTTER_Y = 5; - /** Constant GUTTER_X=5 */ - static private final int GUTTER_X = 5; - /** Constant EXTRA_CARD_SPACING_X=0.04f */ + /** Constant GUTTER_Y=5. */ + private static final int GUTTER_Y = 5; + /** Constant GUTTER_X=5. */ + private static final int GUTTER_X = 5; + /** Constant EXTRA_CARD_SPACING_X=0.04f. */ static final float EXTRA_CARD_SPACING_X = 0.04f; - /** Constant CARD_SPACING_Y=0.06f */ - static private final float CARD_SPACING_Y = 0.06f; - /** Constant STACK_SPACING_X=0.07f */ - static private final float STACK_SPACING_X = 0.07f; - /** Constant STACK_SPACING_Y=0.07f */ - static private final float STACK_SPACING_Y = 0.07f; + /** Constant CARD_SPACING_Y=0.06f. */ + private static final float CARD_SPACING_Y = 0.06f; + /** Constant STACK_SPACING_X=0.07f. */ + private static final float STACK_SPACING_X = 0.07f; + /** Constant STACK_SPACING_Y=0.07f. */ + private static final float STACK_SPACING_Y = 0.07f; private int landStackMax = 5; @@ -45,20 +50,26 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen private int stackSpacingX, stackSpacingY; /** - *

Constructor for PlayArea.

- * - * @param scrollPane a {@link javax.swing.JScrollPane} object. - * @param mirror a boolean. + *

+ * Constructor for PlayArea. + *

+ * + * @param scrollPane + * a {@link javax.swing.JScrollPane} object. + * @param mirror + * a boolean. */ - public PlayArea(JScrollPane scrollPane, boolean mirror) { + public PlayArea(final JScrollPane scrollPane, final boolean mirror) { super(scrollPane); setBackground(Color.white); this.mirror = mirror; } /** - *

doLayout.

- * + *

+ * doLayout. + *

+ * * @since 1.0.15 */ public void doLayout() { @@ -68,7 +79,9 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen outerLoop: // for (CardPanel panel : cardPanels) { - if (!panel.gameCard.isLand() || panel.gameCard.isCreature()) continue; + if (!panel.gameCard.isLand() || panel.gameCard.isCreature()) { + continue; + } int insertIndex = -1; @@ -76,15 +89,18 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen for (int i = 0, n = allLands.size(); i < n; i++) { Stack stack = allLands.get(i); CardPanel firstPanel = stack.get(0); - if (firstPanel.gameCard.getName().equals(panel.gameCard.getName()) ) { + if (firstPanel.gameCard.getName().equals(panel.gameCard.getName())) { if (!firstPanel.attachedPanels.isEmpty() || firstPanel.gameCard.isEnchanted()) { - // Put this land to the left of lands with the same name and attachments. + // Put this land to the left of lands with the same name + // and attachments. insertIndex = i; break; } - if (!panel.attachedPanels.isEmpty() || !panel.gameCard.getCounters().equals(firstPanel.gameCard.getCounters()) + if (!panel.attachedPanels.isEmpty() + || !panel.gameCard.getCounters().equals(firstPanel.gameCard.getCounters()) || firstPanel.gameCard.isEnchanted() || stack.size() == landStackMax) { - // If this land has attachments or the stack is full, put it to the right. + // If this land has attachments or the stack is full, + // put it to the right. insertIndex = i + 1; continue; } @@ -92,7 +108,9 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen stack.add(0, panel); continue outerLoop; } - if (insertIndex != -1) break; + if (insertIndex != -1) { + break; + } } Stack stack = new Stack(); @@ -105,7 +123,9 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen outerLoop: // for (CardPanel panel : cardPanels) { - if (!panel.gameCard.isToken()) continue; + if (!panel.gameCard.isToken()) { + continue; + } int insertIndex = -1; @@ -115,16 +135,19 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen CardPanel firstPanel = stack.get(0); if (firstPanel.gameCard.getName().equals(panel.gameCard.getName())) { if (!firstPanel.attachedPanels.isEmpty()) { - // Put this token to the left of tokens with the same name and attachments. + // Put this token to the left of tokens with the same + // name and attachments. insertIndex = i; break; } - if (!panel.attachedPanels.isEmpty() || !panel.gameCard.getCounters().equals(firstPanel.gameCard.getCounters()) + if (!panel.attachedPanels.isEmpty() + || !panel.gameCard.getCounters().equals(firstPanel.gameCard.getCounters()) || panel.gameCard.isSick() != firstPanel.gameCard.isSick() || panel.gameCard.getNetAttack() != firstPanel.gameCard.getNetAttack() || panel.gameCard.getNetDefense() != firstPanel.gameCard.getNetDefense() || stack.size() == tokenStackMax) { - // If this token has attachments or the stack is full, put it to the right. + // If this token has attachments or the stack is full, + // put it to the right. insertIndex = i + 1; continue; } @@ -132,7 +155,9 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen stack.add(0, panel); continue outerLoop; } - if (insertIndex != -1) break; + if (insertIndex != -1) { + break; + } } Stack stack = new Stack(); @@ -175,22 +200,30 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen } // Store the current rows and others. List storedRows = new ArrayList(rows.size()); - for (Row row : rows) + for (Row row : rows) { storedRows.add((Row) row.clone()); + } Row storedOthers = (Row) others.clone(); // Fill in all rows with others. - for (Row row : rows) + for (Row row : rows) { fillRow(others, rows, row); - // Stop if everything fits, otherwise revert back to the stored values. - if (creatures.isEmpty() && tokens.isEmpty() && lands.isEmpty() && others.isEmpty()) break; + } + // Stop if everything fits, otherwise revert back to the stored + // values. + if (creatures.isEmpty() && tokens.isEmpty() && lands.isEmpty() && others.isEmpty()) { + break; + } rows = storedRows; others = storedOthers; // Try to put others on their own row(s) and fill in the rest. wrap(others, rows, afterFirstRow); - for (Row row : rows) + for (Row row : rows) { fillRow(others, rows, row); + } // If that still doesn't fit, scale down. - if (creatures.isEmpty() && tokens.isEmpty() && lands.isEmpty() && others.isEmpty()) break; + if (creatures.isEmpty() && tokens.isEmpty() && lands.isEmpty() && others.isEmpty()) { + break; + } cardWidth--; } @@ -222,8 +255,9 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen // Align others to the right. if (RowType.other.isType(stack.get(0).gameCard)) { x = playAreaWidth - GUTTER_X + extraCardSpacingX; - for (int i = stackIndex, n = row.size(); i < n; i++) + for (int i = stackIndex, n = row.size(); i < n; i++) { x -= row.get(i).getWidth(); + } } for (int panelIndex = 0, panelCount = stack.size(); panelIndex < panelCount; panelIndex++) { CardPanel panel = stack.get(panelIndex); @@ -241,15 +275,21 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen } /** - *

wrap.

- * - * @param sourceRow a {@link arcane.ui.PlayArea.Row} object. - * @param rows a {@link java.util.List} object. - * @param insertIndex a int. + *

+ * wrap. + *

+ * + * @param sourceRow + * a {@link arcane.ui.PlayArea.Row} object. + * @param rows + * a {@link java.util.List} object. + * @param insertIndex + * a int. * @return a int. */ - private int wrap(Row sourceRow, List rows, int insertIndex) { - // The cards are sure to fit (with vertical scrolling) at the minimum card width. + private int wrap(final Row sourceRow, final List rows, final int insertIndex) { + // The cards are sure to fit (with vertical scrolling) at the minimum + // card width. boolean allowHeightOverflow = cardWidth == cardWidthMin; Row currentRow = new Row(); @@ -259,8 +299,12 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen int rowWidth = currentRow.getWidth(); if (!currentRow.isEmpty() && rowWidth + stack.getWidth() > playAreaWidth) { // Stop processing if the row is too wide or tall. - if (!allowHeightOverflow && rowWidth > playAreaWidth) break; - if (!allowHeightOverflow && getRowsHeight(rows) + sourceRow.getHeight() > playAreaHeight) break; + if (!allowHeightOverflow && rowWidth > playAreaWidth) { + break; + } + if (!allowHeightOverflow && getRowsHeight(rows) + sourceRow.getHeight() > playAreaHeight) { + break; + } rows.add(insertIndex == -1 ? rows.size() : insertIndex, currentRow); currentRow = new Row(); } @@ -276,48 +320,64 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen } } // Remove the wrapped stacks from the source row. - for (Row row : rows) - for (Stack stack : row) + for (Row row : rows) { + for (Stack stack : row) { sourceRow.remove(stack); + } + } return insertIndex; } /** - *

fillRow.

- * - * @param sourceRow a {@link arcane.ui.PlayArea.Row} object. - * @param rows a {@link java.util.List} object. - * @param rows a {@link java.util.List} object. - * @param row a {@link arcane.ui.PlayArea.Row} object. + *

+ * fillRow. + *

+ * + * @param sourceRow + * a {@link arcane.ui.PlayArea.Row} object. + * @param rows + * a {@link java.util.List} object. + * @param rows + * a {@link java.util.List} object. + * @param row + * a {@link arcane.ui.PlayArea.Row} object. */ - private void fillRow(Row sourceRow, List rows, Row row) { + private void fillRow(final Row sourceRow, final List rows, Row row) { int rowWidth = row.getWidth(); while (!sourceRow.isEmpty()) { Stack stack = sourceRow.get(0); rowWidth += stack.getWidth(); - if (rowWidth > playAreaWidth) break; + if (rowWidth > playAreaWidth) { + break; + } if (stack.getHeight() > row.getHeight()) { - if (getRowsHeight(rows) - row.getHeight() + stack.getHeight() > playAreaHeight) break; + if (getRowsHeight(rows) - row.getHeight() + stack.getHeight() > playAreaHeight) { + break; + } } row.add(sourceRow.remove(0)); } } /** - *

getRowsHeight.

- * - * @param rows a {@link java.util.List} object. + *

+ * getRowsHeight. + *

+ * + * @param rows + * a {@link java.util.List} object. * @return a int. */ private int getRowsHeight(List rows) { int height = 0; - for (Row row : rows) + for (Row row : rows) { height += row.getHeight(); + } return height - cardSpacingY + GUTTER_Y * 2; } /** {@inheritDoc} */ - public CardPanel getCardPanel(int x, int y) { + public final CardPanel getCardPanel(final int x, final int y) { for (Row row : rows) { for (Stack stack : row) { for (CardPanel panel : stack) { @@ -334,7 +394,9 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen } if (x > panelX && x < panelX + panelWidth) { if (y > panelY && y < panelY + panelHeight) { - if (!panel.isDisplayEnabled()) return null; + if (!panel.isDisplayEnabled()) { + return null; + } return panel; } } @@ -345,62 +407,74 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen } /** {@inheritDoc} */ - public void mouseLeftClicked(CardPanel panel, MouseEvent evt) { - if (panel.tappedAngle != 0 && panel.tappedAngle != CardPanel.TAPPED_ANGLE) return; + public final void mouseLeftClicked(final CardPanel panel, final MouseEvent evt) { + if (panel.tappedAngle != 0 && panel.tappedAngle != CardPanel.TAPPED_ANGLE) { + return; + } super.mouseLeftClicked(panel, evt); } /** - *

Getter for the field landStackMax.

- * + *

+ * Getter for the field landStackMax. + *

+ * * @return a int. */ - public int getLandStackMax() { + public final int getLandStackMax() { return landStackMax; } /** - *

Setter for the field landStackMax.

- * - * @param landStackMax a int. + *

+ * Setter for the field landStackMax. + *

+ * + * @param landStackMax + * a int. */ - public void setLandStackMax(int landStackMax) { + public final void setLandStackMax(int landStackMax) { this.landStackMax = landStackMax; } /** - *

Getter for the field stackVertical.

- * + *

+ * Getter for the field stackVertical. + *

+ * * @return a boolean. */ - public boolean getStackVertical() { + public final boolean getStackVertical() { return stackVertical; } /** - *

Setter for the field stackVertical.

- * - * @param stackVertical a boolean. + *

+ * Setter for the field stackVertical. + *

+ * + * @param stackVertical + * a boolean. */ - public void setStackVertical(boolean stackVertical) { + public final void setStackVertical(boolean stackVertical) { this.stackVertical = stackVertical; } - static private enum RowType { + private static enum RowType { land, creature, creatureNonToken, other; - public boolean isType(Card card) { + public boolean isType(final Card card) { switch (this) { - case land: - return card.isLand(); - case creature: - return card.isCreature(); - case creatureNonToken: - return card.isCreature() && !card.isToken(); - case other: - return !card.isLand() && !card.isCreature(); - default: - throw new RuntimeException("Unhandled type: " + this); + case land: + return card.isLand(); + case creature: + return card.isCreature(); + case creatureNonToken: + return card.isCreature() && !card.isToken(); + case other: + return !card.isLand() && !card.isCreature(); + default: + throw new RuntimeException("Unhandled type: " + this); } } } @@ -412,39 +486,47 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen super(16); } - public Row(List cardPanels, RowType type) { + public Row(final List cardPanels, final RowType type) { this(); addAll(cardPanels, type); } - private void addAll(List cardPanels, RowType type) { + private void addAll(final List cardPanels, final RowType type) { for (CardPanel panel : cardPanels) { - if (!type.isType(panel.gameCard) || panel.attachedToPanel != null) continue; + if (!type.isType(panel.gameCard) || panel.attachedToPanel != null) { + continue; + } Stack stack = new Stack(); stack.add(panel); add(stack); } } - public boolean addAll(Collection c) { + public boolean addAll(final Collection c) { boolean changed = super.addAll(c); c.clear(); return changed; } private int getWidth() { - if (isEmpty()) return 0; + if (isEmpty()) { + return 0; + } int width = 0; - for (Stack stack : this) + for (Stack stack : this) { width += stack.getWidth(); + } return width + GUTTER_X * 2 - extraCardSpacingX; } private int getHeight() { - if (isEmpty()) return 0; + if (isEmpty()) { + return 0; + } int height = 0; - for (Stack stack : this) + for (Stack stack : this) { height = Math.max(height, stack.getHeight()); + } return height; } } @@ -456,10 +538,11 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen super(8); } - public boolean add(CardPanel panel) { + public boolean add(final CardPanel panel) { boolean appended = super.add(panel); - for (CardPanel attachedPanel : panel.attachedPanels) + for (CardPanel attachedPanel : panel.attachedPanels) { add(attachedPanel); + } return appended; } diff --git a/src/main/java/arcane/ui/ScaledImagePanel.java b/src/main/java/arcane/ui/ScaledImagePanel.java index b3a4757a157..06c286e1bd2 100644 --- a/src/main/java/arcane/ui/ScaledImagePanel.java +++ b/src/main/java/arcane/ui/ScaledImagePanel.java @@ -1,9 +1,13 @@ package arcane.ui; -import javax.swing.*; -import java.awt.*; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.RenderingHints; import java.awt.image.BufferedImage; +import javax.swing.JPanel; + /** *

ScaledImagePanel class.

* @@ -12,9 +16,15 @@ import java.awt.image.BufferedImage; */ public class ScaledImagePanel extends JPanel { - /** Constant serialVersionUID=-5691107238620895385L */ + /** Constant serialVersionUID=-5691107238620895385L. */ private static final long serialVersionUID = -5691107238620895385L; + /** + * + */ public volatile Image srcImage; + /** + * + */ public volatile Image srcImageBlurred; private ScalingType scalingType = ScalingType.bilinear; @@ -37,7 +47,7 @@ public class ScaledImagePanel extends JPanel { * @param srcImageBlurred a {@link java.awt.Image} object. * */ - public void setImage(Image srcImage, Image srcImageBlurred) { + public final void setImage(final Image srcImage, Image srcImageBlurred) { this.srcImage = srcImage; this.srcImageBlurred = srcImageBlurred; } @@ -45,7 +55,7 @@ public class ScaledImagePanel extends JPanel { /** *

clearImage.

*/ - public void clearImage() { + public final void clearImage() { srcImage = null; srcImageBlurred = null; repaint(); @@ -56,7 +66,7 @@ public class ScaledImagePanel extends JPanel { * * @param multiPassType a {@link arcane.ui.ScaledImagePanel.MultipassType} object. */ - public void setScalingMultiPassType(MultipassType multiPassType) { + public final void setScalingMultiPassType(final MultipassType multiPassType) { this.multiPassType = multiPassType; } @@ -65,7 +75,7 @@ public class ScaledImagePanel extends JPanel { * * @param scalingType a {@link arcane.ui.ScaledImagePanel.ScalingType} object. */ - public void setScalingType(ScalingType scalingType) { + public final void setScalingType(final ScalingType scalingType) { this.scalingType = scalingType; } @@ -74,7 +84,7 @@ public class ScaledImagePanel extends JPanel { * * @param blur a boolean. */ - public void setScalingBlur(boolean blur) { + public final void setScalingBlur(final boolean blur) { this.blur = blur; } @@ -83,7 +93,7 @@ public class ScaledImagePanel extends JPanel { * * @param scaleLarger a boolean. */ - public void setScaleLarger(boolean scaleLarger) { + public final void setScaleLarger(final boolean scaleLarger) { this.scaleLarger = scaleLarger; } @@ -92,7 +102,7 @@ public class ScaledImagePanel extends JPanel { * * @return a boolean. */ - public boolean hasImage() { + public final boolean hasImage() { return srcImage != null; } @@ -113,8 +123,9 @@ public class ScaledImagePanel extends JPanel { if (targetWidth > panelWidth) { targetHeight = Math.round(panelWidth * (srcHeight / (float) srcWidth)); targetWidth = panelWidth; - } else + } else { targetHeight = panelHeight; + } } ScalingInfo info = new ScalingInfo(); info.targetWidth = targetWidth; @@ -127,8 +138,10 @@ public class ScaledImagePanel extends JPanel { } /** {@inheritDoc} */ - public void paint(Graphics g) { - if (srcImage == null) return; + public final void paint(final Graphics g) { + if (srcImage == null) { + return; + } Graphics2D g2 = (Graphics2D) g.create(); ScalingInfo info = getScalingInfo(); @@ -149,6 +162,8 @@ public class ScaledImagePanel extends JPanel { case replicate: scaleWithGetScaledInstance(g2, info, Image.SCALE_REPLICATE); break; + default: + break; } } @@ -159,7 +174,7 @@ public class ScaledImagePanel extends JPanel { * @param info a {@link arcane.ui.ScaledImagePanel.ScalingInfo} object. * @param hints a int. */ - private void scaleWithGetScaledInstance(Graphics2D g2, ScalingInfo info, int hints) { + private void scaleWithGetScaledInstance(final Graphics2D g2, final ScalingInfo info, final int hints) { Image srcImage = getSourceImage(info); Image scaledImage = srcImage.getScaledInstance(info.targetWidth, info.targetHeight, hints); g2.drawImage(scaledImage, info.x, info.y, null); @@ -172,17 +187,24 @@ public class ScaledImagePanel extends JPanel { * @param info a {@link arcane.ui.ScaledImagePanel.ScalingInfo} object. * @param hint a {@link java.lang.Object} object. */ - private void scaleWithDrawImage(Graphics2D g2, ScalingInfo info, Object hint) { + private void scaleWithDrawImage(final Graphics2D g2, final ScalingInfo info, final Object hint) { g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint); int tempDestWidth = info.srcWidth / 2, tempDestHeight = info.srcHeight / 2; - if (tempDestWidth < info.targetWidth) tempDestWidth = info.targetWidth; - if (tempDestHeight < info.targetHeight) tempDestHeight = info.targetHeight; + if (tempDestWidth < info.targetWidth) { + tempDestWidth = info.targetWidth; + } + if (tempDestHeight < info.targetHeight) { + tempDestHeight = info.targetHeight; + } Image srcImage = getSourceImage(info); - // If not doing multipass or multipass only needs a single pass, just scale it once directly to the panel surface. - if (multiPassType == MultipassType.none || (tempDestWidth == info.targetWidth && tempDestHeight == info.targetHeight)) { + // If not doing multipass or multipass only needs a single pass, + // just scale it once directly to the panel surface. + if (multiPassType == MultipassType.none + || (tempDestWidth == info.targetWidth && tempDestHeight == info.targetHeight)) + { g2.drawImage(srcImage, info.x, info.y, info.targetWidth, info.targetHeight, null); return; } @@ -191,7 +213,8 @@ public class ScaledImagePanel extends JPanel { Graphics2D g2temp = tempImage.createGraphics(); switch (multiPassType) { case nearestNeighbor: - g2temp.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); + g2temp.setRenderingHint(RenderingHints.KEY_INTERPOLATION, + RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); break; case bilinear: g2temp.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); @@ -199,6 +222,8 @@ public class ScaledImagePanel extends JPanel { case bicubic: g2temp.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); break; + default: + break; } // Render first pass from image to temp. g2temp.drawImage(srcImage, 0, 0, tempDestWidth, tempDestHeight, null); @@ -208,15 +233,21 @@ public class ScaledImagePanel extends JPanel { while (true) { if (tempDestWidth > info.targetWidth) { tempDestWidth = tempDestWidth / 2; - if (tempDestWidth < info.targetWidth) tempDestWidth = info.targetWidth; + if (tempDestWidth < info.targetWidth) { + tempDestWidth = info.targetWidth; + } } if (tempDestHeight > info.targetHeight) { tempDestHeight = tempDestHeight / 2; - if (tempDestHeight < info.targetHeight) tempDestHeight = info.targetHeight; + if (tempDestHeight < info.targetHeight) { + tempDestHeight = info.targetHeight; + } } - if (tempDestWidth == info.targetWidth && tempDestHeight == info.targetHeight) break; + if (tempDestWidth == info.targetWidth && tempDestHeight == info.targetHeight) { + break; + } g2temp.drawImage(tempImage, 0, 0, tempDestWidth, tempDestHeight, 0, 0, tempSrcWidth, tempSrcHeight, null); @@ -226,7 +257,10 @@ public class ScaledImagePanel extends JPanel { g2temp.dispose(); // Render last pass from temp to panel surface. g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint); - g2.drawImage(tempImage, info.x, info.y, info.x + info.targetWidth, info.y + info.targetHeight, 0, 0, tempSrcWidth, + g2.drawImage(tempImage, info.x, + info.y, + info.x + info.targetWidth, + info.y + info.targetHeight, 0, 0, tempSrcWidth, tempSrcHeight, null); } @@ -236,13 +270,17 @@ public class ScaledImagePanel extends JPanel { * @param info a {@link arcane.ui.ScaledImagePanel.ScalingInfo} object. * @return a {@link java.awt.Image} object. */ - private Image getSourceImage(ScalingInfo info) { - if (!blur || srcImageBlurred == null) return srcImage; - if (info.srcWidth / 2 < info.targetWidth || info.srcHeight / 2 < info.targetHeight) return srcImage; + private Image getSourceImage(final ScalingInfo info) { + if (!blur || srcImageBlurred == null) { + return srcImage; + } + if (info.srcWidth / 2 < info.targetWidth || info.srcHeight / 2 < info.targetHeight) { + return srcImage; + } return srcImageBlurred; } - static private class ScalingInfo { + private static class ScalingInfo { public int targetWidth; public int targetHeight; public int srcWidth; @@ -251,11 +289,55 @@ public class ScaledImagePanel extends JPanel { public int y; } - static public enum MultipassType { - none, nearestNeighbor, bilinear, bicubic + /** + * + * MultipassType. + * + */ + public static enum MultipassType { + /** + * + */ + none, + /** + * + */ + nearestNeighbor, + /** + * + */ + bilinear, + /** + * + */ + bicubic } - static public enum ScalingType { - nearestNeighbor, replicate, bilinear, bicubic, areaAveraging + /** + * + * ScalingType. + * + */ + public static enum ScalingType { + /** + * + */ + nearestNeighbor, + /** + * + */ + replicate, + /** + * + */ + bilinear, + /** + * + */ + bicubic, + /** + * + */ + areaAveraging } } diff --git a/src/main/java/arcane/ui/ViewPanel.java b/src/main/java/arcane/ui/ViewPanel.java index d9b032bde90..196bc799c63 100644 --- a/src/main/java/arcane/ui/ViewPanel.java +++ b/src/main/java/arcane/ui/ViewPanel.java @@ -1,7 +1,8 @@ package arcane.ui; -import javax.swing.*; -import java.awt.*; +import java.awt.BorderLayout; + +import javax.swing.JPanel; /** *

ViewPanel class.

@@ -10,7 +11,7 @@ import java.awt.*; * @version $Id$ */ public class ViewPanel extends JPanel { - /** Constant serialVersionUID=7016597023142963068L */ + /** Constant serialVersionUID=7016597023142963068L. */ private static final long serialVersionUID = 7016597023142963068L; /** @@ -18,8 +19,10 @@ public class ViewPanel extends JPanel { * * @since 1.0.15 */ - public void doLayout() { - if (getComponentCount() == 0) return; + public final void doLayout() { + if (getComponentCount() == 0) { + return; + } CardPanel panel = (CardPanel) getComponent(0); int viewWidth = getWidth(); int viewHeight = getHeight(); @@ -30,8 +33,9 @@ public class ViewPanel extends JPanel { if (targetWidth > viewWidth) { targetHeight = Math.round(viewWidth * (srcHeight / (float) srcWidth)); targetWidth = viewWidth; - } else + } else { targetHeight = viewHeight; + } int x = viewWidth / 2 - targetWidth / 2; int y = viewHeight / 2 - targetHeight / 2; panel.setCardBounds(x, y, targetWidth, targetHeight); @@ -42,7 +46,7 @@ public class ViewPanel extends JPanel { * * @param panel a {@link arcane.ui.CardPanel} object. */ - public void setCardPanel(CardPanel panel) { + public final void setCardPanel(final CardPanel panel) { //CardPanel newPanel = new CardPanel(panel.gameCard); //newPanel.setImage(panel); removeAll(); diff --git a/src/main/java/arcane/ui/package-info.java b/src/main/java/arcane/ui/package-info.java index a2cc46f07b7..a6d8339034e 100644 --- a/src/main/java/arcane/ui/package-info.java +++ b/src/main/java/arcane/ui/package-info.java @@ -1,2 +1,2 @@ -/** Forge Card Game */ +/** Forge Card Game. */ package arcane.ui; diff --git a/src/main/java/forge/item/ItemPoolView.java b/src/main/java/forge/item/ItemPoolView.java index 344974a41df..df0bb72de80 100644 --- a/src/main/java/forge/item/ItemPoolView.java +++ b/src/main/java/forge/item/ItemPoolView.java @@ -17,6 +17,7 @@ import net.slightlymagic.braids.util.lambda.Lambda1; * * @author Forge * @version $Id: CardPoolView.java 9708 2011-08-09 19:34:12Z jendave $ + * @param an InventoryItem */ public class ItemPoolView implements Iterable> {