diff --git a/src/main/java/arcane/ui/CardArea.java b/src/main/java/arcane/ui/CardArea.java index fb5431eece4..f2dfbbfdcb9 100644 --- a/src/main/java/arcane/ui/CardArea.java +++ b/src/main/java/arcane/ui/CardArea.java @@ -17,13 +17,14 @@ import arcane.ui.util.Animation; import arcane.ui.util.CardPanelMouseListener; /** - *

CardArea class.

- * + *

+ * CardArea class. + *

+ * * @author Forge * @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; /** - *

Constructor for CardArea.

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

+ * Constructor for CardArea. + *

+ * + * @param scrollPane + * a {@link javax.swing.JScrollPane} object. */ public CardArea(final JScrollPane scrollPane) { super(scrollPane); @@ -113,8 +117,10 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen } /** - *

doLayout.

- * + *

+ * doLayout. + *

+ * * @since 1.0.15 */ public final void doLayout() { @@ -141,16 +147,16 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen 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)); + 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) { @@ -193,17 +199,16 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen 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)); + 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) { @@ -280,9 +285,8 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen } /** {@inheritDoc} */ - public final void mouseDragged(final CardPanel dragPanel, - final int dragOffsetX, final int dragOffsetY, final 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(); @@ -319,13 +323,15 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen 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); } /** - *

Getter for the field maxCoverage.

- * + *

+ * Getter for the field maxCoverage. + *

+ * * @return a float. */ public final float getMaxCoverage() { @@ -333,26 +339,34 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen } /** - *

Setter for the field maxCoverage.

- * - * @param maxCoverage a float. + *

+ * Setter for the field maxCoverage. + *

+ * + * @param maxCoverage + * a float. */ public final void setMaxCoverage(float maxCoverage) { this.maxCoverage = maxCoverage; } /** - *

Setter for the field maxRows.

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

+ * Setter for the field maxRows. + *

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

Getter for the field maxRows.

- * + *

+ * Getter for the field maxRows. + *

+ * * @return a int. */ public final int getMaxRows() { @@ -360,17 +374,22 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen } /** - *

setVertical.

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

+ * setVertical. + *

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

isVertical.

- * + *

+ * isVertical. + *

+ * * @return a boolean. */ public final boolean isVertical() { diff --git a/src/main/java/arcane/ui/CardPanel.java b/src/main/java/arcane/ui/CardPanel.java index 213d3bbf70a..8455589ac3c 100644 --- a/src/main/java/arcane/ui/CardPanel.java +++ b/src/main/java/arcane/ui/CardPanel.java @@ -1,22 +1,41 @@ 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.*; +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.ComponentEvent; import java.util.ArrayList; 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; + /** - *

CardPanel class.

- * + *

+ * CardPanel class. + *

+ * * @author Forge * @version $Id$ */ @@ -47,9 +66,15 @@ public class CardPanel extends JPanel implements CardContainer { private static final int TEXT_GLOW_SIZE = 6; /** 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; /** @@ -87,9 +112,12 @@ public class CardPanel extends JPanel implements CardContainer { private boolean showCastingCost; /** - *

Constructor for CardPanel.

- * - * @param newGameCard a {@link forge.Card} object. + *

+ * Constructor for CardPanel. + *

+ * + * @param newGameCard + * a {@link forge.Card} object. */ public CardPanel(final Card newGameCard) { this.gameCard = newGameCard; @@ -133,11 +161,16 @@ public class CardPanel extends JPanel implements CardContainer { } /** - *

setImage.

- * - * @param srcImage a {@link java.awt.Image} object. - * @param srcImageBlurred a {@link java.awt.Image} object. - * @param srcImageBlurred a {@link java.awt.Image} object. + *

+ * setImage. + *

+ * + * @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) { synchronized (imagePanel) { @@ -153,9 +186,12 @@ public class CardPanel extends JPanel implements CardContainer { } /** - *

setImage.

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

+ * setImage. + *

+ * + * @param panel + * a {@link arcane.ui.CardPanel} object. */ public final void setImage(final CardPanel panel) { synchronized (panel.imagePanel) { @@ -168,26 +204,34 @@ public class CardPanel extends JPanel implements CardContainer { } /** - *

setScalingType.

- * - * @param scalingType a {@link arcane.ui.ScaledImagePanel.ScalingType} object. + *

+ * setScalingType. + *

+ * + * @param scalingType + * a {@link arcane.ui.ScaledImagePanel.ScalingType} object. */ public final void setScalingType(final ScalingType scalingType) { imagePanel.setScalingType(scalingType); } /** - *

Setter for the field displayEnabled.

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

+ * Setter for the field displayEnabled. + *

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

isDisplayEnabled.

- * + *

+ * isDisplayEnabled. + *

+ * * @return a boolean. */ public final boolean isDisplayEnabled() { @@ -195,18 +239,24 @@ public class CardPanel extends JPanel implements CardContainer { } /** - *

setAnimationPanel.

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

+ * setAnimationPanel. + *

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

setSelected.

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

+ * setSelected. + *

+ * + * @param isSelected + * a boolean. */ public final void setSelected(final boolean isSelected) { this.isSelected = isSelected; @@ -214,9 +264,12 @@ public class CardPanel extends JPanel implements CardContainer { } /** - *

Setter for the field showCastingCost.

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

+ * Setter for the field showCastingCost. + *

+ * + * @param showCastingCost + * a boolean. */ public final void setShowCastingCost(final boolean showCastingCost) { this.showCastingCost = showCastingCost; @@ -249,8 +302,7 @@ 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")) + 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")) @@ -260,15 +312,13 @@ public class CardPanel extends JPanel implements CardContainer { || (this.gameCard.getCurSetCode().equals("CHR")) || (this.gameCard.getCurSetCode().equals("S99")) || (this.gameCard.getCurSetCode().equals("PTK")) - || (this.gameCard.getCurSetCode().equals("S00"))) - { + || (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, - cornerSize, cornerSize); + g2d.drawRoundRect(cardXOffset - i, cardYOffset - i + offset, cardWidth + i * 2 - 1, + cardHeight + i * 2 - 1, cornerSize, cornerSize); } } g2d.setColor(Color.white); @@ -284,9 +334,8 @@ public class CardPanel extends JPanel implements CardContainer { 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, - cornerSize, cornerSize); + g2d.drawRoundRect(cardXOffset - i, cardYOffset - i + offset, cardWidth + i * 2 - 1, cardHeight + i * 2 + - 1, cornerSize, cornerSize); } } } @@ -303,43 +352,40 @@ public class CardPanel extends JPanel implements CardContainer { int width = ManaSymbols.getWidth(gameCard.getManaCost()); if (cardWidth < 200) { - ManaSymbols.draw(g, gameCard.getManaCost(), - cardXOffset + cardWidth / 2 - width / 2, cardYOffset + cardHeight / 2); + 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); + 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); + 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); + 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); + ManaSymbols.drawSymbol("countersMulti", g, cardXOffset - 15, cardYOffset + cardHeight - (cardHeight / 3) + - 40); } - //int yOff = (cardHeight/4) + 2; + // 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); + 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); + ManaSymbols.drawSymbol("phasing", g, cardXOffset + cardWidth / 2 - 16, cardYOffset + cardHeight + - (cardHeight / 8) - 16); } if (getCard() != null) { @@ -363,8 +409,8 @@ public class CardPanel extends JPanel implements CardContainer { 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))); + cardXOffset + ((i + 1) * (cardWidth / 3)) - width / 2, cardYOffset + + ((j + 1) * (cardHeight / 7))); } n++; @@ -377,8 +423,10 @@ public class CardPanel extends JPanel implements CardContainer { } /** - *

