Final touches added to "Constructed" submenu: resizing, directions, decklist on doubleclick, randomize buttons for themes and preconstructed, Forge-themed list selectors.

This commit is contained in:
Doublestrike
2011-12-19 06:33:35 +00:00
parent 63e35ba293
commit ac89c7222f
4 changed files with 293 additions and 294 deletions

View File

@@ -2,15 +2,17 @@ package forge.control.home;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Map.Entry;
import java.util.Random;
import javax.swing.JList;
import javax.swing.JOptionPane;
@@ -19,6 +21,7 @@ import javax.swing.event.ListSelectionListener;
import forge.AllZone;
import forge.CardList;
import forge.Command;
import forge.Constant;
import forge.PlayerType;
import forge.deck.Deck;
@@ -55,9 +58,7 @@ public class ControlConstructed {
this.view = v0;
// Reference values for colors, needed for deck generation classes.
// TODO enum me or get from another enum
colorVals = new HashMap<String, String>();
colorVals.put("Random", "AI");
colorVals.put("Random 1", "AI");
colorVals.put("Random 2", "AI");
colorVals.put("Random 3", "AI");
@@ -77,16 +78,28 @@ public class ControlConstructed {
/** */
public void addListeners() {
view.getLstColorsAI().getSelectionModel().addListSelectionListener(new AIColorsListener());
view.getLstColorsAI().setSelectedIndices(new int[] {0, 1});
view.getLstThemesAI().getSelectionModel().addListSelectionListener(new AIThemesListener());
view.getLstDecksAI().getSelectionModel().addListSelectionListener(new AIDecksListener());
view.getLstColorsHuman().getSelectionModel().addListSelectionListener(new HumanColorsListener());
view.getLstThemesHuman().getSelectionModel().addListSelectionListener(new HumanThemesListener());
view.getLstDecksHuman().getSelectionModel().addListSelectionListener(new HumanDecksListener());
MouseListener mouseListener = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
int index = view.getLstDecksHuman().locationToIndex(e.getPoint());
showDecklist(AllZone.getDeckManager().getDeck(deckNames.get(index)));
}
}
};
view.getLstDecksHuman().addMouseListener(mouseListener);
view.getLstDecksAI().addMouseListener(mouseListener);
view.getLstColorsHuman().setSelectedIndices(new int[] {0, 1});
view.getLstColorsAI().setSelectedIndices(new int[] {0, 1});
}
//========== LISTENERS
//========== LISTENERS
/** Listeners for human lists, which pass control directly to regulation logic. */
public class HumanColorsListener implements ListSelectionListener {
@@ -137,7 +150,6 @@ public class ControlConstructed {
"Sorry, single color generated decks aren't supported yet."
+ "\n\rPlease choose at least one more color for the human deck.",
"Human deck: 1 color", JOptionPane.ERROR_MESSAGE);
view.remind(currentHumanSelection);
result = false;
}
else if (human0.length == 4) {
@@ -145,14 +157,12 @@ public class ControlConstructed {
"Sorry, four color generated decks aren't supported yet."
+ "\n\rPlease use 2, 3, or 5 colors for the human deck.",
"Human deck: 4 colors", JOptionPane.ERROR_MESSAGE);
view.remind(currentHumanSelection);
result = false;
}
else if (human0.length > 5) {
JOptionPane.showMessageDialog(null,
"Human deck: maximum five colors!",
"Human deck: too many colors", JOptionPane.ERROR_MESSAGE);
view.remind(currentHumanSelection);
result = false;
}
@@ -174,7 +184,6 @@ public class ControlConstructed {
"Sorry, single color generated decks aren't supported yet."
+ "\n\rPlease choose at least one more color for the AI deck.",
"AI deck: 1 color", JOptionPane.ERROR_MESSAGE);
view.remind(currentAISelection);
result = false;
}
else if (ai0.length == 4) {
@@ -182,24 +191,41 @@ public class ControlConstructed {
"Sorry, four color generated decks aren't supported yet."
+ "\n\rPlease use 2, 3, or 5 colors for the AI deck.",
"AI deck: 4 colors", JOptionPane.ERROR_MESSAGE);
view.remind(currentAISelection);
result = false;
}
else if (ai0.length > 5) {
JOptionPane.showMessageDialog(null,
"AI deck: maximum five colors!",
"AI deck: Too many colors", JOptionPane.ERROR_MESSAGE);
view.remind(currentAISelection);
result = false;
}
return result;
}
/**
* Random chooser for theme decks.
*
* @param lst0 {@link javax.swing.JList}
*/
public void randomPick(JList lst0) {
Random r = new Random();
int i = 0;
if (lst0.getName().equals("lstThemesHuman") || lst0.getName().equals("lstThemesAI")) {
i = r.nextInt(themeNames.size());
}
else {
i = r.nextInt(deckNames.size());
}
lst0.setSelectedIndex(i);
lst0.ensureIndexIsVisible(lst0.getSelectedIndex());
}
/**
* Regulates that only one of the three deck type JLists is in use at a time.
*
* @param lst0 &emsp; a JList that has been clicked
* @param lst0 {@link javax.swing.JList} that has been clicked
*/
public void regulateHuman(JList lst0) {
if (currentHumanSelection != null && lst0 != currentHumanSelection) {
@@ -208,16 +234,6 @@ public class ControlConstructed {
currentHumanSelection = lst0;
// Random chooser for theme decks
if (lst0.getName() != null && lst0.getName().equals("lstThemesHuman")
&& lst0.getSelectedIndex() == 0) {
Random r = new Random();
int i = 0;
while (i == 0) { i = r.nextInt(themeNames.size()); }
lst0.setSelectedIndex(i);
}
// Random chooser for pre-constructed decks
if (lst0.getName() != null && lst0.getName().equals("lstDecksHuman")
&& lst0.getSelectedIndex() == 0) {
@@ -227,14 +243,6 @@ public class ControlConstructed {
while (i == 0) { i = r.nextInt(deckNames.size()); }
lst0.setSelectedIndex(i);
}
// Toggle "view" button accordingly
if (lst0.getName() != null && lst0.getName().equals("lstDecksHuman")) {
view.getBtnHumanDeckList().setEnabled(true);
}
else {
view.getBtnHumanDeckList().setEnabled(false);
}
}
/**
@@ -268,14 +276,6 @@ public class ControlConstructed {
while (i == 0) { i = r.nextInt(deckNames.size()); }
lst0.setSelectedIndex(i);
}
// Toggle "view" button accordingly
if (lst0.getName() != null && lst0.getName().equals("lstDecksAI")) {
view.getBtnAIDeckList().setEnabled(true);
}
else {
view.getBtnAIDeckList().setEnabled(false);
}
}
//========= DECK GENERATION
@@ -432,9 +432,9 @@ public class ControlConstructed {
* @return Object[]
*/
// Four randoms are included which should cover all possibilities.
public Object[] getColorNames() {
return new Object[] {"Random", "Random", "Random",
"Random", "Black", "Blue", "Green", "Red", "White"};
public String[] getColorNames() {
return new String[] {"Random 1", "Random 2", "Random 3",
"Random 4", "Black", "Blue", "Green", "Red", "White"};
}
/**
@@ -460,9 +460,7 @@ public class ControlConstructed {
deckNames.add(0, "Random");
Collection<Deck> allDecks = AllZone.getDeckManager().getConstructedDecks();
for (Deck d : allDecks) {
deckNames.add(d.getName());
}
for (Deck d : allDecks) { deckNames.add(d.getName()); }
// No pre-constructed decks?
if (deckNames.size() == 1) { deckNames = new ArrayList<String>(); }
@@ -472,91 +470,67 @@ public class ControlConstructed {
}
/**
* View deck list.
*
* @param player &emsp; String
*
*/
public void viewDeckList(final String player) {
new DeckListAction(player).actionPerformed(null);
}
private void showDecklist(Deck d0) {
HashMap<String, Integer> deckMap = new HashMap<String, Integer>();
for (Entry<CardPrinted, Integer> s : d0.getMain()) {
deckMap.put(s.getKey().getName(), s.getValue());
}
String nl = System.getProperty("line.separator");
StringBuilder deckList = new StringBuilder();
String dName = d0.getName();
deckList.append(dName == null ? "" : dName + nl + nl);
ArrayList<String> dmKeys = new ArrayList<String>();
for (final String s : deckMap.keySet()) {
dmKeys.add(s);
}
Collections.sort(dmKeys);
for (String s : dmKeys) {
deckList.append(deckMap.get(s) + " x " + s + nl);
}
final StringBuilder msg = new StringBuilder();
if (deckMap.keySet().size() <= 32) {
msg.append(deckList.toString() + nl);
} else {
msg.append("Decklist too long for dialog." + nl + nl);
}
msg.append("Copy Decklist to Clipboard?");
// Output
int rcMsg = JOptionPane.showConfirmDialog(null, msg, "Decklist", JOptionPane.OK_CANCEL_OPTION);
if (rcMsg == JOptionPane.OK_OPTION) {
final StringSelection ss = new StringSelection(deckList.toString());
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
}
} // End showDecklist
/**
* Receives click and programmatic requests for viewing card in a player's deck.
* What to do after exiting the deck editor in the deck lister.
*
* @return Command
*/
private class DeckListAction {
public DeckListAction(final String playerIn) {
player = playerIn;
}
public Command getEditorExitCommand() {
Command exit = new Command() {
private static final long serialVersionUID = -9133358399503226853L;
private String player;
@Override
public void execute() {
public void actionPerformed(final ActionEvent e) {
if (player.equals("Human")
&& (currentHumanSelection.getName().equals("lstColorsHuman")
|| currentHumanSelection.getName().equals("lstThemesHuman"))) {
return;
}
if (player.equals("Computer")
&& (currentAISelection.getName().equals("lstColorsAI")
|| currentAISelection.getName().equals("lstThemesAI"))) {
return;
}
};
Deck targetDeck = (player.equals("Human"))
? AllZone.getDeckManager().getDeck(oa2sa(currentHumanSelection.getSelectedValues())[0])
: AllZone.getDeckManager().getDeck(oa2sa(currentAISelection.getSelectedValues())[0]);
final HashMap<String, Integer> deckMap = new HashMap<String, Integer>();
for (final Entry<CardPrinted, Integer> s : targetDeck.getMain()) {
deckMap.put(s.getKey().getName(), s.getValue());
}
final String nl = System.getProperty("line.separator");
final StringBuilder deckList = new StringBuilder();
String dName = targetDeck.getName();
if (dName == null) {
dName = "";
} else {
deckList.append(dName + nl);
}
final ArrayList<String> dmKeys = new ArrayList<String>();
for (final String s : deckMap.keySet()) {
dmKeys.add(s);
}
Collections.sort(dmKeys);
for (final String s : dmKeys) {
deckList.append(deckMap.get(s) + " x " + s + nl);
}
int rcMsg = -1138;
String ttl = player + "'s Decklist";
if (!dName.equals("")) {
ttl += " - " + dName;
}
final StringBuilder msg = new StringBuilder();
if (deckMap.keySet().size() <= 32) {
msg.append(deckList.toString() + nl);
} else {
msg.append("Decklist too long for dialog." + nl + nl);
}
msg.append("Copy Decklist to Clipboard?");
rcMsg = JOptionPane.showConfirmDialog(null, msg, ttl, JOptionPane.OK_CANCEL_OPTION);
if (rcMsg == JOptionPane.OK_OPTION) {
final StringSelection ss = new StringSelection(deckList.toString());
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
}
}
} // End DeckListAction
return exit;
}
/**
* Exhaustively converts object array to string array.

View File

@@ -1,10 +1,14 @@
package forge.view.home;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
import forge.AllZone;
@@ -34,6 +38,8 @@ public class SubButton extends JButton {
setBorder(new LineBorder(skin.getColor("borders"), 1));
setBackground(skin.getColor("inactive"));
setForeground(skin.getColor("text"));
setVerticalTextPosition(SwingConstants.CENTER);
setFocusPainted(false);
this.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
@@ -44,6 +50,16 @@ public class SubButton extends JButton {
if (isEnabled()) { setBackground(skin.getColor("inactive")); }
}
});
this.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
int px = (int) (SubButton.this.getHeight() / 2.5);
px = (px < 10 ? 10 : px);
px = (px > 15 ? 15 : px);
SubButton.this.setFont(AllZone.getSkin().getFont1().deriveFont(Font.PLAIN, px));
}
});
}
@Override

View File

@@ -1,10 +1,8 @@
package forge.view.home;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractAction;
import javax.swing.DefaultListSelectionModel;
@@ -12,15 +10,13 @@ import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import javax.swing.Timer;
import net.miginfocom.swing.MigLayout;
import forge.AllZone;
import forge.control.home.ControlConstructed;
import forge.deck.Deck;
import forge.game.GameType;
import forge.view.toolbox.FList;
import forge.view.toolbox.FScrollPane;
import forge.view.toolbox.FSkin;
/**
@@ -29,24 +25,20 @@ import forge.view.toolbox.FSkin;
*/
@SuppressWarnings("serial")
public class ViewConstructed extends JPanel {
private String constraints;
private FSkin skin;
private HomeTopLevel parentView;
private Timer timer1 = null;
private int counter;
private JList lstColorsHuman, lstColorsAI, lstThemesHuman,
lstThemesAI, lstDecksHuman, lstDecksAI;
private SubButton btnHumanDeckList, btnAIDeckList;
private JList lstDecksAI;
private SubButton btnHumanRandomTheme, btnHumanRandomDeck, btnAIRandomTheme, btnAIRandomDeck;
private ControlConstructed control;
private FList lstColorsHuman, lstThemesHuman, lstDecksHuman, lstColorsAI, lstThemesAI;
/**
* Assembles swing components for "Constructed" mode menu.
*
* @param v0 &emsp; HomeTopLevel parent view
* @param v0 {@link forge.view.home.HomeTopLevel} parent view
*/
public ViewConstructed(HomeTopLevel v0) {
// Basic init stuff
//========== Basic init stuff
super();
this.setOpaque(false);
this.setLayout(new MigLayout("insets 0, gap 0"));
@@ -54,106 +46,17 @@ public class ViewConstructed extends JPanel {
skin = AllZone.getSkin();
control = new ControlConstructed(this);
lstColorsHuman = new JList();
lstColorsHuman.setListData(control.oa2sa(control.getColorNames()));
populateHuman();
lstColorsAI = new JList();
lstColorsAI.setListData(control.oa2sa(control.getColorNames()));
lstDecksHuman = new JList();
lstDecksAI = new JList();
lstThemesHuman = new JList();
lstThemesHuman.setListData(control.oa2sa(control.getThemeNames()));
lstThemesAI = new JList();
lstThemesAI.setListData(control.oa2sa(control.getThemeNames()));
// Human deck options area
JLabel lblHuman = new JLabel("Choose a deck for the human player:");
lblHuman.setFont(skin.getFont1().deriveFont(Font.BOLD, 16));
lblHuman.setForeground(skin.getColor("text"));
this.add(lblHuman, "w 90%!, h 5%!, gap 5% 5% 2% 0, wrap, span 5 1");
// Human deck list button
btnHumanDeckList = new SubButton();
btnHumanDeckList.setAction(new AbstractAction() {
public void actionPerformed(ActionEvent arg0) {
String s = lstDecksHuman.getSelectedValue().toString();
Deck d = AllZone.getDeckManager().getDeck(s);
parentView.getUtilitiesController().showDeckEditor(GameType.Constructed, d);
}
});
btnHumanDeckList.setFont(skin.getFont1().deriveFont(Font.PLAIN, 13));
btnHumanDeckList.setText("Edit selected deck");
btnHumanDeckList.setVerticalTextPosition(SwingConstants.CENTER);
// Add components
constraints = "w 28%!, h 30%!, span 1 2";
this.add(new JScrollPane(lstColorsHuman), constraints + ", gapleft 3%");
this.add(new OrPanel(), "w 5%!, h 30%!, span 1 2");
this.add(new JScrollPane(lstThemesHuman), constraints);
this.add(new OrPanel(), "w 5%!, h 30%!, span 1 2");
this.add(new JScrollPane(lstDecksHuman), "w 28%!, h 25%!, gapbottom 1%, wrap");
this.add(btnHumanDeckList, "w 28%!, h 4%!, wrap");
// AI deck options area
JLabel lblAI = new JLabel("Choose a deck for the AI player:");
lblAI.setFont(skin.getFont1().deriveFont(Font.BOLD, 16));
lblAI.setForeground(skin.getColor("text"));
this.add(lblAI, "w 90%!, h 5%!, gap 5% 5% 2% 0, wrap, span 5 1");
// AI deck list button
btnAIDeckList = new SubButton();
btnAIDeckList.setAction(new AbstractAction() {
public void actionPerformed(ActionEvent arg0) {
String s = lstDecksAI.getSelectedValue().toString();
Deck d = AllZone.getDeckManager().getDeck(s);
parentView.getUtilitiesController().showDeckEditor(GameType.Constructed, d);
}
});
btnAIDeckList.setFont(skin.getFont1().deriveFont(Font.PLAIN, 13));
btnAIDeckList.setText("Edit selected deck");
// Add components
this.add(new JScrollPane(lstColorsAI), constraints + ", gapleft 3%");
this.add(new OrPanel(), "w 5%!, h 30%!, span 1 2");
this.add(new JScrollPane(lstThemesAI), constraints);
this.add(new OrPanel(), "w 5%!, h 30%!, span 1 2");
this.add(new JScrollPane(lstDecksAI), "w 28%!, h 25%!, gapbottom 1%, wrap");
this.add(btnAIDeckList, "w 28%!, h 4%!, wrap");
// List box properties
this.lstColorsHuman.setName("lstColorsHuman");
this.lstThemesHuman.setName("lstThemesHuman");
this.lstDecksHuman.setName("lstDecksHuman");
this.lstColorsAI.setName("lstColorsAI");
this.lstThemesAI.setName("lstThemesAI");
this.lstDecksAI.setName("lstDecksAI");
this.lstThemesHuman.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
this.lstDecksHuman.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
this.lstThemesAI.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
this.lstDecksAI.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
populateAI();
// Start button
JButton btnStart = new JButton();
StartButton btnStart = new StartButton(parentView);
btnStart.setAction(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent arg0) { control.start(); }
});
btnStart.setRolloverEnabled(true);
btnStart.setPressedIcon(parentView.getStartButtonDown());
btnStart.setRolloverIcon(parentView.getStartButtonOver());
btnStart.setIcon(parentView.getStartButtonUp());
btnStart.setOpaque(false);
btnStart.setContentAreaFilled(false);
btnStart.setBorder(null);
btnStart.setBorderPainted(false);
btnStart.setBounds(10, 476, 205, 84);
JPanel pnlButtonContainer = new JPanel();
pnlButtonContainer.setOpaque(false);
@@ -182,87 +85,210 @@ public class ViewConstructed extends JPanel {
}
}
/** @return HomeTopLevel */
/** Assembles Swing components in human area. */
private void populateHuman() {
lstColorsHuman = new FList();
lstColorsHuman.setListData(control.getColorNames());
lstColorsHuman.setName("lstColorsHuman");
lstThemesHuman = new FList();
lstThemesHuman.setListData(control.oa2sa(control.getThemeNames()));
lstThemesHuman.setName("lstThemesHuman");
lstThemesHuman.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
lstDecksHuman = new FList();
lstDecksHuman.setName("lstDecksHuman");
lstDecksHuman.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
JLabel lblHuman = new JLabel("Choose your deck:");
lblHuman.setFont(skin.getFont1().deriveFont(Font.BOLD, 16));
lblHuman.setForeground(skin.getColor("text"));
lblHuman.setHorizontalAlignment(SwingConstants.CENTER);
JLabel lblColorInfo = new JLabel("Multiple Colors: CTRL");
lblColorInfo.setFont(skin.getFont1().deriveFont(Font.ITALIC, 12));
lblColorInfo.setForeground(skin.getColor("text"));
lblColorInfo.setHorizontalAlignment(SwingConstants.CENTER);
JLabel lblDecklistInfo = new JLabel("Decklist: Double Click");
lblDecklistInfo.setFont(skin.getFont1().deriveFont(Font.ITALIC, 12));
lblDecklistInfo.setForeground(skin.getColor("text"));
lblDecklistInfo.setHorizontalAlignment(SwingConstants.CENTER);
// Random theme button
btnHumanRandomTheme = new SubButton();
btnHumanRandomTheme.setAction(new AbstractAction() {
public void actionPerformed(ActionEvent arg0) {
control.randomPick(lstThemesHuman);
}
});
btnHumanRandomTheme.setText("Random Theme Deck");
// Random deck button
btnHumanRandomDeck = new SubButton();
btnHumanRandomDeck.setAction(new AbstractAction() {
public void actionPerformed(ActionEvent arg0) {
control.randomPick(lstDecksHuman);
}
});
btnHumanRandomDeck.setText("Random Deck");
// Add components to human area
JPanel colorsContainer = new JPanel();
colorsContainer.setOpaque(false);
colorsContainer.setLayout(new MigLayout("insets 0, gap 0"));
colorsContainer.add(lblColorInfo, "w 100%!, h 8%!, gapbottom 2%, wrap");
colorsContainer.add(new FScrollPane(lstColorsHuman), "w 100%!, h 89%!, wrap");
JPanel themeContainer = new JPanel();
themeContainer.setOpaque(false);
themeContainer.setLayout(new MigLayout("insets 0, gap 0"));
themeContainer.add(new FScrollPane(lstThemesHuman), "w 100%!, h 75%!, gaptop 10%, wrap");
themeContainer.add(btnHumanRandomTheme, "w 100%!, h 12%!, gaptop 2.5%");
JPanel decksContainer = new JPanel();
decksContainer.setOpaque(false);
decksContainer.setLayout(new MigLayout("insets 0, gap 0"));
decksContainer.add(lblDecklistInfo, "w 100%!, h 8%!, gapbottom 2%, wrap");
decksContainer.add(new FScrollPane(lstDecksHuman), "w 100%!, h 75%!, wrap");
decksContainer.add(btnHumanRandomDeck, "w 100%!, h 12%!, gaptop 2.5%");
String listConstraints = "w 28%!, h 40%!";
String orConstraints = "w 5%!, h 30%!";
this.add(lblHuman, "w 94%!, h 5%!, gap 3% 0 2% 0, wrap, span 5 1");
this.add(colorsContainer, listConstraints + ", gapleft 3%");
this.add(new OrPanel(), orConstraints);
this.add(themeContainer, listConstraints);
this.add(new OrPanel(), orConstraints);
this.add(decksContainer, listConstraints);
}
/** Assembles Swing components in AI area. */
private void populateAI() {
lstColorsAI = new FList();
lstColorsAI.setListData(control.getColorNames());
lstColorsAI.setName("lstColorsAI");
lstThemesAI = new FList();
lstThemesAI.setListData(control.oa2sa(control.getThemeNames()));
lstThemesAI.setName("lstThemesAI");
lstThemesAI.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
lstDecksAI = new FList();
lstDecksAI.setName("lstDecksAI");
lstDecksAI.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
JLabel lblAI = new JLabel("Choose a deck for the computer:");
lblAI.setFont(skin.getFont1().deriveFont(Font.BOLD, 16));
lblAI.setForeground(skin.getColor("text"));
lblAI.setHorizontalAlignment(SwingConstants.CENTER);
JLabel lblColorInfo = new JLabel("Multiple Colors: CTRL");
lblColorInfo.setFont(skin.getFont1().deriveFont(Font.ITALIC, 12));
lblColorInfo.setForeground(skin.getColor("text"));
lblColorInfo.setHorizontalAlignment(SwingConstants.CENTER);
JLabel lblDecklistInfo = new JLabel("Decklist: Double Click");
lblDecklistInfo.setFont(skin.getFont1().deriveFont(Font.ITALIC, 12));
lblDecklistInfo.setForeground(skin.getColor("text"));
lblDecklistInfo.setHorizontalAlignment(SwingConstants.CENTER);
// Random theme button
btnAIRandomTheme = new SubButton();
btnAIRandomTheme.setAction(new AbstractAction() {
public void actionPerformed(ActionEvent arg0) {
control.randomPick(lstThemesAI);
}
});
btnAIRandomTheme.setText("Random Theme Deck");
// Random deck button
btnAIRandomDeck = new SubButton();
btnAIRandomDeck.setAction(new AbstractAction() {
public void actionPerformed(ActionEvent arg0) {
control.randomPick(lstDecksAI);
}
});
btnAIRandomDeck.setText("Random Deck");
// Add components to AI area
JPanel colorsContainer = new JPanel();
colorsContainer.setOpaque(false);
colorsContainer.setLayout(new MigLayout("insets 0, gap 0"));
colorsContainer.add(lblColorInfo, "w 100%!, h 8%!, gapbottom 2%, wrap");
colorsContainer.add(new FScrollPane(lstColorsAI), "w 100%!, h 89%!, wrap");
JPanel themeContainer = new JPanel();
themeContainer.setOpaque(false);
themeContainer.setLayout(new MigLayout("insets 0, gap 0"));
themeContainer.add(new FScrollPane(lstThemesAI), "w 100%!, h 75%!, gaptop 10%, wrap");
themeContainer.add(btnAIRandomTheme, "w 100%!, h 12%!, gaptop 2.5%");
JPanel decksContainer = new JPanel();
decksContainer.setOpaque(false);
decksContainer.setLayout(new MigLayout("insets 0, gap 0"));
decksContainer.add(lblDecklistInfo, "w 100%!, h 8%!, gapbottom 2%, wrap");
decksContainer.add(new FScrollPane(lstDecksAI), "w 100%!, h 75%!, wrap");
decksContainer.add(btnAIRandomDeck, "w 100%!, h 12%!, gaptop 2.5%");
String listConstraints = "w 28%!, h 40%!";
String orConstraints = "w 5%!, h 30%!";
this.add(lblAI, "w 94%!, h 5%!, gap 3% 0 5% 0, wrap, span 5 1, newline");
this.add(colorsContainer, listConstraints + ", gapleft 3%");
this.add(new OrPanel(), orConstraints);
this.add(themeContainer, listConstraints);
this.add(new OrPanel(), orConstraints);
this.add(decksContainer, listConstraints);
}
//========= RETRIEVAL FUNCTIONS
/** @return {@link forge.view.home.HomeTopLevel} */
public HomeTopLevel getParentView() {
return parentView;
}
/** @return ControlConstructed */
/** @return {@link forge.control.home.ControlConstructed} */
public ControlConstructed getController() {
return control;
}
/**
* Flashes a visual reminder in a list component.
*
* @param lst0 &emsp; JList
*/
public void remind(JList lst0) {
if (timer1 != null) { return; }
final JList target = lst0;
final int[] steps = {210, 215, 220, 220, 220, 215, 210};
final Color oldBG = lst0.getBackground();
counter = 0;
ActionListener fader = new ActionListener() {
@Override
public void actionPerformed(final ActionEvent evt) {
counter++;
if (counter != (steps.length - 1)) {
setBackground(new Color(255, 0, 0, steps[counter]));
}
else {
target.setBackground(oldBG);
timer1.stop();
timer1 = null;
}
}
};
timer1 = new Timer(100, fader);
timer1.start();
}
//========= RETRIEVAL FUNCTIONS
/** @return JList */
/** @return {@link javax.swing.JList} */
public JList getLstColorsHuman() {
return lstColorsHuman;
}
/** @return JList */
/** @return {@link javax.swing.JList} */
public JList getLstThemesHuman() {
return lstThemesHuman;
}
/** @return JList */
/** @return {@link javax.swing.JList} */
public JList getLstDecksHuman() {
return lstDecksHuman;
}
/** @return JList */
/** @return {@link javax.swing.JList} */
public JList getLstColorsAI() {
return lstColorsAI;
}
/** @return JList */
/** @return {@link javax.swing.JList} */
public JList getLstThemesAI() {
return lstThemesAI;
}
/** @return JList */
/** @return {@link javax.swing.JList} */
public JList getLstDecksAI() {
return lstDecksAI;
}
/** @return JButton */
public JButton getBtnHumanDeckList() {
return btnHumanDeckList;
/** @return {@link javax.swing.JButton} */
public JButton getBtnHumanRandomTheme() {
return btnHumanRandomTheme;
}
/** @return JButton */
public JButton getBtnAIDeckList() {
return btnAIDeckList;
/** @return {@link javax.swing.JButton} */
public JButton getBtn() {
return btnHumanRandomDeck;
}
}

View File

@@ -2,8 +2,6 @@ package forge.view.toolbox;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
@@ -56,23 +54,8 @@ public class FList extends JList {
lblItem.setBorder(new EmptyBorder(4, 3, 4, 3));
lblItem.setBackground(skin.getColor("active"));
lblItem.setForeground(skin.getColor("text"));
lblItem.setFont(skin.getFont1().deriveFont(Font.BOLD, 13));
lblItem.setFont(skin.getFont1().deriveFont(Font.PLAIN, 13));
lblItem.setOpaque(isSelected);
lblItem.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
System.out.println("firing asdf");
setOpaque(true);
setBackground(skin.getColor("hover"));
}
@Override
public void mouseExited(MouseEvent e) {
setOpaque(false);
setBackground(null);
}
});
return lblItem;
}
}