1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.magicproject.ui.wizard;
20
21 import java.awt.FlowLayout;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.MouseEvent;
24 import java.awt.event.MouseListener;
25 import java.util.List;
26
27 import javax.swing.JOptionPane;
28 import javax.swing.JPanel;
29 import javax.swing.JScrollPane;
30 import javax.swing.ScrollPaneConstants;
31 import javax.swing.WindowConstants;
32
33 import net.sf.magicproject.clickable.targetable.card.AbstractCard;
34 import net.sf.magicproject.clickable.targetable.card.TriggeredCard;
35 import net.sf.magicproject.ui.MagicUIComponents;
36 import net.sf.magicproject.ui.i18n.LanguageManager;
37
38 /***
39 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
40 * @since 0.82
41 */
42 public class Replacement extends Ok implements MouseListener {
43
44 /***
45 * Creates a new instance of Replacement <br>
46 *
47 * @param eventName
48 * @param triggeredCards
49 */
50 public Replacement(String eventName,
51 List<? extends AbstractCard> triggeredCards) {
52 super(LanguageManager.getString("wiz_replacement.title"), LanguageManager
53 .getString("wiz_replacement.description", eventName),
54 "wiz_replacement.gif", null, 600, 400);
55 setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
56 JScrollPane scroll = new JScrollPane(
57 ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
58 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
59 container = new JPanel(new FlowLayout(FlowLayout.LEFT));
60 for (int i = 0; i < triggeredCards.size(); i++) {
61 container.add(triggeredCards.get(i));
62 triggeredCards.get(i).addMouseListener(this);
63 }
64 isRunning = true;
65 replacement = -1;
66 scroll.setAutoscrolls(true);
67 scroll.setViewportView(container);
68 gameParamPanel.add(scroll);
69 }
70
71 /***
72 * triggers the ok button
73 *
74 * @param event
75 */
76 @Override
77 public void actionPerformed(ActionEvent event) {
78 if (event.getSource() == cancelBtn) {
79 if (replacement != -1) {
80 isRunning = false;
81 validAnswer(JOptionPane.OK_OPTION);
82 }
83 } else {
84 super.actionPerformed(event);
85 }
86 }
87
88 public void mouseClicked(MouseEvent e) {
89 TriggeredCard triggered = (TriggeredCard) e.getSource();
90 MagicUIComponents.logListing.append(triggered.triggeredAbility.getCard()
91 .getController().idPlayer, "Choosen replacement : " + triggered);
92 isRunning = false;
93 for (int i = container.getComponentCount(); i-- > 0;) {
94 if (container.getComponent(i) == triggered) {
95 replacement = i;
96 break;
97 }
98 }
99 setVisible(false);
100 dispose();
101 }
102
103 public void mousePressed(MouseEvent e) {
104
105 }
106
107 public void mouseReleased(MouseEvent e) {
108
109 }
110
111 public void mouseEntered(MouseEvent e) {
112
113 }
114
115 public void mouseExited(MouseEvent e) {
116
117 }
118
119 /***
120 * The choosen replacement ability index.
121 */
122 public static int replacement;
123
124 /***
125 * Indicates we are waiting for a player choice for a replacement ability.
126 */
127 public static boolean isRunning;
128
129 /***
130 * This is the panel containing the possible replacement abilities
131 */
132 private JPanel container;
133 }