[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 * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
/*
* GamePanel.java
*
* Created on Dec 16, 2009, 9:29:58 AM
*/
package mage.client.game; package mage.client.game;
import mage.Constants; import mage.Constants;
import mage.cards.action.ActionCallback; import mage.cards.action.ActionCallback;
import mage.client.MageFrame; import mage.client.MageFrame;
@ -68,15 +62,13 @@ import java.util.*;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
/** /**
* *
* @author BetaSteward_at_googlemail.com, nantuko8 * @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 String YOUR_HAND = "Your hand";
private static final int X_PHASE_WIDTH = 55; private static final int X_PHASE_WIDTH = 55;
private Map<UUID, PlayAreaPanel> players = new HashMap<UUID, PlayAreaPanel>(); 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 smallMode = false;
private boolean initialized = false; private boolean initialized = false;
private HelperPanel helper;
private int storedHeight; private int storedHeight;
private Map<String, HoverButton> hoverButtons; private Map<String, HoverButton> hoverButtons;
/** Creates new form GamePanel */
public GamePanel() { public GamePanel() {
initComponents(); initComponents();
@ -111,51 +101,42 @@ public class GamePanel extends javax.swing.JPanel {
this.feedbackPanel.setConnectedChatPanel(this.userChatPanel); this.feedbackPanel.setConnectedChatPanel(this.userChatPanel);
//FIXME: remove from here // Override layout (I can't edit generated code)
try { this.setLayout(new BorderLayout());
// Override layout (I can't edit generated code) final JLayeredPane j = new JLayeredPane();
this.setLayout(new BorderLayout()); j.setSize(1024, 768);
final JLayeredPane j = new JLayeredPane(); this.add(j);
j.setSize(1024,768); j.add(jSplitPane0, JLayeredPane.DEFAULT_LAYER);
this.add(j);
j.add(jSplitPane0, JLayeredPane.DEFAULT_LAYER);
Map<String, JComponent> myUi = getUIComponents(j);
Plugins.getInstance().updateGamePanel(myUi);
// Enlarge jlayeredpane on resize Map<String, JComponent> myUi = getUIComponents(j);
addComponentListener(new ComponentAdapter(){ Plugins.getInstance().updateGamePanel(myUi);
@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;
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) { if (height < storedHeight) {
String state = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BIG_CARD_TOGGLED, null); pnlBattlefield.setSize(0, 200);
if (state != null) {
if (state.equals("down")) {
jSplitPane0.setDividerLocation(1.0);
}
}
initialized = true;
}
} }
}); storedHeight = height;
} catch (Exception e) { sizeToScreen();
e.printStackTrace();
throw new RuntimeException(e); 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) { 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); ArrowBuilder.getBuilder().setSize(rect.width, rect.height);
DialogManager.getManager(gameId).setScreenWidth(rect.width); DialogManager.getManager(gameId).setScreenWidth(rect.width);
@ -464,9 +442,6 @@ public class GamePanel extends javax.swing.JPanel {
this.txtPhase.setText(""); this.txtPhase.setText("");
} }
updatePhases(game.getStep()); updatePhases(game.getStep());
if (game.getPhase() != null && game.getPhase().toString().equals("End") && game.getStep().toString().equals("End Turn")) {
//AudioManager.playEndTurn();
}
if (game.getStep() != null) { if (game.getStep() != null) {
this.txtStep.setText(game.getStep().toString()); this.txtStep.setText(game.getStep().toString());
@ -505,10 +480,8 @@ public class GamePanel extends javax.swing.JPanel {
showRevealed(game); showRevealed(game);
showLookedAt(game); showLookedAt(game);
if (game.getCombat().size() > 0) { if (game.getCombat().size() > 0) {
//combat.showDialog(game.getCombat());
CombatManager.getInstance().showCombat(game.getCombat(), gameId); CombatManager.getInstance().showCombat(game.getCombat(), gameId);
} else { } else {
//combat.hideDialog();
CombatManager.getInstance().hideCombat(gameId); CombatManager.getInstance().hideCombat(gameId);
} }
this.revalidate(); this.revalidate();
@ -517,28 +490,6 @@ public class GamePanel extends javax.swing.JPanel {
private void displayStack(GameView game, BigCard bigCard, FeedbackPanel feedbackPanel, UUID gameId) { private void displayStack(GameView game, BigCard bigCard, FeedbackPanel feedbackPanel, UUID gameId) {
this.stack.loadCards(game.getStack(), bigCard, gameId, null); 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.setPreferredSize(new java.awt.Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight + 25));
stack.setBackgroundColor(new Color(0,0,0,0)); 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() { btnStopReplay.addActionListener(new java.awt.event.ActionListener() {
@Override @Override
public void actionPerformed(java.awt.event.ActionEvent evt) { 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() { btnNextPlay.addActionListener(new java.awt.event.ActionListener() {
@Override @Override
public void actionPerformed(java.awt.event.ActionEvent evt) { 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() { btnPlay.addActionListener(new java.awt.event.ActionListener() {
@Override @Override
public void actionPerformed(java.awt.event.ActionEvent evt) { 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() { btnSkipForward.addActionListener(new java.awt.event.ActionListener() {
@Override @Override
public void actionPerformed(java.awt.event.ActionEvent evt) { 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() { btnPreviousPlay.addActionListener(new java.awt.event.ActionListener() {
@Override @Override
public void actionPerformed(java.awt.event.ActionEvent evt) { public void actionPerformed(java.awt.event.ActionEvent evt) {
@ -1057,7 +1008,7 @@ public class GamePanel extends javax.swing.JPanel {
} }
pnlReplay.setOpaque(false); pnlReplay.setOpaque(false);
helper = new HelperPanel(); HelperPanel helper = new HelperPanel();
helper.setPreferredSize(new Dimension(100, 90)); helper.setPreferredSize(new Dimension(100, 90));
feedbackPanel.setHelperPanel(helper); 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(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); jPanel3.setLayout(gl_jPanel3);
//helper.setBorder(BorderFactory.createLineBorder(Color.ORANGE));
jSplitPane1.setLeftComponent(jPanel3); jSplitPane1.setLeftComponent(jPanel3);
jSplitPane1.setRightComponent(jSplitPane2); jSplitPane1.setRightComponent(jSplitPane2);

View file

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