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.bin.Cache; |
24 |
|
import jalview.datamodel.AnnotatedCollectionI; |
25 |
|
import jalview.schemes.ColourSchemeI; |
26 |
|
import jalview.schemes.ColourSchemeLoader; |
27 |
|
import jalview.schemes.ColourSchemes; |
28 |
|
import jalview.schemes.ResidueColourScheme; |
29 |
|
import jalview.schemes.UserColourScheme; |
30 |
|
import jalview.util.MessageManager; |
31 |
|
|
32 |
|
import java.awt.Component; |
33 |
|
import java.awt.event.ActionEvent; |
34 |
|
import java.awt.event.ActionListener; |
35 |
|
import java.awt.event.MouseAdapter; |
36 |
|
import java.awt.event.MouseEvent; |
37 |
|
|
38 |
|
import javax.swing.ButtonGroup; |
39 |
|
import javax.swing.JMenu; |
40 |
|
import javax.swing.JRadioButtonMenuItem; |
41 |
|
|
|
|
| 53.4% |
Uncovered Elements: 55 (118) |
Complexity: 32 |
Complexity Density: 0.43 |
|
42 |
|
public class ColourMenuHelper |
43 |
|
{ |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
44 |
|
public interface ColourChangeListener |
45 |
|
{ |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
@param |
50 |
|
|
51 |
|
|
52 |
|
void changeColour_actionPerformed(String name); |
53 |
|
} |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
@param |
70 |
|
|
71 |
|
@param |
72 |
|
|
73 |
|
@param |
74 |
|
|
75 |
|
@param |
76 |
|
|
77 |
|
|
|
|
| 94.6% |
Uncovered Elements: 2 (37) |
Complexity: 6 |
Complexity Density: 0.21 |
|
78 |
223 |
public static ButtonGroup addMenuItems(final JMenu colourMenu,... |
79 |
|
final ColourChangeListener client, AnnotatedCollectionI coll, |
80 |
|
boolean simpleOnly) |
81 |
|
{ |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
223 |
ButtonGroup colours = new ButtonGroup(); |
87 |
|
|
88 |
223 |
if (!simpleOnly) |
89 |
|
{ |
90 |
217 |
JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem( |
91 |
|
MessageManager.getString("label.none")); |
92 |
217 |
noColourmenuItem.setName(ResidueColourScheme.NONE); |
93 |
217 |
noColourmenuItem.addActionListener(new ActionListener() |
94 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
0 |
@Override... |
96 |
|
public void actionPerformed(ActionEvent e) |
97 |
|
{ |
98 |
0 |
client.changeColour_actionPerformed(ResidueColourScheme.NONE); |
99 |
|
} |
100 |
|
}); |
101 |
217 |
colourMenu.add(noColourmenuItem); |
102 |
217 |
colours.add(noColourmenuItem); |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
223 |
Iterable<ColourSchemeI> colourSchemes = ColourSchemes.getInstance() |
110 |
|
.getColourSchemes(); |
111 |
223 |
for (ColourSchemeI scheme : colourSchemes) |
112 |
|
{ |
113 |
4498 |
if (simpleOnly && !scheme.isSimple()) |
114 |
|
{ |
115 |
36 |
continue; |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
4462 |
final String name = scheme.getSchemeName(); |
123 |
4462 |
String label = MessageManager.getStringOrReturn("label.colourScheme_", |
124 |
|
name); |
125 |
4462 |
final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem( |
126 |
|
label); |
127 |
4462 |
radioItem.setName(name); |
128 |
4462 |
radioItem.setEnabled(scheme.isApplicableTo(coll)); |
129 |
4462 |
if (scheme instanceof UserColourScheme) |
130 |
|
{ |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
0 |
radioItem.addMouseListener(new MouseAdapter() |
137 |
|
{ |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 1.5 |
|
138 |
0 |
@Override... |
139 |
|
public void mousePressed(MouseEvent evt) |
140 |
|
{ |
141 |
0 |
if (evt.isPopupTrigger() && !radioItem.isSelected()) |
142 |
|
{ |
143 |
0 |
offerRemoval(); |
144 |
|
} |
145 |
|
} |
146 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 1.5 |
|
147 |
0 |
@Override... |
148 |
|
public void mouseReleased(MouseEvent evt) |
149 |
|
{ |
150 |
0 |
if (evt.isPopupTrigger() && !radioItem.isSelected()) |
151 |
|
{ |
152 |
0 |
offerRemoval(); |
153 |
|
} |
154 |
|
} |
155 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
156 |
0 |
void offerRemoval()... |
157 |
|
{ |
158 |
0 |
ActionListener al = radioItem.getActionListeners()[0]; |
159 |
0 |
radioItem.removeActionListener(al); |
160 |
0 |
int option = JvOptionPane.showInternalConfirmDialog( |
161 |
|
Desktop.desktop, |
162 |
|
MessageManager |
163 |
|
.getString("label.remove_from_default_list"), |
164 |
|
MessageManager |
165 |
|
.getString("label.remove_user_defined_colour"), |
166 |
|
JvOptionPane.YES_NO_OPTION); |
167 |
0 |
if (option == JvOptionPane.YES_OPTION) |
168 |
|
{ |
169 |
0 |
ColourSchemes.getInstance() |
170 |
|
.removeColourScheme(radioItem.getName()); |
171 |
0 |
colourMenu.remove(radioItem); |
172 |
0 |
updatePreferences(); |
173 |
|
} |
174 |
|
else |
175 |
|
{ |
176 |
0 |
radioItem.addActionListener(al); |
177 |
|
} |
178 |
|
} |
179 |
|
}); |
180 |
|
} |
181 |
4462 |
radioItem.addActionListener(new ActionListener() |
182 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
183 |
0 |
@Override... |
184 |
|
public void actionPerformed(ActionEvent evt) |
185 |
|
{ |
186 |
0 |
client.changeColour_actionPerformed(name); |
187 |
|
} |
188 |
|
}); |
189 |
4462 |
colourMenu.add(radioItem); |
190 |
4462 |
colours.add(radioItem); |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
223 |
if (client instanceof AlignFrame) |
198 |
|
{ |
199 |
212 |
final String label = MessageManager.getString("action.user_defined"); |
200 |
212 |
JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem( |
201 |
|
label); |
202 |
212 |
userDefinedColour.setName(ResidueColourScheme.USER_DEFINED_MENU); |
203 |
212 |
userDefinedColour.addActionListener(new ActionListener() |
204 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
205 |
0 |
@Override... |
206 |
|
public void actionPerformed(ActionEvent e) |
207 |
|
{ |
208 |
0 |
client.changeColour_actionPerformed( |
209 |
|
ResidueColourScheme.USER_DEFINED_MENU); |
210 |
|
} |
211 |
|
}); |
212 |
212 |
colourMenu.add(userDefinedColour); |
213 |
212 |
colours.add(userDefinedColour); |
214 |
|
} |
215 |
|
|
216 |
223 |
return colours; |
217 |
|
} |
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
@param |
227 |
|
@param |
228 |
|
|
|
|
| 81.2% |
Uncovered Elements: 6 (32) |
Complexity: 9 |
Complexity Density: 0.5 |
|
229 |
491 |
public static void setColourSelected(JMenu colourMenu, ColourSchemeI cs)... |
230 |
|
{ |
231 |
491 |
String colourName = cs == null ? ResidueColourScheme.NONE |
232 |
|
: cs.getSchemeName(); |
233 |
|
|
234 |
491 |
JRadioButtonMenuItem none = null; |
235 |
491 |
JRadioButtonMenuItem userDefined = null; |
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
491 |
for (Component menuItem : colourMenu.getMenuComponents()) |
242 |
|
{ |
243 |
1497 |
if (menuItem instanceof JRadioButtonMenuItem) |
244 |
|
{ |
245 |
660 |
JRadioButtonMenuItem radioButton = (JRadioButtonMenuItem) menuItem; |
246 |
660 |
String buttonName = radioButton.getName(); |
247 |
660 |
if (buttonName.equals(colourName)) |
248 |
|
{ |
249 |
280 |
radioButton.setSelected(true); |
250 |
280 |
return; |
251 |
|
} |
252 |
380 |
if (ResidueColourScheme.NONE.equals(buttonName)) |
253 |
|
{ |
254 |
32 |
none = radioButton; |
255 |
|
} |
256 |
380 |
if (ResidueColourScheme.USER_DEFINED_MENU.equals(buttonName)) |
257 |
|
{ |
258 |
0 |
userDefined = radioButton; |
259 |
|
} |
260 |
|
} |
261 |
|
} |
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
|
267 |
211 |
if (cs instanceof UserColourScheme && userDefined != null) |
268 |
|
{ |
269 |
0 |
userDefined.setSelected(true); |
270 |
|
} |
271 |
211 |
else if (none != null) |
272 |
|
{ |
273 |
0 |
none.setSelected(true); |
274 |
|
} |
275 |
|
} |
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 6 |
Complexity Density: 0.46 |
|
281 |
0 |
static void updatePreferences()... |
282 |
|
{ |
283 |
0 |
StringBuilder coloursFound = new StringBuilder(); |
284 |
0 |
String[] files = Cache.getProperty("USER_DEFINED_COLOURS").split("\\|"); |
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
|
291 |
0 |
for (String file : files) |
292 |
|
{ |
293 |
0 |
try |
294 |
|
{ |
295 |
0 |
UserColourScheme ucs = ColourSchemeLoader.loadColourScheme(file); |
296 |
0 |
if (ucs != null |
297 |
|
&& ColourSchemes.getInstance().nameExists(ucs.getName())) |
298 |
|
{ |
299 |
0 |
if (coloursFound.length() > 0) |
300 |
|
{ |
301 |
0 |
coloursFound.append("|"); |
302 |
|
} |
303 |
0 |
coloursFound.append(file); |
304 |
|
} |
305 |
|
} catch (Exception ex) |
306 |
|
{ |
307 |
0 |
jalview.bin.Console |
308 |
|
.outPrintln("Error loading User ColourFile\n" + ex); |
309 |
|
} |
310 |
|
} |
311 |
|
|
312 |
0 |
if (coloursFound.toString().length() > 1) |
313 |
|
{ |
314 |
0 |
Cache.setProperty("USER_DEFINED_COLOURS", coloursFound.toString()); |
315 |
|
} |
316 |
|
else |
317 |
|
{ |
318 |
0 |
Cache.applicationProperties.remove("USER_DEFINED_COLOURS"); |
319 |
|
} |
320 |
|
} |
321 |
|
} |