-
Notifications
You must be signed in to change notification settings - Fork 2
/
DefaultsFilterPanel.java
71 lines (62 loc) · 1.98 KB
/
DefaultsFilterPanel.java
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package editor.gui.filter.editor;
import java.awt.FlowLayout;
import java.util.HashMap;
import java.util.Map;
import editor.collection.deck.CategorySpec;
import editor.filter.Filter;
import editor.filter.leaf.FilterLeaf;
import editor.gui.generic.ComboBoxPanel;
import editor.gui.settings.SettingsDialog;
/**
* This class represents a panel that presents the user with a
* single combo box showing the default categories in the
* settings dialog and returns the filter for the selected one.
* It is replaced with the contents of the selected filter in the
* filter tree.
*
* @author Alec Roelke
*/
@SuppressWarnings("serial")
public class DefaultsFilterPanel extends FilterEditorPanel<FilterLeaf<?>>
{
/**
* Combo box showing the default categories.
*/
private ComboBoxPanel<String> defaults;
/**
* Map of category names onto their String representations.
*/
private Map<String, CategorySpec> categories;
/**
* Create a new DefaultsFilterPanel.
*/
public DefaultsFilterPanel()
{
super();
setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
categories = new HashMap<>();
var presets = SettingsDialog.settings().editor.categories.presets();
String[] names = presets.stream().map(CategorySpec::getName).toArray(String[]::new);
for (int i = 0; i < presets.size(); i++)
categories.put(names[i], presets.get(i));
defaults = new ComboBoxPanel<>(names);
add(defaults);
}
/**
* {@inheritDoc}
* This panel doesn't have its own filter; rather, it returns a group containing
* a filter corresponding to the given preset.
*/
@Override
public Filter filter()
{
return new CategorySpec(categories.get(defaults.getSelectedItem())).getFilter();
}
/**
* {@inheritDoc}
* Since this panel doesn't correspond to a filter, this doesn't do anything.
*/
@Override
public void setContents(FilterLeaf<?> filter)
{}
}