1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package p3j.gui.dialogs;
17
18 import java.awt.Frame;
19 import java.awt.event.ActionEvent;
20 import java.awt.event.ActionListener;
21 import java.util.ArrayList;
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Set;
25
26 import javax.swing.ButtonGroup;
27 import javax.swing.JButton;
28 import javax.swing.JDialog;
29 import javax.swing.JPanel;
30 import javax.swing.JRadioButton;
31 import javax.swing.JTextField;
32
33 import p3j.experiment.results.filters.ConfigurableResultFilter;
34 import p3j.experiment.results.filters.IResultFilter;
35 import p3j.experiment.results.filters.IncludeAllResultFilter;
36 import p3j.gui.panels.PropertiesShowPanelFactory;
37 import p3j.misc.gui.GUI;
38 import p3j.pppm.ProjectionModel;
39 import p3j.pppm.parameters.ParameterAssignment;
40 import p3j.pppm.parameters.ParameterInstance;
41 import p3j.pppm.sets.SetType;
42
43
44
45
46
47
48
49
50
51
52
53 public class ConfigureResultFilterDialog extends JDialog {
54
55
56 private static final long serialVersionUID = -2646722465211989759L;
57
58
59 public static final int DIALOG_WIDTH = 640;
60
61
62 public static final int DIALOG_HEIGHT = 200;
63
64
65 private static final int KEY_COLUMN_WIDTH = 70;
66
67
68 private final ProjectionModel projection;
69
70
71 private boolean cancelled;
72
73
74 private transient IResultFilter resultFilter = new IncludeAllResultFilter();
75
76
77 private final JTextField matchString = new JTextField();
78
79
80 private final JRadioButton noFilter = new JRadioButton("No Filter");
81 {
82 noFilter.setSelected(true);
83 }
84
85
86 private final JRadioButton matchSetName = new JRadioButton("Match Set Name");
87
88
89 private final JRadioButton matchAssignName = new JRadioButton(
90 "Match Assignment Name");
91
92
93 private final ButtonGroup buttonGroup = new ButtonGroup();
94 {
95 buttonGroup.add(noFilter);
96 buttonGroup.add(matchSetName);
97 buttonGroup.add(matchAssignName);
98 }
99
100
101
102
103
104
105
106
107
108 public ConfigureResultFilterDialog(Frame owner,
109 final ProjectionModel projectionModel) {
110 super(owner, "Configure Result Filtering", true);
111 setSize(DIALOG_WIDTH, DIALOG_HEIGHT);
112 GUI.centerOnScreen(this);
113 projection = projectionModel;
114
115
116 JButton finish = new JButton("Finish");
117 JButton cancel = new JButton("Cancel");
118
119 List<JButton> buttons = new ArrayList<JButton>();
120 buttons.add(cancel);
121 buttons.add(finish);
122
123 PropertiesShowPanelFactory pspf = new PropertiesShowPanelFactory(
124 KEY_COLUMN_WIDTH, buttons, 1);
125
126 pspf.sep("Filter Setup");
127 pspf.app("Matching String:", matchString);
128 final JPanel switchBox = new JPanel();
129 switchBox.add(noFilter);
130 switchBox.add(matchSetName);
131 switchBox.add(matchAssignName);
132 pspf.app("Filter Scope:", switchBox);
133
134 finish.addActionListener(new ActionListener() {
135 @Override
136 public void actionPerformed(ActionEvent e) {
137 configureFilter();
138 setVisible(false);
139 }
140 });
141
142 cancel.addActionListener(new ActionListener() {
143 @Override
144 public void actionPerformed(ActionEvent e) {
145 cancelled = true;
146 setVisible(false);
147 }
148 });
149
150 getContentPane().add(pspf.constructPanel());
151 }
152
153
154
155
156 protected void configureFilter() {
157 if (noFilter.isSelected()) {
158 return;
159 }
160 if (this.matchSetName.isSelected()) {
161 configureBySetName(matchString.getText());
162 } else {
163 configureByAssignmentName(matchString.getText());
164 }
165 }
166
167
168
169
170
171
172
173 private void configureBySetName(String setName) {
174 int matchingSetCounter = 0;
175 Set<Integer> permissibleIDs = new HashSet<Integer>();
176 for (SetType setType : getProjection().getAllSetTypes()) {
177 for (p3j.pppm.sets.Set set : setType.getSets()) {
178 if (set.getName().contains(setName)) {
179 matchingSetCounter++;
180 Set<ParameterAssignment> assignmentSet = set.getParameterAssignments(
181 setType.getDefinedParameters().get(0)).getAssignments();
182 for (ParameterAssignment assignment : assignmentSet) {
183 permissibleIDs.add(assignment.getID());
184 }
185 }
186 }
187 }
188 resultFilter = new ConfigurableResultFilter(permissibleIDs);
189 GUI.printMessage(this, "Matching sets", matchingSetCounter
190 + " set(s) could be matched.");
191 }
192
193
194
195
196
197
198
199 private void configureByAssignmentName(String assignmentName) {
200 Set<Integer> permissibleIDs = new HashSet<Integer>();
201 for (SetType setType : getProjection().getAllSetTypes()) {
202 for (ParameterInstance paramInstance : setType.getDefinedParameters()) {
203 for (p3j.pppm.sets.Set set : setType.getSets()) {
204 for (ParameterAssignment paramAssignment : set
205 .getParameterAssignments(paramInstance).getAssignments()) {
206 if (paramAssignment.getName().contains(assignmentName)) {
207 permissibleIDs.add(paramAssignment.getID());
208 }
209 }
210 }
211 }
212 }
213 resultFilter = new ConfigurableResultFilter(permissibleIDs);
214 GUI.printMessage(this, "Matching assignments", permissibleIDs.size()
215 + " assignment(s) could be matched.");
216 }
217
218
219
220
221
222
223 public boolean isCancelled() {
224 return cancelled;
225 }
226
227
228
229
230
231
232 public IResultFilter getConfiguredResultFilter() {
233 return resultFilter;
234 }
235
236 public ProjectionModel getProjection() {
237 return projection;
238 }
239
240 }