Converted FLabel to Builder pattern, so inline calls can now be chained together, setting all preferences at the time of instantiation. Also, makes FLabel fairly immutable.

This commit is contained in:
Doublestrike
2012-02-05 10:20:05 +00:00
parent 32be5e90de
commit 2458eb8c71
13 changed files with 410 additions and 467 deletions

View File

@@ -57,6 +57,7 @@ import forge.properties.NewConstants.Lang.GuiDisplay.HumanLibrary;
import forge.view.GuiTopLevel;
import forge.view.match.ViewField;
import forge.view.match.MatchTopLevel;
import forge.view.toolbox.FLabel;
/**
* Child controller, applied to single field in battlefield. Manages player view
@@ -153,11 +154,11 @@ public class ControlField {
*/
private void addZoneListeners() {
// Graveyard card list button
this.view.getLblGraveyard().setHoverable(true);
((FLabel) this.view.getLblGraveyard()).setHoverable(true);
this.view.getLblGraveyard().removeMouseListener(maGraveyard);
this.view.getLblGraveyard().addMouseListener(maGraveyard);
// Exile card list button
this.view.getLblExile().setHoverable(true);
((FLabel) this.view.getLblExile()).setHoverable(true);
this.view.getLblExile().removeMouseListener(maExiled);
this.view.getLblExile().addMouseListener(maExiled);
@@ -167,17 +168,17 @@ public class ControlField {
this.view.getLblLibrary().addMouseListener(maLibrary);
// Hand button
this.view.getLblHand().setHoverable(true);
((FLabel) this.view.getLblHand()).setHoverable(true);
}
else {
this.view.getLblLibrary().setHoverable(false);
((FLabel) this.view.getLblLibrary()).setHoverable(false);
}
this.view.getLblHand().removeMouseListener(maHand);
this.view.getLblHand().addMouseListener(maHand);
// Flashback card list button
this.view.getLblFlashback().setHoverable(true);
((FLabel) this.view.getLblFlashback()).setHoverable(true);
this.view.getLblFlashback().removeMouseListener(maFlashback);
this.view.getLblFlashback().addMouseListener(maFlashback);
}
@@ -186,22 +187,22 @@ public class ControlField {
* Adds listeners to mana "pool" labels, for paying mana.
*/
private void addPoolListeners() {
this.view.getLblBlack().setHoverable(true);
((FLabel) this.view.getLblBlack()).setHoverable(true);
this.view.getLblBlack().removeMouseListener(maBlack);
this.view.getLblBlack().addMouseListener(maBlack);
this.view.getLblBlue().setHoverable(true);
((FLabel) this.view.getLblBlue()).setHoverable(true);
this.view.getLblBlue().removeMouseListener(maBlue);
this.view.getLblBlue().addMouseListener(maBlue);
this.view.getLblGreen().setHoverable(true);
((FLabel) this.view.getLblGreen()).setHoverable(true);
this.view.getLblGreen().removeMouseListener(maGreen);
this.view.getLblGreen().addMouseListener(maGreen);
this.view.getLblRed().setHoverable(true);
((FLabel) this.view.getLblRed()).setHoverable(true);
this.view.getLblRed().removeMouseListener(maRed);
this.view.getLblRed().addMouseListener(maRed);
this.view.getLblWhite().setHoverable(true);
((FLabel) this.view.getLblWhite()).setHoverable(true);
this.view.getLblWhite().removeMouseListener(maWhite);
this.view.getLblWhite().addMouseListener(maWhite);
this.view.getLblColorless().setHoverable(true);
((FLabel) this.view.getLblColorless()).setHoverable(true);
this.view.getLblColorless().removeMouseListener(maColorless);
this.view.getLblColorless().addMouseListener(maColorless);
}

View File

@@ -51,7 +51,7 @@ public class BazaarTopLevel extends FPanel {
private void populateStalls() {
for (final String s : QuestStallManager.getStallNames()) {
final FLabel lbl = new FLabel(s + " ", SwingConstants.RIGHT);
final FLabel lbl = new FLabel.Builder().text(s + " ").fontAlign(SwingConstants.RIGHT).build();
lbl.setIcon(QuestStallManager.getStall(s).getIcon());
lbl.setIconInBackground(true);

View File

@@ -28,9 +28,9 @@ public class ViewItem extends FRoundedPanel {
/** An update-able panel instance representing a single item. */
public ViewItem() {
// Final inits
lblIcon = new FLabel();
lblName = new FLabel();
lblPrice = new FLabel();
lblIcon = new FLabel.Builder().build();
lblName = new FLabel.Builder().build();
lblPrice = new FLabel.Builder().build();
tarDesc = new FTextArea();
btnPurchase = new SubButton("Buy");

View File

@@ -64,9 +64,11 @@ public class ViewStall extends JPanel {
protected ViewStall(final BazaarTopLevel v0) {
// Final/component inits
this.skin = Singletons.getView().getSkin();
this.lblStallName = new FLabel("", SwingConstants.CENTER);
this.lblEmpty = new FLabel("The merchant does not have anything useful for sale.", SwingConstants.CENTER);
this.lblStats = new FLabel();
this.lblStallName = new FLabel.Builder().text("").fontAlign(SwingConstants.CENTER).build();
this.lblEmpty = new FLabel.Builder()
.text("The merchant does not have anything useful for sale.")
.fontAlign(SwingConstants.CENTER).build();
this.lblStats = new FLabel.Builder().build();
this.tpnFluff = new JTextPane();
this.pnlInventory = new JPanel();
this.scrInventory = new FScrollPane(pnlInventory);

View File

@@ -88,11 +88,11 @@ public class QuestFileLister extends JPanel {
final JPanel rowTitle = new JPanel();
rowTitle.setBackground(skin.getColor(FSkin.Colors.CLR_ZEBRA));
rowTitle.setLayout(new MigLayout("insets 0, gap 0"));
rowTitle.add(new FLabel("Delete", SwingConstants.CENTER), "w 15%!, h 20px!, gap 0 0 5px 0");
rowTitle.add(new FLabel("Rename", SwingConstants.CENTER), "w 15%!, h 20px!, gap 0 0 5px 0");
rowTitle.add(new FLabel("Name", SwingConstants.CENTER), "w 40%!, h 20px!, gap 0 0 5px 0");
rowTitle.add(new FLabel("Mode", SwingConstants.CENTER), "w 15%!, h 20px!, gap 0 0 5px 0");
rowTitle.add(new FLabel("Record", SwingConstants.CENTER), "w 15%!, h 20px!, gap 0 0 5px 0");
rowTitle.add(new FLabel.Builder().text("Delete").fontAlign(SwingConstants.CENTER).build(), "w 15%!, h 20px!, gap 0 0 5px 0");
rowTitle.add(new FLabel.Builder().text("Rename").fontAlign(SwingConstants.CENTER).build(), "w 15%!, h 20px!, gap 0 0 5px 0");
rowTitle.add(new FLabel.Builder().text("Name").fontAlign(SwingConstants.CENTER).build(), "w 40%!, h 20px!, gap 0 0 5px 0");
rowTitle.add(new FLabel.Builder().text("Mode").fontAlign(SwingConstants.CENTER).build(), "w 15%!, h 20px!, gap 0 0 5px 0");
rowTitle.add(new FLabel.Builder().text("Record").fontAlign(SwingConstants.CENTER).build(), "w 15%!, h 20px!, gap 0 0 5px 0");
this.add(rowTitle, "w 98%!, h 30px!, gapleft 1%");
RowPanel row;
@@ -102,9 +102,10 @@ public class QuestFileLister extends JPanel {
row = new RowPanel(qd);
row.add(new DeleteButton(row), "w 15%!, h 20px!, gap 0 0 5px 0");
row.add(new EditButton(row), "w 15%!, h 20px!, gaptop 5px");
row.add(new FLabel(qd.getName()), "w 40%!, h 20px!, gap 0 0 5px 0");
row.add(new FLabel(mode, SwingConstants.CENTER), "w 15%!, h 20px!, gap 0 0 5px 0");
row.add(new FLabel(qd.getWin() + "/" + qd.getLost(), SwingConstants.CENTER), "w 15%!, h 20px!, gap 0 0 5px 0");
row.add(new FLabel.Builder().text(qd.getName()).build(), "w 40%!, h 20px!, gap 0 0 5px 0");
row.add(new FLabel.Builder().text(mode).fontAlign(SwingConstants.CENTER).build(), "w 15%!, h 20px!, gap 0 0 5px 0");
row.add(new FLabel.Builder().text(qd.getWin() + "/" + qd.getLost())
.fontAlign(SwingConstants.CENTER).build(), "w 15%!, h 20px!, gap 0 0 5px 0");
this.add(row, "w 98%!, h 30px!, gap 1% 0 0 0");
tempRows.add(row);
}

View File

@@ -50,17 +50,14 @@ public class QuestPreferencesHandler extends JPanel {
pnlBooster = new JPanel();
pnlShop = new JPanel();
lblErrRewards = new FLabel("Rewards Error");
lblErrDifficulty = new FLabel("Difficulty Error");
lblErrBooster = new FLabel("Booster Error");
lblErrShop = new FLabel("Shop Error");
lblErrRewards = new FLabel.Builder().text("Rewards Error").fontStyle(Font.BOLD).build();
lblErrDifficulty = new FLabel.Builder().text("Difficulty Error").fontStyle(Font.BOLD).build();
lblErrBooster = new FLabel.Builder().text("Booster Error").fontStyle(Font.BOLD).build();
lblErrShop = new FLabel.Builder().text("Shop Error").fontStyle(Font.BOLD).build();
lblErrRewards.setForeground(Color.red);
lblErrRewards.setFontStyle(Font.BOLD);
lblErrDifficulty.setForeground(Color.red);
lblErrDifficulty.setFontStyle(Font.BOLD);
lblErrBooster.setForeground(Color.red);
lblErrBooster.setFontStyle(Font.BOLD);
lblErrShop.setForeground(Color.red);
lblErrShop.setFontStyle(Font.BOLD);
@@ -68,168 +65,172 @@ public class QuestPreferencesHandler extends JPanel {
pnlRewards.setOpaque(false);
pnlRewards.setLayout(new MigLayout("insets 0, gap 0, wrap 2"));
pnlRewards.add(new FLabel("Rewards", new ImageIcon("res/images/icons/CoinIcon.png")), "w 100%!, h 30px!, span 2 1");
pnlRewards.add(new FLabel.Builder().text("Rewards")
.icon(new ImageIcon("res/images/icons/CoinIcon.png")).build(),
"w 100%!, h 30px!, span 2 1");
pnlRewards.add(lblErrRewards, "w 100%!, h 30px!, span 2 1");
constraints1 = "w 60px, h 26px!";
constraints2 = "w 150px!, h 26px!";
pnlRewards.add(new FLabel("Base winnings"), constraints2);
pnlRewards.add(new FLabel.Builder().text("Base winnings").build(), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_BASE, ErrType.REWARDS), constraints1);
pnlRewards.add(new FLabel("No losses"), constraints2);
pnlRewards.add(new FLabel.Builder().text("No losses").build(), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_UNDEFEATED, ErrType.REWARDS), constraints1);
pnlRewards.add(new FLabel("Poison win"), constraints2);
pnlRewards.add(new FLabel.Builder().text("Poison win").build(), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_POISON, ErrType.REWARDS), constraints1);
pnlRewards.add(new FLabel("Milling win"), constraints2);
pnlRewards.add(new FLabel.Builder().text("Milling win").build(), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_MILLED, ErrType.REWARDS), constraints1);
pnlRewards.add(new FLabel("Mulligan 0 win"), constraints2);
pnlRewards.add(new FLabel.Builder().text("Mulligan 0 win").build(), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_MULLIGAN0, ErrType.REWARDS), constraints1);
pnlRewards.add(new FLabel("Alternative win"), constraints2);
pnlRewards.add(new FLabel.Builder().text("Alternative win").build(), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_ALTERNATIVE, ErrType.REWARDS), constraints1);
pnlRewards.add(new FLabel("Win by turn 15"), constraints2);
pnlRewards.add(new FLabel.Builder().text("Win by turn 15").build(), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_TURN15, ErrType.REWARDS), constraints1);
pnlRewards.add(new FLabel("Win by turn 10"), constraints2);
pnlRewards.add(new FLabel.Builder().text("Win by turn 10").build(), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_TURN10, ErrType.REWARDS), constraints1);
pnlRewards.add(new FLabel("Win by turn 5"), constraints2);
pnlRewards.add(new FLabel.Builder().text("Win by turn 5").build(), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_TURN5, ErrType.REWARDS), constraints1);
pnlRewards.add(new FLabel("First turn win"), constraints2);
pnlRewards.add(new FLabel.Builder().text("First turn win").build(), constraints2);
pnlRewards.add(new PrefInput(QPref.REWARDS_TURN1, ErrType.REWARDS), constraints1);
// Difficulty table panel
pnlDifficulty.setOpaque(false);
pnlDifficulty.setLayout(new MigLayout("insets 0, gap 0, wrap 5"));
pnlDifficulty.add(new FLabel("Difficulty Adjustments", new ImageIcon("res/images/icons/NotesIcon.png")), "w 100%!, h 30px!, span 5 1");
pnlDifficulty.add(new FLabel.Builder().text("Difficulty Adjustments").icon(new ImageIcon("res/images/icons/NotesIcon.png")), "w 100%!, h 30px!, span 5 1");
pnlDifficulty.add(lblErrDifficulty, "w 100%!, h 30px!, span 5 1");
constraints1 = "w 60px!, h 26px!";
constraints2 = "w 150px!, h 26px!";
pnlDifficulty.add(new FLabel(""), constraints2);
pnlDifficulty.add(new FLabel("Easy"), constraints1);
pnlDifficulty.add(new FLabel("Medium"), constraints1);
pnlDifficulty.add(new FLabel("Hard"), constraints1);
pnlDifficulty.add(new FLabel("Expert"), constraints1);
pnlDifficulty.add(new FLabel.Builder().text("").build(), constraints2);
pnlDifficulty.add(new FLabel.Builder().text("Easy").build(), constraints1);
pnlDifficulty.add(new FLabel.Builder().text("Medium").build(), constraints1);
pnlDifficulty.add(new FLabel.Builder().text("Hard").build(), constraints1);
pnlDifficulty.add(new FLabel.Builder().text("Expert").build(), constraints1);
pnlDifficulty.add(new FLabel("Wins For Booster"), constraints2);
pnlDifficulty.add(new FLabel.Builder().text("Wins For Booster").build(), constraints2);
pnlDifficulty.add(new PrefInput(QPref.WINS_BOOSTER_EASY, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_BOOSTER_MEDIUM, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_BOOSTER_HARD, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_BOOSTER_EXPERT, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new FLabel("Wins For Rank Increase"), constraints2);
pnlDifficulty.add(new FLabel.Builder().text("Wins For Rank Increase").build(), constraints2);
pnlDifficulty.add(new PrefInput(QPref.WINS_RANKUP_EASY, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_RANKUP_MEDIUM, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_RANKUP_HARD, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_RANKUP_EXPERT, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new FLabel("Wins For Medium AI"), constraints2);
pnlDifficulty.add(new FLabel.Builder().text("Wins For Medium AI").build(), constraints2);
pnlDifficulty.add(new PrefInput(QPref.WINS_MEDIUMAI_EASY, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_MEDIUMAI_MEDIUM, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_MEDIUMAI_HARD, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_MEDIUMAI_EXPERT, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new FLabel("Wins For Hard AI"), constraints2);
pnlDifficulty.add(new FLabel.Builder().text("Wins For Hard AI").build(), constraints2);
pnlDifficulty.add(new PrefInput(QPref.WINS_HARDAI_EASY, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_HARDAI_MEDIUM, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_HARDAI_HARD, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_HARDAI_EXPERT, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new FLabel("Wins For Expert AI"), constraints2);
pnlDifficulty.add(new FLabel.Builder().text("Wins For Expert AI").build(), constraints2);
pnlDifficulty.add(new PrefInput(QPref.WINS_EXPERTAI_EASY, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_EXPERTAI_MEDIUM, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_EXPERTAI_HARD, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.WINS_EXPERTAI_EXPERT, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new FLabel("Starting commons"), constraints2);
pnlDifficulty.add(new FLabel.Builder().text("Starting commons").build(), constraints2);
pnlDifficulty.add(new PrefInput(QPref.STARTING_COMMONS_EASY, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_COMMONS_MEDIUM, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_COMMONS_HARD, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_COMMONS_EXPERT, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new FLabel("Starting uncommons"), constraints2);
pnlDifficulty.add(new FLabel.Builder().text("Starting uncommons").build(), constraints2);
pnlDifficulty.add(new PrefInput(QPref.STARTING_UNCOMMONS_EASY, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_UNCOMMONS_MEDIUM, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_UNCOMMONS_HARD, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_UNCOMMONS_EXPERT, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new FLabel("Starting rares"), constraints2);
pnlDifficulty.add(new FLabel.Builder().text("Starting rares").build(), constraints2);
pnlDifficulty.add(new PrefInput(QPref.STARTING_RARES_EASY, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_RARES_MEDIUM, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_RARES_HARD, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_RARES_EXPERT, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new FLabel("Starting credits"), constraints2);
pnlDifficulty.add(new FLabel.Builder().text("Starting credits").build(), constraints2);
pnlDifficulty.add(new PrefInput(QPref.STARTING_CREDITS_EASY, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_CREDITS_MEDIUM, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_CREDITS_HARD, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new PrefInput(QPref.STARTING_CREDITS_EXPERT, ErrType.DIFFICULTY), constraints1);
pnlDifficulty.add(new FLabel("Starting basic lands"), constraints2);
pnlDifficulty.add(new FLabel.Builder().text("Starting basic lands").build(), constraints2);
pnlDifficulty.add(new PrefInput(QPref.STARTING_BASIC_LANDS, ErrType.DIFFICULTY), constraints1 + ", wrap");
pnlDifficulty.add(new FLabel("Starting snow lands"), constraints2);
pnlDifficulty.add(new FLabel.Builder().text("Starting snow lands").build(), constraints2);
pnlDifficulty.add(new PrefInput(QPref.STARTING_SNOW_LANDS, ErrType.DIFFICULTY), constraints1 + ", wrap");
pnlDifficulty.add(new FLabel("Penalty for loss"), constraints2);
pnlDifficulty.add(new FLabel.Builder().text("Penalty for loss").build(), constraints2);
pnlDifficulty.add(new PrefInput(QPref.PENALTY_LOSS, ErrType.DIFFICULTY), constraints1 + ", wrap");
// Booster breakdown panel
pnlBooster.setOpaque(false);
pnlBooster.setLayout(new MigLayout("insets 0, gap 0, wrap 2"));
pnlBooster.add(new FLabel("Booster Pack Ratios", new ImageIcon("res/images/icons/BookIcon.png")), "w 100%!, h 30px!, span 2 1");
pnlBooster.add(new FLabel.Builder().text("Booster Pack Ratios")
.icon(new ImageIcon("res/images/icons/BookIcon.png")).build(),
"w 100%!, h 30px!, span 2 1");
pnlBooster.add(lblErrBooster, "w 100%!, h 30px!, span 2 1");
constraints1 = "w 60px!, h 26px!";
constraints2 = "w 150px!, h 26px!";
pnlBooster.add(new FLabel("Common"), constraints2);
pnlBooster.add(new FLabel.Builder().text("Common").build(), constraints2);
pnlBooster.add(new PrefInput(QPref.BOOSTER_COMMONS, ErrType.BOOSTER), constraints1);
pnlBooster.add(new FLabel("Uncommon"), constraints2);
pnlBooster.add(new FLabel.Builder().text("Uncommon").build(), constraints2);
pnlBooster.add(new PrefInput(QPref.BOOSTER_UNCOMMONS, ErrType.BOOSTER), constraints1);
pnlBooster.add(new FLabel("Rare"), constraints2);
pnlBooster.add(new FLabel.Builder().text("Rare").build(), constraints2);
pnlBooster.add(new PrefInput(QPref.BOOSTER_RARES, ErrType.BOOSTER), constraints1);
// Shop panel
pnlShop.setOpaque(false);
pnlShop.setLayout(new MigLayout("insets 0, gap 0, wrap 2"));
pnlShop.add(new FLabel("Shop Preferences", new ImageIcon("res/images/icons/CoinIcon.png")), "w 100%!, h 30px!, span 2 1");
pnlShop.add(new FLabel.Builder().text("Shop Preferences")
.icon(new ImageIcon("res/images/icons/CoinIcon.png")).build(), "w 100%!, h 30px!, span 2 1");
pnlShop.add(lblErrShop, "w 100%!, h 30px!, span 2 1");
constraints1 = "w 60px, h 26px!";
constraints2 = "w 150px!, h 26px!";
pnlShop.add(new FLabel("Maximum Packs"), constraints2);
pnlShop.add(new FLabel.Builder().text("Maximum Packs").build(), constraints2);
pnlShop.add(new PrefInput(QPref.SHOP_MAX_PACKS, ErrType.SHOP), constraints1);
pnlShop.add(new FLabel("Starting Packs"), constraints2);
pnlShop.add(new FLabel.Builder().text("Starting Packs").build(), constraints2);
pnlShop.add(new PrefInput(QPref.SHOP_STARTING_PACKS, ErrType.SHOP), constraints1);
pnlShop.add(new FLabel("Wins for Pack"), constraints2);
pnlShop.add(new FLabel.Builder().text("Wins for Pack").build(), constraints2);
pnlShop.add(new PrefInput(QPref.SHOP_WINS_FOR_ADDITIONAL_PACK, ErrType.SHOP), constraints1);
pnlShop.add(new FLabel("Common Singles"), constraints2);
pnlShop.add(new FLabel.Builder().text("Common Singles").build(), constraints2);
pnlShop.add(new PrefInput(QPref.SHOP_SINGLES_COMMON, ErrType.SHOP), constraints1);
pnlShop.add(new FLabel("Uncommon Singles"), constraints2);
pnlShop.add(new FLabel.Builder().text("Uncommon Singles").build(), constraints2);
pnlShop.add(new PrefInput(QPref.SHOP_SINGLES_UNCOMMON, ErrType.SHOP), constraints1);
pnlShop.add(new FLabel("Rare Singles"), constraints2);
pnlShop.add(new FLabel.Builder().text("Rare Singles").build(), constraints2);
pnlShop.add(new PrefInput(QPref.SHOP_SINGLES_RARE, ErrType.SHOP), constraints1);
constraints1 = "w 100%!, gap 0 0 20px 0";
this.add(pnlRewards, constraints1);
this.add(pnlDifficulty, constraints1);

View File

@@ -11,7 +11,6 @@ import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
@@ -56,7 +55,7 @@ public class ViewQuest extends JScrollPane {
pnlDuels, pnlChallenges, pnlStart, pnlTitle, pnlNewQuest,
pnlDecks, pnlLoadQuest, pnlPrefs,
tabDuels, tabChallenges, tabDecks, tabQuests, tabPreferences;
private final JLabel lblTitle, lblLife, lblCredits,
private final FLabel lblTitle, lblLife, lblCredits,
lblWins, lblLosses, lblNextChallengeInWins, lblWinStreak;
private final JButton btnBazaar, btnSpellShop, btnStart, btnEmbark,
@@ -108,13 +107,13 @@ public class ViewQuest extends JScrollPane {
pnlLoadQuest = new JPanel();
pnlPrefs = new JPanel();
lblTitle = new FLabel("New Quest", SwingConstants.CENTER);
lblLife = new FLabel();
lblCredits = new FLabel();
lblWins = new FLabel();
lblLosses = new FLabel();
lblNextChallengeInWins = new FLabel();
lblWinStreak = new FLabel();
lblTitle = new FLabel.Builder().text("New Quest").fontAlign(SwingConstants.CENTER).build();
lblLife = new FLabel.Builder().build();
lblCredits = new FLabel.Builder().build();
lblWins = new FLabel.Builder().build();
lblLosses = new FLabel.Builder().build();
lblNextChallengeInWins = new FLabel.Builder().build();
lblWinStreak = new FLabel.Builder().build();
radEasy = new FRadioButton("Easy");
radMedium = new FRadioButton("Medium");
@@ -269,12 +268,12 @@ public class ViewQuest extends JScrollPane {
pnl.setLayout(new MigLayout("insets 0, align center"));
pnl.setBorderColor(clrBorders);
pnl.setBackground(skin.getColor(FSkin.Colors.CLR_THEME2));
pnl.add(new FLabel("Load a previous Quest"), "h 95%!, gap 0 0 2.5% 0");
pnl.add(new FLabel.Builder().text("Load a previous Quest").build(), "h 95%!, gap 0 0 2.5% 0");
final FLabel lbl = new FLabel("To use quest files "
final FLabel lbl = new FLabel.Builder().text("To use quest files "
+ "from previous versions, put them into "
+ "the res/quest/data directory, and restart Forge.", SwingConstants.CENTER);
lbl.setFontScaleFactor(0.8);
+ "the res/quest/data directory, and restart Forge.")
.fontAlign(SwingConstants.CENTER).fontScaleFactor(0.8).build();
final FScrollPane scr = new FScrollPane(lstQuests);
scr.setBorder(null);
@@ -294,7 +293,7 @@ public class ViewQuest extends JScrollPane {
pnl1.setLayout(new MigLayout("insets 0, align center"));
pnl1.setBorderColor(clrBorders);
pnl1.setBackground(skin.getColor(FSkin.Colors.CLR_THEME2));
pnl1.add(new FLabel("Start a new quest"), "h 95%!, gap 0 0 2.5% 0");
pnl1.add(new FLabel.Builder().text("Start a new quest").build(), "h 95%!, gap 0 0 2.5% 0");
final ButtonGroup group1 = new ButtonGroup();
group1.add(radEasy);
@@ -550,8 +549,7 @@ public class ViewQuest extends JScrollPane {
final File base = ForgeProps.getFile(NewConstants.IMAGE_ICON);
File file = new File(base, event.getIconFilename());
FLabel lblIcon = new FLabel();
lblIcon.setIconScaleFactor(1);
final FLabel lblIcon = new FLabel.Builder().iconScaleFactor(1).build();
if (!file.exists()) {
lblIcon.setIcon(skin.getIcon(FSkin.ForgeIcons.ICO_UNKNOWN));
}
@@ -589,9 +587,8 @@ public class ViewQuest extends JScrollPane {
});
// Name
final FLabel lblName = new FLabel(event.getTitle() + ": " + event.getDifficulty());
lblName.setFontScaleFactor(0.6);
lblName.setHoverable(false);
final FLabel lblName = new FLabel.Builder()
.text(event.getTitle() + ": " + event.getDifficulty()).hoverable(false).build();
this.add(lblName, "h 31px!, gap 0 0 10px 5px, wrap");
// Description
@@ -673,38 +670,38 @@ public class ViewQuest extends JScrollPane {
return control;
}
/** @return {@link javax.swing.JLabel} */
public JLabel getLblTitle() {
/** @return {@link javax.swing.FLabel} */
public FLabel getLblTitle() {
return lblTitle;
}
/** @return {@link javax.swing.JLabel} */
public JLabel getLblLife() {
/** @return {@link javax.swing.FLabel} */
public FLabel getLblLife() {
return lblLife;
}
/** @return {@link javax.swing.JLabel} */
public JLabel getLblCredits() {
/** @return {@link javax.swing.FLabel} */
public FLabel getLblCredits() {
return lblCredits;
}
/** @return {@link javax.swing.JLabel} */
public JLabel getLblWins() {
/** @return {@link javax.swing.FLabel} */
public FLabel getLblWins() {
return lblWins;
}
/** @return {@link javax.swing.JLabel} */
public JLabel getLblLosses() {
/** @return {@link javax.swing.FLabel} */
public FLabel getLblLosses() {
return lblLosses;
}
/** @return {@link javax.swing.JLabel} */
public JLabel getLblNextChallengeInWins() {
/** @return {@link javax.swing.FLabel} */
public FLabel getLblNextChallengeInWins() {
return lblNextChallengeInWins;
}
/** @return {@link javax.swing.JLabel} */
public JLabel getLblWinStreak() {
/** @return {@link javax.swing.FLabel} */
public FLabel getLblWinStreak() {
return lblWinStreak;
}

View File

@@ -65,7 +65,7 @@ public class ViewSettings extends JScrollPane {
private JRadioButton radCardTiny, radCardSmaller, radCardSmall,
radCardMedium, radCardLarge, radCardHuge;
private final JLabel lblTitleSkin;
private final FLabel lblTitleSkin;
/**
*
* Assembles swing components for "Settings" mode menu.
@@ -144,7 +144,7 @@ public class ViewSettings extends JScrollPane {
final JLabel lblTitleGraphics = new SectionLabel("Graphic Options");
viewport.add(lblTitleGraphics, sectionConstraints);
lblTitleSkin = new JLabel("Choose Skin");
lblTitleSkin = new FLabel.Builder().text("Choose Skin").build();
lblTitleSkin.setFont(skin.getBoldFont(14));
lblTitleSkin.setForeground(skin.getColor(FSkin.Colors.CLR_TEXT));
final JLabel lblNoteSkin = new NoteLabel("Various user-created themes for Forge backgrounds, fonts, and colors.");
@@ -157,8 +157,7 @@ public class ViewSettings extends JScrollPane {
lstChooseSkin.ensureIndexIsVisible(lstChooseSkin.getSelectedIndex());
viewport.add(new FScrollPane(lstChooseSkin), "h 60px!, w 150px!, gap 10% 0 0 2%, wrap");
final FLabel lblTitleCardSize = new FLabel("Card Size");
lblTitleCardSize.setFontStyle(Font.BOLD);
final FLabel lblTitleCardSize = new FLabel.Builder().text("Card Size").fontStyle(Font.BOLD).build();
final JLabel lblCardSize = new NoteLabel("Size of cards in hand and playing field, when possible");
viewport.add(lblTitleCardSize, regularConstraints);
viewport.add(lblCardSize, regularConstraints);
@@ -191,7 +190,7 @@ public class ViewSettings extends JScrollPane {
FLabel lblTemp;
for (Shortcut s : shortcuts) {
lblTemp = new FLabel(s.getDescription());
lblTemp = new FLabel.Builder().text(s.getDescription()).build();
KeyboardShortcutField ksf = new KeyboardShortcutField(s);
viewport.add(lblTemp, "w 40%!, h 22px!, gap 10%! 0 0 1%");
viewport.add(ksf, "w 25%!");
@@ -453,8 +452,8 @@ public class ViewSettings extends JScrollPane {
return cbDevMode;
}
/** @return {@link javax.swing.JLabel} */
public JLabel getLblTitleSkin() {
/** @return {@link javax.swing.FLabel} */
public FLabel getLblTitleSkin() {
return lblTitleSkin;
}

View File

@@ -68,56 +68,53 @@ public class ViewUtilities extends JPanel {
final String constraintsBTN = "h 30px!, w 50%!, gap 25% 0 0 0";
btnDownloadPics = new SubButton("Download LQ Card Pictures");
final FLabel lblPics = new FLabel("", SwingConstants.CENTER);
lblPics.setText("Download default card picture for each card.");
lblPics.setFontStyle(Font.ITALIC);
final FLabel lblPics = new FLabel.Builder().fontAlign(SwingConstants.CENTER)
.text("Download default card picture for each card.").fontStyle(Font.ITALIC).build();
this.add(btnDownloadPics, constraintsBTN);
this.add(lblPics, constraintsLBL);
btnDownloadSetPics = new SubButton("Download LQ Set Pictures");
final FLabel lblSets = new FLabel("", SwingConstants.CENTER);
lblSets.setText("Download full card picture sets for all cards from legacy releases of MTG.");
lblSets.setFontStyle(Font.ITALIC);
final FLabel lblSets = new FLabel.Builder().fontAlign(SwingConstants.CENTER)
.text("Download full card picture sets for all cards from legacy releases of MTG.")
.fontStyle(Font.ITALIC).build();
this.add(btnDownloadSetPics, constraintsBTN);
this.add(lblSets, constraintsLBL);
btnDownloadQuestImages = new SubButton("Download Quest Images");
final FLabel lblQuest = new FLabel("", SwingConstants.CENTER);
lblQuest.setText("Download tokens and icons used in Quest mode.");
lblQuest.setFontStyle(Font.ITALIC);
final FLabel lblQuest = new FLabel.Builder().fontAlign(SwingConstants.CENTER)
.text("Download tokens and icons used in Quest mode.").fontStyle(Font.ITALIC).build();
this.add(btnDownloadQuestImages, constraintsBTN);
this.add(lblQuest, constraintsLBL);
btnDownloadPrices = new SubButton("Download Card Prices");
final FLabel lblPrices = new FLabel("", SwingConstants.CENTER);
lblPrices.setText("Download up-to-date price list for in-game card shops.");
lblPrices.setFontStyle(Font.ITALIC);
final FLabel lblPrices = new FLabel.Builder().fontAlign(SwingConstants.CENTER)
.text("Download up-to-date price list for in-game card shops.")
.fontStyle(Font.ITALIC).build();
this.add(btnDownloadPrices, constraintsBTN);
this.add(lblPrices, constraintsLBL);
btnImportPictures = new SubButton("Import Pictures");
final FLabel lblImport = new FLabel("", SwingConstants.CENTER);
lblImport.setText("Import card pictures from a local version of Forge.");
lblImport.setFontStyle(Font.ITALIC);
final FLabel lblImport = new FLabel.Builder().fontAlign(SwingConstants.CENTER)
.text("Import card pictures from a local version of Forge.")
.fontStyle(Font.ITALIC).build();
this.add(btnImportPictures, constraintsBTN);
this.add(lblImport, constraintsLBL);
btnReportBug = new SubButton("Report a Bug");
final FLabel lblReport = new FLabel("", SwingConstants.CENTER);
lblReport.setText("Something broken?");
lblReport.setFontStyle(Font.ITALIC);
final FLabel lblReport = new FLabel.Builder().fontAlign(SwingConstants.CENTER)
.text("Something broken?").fontStyle(Font.ITALIC).build();
this.add(btnReportBug, constraintsBTN);
this.add(lblReport, constraintsLBL);
btnDeckEditor = new SubButton("Deck Editor");
final FLabel lblEditor = new FLabel("", SwingConstants.CENTER);
lblEditor.setText("Build or edit a deck using all cards available in Forge.");
lblEditor.setFontStyle(Font.ITALIC);
final FLabel lblEditor = new FLabel.Builder().fontAlign(SwingConstants.CENTER)
.text("Build or edit a deck using all cards available in Forge.")
.fontStyle(Font.ITALIC).build();
this.add(btnDeckEditor, constraintsBTN);
this.add(lblEditor, constraintsLBL);

View File

@@ -67,7 +67,7 @@ public class ViewField extends FRoundedPanel {
private final Border hoverBorder, inactiveBorder;
private DetailLabel lblHand, lblGraveyard, lblLibrary, lblExile,
private FLabel lblHand, lblGraveyard, lblLibrary, lblExile,
lblFlashback, lblPoison, lblBlack, lblBlue,
lblGreen, lblRed, lblWhite, lblColorless;
@@ -288,57 +288,39 @@ public class ViewField extends FRoundedPanel {
// Hand, library, graveyard, exile, flashback, poison labels
final String constraintsCell = "w 45%!, h 100%!, gap 0 5% 2px 2px";
lblHand = new DetailLabel(FSkin.ZoneImages.ICO_HAND, "99");
lblHand.setToolTipText("Cards in hand");
lblLibrary = new DetailLabel(FSkin.ZoneImages.ICO_LIBRARY, "99");
lblLibrary.setToolTipText("Cards in library");
lblHand = getBuiltFLabel(FSkin.ZoneImages.ICO_HAND, "99", "Cards in hand");
lblLibrary = getBuiltFLabel(FSkin.ZoneImages.ICO_LIBRARY, "99", "Cards in library");
row1.add(lblHand, constraintsCell);
row1.add(lblLibrary, constraintsCell);
lblGraveyard = new DetailLabel(FSkin.ZoneImages.ICO_GRAVEYARD, "99");
lblGraveyard.setToolTipText("Cards in graveyard");
lblExile = new DetailLabel(FSkin.ZoneImages.ICO_EXILE, "99");
lblExile.setToolTipText("Exiled cards");
lblGraveyard = getBuiltFLabel(FSkin.ZoneImages.ICO_GRAVEYARD, "99", "Cards in graveyard");
lblExile = getBuiltFLabel(FSkin.ZoneImages.ICO_EXILE, "99", "Exiled cards");
row2.add(lblGraveyard, constraintsCell);
row2.add(lblExile, constraintsCell);
lblFlashback = new DetailLabel(FSkin.ZoneImages.ICO_FLASHBACK, "99");
lblFlashback.setToolTipText("Flashback cards");
lblPoison = new DetailLabel(FSkin.ZoneImages.ICO_POISON, "99");
lblPoison.setToolTipText("Poison counters");
lblFlashback = getBuiltFLabel(FSkin.ZoneImages.ICO_FLASHBACK, "99", "Flashback cards");
lblPoison = getBuiltFLabel(FSkin.ZoneImages.ICO_POISON, "99", "Poison counters");
row3.add(lblFlashback, constraintsCell);
row3.add(lblPoison, constraintsCell);
// Black, Blue, Colorless, Green, Red, White mana labels
lblBlack = new DetailLabel(FSkin.ManaImages.IMG_BLACK, "99");
lblBlack.setToolTipText("Black mana");
lblBlue = new DetailLabel(FSkin.ManaImages.IMG_BLUE, "99");
lblBlue.setToolTipText("Blue mana");
lblBlack = getBuiltFLabel(FSkin.ManaImages.IMG_BLACK, "99", "Black mana");
lblBlue = getBuiltFLabel(FSkin.ManaImages.IMG_BLUE, "99", "Blue mana");
row4.add(lblBlack, constraintsCell);
row4.add(lblBlue, constraintsCell);
lblGreen = new DetailLabel(FSkin.ManaImages.IMG_GREEN, "99");
lblGreen.setToolTipText("Green mana");
lblRed = new DetailLabel(FSkin.ManaImages.IMG_RED, "99");
lblRed.setToolTipText("Red mana");
lblGreen = getBuiltFLabel(FSkin.ManaImages.IMG_GREEN, "99", "Green mana");
lblRed = getBuiltFLabel(FSkin.ManaImages.IMG_RED, "99", "Red mana");
row5.add(lblGreen, constraintsCell);
row5.add(lblRed, constraintsCell);
lblWhite = new DetailLabel(FSkin.ManaImages.IMG_WHITE, "99");
lblWhite.setToolTipText("White mana");
lblColorless = new DetailLabel(FSkin.ManaImages.IMG_COLORLESS, "99");
lblColorless.setToolTipText("Colorless mana");
lblWhite = getBuiltFLabel(FSkin.ManaImages.IMG_WHITE, "99", "White mana");
lblColorless = getBuiltFLabel(FSkin.ManaImages.IMG_COLORLESS, "99", "Colorless mana");
row6.add(lblWhite, constraintsCell);
row6.add(lblColorless, constraintsCell);
@@ -436,262 +418,138 @@ public class ViewField extends FRoundedPanel {
return this.avatarArea;
}
/**
* Gets the lbl life.
*
* @return DetailLabel
*/
/** @return {@link javax.swing.JLabel} */
public JLabel getLblLife() {
return this.lblLife;
}
/**
* Gets the lbl hand.
*
* @return DetailLabel for hand cards
*/
public DetailLabel getLblHand() {
/** @return {@link javax.swing.JLabel} */
public JLabel getLblHand() {
return this.lblHand;
}
/**
* Gets the lbl library.
*
* @return DetailLabel for library cards
*/
public DetailLabel getLblLibrary() {
/** @return {@link javax.swing.JLabel} */
public JLabel getLblLibrary() {
return this.lblLibrary;
}
/**
* Gets the lbl graveyard.
*
* @return DetailLabel for graveyard cards
*/
public DetailLabel getLblGraveyard() {
/** @return {@link javax.swing.JLabel} */
public JLabel getLblGraveyard() {
return this.lblGraveyard;
}
/**
* Gets the lbl exile.
*
* @return DetailLabel for exiled cards
*/
public DetailLabel getLblExile() {
/** @return {@link javax.swing.JLabel} */
public JLabel getLblExile() {
return this.lblExile;
}
/**
* Gets the lbl flashback.
*
* @return DetailLabel for flashback cards
*/
public DetailLabel getLblFlashback() {
/** @return {@link javax.swing.JLabel} */
public JLabel getLblFlashback() {
return this.lblFlashback;
}
/**
* Gets the lbl poison.
*
* @return DetailLabel for poison counters
*/
public DetailLabel getLblPoison() {
/** @return {@link javax.swing.JLabel} */
public JLabel getLblPoison() {
return this.lblPoison;
}
/**
* Gets the lbl colorless.
*
* @return DetailLabel for colorless mana count
*/
public DetailLabel getLblColorless() {
/** @return {@link javax.swing.JLabel} */
public JLabel getLblColorless() {
return this.lblColorless;
}
/**
* Gets the lbl black.
*
* @return DetailLabel for black mana count
*/
public DetailLabel getLblBlack() {
/** @return {@link javax.swing.JLabel} */
public JLabel getLblBlack() {
return this.lblBlack;
}
/**
* Gets the lbl blue.
*
* @return DetailLabel for blue mana count
*/
public DetailLabel getLblBlue() {
/** @return {@link javax.swing.JLabel} */
public JLabel getLblBlue() {
return this.lblBlue;
}
/**
* Gets the lbl green.
*
* @return DetailLabel for green mana count
*/
public DetailLabel getLblGreen() {
/** @return {@link javax.swing.JLabel} */
public JLabel getLblGreen() {
return this.lblGreen;
}
/**
* Gets the lbl red.
*
* @return DetailLabel for red mana count
*/
public DetailLabel getLblRed() {
/** @return {@link javax.swing.JLabel} */
public JLabel getLblRed() {
return this.lblRed;
}
/**
* Gets the lbl white.
*
* @return DetailLabel for white mana count
*/
public DetailLabel getLblWhite() {
/** @return {@link javax.swing.JLabel} */
public JLabel getLblWhite() {
return this.lblWhite;
}
// Phases
/**
* Gets the lbl upkeep.
*
* @return PhaseLabel
*/
/** @return {@link javax.swing.JLabel} */
public PhaseLabel getLblUpkeep() {
return this.lblUpkeep;
}
/**
* Gets the lbl draw.
*
* @return PhaseLabel
*/
/** @return {@link javax.swing.JLabel} */
public PhaseLabel getLblDraw() {
return this.lblDraw;
}
/**
* Gets the lbl main1.
*
* @return PhaseLabel
*/
/** @return {@link javax.swing.JLabel} */
public PhaseLabel getLblMain1() {
return this.lblMain1;
}
/**
* Gets the lbl begin combat.
*
* @return PhaseLabel
*/
/** @return {@link javax.swing.JLabel} */
public PhaseLabel getLblBeginCombat() {
return this.lblBeginCombat;
}
/**
* Gets the lbl declare attackers.
*
* @return PhaseLabel
*/
/** @return {@link javax.swing.JLabel} */
public PhaseLabel getLblDeclareAttackers() {
return this.lblDeclareAttackers;
}
/**
* Gets the lbl declare blockers.
*
* @return PhaseLabel
*/
/** @return {@link javax.swing.JLabel} */
public PhaseLabel getLblDeclareBlockers() {
return this.lblDeclareBlockers;
}
/**
* Gets the lbl combat damage.
*
* @return PhaseLabel
*/
/** @return {@link javax.swing.JLabel} */
public PhaseLabel getLblCombatDamage() {
return this.lblCombatDamage;
}
/**
* Gets the lbl first strike.
*
* @return PhaseLabel
*/
/** @return {@link javax.swing.JLabel} */
public PhaseLabel getLblFirstStrike() {
return this.lblFirstStrike;
}
/**
* Gets the lbl end combat.
*
* @return PhaseLabel
*/
/** @return {@link javax.swing.JLabel} */
public PhaseLabel getLblEndCombat() {
return this.lblEndCombat;
}
/**
* Gets the lbl main2.
*
* @return PhaseLabel
*/
/** @return {@link javax.swing.JLabel} */
public PhaseLabel getLblMain2() {
return this.lblMain2;
}
/**
* Gets the lbl end turn.
*
* @return PhaseLabel
*/
/** @return {@link javax.swing.JLabel} */
public PhaseLabel getLblEndTurn() {
return this.lblEndTurn;
}
/**
* Gets the lbl cleanup.
*
* @return PhaseLabel
*/
/** @return {@link javax.swing.JLabel} */
public PhaseLabel getLblCleanup() {
return this.lblCleanup;
}
// ========== Custom classes
// ========== Custom class handling
/**
* Used to show various values in "details" panel.
*/
// Design note: Labels are used here since buttons have various
// difficulties in displaying the desired "flat" background and
// also strange icon/action behavior.
public class DetailLabel extends FLabel {
/**
* Instance of JLabel detailing info about field: has icon and optional
* hover effect.
*
* @param s0
*   Label's icon address
* @param txt0
*   Label's text
*/
public DetailLabel(final SkinProp s0, final String txt0) {
super(txt0, SwingConstants.RIGHT);
this.setOpaque(false);
this.setFontScaleFactor(0.5);
this.setIconScaleFactor(0.8);
this.setIconBackgroundAlpha(0.6f);
this.setIconInBackground(true);
this.setIcon(new ImageIcon(skin.getImage(s0)));
this.setHoverable(true);
}
private FLabel getBuiltFLabel(SkinProp p0, String s0, String s1) {
return new FLabel.Builder().icon(new ImageIcon(skin.getImage(p0)))
.opaque(false).fontScaleFactor(0.5).iconAlpha(0.6f).iconInBackground(true)
.text(s0).tooltip(s1).fontAlign(SwingConstants.RIGHT).build();
}
/**

View File

@@ -150,10 +150,11 @@ public class ViewWinLose {
final FScrollPane scrLog = new FScrollPane(txtLog);
scrLog.setBorder(null);
pnlLog.setOpaque(false);
final FLabel lblLog = new FLabel("Game Log", SwingConstants.CENTER);
lblLog.setFontScaleFactor(0.8);
lblLog.setFontStyle(Font.BOLD);
pnlLog.add(lblLog, "w 300px!, h 28px!, gap 0 0 20px 0");
pnlLog.add(new FLabel.Builder().text("Game Log").fontAlign(SwingConstants.CENTER)
.fontScaleFactor(0.8).fontStyle(Font.BOLD).build(),
"w 300px!, h 28px!, gap 0 0 20px 0");
pnlLog.add(scrLog, "w 300px!, h 100px!, gap 0 0 10px 0");
pnlLeft.add(pnlLog, "w 100%!");

View File

@@ -94,11 +94,12 @@ public class DeckLister extends JPanel {
JPanel rowTitle = new TitlePanel();
rowTitle.setBackground(skin.getColor(FSkin.Colors.CLR_ZEBRA));
rowTitle.setLayout(new MigLayout("insets 0, gap 0"));
rowTitle.add(new FLabel("Delete", SwingConstants.CENTER), "w 10%!, h 20px!, gaptop 5px");
rowTitle.add(new FLabel("Edit", SwingConstants.CENTER), "w 10%!, h 20px!, gaptop 5px");
rowTitle.add(new FLabel("Deck Name", SwingConstants.CENTER), "w 60%!, h 20px!, gaptop 5px");
rowTitle.add(new FLabel("Main", SwingConstants.CENTER), "w 10%!, h 20px!, gaptop 5px");
rowTitle.add(new FLabel("Side", SwingConstants.CENTER), "w 10%!, h 20px!, gaptop 5px");
rowTitle.add(new FLabel.Builder().text("Delete").fontAlign(SwingConstants.CENTER), "w 10%!, h 20px!, gaptop 5px");
rowTitle.add(new FLabel.Builder().text("Edit").fontAlign(SwingConstants.CENTER), "w 10%!, h 20px!, gaptop 5px");
rowTitle.add(new FLabel.Builder().text("Deck Name").fontAlign(SwingConstants.CENTER), "w 60%!, h 20px!, gaptop 5px");
rowTitle.add(new FLabel.Builder().text("Main").fontAlign(SwingConstants.CENTER), "w 10%!, h 20px!, gaptop 5px");
rowTitle.add(new FLabel.Builder().text("Side").fontAlign(SwingConstants.CENTER), "w 10%!, h 20px!, gaptop 5px");
this.add(rowTitle, "w 98%!, h 30px!, gapleft 1%");
RowPanel row;

View File

@@ -20,150 +20,225 @@ import forge.Command;
import forge.Singletons;
/**
* A custom instance of JLabel using Forge skin properties.
*
* Font size can be scaled to a percentage of label height (60% by default).
*
* Font scaling can be toggled.
* Uses the Builder pattern to facilitate/encourage inline styling.
* Credit to Effective Java 2 (Joshua Bloch).
* Methods in builder can be chained. To declare:
* <code>new FLabel.Builder().method1(foo).method2(bar).method3(baz)...</code>
* <br>and then call build() to make the label.
* <br><br>
* Adjustable features of FLabel:<br>
* - Automatic font scaling (60% size by default, can toggle on/off)<br>
* - Automatic icon scaling (80% size by default, can toggle on/off)<br>
* - Scale font according to height or width<br>
* - Hoverable<br>
* - Selectable<br>
* - Can execute command when clicked
*/
@SuppressWarnings("serial")
public class FLabel extends JLabel {
private final FSkin skin;
private final ComponentAdapter cadResize;
private final MouseAdapter madEvents;
private final Color clrText, clrBorders, clrHover, clrInactive, clrActive;
/**
* Uses the amazing Builder pattern to facilitate/encourage inline styling.
* Credit to Effective Java 2 (Joshua Bloch), a fantastic book.
* Methods in builder can be chained. To declare:
* <code>new FLabel.Builder().method1(foo).method2(bar).method3(baz)...</code>
* <br>and then call build() to make the label.
*/
public static class Builder extends FLabel {
//========== Default values for FLabel are set here.
private double bldFontScaleFactor = 0.6;
private double bldIconScaleFactor = 0.8;
private int bldFontScaleBy = SwingConstants.VERTICAL;
private int bldFontStyle = Font.PLAIN;
private float bldIconAlpha = 1.0f;
private boolean fontScaleAuto;
private boolean iconScaleAuto;
private boolean bldSelectable = false;
private boolean bldHoverable = false;
private boolean bldOpaque = false;
private boolean bldIconInBackground = false;
private boolean bldFontScaleAuto = true;
private boolean bldIconScaleAuto = true;
private int fontScaleBy;
private String bldText, bldToolTip;
private ImageIcon bldIcon;
private int bldFontAlign;
private Command bldCmd;
private boolean iconInBackground;
private boolean opaque;
// Build!
/** @return {@link forge.view.toolbox.FLabel} */
public FLabel build() { return new FLabel(this); }
private boolean selectable;
private boolean selected;
private boolean hoverable;
private boolean hovered;
// Begin builder methods.
/**@param s0 &emsp; {@link java.lang.String}
* @return {@link forge.view.toolbox.Builder} */
public Builder text(String s0) { this.bldText = s0; return this; }
private double fontScaleFactor;
private double iconScaleFactor;
/**@param s0 &emsp; {@link java.lang.String}
* @return {@link forge.view.toolbox.Builder} */
public Builder tooltip(String s0) { this.bldToolTip = s0; return this; }
/**@param i0 &emsp; {@link javax.swing.ImageIcon}
* @return {@link forge.view.toolbox.Builder} */
public Builder icon(ImageIcon i0) { this.bldIcon = i0; return this; }
/**@param i0 &emsp; SwingConstants.CENTER, .LEFT, or .RIGHT
* @return {@link forge.view.toolbox.Builder} */
public Builder fontAlign(int i0) { this.bldFontAlign = i0; return this; }
/**@param b0 &emsp; boolean
* @return {@link forge.view.toolbox.Builder} */
public Builder opaque(boolean b0) { this.bldOpaque = b0; return this; }
/**@param b0 &emsp; boolean
* @return {@link forge.view.toolbox.Builder} */
public Builder hoverable(boolean b0) { this.bldHoverable = b0; return this; }
/**@param b0 &emsp; boolean
* @return {@link forge.view.toolbox.Builder} */
public Builder selectable(boolean b0) { this.bldSelectable = b0; return this; }
/**@param c0 &emsp; {@link forge.Command} to execute if clicked
* @return {@link forge.view.toolbox.Builder} */
public Builder cmdClick(Command c0) { this.bldCmd = c0; return this; }
/**@param i0 &emsp; Font.PLAIN, Font.BOLD, or Font.ITALIC
* @return {@link forge.view.toolbox.Builder} */
public Builder fontStyle(int i0) { this.bldFontStyle = i0; return this; }
/**@param b0 &emsp; boolean
* @return {@link forge.view.toolbox.Builder} */
public Builder fontScaleAuto(boolean b0) { this.bldFontScaleAuto = b0; return this; }
/**@param d0 &emsp; double between 0 and 1, 0.6 by default
* @return {@link forge.view.toolbox.Builder} */
public Builder fontScaleFactor(double d0) { this.bldFontScaleFactor = d0; return this; }
/**@param i0 &emsp; SwingConstants.HORIZONTAL or .VERTICAL
* @return {@link forge.view.toolbox.Builder} */
public Builder fontScaleBy(int i0) { this.bldFontScaleBy = i0; return this; }
/**@param b0 &emsp; boolean
* @return {@link forge.view.toolbox.Builder} */
public Builder iconScaleAuto(boolean b0) { this.bldIconScaleAuto = b0; return this; }
/**@param d0 &emsp; double between 0 and 1, 0.8 by default
* @return {@link forge.view.toolbox.Builder} */
public Builder iconScaleFactor(double d0) { this.bldIconScaleFactor = d0; return this; }
/**@param b0 &emsp; boolean, icon will be drawn independent of text
* @return {@link forge.view.toolbox.Builder} */
public Builder iconInBackground(boolean b0) { this.bldIconInBackground = b0; return this; }
/**@param f0 &emsp; 0.0f - 1.0f. If icon is in background, this alpha is applied.
* @return {@link forge.view.toolbox.Builder} */
public Builder iconAlpha(float f0) { this.bldIconAlpha = f0; return this; }
}
//========== Constructors
/** Must have protected constructor to allow subclassing. */
protected FLabel() { }
// Call this using FLabel.Builder()...
private FLabel(Builder b0) {
super(b0.bldText);
// Init fields from builder
this.fontScaleFactor = b0.bldFontScaleFactor;
this.iconScaleFactor = b0.bldIconScaleFactor;
this.fontScaleBy = b0.bldFontScaleBy;
this.fontStyle = b0.bldFontStyle;
this.selectable = b0.bldSelectable;
this.hoverable = b0.bldHoverable;
this.opaque = b0.bldOpaque;
this.iconInBackground = b0.bldIconInBackground;
this.fontScaleAuto = b0.bldFontScaleAuto;
this.iconScaleAuto = b0.bldIconScaleAuto;
this.setIcon(b0.bldIcon);
this.setIconAlpha(b0.bldIconAlpha);
this.setCommand(b0.bldCmd);
this.setFontAlign(b0.bldFontAlign);
this.setText(b0.bldText);
this.setToolTipText(b0.bldToolTip);
// Non-custom display properties
this.setForeground(clrText);
this.setBackground(clrInactive);
this.setVerticalTextPosition(SwingConstants.CENTER);
this.setVerticalAlignment(SwingConstants.CENTER);
// Resize adapter
this.removeComponentListener(cadResize);
this.addComponentListener(cadResize);
}
// Final inits
private final Color clrText = Singletons.getView().getSkin().getColor(FSkin.Colors.CLR_TEXT);
private final Color clrBorders = Singletons.getView().getSkin().getColor(FSkin.Colors.CLR_BORDERS);
private final Color clrHover = Singletons.getView().getSkin().getColor(FSkin.Colors.CLR_HOVER);
private final Color clrInactive = Singletons.getView().getSkin().getColor(FSkin.Colors.CLR_ACTIVE);
private final Color clrActive = Singletons.getView().getSkin().getColor(FSkin.Colors.CLR_INACTIVE);
// Custom properties, assigned either at realization (using builder)
// or dynamically (using methods below).
private double fontScaleFactor, iconScaleFactor;
private int fontScaleBy, fontStyle;
private boolean selectable, selected, hoverable, hovered, opaque,
iconInBackground, fontScaleAuto, iconScaleAuto;
// Various variables used in image rendering.
private Image img;
private Graphics2D g2d;
private Command cmdClick;
private int x, y, w, h, iw, ih, sw, sh, ref;
private double iar;
private AlphaComposite alphaDim, alphaStrong;
private int fontStyle;
/** */
public FLabel() {
this("");
}
/** @param i0 &emsp; {@link javax.swing.ImageIcon} */
public FLabel(final Icon i0) {
this("");
this.setIcon(i0);
}
/**
* @param s0 &emsp; {@link java.lang.String}
* @param i0 &emsp; {@link javax.swing.ImageIcon}
*/
public FLabel(final String s0, final Icon i0) {
this(s0);
this.setIcon(i0);
}
/**
* @param s0 &emsp; {@link java.lang.String} text
* @param align0 &emsp; Text alignment
*/
public FLabel(final String s0, final int align0) {
this(s0);
this.setHorizontalAlignment(align0);
}
/** @param s0 &emsp; {@link java.lang.String} */
public FLabel(final String s0) {
super(s0);
this.skin = Singletons.getView().getSkin();
// Final inits
this.clrText = skin.getColor(FSkin.Colors.CLR_TEXT);
this.clrBorders = skin.getColor(FSkin.Colors.CLR_BORDERS);
this.clrHover = skin.getColor(FSkin.Colors.CLR_HOVER);
this.clrActive = skin.getColor(FSkin.Colors.CLR_ACTIVE);
this.clrInactive = skin.getColor(FSkin.Colors.CLR_INACTIVE);
// Custom properties
this.fontScaleAuto = true;
this.fontScaleFactor = 0.6;
this.iconScaleAuto = true;
this.iconScaleFactor = 0.8;
this.selectable = false;
this.selected = false;
this.hoverable = false;
this.hovered = false;
this.fontScaleBy = SwingConstants.VERTICAL;
this.fontStyle = Font.PLAIN;
this.iconInBackground = false;
// Default properties
this.setForeground(clrText);
this.setBackground(clrInactive);
this.setVerticalTextPosition(SwingConstants.CENTER);
this.setVerticalAlignment(SwingConstants.CENTER);
this.setIconBackgroundAlpha(1.0f);
// Resize adapter
this.cadResize = new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
if (fontScaleAuto) {
ref = (fontScaleBy == SwingConstants.VERTICAL ? getHeight() : getWidth());
switch (fontStyle) {
case Font.BOLD:
setFont(skin.getBoldFont((int) (ref * fontScaleFactor)));
repaint();
break;
case Font.ITALIC:
setFont(skin.getItalicFont((int) (ref * fontScaleFactor)));
break;
default:
setFont(skin.getFont((int) (ref * fontScaleFactor)));
}
}
// Non-background icon
if (img != null && iconScaleAuto && !iconInBackground) {
h = (int) (getHeight() * iconScaleFactor);
w = (int) (h * iar * iconScaleFactor);
if (w == 0 || h == 0) { return; }
FLabel.super.setIcon(new ImageIcon(img.getScaledInstance(w, h, Image.SCALE_SMOOTH)));
// Resize adapter
private final ComponentAdapter cadResize = new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
if (fontScaleAuto) {
ref = (fontScaleBy == SwingConstants.VERTICAL ? getHeight() : getWidth());
switch (fontStyle) {
case Font.BOLD:
setFont(Singletons.getView().getSkin().getBoldFont((int) (ref * fontScaleFactor)));
repaint();
break;
case Font.ITALIC:
setFont(Singletons.getView().getSkin().getItalicFont((int) (ref * fontScaleFactor)));
break;
default:
setFont(Singletons.getView().getSkin().getFont((int) (ref * fontScaleFactor)));
}
}
};
this.removeComponentListener(cadResize);
this.addComponentListener(cadResize);
this.madEvents = new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) { hovered = true; repaint(); }
@Override
public void mouseExited(MouseEvent e) { hovered = false; repaint(); }
@Override
public void mouseClicked(MouseEvent e) {
if (!selectable) { return; }
if (selected) { setSelected(false); }
else { setSelected(true); }
cmdClick.execute();
// Non-background icon
if (img != null && iconScaleAuto && !iconInBackground) {
h = (int) (getHeight() * iconScaleFactor);
w = (int) (h * iar * iconScaleFactor);
if (w == 0 || h == 0) { return; }
FLabel.super.setIcon(new ImageIcon(img.getScaledInstance(w, h, Image.SCALE_SMOOTH)));
}
};
}
}
};
// Mouse event handler
private final MouseAdapter madEvents = new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) { hovered = true; repaint(); }
@Override
public void mouseExited(MouseEvent e) { hovered = false; repaint(); }
@Override
public void mouseClicked(MouseEvent e) {
if (!selectable) { return; }
if (selected) { setSelected(false); }
else { setSelected(true); }
cmdClick.execute();
}
};
/** @param b0 &emsp; boolean */
public void setHoverable(boolean b0) {
@@ -215,7 +290,7 @@ public class FLabel extends JLabel {
/** Sets alpha if icon is in background.
* @param f0 &emsp; float */
public void setIconBackgroundAlpha(float f0) {
public void setIconAlpha(float f0) {
this.alphaDim = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, f0);
this.alphaStrong = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f);
}
@@ -231,7 +306,7 @@ public class FLabel extends JLabel {
this.fontScaleBy = i0;
}
/** @param i0 &emsp; must be Font.PLAIN, Font.BOLD, Font.ITALIC */
/** @param i0 &emsp; Font.PLAIN, .BOLD, or .ITALIC */
public void setFontStyle(int i0) {
if (i0 != Font.PLAIN && i0 != Font.BOLD && i0 != Font.ITALIC) {
throw new IllegalArgumentException("FLabel$setFontStyle "
@@ -240,6 +315,16 @@ public class FLabel extends JLabel {
this.fontStyle = i0;
}
/** @param i0 &emsp; SwingConstants.CENTER, .LEFT or .RIGHT */
public void setFontAlign(int i0) {
if (i0 != SwingConstants.CENTER && i0 != SwingConstants.LEFT && i0 != SwingConstants.RIGHT) {
throw new IllegalArgumentException("FLabel$setFontStyle "
+ "must be passed either SwingConstants.CENTER, "
+ "SwingConstants.LEFT, or SwingConstants.RIGHT");
}
this.setHorizontalAlignment(i0);
}
@Override
public void setIcon(final Icon i0) {
if (i0 == null) { this.img = null; return; }