[minor] code style

This commit is contained in:
North 2013-03-03 10:41:31 +02:00
parent 122e9c700d
commit 2daae9fb47
2 changed files with 79 additions and 141 deletions

View file

@ -25,14 +25,8 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
/*
* GamePanel.java
*
* Created on Dec 16, 2009, 9:29:58 AM
*/
package mage.client.game;
import mage.Constants;
import mage.cards.action.ActionCallback;
import mage.client.MageFrame;
@ -68,15 +62,13 @@ import java.util.*;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
/**
*
* @author BetaSteward_at_googlemail.com, nantuko8
*/
public class GamePanel extends javax.swing.JPanel {
public final class GamePanel extends javax.swing.JPanel {
private final static Logger logger = Logger.getLogger(GamePanel.class);
private static final Logger logger = Logger.getLogger(GamePanel.class);
private static final String YOUR_HAND = "Your hand";
private static final int X_PHASE_WIDTH = 55;
private Map<UUID, PlayAreaPanel> players = new HashMap<UUID, PlayAreaPanel>();
@ -94,12 +86,10 @@ public class GamePanel extends javax.swing.JPanel {
private boolean smallMode = false;
private boolean initialized = false;
private HelperPanel helper;
private int storedHeight;
private Map<String, HoverButton> hoverButtons;
/** Creates new form GamePanel */
public GamePanel() {
initComponents();
@ -111,51 +101,42 @@ public class GamePanel extends javax.swing.JPanel {
this.feedbackPanel.setConnectedChatPanel(this.userChatPanel);
//FIXME: remove from here
try {
// Override layout (I can't edit generated code)
this.setLayout(new BorderLayout());
final JLayeredPane j = new JLayeredPane();
j.setSize(1024,768);
this.add(j);
j.add(jSplitPane0, JLayeredPane.DEFAULT_LAYER);
Map<String, JComponent> myUi = getUIComponents(j);
Plugins.getInstance().updateGamePanel(myUi);
// Override layout (I can't edit generated code)
this.setLayout(new BorderLayout());
final JLayeredPane j = new JLayeredPane();
j.setSize(1024, 768);
this.add(j);
j.add(jSplitPane0, JLayeredPane.DEFAULT_LAYER);
// Enlarge jlayeredpane on resize
addComponentListener(new ComponentAdapter(){
@Override
public void componentResized(ComponentEvent e) {
int width = ((JComponent)e.getSource()).getWidth();
int height = ((JComponent)e.getSource()).getHeight();
j.setSize(width, height);
jSplitPane0.setSize(width, height);
if (height < storedHeight) {
pnlBattlefield.setSize(0, 200);
}
storedHeight = height;
Map<String, JComponent> myUi = getUIComponents(j);
Plugins.getInstance().updateGamePanel(myUi);
sizeToScreen();
// Enlarge jlayeredpane on resize
addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
int width = ((JComponent) e.getSource()).getWidth();
int height = ((JComponent) e.getSource()).getHeight();
j.setSize(width, height);
jSplitPane0.setSize(width, height);
if (!initialized) {
String state = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BIG_CARD_TOGGLED, null);
if (state != null) {
if (state.equals("down")) {
jSplitPane0.setDividerLocation(1.0);
}
}
initialized = true;
}
if (height < storedHeight) {
pnlBattlefield.setSize(0, 200);
}
});
storedHeight = height;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
sizeToScreen();
if (!initialized) {
String state = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BIG_CARD_TOGGLED, null);
if (state != null && state.equals("down")) {
jSplitPane0.setDividerLocation(1.0);
}
initialized = true;
}
}
});
}
private Map<String, JComponent> getUIComponents(JLayeredPane jLayeredPane) {
@ -263,9 +244,6 @@ public class GamePanel extends javax.swing.JPanel {
}
}
//int height = pnlBattlefield.getHeight();
//phasesContainer.setPreferredSize(new Dimension(X_PHASE_WIDTH, X_PHASE_HEIGHT));
ArrowBuilder.getBuilder().setSize(rect.width, rect.height);
DialogManager.getManager(gameId).setScreenWidth(rect.width);
@ -464,9 +442,6 @@ public class GamePanel extends javax.swing.JPanel {
this.txtPhase.setText("");
}
updatePhases(game.getStep());
if (game.getPhase() != null && game.getPhase().toString().equals("End") && game.getStep().toString().equals("End Turn")) {
//AudioManager.playEndTurn();
}
if (game.getStep() != null) {
this.txtStep.setText(game.getStep().toString());
@ -505,10 +480,8 @@ public class GamePanel extends javax.swing.JPanel {
showRevealed(game);
showLookedAt(game);
if (game.getCombat().size() > 0) {
//combat.showDialog(game.getCombat());
CombatManager.getInstance().showCombat(game.getCombat(), gameId);
} else {
//combat.hideDialog();
CombatManager.getInstance().hideCombat(gameId);
}
this.revalidate();
@ -517,28 +490,6 @@ public class GamePanel extends javax.swing.JPanel {
private void displayStack(GameView game, BigCard bigCard, FeedbackPanel feedbackPanel, UUID gameId) {
this.stack.loadCards(game.getStack(), bigCard, gameId, null);
/*if (game.getStack().size() > 0) {
if (game.getStack().size() != cachedStackSize) {
boolean allPaid = true;
for (CardView cardView : game.getStack().values()) {
if (!cardView.isPaid()) {
allPaid = false;
break;
}
}
if (allPaid) {
DialogManager.getManager().fadeOut();
cachedStackSize = game.getStack().size();
DialogManager.getManager().showStackDialog(game.getStack(), bigCard, feedbackPanel, gameId);
}
} else {
// do nothing
}
} else {
cachedStackSize = game.getStack().size();
DialogManager.getManager().fadeOut();
}*/
}
/**
@ -930,7 +881,7 @@ public class GamePanel extends javax.swing.JPanel {
stack.setPreferredSize(new java.awt.Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight + 25));
stack.setBackgroundColor(new Color(0,0,0,0));
btnStopReplay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_stop.png"))); // NOI18N
btnStopReplay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_stop.png")));
btnStopReplay.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
@ -938,7 +889,7 @@ public class GamePanel extends javax.swing.JPanel {
}
});
btnNextPlay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_stop_right.png"))); // NOI18N
btnNextPlay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_stop_right.png")));
btnNextPlay.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
@ -946,7 +897,7 @@ public class GamePanel extends javax.swing.JPanel {
}
});
btnPlay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_right.png"))); // NOI18N
btnPlay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_right.png")));
btnPlay.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
@ -954,7 +905,7 @@ public class GamePanel extends javax.swing.JPanel {
}
});
btnSkipForward.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_double_stop_right.png"))); // NOI18N
btnSkipForward.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_double_stop_right.png")));
btnSkipForward.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
@ -962,7 +913,7 @@ public class GamePanel extends javax.swing.JPanel {
}
});
btnPreviousPlay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_stop_left.png"))); // NOI18N
btnPreviousPlay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_stop_left.png")));
btnPreviousPlay.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
@ -1057,7 +1008,7 @@ public class GamePanel extends javax.swing.JPanel {
}
pnlReplay.setOpaque(false);
helper = new HelperPanel();
HelperPanel helper = new HelperPanel();
helper.setPreferredSize(new Dimension(100, 90));
feedbackPanel.setHelperPanel(helper);
@ -1118,12 +1069,9 @@ public class GamePanel extends javax.swing.JPanel {
.addComponent(handContainer, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
)
)
//.addComponent(jPhases, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
)
//.addComponent(pnlGameInfo, GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
);
jPanel3.setLayout(gl_jPanel3);
//helper.setBorder(BorderFactory.createLineBorder(Color.ORANGE));
jSplitPane1.setLeftComponent(jPanel3);
jSplitPane1.setRightComponent(jSplitPane2);

View file

@ -41,7 +41,7 @@ public class MageActionCallback implements ActionCallback {
private Popup popup;
private JPopupMenu jPopupMenu;
private BigCard bigCard;
protected static DefaultActionCallback defaultCallback = DefaultActionCallback.getInstance();
protected static final DefaultActionCallback defaultCallback = DefaultActionCallback.getInstance();
protected static Session session = MageFrame.getSession();
private CardView popupCard;
private TransferData popupData;
@ -59,7 +59,7 @@ public class MageActionCallback implements ActionCallback {
this.bigCard = bigCard;
}
public void refreshSession() {
public synchronized void refreshSession() {
if (session == null) {
session = MageFrame.getSession();
}
@ -150,47 +150,42 @@ public class MageActionCallback implements ActionCallback {
private void drawArrowsForTargets(TransferData data, Point parentPoint) {
List<UUID> targets = data.card.getTargets();
if (targets != null) {
Point me = new Point(data.locationOnScreen);
me.translate(-parentPoint.x, -parentPoint.y);
for (UUID uuid : targets) {
if (targets == null) {
return;
}
boolean found = false;
PlayAreaPanel p = MageFrame.getGame(data.gameId).getPlayers().get(uuid);
if (p != null) {
found = true;
Point target = p.getLocationOnScreen();
Point me = new Point(data.locationOnScreen);
me.translate(-parentPoint.x, -parentPoint.y);
for (UUID uuid : targets) {
PlayAreaPanel p = MageFrame.getGame(data.gameId).getPlayers().get(uuid);
if (p != null) {
Point target = p.getLocationOnScreen();
target.translate(-parentPoint.x, -parentPoint.y);
ArrowBuilder.getBuilder().addArrow(data.gameId, (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 40, (int) target.getY() - 40, Color.red, ArrowBuilder.Type.TARGET);
continue;
}
for (PlayAreaPanel panel : MageFrame.getGame(data.gameId).getPlayers().values()) {
MagePermanent permanent = panel.getBattlefieldPanel().getPermanents().get(uuid);
if (permanent != null) {
Point target = permanent.getLocationOnScreen();
target.translate(-parentPoint.x, -parentPoint.y);
ArrowBuilder.getBuilder().addArrow(data.gameId,(int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 40, (int) target.getY() - 40, Color.red, ArrowBuilder.Type.TARGET);
} else {
for (PlayAreaPanel pa : MageFrame.getGame(data.gameId).getPlayers().values()) {
MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid);
if (permanent != null) {
found = true;
Point target = permanent.getLocationOnScreen();
target.translate(-parentPoint.x, -parentPoint.y);
ArrowBuilder.getBuilder().addArrow(data.gameId, (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 40, (int) target.getY() + 10, Color.red, ArrowBuilder.Type.TARGET);
}
}
ArrowBuilder.getBuilder().addArrow(data.gameId, (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 40, (int) target.getY() + 10, Color.red, ArrowBuilder.Type.TARGET);
continue;
}
if (!found) {
for (PlayAreaPanel panel : MageFrame.getGame(data.gameId).getPlayers().values()) {
PlayerView view = panel.getPlayerPanel().getPlayer();
if (view != null) {
SimpleCardsView graveyard = view.getGraveyard();
if (graveyard.containsKey(uuid)) {
found = true;
p = MageFrame.getGame(data.gameId).getPlayers().get(view.getPlayerId());
if (p != null) {
Point target = p.getLocationOnScreen();
target.translate(-parentPoint.x, -parentPoint.y);
int y_offset = p.isSmallMode() ? (PlayAreaPanel.PANEL_HEIGHT - PlayAreaPanel.PANEL_HEIGHT_SMALL) : 0;
ArrowBuilder.getBuilder().addArrow(data.gameId,(int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 15, (int) target.getY() + 145 - y_offset, Color.red, ArrowBuilder.Type.TARGET);
}
continue;
}
PlayerView view = panel.getPlayerPanel().getPlayer();
if (view != null) {
SimpleCardsView graveyard = view.getGraveyard();
if (graveyard.containsKey(uuid)) {
p = MageFrame.getGame(data.gameId).getPlayers().get(view.getPlayerId());
if (p != null) {
Point target = p.getLocationOnScreen();
target.translate(-parentPoint.x, -parentPoint.y);
int yOffset = p.isSmallMode() ? (PlayAreaPanel.PANEL_HEIGHT - PlayAreaPanel.PANEL_HEIGHT_SMALL) : 0;
ArrowBuilder.getBuilder().addArrow(data.gameId, (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 15, (int) target.getY() + 145 - yOffset, Color.red, ArrowBuilder.Type.TARGET);
continue;
}
}
}
@ -204,7 +199,7 @@ public class MageActionCallback implements ActionCallback {
return;
}
if (data.component instanceof MageCard) {
if (data.component != null) {
String showTooltips = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_TOOLTIPS_ANY_ZONE, "true");
if (showTooltips.equals("false")) {
return;
@ -230,15 +225,11 @@ public class MageActionCallback implements ActionCallback {
public void run() {
ThreadUtils.sleep(300);
if (popupCard == null || !popupCard.equals(data.card)) {
if (popupCard == null || !popupCard.equals(data.card) || session == null || !state || enlarged) {
return;
}
try {
if (session == null || !state || enlarged) {
return;
}
final Component popupContainer = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER);
Component popup2 = MageFrame.getUI().getComponent(MageComponents.CARD_INFO_PANE);
@ -297,11 +288,10 @@ public class MageActionCallback implements ActionCallback {
state = true;
}
displayCard(card.getOriginal(), data);
} else {
//hideCard();
}
}
@Override
public void hidePopup() {
this.popupCard = null;
if (popup != null) {
@ -371,6 +361,7 @@ public class MageActionCallback implements ActionCallback {
}
}
@Override
public void mouseWheelMoved(MouseWheelEvent e, TransferData data) {
int notches = e.getWheelRotation();
if (notches < 0) {
@ -456,4 +447,3 @@ public class MageActionCallback implements ActionCallback {
}
}
}