From b0e8fddceb7424b3b9e0baae73f5021d8bde6312 Mon Sep 17 00:00:00 2001 From: Doublestrike Date: Mon, 12 Dec 2011 08:57:30 +0000 Subject: [PATCH] Aesthetic changes to constructed mode view in home screen. Also, a few checkstyle and compiler warning fixes. --- .../control/home/ControlConstructed.java | 36 ++++-- src/main/java/forge/view/GuiTopLevel.java | 2 - src/main/java/forge/view/home/SubButton.java | 16 ++- .../java/forge/view/home/ViewConstructed.java | 107 +++++++++++------- .../java/forge/view/toolbox/CardViewer.java | 2 +- 5 files changed, 107 insertions(+), 56 deletions(-) diff --git a/src/main/java/forge/control/home/ControlConstructed.java b/src/main/java/forge/control/home/ControlConstructed.java index 456f650939a..ceb8cbd5901 100644 --- a/src/main/java/forge/control/home/ControlConstructed.java +++ b/src/main/java/forge/control/home/ControlConstructed.java @@ -38,8 +38,8 @@ import forge.view.home.ViewConstructed; public class ControlConstructed { private ViewConstructed view; - private JList currentHumanSelection = null; - private JList currentAISelection = null; + private JList currentHumanSelection = null; + private JList currentAISelection = null; private Map colorVals; private List themeNames; @@ -196,7 +196,7 @@ public class ControlConstructed { * * @param lst0   a JList that has been clicked */ - public void regulateHuman(JList lst0) { + public void regulateHuman(JList lst0) { if (currentHumanSelection != null && lst0 != currentHumanSelection) { currentHumanSelection.clearSelection(); } @@ -222,6 +222,14 @@ 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); + } } /** @@ -229,7 +237,7 @@ public class ControlConstructed { * * @param lst0   a JList that has been clicked */ - public void regulateAI(JList lst0) { + public void regulateAI(JList lst0) { if (currentAISelection != null && lst0 != currentAISelection) { currentAISelection.clearSelection(); } @@ -255,6 +263,14 @@ 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 @@ -457,19 +473,19 @@ public class ControlConstructed { */ public Object[] getDeckNames() { deckNames = new ArrayList(); + deckNames.add(0, "Random"); + Collection allDecks = AllZone.getDeckManager().getConstructedDecks(); for (Deck d : allDecks) { - deckNames.add(d.getName()); + deckNames.add(d.getName()); } - - //list is alphabetized, but we want the "Random" option first - deckNames.add(0, "Random"); + // No pre-constructed decks? if (deckNames.size() == 1) { deckNames = new ArrayList(); } return deckNames.toArray(); } - + /** * View deck list. */ @@ -478,7 +494,7 @@ public class ControlConstructed { } /** - * Receives click and programmatic requests for viewing card in a player's deck + * Receives click and programmatic requests for viewing card in a player's deck. * */ private class DeckListAction { diff --git a/src/main/java/forge/view/GuiTopLevel.java b/src/main/java/forge/view/GuiTopLevel.java index 00288373851..4705888e457 100644 --- a/src/main/java/forge/view/GuiTopLevel.java +++ b/src/main/java/forge/view/GuiTopLevel.java @@ -33,7 +33,6 @@ import forge.CardList; import forge.Constant; import forge.Display; import forge.GuiMultipleBlockers; -import forge.ImageCache; import forge.MyButton; import forge.Player; import forge.Singletons; @@ -41,7 +40,6 @@ import forge.control.ControlAllUI; import forge.control.match.ControlField; import forge.properties.ForgePreferences; import forge.view.match.ViewField; -import forge.view.swing.OldGuiNewGame; import forge.view.toolbox.FOverlay; /** diff --git a/src/main/java/forge/view/home/SubButton.java b/src/main/java/forge/view/home/SubButton.java index 03838451db1..6a37d2d51a7 100644 --- a/src/main/java/forge/view/home/SubButton.java +++ b/src/main/java/forge/view/home/SubButton.java @@ -1,5 +1,6 @@ package forge.view.home; +import java.awt.Color; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; @@ -15,6 +16,7 @@ import forge.view.toolbox.FSkin; */ @SuppressWarnings("serial") public class SubButton extends JButton { + private FSkin skin; /** */ public SubButton() { this(""); @@ -28,19 +30,27 @@ public class SubButton extends JButton { */ public SubButton(String txt0) { super(txt0); - final FSkin skin = AllZone.getSkin(); + skin = AllZone.getSkin(); setBorder(new LineBorder(skin.getColor("borders"), 1)); setBackground(skin.getColor("inactive")); setForeground(skin.getColor("text")); this.addMouseListener(new MouseAdapter() { public void mouseEntered(MouseEvent e) { - setBackground(skin.getColor("hover")); + if (isEnabled()) { setBackground(skin.getColor("hover")); } } public void mouseExited(MouseEvent e) { - setBackground(skin.getColor("inactive")); + if (isEnabled()) { setBackground(skin.getColor("inactive")); } } }); } + + @Override + public void setEnabled(boolean b0) { + super.setEnabled(b0); + + if (b0) { setBackground(skin.getColor("inactive")); } + else { setBackground(new Color(220, 220, 220)); } + } } diff --git a/src/main/java/forge/view/home/ViewConstructed.java b/src/main/java/forge/view/home/ViewConstructed.java index 5ae33963865..d94a8809d7a 100644 --- a/src/main/java/forge/view/home/ViewConstructed.java +++ b/src/main/java/forge/view/home/ViewConstructed.java @@ -33,9 +33,9 @@ public class ViewConstructed extends JPanel { private Timer timer1 = null; private int counter; - private JList lstColorsHuman, lstColorsAI, lstThemesHuman, + private JList lstColorsHuman, lstColorsAI, lstThemesHuman, lstThemesAI, lstDecksHuman, lstDecksAI; - private SubButton viewHumanDeckList, viewAIDeckList; + private SubButton btnHumanDeckList, btnAIDeckList; private ControlConstructed control; /** @@ -53,12 +53,23 @@ public class ViewConstructed extends JPanel { control = new ControlConstructed(this); // Assemble JLists with arrays from above. - lstColorsHuman = new JList(control.getColorNames()); - lstColorsAI = new JList(control.getColorNames()); - lstDecksHuman = new JList(control.getDeckNames()); - lstDecksAI = new JList(control.getDeckNames()); - lstThemesHuman = new JList(control.getThemeNames()); - lstThemesAI = new JList(control.getThemeNames()); + lstColorsHuman = new JList(); + lstColorsHuman.setListData(control.oa2sa(control.getColorNames())); + + lstColorsAI = new JList(); + lstColorsAI.setListData(control.oa2sa(control.getColorNames())); + + lstDecksHuman = new JList(); + lstDecksHuman.setListData(control.oa2sa(control.getDeckNames())); + + lstDecksAI = new JList(); + lstDecksAI.setListData(control.oa2sa(control.getDeckNames())); + + 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:"); @@ -66,23 +77,26 @@ public class ViewConstructed extends JPanel { lblHuman.setForeground(skin.getColor("text")); this.add(lblHuman, "w 90%!, h 5%!, gap 5% 5% 2% 0, wrap, span 5 1"); - constraints = "w 28%!, h 30%!"; - this.add(new JScrollPane(lstColorsHuman), constraints + ", gapleft 3%"); - this.add(new OrPanel(), "w 5%!, h 30%!"); - this.add(new JScrollPane(lstThemesHuman), constraints); - this.add(new OrPanel(), "w 5%!, h 30%!"); - this.add(new JScrollPane(lstDecksHuman), constraints + ", wrap"); - - viewHumanDeckList = new SubButton(); - viewHumanDeckList.setAction(new AbstractAction() { + // Human deck list button + btnHumanDeckList = new SubButton(); + btnHumanDeckList.setAction(new AbstractAction() { public void actionPerformed(ActionEvent arg0) { ViewConstructed.this.control.viewDeckList("Human"); } }); - viewHumanDeckList.setFont(skin.getFont1().deriveFont(Font.PLAIN, 13)); - viewHumanDeckList.setText("View Human Deck List"); - viewHumanDeckList.setVerticalTextPosition(SwingConstants.CENTER); - this.add(viewHumanDeckList, "w 20%!, h 3%!, gap 5% 5% 2% 0, wrap, span 5 1"); + + btnHumanDeckList.setFont(skin.getFont1().deriveFont(Font.PLAIN, 13)); + btnHumanDeckList.setText("View 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:"); @@ -90,21 +104,23 @@ public class ViewConstructed extends JPanel { lblAI.setForeground(skin.getColor("text")); this.add(lblAI, "w 90%!, h 5%!, gap 5% 5% 2% 0, wrap, span 5 1"); - this.add(new JScrollPane(lstColorsAI), constraints + ", gapleft 3%"); - this.add(new OrPanel(), "w 5%!, h 30%!"); - this.add(new JScrollPane(lstThemesAI), constraints); - this.add(new OrPanel(), "w 5%!, h 30%!"); - this.add(new JScrollPane(lstDecksAI), constraints + ", wrap"); - - viewAIDeckList = new SubButton(); - viewAIDeckList.setAction(new AbstractAction() { + // AI deck list button + btnAIDeckList = new SubButton(); + btnAIDeckList.setAction(new AbstractAction() { public void actionPerformed(ActionEvent arg0) { ViewConstructed.this.control.viewDeckList("Computer"); } }); - viewAIDeckList.setFont(skin.getFont1().deriveFont(Font.PLAIN, 13)); - viewAIDeckList.setText("View AI Deck List"); - this.add(viewAIDeckList, "w 20%!, h 3%!, gap 5% 5% 2% 0, wrap, span 5 1"); + btnAIDeckList.setFont(skin.getFont1().deriveFont(Font.PLAIN, 13)); + btnAIDeckList.setText("View 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"); @@ -178,10 +194,10 @@ public class ViewConstructed extends JPanel { * * @param lst0   JList */ - public void remind(JList lst0) { + public void remind(JList lst0) { if (timer1 != null) { return; } - final JList target = lst0; + final JList target = lst0; final int[] steps = {210, 215, 220, 220, 220, 215, 210}; final Color oldBG = lst0.getBackground(); counter = 0; @@ -207,32 +223,43 @@ public class ViewConstructed extends JPanel { //========= RETRIEVAL FUNCTIONS /** @return JList */ - public JList getLstColorsHuman() { + public JList getLstColorsHuman() { return lstColorsHuman; } /** @return JList */ - public JList getLstThemesHuman() { + public JList getLstThemesHuman() { return lstThemesHuman; } /** @return JList */ - public JList getLstDecksHuman() { + public JList getLstDecksHuman() { return lstDecksHuman; } /** @return JList */ - public JList getLstColorsAI() { + public JList getLstColorsAI() { return lstColorsAI; } /** @return JList */ - public JList getLstThemesAI() { + public JList getLstThemesAI() { return lstThemesAI; } /** @return JList */ - public JList getLstDecksAI() { + public JList getLstDecksAI() { return lstDecksAI; } + + /** @return JButton */ + public JButton getBtnHumanDeckList() { + return btnHumanDeckList; + } + + /** @return JButton */ + public JButton getBtnAIDeckList() { + return btnAIDeckList; + } + } diff --git a/src/main/java/forge/view/toolbox/CardViewer.java b/src/main/java/forge/view/toolbox/CardViewer.java index 6ef8b34d717..2a92843afae 100644 --- a/src/main/java/forge/view/toolbox/CardViewer.java +++ b/src/main/java/forge/view/toolbox/CardViewer.java @@ -73,7 +73,7 @@ public class CardViewer extends JPanel { this.jList.setSelectedIndex(0); } - private class ChooserListModel extends AbstractListModel { + private class ChooserListModel extends AbstractListModel { private static final long serialVersionUID = 3871965346333840556L;