1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import java.util.*;
- import java.awt.*;
- 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)
- {
- // 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);
- }
- /**
- * Update with data from the model.
- */
- 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);
- }
- }
|