-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilterButtons.java
More file actions
46 lines (40 loc) · 1.39 KB
/
FilterButtons.java
File metadata and controls
46 lines (40 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* A JPanel component with methods to add Filter buttons, each
* associated with a particular Filter subclass
*
* @author Richard Dunn, Tim Gesell, modified by Pranav Kadekodi
* @version November 5th 2023
*/
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JButton;
public class FilterButtons extends JPanel {
private SnapShop s;
private ImagePanel ip;
public FilterButtons(SnapShop s) {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
this.s = s;
this.ip = s.getImagePanel();
}
public void addFilter(Filter f, String description) {
JButton filterButton = new JButton(description);//create button with description
filterButton.addActionListener(new FilterButtonListener(ip, f));
add(filterButton);//add button to this JPanel
s.pack();
}
//When a given button, associated with a filter, is clicked,
//tell the ImagePanel to apply the given filter.
private class FilterButtonListener implements ActionListener {
private ImagePanel ip;
private Filter f;
public FilterButtonListener(ImagePanel ip, Filter f) {
this.ip = ip;
this.f = f;
}
public void actionPerformed(ActionEvent e) {
ip.applyFilter(f);
}
}
}