| 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 |
|
|
| |
|
| 0% |
Uncovered Elements: 118 (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 |
|
|
| |
|
| 0% |
Uncovered Elements: 37 (37) |
Complexity: 6 |
Complexity Density: 0.21 |
|
| 78 |
0 |
public static ButtonGroup addMenuItems(final JMenu colourMenu,... |
| 79 |
|
final ColourChangeListener client, AnnotatedCollectionI coll, |
| 80 |
|
boolean simpleOnly) |
| 81 |
|
{ |
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
0 |
ButtonGroup colours = new ButtonGroup(); |
| 87 |
|
|
| 88 |
0 |
if (!simpleOnly) |
| 89 |
|
{ |
| 90 |
0 |
JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem( |
| 91 |
|
MessageManager.getString("label.none")); |
| 92 |
0 |
noColourmenuItem.setName(ResidueColourScheme.NONE); |
| 93 |
0 |
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 |
0 |
colourMenu.add(noColourmenuItem); |
| 102 |
0 |
colours.add(noColourmenuItem); |
| 103 |
|
} |
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
0 |
Iterable<ColourSchemeI> colourSchemes = ColourSchemes.getInstance() |
| 110 |
|
.getColourSchemes(); |
| 111 |
0 |
for (ColourSchemeI scheme : colourSchemes) |
| 112 |
|
{ |
| 113 |
0 |
if (simpleOnly && !scheme.isSimple()) |
| 114 |
|
{ |
| 115 |
0 |
continue; |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
|
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
0 |
final String name = scheme.getSchemeName(); |
| 123 |
0 |
String label = MessageManager.getStringOrReturn("label.colourScheme_", |
| 124 |
|
name); |
| 125 |
0 |
final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem( |
| 126 |
|
label); |
| 127 |
0 |
radioItem.setName(name); |
| 128 |
0 |
radioItem.setEnabled(scheme.isApplicableTo(coll)); |
| 129 |
0 |
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.getDesktopPane(), |
| 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 |
0 |
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 |
0 |
colourMenu.add(radioItem); |
| 190 |
0 |
colours.add(radioItem); |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
|
| 194 |
|
|
| 195 |
|
|
| 196 |
|
|
| 197 |
0 |
if (client instanceof AlignFrame) |
| 198 |
|
{ |
| 199 |
0 |
final String label = MessageManager.getString("action.user_defined"); |
| 200 |
0 |
JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem( |
| 201 |
|
label); |
| 202 |
0 |
userDefinedColour.setName(ResidueColourScheme.USER_DEFINED_MENU); |
| 203 |
0 |
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 |
0 |
colourMenu.add(userDefinedColour); |
| 213 |
0 |
colours.add(userDefinedColour); |
| 214 |
|
} |
| 215 |
|
|
| 216 |
0 |
return colours; |
| 217 |
|
} |
| 218 |
|
|
| 219 |
|
|
| 220 |
|
|
| 221 |
|
|
| 222 |
|
|
| 223 |
|
|
| 224 |
|
|
| 225 |
|
|
| 226 |
|
@param |
| 227 |
|
@param |
| 228 |
|
|
| |
|
| 0% |
Uncovered Elements: 32 (32) |
Complexity: 9 |
Complexity Density: 0.5 |
|
| 229 |
0 |
public static void setColourSelected(JMenu colourMenu, ColourSchemeI cs)... |
| 230 |
|
{ |
| 231 |
0 |
String colourName = cs == null ? ResidueColourScheme.NONE |
| 232 |
|
: cs.getSchemeName(); |
| 233 |
|
|
| 234 |
0 |
JRadioButtonMenuItem none = null; |
| 235 |
0 |
JRadioButtonMenuItem userDefined = null; |
| 236 |
|
|
| 237 |
|
|
| 238 |
|
|
| 239 |
|
|
| 240 |
|
|
| 241 |
0 |
for (Component menuItem : colourMenu.getMenuComponents()) |
| 242 |
|
{ |
| 243 |
0 |
if (menuItem instanceof JRadioButtonMenuItem) |
| 244 |
|
{ |
| 245 |
0 |
JRadioButtonMenuItem radioButton = (JRadioButtonMenuItem) menuItem; |
| 246 |
0 |
String buttonName = radioButton.getName(); |
| 247 |
0 |
if (buttonName.equals(colourName)) |
| 248 |
|
{ |
| 249 |
0 |
radioButton.setSelected(true); |
| 250 |
0 |
return; |
| 251 |
|
} |
| 252 |
0 |
if (ResidueColourScheme.NONE.equals(buttonName)) |
| 253 |
|
{ |
| 254 |
0 |
none = radioButton; |
| 255 |
|
} |
| 256 |
0 |
if (ResidueColourScheme.USER_DEFINED_MENU.equals(buttonName)) |
| 257 |
|
{ |
| 258 |
0 |
userDefined = radioButton; |
| 259 |
|
} |
| 260 |
|
} |
| 261 |
|
} |
| 262 |
|
|
| 263 |
|
|
| 264 |
|
|
| 265 |
|
|
| 266 |
|
|
| 267 |
0 |
if (cs instanceof UserColourScheme && userDefined != null) |
| 268 |
|
{ |
| 269 |
0 |
userDefined.setSelected(true); |
| 270 |
|
} |
| 271 |
0 |
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.removePropertyNoSave("USER_DEFINED_COLOURS"); |
| 319 |
|
} |
| 320 |
|
} |
| 321 |
|
} |