[refactoring][minor] Replaced all tabs with four spaces.

This commit is contained in:
North 2012-06-19 23:50:20 +03:00
parent e646e4768d
commit 239a4fb100
2891 changed files with 79411 additions and 79411 deletions

View file

@ -26,7 +26,7 @@ public class AudioManager {
audioManager = new AudioManager();
audioManager.nextPageClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPrevPage.wav"); //sounds better than OnNextPage
audioManager.prevPageClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPrevPage.wav");
audioManager.anotherTabClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnNextPage.wav");
audioManager.anotherTabClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnNextPage.wav");
audioManager.nextPhaseClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnNextPhase.wav");
audioManager.endTurnClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnEndTurn.wav");
audioManager.tapPermanentClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnTapPermanent.wav");
@ -52,7 +52,7 @@ public class AudioManager {
checkAndPlayClip(getManager().prevPageClip);
}
public static void playAnotherTab() {
public static void playAnotherTab() {
checkAndPlayClip(getManager().anotherTabClip);
}
@ -151,7 +151,7 @@ public class AudioManager {
private Clip nextPageClip = null;
private Clip prevPageClip = null;
private Clip anotherTabClip = null;
private Clip anotherTabClip = null;
private Clip nextPhaseClip = null;
private Clip endTurnClip = null;
private Clip tapPermanentClip = null;

View file

@ -48,85 +48,85 @@ import javax.swing.table.TableColumnModel;
*/
public class ButtonColumn extends AbstractCellEditor implements TableCellRenderer, TableCellEditor, ActionListener, MouseListener {
private JTable table;
private Action action;
private JButton renderButton;
private JButton editButton;
private String text;
private boolean isButtonColumnEditor;
private JTable table;
private Action action;
private JButton renderButton;
private JButton editButton;
private String text;
private boolean isButtonColumnEditor;
public ButtonColumn(JTable table, Action action, int column) {
super();
this.table = table;
this.action = action;
renderButton = new JButton();
public ButtonColumn(JTable table, Action action, int column) {
super();
this.table = table;
this.action = action;
renderButton = new JButton();
editButton = new JButton();
editButton.setFocusPainted(false);
editButton.addActionListener(this);
editButton = new JButton();
editButton.setFocusPainted(false);
editButton.addActionListener(this);
TableColumnModel columnModel = table.getColumnModel();
columnModel.getColumn(column).setCellRenderer(this);
columnModel.getColumn(column).setCellEditor(this);
table.addMouseListener(this);
}
TableColumnModel columnModel = table.getColumnModel();
columnModel.getColumn(column).setCellRenderer(this);
columnModel.getColumn(column).setCellEditor(this);
table.addMouseListener(this);
}
public Object getCellEditorValue() {
return text;
}
public Object getCellEditorValue() {
return text;
}
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (hasFocus)
{
renderButton.setForeground(table.getForeground());
renderButton.setBackground(UIManager.getColor("Button.background"));
}
else if (isSelected)
{
renderButton.setForeground(table.getSelectionForeground());
renderButton.setBackground(table.getSelectionBackground());
}
else
{
renderButton.setForeground(table.getForeground());
renderButton.setBackground(UIManager.getColor("Button.background"));
}
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (hasFocus)
{
renderButton.setForeground(table.getForeground());
renderButton.setBackground(UIManager.getColor("Button.background"));
}
else if (isSelected)
{
renderButton.setForeground(table.getSelectionForeground());
renderButton.setBackground(table.getSelectionBackground());
}
else
{
renderButton.setForeground(table.getForeground());
renderButton.setBackground(UIManager.getColor("Button.background"));
}
renderButton.setText( (value == null) ? "" : value.toString() );
return renderButton;
}
renderButton.setText( (value == null) ? "" : value.toString() );
return renderButton;
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
text = (value == null) ? "" : value.toString();
editButton.setText( text );
return editButton;
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
text = (value == null) ? "" : value.toString();
editButton.setText( text );
return editButton;
}
public void actionPerformed(ActionEvent e) {
int row = table.convertRowIndexToModel( table.getEditingRow() );
fireEditingStopped();
ActionEvent event = new ActionEvent(table, ActionEvent.ACTION_PERFORMED, "" + row);
action.actionPerformed(event);
public void actionPerformed(ActionEvent e) {
int row = table.convertRowIndexToModel( table.getEditingRow() );
fireEditingStopped();
ActionEvent event = new ActionEvent(table, ActionEvent.ACTION_PERFORMED, "" + row);
action.actionPerformed(event);
}
}
public void mousePressed(MouseEvent arg0) {
if (table.isEditing() && table.getCellEditor() == this)
isButtonColumnEditor = true;
}
public void mousePressed(MouseEvent arg0) {
if (table.isEditing() && table.getCellEditor() == this)
isButtonColumnEditor = true;
}
public void mouseReleased(MouseEvent arg0) {
if (isButtonColumnEditor && table.isEditing())
table.getCellEditor().stopCellEditing();
public void mouseReleased(MouseEvent arg0) {
if (isButtonColumnEditor && table.isEditing())
table.getCellEditor().stopCellEditing();
isButtonColumnEditor = false;
}
isButtonColumnEditor = false;
}
public void mouseClicked(MouseEvent arg0) {}
public void mouseClicked(MouseEvent arg0) {}
public void mouseEntered(MouseEvent arg0) {}
public void mouseEntered(MouseEvent arg0) {}
public void mouseExited(MouseEvent arg0) {}
public void mouseExited(MouseEvent arg0) {}
}

View file

@ -37,15 +37,15 @@ import mage.view.CardView;
*/
public class CardViewColorComparator implements Comparator<CardView> {
@Override
public int compare(CardView o1, CardView o2) {
int val = o1.getColor().compareTo(o2.getColor());
if (val == 0) {
return o1.getName().compareTo(o2.getName());
}
else {
return val;
}
}
@Override
public int compare(CardView o1, CardView o2) {
int val = o1.getColor().compareTo(o2.getColor());
if (val == 0) {
return o1.getName().compareTo(o2.getName());
}
else {
return val;
}
}
}

View file

@ -37,15 +37,15 @@ import mage.view.CardView;
*/
public class CardViewCostComparator implements Comparator<CardView> {
@Override
public int compare(CardView o1, CardView o2) {
int val = Integer.valueOf(o1.getConvertedManaCost()).compareTo(Integer.valueOf(o2.getConvertedManaCost()));
if (val == 0) {
return o1.getName().compareTo(o2.getName());
}
else {
return val;
}
}
@Override
public int compare(CardView o1, CardView o2) {
int val = Integer.valueOf(o1.getConvertedManaCost()).compareTo(Integer.valueOf(o2.getConvertedManaCost()));
if (val == 0) {
return o1.getName().compareTo(o2.getName());
}
else {
return val;
}
}
}

View file

@ -37,9 +37,9 @@ import mage.view.CardView;
*/
public class CardViewNameComparator implements Comparator<CardView> {
@Override
public int compare(CardView o1, CardView o2) {
return o1.getName().compareTo(o2.getName());
}
@Override
public int compare(CardView o1, CardView o2) {
return o1.getName().compareTo(o2.getName());
}
}

View file

@ -37,15 +37,15 @@ import mage.view.CardView;
*/
public class CardViewRarityComparator implements Comparator<CardView> {
@Override
public int compare(CardView o1, CardView o2) {
int val = o1.getRarity().compareTo(o2.getRarity());
if (val == 0) {
return o1.getName().compareTo(o2.getName());
}
else {
return val;
}
}
@Override
public int compare(CardView o1, CardView o2) {
int val = o1.getRarity().compareTo(o2.getRarity());
if (val == 0) {
return o1.getName().compareTo(o2.getName());
}
else {
return val;
}
}
}

View file

@ -39,19 +39,19 @@ import mage.view.SimpleCardsView;
* @author BetaSteward_at_googlemail.com
*/
public class CardsViewUtil {
public static CardsView convertSimple(SimpleCardsView view) {
CardsView cards = new CardsView();
for (SimpleCardView simple: view.values()) {
mage.cards.Card card = Sets.findCard(simple.getExpansionSetCode(), simple.getCardNumber());
if (card != null) {
cards.put(simple.getId(), new CardView(card, simple.getId()));
}
}
return cards;
}
}

View file

@ -42,38 +42,38 @@ import org.apache.log4j.Logger;
*/
public class Config {
private final static Logger logger = Logger.getLogger(Config.class);
private final static Logger logger = Logger.getLogger(Config.class);
public static final String remoteServer;
public static final String serverName;
public static final int port;
public static final double cardScalingFactor;
public static final String remoteServer;
public static final String serverName;
public static final int port;
public static final double cardScalingFactor;
public static final double handScalingFactor;
public static final CardDimensions dimensions;
public static final String defaultGameType;
public static final String defaultDeckPath;
public static final String defaultOtherPlayerIndex;
public static final String defaultComputerName;
public static final CardDimensions dimensions;
static {
Properties p = new Properties();
try {
p.load(new FileInputStream(new File("config/config.properties")));
} catch (IOException ex) {
logger.fatal("Config error ", ex);
}
serverName = p.getProperty("server-name");
port = Integer.parseInt(p.getProperty("port"));
remoteServer = p.getProperty("remote-server");
cardScalingFactor = Double.valueOf(p.getProperty("card-scaling-factor"));
public static final String defaultGameType;
public static final String defaultDeckPath;
public static final String defaultOtherPlayerIndex;
public static final String defaultComputerName;
static {
Properties p = new Properties();
try {
p.load(new FileInputStream(new File("config/config.properties")));
} catch (IOException ex) {
logger.fatal("Config error ", ex);
}
serverName = p.getProperty("server-name");
port = Integer.parseInt(p.getProperty("port"));
remoteServer = p.getProperty("remote-server");
cardScalingFactor = Double.valueOf(p.getProperty("card-scaling-factor"));
handScalingFactor = Double.valueOf(p.getProperty("hand-scaling-factor"));
defaultGameType = p.getProperty("default-game-type", "Human");
defaultDeckPath = p.getProperty("default-deck-path");
defaultOtherPlayerIndex = p.getProperty("default-other-player-index");
defaultComputerName = p.getProperty("default-computer-name");
dimensions = new CardDimensions(cardScalingFactor);
}
defaultGameType = p.getProperty("default-game-type", "Human");
defaultDeckPath = p.getProperty("default-deck-path");
defaultOtherPlayerIndex = p.getProperty("default-other-player-index");
defaultComputerName = p.getProperty("default-computer-name");
dimensions = new CardDimensions(cardScalingFactor);
}
}

View file

@ -43,35 +43,35 @@ import org.apache.log4j.Logger;
*/
public class DeckUtil {
private static final transient Logger log = Logger.getLogger(DeckUtil.class);
private static final transient Logger log = Logger.getLogger(DeckUtil.class);
private DeckUtil() {
}
private DeckUtil() {
}
public static Deck construct(DeckView view) {
Deck deck = new Deck();
for (SimpleCardView cardView : view.getCards().values()) {
ExpansionSet set = Sets.findSet(cardView.getExpansionSetCode());
if (set != null) {
Card card = set.findCard(cardView.getCardNumber());
if (card != null) {
deck.getCards().add(card);
} else {
log.fatal("(Deck constructing) Couldn't find card: set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber()));
}
}
}
for (SimpleCardView cardView : view.getSideboard().values()) {
ExpansionSet set = Sets.findSet(cardView.getExpansionSetCode());
if (set != null) {
Card card = set.findCard(cardView.getCardNumber());
if (card != null) {
deck.getSideboard().add(card);
} else {
log.fatal("(Deck constructing) Couldn't find card: set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber()));
}
}
}
return deck;
}
public static Deck construct(DeckView view) {
Deck deck = new Deck();
for (SimpleCardView cardView : view.getCards().values()) {
ExpansionSet set = Sets.findSet(cardView.getExpansionSetCode());
if (set != null) {
Card card = set.findCard(cardView.getCardNumber());
if (card != null) {
deck.getCards().add(card);
} else {
log.fatal("(Deck constructing) Couldn't find card: set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber()));
}
}
}
for (SimpleCardView cardView : view.getSideboard().values()) {
ExpansionSet set = Sets.findSet(cardView.getExpansionSetCode());
if (set != null) {
Card card = set.findCard(cardView.getCardNumber());
if (card != null) {
deck.getSideboard().add(card);
} else {
log.fatal("(Deck constructing) Couldn't find card: set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber()));
}
}
}
return deck;
}
}

View file

@ -8,22 +8,22 @@ import mage.view.CardView;
public class DefaultActionCallback {
private static final DefaultActionCallback INSTANCE = new DefaultActionCallback();
private DefaultActionCallback() {}
public static DefaultActionCallback getInstance() {
return INSTANCE;
}
public void mouseClicked(MouseEvent e, UUID gameId, Session session, CardView card) {
if (gameId != null) {
if (card.isAbility() && card.getAbility() != null) {
session.sendPlayerUUID(gameId, card.getAbility().getId());
} else {
session.sendPlayerUUID(gameId, card.getId());
}
}
}
private static final DefaultActionCallback INSTANCE = new DefaultActionCallback();
private DefaultActionCallback() {}
public static DefaultActionCallback getInstance() {
return INSTANCE;
}
public void mouseClicked(MouseEvent e, UUID gameId, Session session, CardView card) {
if (gameId != null) {
if (card.isAbility() && card.getAbility() != null) {
session.sendPlayerUUID(gameId, card.getAbility().getId());
} else {
session.sendPlayerUUID(gameId, card.getId());
}
}
}
}

View file

@ -38,23 +38,23 @@ import org.apache.log4j.Logger;
*/
public class EDTExceptionHandler implements Thread.UncaughtExceptionHandler {
private final static Logger logger = Logger.getLogger(EDTExceptionHandler.class);
private final static Logger logger = Logger.getLogger(EDTExceptionHandler.class);
@Override
public void uncaughtException(Thread t, Throwable e) {
handle(e);
}
@Override
public void uncaughtException(Thread t, Throwable e) {
handle(e);
}
public void handle(Throwable throwable) {
try {
logger.fatal(null, throwable);
JOptionPane.showMessageDialog(MageFrame.getDesktop(), throwable, "MAGE Client UI error", JOptionPane.ERROR_MESSAGE);
} catch (Throwable t) {}
}
public void handle(Throwable throwable) {
try {
logger.fatal(null, throwable);
JOptionPane.showMessageDialog(MageFrame.getDesktop(), throwable, "MAGE Client UI error", JOptionPane.ERROR_MESSAGE);
} catch (Throwable t) {}
}
public static void registerExceptionHandler() {
Thread.setDefaultUncaughtExceptionHandler(new EDTExceptionHandler());
System.setProperty("sun.awt.exception.handler", EDTExceptionHandler.class.getName());
}
public static void registerExceptionHandler() {
Thread.setDefaultUncaughtExceptionHandler(new EDTExceptionHandler());
System.setProperty("sun.awt.exception.handler", EDTExceptionHandler.class.getName());
}
}

View file

@ -35,19 +35,19 @@ import java.io.Serializable;
* @author BetaSteward_at_googlemail.com
*/
public class Event implements Serializable {
private Object source;
private String eventName;
private Object source;
private String eventName;
public Event(Object source, String eventName) {
this.source = source;
this.eventName = eventName;
}
public Event(Object source, String eventName) {
this.source = source;
this.eventName = eventName;
}
public Object getSource() {
return source;
}
public Object getSource() {
return source;
}
public String getEventName() {
return eventName;
}
public String getEventName() {
return eventName;
}
}

View file

@ -38,25 +38,25 @@ import java.util.concurrent.CopyOnWriteArrayList;
*/
public abstract class EventDispatcher<E extends Event> implements Serializable {
private List<Listener<E>> listeners = new CopyOnWriteArrayList<Listener<E>>();
private List<Listener<E>> listeners = new CopyOnWriteArrayList<Listener<E>>();
public void addListener(Listener<E> listener) {
if (!listeners.contains(listener)) {
listeners.add(listener);
}
}
public void addListener(Listener<E> listener) {
if (!listeners.contains(listener)) {
listeners.add(listener);
}
}
public void removeListener(Listener<E> listener) {
listeners.remove(listener);
}
public void removeListener(Listener<E> listener) {
listeners.remove(listener);
}
public void fireEvent(E event) {
for (Listener<E> listener : listeners) {
listener.event(event);
}
}
public void fireEvent(E event) {
for (Listener<E> listener : listeners) {
listener.event(event);
}
}
public void clearListeners() {
listeners.clear();
}
public void clearListeners() {
listeners.clear();
}
}

View file

@ -36,7 +36,7 @@ import java.io.Serializable;
*/
public interface EventSource<E extends Event> extends Serializable {
void addListener(Listener<E> listener);
void clearListeners();
void addListener(Listener<E> listener);
void clearListeners();
}

View file

@ -3,21 +3,21 @@ package mage.client.util;
import java.io.File;
public class FileUtils {
public static File getTempDir(String key) {
String tmpDir = System.getProperty("java.io.tmpdir");
String sep = System.getProperty("file.separator");
public static File getTempDir(String key) {
String tmpDir = System.getProperty("java.io.tmpdir");
String sep = System.getProperty("file.separator");
if (!tmpDir.endsWith(sep))
tmpDir += sep;
if (!tmpDir.endsWith(sep))
tmpDir += sep;
tmpDir += key + "-" + java.util.UUID.randomUUID().toString();
tmpDir += key + "-" + java.util.UUID.randomUUID().toString();
File dir = new File(tmpDir);
if (!dir.mkdirs()) {
throw new RuntimeException("couldn't create temp directory " + tmpDir);
}
File dir = new File(tmpDir);
if (!dir.mkdirs()) {
throw new RuntimeException("couldn't create temp directory " + tmpDir);
}
return dir;
return dir;
}
}
}

View file

@ -56,123 +56,123 @@ import java.awt.Rectangle;
* @author BetaSteward_at_googlemail.com
*/
public class ImageHelper {
protected static HashMap<String, BufferedImage> images = new HashMap<String, BufferedImage>();
protected static HashMap<String, BufferedImage> backgrounds = new HashMap<String, BufferedImage>();
protected static HashMap<String, BufferedImage> images = new HashMap<String, BufferedImage>();
protected static HashMap<String, BufferedImage> backgrounds = new HashMap<String, BufferedImage>();
public static BufferedImage loadImage(String ref, int width, int height) {
BufferedImage image = loadImage(ref);
if (image != null)
return scaleImage(image, width, height);
return null;
}
public static BufferedImage loadImage(String ref, int width, int height) {
BufferedImage image = loadImage(ref);
if (image != null)
return scaleImage(image, width, height);
return null;
}
/**
*
* @param ref - image name
* @param height - height after scaling
* @return a scaled image that preserves the original aspect ratio, with a specified height
*/
public static BufferedImage loadImage(String ref, int height) {
BufferedImage image = loadImage(ref);
if (image != null)
return scaleImage(image, height);
return null;
}
/**
*
* @param ref - image name
* @param height - height after scaling
* @return a scaled image that preserves the original aspect ratio, with a specified height
*/
public static BufferedImage loadImage(String ref, int height) {
BufferedImage image = loadImage(ref);
if (image != null)
return scaleImage(image, height);
return null;
}
public static BufferedImage loadImage(String ref) {
if (!images.containsKey(ref)) {
try {
images.put(ref, ImageIO.read(ImageHelper.class.getResourceAsStream(ref)));
} catch (Exception e) {
return null;
}
}
return images.get(ref);
}
public static BufferedImage loadImage(String ref) {
if (!images.containsKey(ref)) {
try {
images.put(ref, ImageIO.read(ImageHelper.class.getResourceAsStream(ref)));
} catch (Exception e) {
return null;
}
}
return images.get(ref);
}
public static BufferedImage getBackground(CardView card, String backgroundName) {
if (backgrounds.containsKey(backgroundName)) {
return backgrounds.get(backgroundName);
}
BufferedImage background = new BufferedImage(FRAME_MAX_WIDTH, FRAME_MAX_HEIGHT, BufferedImage.TYPE_INT_RGB);
backgrounds.put(backgroundName, background);
return background;
}
public static BufferedImage getBackground(CardView card, String backgroundName) {
if (backgrounds.containsKey(backgroundName)) {
return backgrounds.get(backgroundName);
}
BufferedImage background = new BufferedImage(FRAME_MAX_WIDTH, FRAME_MAX_HEIGHT, BufferedImage.TYPE_INT_RGB);
backgrounds.put(backgroundName, background);
return background;
}
public static BufferedImage scaleImage(BufferedImage image, int width, int height) {
BufferedImage scaledImage = image;
int w = image.getWidth();
int h = image.getHeight();
do {
w /= 2;
h /= 2;
if (w < width || h < height) {
w = width;
h = height;
}
BufferedImage newImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics2D = newImage.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(scaledImage, 0, 0, w, h, null);
graphics2D.dispose();
scaledImage = newImage;
} while (w != width || h != height);
return scaledImage;
}
public static BufferedImage scaleImage(BufferedImage image, int width, int height) {
BufferedImage scaledImage = image;
int w = image.getWidth();
int h = image.getHeight();
do {
w /= 2;
h /= 2;
if (w < width || h < height) {
w = width;
h = height;
}
BufferedImage newImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics2D = newImage.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(scaledImage, 0, 0, w, h, null);
graphics2D.dispose();
scaledImage = newImage;
} while (w != width || h != height);
return scaledImage;
}
public static BufferedImage scaleImage(BufferedImage image, int height) {
double ratio = height / (double)image.getHeight();
int width = (int) (image.getWidth() * ratio);
return scaleImage(image, width, height);
}
public static BufferedImage scaleImage(BufferedImage image, int height) {
double ratio = height / (double)image.getHeight();
int width = (int) (image.getWidth() * ratio);
return scaleImage(image, width, height);
}
public static MemoryImageSource rotate(Image image, CardDimensions dimensions) {
int buffer[] = new int[dimensions.frameWidth * dimensions.frameHeight];
int rotate[] = new int[dimensions.frameHeight * dimensions.frameWidth];
PixelGrabber grabber = new PixelGrabber(image, 0, 0, dimensions.frameWidth, dimensions.frameHeight, buffer, 0, dimensions.frameWidth);
try {
grabber.grabPixels();
}
catch(InterruptedException e) {
e.printStackTrace();
}
for(int y = 0; y < dimensions.frameHeight; y++) {
for(int x = 0; x < dimensions.frameWidth; x++) {
rotate[((dimensions.frameWidth - x - 1) *dimensions.frameHeight)+y] = buffer[(y*dimensions.frameWidth)+x];
}
}
public static MemoryImageSource rotate(Image image, CardDimensions dimensions) {
int buffer[] = new int[dimensions.frameWidth * dimensions.frameHeight];
int rotate[] = new int[dimensions.frameHeight * dimensions.frameWidth];
PixelGrabber grabber = new PixelGrabber(image, 0, 0, dimensions.frameWidth, dimensions.frameHeight, buffer, 0, dimensions.frameWidth);
try {
grabber.grabPixels();
}
catch(InterruptedException e) {
e.printStackTrace();
}
for(int y = 0; y < dimensions.frameHeight; y++) {
for(int x = 0; x < dimensions.frameWidth; x++) {
rotate[((dimensions.frameWidth - x - 1) *dimensions.frameHeight)+y] = buffer[(y*dimensions.frameWidth)+x];
}
}
return new MemoryImageSource(dimensions.frameHeight, dimensions.frameWidth, rotate, 0, dimensions.frameHeight);
return new MemoryImageSource(dimensions.frameHeight, dimensions.frameWidth, rotate, 0, dimensions.frameHeight);
}
}
public static void drawCosts(List<String> costs, Graphics2D g, int xOffset, int yOffset, ImageObserver o) {
if (costs.size() > 0) {
int costLeft = xOffset;
for (int i = costs.size() - 1; i >= 0; i--) {
String symbol = costs.get(i);
g.drawString(symbol, costLeft, yOffset + SYMBOL_MAX_SPACE);
costLeft -= SYMBOL_MAX_SPACE + 4;
}
}
}
public static void drawCosts(List<String> costs, Graphics2D g, int xOffset, int yOffset, ImageObserver o) {
if (costs.size() > 0) {
int costLeft = xOffset;
for (int i = costs.size() - 1; i >= 0; i--) {
String symbol = costs.get(i);
g.drawString(symbol, costLeft, yOffset + SYMBOL_MAX_SPACE);
costLeft -= SYMBOL_MAX_SPACE + 4;
}
}
}
/**
* Returns an image scaled to the size appropriate for the card picture
* panel
*/
public static BufferedImage getResizedImage(BufferedImage original, int width, int height) {
ResampleOp resampleOp = new ResampleOp(width, height);
BufferedImage image = resampleOp.filter(original, null);
return image;
}
/**
* Returns an image scaled to the size appropriate for the card picture
* panel
*/
public static BufferedImage getResizedImage(BufferedImage original, int width, int height) {
ResampleOp resampleOp = new ResampleOp(width, height);
BufferedImage image = resampleOp.filter(original, null);
return image;
}
/**
* Returns an image scaled to fit width
* panel
*/
/**
* Returns an image scaled to fit width
* panel
*/
public static BufferedImage getResizedImage(BufferedImage original, int width) {
if (width != original.getWidth()) {
double ratio = width / (double) original.getWidth();
@ -183,33 +183,33 @@ public class ImageHelper {
}
}
/**
* Returns an image scaled to the needed size
*/
/**
* Returns an image scaled to the needed size
*/
public static BufferedImage getResizedImage(BufferedImage original, Rectangle sizeNeed) {
ResampleOp resampleOp = new ResampleOp(sizeNeed.width, sizeNeed.height);
BufferedImage image = resampleOp.filter(original, null);
return image;
}
ResampleOp resampleOp = new ResampleOp(sizeNeed.width, sizeNeed.height);
BufferedImage image = resampleOp.filter(original, null);
return image;
}
/**
* Get image using relative path in resources.
* @param path
* @return
*/
public static Image getImageFromResources(String path) {
InputStream stream;
stream = UI.class.getResourceAsStream(path);
if (stream == null) {
throw new IllegalArgumentException("Couldn't find image in resources: " + path);
}
/**
* Get image using relative path in resources.
* @param path
* @return
*/
public static Image getImageFromResources(String path) {
InputStream stream;
stream = UI.class.getResourceAsStream(path);
if (stream == null) {
throw new IllegalArgumentException("Couldn't find image in resources: " + path);
}
try {
BufferedImage image = ImageIO.read(stream);
return image;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
try {
BufferedImage image = ImageIO.read(stream);
return image;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

View file

@ -35,5 +35,5 @@ import java.io.Serializable;
* @author BetaSteward_at_googlemail.com
*/
public interface Listener<E extends Event> extends Serializable {
void event(E event);
void event(E event);
}

View file

@ -16,126 +16,126 @@ import javax.swing.JFrame;
import javax.swing.JPanel;
public class Arrow extends JPanel {
private static final long serialVersionUID = -4631054277822828303L;
private int startX;
private int startY;
private int endX;
private int endY;
private int bodyWidth = 10;
private float headSize = 17;
private Composite composite;
private Color color = Color.red;
private static final long serialVersionUID = -4631054277822828303L;
public Arrow () {
setOpaque(false);
setOpacity(0.6f);
}
private int startX;
private int startY;
private int endX;
private int endY;
private int bodyWidth = 10;
private float headSize = 17;
private Composite composite;
private Color color = Color.red;
protected void paintComponent (Graphics g) {
super.paintComponent(g);
float ex = endX - startX;
float ey = endY - startY;
if (ex == 0 && ey == 0) return;
float length = (float)Math.sqrt(ex * ex + ey * ey);
float bendPercent = (float)Math.asin(ey / length);
if (endX > startX) bendPercent = -bendPercent;
Area arrow = getArrow(length, bendPercent);
Graphics2D g2d = (Graphics2D)g;
g2d.translate(startX, startY);
g2d.rotate(Math.atan2(ey, ex));
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setComposite(composite);
g2d.setColor(this.color);
g2d.fill(arrow);
g2d.setColor(Color.BLACK);
g2d.draw(arrow);
}
public Arrow () {
setOpaque(false);
setOpacity(0.6f);
}
private Area getArrow (float length, float bendPercent) {
float p1x = 0, p1y = 0;
float p2x = length, p2y = 0;
float cx = length / 2, cy = length / 8f * bendPercent;
protected void paintComponent (Graphics g) {
super.paintComponent(g);
float ex = endX - startX;
float ey = endY - startY;
if (ex == 0 && ey == 0) return;
float length = (float)Math.sqrt(ex * ex + ey * ey);
float bendPercent = (float)Math.asin(ey / length);
if (endX > startX) bendPercent = -bendPercent;
Area arrow = getArrow(length, bendPercent);
Graphics2D g2d = (Graphics2D)g;
g2d.translate(startX, startY);
g2d.rotate(Math.atan2(ey, ex));
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setComposite(composite);
g2d.setColor(this.color);
g2d.fill(arrow);
g2d.setColor(Color.BLACK);
g2d.draw(arrow);
}
float adjSize, ex, ey, abs_e;
adjSize = (float)(bodyWidth / 2 / Math.sqrt(2));
ex = p2x - cx;
ey = p2y - cy;
abs_e = (float)Math.sqrt(ex * ex + ey * ey);
ex /= abs_e;
ey /= abs_e;
GeneralPath bodyPath = new GeneralPath();
bodyPath.moveTo(p2x + (ey - ex) * adjSize, p2y - (ex + ey) * adjSize);
bodyPath.quadTo(cx, cy, p1x, p1y - bodyWidth / 2);
bodyPath.lineTo(p1x, p1y + bodyWidth / 2);
bodyPath.quadTo(cx, cy, p2x - (ey + ex) * adjSize, p2y + (ex - ey) * adjSize);
bodyPath.closePath();
private Area getArrow (float length, float bendPercent) {
float p1x = 0, p1y = 0;
float p2x = length, p2y = 0;
float cx = length / 2, cy = length / 8f * bendPercent;
adjSize = (float)(headSize / Math.sqrt(2));
ex = p2x - cx;
ey = p2y - cy;
abs_e = (float)Math.sqrt(ex * ex + ey * ey);
ex /= abs_e;
ey /= abs_e;
GeneralPath headPath = new GeneralPath();
headPath.moveTo(p2x - (ey + ex) * adjSize, p2y + (ex - ey) * adjSize);
headPath.lineTo(p2x, p2y);
headPath.lineTo(p2x + (ey - ex) * adjSize, p2y - (ex + ey) * adjSize);
headPath.closePath();
float adjSize, ex, ey, abs_e;
adjSize = (float)(bodyWidth / 2 / Math.sqrt(2));
ex = p2x - cx;
ey = p2y - cy;
abs_e = (float)Math.sqrt(ex * ex + ey * ey);
ex /= abs_e;
ey /= abs_e;
GeneralPath bodyPath = new GeneralPath();
bodyPath.moveTo(p2x + (ey - ex) * adjSize, p2y - (ex + ey) * adjSize);
bodyPath.quadTo(cx, cy, p1x, p1y - bodyWidth / 2);
bodyPath.lineTo(p1x, p1y + bodyWidth / 2);
bodyPath.quadTo(cx, cy, p2x - (ey + ex) * adjSize, p2y + (ex - ey) * adjSize);
bodyPath.closePath();
Area area = new Area(headPath);
area.add(new Area(bodyPath));
return area;
}
adjSize = (float)(headSize / Math.sqrt(2));
ex = p2x - cx;
ey = p2y - cy;
abs_e = (float)Math.sqrt(ex * ex + ey * ey);
ex /= abs_e;
ey /= abs_e;
GeneralPath headPath = new GeneralPath();
headPath.moveTo(p2x - (ey + ex) * adjSize, p2y + (ex - ey) * adjSize);
headPath.lineTo(p2x, p2y);
headPath.lineTo(p2x + (ey - ex) * adjSize, p2y - (ex + ey) * adjSize);
headPath.closePath();
public int getBodyWidth () {
return bodyWidth;
}
Area area = new Area(headPath);
area.add(new Area(bodyPath));
return area;
}
public void setBodyWidth (int bodyWidth) {
this.bodyWidth = bodyWidth;
}
public int getBodyWidth () {
return bodyWidth;
}
public float getHeadSize () {
return headSize;
}
public void setBodyWidth (int bodyWidth) {
this.bodyWidth = bodyWidth;
}
public void setHeadSize (float headSize) {
this.headSize = headSize;
}
public float getHeadSize () {
return headSize;
}
public void setArrowLocation (int startX, int startY, int endX, int endY) {
this.startX = startX;
this.startY = startY;
this.endX = endX;
this.endY = endY;
repaint();
}
public void setHeadSize (float headSize) {
this.headSize = headSize;
}
public void setOpacity (float opacity) {
composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
}
public void setColor(Color color) {
this.color = color;
}
public void setArrowLocation (int startX, int startY, int endX, int endY) {
this.startX = startX;
this.startY = startY;
this.endX = endX;
this.endY = endY;
repaint();
}
public static void main (String[] args) {
final JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
final Arrow arrow = new Arrow();
frame.add(arrow, BorderLayout.CENTER);
frame.setSize(640, 480);
frame.setResizable(false);
frame.setVisible(true);
frame.getContentPane().addMouseMotionListener(new MouseMotionListener() {
public void mouseMoved (MouseEvent e) {
arrow.setArrowLocation(320, 240, e.getX(), e.getY());
}
public void setOpacity (float opacity) {
composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
}
public void mouseDragged (MouseEvent e) {
}
});
}
public void setColor(Color color) {
this.color = color;
}
public static void main (String[] args) {
final JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
final Arrow arrow = new Arrow();
frame.add(arrow, BorderLayout.CENTER);
frame.setSize(640, 480);
frame.setResizable(false);
frame.setVisible(true);
frame.getContentPane().addMouseMotionListener(new MouseMotionListener() {
public void mouseMoved (MouseEvent e) {
arrow.setArrowLocation(320, 240, e.getX(), e.getY());
}
public void mouseDragged (MouseEvent e) {
}
});
}
}

View file

@ -12,63 +12,63 @@ import java.util.Map;
* @author nantuko
*/
public class ArrowBuilder {
private static JPanel arrowsPanel;
private static JPanel arrowsPanel;
private final static Map<Type, java.util.List<Arrow>> map = new HashMap<Type, java.util.List<Arrow>>();
public enum Type {
PAIRED, SOURCE, TARGET, COMBAT;
}
/**
* Get the panel where all arrows are being drawn.
* @return
*/
public static JPanel getArrowsPanel() {
if (arrowsPanel == null) {
synchronized (ArrowBuilder.class) {
if (arrowsPanel == null) {
arrowsPanel = new JPanel();
arrowsPanel.setVisible(true);
arrowsPanel.setOpaque(false);
//arrowsPanel.setLayout(new BorderLayout());
arrowsPanel.setLayout(null);
//arrowsPanel.setBorder(BorderFactory.createLineBorder(Color.red));
}
}
}
return arrowsPanel;
}
/**
* Not synchronized method for arrows panel.
* Doesn't create JPanel in case the panel doesn't exist.
* Works faster.
*
* @return
*/
public static JPanel getArrowsPanelRef() {
return arrowsPanel;
}
/**
* Get the panel where all arrows are being drawn.
* @return
*/
public static JPanel getArrowsPanel() {
if (arrowsPanel == null) {
synchronized (ArrowBuilder.class) {
if (arrowsPanel == null) {
arrowsPanel = new JPanel();
arrowsPanel.setVisible(true);
arrowsPanel.setOpaque(false);
//arrowsPanel.setLayout(new BorderLayout());
arrowsPanel.setLayout(null);
//arrowsPanel.setBorder(BorderFactory.createLineBorder(Color.red));
}
}
}
return arrowsPanel;
}
/**
* Adds new arrow.
*
* @param startX
* @param startY
* @param endX
* @param endY
* @param color
*/
public static void addArrow(int startX, int startY, int endX, int endY, Color color, Type type) {
JPanel p = getArrowsPanel();
Arrow arrow = new Arrow();
arrow.setColor(color);
arrow.setArrowLocation(startX, startY, endX, endY);
arrow.setBounds(0, 0, Math.max(startX, endX) + 40, Math.max(startY, endY) + 30); // 30 is offset for arrow heads (being cut otherwise)
/**
* Not synchronized method for arrows panel.
* Doesn't create JPanel in case the panel doesn't exist.
* Works faster.
*
* @return
*/
public static JPanel getArrowsPanelRef() {
return arrowsPanel;
}
/**
* Adds new arrow.
*
* @param startX
* @param startY
* @param endX
* @param endY
* @param color
*/
public static void addArrow(int startX, int startY, int endX, int endY, Color color, Type type) {
JPanel p = getArrowsPanel();
Arrow arrow = new Arrow();
arrow.setColor(color);
arrow.setArrowLocation(startX, startY, endX, endY);
arrow.setBounds(0, 0, Math.max(startX, endX) + 40, Math.max(startY, endY) + 30); // 30 is offset for arrow heads (being cut otherwise)
synchronized (map) {
p.add(arrow);
p.add(arrow);
java.util.List<Arrow> arrows = map.get(type);
if (arrows == null) {
arrows = new ArrayList<Arrow>();
@ -76,15 +76,15 @@ public class ArrowBuilder {
}
arrows.add(arrow);
}
p.revalidate();
p.repaint();
}
/**
* Removes all arrows from the screen.
*/
public static void removeAllArrows() {
JPanel p = getArrowsPanel();
p.revalidate();
p.repaint();
}
/**
* Removes all arrows from the screen.
*/
public static void removeAllArrows() {
JPanel p = getArrowsPanel();
synchronized (map) {
if (p.getComponentCount() > 0) {
p.removeAll();
@ -93,7 +93,7 @@ public class ArrowBuilder {
}
map.clear();
}
}
}
public static void removeArrowsByType(Type type) {
java.util.List<Arrow> arrows = map.get(type);

View file

@ -25,9 +25,9 @@ public class BufferedImageBuilder {
}
public static BufferedImage bufferImage(Image image, int type) {
if (image == null) {
return null;
}
if (image == null) {
return null;
}
BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
Graphics2D g = bufferedImage.createGraphics();
g.drawImage(image, null, null);
@ -35,15 +35,15 @@ public class BufferedImageBuilder {
return bufferedImage;
}
public static BufferedImage bufferImage(Image image, int type, Color color) {
if (image == null) {
return null;
}
public static BufferedImage bufferImage(Image image, int type, Color color) {
if (image == null) {
return null;
}
BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
Graphics2D g = bufferedImage.createGraphics();
g.drawImage(image, null, null);
g.setColor(color);
g.fillRect(0, 0, image.getWidth(null), image.getHeight(null));
g.setColor(color);
g.fillRect(0, 0, image.getWidth(null), image.getHeight(null));
return bufferedImage;
}

View file

@ -20,34 +20,34 @@ import mage.client.plugins.impl.Plugins;
public class ColorsChooser extends JComboBox implements ListCellRenderer {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
public ColorsChooser(final String colors) {
public ColorsChooser(final String colors) {
this.setRenderer(this);
this.setRenderer(this);
final DefaultComboBoxModel model = new DefaultComboBoxModel();
final DefaultComboBoxModel model = new DefaultComboBoxModel();
model.addElement("u");
model.addElement("r");
model.addElement("b");
model.addElement("g");
model.addElement("w");
model.addElement("u");
model.addElement("r");
model.addElement("b");
model.addElement("g");
model.addElement("w");
model.addElement("x");
model.addElement("bu");
model.addElement("bg");
model.addElement("br");
model.addElement("bw");
model.addElement("ug");
model.addElement("ur");
model.addElement("uw");
model.addElement("gr");
model.addElement("gw");
model.addElement("rw");
model.addElement("bu");
model.addElement("bg");
model.addElement("br");
model.addElement("bw");
model.addElement("ug");
model.addElement("ur");
model.addElement("uw");
model.addElement("gr");
model.addElement("gw");
model.addElement("rw");
model.addElement("xx");
model.addElement("bur");
model.addElement("bur");
model.addElement("buw");
model.addElement("bug");
model.addElement("brg");
@ -59,49 +59,49 @@ public class ColorsChooser extends JComboBox implements ListCellRenderer {
model.addElement("rgu");
model.addElement("xxx");
setModel(model);
setSelectedItem(colors);
this.setFocusable(false);
}
setModel(model);
setSelectedItem(colors);
this.setFocusable(false);
}
@Override
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected,
final boolean cellHasFocus) {
@Override
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected,
final boolean cellHasFocus) {
final JPanel panel = new JPanel(new FlowLayout());
drawOn(panel, (String) value);
panel.setBorder(Constants.EMPTY_BORDER);
if (isSelected) {
panel.setBackground(Color.LIGHT_GRAY);
}
return panel;
}
private void drawOn(JPanel panel, String value) {
List<Image> images = new ArrayList<Image>();
value = value.toUpperCase();
for (int i = 0; i < value.length(); i++) {
char symbol = value.charAt(i);
Image image = Plugins.getInstance().getManaSymbolImage(String.valueOf(symbol));
if (image != null) {
images.add(image);
}
}
if (images.size() == value.length()) {
int dx = 0;
for (Image image : images) {
ImageIcon icon = new ImageIcon(image);
JLabel imageLabel = new JLabel();
imageLabel.setSize(11, 11);
imageLabel.setLocation(dx, 0);
imageLabel.setIcon(icon);
panel.add(imageLabel);
dx += 13;
}
} else {
String s = value.replace("B", "{B}").replace("R", "{R}").replace("G", "{G}").replace("W", "{W}").replace("U", "{U}").replace("X", "{X}");
panel.add(new JLabel(s));
}
}
final JPanel panel = new JPanel(new FlowLayout());
drawOn(panel, (String) value);
panel.setBorder(Constants.EMPTY_BORDER);
if (isSelected) {
panel.setBackground(Color.LIGHT_GRAY);
}
return panel;
}
private void drawOn(JPanel panel, String value) {
List<Image> images = new ArrayList<Image>();
value = value.toUpperCase();
for (int i = 0; i < value.length(); i++) {
char symbol = value.charAt(i);
Image image = Plugins.getInstance().getManaSymbolImage(String.valueOf(symbol));
if (image != null) {
images.add(image);
}
}
if (images.size() == value.length()) {
int dx = 0;
for (Image image : images) {
ImageIcon icon = new ImageIcon(image);
JLabel imageLabel = new JLabel();
imageLabel.setSize(11, 11);
imageLabel.setLocation(dx, 0);
imageLabel.setIcon(icon);
panel.add(imageLabel);
dx += 13;
}
} else {
String s = value.replace("B", "{B}").replace("R", "{R}").replace("G", "{G}").replace("W", "{W}").replace("U", "{U}").replace("X", "{X}");
panel.add(new JLabel(s));
}
}
}

View file

@ -13,79 +13,79 @@ import mage.view.CardView;
import org.jdesktop.swingx.JXPanel;
public class GuiDisplayUtil {
private static final Font cardNameFont = new Font("Calibri", Font.BOLD, 15);
private static final Font cardNameFont = new Font("Calibri", Font.BOLD, 15);
private static Insets DEFAULT_INSETS = new Insets(0, 0, 70, 25);
private static Insets COMPONENT_INSETS = new Insets(0, 0, 40, 40);
public static JXPanel getDescription(CardView card, int width, int height) {
JXPanel descriptionPanel = new JXPanel();
//descriptionPanel.setAlpha(.8f);
descriptionPanel.setBounds(0, 0, width, height);
descriptionPanel.setVisible(false);
descriptionPanel.setLayout(null);
//descriptionPanel.setBorder(BorderFactory.createLineBorder(Color.green));
JButton j = new JButton("");
j.setBounds(0, 0, width, height);
j.setBackground(Color.black);
j.setLayout(null);
JLabel name = new JLabel("Wrath of God");
name.setBounds(5, 5, width - 90, 20);
name.setForeground(Color.white);
name.setFont(cardNameFont);
//name.setBorder(BorderFactory.createLineBorder(Color.green));
j.add(name);
JLabel cost = new JLabel("B R G W U");
cost.setBounds(width - 85, 5, 77, 20);
cost.setForeground(Color.white);
cost.setFont(cardNameFont);
//cost.setBorder(BorderFactory.createLineBorder(Color.green));
cost.setHorizontalAlignment(SwingConstants.RIGHT);
j.add(cost);
JLabel type = new JLabel("Creature - Goblin Shaman");
type.setBounds(5, 70, width - 8, 20);
type.setForeground(Color.white);
type.setFont(cardNameFont);
//type.setBorder(BorderFactory.createLineBorder(Color.green));
j.add(type);
JLabel cardText = new JLabel();
cardText.setBounds(5, 100, width - 8, 260);
cardText.setForeground(Color.white);
cardText.setFont(cardNameFont);
cardText.setVerticalAlignment(SwingConstants.TOP);
//cardText.setBorder(new EtchedBorder());
j.add(cardText);
name.setText(card.getName());
cost.setText(card.getManaCost().toString());
String typeText = "";
String delimiter = card.getCardTypes().size() > 1 ? " - " : "";
for (CardType t : card.getCardTypes()) {
typeText += t;
typeText += delimiter;
delimiter = " "; // next delimiters are just spaces
}
type.setText(typeText);
cardText.setText("<html>"+card.getRules()+"</html>");
if (CardUtil.isCreature(card)) {
JLabel pt = new JLabel(card.getPower() + "/" + card.getToughness());
pt.setBounds(width - 50, height - 30, 40, 20);
pt.setForeground(Color.white);
pt.setFont(cardNameFont);
pt.setHorizontalAlignment(JLabel.RIGHT);
j.add(pt);
}
descriptionPanel.add(j);
return descriptionPanel;
public static JXPanel getDescription(CardView card, int width, int height) {
JXPanel descriptionPanel = new JXPanel();
//descriptionPanel.setAlpha(.8f);
descriptionPanel.setBounds(0, 0, width, height);
descriptionPanel.setVisible(false);
descriptionPanel.setLayout(null);
//descriptionPanel.setBorder(BorderFactory.createLineBorder(Color.green));
JButton j = new JButton("");
j.setBounds(0, 0, width, height);
j.setBackground(Color.black);
j.setLayout(null);
JLabel name = new JLabel("Wrath of God");
name.setBounds(5, 5, width - 90, 20);
name.setForeground(Color.white);
name.setFont(cardNameFont);
//name.setBorder(BorderFactory.createLineBorder(Color.green));
j.add(name);
JLabel cost = new JLabel("B R G W U");
cost.setBounds(width - 85, 5, 77, 20);
cost.setForeground(Color.white);
cost.setFont(cardNameFont);
//cost.setBorder(BorderFactory.createLineBorder(Color.green));
cost.setHorizontalAlignment(SwingConstants.RIGHT);
j.add(cost);
JLabel type = new JLabel("Creature - Goblin Shaman");
type.setBounds(5, 70, width - 8, 20);
type.setForeground(Color.white);
type.setFont(cardNameFont);
//type.setBorder(BorderFactory.createLineBorder(Color.green));
j.add(type);
JLabel cardText = new JLabel();
cardText.setBounds(5, 100, width - 8, 260);
cardText.setForeground(Color.white);
cardText.setFont(cardNameFont);
cardText.setVerticalAlignment(SwingConstants.TOP);
//cardText.setBorder(new EtchedBorder());
j.add(cardText);
name.setText(card.getName());
cost.setText(card.getManaCost().toString());
String typeText = "";
String delimiter = card.getCardTypes().size() > 1 ? " - " : "";
for (CardType t : card.getCardTypes()) {
typeText += t;
typeText += delimiter;
delimiter = " "; // next delimiters are just spaces
}
type.setText(typeText);
cardText.setText("<html>"+card.getRules()+"</html>");
if (CardUtil.isCreature(card)) {
JLabel pt = new JLabel(card.getPower() + "/" + card.getToughness());
pt.setBounds(width - 50, height - 30, 40, 20);
pt.setForeground(Color.white);
pt.setFont(cardNameFont);
pt.setHorizontalAlignment(JLabel.RIGHT);
j.add(pt);
}
descriptionPanel.add(j);
return descriptionPanel;
}
public static String cleanString(String in) {
@ -103,29 +103,29 @@ public class GuiDisplayUtil {
}
public static void keepComponentInsideScreen(int x, int y, Component c) {
Dimension screenDim = c.getToolkit().getScreenSize();
GraphicsConfiguration g = c.getGraphicsConfiguration();
if (g != null) {
Insets insets = c.getToolkit().getScreenInsets(g);
if (x + c.getWidth() > screenDim.width - insets.right) {
x = (screenDim.width - insets.right) - c.getWidth();
} else if (x < insets.left) {
x = insets.left;
}
if (y + c.getHeight() > screenDim.height - insets.bottom) {
y = (screenDim.height - insets.bottom) - c.getHeight();
} else if (y < insets.top) {
y = insets.top;
}
c.setLocation(x, y);
} else {
System.out.println("null");
}
}
public static void keepComponentInsideScreen(int x, int y, Component c) {
Dimension screenDim = c.getToolkit().getScreenSize();
GraphicsConfiguration g = c.getGraphicsConfiguration();
if (g != null) {
Insets insets = c.getToolkit().getScreenInsets(g);
if (x + c.getWidth() > screenDim.width - insets.right) {
x = (screenDim.width - insets.right) - c.getWidth();
} else if (x < insets.left) {
x = insets.left;
}
if (y + c.getHeight() > screenDim.height - insets.bottom) {
y = (screenDim.height - insets.bottom) - c.getHeight();
} else if (y < insets.top) {
y = insets.top;
}
c.setLocation(x, y);
} else {
System.out.println("null");
}
}
public static Point keepComponentInsideParent(Point l, Point parentPoint, Component c, Component parent) {
int dx = parentPoint.x + parent.getWidth() - DEFAULT_INSETS.right - COMPONENT_INSETS.right;
@ -139,5 +139,5 @@ public class GuiDisplayUtil {
}
return l;
}
}
}

View file

@ -19,7 +19,7 @@ public class SaveObjectUtil {
* Defines should data be saved or not.
* Read from system property:
*/
private static boolean saveIncomeData = false;
private static boolean saveIncomeData = false;
/**
* Defines the system property name to get {@link #saveIncomeData} value from.
@ -30,10 +30,10 @@ public class SaveObjectUtil {
* Date pattern used to form filename to save object to.
*/
private static final String DATE_PATTERN = "[yyyy_MM_dd][H-mm-ss]";
static {
saveIncomeData = System.getProperty(SAVE_DATA_PROPERTY) != null;
}
static {
saveIncomeData = System.getProperty(SAVE_DATA_PROPERTY) != null;
}
/**
* Save object on disk.
@ -41,35 +41,35 @@ public class SaveObjectUtil {
* @param object Object to save.
* @param name Part of name that will be used to form original filename to save object to.
*/
public static void saveObject(Object object, String name) {
if (saveIncomeData) {
ObjectOutputStream oos = null;
try {
File dir = new File("income");
if (!dir.exists() || dir.exists() && dir.isFile()) {
boolean bCreated = dir.mkdir();
if (!bCreated) {
return;
}
}
String time = now(DATE_PATTERN);
File f = new File("income" + File.separator + name + "_" + time + ".save");
if (!f.exists()) {
f.createNewFile();
}
oos = new ObjectOutputStream(new FileOutputStream(f));
oos.writeObject(object);
oos.close();
public static void saveObject(Object object, String name) {
if (saveIncomeData) {
ObjectOutputStream oos = null;
try {
File dir = new File("income");
if (!dir.exists() || dir.exists() && dir.isFile()) {
boolean bCreated = dir.mkdir();
if (!bCreated) {
return;
}
}
String time = now(DATE_PATTERN);
File f = new File("income" + File.separator + name + "_" + time + ".save");
if (!f.exists()) {
f.createNewFile();
}
oos = new ObjectOutputStream(new FileOutputStream(f));
oos.writeObject(object);
oos.close();
} catch (FileNotFoundException e) {
return;
} catch (IOException io) {
return;
}
}
}
public static String now(String dateFormat) {
} catch (FileNotFoundException e) {
return;
} catch (IOException io) {
return;
}
}
}
public static String now(String dateFormat) {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
return sdf.format(cal.getTime());