From f947bd5fc0308979ffdd53ba1cd272db92ca6ff2 Mon Sep 17 00:00:00 2001 From: jendave Date: Sat, 6 Aug 2011 15:18:38 +0000 Subject: [PATCH] Fixed stall refresh issue. --- .../bazaar/QuestAbstractBazaarStall.java | 94 +++++++++++-------- 1 file changed, 56 insertions(+), 38 deletions(-) diff --git a/src/forge/quest/bazaar/QuestAbstractBazaarStall.java b/src/forge/quest/bazaar/QuestAbstractBazaarStall.java index c2d41be9f85..17b0bb663c6 100644 --- a/src/forge/quest/bazaar/QuestAbstractBazaarStall.java +++ b/src/forge/quest/bazaar/QuestAbstractBazaarStall.java @@ -9,28 +9,31 @@ import javax.swing.*; import javax.swing.border.LineBorder; import java.awt.*; -public abstract class QuestAbstractBazaarStall extends JPanel implements NewConstants{ - private static final long serialVersionUID = -4147745071116906043L; - String stallName; +public abstract class QuestAbstractBazaarStall extends JPanel implements NewConstants { + private static final long serialVersionUID = -4147745071116906043L; + String stallName; String fluff; ImageIcon icon; + private JPanel inventoryPanel = new JPanel(); - private JPanel inventoryPanel; - - protected QuestData questData = AllZone.QuestData; + protected QuestData questData = AllZone.QuestData; protected QuestAbstractBazaarStall(String stallName, String iconName, String fluff) { this.fluff = fluff; this.icon = GuiUtils.getIconFromFile(iconName); this.stallName = stallName; - + + initUI(); + + } + + private void initUI() { JLabel stallNameLabel; JLabel creditLabel; - - GridBagLayout layout = new GridBagLayout(); + GridBagLayout layout = new GridBagLayout(); this.setLayout(layout); stallNameLabel = new JLabel(stallName); @@ -48,91 +51,106 @@ public abstract class QuestAbstractBazaarStall extends JPanel implements NewCons fluffArea.setEditable(false); fluffArea.setFocusable(false); - GridBagConstraints constraints = new GridBagConstraints(0,0,1,1,1,0,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(2,2,2,2), 0,0); + GridBagConstraints constraints = new GridBagConstraints(0, + 0, + 1, + 1, + 1, + 0, + GridBagConstraints.CENTER, + GridBagConstraints.NONE, + new Insets(2, 2, 2, 2), + 0, + 0); layout.setConstraints(stallNameLabel, constraints); this.add(stallNameLabel); - constraints.gridy=1; + constraints.gridy = 1; constraints.anchor = GridBagConstraints.WEST; constraints.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(fluffArea, constraints); this.add(fluffArea); - constraints.gridy=2; + constraints.gridy = 2; layout.setConstraints(creditLabel, constraints); this.add(creditLabel); java.util.List stallItems = populateItems(); - if (stallItems == null || stallItems.size() == 0){ + if (stallItems == null || stallItems.size() == 0) { //TODO: Get stall-specific fluff in here. - constraints.gridy=3; - constraints.anchor=GridBagConstraints.NORTHWEST; - constraints.fill=GridBagConstraints.BOTH; + constraints.gridy = 3; + constraints.anchor = GridBagConstraints.NORTHWEST; + constraints.fill = GridBagConstraints.BOTH; JLabel noSaleLabel = new JLabel("This stall does not offer anything useful for purchase."); - layout.setConstraints(noSaleLabel,constraints); + layout.setConstraints(noSaleLabel, constraints); this.add(noSaleLabel); } - else{ - constraints.gridy++; - constraints.insets = new Insets(10,5,10,5); + else { + constraints.gridy=3; + constraints.insets = new Insets(10, 5, 10, 5); JLabel saleLabel = new JLabel("The following items are for sale:"); - layout.setConstraints(saleLabel,constraints); + layout.setConstraints(saleLabel, constraints); this.add(saleLabel); - constraints.insets = new Insets(10,5,10,5); + constraints.insets = new Insets(10, 5, 10, 5); - constraints.anchor=GridBagConstraints.NORTHWEST; - constraints.fill=GridBagConstraints.HORIZONTAL; + constraints.anchor = GridBagConstraints.NORTHWEST; + constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weighty = 1; constraints.weightx = GridBagConstraints.REMAINDER; constraints.fill = GridBagConstraints.BOTH; constraints.gridy++; - - inventoryPanel = new JPanel(); - populateInventory(stallItems); - inventoryPanel.setBorder(new LineBorder(Color.ORANGE,2)); - + inventoryPanel.setBorder(new LineBorder(Color.ORANGE, 2)); JScrollPane scrollPane = new JScrollPane(inventoryPanel); - layout.setConstraints(scrollPane,constraints); + layout.setConstraints(scrollPane, constraints); this.add(scrollPane); } - } private void populateInventory(java.util.List stallItems) { + inventoryPanel = new JPanel(); GridBagLayout innerLayout = new GridBagLayout(); inventoryPanel.setLayout(innerLayout); GridBagConstraints innerConstraints = - new GridBagConstraints(0,0,1,1,1,0,GridBagConstraints.NORTHWEST,GridBagConstraints.HORIZONTAL,new Insets(2,2,2,2), 0, 0); + new GridBagConstraints(0, + 0, + 1, + 1, + 1, + 0, + GridBagConstraints.NORTHWEST, + GridBagConstraints.HORIZONTAL, + new Insets(2, 2, 2, 2), + 0, + 0); for (QuestAbstractBazaarItem item : stallItems) { JPanel itemPanel = item.getItemPanel(); - innerLayout.setConstraints(itemPanel,innerConstraints); + innerLayout.setConstraints(itemPanel, innerConstraints); inventoryPanel.add(itemPanel); innerConstraints.gridy++; } - innerConstraints.weighty=1; + innerConstraints.weighty = 1; JLabel fillLabel = new JLabel(); - innerLayout.setConstraints(fillLabel,innerConstraints); + innerLayout.setConstraints(fillLabel, innerConstraints); inventoryPanel.add(fillLabel); } protected abstract java.util.List populateItems(); - public ImageIcon getStallIcon() { return icon; } @@ -142,7 +160,7 @@ public abstract class QuestAbstractBazaarStall extends JPanel implements NewCons } public void updateItems() { - this.inventoryPanel.removeAll(); - this.populateInventory(populateItems()); + this.removeAll(); + this.initUI(); } }