checkstyle

This commit is contained in:
jendave
2011-10-25 15:41:36 +00:00
parent 942649e5a5
commit 5f3b16f4d0
13 changed files with 920 additions and 522 deletions

View File

@@ -17,13 +17,14 @@ import arcane.ui.util.Animation;
import arcane.ui.util.CardPanelMouseListener; import arcane.ui.util.CardPanelMouseListener;
/** /**
* <p>CardArea class.</p> * <p>
* * CardArea class.
* </p>
*
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class CardArea extends CardPanelContainer implements CardPanelMouseListener public class CardArea extends CardPanelContainer implements CardPanelMouseListener {
{
/** /**
* *
*/ */
@@ -65,9 +66,12 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen
private boolean hasScrollbars; private boolean hasScrollbars;
/** /**
* <p>Constructor for CardArea.</p> * <p>
* * Constructor for CardArea.
* @param scrollPane a {@link javax.swing.JScrollPane} object. * </p>
*
* @param scrollPane
* a {@link javax.swing.JScrollPane} object.
*/ */
public CardArea(final JScrollPane scrollPane) { public CardArea(final JScrollPane scrollPane) {
super(scrollPane); super(scrollPane);
@@ -113,8 +117,10 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen
} }
/** /**
* <p>doLayout.</p> * <p>
* * doLayout.
* </p>
*
* @since 1.0.15 * @since 1.0.15
*/ */
public final void doLayout() { public final void doLayout() {
@@ -141,16 +147,16 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen
cardHeight = Math.round(cardWidth * CardPanel.ASPECT_RATIO); cardHeight = Math.round(cardWidth * CardPanel.ASPECT_RATIO);
cardSpacingX = Math.round(cardWidth * VERT_CARD_SPACING_X); cardSpacingX = Math.round(cardWidth * VERT_CARD_SPACING_X);
cardSpacingY = cardHeight + Math.round(cardWidth * VERT_CARD_SPACING_Y); cardSpacingY = cardHeight + Math.round(cardWidth * VERT_CARD_SPACING_Y);
int maxRows = int maxRows = (int) Math.floor((cardAreaWidth - GUTTER_X * 2 + cardSpacingX)
(int) Math.floor((cardAreaWidth - GUTTER_X * 2 + cardSpacingX) / (cardWidth + cardSpacingX)); / (cardWidth + cardSpacingX));
if (this.maxRows > 0) { if (this.maxRows > 0) {
maxRows = Math.min(this.maxRows, maxRows); maxRows = Math.min(this.maxRows, maxRows);
} }
int availableRowHeight = cardAreaHeight - GUTTER_Y * 2; int availableRowHeight = cardAreaHeight - GUTTER_Y * 2;
int availableCardsPerRow = int availableCardsPerRow = (int) Math.floor((availableRowHeight - (cardHeight - cardSpacingY))
(int) Math.floor((availableRowHeight - (cardHeight - cardSpacingY)) / (double) cardSpacingY); / (double) cardSpacingY);
actualCardsPerRow = actualCardsPerRow = Math
Math.max(availableCardsPerRow, (int) Math.ceil(cardPanels.size() / (float) maxRows)); .max(availableCardsPerRow, (int) Math.ceil(cardPanels.size() / (float) maxRows));
int actualRowHeight = (int) Math.floor((actualCardsPerRow - 1) * cardSpacingY + cardHeight); int actualRowHeight = (int) Math.floor((actualCardsPerRow - 1) * cardSpacingY + cardHeight);
float overflow = actualRowHeight - availableRowHeight; float overflow = actualRowHeight - availableRowHeight;
if (overflow > 0) { if (overflow > 0) {
@@ -193,17 +199,16 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen
int extraCardSpacingX = Math.round(cardWidth * HORIZ_CARD_SPACING_X); int extraCardSpacingX = Math.round(cardWidth * HORIZ_CARD_SPACING_X);
cardSpacingY = Math.round(cardHeight * HORIZ_CARD_SPACING_Y); cardSpacingY = Math.round(cardHeight * HORIZ_CARD_SPACING_Y);
cardSpacingX = cardWidth + extraCardSpacingX; cardSpacingX = cardWidth + extraCardSpacingX;
int maxRows = int maxRows = (int) Math.floor((cardAreaHeight - GUTTER_Y * 2 + cardSpacingY)
(int) Math.floor((cardAreaHeight - GUTTER_Y * 2 + cardSpacingY) / / (double) (cardHeight + cardSpacingY));
(double) (cardHeight + cardSpacingY));
if (this.maxRows > 0) { if (this.maxRows > 0) {
maxRows = Math.min(this.maxRows, maxRows); maxRows = Math.min(this.maxRows, maxRows);
} }
int availableRowWidth = cardAreaWidth - GUTTER_X * 2; int availableRowWidth = cardAreaWidth - GUTTER_X * 2;
int availableCardsPerRow = int availableCardsPerRow = (int) Math.floor((availableRowWidth - (cardWidth - cardSpacingX))
(int) Math.floor((availableRowWidth - (cardWidth - cardSpacingX)) / cardSpacingX); / cardSpacingX);
actualCardsPerRow = actualCardsPerRow = Math
Math.max(availableCardsPerRow, (int) Math.ceil(cardPanels.size() / (float) maxRows)); .max(availableCardsPerRow, (int) Math.ceil(cardPanels.size() / (float) maxRows));
int actualRowWidth = (int) Math.floor((actualCardsPerRow - 1) * cardSpacingX + cardWidth); int actualRowWidth = (int) Math.floor((actualCardsPerRow - 1) * cardSpacingX + cardWidth);
float overflow = actualRowWidth - availableRowWidth; float overflow = actualRowWidth - availableRowWidth;
if (overflow > 0) { if (overflow > 0) {
@@ -280,9 +285,8 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public final void mouseDragged(final CardPanel dragPanel, public final void mouseDragged(final CardPanel dragPanel, final int dragOffsetX, final int dragOffsetY,
final int dragOffsetX, final int dragOffsetY, final MouseEvent evt) final MouseEvent evt) {
{
super.mouseDragged(dragPanel, dragOffsetX, dragOffsetY, evt); super.mouseDragged(dragPanel, dragOffsetX, dragOffsetY, evt);
int mouseX = evt.getX(); int mouseX = evt.getX();
@@ -319,13 +323,15 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen
int startWidth = CardPanel.dragAnimationPanel.getCardWidth(); int startWidth = CardPanel.dragAnimationPanel.getCardWidth();
Point endPos = SwingUtilities.convertPoint(this, dragPanel.getCardLocation(), layeredPane); Point endPos = SwingUtilities.convertPoint(this, dragPanel.getCardLocation(), layeredPane);
int endWidth = dragPanel.getCardWidth(); int endWidth = dragPanel.getCardWidth();
Animation.moveCard(startX, startY, startWidth, endPos.x, endPos.y, endWidth, Animation.moveCard(startX, startY, startWidth, endPos.x, endPos.y, endWidth, CardPanel.dragAnimationPanel,
CardPanel.dragAnimationPanel, dragPanel, layeredPane, 200); dragPanel, layeredPane, 200);
} }
/** /**
* <p>Getter for the field <code>maxCoverage</code>.</p> * <p>
* * Getter for the field <code>maxCoverage</code>.
* </p>
*
* @return a float. * @return a float.
*/ */
public final float getMaxCoverage() { public final float getMaxCoverage() {
@@ -333,26 +339,34 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen
} }
/** /**
* <p>Setter for the field <code>maxCoverage</code>.</p> * <p>
* * Setter for the field <code>maxCoverage</code>.
* @param maxCoverage a float. * </p>
*
* @param maxCoverage
* a float.
*/ */
public final void setMaxCoverage(float maxCoverage) { public final void setMaxCoverage(float maxCoverage) {
this.maxCoverage = maxCoverage; this.maxCoverage = maxCoverage;
} }
/** /**
* <p>Setter for the field <code>maxRows</code>.</p> * <p>
* * Setter for the field <code>maxRows</code>.
* @param maxRows a int. * </p>
*
* @param maxRows
* a int.
*/ */
public final void setMaxRows(int maxRows) { public final void setMaxRows(int maxRows) {
this.maxRows = maxRows; this.maxRows = maxRows;
} }
/** /**
* <p>Getter for the field <code>maxRows</code>.</p> * <p>
* * Getter for the field <code>maxRows</code>.
* </p>
*
* @return a int. * @return a int.
*/ */
public final int getMaxRows() { public final int getMaxRows() {
@@ -360,17 +374,22 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen
} }
/** /**
* <p>setVertical.</p> * <p>
* * setVertical.
* @param isVertical a boolean. * </p>
*
* @param isVertical
* a boolean.
*/ */
public final void setVertical(final boolean isVertical) { public final void setVertical(final boolean isVertical) {
this.isVertical = isVertical; this.isVertical = isVertical;
} }
/** /**
* <p>isVertical.</p> * <p>
* * isVertical.
* </p>
*
* @return a boolean. * @return a boolean.
*/ */
public final boolean isVertical() { public final boolean isVertical() {

View File

@@ -1,22 +1,41 @@
package arcane.ui; package arcane.ui;
import arcane.ui.ScaledImagePanel.MultipassType;
import arcane.ui.ScaledImagePanel.ScalingType;
import arcane.ui.util.GlowText;
import arcane.ui.util.ManaSymbols;
import forge.*;
import javax.swing.*;
import java.awt.Color; import java.awt.Color;
import java.awt.*; import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.ComponentAdapter; import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent; import java.awt.event.ComponentEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.SwingUtilities;
import arcane.ui.ScaledImagePanel.MultipassType;
import arcane.ui.ScaledImagePanel.ScalingType;
import arcane.ui.util.GlowText;
import arcane.ui.util.ManaSymbols;
import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardContainer;
import forge.Counters;
import forge.ImageCache;
import forge.Singletons;
/** /**
* <p>CardPanel class.</p> * <p>
* * CardPanel class.
* </p>
*
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
@@ -47,9 +66,15 @@ public class CardPanel extends JPanel implements CardContainer {
private static final int TEXT_GLOW_SIZE = 6; private static final int TEXT_GLOW_SIZE = 6;
/** Constant <code>TEXT_GLOW_INTENSITY=3f</code>. */ /** Constant <code>TEXT_GLOW_INTENSITY=3f</code>. */
private static final float TEXT_GLOW_INTENSITY = 3f; private static final float TEXT_GLOW_INTENSITY = 3f;
/** Constant <code>rotCenterToTopCorner=1.0295630140987000315797369464196f</code>. */ /**
* Constant
* <code>rotCenterToTopCorner=1.0295630140987000315797369464196f</code>.
*/
private static final float rotCenterToTopCorner = 1.0295630140987000315797369464196f; private static final float rotCenterToTopCorner = 1.0295630140987000315797369464196f;
/** Constant <code>rotCenterToBottomCorner=0.7071067811865475244008443621048f</code>. */ /**
* Constant
* <code>rotCenterToBottomCorner=0.7071067811865475244008443621048f</code>.
*/
private static final float rotCenterToBottomCorner = 0.7071067811865475244008443621048f; private static final float rotCenterToBottomCorner = 0.7071067811865475244008443621048f;
/** /**
@@ -87,9 +112,12 @@ public class CardPanel extends JPanel implements CardContainer {
private boolean showCastingCost; private boolean showCastingCost;
/** /**
* <p>Constructor for CardPanel.</p> * <p>
* * Constructor for CardPanel.
* @param newGameCard a {@link forge.Card} object. * </p>
*
* @param newGameCard
* a {@link forge.Card} object.
*/ */
public CardPanel(final Card newGameCard) { public CardPanel(final Card newGameCard) {
this.gameCard = newGameCard; this.gameCard = newGameCard;
@@ -133,11 +161,16 @@ public class CardPanel extends JPanel implements CardContainer {
} }
/** /**
* <p>setImage.</p> * <p>
* * setImage.
* @param srcImage a {@link java.awt.Image} object. * </p>
* @param srcImageBlurred a {@link java.awt.Image} object. *
* @param srcImageBlurred a {@link java.awt.Image} object. * @param srcImage
* a {@link java.awt.Image} object.
* @param srcImageBlurred
* a {@link java.awt.Image} object.
* @param srcImageBlurred
* a {@link java.awt.Image} object.
*/ */
private void setImage(final Image srcImage, final Image srcImageBlurred) { private void setImage(final Image srcImage, final Image srcImageBlurred) {
synchronized (imagePanel) { synchronized (imagePanel) {
@@ -153,9 +186,12 @@ public class CardPanel extends JPanel implements CardContainer {
} }
/** /**
* <p>setImage.</p> * <p>
* * setImage.
* @param panel a {@link arcane.ui.CardPanel} object. * </p>
*
* @param panel
* a {@link arcane.ui.CardPanel} object.
*/ */
public final void setImage(final CardPanel panel) { public final void setImage(final CardPanel panel) {
synchronized (panel.imagePanel) { synchronized (panel.imagePanel) {
@@ -168,26 +204,34 @@ public class CardPanel extends JPanel implements CardContainer {
} }
/** /**
* <p>setScalingType.</p> * <p>
* * setScalingType.
* @param scalingType a {@link arcane.ui.ScaledImagePanel.ScalingType} object. * </p>
*
* @param scalingType
* a {@link arcane.ui.ScaledImagePanel.ScalingType} object.
*/ */
public final void setScalingType(final ScalingType scalingType) { public final void setScalingType(final ScalingType scalingType) {
imagePanel.setScalingType(scalingType); imagePanel.setScalingType(scalingType);
} }
/** /**
* <p>Setter for the field <code>displayEnabled</code>.</p> * <p>
* * Setter for the field <code>displayEnabled</code>.
* @param displayEnabled a boolean. * </p>
*
* @param displayEnabled
* a boolean.
*/ */
public final void setDisplayEnabled(final boolean displayEnabled) { public final void setDisplayEnabled(final boolean displayEnabled) {
this.displayEnabled = displayEnabled; this.displayEnabled = displayEnabled;
} }
/** /**
* <p>isDisplayEnabled.</p> * <p>
* * isDisplayEnabled.
* </p>
*
* @return a boolean. * @return a boolean.
*/ */
public final boolean isDisplayEnabled() { public final boolean isDisplayEnabled() {
@@ -195,18 +239,24 @@ public class CardPanel extends JPanel implements CardContainer {
} }
/** /**
* <p>setAnimationPanel.</p> * <p>
* * setAnimationPanel.
* @param isAnimationPanel a boolean. * </p>
*
* @param isAnimationPanel
* a boolean.
*/ */
public final void setAnimationPanel(final boolean isAnimationPanel) { public final void setAnimationPanel(final boolean isAnimationPanel) {
this.isAnimationPanel = isAnimationPanel; this.isAnimationPanel = isAnimationPanel;
} }
/** /**
* <p>setSelected.</p> * <p>
* * setSelected.
* @param isSelected a boolean. * </p>
*
* @param isSelected
* a boolean.
*/ */
public final void setSelected(final boolean isSelected) { public final void setSelected(final boolean isSelected) {
this.isSelected = isSelected; this.isSelected = isSelected;
@@ -214,9 +264,12 @@ public class CardPanel extends JPanel implements CardContainer {
} }
/** /**
* <p>Setter for the field <code>showCastingCost</code>.</p> * <p>
* * Setter for the field <code>showCastingCost</code>.
* @param showCastingCost a boolean. * </p>
*
* @param showCastingCost
* a boolean.
*/ */
public final void setShowCastingCost(final boolean showCastingCost) { public final void setShowCastingCost(final boolean showCastingCost) {
this.showCastingCost = showCastingCost; this.showCastingCost = showCastingCost;
@@ -249,8 +302,7 @@ public class CardPanel extends JPanel implements CardContainer {
if (this.gameCard != null) { if (this.gameCard != null) {
if ((!this.gameCard.getImageFilename().equals("none")) && (!this.gameCard.getName().equals("Morph"))) { if ((!this.gameCard.getImageFilename().equals("none")) && (!this.gameCard.getName().equals("Morph"))) {
if ((this.gameCard.getCurSetCode().equals("2ED")) if ((this.gameCard.getCurSetCode().equals("2ED")) || (this.gameCard.getCurSetCode().equals("3ED"))
|| (this.gameCard.getCurSetCode().equals("3ED"))
|| (this.gameCard.getCurSetCode().equals("4ED")) || (this.gameCard.getCurSetCode().equals("4ED"))
|| (this.gameCard.getCurSetCode().equals("5ED")) || (this.gameCard.getCurSetCode().equals("5ED"))
|| (this.gameCard.getCurSetCode().equals("6ED")) || (this.gameCard.getCurSetCode().equals("6ED"))
@@ -260,15 +312,13 @@ public class CardPanel extends JPanel implements CardContainer {
|| (this.gameCard.getCurSetCode().equals("CHR")) || (this.gameCard.getCurSetCode().equals("CHR"))
|| (this.gameCard.getCurSetCode().equals("S99")) || (this.gameCard.getCurSetCode().equals("S99"))
|| (this.gameCard.getCurSetCode().equals("PTK")) || (this.gameCard.getCurSetCode().equals("PTK"))
|| (this.gameCard.getCurSetCode().equals("S00"))) || (this.gameCard.getCurSetCode().equals("S00"))) {
{
if (!isSelected) { if (!isSelected) {
g2d.setColor(Color.black); g2d.setColor(Color.black);
int offset = tapped ? 1 : 0; int offset = tapped ? 1 : 0;
for (int i = 1, n = Math.max(1, Math.round(cardWidth * SELECTED_BORDER_SIZE)); i <= n; i++) { for (int i = 1, n = Math.max(1, Math.round(cardWidth * SELECTED_BORDER_SIZE)); i <= n; i++) {
g2d.drawRoundRect(cardXOffset - i, cardYOffset - i + offset, g2d.drawRoundRect(cardXOffset - i, cardYOffset - i + offset, cardWidth + i * 2 - 1,
cardWidth + i * 2 - 1, cardHeight + i * 2 - 1, cardHeight + i * 2 - 1, cornerSize, cornerSize);
cornerSize, cornerSize);
} }
} }
g2d.setColor(Color.white); g2d.setColor(Color.white);
@@ -284,9 +334,8 @@ public class CardPanel extends JPanel implements CardContainer {
g2d.setColor(Color.green); g2d.setColor(Color.green);
int offset = tapped ? 1 : 0; int offset = tapped ? 1 : 0;
for (int i = 1, n = Math.max(1, Math.round(cardWidth * SELECTED_BORDER_SIZE)); i <= n; i++) { for (int i = 1, n = Math.max(1, Math.round(cardWidth * SELECTED_BORDER_SIZE)); i <= n; i++) {
g2d.drawRoundRect(cardXOffset - i, cardYOffset - i + offset, g2d.drawRoundRect(cardXOffset - i, cardYOffset - i + offset, cardWidth + i * 2 - 1, cardHeight + i * 2
cardWidth + i * 2 - 1, cardHeight + i * 2 - 1, - 1, cornerSize, cornerSize);
cornerSize, cornerSize);
} }
} }
} }
@@ -303,43 +352,40 @@ public class CardPanel extends JPanel implements CardContainer {
int width = ManaSymbols.getWidth(gameCard.getManaCost()); int width = ManaSymbols.getWidth(gameCard.getManaCost());
if (cardWidth < 200) { if (cardWidth < 200) {
ManaSymbols.draw(g, gameCard.getManaCost(), ManaSymbols.draw(g, gameCard.getManaCost(), cardXOffset + cardWidth / 2 - width / 2, cardYOffset
cardXOffset + cardWidth / 2 - width / 2, cardYOffset + cardHeight / 2); + cardHeight / 2);
} }
int counters = getCard().getNumberOfCounters(); int counters = getCard().getNumberOfCounters();
if (counters == 1) { if (counters == 1) {
ManaSymbols.drawSymbol("counters1", g, cardXOffset - 15, ManaSymbols.drawSymbol("counters1", g, cardXOffset - 15, cardYOffset + cardHeight - (cardHeight / 3) - 40);
cardYOffset + cardHeight - (cardHeight / 3) - 40);
} else if (counters == 2) { } else if (counters == 2) {
ManaSymbols.drawSymbol("counters2", g, cardXOffset - 15, ManaSymbols.drawSymbol("counters2", g, cardXOffset - 15, cardYOffset + cardHeight - (cardHeight / 3) - 40);
cardYOffset + cardHeight - (cardHeight / 3) - 40);
} else if (counters == 3) { } else if (counters == 3) {
ManaSymbols.drawSymbol("counters3", g, cardXOffset - 15, ManaSymbols.drawSymbol("counters3", g, cardXOffset - 15, cardYOffset + cardHeight - (cardHeight / 3) - 40);
cardYOffset + cardHeight - (cardHeight / 3) - 40);
} else if (counters > 3) { } else if (counters > 3) {
ManaSymbols.drawSymbol("countersMulti", g, cardXOffset - 15, ManaSymbols.drawSymbol("countersMulti", g, cardXOffset - 15, cardYOffset + cardHeight - (cardHeight / 3)
cardYOffset + cardHeight - (cardHeight / 3) - 40); - 40);
} }
//int yOff = (cardHeight/4) + 2; // int yOff = (cardHeight/4) + 2;
if (getCard().isAttacking()) { if (getCard().isAttacking()) {
ManaSymbols.drawSymbol("attack", g, cardXOffset + cardWidth / 4 - 16, ManaSymbols.drawSymbol("attack", g, cardXOffset + cardWidth / 4 - 16, cardYOffset + cardHeight
cardYOffset + cardHeight - (cardHeight / 8) - 16); - (cardHeight / 8) - 16);
} else if (getCard().isBlocking()) { } else if (getCard().isBlocking()) {
ManaSymbols.drawSymbol("defend", g, cardXOffset + cardWidth / 4 - 16, ManaSymbols.drawSymbol("defend", g, cardXOffset + cardWidth / 4 - 16, cardYOffset + cardHeight
cardYOffset + cardHeight - (cardHeight / 8) - 16); - (cardHeight / 8) - 16);
} }
if (getCard().isCreature() && getCard().hasSickness() && AllZoneUtil.isCardInPlay(getCard())) { if (getCard().isCreature() && getCard().hasSickness() && AllZoneUtil.isCardInPlay(getCard())) {
ManaSymbols.drawSymbol("summonsick", g, cardXOffset + cardWidth / 2 - 16, ManaSymbols.drawSymbol("summonsick", g, cardXOffset + cardWidth / 2 - 16, cardYOffset + cardHeight
cardYOffset + cardHeight - (cardHeight / 8) - 16); - (cardHeight / 8) - 16);
} }
if (getCard().isPhasedOut()) { if (getCard().isPhasedOut()) {
ManaSymbols.drawSymbol("phasing", g, cardXOffset + cardWidth / 2 - 16, ManaSymbols.drawSymbol("phasing", g, cardXOffset + cardWidth / 2 - 16, cardYOffset + cardHeight
cardYOffset + cardHeight - (cardHeight / 8) - 16); - (cardHeight / 8) - 16);
} }
if (getCard() != null) { if (getCard() != null) {
@@ -363,8 +409,8 @@ public class CardPanel extends JPanel implements CardContainer {
if (!mList[n].equals("")) { if (!mList[n].equals("")) {
width = ManaSymbols.getWidth(mList[n]); width = ManaSymbols.getWidth(mList[n]);
ManaSymbols.draw(g, mList[n], ManaSymbols.draw(g, mList[n],
cardXOffset + ((i + 1) * (cardWidth / 3)) - width / 2, cardXOffset + ((i + 1) * (cardWidth / 3)) - width / 2, cardYOffset
cardYOffset + ((j + 1) * (cardHeight / 7))); + ((j + 1) * (cardHeight / 7)));
} }
n++; n++;
@@ -377,8 +423,10 @@ public class CardPanel extends JPanel implements CardContainer {
} }
/** /**
* <p>doLayout.</p> * <p>
* * doLayout.
* </p>
*
* @since 1.0.15 * @since 1.0.15
*/ */
public final void doLayout() { public final void doLayout() {
@@ -409,8 +457,10 @@ public class CardPanel extends JPanel implements CardContainer {
} }
/** /**
* <p>toString.</p> * <p>
* * toString.
* </p>
*
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
public final String toString() { public final String toString() {
@@ -418,12 +468,18 @@ public class CardPanel extends JPanel implements CardContainer {
} }
/** /**
* <p>setCardBounds.</p> * <p>
* * setCardBounds.
* @param x a int. * </p>
* @param y a int. *
* @param width a int. * @param x
* @param height a int. * a int.
* @param y
* a int.
* @param width
* a int.
* @param height
* a int.
*/ */
public final void setCardBounds(final int x, final int y, int width, int height) { public final void setCardBounds(final int x, final int y, int width, int height) {
cardWidth = width; cardWidth = width;
@@ -442,7 +498,9 @@ public class CardPanel extends JPanel implements CardContainer {
} }
/** /**
* <p>repaint.</p> * <p>
* repaint.
* </p>
*/ */
public final void repaint() { public final void repaint() {
Rectangle b = getBounds(); Rectangle b = getBounds();
@@ -455,8 +513,10 @@ public class CardPanel extends JPanel implements CardContainer {
} }
/** /**
* <p>getCardX.</p> * <p>
* * getCardX.
* </p>
*
* @return a int. * @return a int.
*/ */
public final int getCardX() { public final int getCardX() {
@@ -464,8 +524,10 @@ public class CardPanel extends JPanel implements CardContainer {
} }
/** /**
* <p>getCardY.</p> * <p>
* * getCardY.
* </p>
*
* @return a int. * @return a int.
*/ */
public final int getCardY() { public final int getCardY() {
@@ -473,8 +535,10 @@ public class CardPanel extends JPanel implements CardContainer {
} }
/** /**
* <p>Getter for the field <code>cardWidth</code>.</p> * <p>
* * Getter for the field <code>cardWidth</code>.
* </p>
*
* @return a int. * @return a int.
*/ */
public final int getCardWidth() { public final int getCardWidth() {
@@ -482,8 +546,10 @@ public class CardPanel extends JPanel implements CardContainer {
} }
/** /**
* <p>Getter for the field <code>cardHeight</code>.</p> * <p>
* * Getter for the field <code>cardHeight</code>.
* </p>
*
* @return a int. * @return a int.
*/ */
public final int getCardHeight() { public final int getCardHeight() {
@@ -491,8 +557,10 @@ public class CardPanel extends JPanel implements CardContainer {
} }
/** /**
* <p>getCardLocation.</p> * <p>
* * getCardLocation.
* </p>
*
* @return a {@link java.awt.Point} object. * @return a {@link java.awt.Point} object.
*/ */
public final Point getCardLocation() { public final Point getCardLocation() {
@@ -503,9 +571,12 @@ public class CardPanel extends JPanel implements CardContainer {
} }
/** /**
* <p>setText.</p> * <p>
* * setText.
* @param card a {@link forge.Card} object. * </p>
*
* @param card
* a {@link forge.Card} object.
*/ */
public final void setText(final Card card) { public final void setText(final Card card) {
if (card == null || !Singletons.getModel().getPreferences().cardOverlay) { if (card == null || !Singletons.getModel().getPreferences().cardOverlay) {
@@ -521,9 +592,8 @@ public class CardPanel extends JPanel implements CardContainer {
} }
if (card.isCreature() && card.isPlaneswalker()) { if (card.isCreature() && card.isPlaneswalker()) {
ptText.setText(card.getNetAttack() + "/" ptText.setText(card.getNetAttack() + "/" + card.getNetDefense() + " ("
+ card.getNetDefense() + String.valueOf(card.getCounters(Counters.LOYALTY)) + ")");
+ " (" + String.valueOf(card.getCounters(Counters.LOYALTY)) + ")");
} else if (card.isCreature()) { } else if (card.isCreature()) {
ptText.setText(card.getNetAttack() + "/" + card.getNetDefense()); ptText.setText(card.getNetAttack() + "/" + card.getNetDefense());
} else if (card.isPlaneswalker()) { } else if (card.isPlaneswalker()) {
@@ -534,8 +604,10 @@ public class CardPanel extends JPanel implements CardContainer {
} }
/** /**
* <p>getCard.</p> * <p>
* * getCard.
* </p>
*
* @return a {@link forge.Card} object. * @return a {@link forge.Card} object.
*/ */
public final Card getCard() { public final Card getCard() {

View File

@@ -1,14 +1,17 @@
package arcane.ui; package arcane.ui;
import java.awt.Frame;
import java.awt.event.MouseEvent;
import javax.swing.JScrollPane;
import arcane.ui.util.CardPanelMouseListener; import arcane.ui.util.CardPanelMouseListener;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
/** /**
* <p>HandArea class.</p> * <p>
* * HandArea class.
* </p>
*
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
@@ -17,10 +20,14 @@ public class HandArea extends CardArea {
private static final long serialVersionUID = 7488132628637407745L; private static final long serialVersionUID = 7488132628637407745L;
/** /**
* <p>Constructor for HandArea.</p> * <p>
* * Constructor for HandArea.
* @param scrollPane a {@link javax.swing.JScrollPane} object. * </p>
* @param frame a {@link java.awt.Frame} object. *
* @param scrollPane
* a {@link javax.swing.JScrollPane} object.
* @param frame
* a {@link java.awt.Frame} object.
*/ */
public HandArea(final JScrollPane scrollPane, final Frame frame) { public HandArea(final JScrollPane scrollPane, final Frame frame) {
super(scrollPane); super(scrollPane);
@@ -45,11 +52,8 @@ public class HandArea extends CardArea {
} }
public void mouseDragged(final CardPanel dragPanel, public void mouseDragged(final CardPanel dragPanel, final int dragOffsetX, final int dragOffsetY,
final int dragOffsetX, final MouseEvent evt) {
final int dragOffsetY,
final MouseEvent evt)
{
} }
public void mouseDragStart(final CardPanel dragPanel, final MouseEvent evt) { public void mouseDragStart(final CardPanel dragPanel, final MouseEvent evt) {

View File

@@ -1,57 +1,71 @@
package arcane.ui.util; package arcane.ui.util;
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Point;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JLayeredPane;
import javax.swing.SwingUtilities;
import arcane.ui.CardPanel; import arcane.ui.CardPanel;
import arcane.util.Util; import arcane.util.Util;
import javax.swing.*;
import java.awt.*;
import java.util.Timer;
import java.util.TimerTask;
/** /**
* <p>Abstract Animation class.</p> * <p>
* * Abstract Animation class.
* </p>
*
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
abstract public class Animation { public abstract class Animation {
/** Constant <code>TARGET_MILLIS_PER_FRAME=30</code> */ /** Constant <code>TARGET_MILLIS_PER_FRAME=30</code>. */
static private final long TARGET_MILLIS_PER_FRAME = 30; private static final long TARGET_MILLIS_PER_FRAME = 30;
/** Constant <code>timer</code> */ /** Constant <code>timer</code>. */
static private Timer timer = new Timer("Animation", true); private static Timer timer = new Timer("Animation", true);
/** Constant <code>delayedCardPanel</code> */ /** Constant <code>delayedCardPanel</code>. */
static private CardPanel delayedCardPanel; private static CardPanel delayedCardPanel;
/** Constant <code>delayedTime=</code> */ /** Constant <code>delayedTime=</code>. */
static private long delayedTime; private static long delayedTime;
/** Constant <code>enlargedCardPanel</code> */ /** Constant <code>enlargedCardPanel</code>. */
static private CardPanel enlargedCardPanel; private static CardPanel enlargedCardPanel;
/** Constant <code>enlargedAnimationPanel</code> */ /** Constant <code>enlargedAnimationPanel</code>. */
static private CardPanel enlargedAnimationPanel; private static CardPanel enlargedAnimationPanel;
/** Constant <code>enlargeLock</code> */ /** Constant <code>enlargeLock</code>. */
static private Object enlargeLock = new Object(); private static Object enlargeLock = new Object();
private TimerTask timerTask; private TimerTask timerTask;
private FrameTimer frameTimer; private FrameTimer frameTimer;
private long elapsed; private long elapsed;
/** /**
* <p>Constructor for Animation.</p> * <p>
* * Constructor for Animation.
* @param duration a long. * </p>
*
* @param duration
* a long.
*/ */
public Animation(final long duration) { public Animation(final long duration) {
this(duration, 0); this(duration, 0);
} }
/** /**
* <p>Constructor for Animation.</p> * <p>
* * Constructor for Animation.
* @param duration a long. * </p>
* @param delay a long. *
* @param duration
* a long.
* @param delay
* a long.
*/ */
public Animation(final long duration, long delay) { public Animation(final long duration, final long delay) {
timerTask = new TimerTask() { timerTask = new TimerTask() {
public void run() { public void run() {
if (frameTimer == null) { if (frameTimer == null) {
@@ -64,68 +78,86 @@ abstract public class Animation {
elapsed = duration; elapsed = duration;
} }
update(elapsed / (float) duration); update(elapsed / (float) duration);
if (elapsed == duration) end(); if (elapsed == duration) {
end();
}
} }
}; };
timer.scheduleAtFixedRate(timerTask, delay, TARGET_MILLIS_PER_FRAME); timer.scheduleAtFixedRate(timerTask, delay, TARGET_MILLIS_PER_FRAME);
} }
/** /**
* <p>update.</p> * <p>
* * update.
* @param percentage a float. * </p>
*
* @param percentage
* a float.
*/ */
abstract protected void update(float percentage); protected abstract void update(float percentage);
/** /**
* <p>cancel.</p> * <p>
* cancel.
* </p>
*/ */
protected void cancel() { protected final void cancel() {
timerTask.cancel(); timerTask.cancel();
end(); end();
} }
/** /**
* <p>start.</p> * <p>
* start.
* </p>
*/ */
protected void start() { protected void start() {
} }
/** /**
* <p>end.</p> * <p>
* end.
* </p>
*/ */
protected void end() { protected void end() {
} }
/** /**
* Uses averaging of the time between the past few frames to provide smooth animation. * Uses averaging of the time between the past few frames to provide smooth
* animation.
*/ */
private class FrameTimer { private class FrameTimer {
static private final int SAMPLES = 6; private static final int SAMPLES = 6;
static private final long MAX_FRAME = 100; // Max time for one frame, to weed out spikes. private static final long MAX_FRAME = 100; // Max time for one frame, to
// weed out spikes.
private long samples[] = new long[SAMPLES]; private long[] samples = new long[SAMPLES];
private int sampleIndex; private int sampleIndex;
public FrameTimer() { public FrameTimer() {
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
for (int i = SAMPLES - 1; i >= 0; i--) for (int i = SAMPLES - 1; i >= 0; i--) {
samples[i] = currentTime - (SAMPLES - i) * TARGET_MILLIS_PER_FRAME; samples[i] = currentTime - (SAMPLES - i) * TARGET_MILLIS_PER_FRAME;
}
} }
public long getTimeSinceLastFrame() { public long getTimeSinceLastFrame() {
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
int id = sampleIndex - 1; int id = sampleIndex - 1;
if (id < 0) id += SAMPLES; if (id < 0) {
id += SAMPLES;
}
long timeSinceLastSample = currentTime - samples[id]; long timeSinceLastSample = currentTime - samples[id];
// If the slice was too big, advance all the previous times by the diff. // If the slice was too big, advance all the previous times by the
// diff.
if (timeSinceLastSample > MAX_FRAME) { if (timeSinceLastSample > MAX_FRAME) {
long diff = timeSinceLastSample - MAX_FRAME; long diff = timeSinceLastSample - MAX_FRAME;
for (int i = 0; i < SAMPLES; i++) for (int i = 0; i < SAMPLES; i++) {
samples[i] += diff; samples[i] += diff;
}
} }
long timeSinceOldestSample = currentTime - samples[sampleIndex]; long timeSinceOldestSample = currentTime - samples[sampleIndex];
@@ -137,19 +169,24 @@ abstract public class Animation {
} }
/** /**
* <p>tapCardToggle.</p> * <p>
* * tapCardToggle.
* @param panel a {@link arcane.ui.CardPanel} object. * </p>
*
* @param panel
* a {@link arcane.ui.CardPanel} object.
*/ */
static public void tapCardToggle(final CardPanel panel) { public static void tapCardToggle(final CardPanel panel) {
new Animation(200) { new Animation(200) {
protected void start() { protected void start() {
panel.tapped = !panel.tapped; panel.tapped = !panel.tapped;
} }
protected void update(float percentage) { protected void update(final float percentage) {
panel.tappedAngle = CardPanel.TAPPED_ANGLE * percentage; panel.tappedAngle = CardPanel.TAPPED_ANGLE * percentage;
if (!panel.tapped) panel.tappedAngle = CardPanel.TAPPED_ANGLE - panel.tappedAngle; if (!panel.tapped) {
panel.tappedAngle = CardPanel.TAPPED_ANGLE - panel.tappedAngle;
}
panel.repaint(); panel.repaint();
} }
@@ -159,24 +196,38 @@ abstract public class Animation {
}; };
} }
// static public void moveCardToPlay (Component source, final CardPanel dest, final CardPanel animationPanel) { // static public void moveCardToPlay (Component source, final CardPanel
// dest, final CardPanel animationPanel) {
/** /**
* <p>moveCardToPlay.</p> * <p>
* * moveCardToPlay.
* @param startX a int. * </p>
* @param startY a int. *
* @param startWidth a int. * @param startX
* @param endX a int. * a int.
* @param endY a int. * @param startY
* @param endWidth a int. * a int.
* @param animationPanel a {@link arcane.ui.CardPanel} object. * @param startWidth
* @param placeholder a {@link arcane.ui.CardPanel} object. * a int.
* @param layeredPane a {@link javax.swing.JLayeredPane} object. * @param endX
* @param speed a int. * a int.
* @param endY
* a int.
* @param endWidth
* a int.
* @param animationPanel
* a {@link arcane.ui.CardPanel} object.
* @param placeholder
* a {@link arcane.ui.CardPanel} object.
* @param layeredPane
* a {@link javax.swing.JLayeredPane} object.
* @param speed
* a int.
*/ */
static public void moveCardToPlay(final int startX, final int startY, final int startWidth, final int endX, final int endY, public static void moveCardToPlay(final int startX, final int startY, final int startWidth, final int endX,
final int endWidth, final CardPanel animationPanel, final CardPanel placeholder, final JLayeredPane layeredPane, final int endY, final int endWidth, final CardPanel animationPanel, final CardPanel placeholder,
final int speed) { final JLayeredPane layeredPane, final int speed)
{
UI.invokeLater(new Runnable() { UI.invokeLater(new Runnable() {
public void run() { public void run() {
final int startHeight = Math.round(startWidth * CardPanel.ASPECT_RATIO); final int startHeight = Math.round(startWidth * CardPanel.ASPECT_RATIO);
@@ -240,22 +291,34 @@ abstract public class Animation {
} }
/** /**
* <p>moveCard.</p> * <p>
* * moveCard.
* @param startX a int. * </p>
* @param startY a int. *
* @param startWidth a int. * @param startX
* @param endX a int. * a int.
* @param endY a int. * @param startY
* @param endWidth a int. * a int.
* @param animationPanel a {@link arcane.ui.CardPanel} object. * @param startWidth
* @param placeholder a {@link arcane.ui.CardPanel} object. * a int.
* @param layeredPane a {@link javax.swing.JLayeredPane} object. * @param endX
* @param speed a int. * a int.
* @param endY
* a int.
* @param endWidth
* a int.
* @param animationPanel
* a {@link arcane.ui.CardPanel} object.
* @param placeholder
* a {@link arcane.ui.CardPanel} object.
* @param layeredPane
* a {@link javax.swing.JLayeredPane} object.
* @param speed
* a int.
*/ */
static public void moveCard(final int startX, final int startY, final int startWidth, final int endX, final int endY, public static void moveCard(final int startX, final int startY, final int startWidth, final int endX,
final int endWidth, final CardPanel animationPanel, final CardPanel placeholder, final JLayeredPane layeredPane, final int endY, final int endWidth, final CardPanel animationPanel, final CardPanel placeholder,
final int speed) { final JLayeredPane layeredPane, final int speed) {
UI.invokeLater(new Runnable() { UI.invokeLater(new Runnable() {
public void run() { public void run() {
final int startHeight = Math.round(startWidth * CardPanel.ASPECT_RATIO); final int startHeight = Math.round(startWidth * CardPanel.ASPECT_RATIO);
@@ -270,7 +333,7 @@ abstract public class Animation {
} }
new Animation(speed) { new Animation(speed) {
protected void update(float percentage) { protected void update(final float percentage) {
int currentX = startX + Math.round((endX - startX) * percentage); int currentX = startX + Math.round((endX - startX) * percentage);
int currentY = startY + Math.round((endY - startY) * percentage); int currentY = startY + Math.round((endY - startY) * percentage);
int currentWidth = startWidth + Math.round((endWidth - startWidth) * percentage); int currentWidth = startWidth + Math.round((endWidth - startWidth) * percentage);
@@ -283,7 +346,7 @@ abstract public class Animation {
public void run() { public void run() {
if (placeholder != null) { if (placeholder != null) {
placeholder.setDisplayEnabled(true); placeholder.setDisplayEnabled(true);
//placeholder.setImage(animationPanel); // placeholder.setImage(animationPanel);
placeholder.setCard(placeholder.gameCard); placeholder.setCard(placeholder.gameCard);
} }
animationPanel.setVisible(false); animationPanel.setVisible(false);
@@ -298,18 +361,21 @@ abstract public class Animation {
} }
/** /**
* <p>moveCard.</p> * <p>
* * moveCard.
* @param placeholder a {@link arcane.ui.CardPanel} object. * </p>
*
* @param placeholder
* a {@link arcane.ui.CardPanel} object.
*/ */
static public void moveCard(final CardPanel placeholder) { public static void moveCard(final CardPanel placeholder) {
UI.invokeLater(new Runnable() { UI.invokeLater(new Runnable() {
public void run() { public void run() {
EventQueue.invokeLater(new Runnable() { EventQueue.invokeLater(new Runnable() {
public void run() { public void run() {
if (placeholder != null) { if (placeholder != null) {
placeholder.setDisplayEnabled(true); placeholder.setDisplayEnabled(true);
//placeholder.setImage(imagePanel); // placeholder.setImage(imagePanel);
placeholder.setCard(placeholder.gameCard); placeholder.setCard(placeholder.gameCard);
} }
} }
@@ -319,16 +385,20 @@ abstract public class Animation {
} }
/** /**
* <p>shrinkCard.</p> * <p>
* shrinkCard.
* </p>
*/ */
static public void shrinkCard() { public static void shrinkCard() {
CardPanel enlargedCardPanel, enlargedAnimationPanel; CardPanel enlargedCardPanel, enlargedAnimationPanel;
synchronized (enlargeLock) { synchronized (enlargeLock) {
delayedCardPanel = null; delayedCardPanel = null;
delayedTime = 0; delayedTime = 0;
enlargedCardPanel = Animation.enlargedCardPanel; enlargedCardPanel = Animation.enlargedCardPanel;
enlargedAnimationPanel = Animation.enlargedAnimationPanel; enlargedAnimationPanel = Animation.enlargedAnimationPanel;
if (enlargedAnimationPanel == null) return; if (enlargedAnimationPanel == null) {
return;
}
Animation.enlargedCardPanel = null; Animation.enlargedCardPanel = null;
Animation.enlargedAnimationPanel = null; Animation.enlargedAnimationPanel = null;
} }
@@ -345,10 +415,11 @@ abstract public class Animation {
final int endHeight = Math.round(endWidth * CardPanel.ASPECT_RATIO); final int endHeight = Math.round(endWidth * CardPanel.ASPECT_RATIO);
new Animation(200) { new Animation(200) {
protected void update(float percentage) { protected void update(final float percentage) {
int currentWidth = startWidth + Math.round((endWidth - startWidth) * percentage); int currentWidth = startWidth + Math.round((endWidth - startWidth) * percentage);
int currentHeight = startHeight + Math.round((endHeight - startHeight) * percentage); int currentHeight = startHeight + Math.round((endHeight - startHeight) * percentage);
Point startPos = SwingUtilities.convertPoint(overPanel.getParent(), overPanel.getCardLocation(), layeredPane); Point startPos = SwingUtilities.convertPoint(overPanel.getParent(), overPanel.getCardLocation(),
layeredPane);
int centerX = startPos.x + Math.round(endWidth / 2f); int centerX = startPos.x + Math.round(endWidth / 2f);
int centerY = startPos.y + Math.round(endHeight / 2f); int centerY = startPos.y + Math.round(endHeight / 2f);
int currentX = Math.max(0, centerX - Math.round(currentWidth / 2f)); int currentX = Math.max(0, centerX - Math.round(currentWidth / 2f));
@@ -372,13 +443,18 @@ abstract public class Animation {
} }
/** /**
* <p>enlargeCard.</p> * <p>
* * enlargeCard.
* @param overPanel a {@link arcane.ui.CardPanel} object. * </p>
* @param clientFrame a {@link java.awt.Frame} object. *
* @param delay a long. * @param overPanel
* a {@link arcane.ui.CardPanel} object.
* @param clientFrame
* a {@link java.awt.Frame} object.
* @param delay
* a long.
*/ */
static public void enlargeCard(final CardPanel overPanel, final Frame clientFrame, long delay) { public static void enlargeCard(final CardPanel overPanel, final Frame clientFrame, final long delay) {
if (SwingUtilities.getRootPane(overPanel) == null) { if (SwingUtilities.getRootPane(overPanel) == null) {
synchronized (enlargeLock) { synchronized (enlargeLock) {
delayedCardPanel = null; delayedCardPanel = null;
@@ -386,7 +462,9 @@ abstract public class Animation {
if (Animation.enlargedCardPanel != null) { if (Animation.enlargedCardPanel != null) {
Animation.enlargedCardPanel = null; Animation.enlargedCardPanel = null;
} }
if (enlargedAnimationPanel == null) return; if (enlargedAnimationPanel == null) {
return;
}
Animation.enlargedAnimationPanel.setVisible(false); Animation.enlargedAnimationPanel.setVisible(false);
Animation.enlargedAnimationPanel.repaint(); Animation.enlargedAnimationPanel.repaint();
@@ -400,12 +478,20 @@ abstract public class Animation {
final int startHeight = Math.round(startWidth * CardPanel.ASPECT_RATIO); final int startHeight = Math.round(startWidth * CardPanel.ASPECT_RATIO);
final int endWidth = 300; final int endWidth = 300;
final int endHeight = Math.round(endWidth * CardPanel.ASPECT_RATIO); final int endHeight = Math.round(endWidth * CardPanel.ASPECT_RATIO);
if (startWidth >= endWidth) return; if (startWidth >= endWidth) {
return;
}
long delayedTime; long delayedTime;
synchronized (enlargeLock) { synchronized (enlargeLock) {
if (enlargedCardPanel == overPanel) return; // Already showing this card enlarged. if (enlargedCardPanel == overPanel)
if (delay > 0 && delayedCardPanel == overPanel) return; // Already delayed this card. {
return; // Already showing this card enlarged.
}
if (delay > 0 && delayedCardPanel == overPanel)
{
return; // Already delayed this card.
}
delayedCardPanel = overPanel; delayedCardPanel = overPanel;
Animation.delayedTime = System.currentTimeMillis(); Animation.delayedTime = System.currentTimeMillis();
delayedTime = Animation.delayedTime; delayedTime = Animation.delayedTime;
@@ -418,8 +504,10 @@ abstract public class Animation {
new Animation(200, delay) { new Animation(200, delay) {
protected void start() { protected void start() {
synchronized (enlargeLock) { synchronized (enlargeLock) {
// Cancel if the panel is no longer delayed or already shown. // Cancel if the panel is no longer delayed or already
if (delayedCardPanel != overPanel || thisDelayedTime != Animation.delayedTime || enlargedCardPanel == overPanel) { // shown.
if (delayedCardPanel != overPanel || thisDelayedTime != Animation.delayedTime
|| enlargedCardPanel == overPanel) {
cancel(); cancel();
return; return;
} }
@@ -429,7 +517,7 @@ abstract public class Animation {
Point startPos = overPanel.getCardLocation(); Point startPos = overPanel.getCardLocation();
animationPanel.setCardBounds(startPos.x, startPos.y, startWidth, startHeight); animationPanel.setCardBounds(startPos.x, startPos.y, startWidth, startHeight);
} }
//clientFrame.clearArrows(); // clientFrame.clearArrows();
animationPanel.tappedAngle = overPanel.tappedAngle; animationPanel.tappedAngle = overPanel.tappedAngle;
try { try {
Util.invokeAndWait(new Runnable() { Util.invokeAndWait(new Runnable() {
@@ -442,7 +530,7 @@ abstract public class Animation {
} }
} }
protected void update(float percentage) { protected void update(final float percentage) {
synchronized (enlargeLock) { synchronized (enlargeLock) {
if (enlargedAnimationPanel != animationPanel) { if (enlargedAnimationPanel != animationPanel) {
cancel(); cancel();
@@ -451,7 +539,8 @@ abstract public class Animation {
} }
int currentWidth = startWidth + Math.round((endWidth - startWidth) * percentage); int currentWidth = startWidth + Math.round((endWidth - startWidth) * percentage);
int currentHeight = startHeight + Math.round((endHeight - startHeight) * percentage); int currentHeight = startHeight + Math.round((endHeight - startHeight) * percentage);
Point startPos = SwingUtilities.convertPoint(overPanel.getParent(), overPanel.getCardLocation(), layeredPane); Point startPos = SwingUtilities.convertPoint(overPanel.getParent(), overPanel.getCardLocation(),
layeredPane);
int centerX = startPos.x + Math.round(startWidth / 2f); int centerX = startPos.x + Math.round(startWidth / 2f);
int centerY = startPos.y + Math.round(startHeight / 2f); int centerY = startPos.y + Math.round(startHeight / 2f);
int currentX = Math.max(0, centerX - Math.round(currentWidth / 2f)); int currentX = Math.max(0, centerX - Math.round(currentWidth / 2f));
@@ -465,11 +554,13 @@ abstract public class Animation {
} }
/** /**
* <p>isShowingEnlargedCard.</p> * <p>
* * isShowingEnlargedCard.
* </p>
*
* @return a boolean. * @return a boolean.
*/ */
static public boolean isShowingEnlargedCard() { public static boolean isShowingEnlargedCard() {
synchronized (enlargeLock) { synchronized (enlargeLock) {
return enlargedAnimationPanel != null; return enlargedAnimationPanel != null;
} }

View File

@@ -17,7 +17,7 @@ public interface CardPanelMouseListener {
* @param panel a {@link arcane.ui.CardPanel} object. * @param panel a {@link arcane.ui.CardPanel} object.
* @param evt a {@link java.awt.event.MouseEvent} object. * @param evt a {@link java.awt.event.MouseEvent} object.
*/ */
public void mouseOver(CardPanel panel, MouseEvent evt); void mouseOver(CardPanel panel, MouseEvent evt);
/** /**
* <p>mouseOut.</p> * <p>mouseOut.</p>
@@ -25,7 +25,7 @@ public interface CardPanelMouseListener {
* @param panel a {@link arcane.ui.CardPanel} object. * @param panel a {@link arcane.ui.CardPanel} object.
* @param evt a {@link java.awt.event.MouseEvent} object. * @param evt a {@link java.awt.event.MouseEvent} object.
*/ */
public void mouseOut(CardPanel panel, MouseEvent evt); void mouseOut(CardPanel panel, MouseEvent evt);
/** /**
* <p>mouseLeftClicked.</p> * <p>mouseLeftClicked.</p>
@@ -33,7 +33,7 @@ public interface CardPanelMouseListener {
* @param panel a {@link arcane.ui.CardPanel} object. * @param panel a {@link arcane.ui.CardPanel} object.
* @param evt a {@link java.awt.event.MouseEvent} object. * @param evt a {@link java.awt.event.MouseEvent} object.
*/ */
public void mouseLeftClicked(CardPanel panel, MouseEvent evt); void mouseLeftClicked(CardPanel panel, MouseEvent evt);
/** /**
* <p>mouseMiddleClicked.</p> * <p>mouseMiddleClicked.</p>
@@ -41,7 +41,7 @@ public interface CardPanelMouseListener {
* @param panel a {@link arcane.ui.CardPanel} object. * @param panel a {@link arcane.ui.CardPanel} object.
* @param evt a {@link java.awt.event.MouseEvent} object. * @param evt a {@link java.awt.event.MouseEvent} object.
*/ */
public void mouseMiddleClicked(CardPanel panel, MouseEvent evt); void mouseMiddleClicked(CardPanel panel, MouseEvent evt);
/** /**
* <p>mouseRightClicked.</p> * <p>mouseRightClicked.</p>
@@ -49,7 +49,7 @@ public interface CardPanelMouseListener {
* @param panel a {@link arcane.ui.CardPanel} object. * @param panel a {@link arcane.ui.CardPanel} object.
* @param evt a {@link java.awt.event.MouseEvent} object. * @param evt a {@link java.awt.event.MouseEvent} object.
*/ */
public void mouseRightClicked(CardPanel panel, MouseEvent evt); void mouseRightClicked(CardPanel panel, MouseEvent evt);
/** /**
* <p>mouseDragStart.</p> * <p>mouseDragStart.</p>
@@ -57,7 +57,7 @@ public interface CardPanelMouseListener {
* @param dragPanel a {@link arcane.ui.CardPanel} object. * @param dragPanel a {@link arcane.ui.CardPanel} object.
* @param evt a {@link java.awt.event.MouseEvent} object. * @param evt a {@link java.awt.event.MouseEvent} object.
*/ */
public void mouseDragStart(CardPanel dragPanel, MouseEvent evt); void mouseDragStart(CardPanel dragPanel, MouseEvent evt);
/** /**
* <p>mouseDragged.</p> * <p>mouseDragged.</p>
@@ -67,7 +67,7 @@ public interface CardPanelMouseListener {
* @param dragOffsetY a int. * @param dragOffsetY a int.
* @param evt a {@link java.awt.event.MouseEvent} object. * @param evt a {@link java.awt.event.MouseEvent} object.
*/ */
public void mouseDragged(CardPanel dragPanel, int dragOffsetX, int dragOffsetY, MouseEvent evt); void mouseDragged(CardPanel dragPanel, int dragOffsetX, int dragOffsetY, MouseEvent evt);
/** /**
* <p>mouseDragEnd.</p> * <p>mouseDragEnd.</p>
@@ -75,5 +75,5 @@ public interface CardPanelMouseListener {
* @param dragPanel a {@link arcane.ui.CardPanel} object. * @param dragPanel a {@link arcane.ui.CardPanel} object.
* @param evt a {@link java.awt.event.MouseEvent} object. * @param evt a {@link java.awt.event.MouseEvent} object.
*/ */
public void mouseDragEnd(CardPanel dragPanel, MouseEvent evt); void mouseDragEnd(CardPanel dragPanel, MouseEvent evt);
} }

View File

@@ -1,7 +1,11 @@
package arcane.ui.util; package arcane.ui.util;
import javax.swing.*; import java.awt.AlphaComposite;
import java.awt.*; import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.font.FontRenderContext; import java.awt.font.FontRenderContext;
import java.awt.font.LineBreakMeasurer; import java.awt.font.LineBreakMeasurer;
import java.awt.font.TextAttribute; import java.awt.font.TextAttribute;
@@ -11,46 +15,60 @@ import java.text.AttributedString;
import java.text.BreakIterator; import java.text.BreakIterator;
import java.util.Locale; import java.util.Locale;
import javax.swing.JLabel;
/** /**
* <p>GlowText class.</p> * <p>
* * GlowText class.
* </p>
*
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class GlowText extends JLabel { public class GlowText extends JLabel {
/** Constant <code>serialVersionUID=-2868833097364223352L</code> */ /** Constant <code>serialVersionUID=-2868833097364223352L</code>. */
private static final long serialVersionUID = -2868833097364223352L; private static final long serialVersionUID = -2868833097364223352L;
private int glowSize; private int glowSize;
private Color glowColor; private Color glowColor;
private boolean wrap; private boolean wrap;
/** /**
* <p>setGlow.</p> * <p>
* * setGlow.
* @param glowColor a {@link java.awt.Color} object. * </p>
* @param size a int. *
* @param intensity a float. * @param glowColor
* a {@link java.awt.Color} object.
* @param size
* a int.
* @param intensity
* a float.
*/ */
public void setGlow(Color glowColor, int size, float intensity) { public final void setGlow(final Color glowColor, int size, float intensity) {
this.glowColor = glowColor; this.glowColor = glowColor;
this.glowSize = size; this.glowSize = size;
} }
/** /**
* <p>Setter for the field <code>wrap</code>.</p> * <p>
* * Setter for the field <code>wrap</code>.
* @param wrap a boolean. * </p>
*
* @param wrap
* a boolean.
*/ */
public void setWrap(boolean wrap) { public final void setWrap(final boolean wrap) {
this.wrap = wrap; this.wrap = wrap;
} }
/** /**
* <p>getPreferredSize.</p> * <p>
* * getPreferredSize.
* </p>
*
* @return a {@link java.awt.Dimension} object. * @return a {@link java.awt.Dimension} object.
*/ */
public Dimension getPreferredSize() { public final Dimension getPreferredSize() {
Dimension size = super.getPreferredSize(); Dimension size = super.getPreferredSize();
size.width += glowSize; size.width += glowSize;
size.height += glowSize / 2; size.height += glowSize / 2;
@@ -58,13 +76,15 @@ public class GlowText extends JLabel {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public void setText(String text) { public final void setText(final String text) {
super.setText(text); super.setText(text);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public void paint(Graphics g) { public final void paint(final Graphics g) {
if (getText().length() == 0) return; if (getText().length() == 0) {
return;
}
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
@@ -79,19 +99,24 @@ public class GlowText extends JLabel {
AttributedCharacterIterator charIterator = attributedString.getIterator(); AttributedCharacterIterator charIterator = attributedString.getIterator();
FontRenderContext fontContext = g2d.getFontRenderContext(); FontRenderContext fontContext = g2d.getFontRenderContext();
LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, BreakIterator.getWordInstance(Locale.ENGLISH), fontContext); LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, BreakIterator.getWordInstance(Locale.ENGLISH),
fontContext);
int lineCount = 0; int lineCount = 0;
while (measurer.getPosition() < charIterator.getEndIndex()) { while (measurer.getPosition() < charIterator.getEndIndex()) {
measurer.nextLayout(wrapWidth); measurer.nextLayout(wrapWidth);
lineCount++; lineCount++;
if (lineCount > 2) break; if (lineCount > 2) {
break;
}
} }
charIterator.first(); charIterator.first();
// Use char wrap if word wrap would cause more than two lines of text. // Use char wrap if word wrap would cause more than two lines of text.
if (lineCount > 2) if (lineCount > 2) {
measurer = new LineBreakMeasurer(charIterator, BreakIterator.getCharacterInstance(Locale.ENGLISH), fontContext); measurer = new LineBreakMeasurer(charIterator, BreakIterator.getCharacterInstance(Locale.ENGLISH),
else fontContext);
} else {
measurer.setPosition(0); measurer.setPosition(0);
}
while (measurer.getPosition() < charIterator.getEndIndex()) { while (measurer.getPosition() < charIterator.getEndIndex()) {
TextLayout textLayout = measurer.nextLayout(wrapWidth); TextLayout textLayout = measurer.nextLayout(wrapWidth);
float ascent = textLayout.getAscent(); float ascent = textLayout.getAscent();
@@ -108,7 +133,13 @@ public class GlowText extends JLabel {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
textLayout.draw(g2d, textX + glowSize / 2, textY + glowSize / 2); textLayout.draw(g2d, textX + glowSize / 2, textY + glowSize / 2);
textY += textLayout.getDescent() + textLayout.getLeading(); // Move down to top of next line. textY += textLayout.getDescent() + textLayout.getLeading(); // Move
// down
// to
// top
// of
// next
// line.
} }
} }
} }

View File

@@ -1,7 +1,7 @@
package arcane.ui.util; package arcane.ui.util;
import javax.imageio.ImageIO; import java.awt.Graphics2D;
import java.awt.*; import java.awt.Image;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.image.ConvolveOp; import java.awt.image.ConvolveOp;
import java.awt.image.Kernel; import java.awt.image.Kernel;
@@ -9,23 +9,32 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import javax.imageio.ImageIO;
/** /**
* <p>ImageUtil class.</p> * <p>
* * ImageUtil class.
* </p>
*
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class ImageUtil { public class ImageUtil {
/** /**
* <p>getImage.</p> * <p>
* * getImage.
* @param stream a {@link java.io.InputStream} object. * </p>
*
* @param stream
* a {@link java.io.InputStream} object.
* @return a {@link java.awt.image.BufferedImage} object. * @return a {@link java.awt.image.BufferedImage} object.
* @throws java.io.IOException if any. * @throws java.io.IOException
* if any.
*/ */
static public BufferedImage getImage(InputStream stream) throws IOException { public static BufferedImage getImage(final InputStream stream) throws IOException {
Image tempImage = ImageIO.read(stream); Image tempImage = ImageIO.read(stream);
BufferedImage image = new BufferedImage(tempImage.getWidth(null), tempImage.getHeight(null), BufferedImage.TYPE_INT_ARGB); BufferedImage image = new BufferedImage(tempImage.getWidth(null), tempImage.getHeight(null),
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = image.createGraphics(); Graphics2D g2 = image.createGraphics();
g2.drawImage(tempImage, 0, 0, null); g2.drawImage(tempImage, 0, 0, null);
g2.dispose(); g2.dispose();
@@ -33,15 +42,20 @@ public class ImageUtil {
} }
/** /**
* <p>getImage.</p> * <p>
* * getImage.
* @param file a {@link java.io.File} object. * </p>
*
* @param file
* a {@link java.io.File} object.
* @return a {@link java.awt.image.BufferedImage} object. * @return a {@link java.awt.image.BufferedImage} object.
* @throws java.io.IOException if any. * @throws java.io.IOException
* if any.
*/ */
static public BufferedImage getImage(File file) throws IOException { public static BufferedImage getImage(final File file) throws IOException {
Image tempImage = ImageIO.read(file); Image tempImage = ImageIO.read(file);
BufferedImage image = new BufferedImage(tempImage.getWidth(null), tempImage.getHeight(null), BufferedImage.TYPE_INT_ARGB); BufferedImage image = new BufferedImage(tempImage.getWidth(null), tempImage.getHeight(null),
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = image.createGraphics(); Graphics2D g2 = image.createGraphics();
g2.drawImage(tempImage, 0, 0, null); g2.drawImage(tempImage, 0, 0, null);
g2.dispose(); g2.dispose();
@@ -49,18 +63,24 @@ public class ImageUtil {
} }
/** /**
* <p>getBlurredImage.</p> * <p>
* * getBlurredImage.
* @param image a {@link java.awt.image.BufferedImage} object. * </p>
* @param radius a int. *
* @param intensity a float. * @param image
* a {@link java.awt.image.BufferedImage} object.
* @param radius
* a int.
* @param intensity
* a float.
* @return a {@link java.awt.image.BufferedImage} object. * @return a {@link java.awt.image.BufferedImage} object.
*/ */
static public BufferedImage getBlurredImage(BufferedImage image, int radius, float intensity) { public static BufferedImage getBlurredImage(final BufferedImage image, final int radius, final float intensity) {
float weight = intensity / (radius * radius); float weight = intensity / (radius * radius);
float[] elements = new float[radius * radius]; float[] elements = new float[radius * radius];
for (int i = 0, n = radius * radius; i < n; i++) for (int i = 0, n = radius * radius; i < n; i++) {
elements[i] = weight; elements[i] = weight;
}
ConvolveOp blurOp = new ConvolveOp(new Kernel(radius, radius, elements)); ConvolveOp blurOp = new ConvolveOp(new Kernel(radius, radius, elements));
return blurOp.filter(image, null); return blurOp.filter(image, null);
} }

View File

@@ -1,49 +1,62 @@
package arcane.ui.util; package arcane.ui.util;
import com.esotericsoftware.minlog.Log; import java.awt.Graphics;
import java.awt.Image;
import java.awt.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.esotericsoftware.minlog.Log;
/** /**
* <p>ManaSymbols class.</p> * <p>
* * ManaSymbols class.
* </p>
*
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class ManaSymbols { public class ManaSymbols {
/** Constant <code>manaImages</code> */ /** Constant <code>manaImages</code>. */
static private final Map<String, Image> manaImages = new HashMap<String, Image>(); private static final Map<String, Image> manaImages = new HashMap<String, Image>();
/** Constant <code>replaceSymbolsPattern</code> */ /** Constant <code>replaceSymbolsPattern</code>. */
static private Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}"); private static Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
/** /**
* <p>loadImages.</p> * <p>
* loadImages.
* </p>
*/ */
static public void loadImages() { public static void loadImages() {
String[] symbols = new String[]{"0", "1", "10", "11", "12", "15", "16", "2", "20", "2W", "2U", "2R", "2G", "2B", "3", String[] symbols = new String[] {"0", "1", "10", "11", "12", "15", "16", "2", "20", "2W", "2U", "2R", "2G",
"4", "5", "6", "7", "8", "9", "B", "BG", "BR", "G", "GU", "GW", "R", "RG", "RW", "S", "T", "U", "UB", "2B", "3", "4", "5", "6", "7", "8", "9", "B", "BG", "BR", "G", "GU", "GW", "R", "RG", "RW", "S", "T",
"UR", "W", "WB", "WU", "PW", "PU", "PB", "PR", "PG", "X", "Y", "Z", "slash", "attack", "defend", "summonsick", "U", "UB", "UR", "W", "WB", "WU", "PW", "PU", "PB", "PR", "PG", "X", "Y", "Z", "slash", "attack",
"phasing", "counters1", "counters2", "counters3", "countersMulti", "defend", "summonsick", "phasing", "counters1", "counters2", "counters3", "countersMulti", "foil01",
"foil01","foil02","foil03","foil04","foil05","foil06","foil07","foil08","foil09","foil10"}; "foil02", "foil03", "foil04", "foil05", "foil06", "foil07", "foil08", "foil09", "foil10" };
for (String symbol : symbols) for (String symbol : symbols) {
manaImages.put(symbol, UI.getImageIcon("res/images/symbols-13/" + symbol + ".png").getImage()); manaImages.put(symbol, UI.getImageIcon("res/images/symbols-13/" + symbol + ".png").getImage());
}
} }
/** /**
* <p>draw.</p> * <p>
* * draw.
* @param g a {@link java.awt.Graphics} object. * </p>
* @param manaCost a {@link java.lang.String} object. *
* @param x a int. * @param g
* @param y a int. * a {@link java.awt.Graphics} object.
* @param manaCost
* a {@link java.lang.String} object.
* @param x
* a int.
* @param y
* a int.
*/ */
static public void draw(Graphics g, String manaCost, int x, int y) { public static void draw(Graphics g, String manaCost, int x, int y) {
if (manaCost.length() == 0) return; if (manaCost.length() == 0) {
return;
}
manaCost = UI.getDisplayManaCost(manaCost); manaCost = UI.getDisplayManaCost(manaCost);
StringTokenizer tok = new StringTokenizer(manaCost, " "); StringTokenizer tok = new StringTokenizer(manaCost, " ");
while (tok.hasMoreTokens()) { while (tok.hasMoreTokens()) {
@@ -54,12 +67,25 @@ public class ManaSymbols {
continue; continue;
} }
g.drawImage(image, x, y, null); g.drawImage(image, x, y, null);
x += symbol.length() > 2 ? 10 : 14; // slash.png is only 10 pixels wide. x += symbol.length() > 2 ? 10 : 14; // slash.png is only 10 pixels
// wide.
} }
} }
static public void draw(Graphics g, String s, int x, int y, int w, int h) { /**
if (s.length() == 0) return; *
* draw.
* @param g a Graphics
* @param s a STring
* @param x an int
* @param y an int
* @param w an int
* @param h and int
*/
public static void draw(final Graphics g, String s, int x, final int y, final int w, final int h) {
if (s.length() == 0) {
return;
}
s = UI.getDisplayManaCost(s); s = UI.getDisplayManaCost(s);
StringTokenizer tok = new StringTokenizer(s, " "); StringTokenizer tok = new StringTokenizer(s, " ");
while (tok.hasMoreTokens()) { while (tok.hasMoreTokens()) {
@@ -69,69 +95,90 @@ public class ManaSymbols {
Log.info("Symbol not recognized \"" + symbol + "\" in string: " + s); Log.info("Symbol not recognized \"" + symbol + "\" in string: " + s);
continue; continue;
} }
//g.drawImage(image, x, y, null); // g.drawImage(image, x, y, null);
g.drawImage(image, x, y, w, h, null); g.drawImage(image, x, y, w, h, null);
x += symbol.length() > 2 ? 10 : 14; // slash.png is only 10 pixels wide. x += symbol.length() > 2 ? 10 : 14; // slash.png is only 10 pixels
// wide.
} }
} }
/** /**
* <p>drawAttack.</p> * <p>
* * drawAttack.
* @param g a {@link java.awt.Graphics} object. * </p>
* @param x a int. *
* @param y a int. * @param g
* a {@link java.awt.Graphics} object.
* @param x
* a int.
* @param y
* a int.
*/ */
static public void drawAttack(Graphics g, int x, int y) { public static void drawAttack(final Graphics g, final int x, final int y) {
Image image = manaImages.get("attack"); Image image = manaImages.get("attack");
g.drawImage(image, x, y, null); g.drawImage(image, x, y, null);
} }
/** /**
* <p>drawSymbol.</p> * <p>
* * drawSymbol.
* @param imageName a {@link java.lang.String} object. * </p>
* @param g a {@link java.awt.Graphics} object. *
* @param x a int. * @param imageName
* @param y a int. * a {@link java.lang.String} object.
* @param g
* a {@link java.awt.Graphics} object.
* @param x
* a int.
* @param y
* a int.
*/ */
static public void drawSymbol(String imageName, Graphics g, int x, int y) { public static void drawSymbol(final String imageName, final Graphics g, final int x, final int y) {
Image image = manaImages.get(imageName); Image image = manaImages.get(imageName);
g.drawImage(image, x, y, null); g.drawImage(image, x, y, null);
} }
/** /**
* <p>getWidth.</p> * <p>
* * getWidth.
* @param manaCost a {@link java.lang.String} object. * </p>
*
* @param manaCost
* a {@link java.lang.String} object.
* @return a int. * @return a int.
*/ */
static public int getWidth(String manaCost) { public static int getWidth(final String manaCost) {
int width = 0; int width = 0;
StringTokenizer tok = new StringTokenizer(manaCost, " "); StringTokenizer tok = new StringTokenizer(manaCost, " ");
while (tok.hasMoreTokens()) { while (tok.hasMoreTokens()) {
String symbol = tok.nextToken(); String symbol = tok.nextToken();
width += symbol.length() > 2 ? 10 : 14; // slash.png is only 10 pixels wide. width += symbol.length() > 2 ? 10 : 14; // slash.png is only 10
// pixels wide.
} }
return width; return width;
} }
/** /**
* <p>replaceSymbolsWithHTML.</p> * <p>
* * replaceSymbolsWithHTML.
* @param value a {@link java.lang.String} object. * </p>
* @param small a boolean. *
* @param value
* a {@link java.lang.String} object.
* @param small
* a boolean.
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
static public synchronized String replaceSymbolsWithHTML(String value, boolean small) { public static synchronized String replaceSymbolsWithHTML(String value, final boolean small) {
if (small) { if (small) {
value = value.replace("{C}", "<img src='file:res/images/symbols-11/C.png' width=13 height=11>"); value = value.replace("{C}", "<img src='file:res/images/symbols-11/C.png' width=13 height=11>");
return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:res/images/symbols-11/$1$2.png' width=11 height=11>"); return replaceSymbolsPattern.matcher(value).replaceAll(
"<img src='file:res/images/symbols-11/$1$2.png' width=11 height=11>");
} else { } else {
value = value.replace("{slash}", "<img src='file:res/images/symbols-13/slash.png' width=10 height=13>"); value = value.replace("{slash}", "<img src='file:res/images/symbols-13/slash.png' width=10 height=13>");
value = value.replace("{C}", "<img src='file:res/images/symbols-13/C.png' width=16 height=13>"); value = value.replace("{C}", "<img src='file:res/images/symbols-13/C.png' width=16 height=13>");
return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:res/images/symbols-13/$1$2.png' width=13 height=13>"); return replaceSymbolsPattern.matcher(value).replaceAll(
"<img src='file:res/images/symbols-13/$1$2.png' width=13 height=13>");
} }
} }
} }

View File

@@ -1,18 +1,14 @@
package arcane.ui.util; package arcane.ui.util;
import com.google.common.collect.MapMaker; import java.awt.Component;
import java.awt.Container;
import javax.swing.*; import java.awt.Dimension;
import javax.swing.border.Border; import java.awt.EventQueue;
import javax.swing.border.TitledBorder; import java.awt.Font;
import javax.swing.text.Element; import java.awt.Image;
import javax.swing.text.StyleConstants; import java.awt.Insets;
import javax.swing.text.View; import java.awt.Point;
import javax.swing.text.ViewFactory; import java.awt.Toolkit;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.ImageView;
import java.awt.*;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
@@ -25,60 +21,95 @@ import java.net.URL;
import java.util.Collections; import java.util.Collections;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JToggleButton;
import javax.swing.JViewport;
import javax.swing.ScrollPaneConstants;
import javax.swing.UIManager;
import javax.swing.ViewportLayout;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import javax.swing.text.Element;
import javax.swing.text.StyleConstants;
import javax.swing.text.View;
import javax.swing.text.ViewFactory;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.ImageView;
import com.google.common.collect.MapMaker;
/** /**
* UI utility functions. * UI utility functions.
* *
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class UI { public class UI {
/** Constant <code>imageCache</code> */ /** Constant <code>imageCache</code>. */
static private ConcurrentMap<URI, Image> imageCache = new MapMaker().softValues().makeMap(); private static ConcurrentMap<URI, Image> imageCache = new MapMaker().softValues().makeMap();
/** /**
* <p>getToggleButton.</p> * <p>
* * getToggleButton.
* </p>
*
* @return a {@link javax.swing.JToggleButton} object. * @return a {@link javax.swing.JToggleButton} object.
*/ */
static public JToggleButton getToggleButton() { public static JToggleButton getToggleButton() {
JToggleButton button = new JToggleButton(); JToggleButton button = new JToggleButton();
button.setMargin(new Insets(2, 4, 2, 4)); button.setMargin(new Insets(2, 4, 2, 4));
return button; return button;
} }
/** /**
* <p>getButton.</p> * <p>
* * getButton.
* </p>
*
* @return a {@link javax.swing.JButton} object. * @return a {@link javax.swing.JButton} object.
*/ */
static public JButton getButton() { public static JButton getButton() {
JButton button = new JButton(); JButton button = new JButton();
button.setMargin(new Insets(2, 4, 2, 4)); button.setMargin(new Insets(2, 4, 2, 4));
return button; return button;
} }
/** /**
* <p>setTitle.</p> * <p>
* * setTitle.
* @param panel a {@link javax.swing.JPanel} object. * </p>
* @param title a {@link java.lang.String} object. *
* @param panel
* a {@link javax.swing.JPanel} object.
* @param title
* a {@link java.lang.String} object.
*/ */
static public void setTitle(JPanel panel, String title) { public static void setTitle(final JPanel panel, final String title) {
Border border = panel.getBorder(); Border border = panel.getBorder();
if (border instanceof TitledBorder) { if (border instanceof TitledBorder) {
((TitledBorder) panel.getBorder()).setTitle(title); ((TitledBorder) panel.getBorder()).setTitle(title);
panel.repaint(); panel.repaint();
} else } else {
panel.setBorder(BorderFactory.createTitledBorder(title)); panel.setBorder(BorderFactory.createTitledBorder(title));
}
} }
/** /**
* <p>getFileURL.</p> * <p>
* * getFileURL.
* @param path a {@link java.lang.String} object. * </p>
*
* @param path
* a {@link java.lang.String} object.
* @return a {@link java.net.URL} object. * @return a {@link java.net.URL} object.
*/ */
static public URL getFileURL(String path) { public static URL getFileURL(final String path) {
File file = new File(path); File file = new File(path);
if (file.exists()) { if (file.exists()) {
try { try {
@@ -90,24 +121,32 @@ public class UI {
} }
/** /**
* <p>getImageIcon.</p> * <p>
* * getImageIcon.
* @param path a {@link java.lang.String} object. * </p>
*
* @param path
* a {@link java.lang.String} object.
* @return a {@link javax.swing.ImageIcon} object. * @return a {@link javax.swing.ImageIcon} object.
*/ */
static public ImageIcon getImageIcon(String path) { public static ImageIcon getImageIcon(final String path) {
InputStream stream = null; InputStream stream = null;
try { try {
try { try {
stream = UI.class.getResourceAsStream(path); stream = UI.class.getResourceAsStream(path);
if (stream == null && new File(path).exists()) stream = new FileInputStream(path); if (stream == null && new File(path).exists()) {
if (stream == null) throw new RuntimeException("Image not found: " + path); stream = new FileInputStream(path);
}
if (stream == null) {
throw new RuntimeException("Image not found: " + path);
}
byte[] data = new byte[stream.available()]; byte[] data = new byte[stream.available()];
stream.read(data); stream.read(data);
return new ImageIcon(data); return new ImageIcon(data);
} finally { } finally {
if (stream != null) if (stream != null) {
stream.close(); stream.close();
}
} }
} catch (IOException ex) { } catch (IOException ex) {
throw new RuntimeException("Error reading image: " + path); throw new RuntimeException("Error reading image: " + path);
@@ -115,34 +154,48 @@ public class UI {
} }
/** /**
* <p>setHTMLEditorKit.</p> * <p>
* * setHTMLEditorKit.
* @param editorPane a {@link javax.swing.JEditorPane} object. * </p>
*
* @param editorPane
* a {@link javax.swing.JEditorPane} object.
*/ */
static public void setHTMLEditorKit(JEditorPane editorPane) { public static void setHTMLEditorKit(final JEditorPane editorPane) {
editorPane.getDocument().putProperty("imageCache", imageCache); // Read internally by ImageView, but never written. editorPane.getDocument().putProperty("imageCache", imageCache); // Read
// internally
// by
// ImageView,
// but
// never
// written.
// Extend all this shit to cache images. // Extend all this shit to cache images.
editorPane.setEditorKit(new HTMLEditorKit() { editorPane.setEditorKit(new HTMLEditorKit() {
private static final long serialVersionUID = -562969765076450440L; private static final long serialVersionUID = -562969765076450440L;
public ViewFactory getViewFactory() { public ViewFactory getViewFactory() {
return new HTMLFactory() { return new HTMLFactory() {
public View create(Element elem) { public View create(final Element elem) {
Object o = elem.getAttributes().getAttribute(StyleConstants.NameAttribute); Object o = elem.getAttributes().getAttribute(StyleConstants.NameAttribute);
if (o instanceof HTML.Tag) { if (o instanceof HTML.Tag) {
HTML.Tag kind = (HTML.Tag) o; HTML.Tag kind = (HTML.Tag) o;
if (kind == HTML.Tag.IMG) return new ImageView(elem) { if (kind == HTML.Tag.IMG) {
public URL getImageURL() { return new ImageView(elem) {
URL url = super.getImageURL(); public URL getImageURL() {
// Put an image into the cache to be read by other ImageView methods. URL url = super.getImageURL();
if (url != null && imageCache.get(url) == null) // Put an image into the cache to be
try { // read by other ImageView methods.
imageCache.put(url.toURI(), Toolkit.getDefaultToolkit().createImage(url)); if (url != null && imageCache.get(url) == null) {
} catch (URISyntaxException e) { try {
imageCache.put(url.toURI(), Toolkit.getDefaultToolkit()
.createImage(url));
} catch (URISyntaxException e) {
}
} }
return url; return url;
} }
}; };
}
} }
return super.create(elem); return super.create(elem);
} }
@@ -152,17 +205,21 @@ public class UI {
} }
/** /**
* <p>setVerticalScrollingView.</p> * <p>
* * setVerticalScrollingView.
* @param scrollPane a {@link javax.swing.JScrollPane} object. * </p>
* @param view a {@link java.awt.Component} object. *
* @param scrollPane
* a {@link javax.swing.JScrollPane} object.
* @param view
* a {@link java.awt.Component} object.
*/ */
static public void setVerticalScrollingView(JScrollPane scrollPane, final Component view) { public static void setVerticalScrollingView(final JScrollPane scrollPane, final Component view) {
final JViewport viewport = new JViewport(); final JViewport viewport = new JViewport();
viewport.setLayout(new ViewportLayout() { viewport.setLayout(new ViewportLayout() {
private static final long serialVersionUID = -4436977380450713628L; private static final long serialVersionUID = -4436977380450713628L;
public void layoutContainer(Container parent) { public void layoutContainer(final Container parent) {
viewport.setViewPosition(new Point(0, 0)); viewport.setViewPosition(new Point(0, 0));
Dimension viewportSize = viewport.getSize(); Dimension viewportSize = viewport.getSize();
int width = viewportSize.width; int width = viewportSize.width;
@@ -176,35 +233,47 @@ public class UI {
} }
/** /**
* <p>getDisplayManaCost.</p> * <p>
* * getDisplayManaCost.
* @param manaCost a {@link java.lang.String} object. * </p>
*
* @param manaCost
* a {@link java.lang.String} object.
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
static public String getDisplayManaCost(String manaCost) { public static String getDisplayManaCost(String manaCost) {
manaCost = manaCost.replace("/", ""); manaCost = manaCost.replace("/", "");
manaCost = manaCost.replace("X 0", "X"); manaCost = manaCost.replace("X 0", "X");
// A pipe in the cost means "process left of the pipe as the card color, but display right of the pipe as the cost". // A pipe in the cost means
// "process left of the pipe as the card color, but display right of the pipe as the cost".
int pipePosition = manaCost.indexOf("{|}"); int pipePosition = manaCost.indexOf("{|}");
if (pipePosition != -1) manaCost = manaCost.substring(pipePosition + 3); if (pipePosition != -1) {
manaCost = manaCost.substring(pipePosition + 3);
}
return manaCost; return manaCost;
} }
/** /**
* <p>invokeLater.</p> * <p>
* * invokeLater.
* @param runnable a {@link java.lang.Runnable} object. * </p>
*
* @param runnable
* a {@link java.lang.Runnable} object.
*/ */
static public void invokeLater(Runnable runnable) { public static void invokeLater(final Runnable runnable) {
EventQueue.invokeLater(runnable); EventQueue.invokeLater(runnable);
} }
/** /**
* <p>invokeAndWait.</p> * <p>
* * invokeAndWait.
* @param runnable a {@link java.lang.Runnable} object. * </p>
*
* @param runnable
* a {@link java.lang.Runnable} object.
*/ */
static public void invokeAndWait(Runnable runnable) { public static void invokeAndWait(final Runnable runnable) {
if (EventQueue.isDispatchThread()) { if (EventQueue.isDispatchThread()) {
runnable.run(); runnable.run();
return; return;
@@ -218,9 +287,11 @@ public class UI {
} }
/** /**
* <p>setSystemLookAndFeel.</p> * <p>
* setSystemLookAndFeel.
* </p>
*/ */
static public void setSystemLookAndFeel() { public static void setSystemLookAndFeel() {
try { try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception ex) { } catch (Exception ex) {
@@ -230,14 +301,19 @@ public class UI {
} }
/** /**
* <p>setDefaultFont.</p> * <p>
* * setDefaultFont.
* @param font a {@link java.awt.Font} object. * </p>
*
* @param font
* a {@link java.awt.Font} object.
*/ */
static public void setDefaultFont(Font font) { public static void setDefaultFont(final Font font) {
for (Object key : Collections.list(UIManager.getDefaults().keys())) { for (Object key : Collections.list(UIManager.getDefaults().keys())) {
Object value = UIManager.get(key); Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource) UIManager.put(key, font); if (value instanceof javax.swing.plaf.FontUIResource) {
UIManager.put(key, font);
}
} }
} }
} }

View File

@@ -1,2 +1,2 @@
/** Forge Card Game */ /** Forge Card Game. */
package arcane.ui.util; package arcane.ui.util;

View File

@@ -5,7 +5,7 @@ import java.io.OutputStream;
/** /**
* An OutputStream that writes to multiple other OutputStreams. * An OutputStream that writes to multiple other OutputStreams.
* *
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
@@ -13,25 +13,32 @@ public class MultiplexOutputStream extends OutputStream {
private final OutputStream[] streams; private final OutputStream[] streams;
/** /**
* <p>Constructor for MultiplexOutputStream.</p> * <p>
* * Constructor for MultiplexOutputStream.
* @param streams a {@link java.io.OutputStream} object. * </p>
*
* @param streams
* a {@link java.io.OutputStream} object.
*/ */
public MultiplexOutputStream(OutputStream... streams) { public MultiplexOutputStream(final OutputStream... streams) {
super(); super();
if (streams == null) throw new IllegalArgumentException("streams cannot be null."); if (streams == null) {
throw new IllegalArgumentException("streams cannot be null.");
}
this.streams = streams; this.streams = streams;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public void write(int b) throws IOException { public final void write(final int b) throws IOException {
for (int i = 0; i < streams.length; i++) for (int i = 0; i < streams.length; i++) {
streams[i].write(b); streams[i].write(b);
}
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public void write(byte[] b, int off, int len) throws IOException { public final void write(final byte[] b, final int off, final int len) throws IOException {
for (int i = 0; i < streams.length; i++) for (int i = 0; i < streams.length; i++) {
streams[i].write(b, off, len); streams[i].write(b, off, len);
}
} }
} }

View File

@@ -1,6 +1,5 @@
package arcane.util; package arcane.util;
import javax.swing.*;
import java.io.IOException; import java.io.IOException;
import java.net.DatagramPacket; import java.net.DatagramPacket;
import java.net.DatagramSocket; import java.net.DatagramSocket;
@@ -13,63 +12,91 @@ import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.swing.SwingUtilities;
/** /**
* <p>Util class.</p> * <p>
* * Util class.
* </p>
*
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class Util { public class Util {
/** Constant <code>isMac=System.getProperty("os.name").toLowerCase().indexOf("mac") != -1</code> */ /**
static public final boolean isMac = System.getProperty("os.name").toLowerCase().indexOf("mac") != -1; * Constant.
/** Constant <code>isWindows=System.getProperty("os.name").toLowerCase().indexOf("windows") == -1</code> */ * <code>isMac=System.getProperty("os.name").toLowerCase().indexOf("mac") != -1</code>.
static public final boolean isWindows = System.getProperty("os.name").toLowerCase().indexOf("windows") == -1; */
public static final boolean isMac = System.getProperty("os.name").toLowerCase().indexOf("mac") != -1;
/**
* Constant.
* <code>isWindows=System.getProperty("os.name").toLowerCase().indexOf("windows") == -1</code>
*/
public static final boolean isWindows = System.getProperty("os.name").toLowerCase().indexOf("windows") == -1;
/** Constant <code>threadPool</code> */ /** Constant <code>threadPool</code>. */
static public ThreadPoolExecutor threadPool; public static ThreadPoolExecutor threadPool;
/** Constant <code>threadCount</code> */ /** Constant <code>threadCount</code>. */
static private int threadCount; private static int threadCount;
static { static {
threadPool = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new ThreadFactory() { threadPool = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(),
public Thread newThread(Runnable runnable) { new ThreadFactory() {
threadCount++; public Thread newThread(final Runnable runnable) {
Thread thread = new Thread(runnable, "Util" + threadCount); threadCount++;
thread.setDaemon(true); Thread thread = new Thread(runnable, "Util" + threadCount);
return thread; thread.setDaemon(true);
} return thread;
}); }
});
threadPool.prestartAllCoreThreads(); threadPool.prestartAllCoreThreads();
} }
/** /**
* <p>broadcast.</p> * <p>
* * broadcast.
* @param data an array of byte. * </p>
* @param port a int. *
* @throws java.io.IOException if any. * @param data
* an array of byte.
* @param port
* a int.
* @throws java.io.IOException
* if any.
*/ */
public static void broadcast(byte[] data, int port) throws IOException { public static void broadcast(final byte[] data, final int port) throws IOException {
DatagramSocket socket = new DatagramSocket(); DatagramSocket socket = new DatagramSocket();
broadcast(socket, data, port, NetworkInterface.getNetworkInterfaces()); broadcast(socket, data, port, NetworkInterface.getNetworkInterfaces());
socket.close(); socket.close();
} }
/** /**
* <p>broadcast.</p> * <p>
* * broadcast.
* @param socket a {@link java.net.DatagramSocket} object. * </p>
* @param data an array of byte. *
* @param port a int. * @param socket
* @param ifaces a {@link java.util.Enumeration} object. * a {@link java.net.DatagramSocket} object.
* @throws java.io.IOException if any. * @param data
* an array of byte.
* @param port
* a int.
* @param ifaces
* a {@link java.util.Enumeration} object.
* @throws java.io.IOException
* if any.
*/ */
private static void broadcast(DatagramSocket socket, byte[] data, int port, Enumeration<NetworkInterface> ifaces) private static void broadcast(final DatagramSocket socket,
throws IOException { final byte[] data, final int port, final Enumeration<NetworkInterface> ifaces)
throws IOException
{
for (NetworkInterface iface : Collections.list(ifaces)) { for (NetworkInterface iface : Collections.list(ifaces)) {
for (InetAddress address : Collections.list(iface.getInetAddresses())) { for (InetAddress address : Collections.list(iface.getInetAddresses())) {
if (!address.isSiteLocalAddress()) continue; if (!address.isSiteLocalAddress()) {
// Java 1.5 doesn't support getting the subnet mask, so try the two most common. continue;
}
// Java 1.5 doesn't support getting the subnet mask, so try the
// two most common.
byte[] ip = address.getAddress(); byte[] ip = address.getAddress();
ip[3] = -1; // 255.255.255.0 ip[3] = -1; // 255.255.255.0
socket.send(new DatagramPacket(data, data.length, InetAddress.getByAddress(ip), port)); socket.send(new DatagramPacket(data, data.length, InetAddress.getByAddress(ip), port));
@@ -80,12 +107,16 @@ public class Util {
} }
/** /**
* <p>invokeAndWait.</p> * <p>
* * invokeAndWait.
* @param runnable a {@link java.lang.Runnable} object. * </p>
* @throws java.lang.Exception if any. *
* @param runnable
* a {@link java.lang.Runnable} object.
* @throws java.lang.Exception
* if any.
*/ */
public static void invokeAndWait(Runnable runnable) throws Exception { public static void invokeAndWait(final Runnable runnable) throws Exception {
try { try {
SwingUtilities.invokeAndWait(runnable); SwingUtilities.invokeAndWait(runnable);
} catch (Exception ex) { } catch (Exception ex) {

View File

@@ -1,2 +1,2 @@
/** Forge Card Game */ /** Forge Card Game. */
package arcane.util; package arcane.util;