mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
checkstyle
This commit is contained in:
@@ -17,13 +17,14 @@ import arcane.ui.util.Animation;
|
||||
import arcane.ui.util.CardPanelMouseListener;
|
||||
|
||||
/**
|
||||
* <p>CardArea class.</p>
|
||||
* <p>
|
||||
* CardArea class.
|
||||
* </p>
|
||||
*
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* <p>Constructor for CardArea.</p>
|
||||
* <p>
|
||||
* Constructor for CardArea.
|
||||
* </p>
|
||||
*
|
||||
* @param scrollPane a {@link javax.swing.JScrollPane} object.
|
||||
* @param scrollPane
|
||||
* a {@link javax.swing.JScrollPane} object.
|
||||
*/
|
||||
public CardArea(final JScrollPane scrollPane) {
|
||||
super(scrollPane);
|
||||
@@ -113,7 +117,9 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>doLayout.</p>
|
||||
* <p>
|
||||
* doLayout.
|
||||
* </p>
|
||||
*
|
||||
* @since 1.0.15
|
||||
*/
|
||||
@@ -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,12 +323,14 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Getter for the field <code>maxCoverage</code>.</p>
|
||||
* <p>
|
||||
* Getter for the field <code>maxCoverage</code>.
|
||||
* </p>
|
||||
*
|
||||
* @return a float.
|
||||
*/
|
||||
@@ -333,25 +339,33 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Setter for the field <code>maxCoverage</code>.</p>
|
||||
* <p>
|
||||
* Setter for the field <code>maxCoverage</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param maxCoverage a float.
|
||||
* @param maxCoverage
|
||||
* a float.
|
||||
*/
|
||||
public final void setMaxCoverage(float maxCoverage) {
|
||||
this.maxCoverage = maxCoverage;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Setter for the field <code>maxRows</code>.</p>
|
||||
* <p>
|
||||
* Setter for the field <code>maxRows</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param maxRows a int.
|
||||
* @param maxRows
|
||||
* a int.
|
||||
*/
|
||||
public final void setMaxRows(int 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.
|
||||
*/
|
||||
@@ -360,16 +374,21 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setVertical.</p>
|
||||
* <p>
|
||||
* setVertical.
|
||||
* </p>
|
||||
*
|
||||
* @param isVertical a boolean.
|
||||
* @param isVertical
|
||||
* a boolean.
|
||||
*/
|
||||
public final void setVertical(final boolean isVertical) {
|
||||
this.isVertical = isVertical;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isVertical.</p>
|
||||
* <p>
|
||||
* isVertical.
|
||||
* </p>
|
||||
*
|
||||
* @return a boolean.
|
||||
*/
|
||||
|
||||
@@ -1,21 +1,40 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>CardPanel class.</p>
|
||||
* <p>
|
||||
* CardPanel class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
@@ -47,9 +66,15 @@ public class CardPanel extends JPanel implements CardContainer {
|
||||
private static final int TEXT_GLOW_SIZE = 6;
|
||||
/** Constant <code>TEXT_GLOW_INTENSITY=3f</code>. */
|
||||
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;
|
||||
/** Constant <code>rotCenterToBottomCorner=0.7071067811865475244008443621048f</code>. */
|
||||
/**
|
||||
* Constant
|
||||
* <code>rotCenterToBottomCorner=0.7071067811865475244008443621048f</code>.
|
||||
*/
|
||||
private static final float rotCenterToBottomCorner = 0.7071067811865475244008443621048f;
|
||||
|
||||
/**
|
||||
@@ -87,9 +112,12 @@ public class CardPanel extends JPanel implements CardContainer {
|
||||
private boolean showCastingCost;
|
||||
|
||||
/**
|
||||
* <p>Constructor for CardPanel.</p>
|
||||
* <p>
|
||||
* Constructor for CardPanel.
|
||||
* </p>
|
||||
*
|
||||
* @param newGameCard a {@link forge.Card} object.
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setImage.</p>
|
||||
* <p>
|
||||
* setImage.
|
||||
* </p>
|
||||
*
|
||||
* @param srcImage a {@link java.awt.Image} object.
|
||||
* @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) {
|
||||
synchronized (imagePanel) {
|
||||
@@ -153,9 +186,12 @@ public class CardPanel extends JPanel implements CardContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setImage.</p>
|
||||
* <p>
|
||||
* setImage.
|
||||
* </p>
|
||||
*
|
||||
* @param panel a {@link arcane.ui.CardPanel} object.
|
||||
* @param panel
|
||||
* a {@link arcane.ui.CardPanel} object.
|
||||
*/
|
||||
public final void setImage(final CardPanel panel) {
|
||||
synchronized (panel.imagePanel) {
|
||||
@@ -168,25 +204,33 @@ public class CardPanel extends JPanel implements CardContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setScalingType.</p>
|
||||
* <p>
|
||||
* setScalingType.
|
||||
* </p>
|
||||
*
|
||||
* @param scalingType a {@link arcane.ui.ScaledImagePanel.ScalingType} object.
|
||||
* @param scalingType
|
||||
* a {@link arcane.ui.ScaledImagePanel.ScalingType} object.
|
||||
*/
|
||||
public final void setScalingType(final ScalingType scalingType) {
|
||||
imagePanel.setScalingType(scalingType);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Setter for the field <code>displayEnabled</code>.</p>
|
||||
* <p>
|
||||
* Setter for the field <code>displayEnabled</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param displayEnabled a boolean.
|
||||
* @param displayEnabled
|
||||
* a boolean.
|
||||
*/
|
||||
public final void setDisplayEnabled(final boolean displayEnabled) {
|
||||
this.displayEnabled = displayEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isDisplayEnabled.</p>
|
||||
* <p>
|
||||
* isDisplayEnabled.
|
||||
* </p>
|
||||
*
|
||||
* @return a boolean.
|
||||
*/
|
||||
@@ -195,18 +239,24 @@ public class CardPanel extends JPanel implements CardContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setAnimationPanel.</p>
|
||||
* <p>
|
||||
* setAnimationPanel.
|
||||
* </p>
|
||||
*
|
||||
* @param isAnimationPanel a boolean.
|
||||
* @param isAnimationPanel
|
||||
* a boolean.
|
||||
*/
|
||||
public final void setAnimationPanel(final boolean isAnimationPanel) {
|
||||
this.isAnimationPanel = isAnimationPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setSelected.</p>
|
||||
* <p>
|
||||
* setSelected.
|
||||
* </p>
|
||||
*
|
||||
* @param isSelected a boolean.
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Setter for the field <code>showCastingCost</code>.</p>
|
||||
* <p>
|
||||
* Setter for the field <code>showCastingCost</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param showCastingCost a boolean.
|
||||
* @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,7 +423,9 @@ public class CardPanel extends JPanel implements CardContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>doLayout.</p>
|
||||
* <p>
|
||||
* doLayout.
|
||||
* </p>
|
||||
*
|
||||
* @since 1.0.15
|
||||
*/
|
||||
@@ -409,7 +457,9 @@ public class CardPanel extends JPanel implements CardContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>toString.</p>
|
||||
* <p>
|
||||
* toString.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
@@ -418,12 +468,18 @@ public class CardPanel extends JPanel implements CardContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setCardBounds.</p>
|
||||
* <p>
|
||||
* setCardBounds.
|
||||
* </p>
|
||||
*
|
||||
* @param x a int.
|
||||
* @param y a int.
|
||||
* @param width a int.
|
||||
* @param height a int.
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>repaint.</p>
|
||||
* <p>
|
||||
* repaint.
|
||||
* </p>
|
||||
*/
|
||||
public final void repaint() {
|
||||
Rectangle b = getBounds();
|
||||
@@ -455,7 +513,9 @@ public class CardPanel extends JPanel implements CardContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getCardX.</p>
|
||||
* <p>
|
||||
* getCardX.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
*/
|
||||
@@ -464,7 +524,9 @@ public class CardPanel extends JPanel implements CardContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getCardY.</p>
|
||||
* <p>
|
||||
* getCardY.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
*/
|
||||
@@ -473,7 +535,9 @@ 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.
|
||||
*/
|
||||
@@ -482,7 +546,9 @@ 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.
|
||||
*/
|
||||
@@ -491,7 +557,9 @@ public class CardPanel extends JPanel implements CardContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getCardLocation.</p>
|
||||
* <p>
|
||||
* getCardLocation.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.awt.Point} object.
|
||||
*/
|
||||
@@ -503,9 +571,12 @@ public class CardPanel extends JPanel implements CardContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setText.</p>
|
||||
* <p>
|
||||
* setText.
|
||||
* </p>
|
||||
*
|
||||
* @param card a {@link forge.Card} object.
|
||||
* @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,7 +604,9 @@ public class CardPanel extends JPanel implements CardContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getCard.</p>
|
||||
* <p>
|
||||
* getCard.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.Card} object.
|
||||
*/
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>HandArea class.</p>
|
||||
* <p>
|
||||
* HandArea class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
@@ -17,10 +20,14 @@ public class HandArea extends CardArea {
|
||||
private static final long serialVersionUID = 7488132628637407745L;
|
||||
|
||||
/**
|
||||
* <p>Constructor for HandArea.</p>
|
||||
* <p>
|
||||
* Constructor for HandArea.
|
||||
* </p>
|
||||
*
|
||||
* @param scrollPane a {@link javax.swing.JScrollPane} object.
|
||||
* @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) {
|
||||
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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* <p>Abstract Animation class.</p>
|
||||
* <p>
|
||||
* Abstract Animation class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
abstract public class Animation {
|
||||
/** Constant <code>TARGET_MILLIS_PER_FRAME=30</code> */
|
||||
static private final long TARGET_MILLIS_PER_FRAME = 30;
|
||||
public abstract class Animation {
|
||||
/** Constant <code>TARGET_MILLIS_PER_FRAME=30</code>. */
|
||||
private static final long TARGET_MILLIS_PER_FRAME = 30;
|
||||
|
||||
/** Constant <code>timer</code> */
|
||||
static private Timer timer = new Timer("Animation", true);
|
||||
/** Constant <code>timer</code>. */
|
||||
private static Timer timer = new Timer("Animation", true);
|
||||
|
||||
/** Constant <code>delayedCardPanel</code> */
|
||||
static private CardPanel delayedCardPanel;
|
||||
/** Constant <code>delayedTime=</code> */
|
||||
static private long delayedTime;
|
||||
/** Constant <code>enlargedCardPanel</code> */
|
||||
static private CardPanel enlargedCardPanel;
|
||||
/** Constant <code>enlargedAnimationPanel</code> */
|
||||
static private CardPanel enlargedAnimationPanel;
|
||||
/** Constant <code>enlargeLock</code> */
|
||||
static private Object enlargeLock = new Object();
|
||||
/** Constant <code>delayedCardPanel</code>. */
|
||||
private static CardPanel delayedCardPanel;
|
||||
/** Constant <code>delayedTime=</code>. */
|
||||
private static long delayedTime;
|
||||
/** Constant <code>enlargedCardPanel</code>. */
|
||||
private static CardPanel enlargedCardPanel;
|
||||
/** Constant <code>enlargedAnimationPanel</code>. */
|
||||
private static CardPanel enlargedAnimationPanel;
|
||||
/** Constant <code>enlargeLock</code>. */
|
||||
private static Object enlargeLock = new Object();
|
||||
|
||||
private TimerTask timerTask;
|
||||
private FrameTimer frameTimer;
|
||||
private long elapsed;
|
||||
|
||||
/**
|
||||
* <p>Constructor for Animation.</p>
|
||||
* <p>
|
||||
* Constructor for Animation.
|
||||
* </p>
|
||||
*
|
||||
* @param duration a long.
|
||||
* @param duration
|
||||
* a long.
|
||||
*/
|
||||
public Animation(final long duration) {
|
||||
this(duration, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Constructor for Animation.</p>
|
||||
* <p>
|
||||
* Constructor for Animation.
|
||||
* </p>
|
||||
*
|
||||
* @param duration a long.
|
||||
* @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() {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>update.</p>
|
||||
* <p>
|
||||
* update.
|
||||
* </p>
|
||||
*
|
||||
* @param percentage a float.
|
||||
* @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();
|
||||
end();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>start.</p>
|
||||
* <p>
|
||||
* start.
|
||||
* </p>
|
||||
*/
|
||||
protected void start() {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>end.</p>
|
||||
* <p>
|
||||
* end.
|
||||
* </p>
|
||||
*/
|
||||
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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>tapCardToggle.</p>
|
||||
* <p>
|
||||
* tapCardToggle.
|
||||
* </p>
|
||||
*
|
||||
* @param panel a {@link arcane.ui.CardPanel} object.
|
||||
* @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) {
|
||||
/**
|
||||
* <p>moveCardToPlay.</p>
|
||||
* <p>
|
||||
* moveCardToPlay.
|
||||
* </p>
|
||||
*
|
||||
* @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.
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>moveCard.</p>
|
||||
* <p>
|
||||
* moveCard.
|
||||
* </p>
|
||||
*
|
||||
* @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.
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>moveCard.</p>
|
||||
* <p>
|
||||
* moveCard.
|
||||
* </p>
|
||||
*
|
||||
* @param placeholder a {@link arcane.ui.CardPanel} object.
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>shrinkCard.</p>
|
||||
* <p>
|
||||
* shrinkCard.
|
||||
* </p>
|
||||
*/
|
||||
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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>enlargeCard.</p>
|
||||
* <p>
|
||||
* enlargeCard.
|
||||
* </p>
|
||||
*
|
||||
* @param overPanel a {@link arcane.ui.CardPanel} object.
|
||||
* @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) {
|
||||
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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isShowingEnlargedCard.</p>
|
||||
* <p>
|
||||
* isShowingEnlargedCard.
|
||||
* </p>
|
||||
*
|
||||
* @return a boolean.
|
||||
*/
|
||||
static public boolean isShowingEnlargedCard() {
|
||||
public static boolean isShowingEnlargedCard() {
|
||||
synchronized (enlargeLock) {
|
||||
return enlargedAnimationPanel != null;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
/**
|
||||
* <p>mouseOut.</p>
|
||||
@@ -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);
|
||||
|
||||
/**
|
||||
* <p>mouseLeftClicked.</p>
|
||||
@@ -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);
|
||||
|
||||
/**
|
||||
* <p>mouseMiddleClicked.</p>
|
||||
@@ -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);
|
||||
|
||||
/**
|
||||
* <p>mouseRightClicked.</p>
|
||||
@@ -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);
|
||||
|
||||
/**
|
||||
* <p>mouseDragStart.</p>
|
||||
@@ -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);
|
||||
|
||||
/**
|
||||
* <p>mouseDragged.</p>
|
||||
@@ -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);
|
||||
|
||||
/**
|
||||
* <p>mouseDragEnd.</p>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* <p>GlowText class.</p>
|
||||
* <p>
|
||||
* GlowText class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class GlowText extends JLabel {
|
||||
/** Constant <code>serialVersionUID=-2868833097364223352L</code> */
|
||||
/** Constant <code>serialVersionUID=-2868833097364223352L</code>. */
|
||||
private static final long serialVersionUID = -2868833097364223352L;
|
||||
private int glowSize;
|
||||
private Color glowColor;
|
||||
private boolean wrap;
|
||||
|
||||
/**
|
||||
* <p>setGlow.</p>
|
||||
* <p>
|
||||
* setGlow.
|
||||
* </p>
|
||||
*
|
||||
* @param glowColor a {@link java.awt.Color} object.
|
||||
* @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.glowSize = size;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Setter for the field <code>wrap</code>.</p>
|
||||
* <p>
|
||||
* Setter for the field <code>wrap</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param wrap a boolean.
|
||||
* @param wrap
|
||||
* a boolean.
|
||||
*/
|
||||
public void setWrap(boolean wrap) {
|
||||
public final void setWrap(final boolean wrap) {
|
||||
this.wrap = wrap;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getPreferredSize.</p>
|
||||
* <p>
|
||||
* getPreferredSize.
|
||||
* </p>
|
||||
*
|
||||
* @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.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* <p>ImageUtil class.</p>
|
||||
* <p>
|
||||
* ImageUtil class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ImageUtil {
|
||||
/**
|
||||
* <p>getImage.</p>
|
||||
* <p>
|
||||
* getImage.
|
||||
* </p>
|
||||
*
|
||||
* @param stream a {@link java.io.InputStream} object.
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getImage.</p>
|
||||
* <p>
|
||||
* getImage.
|
||||
* </p>
|
||||
*
|
||||
* @param file a {@link java.io.File} object.
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getBlurredImage.</p>
|
||||
* <p>
|
||||
* getBlurredImage.
|
||||
* </p>
|
||||
*
|
||||
* @param image a {@link java.awt.image.BufferedImage} object.
|
||||
* @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.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* <p>ManaSymbols class.</p>
|
||||
* <p>
|
||||
* ManaSymbols class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ManaSymbols {
|
||||
/** Constant <code>manaImages</code> */
|
||||
static private final Map<String, Image> manaImages = new HashMap<String, Image>();
|
||||
/** Constant <code>replaceSymbolsPattern</code> */
|
||||
static private Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
|
||||
/** Constant <code>manaImages</code>. */
|
||||
private static final Map<String, Image> manaImages = new HashMap<String, Image>();
|
||||
/** Constant <code>replaceSymbolsPattern</code>. */
|
||||
private static Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
|
||||
|
||||
/**
|
||||
* <p>loadImages.</p>
|
||||
* <p>
|
||||
* loadImages.
|
||||
* </p>
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>draw.</p>
|
||||
* <p>
|
||||
* draw.
|
||||
* </p>
|
||||
*
|
||||
* @param g a {@link java.awt.Graphics} object.
|
||||
* @param manaCost a {@link java.lang.String} object.
|
||||
* @param x a int.
|
||||
* @param y a int.
|
||||
* @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.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>drawAttack.</p>
|
||||
* <p>
|
||||
* drawAttack.
|
||||
* </p>
|
||||
*
|
||||
* @param g a {@link java.awt.Graphics} object.
|
||||
* @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");
|
||||
g.drawImage(image, x, y, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>drawSymbol.</p>
|
||||
* <p>
|
||||
* drawSymbol.
|
||||
* </p>
|
||||
*
|
||||
* @param imageName a {@link java.lang.String} object.
|
||||
* @param g a {@link java.awt.Graphics} object.
|
||||
* @param x a int.
|
||||
* @param y a int.
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getWidth.</p>
|
||||
* <p>
|
||||
* getWidth.
|
||||
* </p>
|
||||
*
|
||||
* @param manaCost a {@link java.lang.String} object.
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>replaceSymbolsWithHTML.</p>
|
||||
* <p>
|
||||
* replaceSymbolsWithHTML.
|
||||
* </p>
|
||||
*
|
||||
* @param value a {@link java.lang.String} object.
|
||||
* @param small a boolean.
|
||||
* @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}", "<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 {
|
||||
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>");
|
||||
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>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,6 +21,29 @@ 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.
|
||||
*
|
||||
@@ -32,53 +51,65 @@ import java.util.concurrent.ConcurrentMap;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class UI {
|
||||
/** Constant <code>imageCache</code> */
|
||||
static private ConcurrentMap<URI, Image> imageCache = new MapMaker().softValues().makeMap();
|
||||
/** Constant <code>imageCache</code>. */
|
||||
private static ConcurrentMap<URI, Image> imageCache = new MapMaker().softValues().makeMap();
|
||||
|
||||
/**
|
||||
* <p>getToggleButton.</p>
|
||||
* <p>
|
||||
* getToggleButton.
|
||||
* </p>
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getButton.</p>
|
||||
* <p>
|
||||
* getButton.
|
||||
* </p>
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setTitle.</p>
|
||||
* <p>
|
||||
* setTitle.
|
||||
* </p>
|
||||
*
|
||||
* @param panel a {@link javax.swing.JPanel} object.
|
||||
* @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();
|
||||
if (border instanceof TitledBorder) {
|
||||
((TitledBorder) panel.getBorder()).setTitle(title);
|
||||
panel.repaint();
|
||||
} else
|
||||
} else {
|
||||
panel.setBorder(BorderFactory.createTitledBorder(title));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getFileURL.</p>
|
||||
* <p>
|
||||
* getFileURL.
|
||||
* </p>
|
||||
*
|
||||
* @param path a {@link java.lang.String} object.
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getImageIcon.</p>
|
||||
* <p>
|
||||
* getImageIcon.
|
||||
* </p>
|
||||
*
|
||||
* @param path a {@link java.lang.String} object.
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setHTMLEditorKit.</p>
|
||||
* <p>
|
||||
* setHTMLEditorKit.
|
||||
* </p>
|
||||
*
|
||||
* @param editorPane a {@link javax.swing.JEditorPane} object.
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setVerticalScrollingView.</p>
|
||||
* <p>
|
||||
* setVerticalScrollingView.
|
||||
* </p>
|
||||
*
|
||||
* @param scrollPane a {@link javax.swing.JScrollPane} object.
|
||||
* @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();
|
||||
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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getDisplayManaCost.</p>
|
||||
* <p>
|
||||
* getDisplayManaCost.
|
||||
* </p>
|
||||
*
|
||||
* @param manaCost a {@link java.lang.String} object.
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>invokeLater.</p>
|
||||
* <p>
|
||||
* invokeLater.
|
||||
* </p>
|
||||
*
|
||||
* @param runnable a {@link java.lang.Runnable} object.
|
||||
* @param runnable
|
||||
* a {@link java.lang.Runnable} object.
|
||||
*/
|
||||
static public void invokeLater(Runnable runnable) {
|
||||
public static void invokeLater(final Runnable runnable) {
|
||||
EventQueue.invokeLater(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>invokeAndWait.</p>
|
||||
* <p>
|
||||
* invokeAndWait.
|
||||
* </p>
|
||||
*
|
||||
* @param runnable a {@link java.lang.Runnable} object.
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setSystemLookAndFeel.</p>
|
||||
* <p>
|
||||
* setSystemLookAndFeel.
|
||||
* </p>
|
||||
*/
|
||||
static public void setSystemLookAndFeel() {
|
||||
public static void setSystemLookAndFeel() {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (Exception ex) {
|
||||
@@ -230,14 +301,19 @@ public class UI {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setDefaultFont.</p>
|
||||
* <p>
|
||||
* setDefaultFont.
|
||||
* </p>
|
||||
*
|
||||
* @param font a {@link java.awt.Font} object.
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
/** Forge Card Game */
|
||||
/** Forge Card Game. */
|
||||
package arcane.ui.util;
|
||||
|
||||
@@ -13,25 +13,32 @@ public class MultiplexOutputStream extends OutputStream {
|
||||
private final OutputStream[] streams;
|
||||
|
||||
/**
|
||||
* <p>Constructor for MultiplexOutputStream.</p>
|
||||
* <p>
|
||||
* Constructor for MultiplexOutputStream.
|
||||
* </p>
|
||||
*
|
||||
* @param streams a {@link java.io.OutputStream} object.
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* <p>Util class.</p>
|
||||
* <p>
|
||||
* Util class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
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 <code>isWindows=System.getProperty("os.name").toLowerCase().indexOf("windows") == -1</code> */
|
||||
static public final boolean isWindows = System.getProperty("os.name").toLowerCase().indexOf("windows") == -1;
|
||||
/**
|
||||
* Constant.
|
||||
* <code>isMac=System.getProperty("os.name").toLowerCase().indexOf("mac") != -1</code>.
|
||||
*/
|
||||
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> */
|
||||
static public ThreadPoolExecutor threadPool;
|
||||
/** Constant <code>threadCount</code> */
|
||||
static private int threadCount;
|
||||
/** Constant <code>threadPool</code>. */
|
||||
public static ThreadPoolExecutor threadPool;
|
||||
/** Constant <code>threadCount</code>. */
|
||||
private static int threadCount;
|
||||
|
||||
static {
|
||||
threadPool = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), 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<Runnable>(),
|
||||
new ThreadFactory() {
|
||||
public Thread newThread(final Runnable runnable) {
|
||||
threadCount++;
|
||||
Thread thread = new Thread(runnable, "Util" + threadCount);
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
}
|
||||
});
|
||||
threadPool.prestartAllCoreThreads();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>broadcast.</p>
|
||||
* <p>
|
||||
* broadcast.
|
||||
* </p>
|
||||
*
|
||||
* @param data an array of byte.
|
||||
* @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();
|
||||
broadcast(socket, data, port, NetworkInterface.getNetworkInterfaces());
|
||||
socket.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>broadcast.</p>
|
||||
* <p>
|
||||
* broadcast.
|
||||
* </p>
|
||||
*
|
||||
* @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.
|
||||
* @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<NetworkInterface> ifaces)
|
||||
throws IOException {
|
||||
private static void broadcast(final DatagramSocket socket,
|
||||
final byte[] data, final int port, final Enumeration<NetworkInterface> 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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>invokeAndWait.</p>
|
||||
* <p>
|
||||
* invokeAndWait.
|
||||
* </p>
|
||||
*
|
||||
* @param runnable a {@link java.lang.Runnable} object.
|
||||
* @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 {
|
||||
SwingUtilities.invokeAndWait(runnable);
|
||||
} catch (Exception ex) {
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
/** Forge Card Game */
|
||||
/** Forge Card Game. */
|
||||
package arcane.util;
|
||||
|
||||
Reference in New Issue
Block a user