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.bin.Console; |
25 |
|
|
26 |
|
import java.awt.Component; |
27 |
|
|
|
|
| 55.7% |
Uncovered Elements: 39 (88) |
Complexity: 23 |
Complexity Density: 0.42 |
|
28 |
|
public class PromptUserConfig implements Runnable |
29 |
|
{ |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
String property = null; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
boolean allowCancel = false; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
String dialogTitle; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
String dialogText; |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
Runnable iftrue = null, iffalse = null, ifundef = null; |
63 |
|
|
64 |
|
private Component component; |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
private boolean removeifunset; |
71 |
|
|
72 |
|
|
73 |
|
@return |
74 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
0 |
public boolean isRemoveifunset()... |
76 |
|
{ |
77 |
0 |
return removeifunset; |
78 |
|
} |
79 |
|
|
80 |
|
|
81 |
|
@param |
82 |
|
|
83 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
84 |
0 |
public void setRemoveifunset(boolean removeifunset)... |
85 |
|
{ |
86 |
0 |
this.removeifunset = removeifunset; |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
|
@param |
91 |
|
|
92 |
|
@param |
93 |
|
|
94 |
|
@param |
95 |
|
|
96 |
|
@param |
97 |
|
|
98 |
|
@param |
99 |
|
|
100 |
|
@param |
101 |
|
|
102 |
|
@param |
103 |
|
|
104 |
|
@param |
105 |
|
|
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
107 |
43 |
public PromptUserConfig(Component desktop, String property,... |
108 |
|
String dialogTitle, String dialogText, Runnable iftrue, |
109 |
|
Runnable iffalse, Runnable ifundef, boolean allowCancel) |
110 |
|
{ |
111 |
43 |
super(); |
112 |
43 |
this.component = desktop; |
113 |
43 |
this.property = property; |
114 |
43 |
this.dialogTitle = dialogTitle; |
115 |
43 |
this.dialogText = dialogText; |
116 |
43 |
this.iftrue = iftrue; |
117 |
43 |
this.iffalse = iffalse; |
118 |
43 |
this.ifundef = ifundef; |
119 |
43 |
this.allowCancel = allowCancel; |
120 |
|
} |
121 |
|
|
|
|
| 56.8% |
Uncovered Elements: 19 (44) |
Complexity: 12 |
Complexity Density: 0.43 |
|
122 |
33 |
@Override... |
123 |
|
public void run() |
124 |
|
{ |
125 |
33 |
if (property == null) |
126 |
|
{ |
127 |
0 |
return; |
128 |
|
} |
129 |
|
|
130 |
33 |
String lastq = Cache.getProperty(property); |
131 |
|
|
132 |
33 |
if (lastq == null) |
133 |
|
{ |
134 |
17 |
raiseDialog(); |
135 |
17 |
Console.debug("Got user response."); |
136 |
|
} |
137 |
33 |
lastq = Cache.getProperty(property); |
138 |
33 |
String extype = ""; |
139 |
33 |
Exception e = null; |
140 |
33 |
if (lastq == null) |
141 |
|
{ |
142 |
|
|
143 |
17 |
try |
144 |
|
{ |
145 |
17 |
if (ifundef != null) |
146 |
|
{ |
147 |
0 |
ifundef.run(); |
148 |
|
} |
149 |
|
} catch (Exception ex) |
150 |
|
{ |
151 |
0 |
e = ex; |
152 |
0 |
extype = "undefined"; |
153 |
|
} |
154 |
|
} |
155 |
16 |
else if (Boolean.valueOf(lastq).booleanValue()) |
156 |
|
{ |
157 |
|
|
158 |
0 |
try |
159 |
|
{ |
160 |
0 |
if (iftrue != null) |
161 |
|
{ |
162 |
0 |
iftrue.run(); |
163 |
|
} |
164 |
|
} catch (Exception ex) |
165 |
|
{ |
166 |
0 |
e = ex; |
167 |
0 |
extype = "if true"; |
168 |
|
} |
169 |
|
} |
170 |
|
else |
171 |
|
{ |
172 |
16 |
try |
173 |
|
{ |
174 |
16 |
if (iffalse != null) |
175 |
|
{ |
176 |
16 |
iffalse.run(); |
177 |
|
} |
178 |
|
} catch (Exception ex) |
179 |
|
{ |
180 |
0 |
e = ex; |
181 |
0 |
extype = "if false"; |
182 |
|
} |
183 |
|
} |
184 |
|
|
185 |
33 |
if (e != null) |
186 |
|
{ |
187 |
0 |
Console.warn("Unexpected exception when executing the " + extype |
188 |
|
+ " runnable for property " + property, e); |
189 |
|
} |
190 |
|
} |
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
|
|
| 42.9% |
Uncovered Elements: 16 (28) |
Complexity: 8 |
Complexity Density: 0.5 |
|
195 |
17 |
private void raiseDialog()... |
196 |
|
{ |
197 |
17 |
if (Console.isDebugEnabled()) |
198 |
|
{ |
199 |
0 |
Console.debug("Prompting user for " + dialogTitle |
200 |
|
+ " for Cache property " + property); |
201 |
|
} |
202 |
17 |
try |
203 |
|
{ |
204 |
17 |
int reply = JvOptionPane.showConfirmDialog(Desktop.desktop, |
205 |
|
dialogText, dialogTitle, |
206 |
17 |
(allowCancel) ? JvOptionPane.YES_NO_CANCEL_OPTION |
207 |
|
: JvOptionPane.YES_NO_OPTION, |
208 |
|
JvOptionPane.QUESTION_MESSAGE); |
209 |
|
|
210 |
|
|
211 |
17 |
Console.debug("Got response : " + reply); |
212 |
17 |
if (reply == JvOptionPane.YES_OPTION) |
213 |
|
{ |
214 |
0 |
Cache.setProperty(property, "true"); |
215 |
|
} |
216 |
17 |
else if (reply == JvOptionPane.NO_OPTION) |
217 |
|
{ |
218 |
0 |
if (removeifunset) |
219 |
|
{ |
220 |
0 |
Cache.removeProperty(property); |
221 |
|
} |
222 |
|
else |
223 |
|
{ |
224 |
0 |
Cache.setProperty(property, "false"); |
225 |
|
} |
226 |
|
} |
227 |
|
else |
228 |
|
{ |
229 |
17 |
Console.debug("User cancelled setting " + property); |
230 |
17 |
return; |
231 |
|
} |
232 |
|
|
233 |
0 |
if (Console.isDebugEnabled()) |
234 |
|
{ |
235 |
0 |
Console.debug( |
236 |
|
"User set property to " + Cache.getProperty(property)); |
237 |
|
} |
238 |
|
} catch (Exception e) |
239 |
|
{ |
240 |
0 |
Console.warn( |
241 |
|
"Unexpected exception when prompting user for yes/no setting for property " |
242 |
|
+ property, |
243 |
|
e); |
244 |
|
} |
245 |
|
} |
246 |
|
} |