doLayout.

- * + *

+ * doLayout. + *

+ * * @since 1.0.15 */ public final void doLayout() { @@ -409,8 +457,10 @@ public class CardPanel extends JPanel implements CardContainer { } /** - *

toString.

- * + *

+ * toString. + *

+ * * @return a {@link java.lang.String} object. */ public final String toString() { @@ -418,12 +468,18 @@ public class CardPanel extends JPanel implements CardContainer { } /** - *

setCardBounds.

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

+ * setCardBounds. + *

+ * + * @param x + * 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) { cardWidth = width; @@ -442,7 +498,9 @@ public class CardPanel extends JPanel implements CardContainer { } /** - *

repaint.

+ *

+ * repaint. + *

*/ public final void repaint() { Rectangle b = getBounds(); @@ -455,8 +513,10 @@ public class CardPanel extends JPanel implements CardContainer { } /** - *

getCardX.

- * + *

+ * getCardX. + *

+ * * @return a int. */ public final int getCardX() { @@ -464,8 +524,10 @@ public class CardPanel extends JPanel implements CardContainer { } /** - *

getCardY.

- * + *

+ * getCardY. + *

+ * * @return a int. */ public final int getCardY() { @@ -473,8 +535,10 @@ public class CardPanel extends JPanel implements CardContainer { } /** - *

Getter for the field cardWidth.

- * + *

+ * Getter for the field cardWidth. + *

+ * * @return a int. */ public final int getCardWidth() { @@ -482,8 +546,10 @@ public class CardPanel extends JPanel implements CardContainer { } /** - *

Getter for the field cardHeight.

- * + *

+ * Getter for the field cardHeight. + *

+ * * @return a int. */ public final int getCardHeight() { @@ -491,8 +557,10 @@ public class CardPanel extends JPanel implements CardContainer { } /** - *

getCardLocation.

- * + *

+ * getCardLocation. + *

+ * * @return a {@link java.awt.Point} object. */ public final Point getCardLocation() { @@ -503,9 +571,12 @@ public class CardPanel extends JPanel implements CardContainer { } /** - *

setText.

- * - * @param card a {@link forge.Card} object. + *

+ * setText. + *

+ * + * @param card + * a {@link forge.Card} object. */ public final void setText(final Card card) { if (card == null || !Singletons.getModel().getPreferences().cardOverlay) { @@ -521,9 +592,8 @@ 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()) { @@ -534,8 +604,10 @@ public class CardPanel extends JPanel implements CardContainer { } /** - *

getCard.

- * + *

+ * getCard. + *

+ * * @return a {@link forge.Card} object. */ public final Card getCard() { diff --git a/src/main/java/arcane/ui/HandArea.java b/src/main/java/arcane/ui/HandArea.java index 654bf156bdd..0983e940a54 100644 --- a/src/main/java/arcane/ui/HandArea.java +++ b/src/main/java/arcane/ui/HandArea.java @@ -1,14 +1,17 @@ package arcane.ui; +import java.awt.Frame; +import java.awt.event.MouseEvent; + +import javax.swing.JScrollPane; + import arcane.ui.util.CardPanelMouseListener; -import javax.swing.*; -import java.awt.*; -import java.awt.event.MouseEvent; - /** - *

HandArea class.

- * + *

+ * HandArea class. + *

+ * * @author Forge * @version $Id$ */ @@ -17,10 +20,14 @@ public class HandArea extends CardArea { private static final long serialVersionUID = 7488132628637407745L; /** - *

Constructor for HandArea.

- * - * @param scrollPane a {@link javax.swing.JScrollPane} object. - * @param frame a {@link java.awt.Frame} object. + *

+ * Constructor for HandArea. + *

+ * + * @param scrollPane + * a {@link javax.swing.JScrollPane} object. + * @param frame + * a {@link java.awt.Frame} object. */ public HandArea(final JScrollPane scrollPane, final Frame frame) { super(scrollPane); @@ -45,11 +52,8 @@ public class HandArea extends CardArea { } - public void mouseDragged(final CardPanel dragPanel, - final int dragOffsetX, - final int dragOffsetY, - final MouseEvent evt) - { + public void mouseDragged(final CardPanel dragPanel, final int dragOffsetX, final int dragOffsetY, + final MouseEvent evt) { } public void mouseDragStart(final CardPanel dragPanel, final MouseEvent evt) { diff --git a/src/main/java/arcane/ui/util/Animation.java b/src/main/java/arcane/ui/util/Animation.java index caac66316d4..475674c6b78 100644 --- a/src/main/java/arcane/ui/util/Animation.java +++ b/src/main/java/arcane/ui/util/Animation.java @@ -1,57 +1,71 @@ 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.util.Util; -import javax.swing.*; -import java.awt.*; -import java.util.Timer; -import java.util.TimerTask; - /** - *

Abstract Animation class.

- * + *

+ * Abstract Animation class. + *

+ * * @author Forge * @version $Id$ */ -abstract public class Animation { - /** Constant TARGET_MILLIS_PER_FRAME=30 */ - static private final long TARGET_MILLIS_PER_FRAME = 30; +public abstract class Animation { + /** Constant TARGET_MILLIS_PER_FRAME=30. */ + private static final long TARGET_MILLIS_PER_FRAME = 30; - /** Constant timer */ - static private Timer timer = new Timer("Animation", true); + /** Constant timer. */ + private static Timer timer = new Timer("Animation", true); - /** Constant delayedCardPanel */ - static private CardPanel delayedCardPanel; - /** Constant delayedTime= */ - static private long delayedTime; - /** Constant enlargedCardPanel */ - static private CardPanel enlargedCardPanel; - /** Constant enlargedAnimationPanel */ - static private CardPanel enlargedAnimationPanel; - /** Constant enlargeLock */ - static private Object enlargeLock = new Object(); + /** Constant delayedCardPanel. */ + private static CardPanel delayedCardPanel; + /** Constant delayedTime=. */ + private static long delayedTime; + /** Constant enlargedCardPanel. */ + private static CardPanel enlargedCardPanel; + /** Constant enlargedAnimationPanel. */ + private static CardPanel enlargedAnimationPanel; + /** Constant enlargeLock. */ + private static Object enlargeLock = new Object(); private TimerTask timerTask; private FrameTimer frameTimer; private long elapsed; /** - *

Constructor for Animation.

- * - * @param duration a long. + *

+ * Constructor for Animation. + *

+ * + * @param duration + * a long. */ public Animation(final long duration) { this(duration, 0); } /** - *

Constructor for Animation.

- * - * @param duration a long. - * @param delay a long. + *

+ * Constructor for Animation. + *

+ * + * @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() { public void run() { if (frameTimer == null) { @@ -64,68 +78,86 @@ abstract public class Animation { elapsed = duration; } update(elapsed / (float) duration); - if (elapsed == duration) end(); + if (elapsed == duration) { + end(); + } } }; timer.scheduleAtFixedRate(timerTask, delay, TARGET_MILLIS_PER_FRAME); } /** - *

update.

- * - * @param percentage a float. + *

+ * update. + *

+ * + * @param percentage + * a float. */ - abstract protected void update(float percentage); + protected abstract void update(float percentage); /** - *

cancel.

+ *

+ * cancel. + *

*/ - protected void cancel() { + protected final void cancel() { timerTask.cancel(); end(); } /** - *

start.

+ *

+ * start. + *

*/ protected void start() { } /** - *

end.

+ *

+ * 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 { - static private final int SAMPLES = 6; - static private final long MAX_FRAME = 100; // Max time for one frame, to weed out spikes. + private static final int SAMPLES = 6; + 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; public FrameTimer() { 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; + } } public long getTimeSinceLastFrame() { long currentTime = System.currentTimeMillis(); int id = sampleIndex - 1; - if (id < 0) id += SAMPLES; + if (id < 0) { + id += SAMPLES; + } 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) { long diff = timeSinceLastSample - MAX_FRAME; - for (int i = 0; i < SAMPLES; i++) + for (int i = 0; i < SAMPLES; i++) { samples[i] += diff; + } } long timeSinceOldestSample = currentTime - samples[sampleIndex]; @@ -137,19 +169,24 @@ abstract public class Animation { } /** - *

tapCardToggle.

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

+ * tapCardToggle. + *

+ * + * @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) { protected void start() { panel.tapped = !panel.tapped; } - protected void update(float percentage) { + protected void update(final float 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(); } @@ -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) { /** - *

moveCardToPlay.

- * - * @param startX a int. - * @param startY a int. - * @param startWidth a int. - * @param endX 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. + *

+ * moveCardToPlay. + *

+ * + * @param startX + * a int. + * @param startY + * a int. + * @param startWidth + * a int. + * @param endX + * 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, - final int endWidth, final CardPanel animationPanel, final CardPanel placeholder, final JLayeredPane layeredPane, - final int speed) { + public static void moveCardToPlay(final int startX, final int startY, final int startWidth, final int endX, + final int endY, final int endWidth, final CardPanel animationPanel, final CardPanel placeholder, + final JLayeredPane layeredPane, final int speed) + { UI.invokeLater(new Runnable() { public void run() { final int startHeight = Math.round(startWidth * CardPanel.ASPECT_RATIO); @@ -240,22 +291,34 @@ abstract public class Animation { } /** - *

moveCard.

- * - * @param startX a int. - * @param startY a int. - * @param startWidth a int. - * @param endX 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. + *

+ * moveCard. + *

+ * + * @param startX + * a int. + * @param startY + * a int. + * @param startWidth + * a int. + * @param endX + * 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, - final int endWidth, final CardPanel animationPanel, final CardPanel placeholder, final JLayeredPane layeredPane, - final int speed) { + public static void moveCard(final int startX, final int startY, final int startWidth, final int endX, + final int endY, final int endWidth, final CardPanel animationPanel, final CardPanel placeholder, + final JLayeredPane layeredPane, final int speed) { UI.invokeLater(new Runnable() { public void run() { final int startHeight = Math.round(startWidth * CardPanel.ASPECT_RATIO); @@ -270,7 +333,7 @@ abstract public class Animation { } new Animation(speed) { - protected void update(float percentage) { + protected void update(final float percentage) { int currentX = startX + Math.round((endX - startX) * percentage); int currentY = startY + Math.round((endY - startY) * percentage); int currentWidth = startWidth + Math.round((endWidth - startWidth) * percentage); @@ -283,7 +346,7 @@ abstract public class Animation { public void run() { if (placeholder != null) { placeholder.setDisplayEnabled(true); - //placeholder.setImage(animationPanel); + // placeholder.setImage(animationPanel); placeholder.setCard(placeholder.gameCard); } animationPanel.setVisible(false); @@ -298,18 +361,21 @@ abstract public class Animation { } /** - *

moveCard.

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

+ * moveCard. + *

+ * + * @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() { public void run() { EventQueue.invokeLater(new Runnable() { public void run() { if (placeholder != null) { placeholder.setDisplayEnabled(true); - //placeholder.setImage(imagePanel); + // placeholder.setImage(imagePanel); placeholder.setCard(placeholder.gameCard); } } @@ -319,16 +385,20 @@ abstract public class Animation { } /** - *

shrinkCard.

+ *

+ * shrinkCard. + *

*/ - static public void shrinkCard() { + public static void shrinkCard() { CardPanel enlargedCardPanel, enlargedAnimationPanel; synchronized (enlargeLock) { delayedCardPanel = null; delayedTime = 0; enlargedCardPanel = Animation.enlargedCardPanel; enlargedAnimationPanel = Animation.enlargedAnimationPanel; - if (enlargedAnimationPanel == null) return; + if (enlargedAnimationPanel == null) { + return; + } Animation.enlargedCardPanel = null; Animation.enlargedAnimationPanel = null; } @@ -345,10 +415,11 @@ abstract public class Animation { final int endHeight = Math.round(endWidth * CardPanel.ASPECT_RATIO); new Animation(200) { - protected void update(float percentage) { + protected void update(final float percentage) { int currentWidth = startWidth + Math.round((endWidth - startWidth) * 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 centerY = startPos.y + Math.round(endHeight / 2f); int currentX = Math.max(0, centerX - Math.round(currentWidth / 2f)); @@ -372,13 +443,18 @@ abstract public class Animation { } /** - *

enlargeCard.

- * - * @param overPanel a {@link arcane.ui.CardPanel} object. - * @param clientFrame a {@link java.awt.Frame} object. - * @param delay a long. + *

+ * enlargeCard. + *

+ * + * @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) { synchronized (enlargeLock) { delayedCardPanel = null; @@ -386,7 +462,9 @@ abstract public class Animation { if (Animation.enlargedCardPanel != null) { Animation.enlargedCardPanel = null; } - if (enlargedAnimationPanel == null) return; + if (enlargedAnimationPanel == null) { + return; + } Animation.enlargedAnimationPanel.setVisible(false); Animation.enlargedAnimationPanel.repaint(); @@ -400,12 +478,20 @@ abstract public class Animation { final int startHeight = Math.round(startWidth * CardPanel.ASPECT_RATIO); final int endWidth = 300; final int endHeight = Math.round(endWidth * CardPanel.ASPECT_RATIO); - if (startWidth >= endWidth) return; + if (startWidth >= endWidth) { + return; + } long delayedTime; synchronized (enlargeLock) { - if (enlargedCardPanel == overPanel) return; // Already showing this card enlarged. - if (delay > 0 && delayedCardPanel == overPanel) return; // Already delayed this card. + if (enlargedCardPanel == overPanel) + { + return; // Already showing this card enlarged. + } + if (delay > 0 && delayedCardPanel == overPanel) + { + return; // Already delayed this card. + } delayedCardPanel = overPanel; Animation.delayedTime = System.currentTimeMillis(); delayedTime = Animation.delayedTime; @@ -418,8 +504,10 @@ abstract public class Animation { new Animation(200, delay) { protected void start() { synchronized (enlargeLock) { - // Cancel if the panel is no longer delayed or already shown. - if (delayedCardPanel != overPanel || thisDelayedTime != Animation.delayedTime || enlargedCardPanel == overPanel) { + // Cancel if the panel is no longer delayed or already + // shown. + if (delayedCardPanel != overPanel || thisDelayedTime != Animation.delayedTime + || enlargedCardPanel == overPanel) { cancel(); return; } @@ -429,7 +517,7 @@ abstract public class Animation { Point startPos = overPanel.getCardLocation(); animationPanel.setCardBounds(startPos.x, startPos.y, startWidth, startHeight); } - //clientFrame.clearArrows(); + // clientFrame.clearArrows(); animationPanel.tappedAngle = overPanel.tappedAngle; try { 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) { if (enlargedAnimationPanel != animationPanel) { cancel(); @@ -451,7 +539,8 @@ abstract public class Animation { } int currentWidth = startWidth + Math.round((endWidth - startWidth) * 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 centerY = startPos.y + Math.round(startHeight / 2f); int currentX = Math.max(0, centerX - Math.round(currentWidth / 2f)); @@ -465,11 +554,13 @@ abstract public class Animation { } /** - *

isShowingEnlargedCard.

- * + *

+ * isShowingEnlargedCard. + *

+ * * @return a boolean. */ - static public boolean isShowingEnlargedCard() { + public static boolean isShowingEnlargedCard() { synchronized (enlargeLock) { return enlargedAnimationPanel != null; } diff --git a/src/main/java/arcane/ui/util/CardPanelMouseListener.java b/src/main/java/arcane/ui/util/CardPanelMouseListener.java index eba7364dff3..4c775dcc0c1 100644 --- a/src/main/java/arcane/ui/util/CardPanelMouseListener.java +++ b/src/main/java/arcane/ui/util/CardPanelMouseListener.java @@ -17,7 +17,7 @@ public interface CardPanelMouseListener { * @param panel a {@link arcane.ui.CardPanel} object. * @param evt a {@link java.awt.event.MouseEvent} object. */ - public void mouseOver(CardPanel panel, MouseEvent evt); + void mouseOver(CardPanel panel, MouseEvent evt); /** *

mouseOut.

@@ -25,7 +25,7 @@ public interface CardPanelMouseListener { * @param panel a {@link arcane.ui.CardPanel} object. * @param evt a {@link java.awt.event.MouseEvent} object. */ - public void mouseOut(CardPanel panel, MouseEvent evt); + void mouseOut(CardPanel panel, MouseEvent evt); /** *

mouseLeftClicked.

@@ -33,7 +33,7 @@ public interface CardPanelMouseListener { * @param panel a {@link arcane.ui.CardPanel} object. * @param evt a {@link java.awt.event.MouseEvent} object. */ - public void mouseLeftClicked(CardPanel panel, MouseEvent evt); + void mouseLeftClicked(CardPanel panel, MouseEvent evt); /** *

mouseMiddleClicked.

@@ -41,7 +41,7 @@ public interface CardPanelMouseListener { * @param panel a {@link arcane.ui.CardPanel} object. * @param evt a {@link java.awt.event.MouseEvent} object. */ - public void mouseMiddleClicked(CardPanel panel, MouseEvent evt); + void mouseMiddleClicked(CardPanel panel, MouseEvent evt); /** *

mouseRightClicked.

@@ -49,7 +49,7 @@ public interface CardPanelMouseListener { * @param panel a {@link arcane.ui.CardPanel} object. * @param evt a {@link java.awt.event.MouseEvent} object. */ - public void mouseRightClicked(CardPanel panel, MouseEvent evt); + void mouseRightClicked(CardPanel panel, MouseEvent evt); /** *

mouseDragStart.

@@ -57,7 +57,7 @@ public interface CardPanelMouseListener { * @param dragPanel a {@link arcane.ui.CardPanel} object. * @param evt a {@link java.awt.event.MouseEvent} object. */ - public void mouseDragStart(CardPanel dragPanel, MouseEvent evt); + void mouseDragStart(CardPanel dragPanel, MouseEvent evt); /** *

mouseDragged.

@@ -67,7 +67,7 @@ public interface CardPanelMouseListener { * @param dragOffsetY a int. * @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); /** *

mouseDragEnd.

@@ -75,5 +75,5 @@ public interface CardPanelMouseListener { * @param dragPanel a {@link arcane.ui.CardPanel} object. * @param evt a {@link java.awt.event.MouseEvent} object. */ - public void mouseDragEnd(CardPanel dragPanel, MouseEvent evt); + void mouseDragEnd(CardPanel dragPanel, MouseEvent evt); } diff --git a/src/main/java/arcane/ui/util/GlowText.java b/src/main/java/arcane/ui/util/GlowText.java index c1ab86876a9..9b4d5f04e88 100644 --- a/src/main/java/arcane/ui/util/GlowText.java +++ b/src/main/java/arcane/ui/util/GlowText.java @@ -1,7 +1,11 @@ package arcane.ui.util; -import javax.swing.*; -import java.awt.*; +import java.awt.AlphaComposite; +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.LineBreakMeasurer; import java.awt.font.TextAttribute; @@ -11,46 +15,60 @@ import java.text.AttributedString; import java.text.BreakIterator; import java.util.Locale; +import javax.swing.JLabel; + /** - *

GlowText class.

- * + *

+ * GlowText class. + *

+ * * @author Forge * @version $Id$ */ public class GlowText extends JLabel { - /** Constant serialVersionUID=-2868833097364223352L */ + /** Constant serialVersionUID=-2868833097364223352L. */ private static final long serialVersionUID = -2868833097364223352L; private int glowSize; private Color glowColor; private boolean wrap; /** - *

setGlow.

- * - * @param glowColor a {@link java.awt.Color} object. - * @param size a int. - * @param intensity a float. + *

+ * setGlow. + *

+ * + * @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.glowSize = size; } /** - *

Setter for the field wrap.

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

+ * Setter for the field wrap. + *

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

getPreferredSize.

- * + *

+ * getPreferredSize. + *

+ * * @return a {@link java.awt.Dimension} object. */ - public Dimension getPreferredSize() { + public final Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); size.width += glowSize; size.height += glowSize / 2; @@ -58,13 +76,15 @@ public class GlowText extends JLabel { } /** {@inheritDoc} */ - public void setText(String text) { + public final void setText(final String text) { super.setText(text); } /** {@inheritDoc} */ - public void paint(Graphics g) { - if (getText().length() == 0) return; + public final void paint(final Graphics g) { + if (getText().length() == 0) { + return; + } Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); @@ -79,19 +99,24 @@ public class GlowText extends JLabel { AttributedCharacterIterator charIterator = attributedString.getIterator(); 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; while (measurer.getPosition() < charIterator.getEndIndex()) { measurer.nextLayout(wrapWidth); lineCount++; - if (lineCount > 2) break; + if (lineCount > 2) { + break; + } } charIterator.first(); // Use char wrap if word wrap would cause more than two lines of text. - if (lineCount > 2) - measurer = new LineBreakMeasurer(charIterator, BreakIterator.getCharacterInstance(Locale.ENGLISH), fontContext); - else + if (lineCount > 2) { + measurer = new LineBreakMeasurer(charIterator, BreakIterator.getCharacterInstance(Locale.ENGLISH), + fontContext); + } else { measurer.setPosition(0); + } while (measurer.getPosition() < charIterator.getEndIndex()) { TextLayout textLayout = measurer.nextLayout(wrapWidth); float ascent = textLayout.getAscent(); @@ -108,7 +133,13 @@ public class GlowText extends JLabel { g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); 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. } } } diff --git a/src/main/java/arcane/ui/util/ImageUtil.java b/src/main/java/arcane/ui/util/ImageUtil.java index 54b8c0ccb9a..48ac1aca633 100644 --- a/src/main/java/arcane/ui/util/ImageUtil.java +++ b/src/main/java/arcane/ui/util/ImageUtil.java @@ -1,7 +1,7 @@ package arcane.ui.util; -import javax.imageio.ImageIO; -import java.awt.*; +import java.awt.Graphics2D; +import java.awt.Image; import java.awt.image.BufferedImage; import java.awt.image.ConvolveOp; import java.awt.image.Kernel; @@ -9,23 +9,32 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import javax.imageio.ImageIO; + /** - *

ImageUtil class.

- * + *

+ * ImageUtil class. + *

+ * * @author Forge * @version $Id$ */ public class ImageUtil { /** - *

getImage.

- * - * @param stream a {@link java.io.InputStream} object. + *

+ * getImage. + *

+ * + * @param stream + * a {@link java.io.InputStream} 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); - 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(); g2.drawImage(tempImage, 0, 0, null); g2.dispose(); @@ -33,15 +42,20 @@ public class ImageUtil { } /** - *

getImage.

- * - * @param file a {@link java.io.File} object. + *

+ * getImage. + *

+ * + * @param file + * a {@link java.io.File} 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); - 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(); g2.drawImage(tempImage, 0, 0, null); g2.dispose(); @@ -49,18 +63,24 @@ public class ImageUtil { } /** - *

getBlurredImage.

- * - * @param image a {@link java.awt.image.BufferedImage} object. - * @param radius a int. - * @param intensity a float. + *

+ * getBlurredImage. + *

+ * + * @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. */ - 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[] 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; + } ConvolveOp blurOp = new ConvolveOp(new Kernel(radius, radius, elements)); return blurOp.filter(image, null); } diff --git a/src/main/java/arcane/ui/util/ManaSymbols.java b/src/main/java/arcane/ui/util/ManaSymbols.java index ae29d71ecd7..55f13e672a8 100644 --- a/src/main/java/arcane/ui/util/ManaSymbols.java +++ b/src/main/java/arcane/ui/util/ManaSymbols.java @@ -1,49 +1,62 @@ package arcane.ui.util; -import com.esotericsoftware.minlog.Log; - -import java.awt.*; +import java.awt.Graphics; +import java.awt.Image; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; import java.util.regex.Pattern; +import com.esotericsoftware.minlog.Log; /** - *

ManaSymbols class.

- * + *

+ * ManaSymbols class. + *

+ * * @author Forge * @version $Id$ */ public class ManaSymbols { - /** Constant manaImages */ - static private final Map manaImages = new HashMap(); - /** Constant replaceSymbolsPattern */ - static private Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}"); + /** Constant manaImages. */ + private static final Map manaImages = new HashMap(); + /** Constant replaceSymbolsPattern. */ + private static Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}"); /** - *

loadImages.

+ *

+ * loadImages. + *

*/ - static public void loadImages() { - String[] symbols = new String[]{"0", "1", "10", "11", "12", "15", "16", "2", "20", "2W", "2U", "2R", "2G", "2B", "3", - "4", "5", "6", "7", "8", "9", "B", "BG", "BR", "G", "GU", "GW", "R", "RG", "RW", "S", "T", "U", "UB", - "UR", "W", "WB", "WU", "PW", "PU", "PB", "PR", "PG", "X", "Y", "Z", "slash", "attack", "defend", "summonsick", - "phasing", "counters1", "counters2", "counters3", "countersMulti", - "foil01","foil02","foil03","foil04","foil05","foil06","foil07","foil08","foil09","foil10"}; - for (String symbol : symbols) + public static void loadImages() { + String[] symbols = new String[] {"0", "1", "10", "11", "12", "15", "16", "2", "20", "2W", "2U", "2R", "2G", + "2B", "3", "4", "5", "6", "7", "8", "9", "B", "BG", "BR", "G", "GU", "GW", "R", "RG", "RW", "S", "T", + "U", "UB", "UR", "W", "WB", "WU", "PW", "PU", "PB", "PR", "PG", "X", "Y", "Z", "slash", "attack", + "defend", "summonsick", "phasing", "counters1", "counters2", "counters3", "countersMulti", "foil01", + "foil02", "foil03", "foil04", "foil05", "foil06", "foil07", "foil08", "foil09", "foil10" }; + for (String symbol : symbols) { manaImages.put(symbol, UI.getImageIcon("res/images/symbols-13/" + symbol + ".png").getImage()); + } } /** - *

draw.

- * - * @param g a {@link java.awt.Graphics} object. - * @param manaCost a {@link java.lang.String} object. - * @param x a int. - * @param y a int. + *

+ * draw. + *

+ * + * @param g + * 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) { - if (manaCost.length() == 0) return; + public static void draw(Graphics g, String manaCost, int x, int y) { + if (manaCost.length() == 0) { + return; + } manaCost = UI.getDisplayManaCost(manaCost); StringTokenizer tok = new StringTokenizer(manaCost, " "); while (tok.hasMoreTokens()) { @@ -54,12 +67,25 @@ public class ManaSymbols { continue; } 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); StringTokenizer tok = new StringTokenizer(s, " "); while (tok.hasMoreTokens()) { @@ -69,69 +95,90 @@ public class ManaSymbols { Log.info("Symbol not recognized \"" + symbol + "\" in string: " + s); continue; } - //g.drawImage(image, x, y, null); + // g.drawImage(image, x, y, 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. } } - + /** - *

drawAttack.

- * - * @param g a {@link java.awt.Graphics} object. - * @param x a int. - * @param y a int. + *

+ * drawAttack. + *

+ * + * @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"); g.drawImage(image, x, y, null); } - /** - *

drawSymbol.

- * - * @param imageName a {@link java.lang.String} object. - * @param g a {@link java.awt.Graphics} object. - * @param x a int. - * @param y a int. + *

+ * drawSymbol. + *

+ * + * @param imageName + * 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); g.drawImage(image, x, y, null); } /** - *

getWidth.

- * - * @param manaCost a {@link java.lang.String} object. + *

+ * getWidth. + *

+ * + * @param manaCost + * a {@link java.lang.String} object. * @return a int. */ - static public int getWidth(String manaCost) { + public static int getWidth(final String manaCost) { int width = 0; StringTokenizer tok = new StringTokenizer(manaCost, " "); while (tok.hasMoreTokens()) { 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; } /** - *

replaceSymbolsWithHTML.

- * - * @param value a {@link java.lang.String} object. - * @param small a boolean. + *

+ * replaceSymbolsWithHTML. + *

+ * + * @param value + * a {@link java.lang.String} object. + * @param small + * a boolean. * @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) { value = value.replace("{C}", ""); - return replaceSymbolsPattern.matcher(value).replaceAll(""); + return replaceSymbolsPattern.matcher(value).replaceAll( + ""); } else { value = value.replace("{slash}", ""); value = value.replace("{C}", ""); - return replaceSymbolsPattern.matcher(value).replaceAll(""); + return replaceSymbolsPattern.matcher(value).replaceAll( + ""); } } } diff --git a/src/main/java/arcane/ui/util/UI.java b/src/main/java/arcane/ui/util/UI.java index 83ecddee9ac..7a85cd3bf2b 100644 --- a/src/main/java/arcane/ui/util/UI.java +++ b/src/main/java/arcane/ui/util/UI.java @@ -1,18 +1,14 @@ package arcane.ui.util; -import com.google.common.collect.MapMaker; - -import javax.swing.*; -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 java.awt.*; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.Font; +import java.awt.Image; +import java.awt.Insets; +import java.awt.Point; +import java.awt.Toolkit; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -25,60 +21,95 @@ import java.net.URL; import java.util.Collections; 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. - * + * * @author Forge * @version $Id$ */ public class UI { - /** Constant imageCache */ - static private ConcurrentMap imageCache = new MapMaker().softValues().makeMap(); + /** Constant imageCache. */ + private static ConcurrentMap imageCache = new MapMaker().softValues().makeMap(); /** - *

getToggleButton.

- * + *

+ * getToggleButton. + *

+ * * @return a {@link javax.swing.JToggleButton} object. */ - static public JToggleButton getToggleButton() { + public static JToggleButton getToggleButton() { JToggleButton button = new JToggleButton(); button.setMargin(new Insets(2, 4, 2, 4)); return button; } /** - *

getButton.

- * + *

+ * getButton. + *

+ * * @return a {@link javax.swing.JButton} object. */ - static public JButton getButton() { + public static JButton getButton() { JButton button = new JButton(); button.setMargin(new Insets(2, 4, 2, 4)); return button; } /** - *

setTitle.

- * - * @param panel a {@link javax.swing.JPanel} object. - * @param title a {@link java.lang.String} object. + *

+ * setTitle. + *

+ * + * @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(); if (border instanceof TitledBorder) { ((TitledBorder) panel.getBorder()).setTitle(title); panel.repaint(); - } else + } else { panel.setBorder(BorderFactory.createTitledBorder(title)); + } } /** - *

getFileURL.

- * - * @param path a {@link java.lang.String} object. + *

+ * getFileURL. + *

+ * + * @param path + * a {@link java.lang.String} 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); if (file.exists()) { try { @@ -90,24 +121,32 @@ public class UI { } /** - *

getImageIcon.

- * - * @param path a {@link java.lang.String} object. + *

+ * getImageIcon. + *

+ * + * @param path + * a {@link java.lang.String} object. * @return a {@link javax.swing.ImageIcon} object. */ - static public ImageIcon getImageIcon(String path) { + public static ImageIcon getImageIcon(final String path) { InputStream stream = null; try { try { stream = UI.class.getResourceAsStream(path); - if (stream == null && new File(path).exists()) stream = new FileInputStream(path); - if (stream == null) throw new RuntimeException("Image not found: " + path); + if (stream == null && new File(path).exists()) { + stream = new FileInputStream(path); + } + if (stream == null) { + throw new RuntimeException("Image not found: " + path); + } byte[] data = new byte[stream.available()]; stream.read(data); return new ImageIcon(data); } finally { - if (stream != null) + if (stream != null) { stream.close(); + } } } catch (IOException ex) { throw new RuntimeException("Error reading image: " + path); @@ -115,34 +154,48 @@ public class UI { } /** - *

setHTMLEditorKit.

- * - * @param editorPane a {@link javax.swing.JEditorPane} object. + *

+ * setHTMLEditorKit. + *

+ * + * @param editorPane + * a {@link javax.swing.JEditorPane} object. */ - static public void setHTMLEditorKit(JEditorPane editorPane) { - editorPane.getDocument().putProperty("imageCache", imageCache); // Read internally by ImageView, but never written. + public static void setHTMLEditorKit(final JEditorPane editorPane) { + editorPane.getDocument().putProperty("imageCache", imageCache); // Read + // internally + // by + // ImageView, + // but + // never + // written. // Extend all this shit to cache images. editorPane.setEditorKit(new HTMLEditorKit() { private static final long serialVersionUID = -562969765076450440L; public ViewFactory getViewFactory() { return new HTMLFactory() { - public View create(Element elem) { + public View create(final Element elem) { Object o = elem.getAttributes().getAttribute(StyleConstants.NameAttribute); if (o instanceof HTML.Tag) { HTML.Tag kind = (HTML.Tag) o; - if (kind == HTML.Tag.IMG) return new ImageView(elem) { - public URL getImageURL() { - URL url = super.getImageURL(); - // Put an image into the cache to be read by other ImageView methods. - if (url != null && imageCache.get(url) == null) - try { - imageCache.put(url.toURI(), Toolkit.getDefaultToolkit().createImage(url)); - } catch (URISyntaxException e) { + if (kind == HTML.Tag.IMG) { + return new ImageView(elem) { + public URL getImageURL() { + URL url = super.getImageURL(); + // Put an image into the cache to be + // read by other ImageView methods. + if (url != null && imageCache.get(url) == null) { + try { + imageCache.put(url.toURI(), Toolkit.getDefaultToolkit() + .createImage(url)); + } catch (URISyntaxException e) { + } } - return url; - } - }; + return url; + } + }; + } } return super.create(elem); } @@ -152,17 +205,21 @@ public class UI { } /** - *

setVerticalScrollingView.

- * - * @param scrollPane a {@link javax.swing.JScrollPane} object. - * @param view a {@link java.awt.Component} object. + *

+ * setVerticalScrollingView. + *

+ * + * @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(); viewport.setLayout(new ViewportLayout() { private static final long serialVersionUID = -4436977380450713628L; - public void layoutContainer(Container parent) { + public void layoutContainer(final Container parent) { viewport.setViewPosition(new Point(0, 0)); Dimension viewportSize = viewport.getSize(); int width = viewportSize.width; @@ -176,35 +233,47 @@ public class UI { } /** - *

getDisplayManaCost.

- * - * @param manaCost a {@link java.lang.String} object. + *

+ * getDisplayManaCost. + *

+ * + * @param manaCost + * 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("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("{|}"); - if (pipePosition != -1) manaCost = manaCost.substring(pipePosition + 3); + if (pipePosition != -1) { + manaCost = manaCost.substring(pipePosition + 3); + } return manaCost; } /** - *

invokeLater.

- * - * @param runnable a {@link java.lang.Runnable} object. + *

+ * invokeLater. + *

+ * + * @param runnable + * a {@link java.lang.Runnable} object. */ - static public void invokeLater(Runnable runnable) { + public static void invokeLater(final Runnable runnable) { EventQueue.invokeLater(runnable); } /** - *

invokeAndWait.

- * - * @param runnable a {@link java.lang.Runnable} object. + *

+ * invokeAndWait. + *

+ * + * @param runnable + * a {@link java.lang.Runnable} object. */ - static public void invokeAndWait(Runnable runnable) { + public static void invokeAndWait(final Runnable runnable) { if (EventQueue.isDispatchThread()) { runnable.run(); return; @@ -218,9 +287,11 @@ public class UI { } /** - *

setSystemLookAndFeel.

+ *

+ * setSystemLookAndFeel. + *

*/ - static public void setSystemLookAndFeel() { + public static void setSystemLookAndFeel() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ex) { @@ -230,14 +301,19 @@ public class UI { } /** - *

setDefaultFont.

- * - * @param font a {@link java.awt.Font} object. + *

+ * setDefaultFont. + *

+ * + * @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())) { 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); + } } } } diff --git a/src/main/java/arcane/ui/util/package-info.java b/src/main/java/arcane/ui/util/package-info.java index d9ec8d71bcf..7276164503d 100644 --- a/src/main/java/arcane/ui/util/package-info.java +++ b/src/main/java/arcane/ui/util/package-info.java @@ -1,2 +1,2 @@ -/** Forge Card Game */ +/** Forge Card Game. */ package arcane.ui.util; diff --git a/src/main/java/arcane/util/MultiplexOutputStream.java b/src/main/java/arcane/util/MultiplexOutputStream.java index b1db49efc47..75cecec70d1 100644 --- a/src/main/java/arcane/util/MultiplexOutputStream.java +++ b/src/main/java/arcane/util/MultiplexOutputStream.java @@ -5,7 +5,7 @@ import java.io.OutputStream; /** * An OutputStream that writes to multiple other OutputStreams. - * + * * @author Forge * @version $Id$ */ @@ -13,25 +13,32 @@ public class MultiplexOutputStream extends OutputStream { private final OutputStream[] streams; /** - *

Constructor for MultiplexOutputStream.

- * - * @param streams a {@link java.io.OutputStream} object. + *

+ * Constructor for MultiplexOutputStream. + *

+ * + * @param streams + * a {@link java.io.OutputStream} object. */ - public MultiplexOutputStream(OutputStream... streams) { + public MultiplexOutputStream(final OutputStream... streams) { super(); - if (streams == null) throw new IllegalArgumentException("streams cannot be null."); + if (streams == null) { + throw new IllegalArgumentException("streams cannot be null."); + } this.streams = streams; } /** {@inheritDoc} */ - public void write(int b) throws IOException { - for (int i = 0; i < streams.length; i++) + public final void write(final int b) throws IOException { + for (int i = 0; i < streams.length; i++) { streams[i].write(b); + } } /** {@inheritDoc} */ - public void write(byte[] b, int off, int len) throws IOException { - for (int i = 0; i < streams.length; i++) + public final void write(final byte[] b, final int off, final int len) throws IOException { + for (int i = 0; i < streams.length; i++) { streams[i].write(b, off, len); + } } } diff --git a/src/main/java/arcane/util/Util.java b/src/main/java/arcane/util/Util.java index 23b34cb5fce..e05b4e68044 100644 --- a/src/main/java/arcane/util/Util.java +++ b/src/main/java/arcane/util/Util.java @@ -1,6 +1,5 @@ package arcane.util; -import javax.swing.*; import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; @@ -13,63 +12,91 @@ import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import javax.swing.SwingUtilities; + /** - *

Util class.

- * + *

+ * Util class. + *

+ * * @author Forge * @version $Id$ */ public class Util { - /** Constant isMac=System.getProperty("os.name").toLowerCase().indexOf("mac") != -1 */ - static public final boolean isMac = System.getProperty("os.name").toLowerCase().indexOf("mac") != -1; - /** Constant isWindows=System.getProperty("os.name").toLowerCase().indexOf("windows") == -1 */ - static public final boolean isWindows = System.getProperty("os.name").toLowerCase().indexOf("windows") == -1; + /** + * Constant. + * isMac=System.getProperty("os.name").toLowerCase().indexOf("mac") != -1. + */ + public static final boolean isMac = System.getProperty("os.name").toLowerCase().indexOf("mac") != -1; + /** + * Constant. + * isWindows=System.getProperty("os.name").toLowerCase().indexOf("windows") == -1 + */ + public static final boolean isWindows = System.getProperty("os.name").toLowerCase().indexOf("windows") == -1; - /** Constant threadPool */ - static public ThreadPoolExecutor threadPool; - /** Constant threadCount */ - static private int threadCount; + /** Constant threadPool. */ + public static ThreadPoolExecutor threadPool; + /** Constant threadCount. */ + private static int threadCount; static { - threadPool = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new ThreadFactory() { - public Thread newThread(Runnable runnable) { - threadCount++; - Thread thread = new Thread(runnable, "Util" + threadCount); - thread.setDaemon(true); - return thread; - } - }); + threadPool = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), + new ThreadFactory() { + public Thread newThread(final Runnable runnable) { + threadCount++; + Thread thread = new Thread(runnable, "Util" + threadCount); + thread.setDaemon(true); + return thread; + } + }); threadPool.prestartAllCoreThreads(); } /** - *

broadcast.

- * - * @param data an array of byte. - * @param port a int. - * @throws java.io.IOException if any. + *

+ * broadcast. + *

+ * + * @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(); broadcast(socket, data, port, NetworkInterface.getNetworkInterfaces()); socket.close(); } /** - *

broadcast.

- * - * @param socket a {@link java.net.DatagramSocket} object. - * @param data an array of byte. - * @param port a int. - * @param ifaces a {@link java.util.Enumeration} object. - * @throws java.io.IOException if any. + *

+ * broadcast. + *

+ * + * @param socket + * a {@link java.net.DatagramSocket} object. + * @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 ifaces) - throws IOException { + private static void broadcast(final DatagramSocket socket, + final byte[] data, final int port, final Enumeration ifaces) + throws IOException + { for (NetworkInterface iface : Collections.list(ifaces)) { for (InetAddress address : Collections.list(iface.getInetAddresses())) { - if (!address.isSiteLocalAddress()) continue; - // Java 1.5 doesn't support getting the subnet mask, so try the two most common. + if (!address.isSiteLocalAddress()) { + continue; + } + // Java 1.5 doesn't support getting the subnet mask, so try the + // two most common. byte[] ip = address.getAddress(); ip[3] = -1; // 255.255.255.0 socket.send(new DatagramPacket(data, data.length, InetAddress.getByAddress(ip), port)); @@ -80,12 +107,16 @@ public class Util { } /** - *

invokeAndWait.

- * - * @param runnable a {@link java.lang.Runnable} object. - * @throws java.lang.Exception if any. + *

+ * invokeAndWait. + *

+ * + * @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 { SwingUtilities.invokeAndWait(runnable); } catch (Exception ex) { diff --git a/src/main/java/arcane/util/package-info.java b/src/main/java/arcane/util/package-info.java index f60f91ddb8c..b6426aa8724 100644 --- a/src/main/java/arcane/util/package-info.java +++ b/src/main/java/arcane/util/package-info.java @@ -1,2 +1,2 @@ -/** Forge Card Game */ +/** Forge Card Game. */ package arcane.util;