|
@@ -5,6 +5,7 @@ import javax.swing.*;
|
|
|
public class Gallery extends JPanel implements Observer
|
|
|
{
|
|
|
private Model model;
|
|
|
+ private ArrayList<Item> items;
|
|
|
|
|
|
// Bob the Builder this shit
|
|
|
public Gallery(Model model)
|
|
@@ -12,7 +13,11 @@ public class Gallery extends JPanel implements Observer
|
|
|
// Hook up this observer so that it will be notified when the model
|
|
|
// changes.
|
|
|
this.model = model;
|
|
|
+ this.setLayout();
|
|
|
this.setBackground(Color.white);
|
|
|
+ this.items = new ArrayList();
|
|
|
+ reList();
|
|
|
+ reFill(3);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -20,7 +25,62 @@ public class Gallery extends JPanel implements Observer
|
|
|
*/
|
|
|
public void update(Object observable)
|
|
|
{
|
|
|
+ reList();
|
|
|
+ reFill(3);
|
|
|
revalidate();
|
|
|
repaint();
|
|
|
}
|
|
|
+
|
|
|
+ private void reList()
|
|
|
+ {
|
|
|
+ ArrayList<PicData> temp = model.getPics();
|
|
|
+ this.items.clear();
|
|
|
+ for (PicData p: temp)
|
|
|
+ {
|
|
|
+ this.items.add(p);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void reFill(int cols)
|
|
|
+ {
|
|
|
+ if (model.getGrid())
|
|
|
+ {
|
|
|
+ this.setLayout(new GridLayout(0, cols));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ this.setLayout(new GridLayout(0, 1));
|
|
|
+ }
|
|
|
+
|
|
|
+ this.removeAll();
|
|
|
+
|
|
|
+ for (Item i: items)
|
|
|
+ {
|
|
|
+ this.add(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class Item extends JPanel
|
|
|
+{
|
|
|
+ private PicData data;
|
|
|
+ private JLabel pic;
|
|
|
+ private JLabel name;
|
|
|
+ private JLabel rating;
|
|
|
+ private JLabel dateSize;
|
|
|
+
|
|
|
+ public Item(PicData p)
|
|
|
+ {
|
|
|
+ this.data = p;
|
|
|
+ this.setLayout(new GridLayout(0, 1));
|
|
|
+ this.setPreferredSize(100, 150);
|
|
|
+ this.pic = new JLabel(data.getPic());
|
|
|
+ this.name = new JLabel(data.getName());
|
|
|
+ this.rating = new JLabel(data.getRating().toString());
|
|
|
+ this.dateSize = new JLabel(data.getDate().toString() + data.getSize().toString());
|
|
|
+ this.add(pic);
|
|
|
+ this.add(name);
|
|
|
+ this.add(rating);
|
|
|
+ this.add(dateSize);
|
|
|
+ }
|
|
|
}
|