123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- import java.io.*;
- import java.io.File;
- import java.util.*;
- import java.awt.*;
- import javax.swing.*;
- import javax.swing.event.*;
- import java.awt.event.*;
- import javax.swing.ImageIcon;
- import java.awt.image.*;
- import javax.imageio.ImageIO;
- import javax.swing.JFileChooser;
- public class Controls extends JPanel implements Observer
- {
- private Model model;
- private JSlider rating;
- private JRadioButton grid;
- private JRadioButton list;
- private ButtonGroup layouts;
- private Image starImg;
- private Image gridImg;
- private Image listImg;
- private Image folderImg;
- private ImageIcon starIcon;
- private ImageIcon gridIcon;
- private ImageIcon listIcon;
- private ImageIcon folderIcon;
- private JButton fileButton;
- private JFileChooser fileChooser;
- // Bob the Builder this shit
- public Controls(Model model)
- {
- // Hook up this observer so that it will be notified when the model
- // changes.
- this.model = model;
- this.setBackground(Color.cyan);
- this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
- this.setPreferredSize(new Dimension(1280,75));
- this.setMinimumSize(new Dimension(320, 75));
-
- try
- {
- this.starImg = ImageIO.read(new File("src/main/resources/star.png"));
- } catch(IOException e) {}
- try
- {
- this.gridImg = ImageIO.read(new File("src/main/resources/grid.png"));
- } catch(IOException e) {}
- try
- {
- this.listImg = ImageIO.read(new File("src/main/resources/list.png"));
- } catch(IOException e) {}
-
- try
- {
- this.folderImg = ImageIO.read(new File("src/main/resources/folder.jpg"));
- } catch(IOException e) {}
-
-
- this.starImg = starImg.getScaledInstance(50, 50, java.awt.Image.SCALE_SMOOTH);
- this.gridImg = gridImg.getScaledInstance(50, 50, java.awt.Image.SCALE_SMOOTH);
- this.listImg = listImg.getScaledInstance(50, 50, java.awt.Image.SCALE_SMOOTH);
- this.folderImg = folderImg.getScaledInstance(50, 50, java.awt.Image.SCALE_SMOOTH);
- this.starIcon = new ImageIcon(starImg);
- this.gridIcon = new ImageIcon(gridImg);
- this.listIcon = new ImageIcon(listImg);
- this.folderIcon = new ImageIcon(folderImg);
-
- this.grid = new JRadioButton(gridIcon, true);
- grid.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- if (!(grid.isSelected(layouts)))
- {
- grid.setSelected(layouts, true);
- list.setSelected(layouts, false);
- model.switchLayout();
- }
- }
- });
-
- this.list = new JRadioButton(listIcon, false);
- list.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- if (!(list.isSelected(layouts)))
- {
- list.setSelected(layouts, true);
- grid.setSelected(layouts, false);
- model.switchLayout();
- }
- }
- });
-
- this.layouts = new ButtonGroup();
- layouts.add(grid);
- layouts.add(list);
- grid.setSelected(layouts, true);
- list.setSelected(layouts, false);
-
- this.fileChooser = new JFileChooser();
- this.fileButton = new JButton(folderIcon);
- fileButton.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- int retval = fileChooser.showOpenDialog(null);
-
- if (retval == JFileChooser.APPROVE_OPTION)
- {
- File file = fileChooser.getSelectedFile();
- if (file.isFile())
- {
- model.newPic(file.getAbsolutePath(), file.getName(), file.length(), file.lastModified());
- }
- }
- }
- });
-
- this.rating = new JSlider(0, 5, 0);
- rating.addChangeListener(new ChangeListener()
- {
- public void stateChanged(ChangeEvent e)
- {
- model.changeFilter(rating.getValue());
- }
- });
- this.rating.setPreferredSize(new Dimension(280, 75));
- this.add(grid);
- this.add(list);
- this.add(rating);
- this.add(fileButton);
- model.addObserver(this);
- }
- public void update(Object observable)
- {
- revalidate();
- repaint();
- }
- }
|