1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import jalview.api.AlignmentViewPanel; |
24 |
|
import jalview.util.MessageManager; |
25 |
|
import jalview.util.Platform; |
26 |
|
|
27 |
|
import java.awt.Component; |
28 |
|
import java.awt.event.ActionEvent; |
29 |
|
import java.awt.event.ActionListener; |
30 |
|
import java.awt.event.ItemEvent; |
31 |
|
import java.awt.event.ItemListener; |
32 |
|
import java.awt.event.MouseAdapter; |
33 |
|
import java.awt.event.MouseEvent; |
34 |
|
import java.util.List; |
35 |
|
|
36 |
|
import javax.swing.JCheckBoxMenuItem; |
37 |
|
import javax.swing.JMenu; |
38 |
|
import javax.swing.JMenuItem; |
39 |
|
import javax.swing.event.MenuEvent; |
40 |
|
import javax.swing.event.MenuListener; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
@author |
50 |
|
|
51 |
|
|
|
|
| 5.9% |
Uncovered Elements: 95 (101) |
Complexity: 27 |
Complexity Density: 0.4 |
|
52 |
|
public class ViewSelectionMenu extends JMenu |
53 |
|
{ |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
54 |
|
public interface ViewSetProvider |
55 |
|
{ |
56 |
|
public AlignmentPanel[] getAllAlignmentPanels(); |
57 |
|
} |
58 |
|
|
59 |
|
private ViewSetProvider _allviews; |
60 |
|
|
61 |
|
private List<AlignmentViewPanel> _selectedviews; |
62 |
|
|
63 |
|
private ItemListener _handler; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
@param |
72 |
|
|
73 |
|
@param |
74 |
|
|
75 |
|
@param |
76 |
|
|
77 |
|
|
78 |
|
@param |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
83 |
221 |
public ViewSelectionMenu(String title, final ViewSetProvider allviews,... |
84 |
|
final List<AlignmentViewPanel> selectedviews, |
85 |
|
final ItemListener handler) |
86 |
|
{ |
87 |
221 |
super(title); |
88 |
221 |
this._allviews = allviews; |
89 |
221 |
this._selectedviews = selectedviews; |
90 |
221 |
this._handler = handler; |
91 |
221 |
addMenuListener(new MenuListener() |
92 |
|
{ |
93 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
94 |
0 |
@Override... |
95 |
|
public void menuSelected(MenuEvent e) |
96 |
|
{ |
97 |
0 |
rebuild(); |
98 |
|
|
99 |
|
} |
100 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
101 |
0 |
@Override... |
102 |
|
public void menuDeselected(MenuEvent e) |
103 |
|
{ |
104 |
|
|
105 |
|
|
106 |
|
} |
107 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
108 |
0 |
@Override... |
109 |
|
public void menuCanceled(MenuEvent e) |
110 |
|
{ |
111 |
|
|
112 |
|
|
113 |
|
} |
114 |
|
}); |
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
private boolean append = false; |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
private boolean enabled = true; |
128 |
|
|
129 |
|
private JMenuItem selectAll, invertSel; |
130 |
|
|
131 |
|
private JCheckBoxMenuItem toggleview = null; |
132 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 5 |
Complexity Density: 0.21 |
|
133 |
0 |
private void rebuild()... |
134 |
|
{ |
135 |
0 |
removeAll(); |
136 |
0 |
AlignmentPanel[] allviews = _allviews.getAllAlignmentPanels(); |
137 |
0 |
if (allviews == null) |
138 |
|
{ |
139 |
0 |
setVisible(false); |
140 |
0 |
return; |
141 |
|
} |
142 |
0 |
if (allviews.length >= 2) |
143 |
|
{ |
144 |
|
|
145 |
0 |
append = append || _selectedviews.size() > 1; |
146 |
0 |
toggleview = new JCheckBoxMenuItem( |
147 |
|
MessageManager.getString("label.select_many_views"), append); |
148 |
0 |
toggleview.setToolTipText( |
149 |
|
MessageManager.getString("label.toggle_enabled_views")); |
150 |
0 |
toggleview.addItemListener(new ItemListener() |
151 |
|
{ |
152 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
153 |
0 |
@Override... |
154 |
|
public void itemStateChanged(ItemEvent arg0) |
155 |
|
{ |
156 |
0 |
if (enabled) |
157 |
|
{ |
158 |
0 |
append = !append; |
159 |
0 |
selectAll.setEnabled(append); |
160 |
0 |
invertSel.setEnabled(append); |
161 |
|
} |
162 |
|
|
163 |
|
} |
164 |
|
|
165 |
|
}); |
166 |
0 |
add(toggleview); |
167 |
0 |
add(selectAll = new JMenuItem( |
168 |
|
MessageManager.getString("label.select_all_views"))); |
169 |
0 |
selectAll.addActionListener(new ActionListener() |
170 |
|
{ |
171 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
172 |
0 |
@Override... |
173 |
|
public void actionPerformed(ActionEvent e) |
174 |
|
{ |
175 |
0 |
for (Component c : getMenuComponents()) |
176 |
|
{ |
177 |
0 |
boolean t = append; |
178 |
0 |
append = true; |
179 |
0 |
if (c instanceof JCheckBoxMenuItem) |
180 |
|
{ |
181 |
0 |
if (toggleview != c && !((JCheckBoxMenuItem) c).isSelected()) |
182 |
|
{ |
183 |
0 |
((JCheckBoxMenuItem) c).doClick(); |
184 |
|
} |
185 |
|
} |
186 |
0 |
append = t; |
187 |
|
} |
188 |
|
} |
189 |
|
}); |
190 |
0 |
add(invertSel = new JMenuItem( |
191 |
|
MessageManager.getString("label.invert_selection"))); |
192 |
0 |
invertSel.addActionListener(new ActionListener() |
193 |
|
{ |
194 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
195 |
0 |
@Override... |
196 |
|
public void actionPerformed(ActionEvent e) |
197 |
|
{ |
198 |
0 |
boolean t = append; |
199 |
0 |
append = true; |
200 |
0 |
for (Component c : getMenuComponents()) |
201 |
|
{ |
202 |
0 |
if (toggleview != c && c instanceof JCheckBoxMenuItem) |
203 |
|
{ |
204 |
0 |
((JCheckBoxMenuItem) c).doClick(); |
205 |
|
} |
206 |
|
} |
207 |
0 |
append = t; |
208 |
|
} |
209 |
|
}); |
210 |
0 |
invertSel.setEnabled(append); |
211 |
0 |
selectAll.setEnabled(append); |
212 |
|
} |
213 |
0 |
for (final AlignmentPanel ap : allviews) |
214 |
|
{ |
215 |
0 |
String nm = ((ap.getViewName() == null |
216 |
|
|| ap.getViewName().length() == 0) ? "" |
217 |
|
: ap.getViewName() + " for ") |
218 |
|
+ ap.alignFrame.getTitle(); |
219 |
0 |
final JCheckBoxMenuItem checkBox = new JCheckBoxMenuItem(nm, |
220 |
|
_selectedviews.contains(ap)); |
221 |
0 |
checkBox.addItemListener(new ItemListener() |
222 |
|
{ |
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 5 |
Complexity Density: 0.28 |
|
223 |
0 |
@Override... |
224 |
|
public void itemStateChanged(ItemEvent e) |
225 |
|
{ |
226 |
0 |
if (enabled) |
227 |
|
{ |
228 |
0 |
if (append) |
229 |
|
{ |
230 |
0 |
enabled = false; |
231 |
|
|
232 |
0 |
if (_selectedviews.indexOf(ap) == -1) |
233 |
|
{ |
234 |
0 |
_selectedviews.add(ap); |
235 |
0 |
checkBox.setSelected(true); |
236 |
|
} |
237 |
|
else |
238 |
|
{ |
239 |
0 |
_selectedviews.remove(ap); |
240 |
0 |
checkBox.setSelected(false); |
241 |
|
} |
242 |
0 |
enabled = true; |
243 |
0 |
_handler.itemStateChanged(e); |
244 |
|
} |
245 |
|
else |
246 |
|
{ |
247 |
|
|
248 |
0 |
_selectedviews.clear(); |
249 |
0 |
_selectedviews.add(ap); |
250 |
0 |
enabled = false; |
251 |
0 |
for (Component c : getMenuComponents()) |
252 |
|
{ |
253 |
0 |
if (c instanceof JCheckBoxMenuItem) |
254 |
|
{ |
255 |
0 |
((JCheckBoxMenuItem) c).setSelected(checkBox == c); |
256 |
|
} |
257 |
|
} |
258 |
0 |
enabled = true; |
259 |
|
|
260 |
0 |
_handler.itemStateChanged(e); |
261 |
|
} |
262 |
|
} |
263 |
|
} |
264 |
|
}); |
265 |
0 |
final ViewSelectionMenu us = this; |
266 |
0 |
checkBox.addMouseListener(new MouseAdapter() |
267 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 2 |
Complexity Density: 2 |
|
268 |
0 |
@Override... |
269 |
|
public void mouseExited(MouseEvent e) |
270 |
|
{ |
271 |
0 |
try |
272 |
|
{ |
273 |
|
} catch (Exception ex) |
274 |
|
{ |
275 |
|
} |
276 |
|
} |
277 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 2 |
Complexity Density: 1 |
|
278 |
0 |
@Override... |
279 |
|
public void mouseEntered(MouseEvent e) |
280 |
|
{ |
281 |
0 |
try |
282 |
|
{ |
283 |
0 |
ap.setAlignFrameView(); |
284 |
|
} catch (Exception ex) |
285 |
|
{ |
286 |
|
} |
287 |
|
} |
288 |
|
}); |
289 |
0 |
add(checkBox); |
290 |
|
} |
291 |
|
} |
292 |
|
|
293 |
|
} |