| 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 |
|
|
| |
|
| 0% |
Uncovered Elements: 88 (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 |
|
|
| |
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
| 107 |
0 |
public PromptUserConfig(Component desktop, String property,... |
| 108 |
|
String dialogTitle, String dialogText, Runnable iftrue, |
| 109 |
|
Runnable iffalse, Runnable ifundef, boolean allowCancel) |
| 110 |
|
{ |
| 111 |
0 |
super(); |
| 112 |
0 |
this.component = desktop; |
| 113 |
0 |
this.property = property; |
| 114 |
0 |
this.dialogTitle = dialogTitle; |
| 115 |
0 |
this.dialogText = dialogText; |
| 116 |
0 |
this.iftrue = iftrue; |
| 117 |
0 |
this.iffalse = iffalse; |
| 118 |
0 |
this.ifundef = ifundef; |
| 119 |
0 |
this.allowCancel = allowCancel; |
| 120 |
|
} |
| 121 |
|
|
| |
|
| 0% |
Uncovered Elements: 44 (44) |
Complexity: 12 |
Complexity Density: 0.43 |
|
| 122 |
0 |
@Override... |
| 123 |
|
public void run() |
| 124 |
|
{ |
| 125 |
0 |
if (property == null) |
| 126 |
|
{ |
| 127 |
0 |
return; |
| 128 |
|
} |
| 129 |
|
|
| 130 |
0 |
String lastq = Cache.getProperty(property); |
| 131 |
|
|
| 132 |
0 |
if (lastq == null) |
| 133 |
|
{ |
| 134 |
0 |
raiseDialog(); |
| 135 |
0 |
Console.debug("Got user response."); |
| 136 |
|
} |
| 137 |
0 |
lastq = Cache.getProperty(property); |
| 138 |
0 |
String extype = ""; |
| 139 |
0 |
Exception e = null; |
| 140 |
0 |
if (lastq == null) |
| 141 |
|
{ |
| 142 |
|
|
| 143 |
0 |
try |
| 144 |
|
{ |
| 145 |
0 |
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 |
0 |
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 |
0 |
try |
| 173 |
|
{ |
| 174 |
0 |
if (iffalse != null) |
| 175 |
|
{ |
| 176 |
0 |
iffalse.run(); |
| 177 |
|
} |
| 178 |
|
} catch (Exception ex) |
| 179 |
|
{ |
| 180 |
0 |
e = ex; |
| 181 |
0 |
extype = "if false"; |
| 182 |
|
} |
| 183 |
|
} |
| 184 |
|
|
| 185 |
0 |
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 |
|
|
| |
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 8 |
Complexity Density: 0.5 |
|
| 195 |
0 |
private void raiseDialog()... |
| 196 |
|
{ |
| 197 |
0 |
if (Console.isDebugEnabled()) |
| 198 |
|
{ |
| 199 |
0 |
Console.debug("Prompting user for " + dialogTitle |
| 200 |
|
+ " for Cache property " + property); |
| 201 |
|
} |
| 202 |
0 |
try |
| 203 |
|
{ |
| 204 |
0 |
int reply = JvOptionPane.showConfirmDialog(Desktop.getDesktopPane(), |
| 205 |
|
dialogText, dialogTitle, |
| 206 |
0 |
(allowCancel) ? JvOptionPane.YES_NO_CANCEL_OPTION |
| 207 |
|
: JvOptionPane.YES_NO_OPTION, |
| 208 |
|
JvOptionPane.QUESTION_MESSAGE); |
| 209 |
|
|
| 210 |
|
|
| 211 |
0 |
Console.debug("Got response : " + reply); |
| 212 |
0 |
if (reply == JvOptionPane.YES_OPTION) |
| 213 |
|
{ |
| 214 |
0 |
Cache.setProperty(property, "true"); |
| 215 |
|
} |
| 216 |
0 |
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 |
0 |
Console.debug("User cancelled setting " + property); |
| 230 |
0 |
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 |
|
} |